// verify_bits.zig pub const O = packed struct(u32) { ACCMODE: u2 = 0, // bit 0-1 _2: u4 = 0, // bit 2-5 CREAT: bool = false, // bit 6 EXCL: bool = false, // bit 7 NOCTTY: bool = false, // bit 8 TRUNC: bool = false, // bit 9 _10: u22 = 0, // bit 10-31 }; // Verification 1: Modifying multiple fields using a packed struct. // Expectation: The compiler will merge these three modifications into a single // efficient bitwise OR instruction (orr). export fn test_struct(flags: *O) void { flags.ACCMODE = 1; // Set bit 0-1 flags.CREAT = true; // Set bit 6 flags.TRUNC = true; // Set bit 9 } // Verification 2: Traditional bitmasking approach. // Expectation: The generated machine code logic should be identical to test_struct. export fn test_manual(flags: *u32) void { // 0x241 = (1 << 0) | (1 << 6) | (1 << 9) flags.* = (flags.* & ~@as(u32, 0x3)) | 0x241; }