bitfields - 4425 bells & whistles

Era Scarecrow rtcvb32 at yahoo.com
Thu Aug 2 06:26:16 PDT 2012


Following from issue list:

bearophile_hugs 2010-10-04 18:16:44 PDT
>Another possible feature is to make std.bitmanip.bitfields 
>generate two
versions of the code, that get compiled conditionally according 
to the CPU
endianess:

> static if (std.system.endian == std.system.Endian.BigEndian) {
>    ...
> } else {
>     ...
> }

Having it endian specific brings up a couple questions.

  Which endian is 'correct'? Resolutions could be...
   a) Both are correct (Leave as is)
   b) big/little is correct and should always convert to the other 
(which one?)
   c) Specify correct type as a flag, then swaps for the other in 
generated code

  Second, which would be the best approach?
   a) swap bytes in a temporary, modify the temporary, replace 
storage? (In every function)
   b) use current endianness, then prepping saving/loading have it 
swap? (very unlikely)
   c) use ubyte array and use shifting on each byte (small Endian, 
also allows for odd byte sizes, not very likely, but possible)

  I know an instruction for the Pentium system (686+?) bswap will 
swap the appropriate bytes as a conversion and takes a single 
cycle, using assembler that can be incorporated assuming it's 
ready for it (course than the template would be updated more 
likely and not the bitfield template).


More information about the Digitalmars-d-learn mailing list