# stage2: Use mem.readPackedInt etc\. for packed bitcasts · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/3295fee9116789f144e6406493116c451aee7c57)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 3295fee9116789f144e6406493116c451aee7c57

Requested commit: 3295fee9116789f144e6406493116c451aee7c57

Commit: 3295fee9116789f144e6406493116c451aee7c57

Tree: 71f10d7a5b987b956d0811d925424fea57fddd09

Author: Cody Tapscott

Committer: Cody Tapscott

## Message

```
stage2: Use mem.readPackedInt etc. for packed bitcasts

Packed memory has a well-defined layout that doesn't require
conversion from an integer to read from. Let's use it :-)

This change means that for bitcasting to/from a packed value that
is N layers deep, we no longer have to create N temporary big-ints
and perform N copies.

Other miscellaneous improvements:
  - Adds support for casting to packed enums and vectors
  - 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

This also changes the bitcast memory layout of exotic integers on
big-endian systems to match what's empirically observed on our targets.
Technically, this layout is not guaranteed by LLVM so we should probably
ban bitcasts that reveal these padding bits, but for now this is an
improvement.

```

## Parents

- [c639c225444c9252515949786e139494fb728861](https://git.cafe/gitcafe/zig/commit/c639c225444c9252515949786e139494fb728861?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/3295fee9116789f144e6406493116c451aee7c57?format=markdown)
