zig icon indicating copy to clipboard operation
zig copied to clipboard

Introduce `std.mem.readPackedInt` and improve bitcasting of packed memory layouts

Open topolarity opened this issue 1 year ago • 1 comments

Packed memory has a well-defined layout that doesn't require actually using a BigInt to read from. Let's use it :-)

Included changes:

  • Adds readPackedInt, writePackedInt and friends to std.mem
  • Adds support for casting to packed enums and vectors
    • (follow-up to #13124)
  • Fixes bitcasting to/from vectors outside of a packed struct
  • Adds a fast path for bitcasting <= u/i64
  • Fixes bug when bitcasting f80 which would clear following fields

topolarity avatar Oct 18 '22 19:10 topolarity

So far writePackedIntLittle and writePackedIntBig have no test coverage testing them against another and it would be nice to reverse the ints with byteswap to ensure both work as expected. At least, if that is feasible.

I think this is already covered. writePackedIntLittle/Big are tested through writePackedInt, including foreign endianness with byte swaps.

topolarity avatar Oct 19 '22 18:10 topolarity