Re: [Boost-bugs] [Boost C++ Libraries] #9235: Construction from binary data

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #9235: Construction from binary data
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-02-18 15:22:39


#9235: Construction from binary data
-------------------------------+----------------------------
  Reporter: psiha | Owner: johnmaddock
      Type: Feature Requests | Status: reopened
 Milestone: To Be Determined | Component: multiprecision
   Version: Boost 1.54.0 | Severity: Optimization
Resolution: | Keywords:
-------------------------------+----------------------------

Comment (by psiha):

 Replying to [comment:5 johnmaddock]:

 I've just noticed you've added import/export_bits() :) ...interface-wise
 this would be enough to close this ticket however I'm not fully happy with
 the implementation so let's not yet ;-D


> It's not quite as trivial as you think: the internal data layout is
 highly platform/compiler dependent. For example a 128-bit integer is
 represented as 4 32 bit words on MSVC, but as a single 128-bit value on
 GCC-x64 (which has {{{__int128}}}).
 [[BR]]
 This does/should not matter if the endianess of the machine and your
 internal implementation match, the byte layout will be the same. Except if
 the 'raw'/binary data is in a different endianess than your internal
 representation (modeled by the msv_first import/export_bits() parameter)
 but even then it is a matter of a simple byte reversal.
 Tried it with both importing and exporting with Boost 1.60 and 'it just
 works':

 {{{
     template <class Key>
     void LE_NOTHROW load( Key & key, std::array<std::uint8_t,
 Constants::rsaKeySizeInBytes> const & keyBytes )
     {
     #if 0
         BOOST_VERIFY( &import_bits( key, keyBytes.begin(), keyBytes.end()
 ) == &key );
     #else
         key.backend().resize( key.backend().internal_limb_count, 0 );
         std::reverse_copy( keyBytes.begin(), keyBytes.end(),
 reinterpret_cast<std::uint8_t *>( key.backend().limbs() ) );
     #endif
     }
 }}}

 and looks trivial in the disassembly window ;)


 ps. first I tried to force key (a fixed unchecked uint4096_t) limb count
 to max by constructing it as Key key( -1 ) but that didn't quite give a
 picturesque codegen ;D

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/9235#comment:6>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:19 UTC