Zig's new bitCast semantics and LLVM back end improvements(ziglang.org)
244 points by kouosi 21 hours ago | 125 comments
tl;dr: Zig's `@bitCast` has been redefined with new semantics based on a type's "logical bit layout" rather than reinterpreting memory bytes, making behavior endian-agnostic and enabling operations like converting `[2]u3` to `@Vector(3, u2)`. The change was driven by LLVM backend improvements that now extend arbitrary bit-width integers (u4, u13, etc.) to ABI-sized types in memory—matching Clang's `_BitInt(N)` lowering—which restored missed optimizations and yielded ~5% performance gains in the Zig compiler itself. The new semantics are implemented across all backends and comptime execution, landing in 0.17.0.
HN Discussion:
  • New bitCast semantics enable cleaner bit-packed binary header manipulation
  • Curious about practical applications like Base64 conversion using the new semantics
  • ~Skeptical of arbitrary-width integers, preferring manual bit packing for clarity
  • Calling the new semantics 'endian-agnostic' is misleading since it picks little-endian
  • The new semantics are a significant mistake