| author | |
| committer | |
| log | 3fc6fc68129219a026ae3d7dff82513758e33a21 |
| tree | ab1a4fdc8886513ddbbfa7167ecf92eede629cfd |
| parent | 149200aac5f7f78fbb3427e3a9445c80efd2116b |
Let's take this breaking change opportunity to fix the style of this
enum.160 files changed, 1306 insertions(+), 1306 deletions(-)
deps/aro/Compilation.zig+1-1| ... | @@ -402,7 +402,7 @@ pub fn generateBuiltinMacros(comp: *Compilation) !Source { | ... | @@ -402,7 +402,7 @@ pub fn generateBuiltinMacros(comp: *Compilation) !Source { |
| 402 | \\#define __ORDER_PDP_ENDIAN__ 3412 | 402 | \\#define __ORDER_PDP_ENDIAN__ 3412 |
| 403 | \\ | 403 | \\ |
| 404 | ); | 404 | ); |
| 405 | if (comp.target.cpu.arch.endian() == .Little) try w.writeAll( | 405 | if (comp.target.cpu.arch.endian() == .little) try w.writeAll( |
| 406 | \\#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ | 406 | \\#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ |
| 407 | \\#define __LITTLE_ENDIAN__ 1 | 407 | \\#define __LITTLE_ENDIAN__ 1 |
| 408 | \\ | 408 | \\ |
deps/aro/target.zig+2-2| ... | @@ -398,8 +398,8 @@ pub fn ldEmulationOption(target: std.Target, arm_endianness: ?std.builtin.Endian | ... | @@ -398,8 +398,8 @@ pub fn ldEmulationOption(target: std.Target, arm_endianness: ?std.builtin.Endian |
| 398 | .thumb, | 398 | .thumb, |
| 399 | .thumbeb, | 399 | .thumbeb, |
| 400 | => switch (arm_endianness orelse target.cpu.arch.endian()) { | 400 | => switch (arm_endianness orelse target.cpu.arch.endian()) { |
| 401 | .Little => "armelf_linux_eabi", | 401 | .little => "armelf_linux_eabi", |
| 402 | .Big => "armelfb_linux_eabi", | 402 | .big => "armelfb_linux_eabi", |
| 403 | }, | 403 | }, |
| 404 | .aarch64 => "aarch64linux", | 404 | .aarch64 => "aarch64linux", |
| 405 | .aarch64_be => "aarch64linuxb", | 405 | .aarch64_be => "aarch64linuxb", |
doc/langref.html.in+2-2| ... | @@ -3376,11 +3376,11 @@ fn doTheTest() !void { | ... | @@ -3376,11 +3376,11 @@ fn doTheTest() !void { |
| 3376 | 3376 | ||
| 3377 | var ordered: [2]u8 = @bitCast(full); | 3377 | var ordered: [2]u8 = @bitCast(full); |
| 3378 | switch (native_endian) { | 3378 | switch (native_endian) { |
| 3379 | .Big => { | 3379 | .big => { |
| 3380 | try expect(ordered[0] == 0x12); | 3380 | try expect(ordered[0] == 0x12); |
| 3381 | try expect(ordered[1] == 0x34); | 3381 | try expect(ordered[1] == 0x34); |
| 3382 | }, | 3382 | }, |
| 3383 | .Little => { | 3383 | .little => { |
| 3384 | try expect(ordered[0] == 0x34); | 3384 | try expect(ordered[0] == 0x34); |
| 3385 | try expect(ordered[1] == 0x12); | 3385 | try expect(ordered[1] == 0x12); |
| 3386 | }, | 3386 | }, |
lib/compiler_rt/common.zig+1-1| ... | @@ -249,7 +249,7 @@ pub fn HalveInt(comptime T: type, comptime signed_half: bool) type { | ... | @@ -249,7 +249,7 @@ pub fn HalveInt(comptime T: type, comptime signed_half: bool) type { |
| 249 | pub const HalfT = if (signed_half) HalfTS else HalfTU; | 249 | pub const HalfT = if (signed_half) HalfTS else HalfTU; |
| 250 | 250 | ||
| 251 | all: T, | 251 | all: T, |
| 252 | s: if (native_endian == .Little) | 252 | s: if (native_endian == .little) |
| 253 | extern struct { low: HalfT, high: HalfT } | 253 | extern struct { low: HalfT, high: HalfT } |
| 254 | else | 254 | else |
| 255 | extern struct { high: HalfT, low: HalfT }, | 255 | extern struct { high: HalfT, low: HalfT }, |
lib/compiler_rt/fmod.zig+6-6| ... | @@ -142,16 +142,16 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 { | ... | @@ -142,16 +142,16 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 { |
| 142 | const bPtr_u16: [*]u16 = @ptrCast(&bmod); | 142 | const bPtr_u16: [*]u16 = @ptrCast(&bmod); |
| 143 | 143 | ||
| 144 | const exp_and_sign_index = comptime switch (builtin.target.cpu.arch.endian()) { | 144 | const exp_and_sign_index = comptime switch (builtin.target.cpu.arch.endian()) { |
| 145 | .Little => 7, | 145 | .little => 7, |
| 146 | .Big => 0, | 146 | .big => 0, |
| 147 | }; | 147 | }; |
| 148 | const low_index = comptime switch (builtin.target.cpu.arch.endian()) { | 148 | const low_index = comptime switch (builtin.target.cpu.arch.endian()) { |
| 149 | .Little => 0, | 149 | .little => 0, |
| 150 | .Big => 1, | 150 | .big => 1, |
| 151 | }; | 151 | }; |
| 152 | const high_index = comptime switch (builtin.target.cpu.arch.endian()) { | 152 | const high_index = comptime switch (builtin.target.cpu.arch.endian()) { |
| 153 | .Little => 1, | 153 | .little => 1, |
| 154 | .Big => 0, | 154 | .big => 0, |
| 155 | }; | 155 | }; |
| 156 | 156 | ||
| 157 | const signA = aPtr_u16[exp_and_sign_index] & 0x8000; | 157 | const signA = aPtr_u16[exp_and_sign_index] & 0x8000; |
lib/compiler_rt/udivmod.zig+2-2| ... | @@ -5,8 +5,8 @@ const Log2Int = std.math.Log2Int; | ... | @@ -5,8 +5,8 @@ const Log2Int = std.math.Log2Int; |
| 5 | const HalveInt = @import("common.zig").HalveInt; | 5 | const HalveInt = @import("common.zig").HalveInt; |
| 6 | 6 | ||
| 7 | const lo = switch (builtin.cpu.arch.endian()) { | 7 | const lo = switch (builtin.cpu.arch.endian()) { |
| 8 | .Big => 1, | 8 | .big => 1, |
| 9 | .Little => 0, | 9 | .little => 0, |
| 10 | }; | 10 | }; |
| 11 | const hi = 1 - lo; | 11 | const hi = 1 - lo; |
| 12 | 12 |
lib/compiler_rt/udivmodei4.zig+2-2| ... | @@ -15,12 +15,12 @@ const endian = builtin.cpu.arch.endian(); | ... | @@ -15,12 +15,12 @@ const endian = builtin.cpu.arch.endian(); |
| 15 | 15 | ||
| 16 | /// Get the value of a limb. | 16 | /// Get the value of a limb. |
| 17 | inline fn limb(x: []const u32, i: usize) u32 { | 17 | inline fn limb(x: []const u32, i: usize) u32 { |
| 18 | return if (endian == .Little) x[i] else x[x.len - 1 - i]; | 18 | return if (endian == .little) x[i] else x[x.len - 1 - i]; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | /// Change the value of a limb. | 21 | /// Change the value of a limb. |
| 22 | inline fn limb_set(x: []u32, i: usize, v: u32) void { | 22 | inline fn limb_set(x: []u32, i: usize, v: u32) void { |
| 23 | if (endian == .Little) { | 23 | if (endian == .little) { |
| 24 | x[i] = v; | 24 | x[i] = v; |
| 25 | } else { | 25 | } else { |
| 26 | x[x.len - 1 - i] = v; | 26 | x[x.len - 1 - i] = v; |
lib/std/Build/Step/CheckObject.zig+2-2| ... | @@ -1624,8 +1624,8 @@ const WasmDumper = struct { | ... | @@ -1624,8 +1624,8 @@ const WasmDumper = struct { |
| 1624 | switch (opcode) { | 1624 | switch (opcode) { |
| 1625 | .i32_const => try writer.print("i32.const {x}\n", .{try std.leb.readILEB128(i32, reader)}), | 1625 | .i32_const => try writer.print("i32.const {x}\n", .{try std.leb.readILEB128(i32, reader)}), |
| 1626 | .i64_const => try writer.print("i64.const {x}\n", .{try std.leb.readILEB128(i64, reader)}), | 1626 | .i64_const => try writer.print("i64.const {x}\n", .{try std.leb.readILEB128(i64, reader)}), |
| 1627 | .f32_const => try writer.print("f32.const {x}\n", .{@as(f32, @bitCast(try reader.readInt(u32, .Little)))}), | 1627 | .f32_const => try writer.print("f32.const {x}\n", .{@as(f32, @bitCast(try reader.readInt(u32, .little)))}), |
| 1628 | .f64_const => try writer.print("f64.const {x}\n", .{@as(f64, @bitCast(try reader.readInt(u64, .Little)))}), | 1628 | .f64_const => try writer.print("f64.const {x}\n", .{@as(f64, @bitCast(try reader.readInt(u64, .little)))}), |
| 1629 | .global_get => try writer.print("global.get {x}\n", .{try std.leb.readULEB128(u32, reader)}), | 1629 | .global_get => try writer.print("global.get {x}\n", .{try std.leb.readULEB128(u32, reader)}), |
| 1630 | else => unreachable, | 1630 | else => unreachable, |
| 1631 | } | 1631 | } |
lib/std/base64.zig+4-4| ... | @@ -104,14 +104,14 @@ pub const Base64Encoder = struct { | ... | @@ -104,14 +104,14 @@ pub const Base64Encoder = struct { |
| 104 | var idx: usize = 0; | 104 | var idx: usize = 0; |
| 105 | var out_idx: usize = 0; | 105 | var out_idx: usize = 0; |
| 106 | while (idx + 15 < source.len) : (idx += 12) { | 106 | while (idx + 15 < source.len) : (idx += 12) { |
| 107 | const bits = std.mem.readInt(u128, source[idx..][0..16], .Big); | 107 | const bits = std.mem.readInt(u128, source[idx..][0..16], .big); |
| 108 | inline for (0..16) |i| { | 108 | inline for (0..16) |i| { |
| 109 | dest[out_idx + i] = encoder.alphabet_chars[@truncate((bits >> (122 - i * 6)) & 0x3f)]; | 109 | dest[out_idx + i] = encoder.alphabet_chars[@truncate((bits >> (122 - i * 6)) & 0x3f)]; |
| 110 | } | 110 | } |
| 111 | out_idx += 16; | 111 | out_idx += 16; |
| 112 | } | 112 | } |
| 113 | while (idx + 3 < source.len) : (idx += 3) { | 113 | while (idx + 3 < source.len) : (idx += 3) { |
| 114 | const bits = std.mem.readInt(u32, source[idx..][0..4], .Big); | 114 | const bits = std.mem.readInt(u32, source[idx..][0..4], .big); |
| 115 | dest[out_idx] = encoder.alphabet_chars[(bits >> 26) & 0x3f]; | 115 | dest[out_idx] = encoder.alphabet_chars[(bits >> 26) & 0x3f]; |
| 116 | dest[out_idx + 1] = encoder.alphabet_chars[(bits >> 20) & 0x3f]; | 116 | dest[out_idx + 1] = encoder.alphabet_chars[(bits >> 20) & 0x3f]; |
| 117 | dest[out_idx + 2] = encoder.alphabet_chars[(bits >> 14) & 0x3f]; | 117 | dest[out_idx + 2] = encoder.alphabet_chars[(bits >> 14) & 0x3f]; |
| ... | @@ -226,7 +226,7 @@ pub const Base64Decoder = struct { | ... | @@ -226,7 +226,7 @@ pub const Base64Decoder = struct { |
| 226 | if ((new_bits & invalid_char_tst) != 0) return error.InvalidCharacter; | 226 | if ((new_bits & invalid_char_tst) != 0) return error.InvalidCharacter; |
| 227 | bits |= (new_bits << (24 * i)); | 227 | bits |= (new_bits << (24 * i)); |
| 228 | } | 228 | } |
| 229 | std.mem.writeInt(u128, dest[dest_idx..][0..16], bits, .Little); | 229 | std.mem.writeInt(u128, dest[dest_idx..][0..16], bits, .little); |
| 230 | } | 230 | } |
| 231 | while (fast_src_idx + 4 < source.len and dest_idx + 3 < dest.len) : ({ | 231 | while (fast_src_idx + 4 < source.len and dest_idx + 3 < dest.len) : ({ |
| 232 | fast_src_idx += 4; | 232 | fast_src_idx += 4; |
| ... | @@ -237,7 +237,7 @@ pub const Base64Decoder = struct { | ... | @@ -237,7 +237,7 @@ pub const Base64Decoder = struct { |
| 237 | bits |= decoder.fast_char_to_index[2][source[fast_src_idx + 2]]; | 237 | bits |= decoder.fast_char_to_index[2][source[fast_src_idx + 2]]; |
| 238 | bits |= decoder.fast_char_to_index[3][source[fast_src_idx + 3]]; | 238 | bits |= decoder.fast_char_to_index[3][source[fast_src_idx + 3]]; |
| 239 | if ((bits & invalid_char_tst) != 0) return error.InvalidCharacter; | 239 | if ((bits & invalid_char_tst) != 0) return error.InvalidCharacter; |
| 240 | std.mem.writeInt(u32, dest[dest_idx..][0..4], bits, .Little); | 240 | std.mem.writeInt(u32, dest[dest_idx..][0..4], bits, .little); |
| 241 | } | 241 | } |
| 242 | var remaining = source[fast_src_idx..]; | 242 | var remaining = source[fast_src_idx..]; |
| 243 | for (remaining, fast_src_idx..) |c, src_idx| { | 243 | for (remaining, fast_src_idx..) |c, src_idx| { |
lib/std/builtin.zig+2-2| ... | @@ -450,8 +450,8 @@ pub const FloatMode = enum { | ... | @@ -450,8 +450,8 @@ pub const FloatMode = enum { |
| 450 | /// This data structure is used by the Zig language code generation and | 450 | /// This data structure is used by the Zig language code generation and |
| 451 | /// therefore must be kept in sync with the compiler implementation. | 451 | /// therefore must be kept in sync with the compiler implementation. |
| 452 | pub const Endian = enum { | 452 | pub const Endian = enum { |
| 453 | Big, | 453 | big, |
| 454 | Little, | 454 | little, |
| 455 | }; | 455 | }; |
| 456 | 456 | ||
| 457 | /// This data structure is used by the Zig language code generation and | 457 | /// This data structure is used by the Zig language code generation and |
lib/std/child_process.zig+2-2| ... | @@ -1376,7 +1376,7 @@ fn writeIntFd(fd: i32, value: ErrInt) !void { | ... | @@ -1376,7 +1376,7 @@ fn writeIntFd(fd: i32, value: ErrInt) !void { |
| 1376 | .capable_io_mode = .blocking, | 1376 | .capable_io_mode = .blocking, |
| 1377 | .intended_io_mode = .blocking, | 1377 | .intended_io_mode = .blocking, |
| 1378 | }; | 1378 | }; |
| 1379 | file.writer().writeInt(u64, @intCast(value), .Little) catch return error.SystemResources; | 1379 | file.writer().writeInt(u64, @intCast(value), .little) catch return error.SystemResources; |
| 1380 | } | 1380 | } |
| 1381 | 1381 | ||
| 1382 | fn readIntFd(fd: i32) !ErrInt { | 1382 | fn readIntFd(fd: i32) !ErrInt { |
| ... | @@ -1385,7 +1385,7 @@ fn readIntFd(fd: i32) !ErrInt { | ... | @@ -1385,7 +1385,7 @@ fn readIntFd(fd: i32) !ErrInt { |
| 1385 | .capable_io_mode = .blocking, | 1385 | .capable_io_mode = .blocking, |
| 1386 | .intended_io_mode = .blocking, | 1386 | .intended_io_mode = .blocking, |
| 1387 | }; | 1387 | }; |
| 1388 | return @as(ErrInt, @intCast(file.reader().readInt(u64, .Little) catch return error.SystemResources)); | 1388 | return @as(ErrInt, @intCast(file.reader().readInt(u64, .little) catch return error.SystemResources)); |
| 1389 | } | 1389 | } |
| 1390 | 1390 | ||
| 1391 | /// Caller must free result. | 1391 | /// Caller must free result. |
lib/std/coff.zig+20-20| ... | @@ -663,7 +663,7 @@ pub const Symbol = struct { | ... | @@ -663,7 +663,7 @@ pub const Symbol = struct { |
| 663 | 663 | ||
| 664 | pub fn getNameOffset(self: Symbol) ?u32 { | 664 | pub fn getNameOffset(self: Symbol) ?u32 { |
| 665 | if (!std.mem.eql(u8, self.name[0..4], "\x00\x00\x00\x00")) return null; | 665 | if (!std.mem.eql(u8, self.name[0..4], "\x00\x00\x00\x00")) return null; |
| 666 | const offset = std.mem.readInt(u32, self.name[4..8], .Little); | 666 | const offset = std.mem.readInt(u32, self.name[4..8], .little); |
| 667 | return offset; | 667 | return offset; |
| 668 | } | 668 | } |
| 669 | }; | 669 | }; |
| ... | @@ -1075,7 +1075,7 @@ pub const Coff = struct { | ... | @@ -1075,7 +1075,7 @@ pub const Coff = struct { |
| 1075 | var stream = std.io.fixedBufferStream(data); | 1075 | var stream = std.io.fixedBufferStream(data); |
| 1076 | const reader = stream.reader(); | 1076 | const reader = stream.reader(); |
| 1077 | try stream.seekTo(pe_pointer_offset); | 1077 | try stream.seekTo(pe_pointer_offset); |
| 1078 | var coff_header_offset = try reader.readInt(u32, .Little); | 1078 | var coff_header_offset = try reader.readInt(u32, .little); |
| 1079 | try stream.seekTo(coff_header_offset); | 1079 | try stream.seekTo(coff_header_offset); |
| 1080 | var buf: [4]u8 = undefined; | 1080 | var buf: [4]u8 = undefined; |
| 1081 | try reader.readNoEof(&buf); | 1081 | try reader.readNoEof(&buf); |
| ... | @@ -1142,7 +1142,7 @@ pub const Coff = struct { | ... | @@ -1142,7 +1142,7 @@ pub const Coff = struct { |
| 1142 | if (!mem.eql(u8, &cv_signature, "RSDS")) | 1142 | if (!mem.eql(u8, &cv_signature, "RSDS")) |
| 1143 | return error.InvalidPEMagic; | 1143 | return error.InvalidPEMagic; |
| 1144 | try reader.readNoEof(self.guid[0..]); | 1144 | try reader.readNoEof(self.guid[0..]); |
| 1145 | self.age = try reader.readInt(u32, .Little); | 1145 | self.age = try reader.readInt(u32, .little); |
| 1146 | 1146 | ||
| 1147 | // Finally read the null-terminated string. | 1147 | // Finally read the null-terminated string. |
| 1148 | var byte = try reader.readByte(); | 1148 | var byte = try reader.readByte(); |
| ... | @@ -1223,7 +1223,7 @@ pub const Coff = struct { | ... | @@ -1223,7 +1223,7 @@ pub const Coff = struct { |
| 1223 | if (coff_header.pointer_to_symbol_table == 0) return null; | 1223 | if (coff_header.pointer_to_symbol_table == 0) return null; |
| 1224 | 1224 | ||
| 1225 | const offset = coff_header.pointer_to_symbol_table + Symbol.sizeOf() * coff_header.number_of_symbols; | 1225 | const offset = coff_header.pointer_to_symbol_table + Symbol.sizeOf() * coff_header.number_of_symbols; |
| 1226 | const size = mem.readInt(u32, self.data[offset..][0..4], .Little); | 1226 | const size = mem.readInt(u32, self.data[offset..][0..4], .little); |
| 1227 | if ((offset + size) > self.data.len) return error.InvalidStrtabSize; | 1227 | if ((offset + size) > self.data.len) return error.InvalidStrtabSize; |
| 1228 | 1228 | ||
| 1229 | return Strtab{ .buffer = self.data[offset..][0..size] }; | 1229 | return Strtab{ .buffer = self.data[offset..][0..size] }; |
| ... | @@ -1324,9 +1324,9 @@ pub const Symtab = struct { | ... | @@ -1324,9 +1324,9 @@ pub const Symtab = struct { |
| 1324 | fn asSymbol(raw: []const u8) Symbol { | 1324 | fn asSymbol(raw: []const u8) Symbol { |
| 1325 | return .{ | 1325 | return .{ |
| 1326 | .name = raw[0..8].*, | 1326 | .name = raw[0..8].*, |
| 1327 | .value = mem.readInt(u32, raw[8..12], .Little), | 1327 | .value = mem.readInt(u32, raw[8..12], .little), |
| 1328 | .section_number = @as(SectionNumber, @enumFromInt(mem.readInt(u16, raw[12..14], .Little))), | 1328 | .section_number = @as(SectionNumber, @enumFromInt(mem.readInt(u16, raw[12..14], .little))), |
| 1329 | .type = @as(SymType, @bitCast(mem.readInt(u16, raw[14..16], .Little))), | 1329 | .type = @as(SymType, @bitCast(mem.readInt(u16, raw[14..16], .little))), |
| 1330 | .storage_class = @as(StorageClass, @enumFromInt(raw[16])), | 1330 | .storage_class = @as(StorageClass, @enumFromInt(raw[16])), |
| 1331 | .number_of_aux_symbols = raw[17], | 1331 | .number_of_aux_symbols = raw[17], |
| 1332 | }; | 1332 | }; |
| ... | @@ -1335,27 +1335,27 @@ pub const Symtab = struct { | ... | @@ -1335,27 +1335,27 @@ pub const Symtab = struct { |
| 1335 | fn asDebugInfo(raw: []const u8) DebugInfoDefinition { | 1335 | fn asDebugInfo(raw: []const u8) DebugInfoDefinition { |
| 1336 | return .{ | 1336 | return .{ |
| 1337 | .unused_1 = raw[0..4].*, | 1337 | .unused_1 = raw[0..4].*, |
| 1338 | .linenumber = mem.readInt(u16, raw[4..6], .Little), | 1338 | .linenumber = mem.readInt(u16, raw[4..6], .little), |
| 1339 | .unused_2 = raw[6..12].*, | 1339 | .unused_2 = raw[6..12].*, |
| 1340 | .pointer_to_next_function = mem.readInt(u32, raw[12..16], .Little), | 1340 | .pointer_to_next_function = mem.readInt(u32, raw[12..16], .little), |
| 1341 | .unused_3 = raw[16..18].*, | 1341 | .unused_3 = raw[16..18].*, |
| 1342 | }; | 1342 | }; |
| 1343 | } | 1343 | } |
| 1344 | 1344 | ||
| 1345 | fn asFuncDef(raw: []const u8) FunctionDefinition { | 1345 | fn asFuncDef(raw: []const u8) FunctionDefinition { |
| 1346 | return .{ | 1346 | return .{ |
| 1347 | .tag_index = mem.readInt(u32, raw[0..4], .Little), | 1347 | .tag_index = mem.readInt(u32, raw[0..4], .little), |
| 1348 | .total_size = mem.readInt(u32, raw[4..8], .Little), | 1348 | .total_size = mem.readInt(u32, raw[4..8], .little), |
| 1349 | .pointer_to_linenumber = mem.readInt(u32, raw[8..12], .Little), | 1349 | .pointer_to_linenumber = mem.readInt(u32, raw[8..12], .little), |
| 1350 | .pointer_to_next_function = mem.readInt(u32, raw[12..16], .Little), | 1350 | .pointer_to_next_function = mem.readInt(u32, raw[12..16], .little), |
| 1351 | .unused = raw[16..18].*, | 1351 | .unused = raw[16..18].*, |
| 1352 | }; | 1352 | }; |
| 1353 | } | 1353 | } |
| 1354 | 1354 | ||
| 1355 | fn asWeakExtDef(raw: []const u8) WeakExternalDefinition { | 1355 | fn asWeakExtDef(raw: []const u8) WeakExternalDefinition { |
| 1356 | return .{ | 1356 | return .{ |
| 1357 | .tag_index = mem.readInt(u32, raw[0..4], .Little), | 1357 | .tag_index = mem.readInt(u32, raw[0..4], .little), |
| 1358 | .flag = @as(WeakExternalFlag, @enumFromInt(mem.readInt(u32, raw[4..8], .Little))), | 1358 | .flag = @as(WeakExternalFlag, @enumFromInt(mem.readInt(u32, raw[4..8], .little))), |
| 1359 | .unused = raw[8..18].*, | 1359 | .unused = raw[8..18].*, |
| 1360 | }; | 1360 | }; |
| 1361 | } | 1361 | } |
| ... | @@ -1368,11 +1368,11 @@ pub const Symtab = struct { | ... | @@ -1368,11 +1368,11 @@ pub const Symtab = struct { |
| 1368 | 1368 | ||
| 1369 | fn asSectDef(raw: []const u8) SectionDefinition { | 1369 | fn asSectDef(raw: []const u8) SectionDefinition { |
| 1370 | return .{ | 1370 | return .{ |
| 1371 | .length = mem.readInt(u32, raw[0..4], .Little), | 1371 | .length = mem.readInt(u32, raw[0..4], .little), |
| 1372 | .number_of_relocations = mem.readInt(u16, raw[4..6], .Little), | 1372 | .number_of_relocations = mem.readInt(u16, raw[4..6], .little), |
| 1373 | .number_of_linenumbers = mem.readInt(u16, raw[6..8], .Little), | 1373 | .number_of_linenumbers = mem.readInt(u16, raw[6..8], .little), |
| 1374 | .checksum = mem.readInt(u32, raw[8..12], .Little), | 1374 | .checksum = mem.readInt(u32, raw[8..12], .little), |
| 1375 | .number = mem.readInt(u16, raw[12..14], .Little), | 1375 | .number = mem.readInt(u16, raw[12..14], .little), |
| 1376 | .selection = @as(ComdatSelection, @enumFromInt(raw[14])), | 1376 | .selection = @as(ComdatSelection, @enumFromInt(raw[14])), |
| 1377 | .unused = raw[15..18].*, | 1377 | .unused = raw[15..18].*, |
| 1378 | }; | 1378 | }; |
lib/std/compress/gzip.zig+5-5| ... | @@ -58,7 +58,7 @@ pub fn Decompress(comptime ReaderType: type) type { | ... | @@ -58,7 +58,7 @@ pub fn Decompress(comptime ReaderType: type) type { |
| 58 | const FLG = header[3]; | 58 | const FLG = header[3]; |
| 59 | // Modification time, as a Unix timestamp. | 59 | // Modification time, as a Unix timestamp. |
| 60 | // If zero there's no timestamp available. | 60 | // If zero there's no timestamp available. |
| 61 | const MTIME = mem.readInt(u32, header[4..8], .Little); | 61 | const MTIME = mem.readInt(u32, header[4..8], .little); |
| 62 | // Extra flags | 62 | // Extra flags |
| 63 | const XFL = header[8]; | 63 | const XFL = header[8]; |
| 64 | // Operating system where the compression took place | 64 | // Operating system where the compression took place |
| ... | @@ -66,7 +66,7 @@ pub fn Decompress(comptime ReaderType: type) type { | ... | @@ -66,7 +66,7 @@ pub fn Decompress(comptime ReaderType: type) type { |
| 66 | _ = XFL; | 66 | _ = XFL; |
| 67 | 67 | ||
| 68 | const extra = if (FLG & FEXTRA != 0) blk: { | 68 | const extra = if (FLG & FEXTRA != 0) blk: { |
| 69 | const len = try hashed_reader.readInt(u16, .Little); | 69 | const len = try hashed_reader.readInt(u16, .little); |
| 70 | const tmp_buf = try allocator.alloc(u8, len); | 70 | const tmp_buf = try allocator.alloc(u8, len); |
| 71 | errdefer allocator.free(tmp_buf); | 71 | errdefer allocator.free(tmp_buf); |
| 72 | 72 | ||
| ... | @@ -88,7 +88,7 @@ pub fn Decompress(comptime ReaderType: type) type { | ... | @@ -88,7 +88,7 @@ pub fn Decompress(comptime ReaderType: type) type { |
| 88 | errdefer if (comment) |p| allocator.free(p); | 88 | errdefer if (comment) |p| allocator.free(p); |
| 89 | 89 | ||
| 90 | if (FLG & FHCRC != 0) { | 90 | if (FLG & FHCRC != 0) { |
| 91 | const hash = try source.readInt(u16, .Little); | 91 | const hash = try source.readInt(u16, .little); |
| 92 | if (hash != @as(u16, @truncate(hasher.hasher.final()))) | 92 | if (hash != @as(u16, @truncate(hasher.hasher.final()))) |
| 93 | return error.WrongChecksum; | 93 | return error.WrongChecksum; |
| 94 | } | 94 | } |
| ... | @@ -133,12 +133,12 @@ pub fn Decompress(comptime ReaderType: type) type { | ... | @@ -133,12 +133,12 @@ pub fn Decompress(comptime ReaderType: type) type { |
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | // We've reached the end of stream, check if the checksum matches | 135 | // We've reached the end of stream, check if the checksum matches |
| 136 | const hash = try self.in_reader.readInt(u32, .Little); | 136 | const hash = try self.in_reader.readInt(u32, .little); |
| 137 | if (hash != self.hasher.final()) | 137 | if (hash != self.hasher.final()) |
| 138 | return error.WrongChecksum; | 138 | return error.WrongChecksum; |
| 139 | 139 | ||
| 140 | // The ISIZE field is the size of the uncompressed input modulo 2^32 | 140 | // The ISIZE field is the size of the uncompressed input modulo 2^32 |
| 141 | const input_size = try self.in_reader.readInt(u32, .Little); | 141 | const input_size = try self.in_reader.readInt(u32, .little); |
| 142 | if (self.read_amt & 0xffffffff != input_size) | 142 | if (self.read_amt & 0xffffffff != input_size) |
| 143 | return error.CorruptedData; | 143 | return error.CorruptedData; |
| 144 | 144 |
lib/std/compress/lzma/decode.zig+3-3| ... | @@ -58,12 +58,12 @@ pub const Params = struct { | ... | @@ -58,12 +58,12 @@ pub const Params = struct { |
| 58 | props /= 5; | 58 | props /= 5; |
| 59 | const pb = @as(u3, @intCast(props)); | 59 | const pb = @as(u3, @intCast(props)); |
| 60 | 60 | ||
| 61 | const dict_size_provided = try reader.readInt(u32, .Little); | 61 | const dict_size_provided = try reader.readInt(u32, .little); |
| 62 | const dict_size = @max(0x1000, dict_size_provided); | 62 | const dict_size = @max(0x1000, dict_size_provided); |
| 63 | 63 | ||
| 64 | const unpacked_size = switch (options.unpacked_size) { | 64 | const unpacked_size = switch (options.unpacked_size) { |
| 65 | .read_from_header => blk: { | 65 | .read_from_header => blk: { |
| 66 | const unpacked_size_provided = try reader.readInt(u64, .Little); | 66 | const unpacked_size_provided = try reader.readInt(u64, .little); |
| 67 | const marker_mandatory = unpacked_size_provided == 0xFFFF_FFFF_FFFF_FFFF; | 67 | const marker_mandatory = unpacked_size_provided == 0xFFFF_FFFF_FFFF_FFFF; |
| 68 | break :blk if (marker_mandatory) | 68 | break :blk if (marker_mandatory) |
| 69 | null | 69 | null |
| ... | @@ -71,7 +71,7 @@ pub const Params = struct { | ... | @@ -71,7 +71,7 @@ pub const Params = struct { |
| 71 | unpacked_size_provided; | 71 | unpacked_size_provided; |
| 72 | }, | 72 | }, |
| 73 | .read_header_but_use_provided => |x| blk: { | 73 | .read_header_but_use_provided => |x| blk: { |
| 74 | _ = try reader.readInt(u64, .Little); | 74 | _ = try reader.readInt(u64, .little); |
| 75 | break :blk x; | 75 | break :blk x; |
| 76 | }, | 76 | }, |
| 77 | .use_provided => |x| x, | 77 | .use_provided => |x| x, |
lib/std/compress/lzma/decode/rangecoder.zig+1-1| ... | @@ -12,7 +12,7 @@ pub const RangeDecoder = struct { | ... | @@ -12,7 +12,7 @@ pub const RangeDecoder = struct { |
| 12 | } | 12 | } |
| 13 | return RangeDecoder{ | 13 | return RangeDecoder{ |
| 14 | .range = 0xFFFF_FFFF, | 14 | .range = 0xFFFF_FFFF, |
| 15 | .code = try reader.readInt(u32, .Big), | 15 | .code = try reader.readInt(u32, .big), |
| 16 | }; | 16 | }; |
| 17 | } | 17 | } |
| 18 | 18 |
lib/std/compress/lzma2/decode.zig+3-3| ... | @@ -97,12 +97,12 @@ pub const Decoder = struct { | ... | @@ -97,12 +97,12 @@ pub const Decoder = struct { |
| 97 | const unpacked_size = blk: { | 97 | const unpacked_size = blk: { |
| 98 | var tmp: u64 = status & 0x1F; | 98 | var tmp: u64 = status & 0x1F; |
| 99 | tmp <<= 16; | 99 | tmp <<= 16; |
| 100 | tmp |= try reader.readInt(u16, .Big); | 100 | tmp |= try reader.readInt(u16, .big); |
| 101 | break :blk tmp + 1; | 101 | break :blk tmp + 1; |
| 102 | }; | 102 | }; |
| 103 | 103 | ||
| 104 | const packed_size = blk: { | 104 | const packed_size = blk: { |
| 105 | const tmp: u17 = try reader.readInt(u16, .Big); | 105 | const tmp: u17 = try reader.readInt(u16, .big); |
| 106 | break :blk tmp + 1; | 106 | break :blk tmp + 1; |
| 107 | }; | 107 | }; |
| 108 | 108 | ||
| ... | @@ -155,7 +155,7 @@ pub const Decoder = struct { | ... | @@ -155,7 +155,7 @@ pub const Decoder = struct { |
| 155 | accum: *LzAccumBuffer, | 155 | accum: *LzAccumBuffer, |
| 156 | reset_dict: bool, | 156 | reset_dict: bool, |
| 157 | ) !void { | 157 | ) !void { |
| 158 | const unpacked_size = @as(u17, try reader.readInt(u16, .Big)) + 1; | 158 | const unpacked_size = @as(u17, try reader.readInt(u16, .big)) + 1; |
| 159 | 159 | ||
| 160 | if (reset_dict) { | 160 | if (reset_dict) { |
| 161 | try accum.reset(writer); | 161 | try accum.reset(writer); |
lib/std/compress/xz.zig+5-5| ... | @@ -12,7 +12,7 @@ pub const Check = enum(u4) { | ... | @@ -12,7 +12,7 @@ pub const Check = enum(u4) { |
| 12 | }; | 12 | }; |
| 13 | 13 | ||
| 14 | fn readStreamFlags(reader: anytype, check: *Check) !void { | 14 | fn readStreamFlags(reader: anytype, check: *Check) !void { |
| 15 | var bit_reader = std.io.bitReader(.Little, reader); | 15 | var bit_reader = std.io.bitReader(.little, reader); |
| 16 | 16 | ||
| 17 | const reserved1 = try bit_reader.readBitsNoEof(u8, 8); | 17 | const reserved1 = try bit_reader.readBitsNoEof(u8, 8); |
| 18 | if (reserved1 != 0) | 18 | if (reserved1 != 0) |
| ... | @@ -52,7 +52,7 @@ pub fn Decompress(comptime ReaderType: type) type { | ... | @@ -52,7 +52,7 @@ pub fn Decompress(comptime ReaderType: type) type { |
| 52 | break :blk hasher.hasher.final(); | 52 | break :blk hasher.hasher.final(); |
| 53 | }; | 53 | }; |
| 54 | 54 | ||
| 55 | const hash_b = try source.readInt(u32, .Little); | 55 | const hash_b = try source.readInt(u32, .little); |
| 56 | if (hash_a != hash_b) | 56 | if (hash_a != hash_b) |
| 57 | return error.WrongChecksum; | 57 | return error.WrongChecksum; |
| 58 | 58 | ||
| ... | @@ -105,20 +105,20 @@ pub fn Decompress(comptime ReaderType: type) type { | ... | @@ -105,20 +105,20 @@ pub fn Decompress(comptime ReaderType: type) type { |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | const hash_a = hasher.hasher.final(); | 107 | const hash_a = hasher.hasher.final(); |
| 108 | const hash_b = try counting_reader.readInt(u32, .Little); | 108 | const hash_b = try counting_reader.readInt(u32, .little); |
| 109 | if (hash_a != hash_b) | 109 | if (hash_a != hash_b) |
| 110 | return error.WrongChecksum; | 110 | return error.WrongChecksum; |
| 111 | 111 | ||
| 112 | break :blk counter.bytes_read; | 112 | break :blk counter.bytes_read; |
| 113 | }; | 113 | }; |
| 114 | 114 | ||
| 115 | const hash_a = try self.in_reader.readInt(u32, .Little); | 115 | const hash_a = try self.in_reader.readInt(u32, .little); |
| 116 | 116 | ||
| 117 | const hash_b = blk: { | 117 | const hash_b = blk: { |
| 118 | var hasher = std.compress.hashedReader(self.in_reader, Crc32.init()); | 118 | var hasher = std.compress.hashedReader(self.in_reader, Crc32.init()); |
| 119 | const hashed_reader = hasher.reader(); | 119 | const hashed_reader = hasher.reader(); |
| 120 | 120 | ||
| 121 | const backward_size = (@as(u64, try hashed_reader.readInt(u32, .Little)) + 1) * 4; | 121 | const backward_size = (@as(u64, try hashed_reader.readInt(u32, .little)) + 1) * 4; |
| 122 | if (backward_size != index_size) | 122 | if (backward_size != index_size) |
| 123 | return error.CorruptInput; | 123 | return error.CorruptInput; |
| 124 | 124 |
lib/std/compress/xz/block.zig+3-3| ... | @@ -148,7 +148,7 @@ pub fn Decoder(comptime ReaderType: type) type { | ... | @@ -148,7 +148,7 @@ pub fn Decoder(comptime ReaderType: type) type { |
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | const hash_a = header_hasher.hasher.final(); | 150 | const hash_a = header_hasher.hasher.final(); |
| 151 | const hash_b = try header_reader.readInt(u32, .Little); | 151 | const hash_b = try header_reader.readInt(u32, .little); |
| 152 | if (hash_a != hash_b) | 152 | if (hash_a != hash_b) |
| 153 | return error.WrongChecksum; | 153 | return error.WrongChecksum; |
| 154 | } | 154 | } |
| ... | @@ -182,13 +182,13 @@ pub fn Decoder(comptime ReaderType: type) type { | ... | @@ -182,13 +182,13 @@ pub fn Decoder(comptime ReaderType: type) type { |
| 182 | .none => {}, | 182 | .none => {}, |
| 183 | .crc32 => { | 183 | .crc32 => { |
| 184 | const hash_a = Crc32.hash(unpacked_bytes); | 184 | const hash_a = Crc32.hash(unpacked_bytes); |
| 185 | const hash_b = try self.inner_reader.readInt(u32, .Little); | 185 | const hash_b = try self.inner_reader.readInt(u32, .little); |
| 186 | if (hash_a != hash_b) | 186 | if (hash_a != hash_b) |
| 187 | return error.WrongChecksum; | 187 | return error.WrongChecksum; |
| 188 | }, | 188 | }, |
| 189 | .crc64 => { | 189 | .crc64 => { |
| 190 | const hash_a = Crc64.hash(unpacked_bytes); | 190 | const hash_a = Crc64.hash(unpacked_bytes); |
| 191 | const hash_b = try self.inner_reader.readInt(u64, .Little); | 191 | const hash_b = try self.inner_reader.readInt(u64, .little); |
| 192 | if (hash_a != hash_b) | 192 | if (hash_a != hash_b) |
| 193 | return error.WrongChecksum; | 193 | return error.WrongChecksum; |
| 194 | }, | 194 | }, |
lib/std/compress/zlib.zig+4-4| ... | @@ -36,7 +36,7 @@ pub fn DecompressStream(comptime ReaderType: type) type { | ... | @@ -36,7 +36,7 @@ pub fn DecompressStream(comptime ReaderType: type) type { |
| 36 | 36 | ||
| 37 | fn init(allocator: mem.Allocator, source: ReaderType) !Self { | 37 | fn init(allocator: mem.Allocator, source: ReaderType) !Self { |
| 38 | // Zlib header format is specified in RFC1950 | 38 | // Zlib header format is specified in RFC1950 |
| 39 | const header_u16 = try source.readInt(u16, .Big); | 39 | const header_u16 = try source.readInt(u16, .big); |
| 40 | 40 | ||
| 41 | // verify the header checksum | 41 | // verify the header checksum |
| 42 | if (header_u16 % 31 != 0) | 42 | if (header_u16 % 31 != 0) |
| ... | @@ -81,7 +81,7 @@ pub fn DecompressStream(comptime ReaderType: type) type { | ... | @@ -81,7 +81,7 @@ pub fn DecompressStream(comptime ReaderType: type) type { |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | // We've reached the end of stream, check if the checksum matches | 83 | // We've reached the end of stream, check if the checksum matches |
| 84 | const hash = try self.in_reader.readInt(u32, .Big); | 84 | const hash = try self.in_reader.readInt(u32, .big); |
| 85 | if (hash != self.hasher.final()) | 85 | if (hash != self.hasher.final()) |
| 86 | return error.WrongChecksum; | 86 | return error.WrongChecksum; |
| 87 | 87 | ||
| ... | @@ -132,7 +132,7 @@ pub fn CompressStream(comptime WriterType: type) type { | ... | @@ -132,7 +132,7 @@ pub fn CompressStream(comptime WriterType: type) type { |
| 132 | }; | 132 | }; |
| 133 | header.checksum = @as(u5, @truncate(31 - @as(u16, @bitCast(header)) % 31)); | 133 | header.checksum = @as(u5, @truncate(31 - @as(u16, @bitCast(header)) % 31)); |
| 134 | 134 | ||
| 135 | try dest.writeInt(u16, @as(u16, @bitCast(header)), .Big); | 135 | try dest.writeInt(u16, @as(u16, @bitCast(header)), .big); |
| 136 | 136 | ||
| 137 | const compression_level: deflate.Compression = switch (options.level) { | 137 | const compression_level: deflate.Compression = switch (options.level) { |
| 138 | .no_compression => .no_compression, | 138 | .no_compression => .no_compression, |
| ... | @@ -171,7 +171,7 @@ pub fn CompressStream(comptime WriterType: type) type { | ... | @@ -171,7 +171,7 @@ pub fn CompressStream(comptime WriterType: type) type { |
| 171 | pub fn finish(self: *Self) !void { | 171 | pub fn finish(self: *Self) !void { |
| 172 | const hash = self.hasher.final(); | 172 | const hash = self.hasher.final(); |
| 173 | try self.deflator.close(); | 173 | try self.deflator.close(); |
| 174 | try self.in_writer.writeInt(u32, hash, .Big); | 174 | try self.in_writer.writeInt(u32, hash, .big); |
| 175 | } | 175 | } |
| 176 | }; | 176 | }; |
| 177 | } | 177 | } |
lib/std/compress/zstandard.zig+1-1| ... | @@ -201,7 +201,7 @@ pub fn DecompressStream( | ... | @@ -201,7 +201,7 @@ pub fn DecompressStream( |
| 201 | if (block_header.last_block) { | 201 | if (block_header.last_block) { |
| 202 | self.state = .LastBlock; | 202 | self.state = .LastBlock; |
| 203 | if (self.frame_context.has_checksum) { | 203 | if (self.frame_context.has_checksum) { |
| 204 | const checksum = source_reader.readInt(u32, .Little) catch | 204 | const checksum = source_reader.readInt(u32, .little) catch |
| 205 | return error.MalformedFrame; | 205 | return error.MalformedFrame; |
| 206 | if (comptime options.verify_checksum) { | 206 | if (comptime options.verify_checksum) { |
| 207 | if (self.frame_context.hasher_opt) |*hasher| { | 207 | if (self.frame_context.hasher_opt) |*hasher| { |
lib/std/compress/zstandard/decode/block.zig+3-3| ... | @@ -1029,9 +1029,9 @@ fn decodeStreams(size_format: u2, stream_data: []const u8) !LiteralsSection.Stre | ... | @@ -1029,9 +1029,9 @@ fn decodeStreams(size_format: u2, stream_data: []const u8) !LiteralsSection.Stre |
| 1029 | 1029 | ||
| 1030 | if (stream_data.len < 6) return error.MalformedLiteralsSection; | 1030 | if (stream_data.len < 6) return error.MalformedLiteralsSection; |
| 1031 | 1031 | ||
| 1032 | const stream_1_length: usize = std.mem.readInt(u16, stream_data[0..2], .Little); | 1032 | const stream_1_length: usize = std.mem.readInt(u16, stream_data[0..2], .little); |
| 1033 | const stream_2_length: usize = std.mem.readInt(u16, stream_data[2..4], .Little); | 1033 | const stream_2_length: usize = std.mem.readInt(u16, stream_data[2..4], .little); |
| 1034 | const stream_3_length: usize = std.mem.readInt(u16, stream_data[4..6], .Little); | 1034 | const stream_3_length: usize = std.mem.readInt(u16, stream_data[4..6], .little); |
| 1035 | 1035 | ||
| 1036 | const stream_1_start = 6; | 1036 | const stream_1_start = 6; |
| 1037 | const stream_2_start = stream_1_start + stream_1_length; | 1037 | const stream_2_start = stream_1_start + stream_1_length; |
lib/std/compress/zstandard/decompress.zig+14-14| ... | @@ -28,7 +28,7 @@ pub fn isSkippableMagic(magic: u32) bool { | ... | @@ -28,7 +28,7 @@ pub fn isSkippableMagic(magic: u32) bool { |
| 28 | /// skippable frames. | 28 | /// skippable frames. |
| 29 | /// - `error.EndOfStream` if `source` contains fewer than 4 bytes | 29 | /// - `error.EndOfStream` if `source` contains fewer than 4 bytes |
| 30 | pub fn decodeFrameType(source: anytype) error{ BadMagic, EndOfStream }!frame.Kind { | 30 | pub fn decodeFrameType(source: anytype) error{ BadMagic, EndOfStream }!frame.Kind { |
| 31 | const magic = try source.readInt(u32, .Little); | 31 | const magic = try source.readInt(u32, .little); |
| 32 | return frameType(magic); | 32 | return frameType(magic); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| ... | @@ -62,14 +62,14 @@ pub const HeaderError = error{ BadMagic, EndOfStream, ReservedBitSet }; | ... | @@ -62,14 +62,14 @@ pub const HeaderError = error{ BadMagic, EndOfStream, ReservedBitSet }; |
| 62 | /// - `error.ReservedBitSet` if the frame is a Zstandard frame and any of the | 62 | /// - `error.ReservedBitSet` if the frame is a Zstandard frame and any of the |
| 63 | /// reserved bits are set | 63 | /// reserved bits are set |
| 64 | pub fn decodeFrameHeader(source: anytype) (@TypeOf(source).Error || HeaderError)!FrameHeader { | 64 | pub fn decodeFrameHeader(source: anytype) (@TypeOf(source).Error || HeaderError)!FrameHeader { |
| 65 | const magic = try source.readInt(u32, .Little); | 65 | const magic = try source.readInt(u32, .little); |
| 66 | const frame_type = try frameType(magic); | 66 | const frame_type = try frameType(magic); |
| 67 | switch (frame_type) { | 67 | switch (frame_type) { |
| 68 | .zstandard => return FrameHeader{ .zstandard = try decodeZstandardHeader(source) }, | 68 | .zstandard => return FrameHeader{ .zstandard = try decodeZstandardHeader(source) }, |
| 69 | .skippable => return FrameHeader{ | 69 | .skippable => return FrameHeader{ |
| 70 | .skippable = .{ | 70 | .skippable = .{ |
| 71 | .magic_number = magic, | 71 | .magic_number = magic, |
| 72 | .frame_size = try source.readInt(u32, .Little), | 72 | .frame_size = try source.readInt(u32, .little), |
| 73 | }, | 73 | }, |
| 74 | }, | 74 | }, |
| 75 | } | 75 | } |
| ... | @@ -190,7 +190,7 @@ pub fn decodeFrame( | ... | @@ -190,7 +190,7 @@ pub fn decodeFrame( |
| 190 | switch (try decodeFrameType(fbs.reader())) { | 190 | switch (try decodeFrameType(fbs.reader())) { |
| 191 | .zstandard => return decodeZstandardFrame(dest, src, verify_checksum), | 191 | .zstandard => return decodeZstandardFrame(dest, src, verify_checksum), |
| 192 | .skippable => { | 192 | .skippable => { |
| 193 | const content_size = try fbs.reader().readInt(u32, .Little); | 193 | const content_size = try fbs.reader().readInt(u32, .little); |
| 194 | if (content_size > std.math.maxInt(usize) - 8) return error.SkippableSizeTooLarge; | 194 | if (content_size > std.math.maxInt(usize) - 8) return error.SkippableSizeTooLarge; |
| 195 | const read_count = @as(usize, content_size) + 8; | 195 | const read_count = @as(usize, content_size) + 8; |
| 196 | if (read_count > src.len) return error.SkippableSizeTooLarge; | 196 | if (read_count > src.len) return error.SkippableSizeTooLarge; |
| ... | @@ -235,7 +235,7 @@ pub fn decodeFrameArrayList( | ... | @@ -235,7 +235,7 @@ pub fn decodeFrameArrayList( |
| 235 | ) (error{ BadMagic, OutOfMemory, SkippableSizeTooLarge } || FrameContext.Error || FrameError)!usize { | 235 | ) (error{ BadMagic, OutOfMemory, SkippableSizeTooLarge } || FrameContext.Error || FrameError)!usize { |
| 236 | var fbs = std.io.fixedBufferStream(src); | 236 | var fbs = std.io.fixedBufferStream(src); |
| 237 | const reader = fbs.reader(); | 237 | const reader = fbs.reader(); |
| 238 | const magic = try reader.readInt(u32, .Little); | 238 | const magic = try reader.readInt(u32, .little); |
| 239 | switch (try frameType(magic)) { | 239 | switch (try frameType(magic)) { |
| 240 | .zstandard => return decodeZstandardFrameArrayList( | 240 | .zstandard => return decodeZstandardFrameArrayList( |
| 241 | allocator, | 241 | allocator, |
| ... | @@ -245,7 +245,7 @@ pub fn decodeFrameArrayList( | ... | @@ -245,7 +245,7 @@ pub fn decodeFrameArrayList( |
| 245 | window_size_max, | 245 | window_size_max, |
| 246 | ), | 246 | ), |
| 247 | .skippable => { | 247 | .skippable => { |
| 248 | const content_size = try fbs.reader().readInt(u32, .Little); | 248 | const content_size = try fbs.reader().readInt(u32, .little); |
| 249 | if (content_size > std.math.maxInt(usize) - 8) return error.SkippableSizeTooLarge; | 249 | if (content_size > std.math.maxInt(usize) - 8) return error.SkippableSizeTooLarge; |
| 250 | const read_count = @as(usize, content_size) + 8; | 250 | const read_count = @as(usize, content_size) + 8; |
| 251 | if (read_count > src.len) return error.SkippableSizeTooLarge; | 251 | if (read_count > src.len) return error.SkippableSizeTooLarge; |
| ... | @@ -299,7 +299,7 @@ pub fn decodeZstandardFrame( | ... | @@ -299,7 +299,7 @@ pub fn decodeZstandardFrame( |
| 299 | WindowSizeUnknown, | 299 | WindowSizeUnknown, |
| 300 | DictionaryIdFlagUnsupported, | 300 | DictionaryIdFlagUnsupported, |
| 301 | } || FrameError)!ReadWriteCount { | 301 | } || FrameError)!ReadWriteCount { |
| 302 | assert(std.mem.readInt(u32, src[0..4], .Little) == frame.Zstandard.magic_number); | 302 | assert(std.mem.readInt(u32, src[0..4], .little) == frame.Zstandard.magic_number); |
| 303 | var consumed_count: usize = 4; | 303 | var consumed_count: usize = 4; |
| 304 | 304 | ||
| 305 | var frame_context = context: { | 305 | var frame_context = context: { |
| ... | @@ -351,7 +351,7 @@ pub fn decodeZStandardFrameBlocks( | ... | @@ -351,7 +351,7 @@ pub fn decodeZStandardFrameBlocks( |
| 351 | if (written_count != content_size) return error.BadContentSize; | 351 | if (written_count != content_size) return error.BadContentSize; |
| 352 | if (frame_context.has_checksum) { | 352 | if (frame_context.has_checksum) { |
| 353 | if (src.len < consumed_count + 4) return error.EndOfStream; | 353 | if (src.len < consumed_count + 4) return error.EndOfStream; |
| 354 | const checksum = std.mem.readInt(u32, src[consumed_count..][0..4], .Little); | 354 | const checksum = std.mem.readInt(u32, src[consumed_count..][0..4], .little); |
| 355 | consumed_count += 4; | 355 | consumed_count += 4; |
| 356 | if (frame_context.hasher_opt) |*hasher| { | 356 | if (frame_context.hasher_opt) |*hasher| { |
| 357 | if (checksum != computeChecksum(hasher)) return error.ChecksumFailure; | 357 | if (checksum != computeChecksum(hasher)) return error.ChecksumFailure; |
| ... | @@ -442,7 +442,7 @@ pub fn decodeZstandardFrameArrayList( | ... | @@ -442,7 +442,7 @@ pub fn decodeZstandardFrameArrayList( |
| 442 | verify_checksum: bool, | 442 | verify_checksum: bool, |
| 443 | window_size_max: usize, | 443 | window_size_max: usize, |
| 444 | ) (error{OutOfMemory} || FrameContext.Error || FrameError)!usize { | 444 | ) (error{OutOfMemory} || FrameContext.Error || FrameError)!usize { |
| 445 | assert(std.mem.readInt(u32, src[0..4], .Little) == frame.Zstandard.magic_number); | 445 | assert(std.mem.readInt(u32, src[0..4], .little) == frame.Zstandard.magic_number); |
| 446 | var consumed_count: usize = 4; | 446 | var consumed_count: usize = 4; |
| 447 | 447 | ||
| 448 | var frame_context = context: { | 448 | var frame_context = context: { |
| ... | @@ -517,7 +517,7 @@ pub fn decodeZstandardFrameBlocksArrayList( | ... | @@ -517,7 +517,7 @@ pub fn decodeZstandardFrameBlocksArrayList( |
| 517 | 517 | ||
| 518 | if (frame_context.has_checksum) { | 518 | if (frame_context.has_checksum) { |
| 519 | if (src.len < consumed_count + 4) return error.EndOfStream; | 519 | if (src.len < consumed_count + 4) return error.EndOfStream; |
| 520 | const checksum = std.mem.readInt(u32, src[consumed_count..][0..4], .Little); | 520 | const checksum = std.mem.readInt(u32, src[consumed_count..][0..4], .little); |
| 521 | consumed_count += 4; | 521 | consumed_count += 4; |
| 522 | if (frame_context.hasher_opt) |*hasher| { | 522 | if (frame_context.hasher_opt) |*hasher| { |
| 523 | if (checksum != computeChecksum(hasher)) return error.ChecksumFailure; | 523 | if (checksum != computeChecksum(hasher)) return error.ChecksumFailure; |
| ... | @@ -566,9 +566,9 @@ fn decodeFrameBlocksInner( | ... | @@ -566,9 +566,9 @@ fn decodeFrameBlocksInner( |
| 566 | /// Decode the header of a skippable frame. The first four bytes of `src` must | 566 | /// Decode the header of a skippable frame. The first four bytes of `src` must |
| 567 | /// be a valid magic number for a skippable frame. | 567 | /// be a valid magic number for a skippable frame. |
| 568 | pub fn decodeSkippableHeader(src: *const [8]u8) SkippableHeader { | 568 | pub fn decodeSkippableHeader(src: *const [8]u8) SkippableHeader { |
| 569 | const magic = std.mem.readInt(u32, src[0..4], .Little); | 569 | const magic = std.mem.readInt(u32, src[0..4], .little); |
| 570 | assert(isSkippableMagic(magic)); | 570 | assert(isSkippableMagic(magic)); |
| 571 | const frame_size = std.mem.readInt(u32, src[4..8], .Little); | 571 | const frame_size = std.mem.readInt(u32, src[4..8], .little); |
| 572 | return .{ | 572 | return .{ |
| 573 | .magic_number = magic, | 573 | .magic_number = magic, |
| 574 | .frame_size = frame_size, | 574 | .frame_size = frame_size, |
| ... | @@ -609,13 +609,13 @@ pub fn decodeZstandardHeader( | ... | @@ -609,13 +609,13 @@ pub fn decodeZstandardHeader( |
| 609 | if (descriptor.dictionary_id_flag > 0) { | 609 | if (descriptor.dictionary_id_flag > 0) { |
| 610 | // if flag is 3 then field_size = 4, else field_size = flag | 610 | // if flag is 3 then field_size = 4, else field_size = flag |
| 611 | const field_size = (@as(u4, 1) << descriptor.dictionary_id_flag) >> 1; | 611 | const field_size = (@as(u4, 1) << descriptor.dictionary_id_flag) >> 1; |
| 612 | dictionary_id = try source.readVarInt(u32, .Little, field_size); | 612 | dictionary_id = try source.readVarInt(u32, .little, field_size); |
| 613 | } | 613 | } |
| 614 | 614 | ||
| 615 | var content_size: ?u64 = null; | 615 | var content_size: ?u64 = null; |
| 616 | if (descriptor.single_segment_flag or descriptor.content_size_flag > 0) { | 616 | if (descriptor.single_segment_flag or descriptor.content_size_flag > 0) { |
| 617 | const field_size = @as(u4, 1) << descriptor.content_size_flag; | 617 | const field_size = @as(u4, 1) << descriptor.content_size_flag; |
| 618 | content_size = try source.readVarInt(u64, .Little, field_size); | 618 | content_size = try source.readVarInt(u64, .little, field_size); |
| 619 | if (field_size == 2) content_size.? += 256; | 619 | if (field_size == 2) content_size.? += 256; |
| 620 | } | 620 | } |
| 621 | 621 |
lib/std/compress/zstandard/readers.zig+4-4| ... | @@ -31,11 +31,11 @@ pub const ReversedByteReader = struct { | ... | @@ -31,11 +31,11 @@ pub const ReversedByteReader = struct { |
| 31 | /// FSE compressed data. | 31 | /// FSE compressed data. |
| 32 | pub const ReverseBitReader = struct { | 32 | pub const ReverseBitReader = struct { |
| 33 | byte_reader: ReversedByteReader, | 33 | byte_reader: ReversedByteReader, |
| 34 | bit_reader: std.io.BitReader(.Big, ReversedByteReader.Reader), | 34 | bit_reader: std.io.BitReader(.big, ReversedByteReader.Reader), |
| 35 | 35 | ||
| 36 | pub fn init(self: *ReverseBitReader, bytes: []const u8) error{BitStreamHasNoStartBit}!void { | 36 | pub fn init(self: *ReverseBitReader, bytes: []const u8) error{BitStreamHasNoStartBit}!void { |
| 37 | self.byte_reader = ReversedByteReader.init(bytes); | 37 | self.byte_reader = ReversedByteReader.init(bytes); |
| 38 | self.bit_reader = std.io.bitReader(.Big, self.byte_reader.reader()); | 38 | self.bit_reader = std.io.bitReader(.big, self.byte_reader.reader()); |
| 39 | if (bytes.len == 0) return; | 39 | if (bytes.len == 0) return; |
| 40 | var i: usize = 0; | 40 | var i: usize = 0; |
| 41 | while (i < 8 and 0 == self.readBitsNoEof(u1, 1) catch unreachable) : (i += 1) {} | 41 | while (i < 8 and 0 == self.readBitsNoEof(u1, 1) catch unreachable) : (i += 1) {} |
| ... | @@ -61,7 +61,7 @@ pub const ReverseBitReader = struct { | ... | @@ -61,7 +61,7 @@ pub const ReverseBitReader = struct { |
| 61 | 61 | ||
| 62 | pub fn BitReader(comptime Reader: type) type { | 62 | pub fn BitReader(comptime Reader: type) type { |
| 63 | return struct { | 63 | return struct { |
| 64 | underlying: std.io.BitReader(.Little, Reader), | 64 | underlying: std.io.BitReader(.little, Reader), |
| 65 | 65 | ||
| 66 | pub fn readBitsNoEof(self: *@This(), comptime U: type, num_bits: usize) !U { | 66 | pub fn readBitsNoEof(self: *@This(), comptime U: type, num_bits: usize) !U { |
| 67 | return self.underlying.readBitsNoEof(U, num_bits); | 67 | return self.underlying.readBitsNoEof(U, num_bits); |
| ... | @@ -78,5 +78,5 @@ pub fn BitReader(comptime Reader: type) type { | ... | @@ -78,5 +78,5 @@ pub fn BitReader(comptime Reader: type) type { |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | pub fn bitReader(reader: anytype) BitReader(@TypeOf(reader)) { | 80 | pub fn bitReader(reader: anytype) BitReader(@TypeOf(reader)) { |
| 81 | return .{ .underlying = std.io.bitReader(.Little, reader) }; | 81 | return .{ .underlying = std.io.bitReader(.little, reader) }; |
| 82 | } | 82 | } |
lib/std/crypto/25519/field.zig+9-9| ... | @@ -71,11 +71,11 @@ pub const Fe = struct { | ... | @@ -71,11 +71,11 @@ pub const Fe = struct { |
| 71 | /// Unpack a field element | 71 | /// Unpack a field element |
| 72 | pub fn fromBytes(s: [32]u8) Fe { | 72 | pub fn fromBytes(s: [32]u8) Fe { |
| 73 | var fe: Fe = undefined; | 73 | var fe: Fe = undefined; |
| 74 | fe.limbs[0] = std.mem.readInt(u64, s[0..8], .Little) & MASK51; | 74 | fe.limbs[0] = std.mem.readInt(u64, s[0..8], .little) & MASK51; |
| 75 | fe.limbs[1] = (std.mem.readInt(u64, s[6..14], .Little) >> 3) & MASK51; | 75 | fe.limbs[1] = (std.mem.readInt(u64, s[6..14], .little) >> 3) & MASK51; |
| 76 | fe.limbs[2] = (std.mem.readInt(u64, s[12..20], .Little) >> 6) & MASK51; | 76 | fe.limbs[2] = (std.mem.readInt(u64, s[12..20], .little) >> 6) & MASK51; |
| 77 | fe.limbs[3] = (std.mem.readInt(u64, s[19..27], .Little) >> 1) & MASK51; | 77 | fe.limbs[3] = (std.mem.readInt(u64, s[19..27], .little) >> 1) & MASK51; |
| 78 | fe.limbs[4] = (std.mem.readInt(u64, s[24..32], .Little) >> 12) & MASK51; | 78 | fe.limbs[4] = (std.mem.readInt(u64, s[24..32], .little) >> 12) & MASK51; |
| 79 | 79 | ||
| 80 | return fe; | 80 | return fe; |
| 81 | } | 81 | } |
| ... | @@ -85,10 +85,10 @@ pub const Fe = struct { | ... | @@ -85,10 +85,10 @@ pub const Fe = struct { |
| 85 | var reduced = fe; | 85 | var reduced = fe; |
| 86 | reduced.reduce(); | 86 | reduced.reduce(); |
| 87 | var s: [32]u8 = undefined; | 87 | var s: [32]u8 = undefined; |
| 88 | std.mem.writeInt(u64, s[0..8], reduced.limbs[0] | (reduced.limbs[1] << 51), .Little); | 88 | std.mem.writeInt(u64, s[0..8], reduced.limbs[0] | (reduced.limbs[1] << 51), .little); |
| 89 | std.mem.writeInt(u64, s[8..16], (reduced.limbs[1] >> 13) | (reduced.limbs[2] << 38), .Little); | 89 | std.mem.writeInt(u64, s[8..16], (reduced.limbs[1] >> 13) | (reduced.limbs[2] << 38), .little); |
| 90 | std.mem.writeInt(u64, s[16..24], (reduced.limbs[2] >> 26) | (reduced.limbs[3] << 25), .Little); | 90 | std.mem.writeInt(u64, s[16..24], (reduced.limbs[2] >> 26) | (reduced.limbs[3] << 25), .little); |
| 91 | std.mem.writeInt(u64, s[24..32], (reduced.limbs[3] >> 39) | (reduced.limbs[4] << 12), .Little); | 91 | std.mem.writeInt(u64, s[24..32], (reduced.limbs[3] >> 39) | (reduced.limbs[4] << 12), .little); |
| 92 | 92 | ||
| 93 | return s; | 93 | return s; |
| 94 | } | 94 | } |
lib/std/crypto/25519/scalar.zig+6-6| ... | @@ -15,7 +15,7 @@ pub const zero = [_]u8{0} ** 32; | ... | @@ -15,7 +15,7 @@ pub const zero = [_]u8{0} ** 32; |
| 15 | 15 | ||
| 16 | const field_order_s = s: { | 16 | const field_order_s = s: { |
| 17 | var s: [32]u8 = undefined; | 17 | var s: [32]u8 = undefined; |
| 18 | mem.writeInt(u256, &s, field_order, .Little); | 18 | mem.writeInt(u256, &s, field_order, .little); |
| 19 | break :s s; | 19 | break :s s; |
| 20 | }; | 20 | }; |
| 21 | 21 | ||
| ... | @@ -127,9 +127,9 @@ pub const Scalar = struct { | ... | @@ -127,9 +127,9 @@ pub const Scalar = struct { |
| 127 | var bytes: CompressedScalar = undefined; | 127 | var bytes: CompressedScalar = undefined; |
| 128 | var i: usize = 0; | 128 | var i: usize = 0; |
| 129 | while (i < 4) : (i += 1) { | 129 | while (i < 4) : (i += 1) { |
| 130 | mem.writeInt(u64, bytes[i * 7 ..][0..8], expanded.limbs[i], .Little); | 130 | mem.writeInt(u64, bytes[i * 7 ..][0..8], expanded.limbs[i], .little); |
| 131 | } | 131 | } |
| 132 | mem.writeInt(u32, bytes[i * 7 ..][0..4], @intCast(expanded.limbs[i]), .Little); | 132 | mem.writeInt(u32, bytes[i * 7 ..][0..4], @intCast(expanded.limbs[i]), .little); |
| 133 | return bytes; | 133 | return bytes; |
| 134 | } | 134 | } |
| 135 | 135 | ||
| ... | @@ -580,7 +580,7 @@ const ScalarDouble = struct { | ... | @@ -580,7 +580,7 @@ const ScalarDouble = struct { |
| 580 | var limbs: Limbs = undefined; | 580 | var limbs: Limbs = undefined; |
| 581 | var i: usize = 0; | 581 | var i: usize = 0; |
| 582 | while (i < 9) : (i += 1) { | 582 | while (i < 9) : (i += 1) { |
| 583 | limbs[i] = mem.readInt(u64, bytes[i * 7 ..][0..8], .Little) & 0xffffffffffffff; | 583 | limbs[i] = mem.readInt(u64, bytes[i * 7 ..][0..8], .little) & 0xffffffffffffff; |
| 584 | } | 584 | } |
| 585 | limbs[i] = @as(u64, bytes[i * 7]); | 585 | limbs[i] = @as(u64, bytes[i * 7]); |
| 586 | return ScalarDouble{ .limbs = limbs }; | 586 | return ScalarDouble{ .limbs = limbs }; |
| ... | @@ -590,9 +590,9 @@ const ScalarDouble = struct { | ... | @@ -590,9 +590,9 @@ const ScalarDouble = struct { |
| 590 | var limbs: Limbs = undefined; | 590 | var limbs: Limbs = undefined; |
| 591 | var i: usize = 0; | 591 | var i: usize = 0; |
| 592 | while (i < 4) : (i += 1) { | 592 | while (i < 4) : (i += 1) { |
| 593 | limbs[i] = mem.readInt(u64, bytes[i * 7 ..][0..8], .Little) & 0xffffffffffffff; | 593 | limbs[i] = mem.readInt(u64, bytes[i * 7 ..][0..8], .little) & 0xffffffffffffff; |
| 594 | } | 594 | } |
| 595 | limbs[i] = @as(u64, mem.readInt(u32, bytes[i * 7 ..][0..4], .Little)); | 595 | limbs[i] = @as(u64, mem.readInt(u32, bytes[i * 7 ..][0..4], .little)); |
| 596 | @memset(limbs[5..], 0); | 596 | @memset(limbs[5..], 0); |
| 597 | return ScalarDouble{ .limbs = limbs }; | 597 | return ScalarDouble{ .limbs = limbs }; |
| 598 | } | 598 | } |
lib/std/crypto/Certificate.zig+4-4| ... | @@ -1075,7 +1075,7 @@ pub const rsa = struct { | ... | @@ -1075,7 +1075,7 @@ pub const rsa = struct { |
| 1075 | // Reject modulus below 512 bits. | 1075 | // Reject modulus below 512 bits. |
| 1076 | // 512-bit RSA was factored in 1999, so this limit barely means anything, | 1076 | // 512-bit RSA was factored in 1999, so this limit barely means anything, |
| 1077 | // but establish some limit now to ratchet in what we can. | 1077 | // but establish some limit now to ratchet in what we can. |
| 1078 | const _n = Modulus.fromBytes(modulus_bytes, .Big) catch return error.CertificatePublicKeyInvalid; | 1078 | const _n = Modulus.fromBytes(modulus_bytes, .big) catch return error.CertificatePublicKeyInvalid; |
| 1079 | if (_n.bits() < 512) return error.CertificatePublicKeyInvalid; | 1079 | if (_n.bits() < 512) return error.CertificatePublicKeyInvalid; |
| 1080 | 1080 | ||
| 1081 | // Exponent must be odd and greater than 2. | 1081 | // Exponent must be odd and greater than 2. |
| ... | @@ -1085,7 +1085,7 @@ pub const rsa = struct { | ... | @@ -1085,7 +1085,7 @@ pub const rsa = struct { |
| 1085 | // Windows commonly does. | 1085 | // Windows commonly does. |
| 1086 | // [1] https://learn.microsoft.com/en-us/windows/win32/api/wincrypt/ns-wincrypt-rsapubkey | 1086 | // [1] https://learn.microsoft.com/en-us/windows/win32/api/wincrypt/ns-wincrypt-rsapubkey |
| 1087 | if (pub_bytes.len > 4) return error.CertificatePublicKeyInvalid; | 1087 | if (pub_bytes.len > 4) return error.CertificatePublicKeyInvalid; |
| 1088 | const _e = Fe.fromBytes(_n, pub_bytes, .Big) catch return error.CertificatePublicKeyInvalid; | 1088 | const _e = Fe.fromBytes(_n, pub_bytes, .big) catch return error.CertificatePublicKeyInvalid; |
| 1089 | if (!_e.isOdd()) return error.CertificatePublicKeyInvalid; | 1089 | if (!_e.isOdd()) return error.CertificatePublicKeyInvalid; |
| 1090 | const e_v = _e.toPrimitive(u32) catch return error.CertificatePublicKeyInvalid; | 1090 | const e_v = _e.toPrimitive(u32) catch return error.CertificatePublicKeyInvalid; |
| 1091 | if (e_v < 2) return error.CertificatePublicKeyInvalid; | 1091 | if (e_v < 2) return error.CertificatePublicKeyInvalid; |
| ... | @@ -1116,10 +1116,10 @@ pub const rsa = struct { | ... | @@ -1116,10 +1116,10 @@ pub const rsa = struct { |
| 1116 | }; | 1116 | }; |
| 1117 | 1117 | ||
| 1118 | fn encrypt(comptime modulus_len: usize, msg: [modulus_len]u8, public_key: PublicKey) ![modulus_len]u8 { | 1118 | fn encrypt(comptime modulus_len: usize, msg: [modulus_len]u8, public_key: PublicKey) ![modulus_len]u8 { |
| 1119 | const m = Fe.fromBytes(public_key.n, &msg, .Big) catch return error.MessageTooLong; | 1119 | const m = Fe.fromBytes(public_key.n, &msg, .big) catch return error.MessageTooLong; |
| 1120 | const e = public_key.n.powPublic(m, public_key.e) catch unreachable; | 1120 | const e = public_key.n.powPublic(m, public_key.e) catch unreachable; |
| 1121 | var res: [modulus_len]u8 = undefined; | 1121 | var res: [modulus_len]u8 = undefined; |
| 1122 | e.toBytes(&res, .Big) catch unreachable; | 1122 | e.toBytes(&res, .big) catch unreachable; |
| 1123 | return res; | 1123 | return res; |
| 1124 | } | 1124 | } |
| 1125 | }; | 1125 | }; |
lib/std/crypto/Certificate/Bundle/macos.zig+2-2| ... | @@ -32,7 +32,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void { | ... | @@ -32,7 +32,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void { |
| 32 | 32 | ||
| 33 | var table_idx: u32 = 0; | 33 | var table_idx: u32 = 0; |
| 34 | while (table_idx < table_list.len) : (table_idx += 1) { | 34 | while (table_idx < table_list.len) : (table_idx += 1) { |
| 35 | table_list[table_idx] = try reader.readInt(u32, .Big); | 35 | table_list[table_idx] = try reader.readInt(u32, .big); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | const now_sec = std.time.timestamp(); | 38 | const now_sec = std.time.timestamp(); |
| ... | @@ -51,7 +51,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void { | ... | @@ -51,7 +51,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void { |
| 51 | 51 | ||
| 52 | var record_idx: u32 = 0; | 52 | var record_idx: u32 = 0; |
| 53 | while (record_idx < record_list.len) : (record_idx += 1) { | 53 | while (record_idx < record_list.len) : (record_idx += 1) { |
| 54 | record_list[record_idx] = try reader.readInt(u32, .Big); | 54 | record_list[record_idx] = try reader.readInt(u32, .big); |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | for (record_list) |record_offset| { | 57 | for (record_list) |record_offset| { |
lib/std/crypto/aegis.zig+4-4| ... | @@ -106,8 +106,8 @@ const State128L = struct { | ... | @@ -106,8 +106,8 @@ const State128L = struct { |
| 106 | fn mac(state: *State128L, comptime tag_bits: u9, adlen: usize, mlen: usize) [tag_bits / 8]u8 { | 106 | fn mac(state: *State128L, comptime tag_bits: u9, adlen: usize, mlen: usize) [tag_bits / 8]u8 { |
| 107 | const blocks = &state.blocks; | 107 | const blocks = &state.blocks; |
| 108 | var sizes: [16]u8 = undefined; | 108 | var sizes: [16]u8 = undefined; |
| 109 | mem.writeInt(u64, sizes[0..8], adlen * 8, .Little); | 109 | mem.writeInt(u64, sizes[0..8], adlen * 8, .little); |
| 110 | mem.writeInt(u64, sizes[8..16], mlen * 8, .Little); | 110 | mem.writeInt(u64, sizes[8..16], mlen * 8, .little); |
| 111 | const tmp = AesBlock.fromBytes(&sizes).xorBlocks(blocks[2]); | 111 | const tmp = AesBlock.fromBytes(&sizes).xorBlocks(blocks[2]); |
| 112 | var i: usize = 0; | 112 | var i: usize = 0; |
| 113 | while (i < 7) : (i += 1) { | 113 | while (i < 7) : (i += 1) { |
| ... | @@ -284,8 +284,8 @@ const State256 = struct { | ... | @@ -284,8 +284,8 @@ const State256 = struct { |
| 284 | fn mac(state: *State256, comptime tag_bits: u9, adlen: usize, mlen: usize) [tag_bits / 8]u8 { | 284 | fn mac(state: *State256, comptime tag_bits: u9, adlen: usize, mlen: usize) [tag_bits / 8]u8 { |
| 285 | const blocks = &state.blocks; | 285 | const blocks = &state.blocks; |
| 286 | var sizes: [16]u8 = undefined; | 286 | var sizes: [16]u8 = undefined; |
| 287 | mem.writeInt(u64, sizes[0..8], adlen * 8, .Little); | 287 | mem.writeInt(u64, sizes[0..8], adlen * 8, .little); |
| 288 | mem.writeInt(u64, sizes[8..16], mlen * 8, .Little); | 288 | mem.writeInt(u64, sizes[8..16], mlen * 8, .little); |
| 289 | const tmp = AesBlock.fromBytes(&sizes).xorBlocks(blocks[3]); | 289 | const tmp = AesBlock.fromBytes(&sizes).xorBlocks(blocks[3]); |
| 290 | var i: usize = 0; | 290 | var i: usize = 0; |
| 291 | while (i < 7) : (i += 1) { | 291 | while (i < 7) : (i += 1) { |
lib/std/crypto/aes.zig+1-1| ... | @@ -50,7 +50,7 @@ test "ctr" { | ... | @@ -50,7 +50,7 @@ test "ctr" { |
| 50 | 50 | ||
| 51 | var out: [exp_out.len]u8 = undefined; | 51 | var out: [exp_out.len]u8 = undefined; |
| 52 | var ctx = Aes128.initEnc(key); | 52 | var ctx = Aes128.initEnc(key); |
| 53 | ctr(AesEncryptCtx(Aes128), ctx, out[0..], in[0..], iv, std.builtin.Endian.Big); | 53 | ctr(AesEncryptCtx(Aes128), ctx, out[0..], in[0..], iv, std.builtin.Endian.big); |
| 54 | try testing.expectEqualSlices(u8, exp_out[0..], out[0..]); | 54 | try testing.expectEqualSlices(u8, exp_out[0..], out[0..]); |
| 55 | } | 55 | } |
| 56 | 56 |
lib/std/crypto/aes/soft.zig+18-18| ... | @@ -15,20 +15,20 @@ pub const Block = struct { | ... | @@ -15,20 +15,20 @@ pub const Block = struct { |
| 15 | 15 | ||
| 16 | /// Convert a byte sequence into an internal representation. | 16 | /// Convert a byte sequence into an internal representation. |
| 17 | pub inline fn fromBytes(bytes: *const [16]u8) Block { | 17 | pub inline fn fromBytes(bytes: *const [16]u8) Block { |
| 18 | const s0 = mem.readInt(u32, bytes[0..4], .Little); | 18 | const s0 = mem.readInt(u32, bytes[0..4], .little); |
| 19 | const s1 = mem.readInt(u32, bytes[4..8], .Little); | 19 | const s1 = mem.readInt(u32, bytes[4..8], .little); |
| 20 | const s2 = mem.readInt(u32, bytes[8..12], .Little); | 20 | const s2 = mem.readInt(u32, bytes[8..12], .little); |
| 21 | const s3 = mem.readInt(u32, bytes[12..16], .Little); | 21 | const s3 = mem.readInt(u32, bytes[12..16], .little); |
| 22 | return Block{ .repr = BlockVec{ s0, s1, s2, s3 } }; | 22 | return Block{ .repr = BlockVec{ s0, s1, s2, s3 } }; |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | /// Convert the internal representation of a block into a byte sequence. | 25 | /// Convert the internal representation of a block into a byte sequence. |
| 26 | pub inline fn toBytes(block: Block) [16]u8 { | 26 | pub inline fn toBytes(block: Block) [16]u8 { |
| 27 | var bytes: [16]u8 = undefined; | 27 | var bytes: [16]u8 = undefined; |
| 28 | mem.writeInt(u32, bytes[0..4], block.repr[0], .Little); | 28 | mem.writeInt(u32, bytes[0..4], block.repr[0], .little); |
| 29 | mem.writeInt(u32, bytes[4..8], block.repr[1], .Little); | 29 | mem.writeInt(u32, bytes[4..8], block.repr[1], .little); |
| 30 | mem.writeInt(u32, bytes[8..12], block.repr[2], .Little); | 30 | mem.writeInt(u32, bytes[8..12], block.repr[2], .little); |
| 31 | mem.writeInt(u32, bytes[12..16], block.repr[3], .Little); | 31 | mem.writeInt(u32, bytes[12..16], block.repr[3], .little); |
| 32 | return bytes; | 32 | return bytes; |
| 33 | } | 33 | } |
| 34 | 34 | ||
| ... | @@ -123,13 +123,13 @@ pub const Block = struct { | ... | @@ -123,13 +123,13 @@ pub const Block = struct { |
| 123 | // Last round uses s-box directly and XORs to produce output. | 123 | // Last round uses s-box directly and XORs to produce output. |
| 124 | var x: [4]u8 = undefined; | 124 | var x: [4]u8 = undefined; |
| 125 | x = sbox_lookup(&sbox_encrypt, @as(u8, @truncate(s0)), @as(u8, @truncate(s1 >> 8)), @as(u8, @truncate(s2 >> 16)), @as(u8, @truncate(s3 >> 24))); | 125 | x = sbox_lookup(&sbox_encrypt, @as(u8, @truncate(s0)), @as(u8, @truncate(s1 >> 8)), @as(u8, @truncate(s2 >> 16)), @as(u8, @truncate(s3 >> 24))); |
| 126 | var t0 = mem.readInt(u32, &x, .Little); | 126 | var t0 = mem.readInt(u32, &x, .little); |
| 127 | x = sbox_lookup(&sbox_encrypt, @as(u8, @truncate(s1)), @as(u8, @truncate(s2 >> 8)), @as(u8, @truncate(s3 >> 16)), @as(u8, @truncate(s0 >> 24))); | 127 | x = sbox_lookup(&sbox_encrypt, @as(u8, @truncate(s1)), @as(u8, @truncate(s2 >> 8)), @as(u8, @truncate(s3 >> 16)), @as(u8, @truncate(s0 >> 24))); |
| 128 | var t1 = mem.readInt(u32, &x, .Little); | 128 | var t1 = mem.readInt(u32, &x, .little); |
| 129 | x = sbox_lookup(&sbox_encrypt, @as(u8, @truncate(s2)), @as(u8, @truncate(s3 >> 8)), @as(u8, @truncate(s0 >> 16)), @as(u8, @truncate(s1 >> 24))); | 129 | x = sbox_lookup(&sbox_encrypt, @as(u8, @truncate(s2)), @as(u8, @truncate(s3 >> 8)), @as(u8, @truncate(s0 >> 16)), @as(u8, @truncate(s1 >> 24))); |
| 130 | var t2 = mem.readInt(u32, &x, .Little); | 130 | var t2 = mem.readInt(u32, &x, .little); |
| 131 | x = sbox_lookup(&sbox_encrypt, @as(u8, @truncate(s3)), @as(u8, @truncate(s0 >> 8)), @as(u8, @truncate(s1 >> 16)), @as(u8, @truncate(s2 >> 24))); | 131 | x = sbox_lookup(&sbox_encrypt, @as(u8, @truncate(s3)), @as(u8, @truncate(s0 >> 8)), @as(u8, @truncate(s1 >> 16)), @as(u8, @truncate(s2 >> 24))); |
| 132 | var t3 = mem.readInt(u32, &x, .Little); | 132 | var t3 = mem.readInt(u32, &x, .little); |
| 133 | 133 | ||
| 134 | t0 ^= round_key.repr[0]; | 134 | t0 ^= round_key.repr[0]; |
| 135 | t1 ^= round_key.repr[1]; | 135 | t1 ^= round_key.repr[1]; |
| ... | @@ -219,13 +219,13 @@ pub const Block = struct { | ... | @@ -219,13 +219,13 @@ pub const Block = struct { |
| 219 | // Last round uses s-box directly and XORs to produce output. | 219 | // Last round uses s-box directly and XORs to produce output. |
| 220 | var x: [4]u8 = undefined; | 220 | var x: [4]u8 = undefined; |
| 221 | x = sbox_lookup(&sbox_decrypt, @as(u8, @truncate(s0)), @as(u8, @truncate(s3 >> 8)), @as(u8, @truncate(s2 >> 16)), @as(u8, @truncate(s1 >> 24))); | 221 | x = sbox_lookup(&sbox_decrypt, @as(u8, @truncate(s0)), @as(u8, @truncate(s3 >> 8)), @as(u8, @truncate(s2 >> 16)), @as(u8, @truncate(s1 >> 24))); |
| 222 | var t0 = mem.readInt(u32, &x, .Little); | 222 | var t0 = mem.readInt(u32, &x, .little); |
| 223 | x = sbox_lookup(&sbox_decrypt, @as(u8, @truncate(s1)), @as(u8, @truncate(s0 >> 8)), @as(u8, @truncate(s3 >> 16)), @as(u8, @truncate(s2 >> 24))); | 223 | x = sbox_lookup(&sbox_decrypt, @as(u8, @truncate(s1)), @as(u8, @truncate(s0 >> 8)), @as(u8, @truncate(s3 >> 16)), @as(u8, @truncate(s2 >> 24))); |
| 224 | var t1 = mem.readInt(u32, &x, .Little); | 224 | var t1 = mem.readInt(u32, &x, .little); |
| 225 | x = sbox_lookup(&sbox_decrypt, @as(u8, @truncate(s2)), @as(u8, @truncate(s1 >> 8)), @as(u8, @truncate(s0 >> 16)), @as(u8, @truncate(s3 >> 24))); | 225 | x = sbox_lookup(&sbox_decrypt, @as(u8, @truncate(s2)), @as(u8, @truncate(s1 >> 8)), @as(u8, @truncate(s0 >> 16)), @as(u8, @truncate(s3 >> 24))); |
| 226 | var t2 = mem.readInt(u32, &x, .Little); | 226 | var t2 = mem.readInt(u32, &x, .little); |
| 227 | x = sbox_lookup(&sbox_decrypt, @as(u8, @truncate(s3)), @as(u8, @truncate(s2 >> 8)), @as(u8, @truncate(s1 >> 16)), @as(u8, @truncate(s0 >> 24))); | 227 | x = sbox_lookup(&sbox_decrypt, @as(u8, @truncate(s3)), @as(u8, @truncate(s2 >> 8)), @as(u8, @truncate(s1 >> 16)), @as(u8, @truncate(s0 >> 24))); |
| 228 | var t3 = mem.readInt(u32, &x, .Little); | 228 | var t3 = mem.readInt(u32, &x, .little); |
| 229 | 229 | ||
| 230 | t0 ^= round_key.repr[0]; | 230 | t0 ^= round_key.repr[0]; |
| 231 | t1 ^= round_key.repr[1]; | 231 | t1 ^= round_key.repr[1]; |
| ... | @@ -349,14 +349,14 @@ fn KeySchedule(comptime Aes: type) type { | ... | @@ -349,14 +349,14 @@ fn KeySchedule(comptime Aes: type) type { |
| 349 | // Apply sbox_encrypt to each byte in w. | 349 | // Apply sbox_encrypt to each byte in w. |
| 350 | fn func(w: u32) u32 { | 350 | fn func(w: u32) u32 { |
| 351 | const x = sbox_lookup(&sbox_key_schedule, @as(u8, @truncate(w)), @as(u8, @truncate(w >> 8)), @as(u8, @truncate(w >> 16)), @as(u8, @truncate(w >> 24))); | 351 | const x = sbox_lookup(&sbox_key_schedule, @as(u8, @truncate(w)), @as(u8, @truncate(w >> 8)), @as(u8, @truncate(w >> 16)), @as(u8, @truncate(w >> 24))); |
| 352 | return mem.readInt(u32, &x, .Little); | 352 | return mem.readInt(u32, &x, .little); |
| 353 | } | 353 | } |
| 354 | }.func; | 354 | }.func; |
| 355 | 355 | ||
| 356 | var round_keys: [rounds + 1]Block = undefined; | 356 | var round_keys: [rounds + 1]Block = undefined; |
| 357 | comptime var i: usize = 0; | 357 | comptime var i: usize = 0; |
| 358 | inline while (i < words_in_key) : (i += 1) { | 358 | inline while (i < words_in_key) : (i += 1) { |
| 359 | round_keys[i / 4].repr[i % 4] = mem.readInt(u32, key[4 * i ..][0..4], .Big); | 359 | round_keys[i / 4].repr[i % 4] = mem.readInt(u32, key[4 * i ..][0..4], .big); |
| 360 | } | 360 | } |
| 361 | inline while (i < round_keys.len * 4) : (i += 1) { | 361 | inline while (i < round_keys.len * 4) : (i += 1) { |
| 362 | var t = round_keys[(i - 1) / 4].repr[(i - 1) % 4]; | 362 | var t = round_keys[(i - 1) / 4].repr[(i - 1) % 4]; |
lib/std/crypto/aes_gcm.zig+10-10| ... | @@ -33,7 +33,7 @@ fn AesGcm(comptime Aes: anytype) type { | ... | @@ -33,7 +33,7 @@ fn AesGcm(comptime Aes: anytype) type { |
| 33 | var t: [16]u8 = undefined; | 33 | var t: [16]u8 = undefined; |
| 34 | var j: [16]u8 = undefined; | 34 | var j: [16]u8 = undefined; |
| 35 | j[0..nonce_length].* = npub; | 35 | j[0..nonce_length].* = npub; |
| 36 | mem.writeInt(u32, j[nonce_length..][0..4], 1, .Big); | 36 | mem.writeInt(u32, j[nonce_length..][0..4], 1, .big); |
| 37 | aes.encrypt(&t, &j); | 37 | aes.encrypt(&t, &j); |
| 38 | 38 | ||
| 39 | const block_count = (math.divCeil(usize, ad.len, Ghash.block_length) catch unreachable) + (math.divCeil(usize, c.len, Ghash.block_length) catch unreachable) + 1; | 39 | const block_count = (math.divCeil(usize, ad.len, Ghash.block_length) catch unreachable) + (math.divCeil(usize, c.len, Ghash.block_length) catch unreachable) + 1; |
| ... | @@ -41,14 +41,14 @@ fn AesGcm(comptime Aes: anytype) type { | ... | @@ -41,14 +41,14 @@ fn AesGcm(comptime Aes: anytype) type { |
| 41 | mac.update(ad); | 41 | mac.update(ad); |
| 42 | mac.pad(); | 42 | mac.pad(); |
| 43 | 43 | ||
| 44 | mem.writeInt(u32, j[nonce_length..][0..4], 2, .Big); | 44 | mem.writeInt(u32, j[nonce_length..][0..4], 2, .big); |
| 45 | modes.ctr(@TypeOf(aes), aes, c, m, j, std.builtin.Endian.Big); | 45 | modes.ctr(@TypeOf(aes), aes, c, m, j, std.builtin.Endian.big); |
| 46 | mac.update(c[0..m.len][0..]); | 46 | mac.update(c[0..m.len][0..]); |
| 47 | mac.pad(); | 47 | mac.pad(); |
| 48 | 48 | ||
| 49 | var final_block = h; | 49 | var final_block = h; |
| 50 | mem.writeInt(u64, final_block[0..8], ad.len * 8, .Big); | 50 | mem.writeInt(u64, final_block[0..8], ad.len * 8, .big); |
| 51 | mem.writeInt(u64, final_block[8..16], m.len * 8, .Big); | 51 | mem.writeInt(u64, final_block[8..16], m.len * 8, .big); |
| 52 | mac.update(&final_block); | 52 | mac.update(&final_block); |
| 53 | mac.final(tag); | 53 | mac.final(tag); |
| 54 | for (t, 0..) |x, i| { | 54 | for (t, 0..) |x, i| { |
| ... | @@ -75,7 +75,7 @@ fn AesGcm(comptime Aes: anytype) type { | ... | @@ -75,7 +75,7 @@ fn AesGcm(comptime Aes: anytype) type { |
| 75 | var t: [16]u8 = undefined; | 75 | var t: [16]u8 = undefined; |
| 76 | var j: [16]u8 = undefined; | 76 | var j: [16]u8 = undefined; |
| 77 | j[0..nonce_length].* = npub; | 77 | j[0..nonce_length].* = npub; |
| 78 | mem.writeInt(u32, j[nonce_length..][0..4], 1, .Big); | 78 | mem.writeInt(u32, j[nonce_length..][0..4], 1, .big); |
| 79 | aes.encrypt(&t, &j); | 79 | aes.encrypt(&t, &j); |
| 80 | 80 | ||
| 81 | const block_count = (math.divCeil(usize, ad.len, Ghash.block_length) catch unreachable) + (math.divCeil(usize, c.len, Ghash.block_length) catch unreachable) + 1; | 81 | const block_count = (math.divCeil(usize, ad.len, Ghash.block_length) catch unreachable) + (math.divCeil(usize, c.len, Ghash.block_length) catch unreachable) + 1; |
| ... | @@ -87,8 +87,8 @@ fn AesGcm(comptime Aes: anytype) type { | ... | @@ -87,8 +87,8 @@ fn AesGcm(comptime Aes: anytype) type { |
| 87 | mac.pad(); | 87 | mac.pad(); |
| 88 | 88 | ||
| 89 | var final_block = h; | 89 | var final_block = h; |
| 90 | mem.writeInt(u64, final_block[0..8], ad.len * 8, .Big); | 90 | mem.writeInt(u64, final_block[0..8], ad.len * 8, .big); |
| 91 | mem.writeInt(u64, final_block[8..16], m.len * 8, .Big); | 91 | mem.writeInt(u64, final_block[8..16], m.len * 8, .big); |
| 92 | mac.update(&final_block); | 92 | mac.update(&final_block); |
| 93 | var computed_tag: [Ghash.mac_length]u8 = undefined; | 93 | var computed_tag: [Ghash.mac_length]u8 = undefined; |
| 94 | mac.final(&computed_tag); | 94 | mac.final(&computed_tag); |
| ... | @@ -103,8 +103,8 @@ fn AesGcm(comptime Aes: anytype) type { | ... | @@ -103,8 +103,8 @@ fn AesGcm(comptime Aes: anytype) type { |
| 103 | return error.AuthenticationFailed; | 103 | return error.AuthenticationFailed; |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | mem.writeInt(u32, j[nonce_length..][0..4], 2, .Big); | 106 | mem.writeInt(u32, j[nonce_length..][0..4], 2, .big); |
| 107 | modes.ctr(@TypeOf(aes), aes, m, c, j, std.builtin.Endian.Big); | 107 | modes.ctr(@TypeOf(aes), aes, m, c, j, std.builtin.Endian.big); |
| 108 | } | 108 | } |
| 109 | }; | 109 | }; |
| 110 | } | 110 | } |
lib/std/crypto/aes_ocb.zig+4-4| ... | @@ -29,10 +29,10 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -29,10 +29,10 @@ fn AesOcb(comptime Aes: anytype) type { |
| 29 | upto: usize, | 29 | upto: usize, |
| 30 | 30 | ||
| 31 | inline fn double(l: Block) Block { | 31 | inline fn double(l: Block) Block { |
| 32 | const l_ = mem.readInt(u128, &l, .Big); | 32 | const l_ = mem.readInt(u128, &l, .big); |
| 33 | const l_2 = (l_ << 1) ^ (0x87 & -%(l_ >> 127)); | 33 | const l_2 = (l_ << 1) ^ (0x87 & -%(l_ >> 127)); |
| 34 | var l2: Block = undefined; | 34 | var l2: Block = undefined; |
| 35 | mem.writeInt(u128, &l2, l_2, .Big); | 35 | mem.writeInt(u128, &l2, l_2, .big); |
| 36 | return l2; | 36 | return l2; |
| 37 | } | 37 | } |
| 38 | 38 | ||
| ... | @@ -94,10 +94,10 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -94,10 +94,10 @@ fn AesOcb(comptime Aes: anytype) type { |
| 94 | nx[15] &= 0xc0; | 94 | nx[15] &= 0xc0; |
| 95 | var ktop_: Block = undefined; | 95 | var ktop_: Block = undefined; |
| 96 | aes_enc_ctx.encrypt(&ktop_, &nx); | 96 | aes_enc_ctx.encrypt(&ktop_, &nx); |
| 97 | const ktop = mem.readInt(u128, &ktop_, .Big); | 97 | const ktop = mem.readInt(u128, &ktop_, .big); |
| 98 | var stretch = (@as(u192, ktop) << 64) | @as(u192, @as(u64, @truncate(ktop >> 64)) ^ @as(u64, @truncate(ktop >> 56))); | 98 | var stretch = (@as(u192, ktop) << 64) | @as(u192, @as(u64, @truncate(ktop >> 64)) ^ @as(u64, @truncate(ktop >> 56))); |
| 99 | var offset: Block = undefined; | 99 | var offset: Block = undefined; |
| 100 | mem.writeInt(u128, &offset, @as(u128, @truncate(stretch >> (64 - @as(u7, bottom)))), .Big); | 100 | mem.writeInt(u128, &offset, @as(u128, @truncate(stretch >> (64 - @as(u7, bottom)))), .big); |
| 101 | return offset; | 101 | return offset; |
| 102 | } | 102 | } |
| 103 | 103 |
lib/std/crypto/argon2.zig+17-17| ... | @@ -110,27 +110,27 @@ fn initHash( | ... | @@ -110,27 +110,27 @@ fn initHash( |
| 110 | var parameters: [24]u8 = undefined; | 110 | var parameters: [24]u8 = undefined; |
| 111 | var tmp: [4]u8 = undefined; | 111 | var tmp: [4]u8 = undefined; |
| 112 | var b2 = Blake2b512.init(.{}); | 112 | var b2 = Blake2b512.init(.{}); |
| 113 | mem.writeInt(u32, parameters[0..4], params.p, .Little); | 113 | mem.writeInt(u32, parameters[0..4], params.p, .little); |
| 114 | mem.writeInt(u32, parameters[4..8], @as(u32, @intCast(dk_len)), .Little); | 114 | mem.writeInt(u32, parameters[4..8], @as(u32, @intCast(dk_len)), .little); |
| 115 | mem.writeInt(u32, parameters[8..12], params.m, .Little); | 115 | mem.writeInt(u32, parameters[8..12], params.m, .little); |
| 116 | mem.writeInt(u32, parameters[12..16], params.t, .Little); | 116 | mem.writeInt(u32, parameters[12..16], params.t, .little); |
| 117 | mem.writeInt(u32, parameters[16..20], version, .Little); | 117 | mem.writeInt(u32, parameters[16..20], version, .little); |
| 118 | mem.writeInt(u32, parameters[20..24], @intFromEnum(mode), .Little); | 118 | mem.writeInt(u32, parameters[20..24], @intFromEnum(mode), .little); |
| 119 | b2.update(&parameters); | 119 | b2.update(&parameters); |
| 120 | mem.writeInt(u32, &tmp, @as(u32, @intCast(password.len)), .Little); | 120 | mem.writeInt(u32, &tmp, @as(u32, @intCast(password.len)), .little); |
| 121 | b2.update(&tmp); | 121 | b2.update(&tmp); |
| 122 | b2.update(password); | 122 | b2.update(password); |
| 123 | mem.writeInt(u32, &tmp, @as(u32, @intCast(salt.len)), .Little); | 123 | mem.writeInt(u32, &tmp, @as(u32, @intCast(salt.len)), .little); |
| 124 | b2.update(&tmp); | 124 | b2.update(&tmp); |
| 125 | b2.update(salt); | 125 | b2.update(salt); |
| 126 | const secret = params.secret orelse ""; | 126 | const secret = params.secret orelse ""; |
| 127 | std.debug.assert(secret.len <= max_int); | 127 | std.debug.assert(secret.len <= max_int); |
| 128 | mem.writeInt(u32, &tmp, @as(u32, @intCast(secret.len)), .Little); | 128 | mem.writeInt(u32, &tmp, @as(u32, @intCast(secret.len)), .little); |
| 129 | b2.update(&tmp); | 129 | b2.update(&tmp); |
| 130 | b2.update(secret); | 130 | b2.update(secret); |
| 131 | const ad = params.ad orelse ""; | 131 | const ad = params.ad orelse ""; |
| 132 | std.debug.assert(ad.len <= max_int); | 132 | std.debug.assert(ad.len <= max_int); |
| 133 | mem.writeInt(u32, &tmp, @as(u32, @intCast(ad.len)), .Little); | 133 | mem.writeInt(u32, &tmp, @as(u32, @intCast(ad.len)), .little); |
| 134 | b2.update(&tmp); | 134 | b2.update(&tmp); |
| 135 | b2.update(ad); | 135 | b2.update(ad); |
| 136 | b2.final(h0[0..Blake2b512.digest_length]); | 136 | b2.final(h0[0..Blake2b512.digest_length]); |
| ... | @@ -140,7 +140,7 @@ fn initHash( | ... | @@ -140,7 +140,7 @@ fn initHash( |
| 140 | fn blake2bLong(out: []u8, in: []const u8) void { | 140 | fn blake2bLong(out: []u8, in: []const u8) void { |
| 141 | const H = Blake2b512; | 141 | const H = Blake2b512; |
| 142 | var outlen_bytes: [4]u8 = undefined; | 142 | var outlen_bytes: [4]u8 = undefined; |
| 143 | mem.writeInt(u32, &outlen_bytes, @as(u32, @intCast(out.len)), .Little); | 143 | mem.writeInt(u32, &outlen_bytes, @as(u32, @intCast(out.len)), .little); |
| 144 | 144 | ||
| 145 | var out_buf: [H.digest_length]u8 = undefined; | 145 | var out_buf: [H.digest_length]u8 = undefined; |
| 146 | 146 | ||
| ... | @@ -183,18 +183,18 @@ fn initBlocks( | ... | @@ -183,18 +183,18 @@ fn initBlocks( |
| 183 | var lane: u24 = 0; | 183 | var lane: u24 = 0; |
| 184 | while (lane < threads) : (lane += 1) { | 184 | while (lane < threads) : (lane += 1) { |
| 185 | const j = lane * (memory / threads); | 185 | const j = lane * (memory / threads); |
| 186 | mem.writeInt(u32, h0[Blake2b512.digest_length + 4 ..][0..4], lane, .Little); | 186 | mem.writeInt(u32, h0[Blake2b512.digest_length + 4 ..][0..4], lane, .little); |
| 187 | 187 | ||
| 188 | mem.writeInt(u32, h0[Blake2b512.digest_length..][0..4], 0, .Little); | 188 | mem.writeInt(u32, h0[Blake2b512.digest_length..][0..4], 0, .little); |
| 189 | blake2bLong(&block0, h0); | 189 | blake2bLong(&block0, h0); |
| 190 | for (&blocks.items[j + 0], 0..) |*v, i| { | 190 | for (&blocks.items[j + 0], 0..) |*v, i| { |
| 191 | v.* = mem.readInt(u64, block0[i * 8 ..][0..8], .Little); | 191 | v.* = mem.readInt(u64, block0[i * 8 ..][0..8], .little); |
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | mem.writeInt(u32, h0[Blake2b512.digest_length..][0..4], 1, .Little); | 194 | mem.writeInt(u32, h0[Blake2b512.digest_length..][0..4], 1, .little); |
| 195 | blake2bLong(&block0, h0); | 195 | blake2bLong(&block0, h0); |
| 196 | for (&blocks.items[j + 1], 0..) |*v, i| { | 196 | for (&blocks.items[j + 1], 0..) |*v, i| { |
| 197 | v.* = mem.readInt(u64, block0[i * 8 ..][0..8], .Little); | 197 | v.* = mem.readInt(u64, block0[i * 8 ..][0..8], .little); |
| 198 | } | 198 | } |
| 199 | } | 199 | } |
| 200 | } | 200 | } |
| ... | @@ -433,7 +433,7 @@ fn finalize( | ... | @@ -433,7 +433,7 @@ fn finalize( |
| 433 | } | 433 | } |
| 434 | var block: [1024]u8 = undefined; | 434 | var block: [1024]u8 = undefined; |
| 435 | for (blocks.items[memory - 1], 0..) |v, i| { | 435 | for (blocks.items[memory - 1], 0..) |v, i| { |
| 436 | mem.writeInt(u64, block[i * 8 ..][0..8], v, .Little); | 436 | mem.writeInt(u64, block[i * 8 ..][0..8], v, .little); |
| 437 | } | 437 | } |
| 438 | blake2bLong(out, &block); | 438 | blake2bLong(out, &block); |
| 439 | } | 439 | } |
lib/std/crypto/ascon.zig+3-3| ... | @@ -96,8 +96,8 @@ pub fn State(comptime endian: std.builtin.Endian) type { | ... | @@ -96,8 +96,8 @@ pub fn State(comptime endian: std.builtin.Endian) type { |
| 96 | /// XOR a byte into the state at a given offset. | 96 | /// XOR a byte into the state at a given offset. |
| 97 | pub fn addByte(self: *Self, byte: u8, offset: usize) void { | 97 | pub fn addByte(self: *Self, byte: u8, offset: usize) void { |
| 98 | const z = switch (endian) { | 98 | const z = switch (endian) { |
| 99 | .Big => 64 - 8 - 8 * @as(u6, @truncate(offset % 8)), | 99 | .big => 64 - 8 - 8 * @as(u6, @truncate(offset % 8)), |
| 100 | .Little => 8 * @as(u6, @truncate(offset % 8)), | 100 | .little => 8 * @as(u6, @truncate(offset % 8)), |
| 101 | }; | 101 | }; |
| 102 | self.st[offset / 8] ^= @as(u64, byte) << z; | 102 | self.st[offset / 8] ^= @as(u64, byte) << z; |
| 103 | } | 103 | } |
| ... | @@ -215,7 +215,7 @@ pub fn State(comptime endian: std.builtin.Endian) type { | ... | @@ -215,7 +215,7 @@ pub fn State(comptime endian: std.builtin.Endian) type { |
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | test "ascon" { | 217 | test "ascon" { |
| 218 | const Ascon = State(.Big); | 218 | const Ascon = State(.big); |
| 219 | const bytes = [_]u8{0x01} ** Ascon.block_bytes; | 219 | const bytes = [_]u8{0x01} ** Ascon.block_bytes; |
| 220 | var st = Ascon.init(bytes); | 220 | var st = Ascon.init(bytes); |
| 221 | var out: [Ascon.block_bytes]u8 = undefined; | 221 | var out: [Ascon.block_bytes]u8 = undefined; |
lib/std/crypto/bcrypt.zig+2-2| ... | @@ -451,7 +451,7 @@ pub fn bcrypt( | ... | @@ -451,7 +451,7 @@ pub fn bcrypt( |
| 451 | 451 | ||
| 452 | var ct: [ct_length]u8 = undefined; | 452 | var ct: [ct_length]u8 = undefined; |
| 453 | for (cdata, 0..) |c, i| { | 453 | for (cdata, 0..) |c, i| { |
| 454 | mem.writeInt(u32, ct[i * 4 ..][0..4], c, .Big); | 454 | mem.writeInt(u32, ct[i * 4 ..][0..4], c, .big); |
| 455 | } | 455 | } |
| 456 | return ct[0..dk_length].*; | 456 | return ct[0..dk_length].*; |
| 457 | } | 457 | } |
| ... | @@ -547,7 +547,7 @@ const pbkdf_prf = struct { | ... | @@ -547,7 +547,7 @@ const pbkdf_prf = struct { |
| 547 | // copy out | 547 | // copy out |
| 548 | var out: [32]u8 = undefined; | 548 | var out: [32]u8 = undefined; |
| 549 | for (cdata, 0..) |v, i| { | 549 | for (cdata, 0..) |v, i| { |
| 550 | std.mem.writeInt(u32, out[4 * i ..][0..4], v, .Little); | 550 | std.mem.writeInt(u32, out[4 * i ..][0..4], v, .little); |
| 551 | } | 551 | } |
| 552 | 552 | ||
| 553 | // zap | 553 | // zap |
lib/std/crypto/blake2.zig+10-10| ... | @@ -85,12 +85,12 @@ pub fn Blake2s(comptime out_bits: usize) type { | ... | @@ -85,12 +85,12 @@ pub fn Blake2s(comptime out_bits: usize) type { |
| 85 | d.buf_len = 0; | 85 | d.buf_len = 0; |
| 86 | 86 | ||
| 87 | if (options.salt) |salt| { | 87 | if (options.salt) |salt| { |
| 88 | d.h[4] ^= mem.readInt(u32, salt[0..4], .Little); | 88 | d.h[4] ^= mem.readInt(u32, salt[0..4], .little); |
| 89 | d.h[5] ^= mem.readInt(u32, salt[4..8], .Little); | 89 | d.h[5] ^= mem.readInt(u32, salt[4..8], .little); |
| 90 | } | 90 | } |
| 91 | if (options.context) |context| { | 91 | if (options.context) |context| { |
| 92 | d.h[6] ^= mem.readInt(u32, context[0..4], .Little); | 92 | d.h[6] ^= mem.readInt(u32, context[0..4], .little); |
| 93 | d.h[7] ^= mem.readInt(u32, context[4..8], .Little); | 93 | d.h[7] ^= mem.readInt(u32, context[4..8], .little); |
| 94 | } | 94 | } |
| 95 | if (key_len > 0) { | 95 | if (key_len > 0) { |
| 96 | @memset(d.buf[key_len..], 0); | 96 | @memset(d.buf[key_len..], 0); |
| ... | @@ -143,7 +143,7 @@ pub fn Blake2s(comptime out_bits: usize) type { | ... | @@ -143,7 +143,7 @@ pub fn Blake2s(comptime out_bits: usize) type { |
| 143 | var v: [16]u32 = undefined; | 143 | var v: [16]u32 = undefined; |
| 144 | 144 | ||
| 145 | for (&m, 0..) |*r, i| { | 145 | for (&m, 0..) |*r, i| { |
| 146 | r.* = mem.readInt(u32, b[4 * i ..][0..4], .Little); | 146 | r.* = mem.readInt(u32, b[4 * i ..][0..4], .little); |
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | var k: usize = 0; | 149 | var k: usize = 0; |
| ... | @@ -521,12 +521,12 @@ pub fn Blake2b(comptime out_bits: usize) type { | ... | @@ -521,12 +521,12 @@ pub fn Blake2b(comptime out_bits: usize) type { |
| 521 | d.buf_len = 0; | 521 | d.buf_len = 0; |
| 522 | 522 | ||
| 523 | if (options.salt) |salt| { | 523 | if (options.salt) |salt| { |
| 524 | d.h[4] ^= mem.readInt(u64, salt[0..8], .Little); | 524 | d.h[4] ^= mem.readInt(u64, salt[0..8], .little); |
| 525 | d.h[5] ^= mem.readInt(u64, salt[8..16], .Little); | 525 | d.h[5] ^= mem.readInt(u64, salt[8..16], .little); |
| 526 | } | 526 | } |
| 527 | if (options.context) |context| { | 527 | if (options.context) |context| { |
| 528 | d.h[6] ^= mem.readInt(u64, context[0..8], .Little); | 528 | d.h[6] ^= mem.readInt(u64, context[0..8], .little); |
| 529 | d.h[7] ^= mem.readInt(u64, context[8..16], .Little); | 529 | d.h[7] ^= mem.readInt(u64, context[8..16], .little); |
| 530 | } | 530 | } |
| 531 | if (key_len > 0) { | 531 | if (key_len > 0) { |
| 532 | @memset(d.buf[key_len..], 0); | 532 | @memset(d.buf[key_len..], 0); |
| ... | @@ -579,7 +579,7 @@ pub fn Blake2b(comptime out_bits: usize) type { | ... | @@ -579,7 +579,7 @@ pub fn Blake2b(comptime out_bits: usize) type { |
| 579 | var v: [16]u64 = undefined; | 579 | var v: [16]u64 = undefined; |
| 580 | 580 | ||
| 581 | for (&m, 0..) |*r, i| { | 581 | for (&m, 0..) |*r, i| { |
| 582 | r.* = mem.readInt(u64, b[8 * i ..][0..8], .Little); | 582 | r.* = mem.readInt(u64, b[8 * i ..][0..8], .little); |
| 583 | } | 583 | } |
| 584 | 584 | ||
| 585 | var k: usize = 0; | 585 | var k: usize = 0; |
lib/std/crypto/blake3.zig+2-2| ... | @@ -212,7 +212,7 @@ fn first8Words(words: [16]u32) [8]u32 { | ... | @@ -212,7 +212,7 @@ fn first8Words(words: [16]u32) [8]u32 { |
| 212 | fn wordsFromLittleEndianBytes(comptime count: usize, bytes: [count * 4]u8) [count]u32 { | 212 | fn wordsFromLittleEndianBytes(comptime count: usize, bytes: [count * 4]u8) [count]u32 { |
| 213 | var words: [count]u32 = undefined; | 213 | var words: [count]u32 = undefined; |
| 214 | for (&words, 0..) |*word, i| { | 214 | for (&words, 0..) |*word, i| { |
| 215 | word.* = mem.readInt(u32, bytes[4 * i ..][0..4], .Little); | 215 | word.* = mem.readInt(u32, bytes[4 * i ..][0..4], .little); |
| 216 | } | 216 | } |
| 217 | return words; | 217 | return words; |
| 218 | } | 218 | } |
| ... | @@ -252,7 +252,7 @@ const Output = struct { | ... | @@ -252,7 +252,7 @@ const Output = struct { |
| 252 | var word_counter: usize = 0; | 252 | var word_counter: usize = 0; |
| 253 | while (out_word_it.next()) |out_word| { | 253 | while (out_word_it.next()) |out_word| { |
| 254 | var word_bytes: [4]u8 = undefined; | 254 | var word_bytes: [4]u8 = undefined; |
| 255 | mem.writeInt(u32, &word_bytes, words[word_counter], .Little); | 255 | mem.writeInt(u32, &word_bytes, words[word_counter], .little); |
| 256 | @memcpy(out_word, word_bytes[0..out_word.len]); | 256 | @memcpy(out_word, word_bytes[0..out_word.len]); |
| 257 | word_counter += 1; | 257 | word_counter += 1; |
| 258 | } | 258 | } |
lib/std/crypto/chacha20.zig+73-73| ... | @@ -87,10 +87,10 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type | ... | @@ -87,10 +87,10 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type |
| 87 | switch (degree) { | 87 | switch (degree) { |
| 88 | 1 => { | 88 | 1 => { |
| 89 | const constant_le = Lane{ | 89 | const constant_le = Lane{ |
| 90 | mem.readInt(u32, c[0..4], .Little), | 90 | mem.readInt(u32, c[0..4], .little), |
| 91 | mem.readInt(u32, c[4..8], .Little), | 91 | mem.readInt(u32, c[4..8], .little), |
| 92 | mem.readInt(u32, c[8..12], .Little), | 92 | mem.readInt(u32, c[8..12], .little), |
| 93 | mem.readInt(u32, c[12..16], .Little), | 93 | mem.readInt(u32, c[12..16], .little), |
| 94 | }; | 94 | }; |
| 95 | return BlockVec{ | 95 | return BlockVec{ |
| 96 | constant_le, | 96 | constant_le, |
| ... | @@ -101,14 +101,14 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type | ... | @@ -101,14 +101,14 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type |
| 101 | }, | 101 | }, |
| 102 | 2 => { | 102 | 2 => { |
| 103 | const constant_le = Lane{ | 103 | const constant_le = Lane{ |
| 104 | mem.readInt(u32, c[0..4], .Little), | 104 | mem.readInt(u32, c[0..4], .little), |
| 105 | mem.readInt(u32, c[4..8], .Little), | 105 | mem.readInt(u32, c[4..8], .little), |
| 106 | mem.readInt(u32, c[8..12], .Little), | 106 | mem.readInt(u32, c[8..12], .little), |
| 107 | mem.readInt(u32, c[12..16], .Little), | 107 | mem.readInt(u32, c[12..16], .little), |
| 108 | mem.readInt(u32, c[0..4], .Little), | 108 | mem.readInt(u32, c[0..4], .little), |
| 109 | mem.readInt(u32, c[4..8], .Little), | 109 | mem.readInt(u32, c[4..8], .little), |
| 110 | mem.readInt(u32, c[8..12], .Little), | 110 | mem.readInt(u32, c[8..12], .little), |
| 111 | mem.readInt(u32, c[12..16], .Little), | 111 | mem.readInt(u32, c[12..16], .little), |
| 112 | }; | 112 | }; |
| 113 | const n1 = @addWithOverflow(d[0], 1); | 113 | const n1 = @addWithOverflow(d[0], 1); |
| 114 | return BlockVec{ | 114 | return BlockVec{ |
| ... | @@ -123,22 +123,22 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type | ... | @@ -123,22 +123,22 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type |
| 123 | const n2 = @addWithOverflow(d[0], 2); | 123 | const n2 = @addWithOverflow(d[0], 2); |
| 124 | const n3 = @addWithOverflow(d[0], 3); | 124 | const n3 = @addWithOverflow(d[0], 3); |
| 125 | const constant_le = Lane{ | 125 | const constant_le = Lane{ |
| 126 | mem.readInt(u32, c[0..4], .Little), | 126 | mem.readInt(u32, c[0..4], .little), |
| 127 | mem.readInt(u32, c[4..8], .Little), | 127 | mem.readInt(u32, c[4..8], .little), |
| 128 | mem.readInt(u32, c[8..12], .Little), | 128 | mem.readInt(u32, c[8..12], .little), |
| 129 | mem.readInt(u32, c[12..16], .Little), | 129 | mem.readInt(u32, c[12..16], .little), |
| 130 | mem.readInt(u32, c[0..4], .Little), | 130 | mem.readInt(u32, c[0..4], .little), |
| 131 | mem.readInt(u32, c[4..8], .Little), | 131 | mem.readInt(u32, c[4..8], .little), |
| 132 | mem.readInt(u32, c[8..12], .Little), | 132 | mem.readInt(u32, c[8..12], .little), |
| 133 | mem.readInt(u32, c[12..16], .Little), | 133 | mem.readInt(u32, c[12..16], .little), |
| 134 | mem.readInt(u32, c[0..4], .Little), | 134 | mem.readInt(u32, c[0..4], .little), |
| 135 | mem.readInt(u32, c[4..8], .Little), | 135 | mem.readInt(u32, c[4..8], .little), |
| 136 | mem.readInt(u32, c[8..12], .Little), | 136 | mem.readInt(u32, c[8..12], .little), |
| 137 | mem.readInt(u32, c[12..16], .Little), | 137 | mem.readInt(u32, c[12..16], .little), |
| 138 | mem.readInt(u32, c[0..4], .Little), | 138 | mem.readInt(u32, c[0..4], .little), |
| 139 | mem.readInt(u32, c[4..8], .Little), | 139 | mem.readInt(u32, c[4..8], .little), |
| 140 | mem.readInt(u32, c[8..12], .Little), | 140 | mem.readInt(u32, c[8..12], .little), |
| 141 | mem.readInt(u32, c[12..16], .Little), | 141 | mem.readInt(u32, c[12..16], .little), |
| 142 | }; | 142 | }; |
| 143 | return BlockVec{ | 143 | return BlockVec{ |
| 144 | constant_le, | 144 | constant_le, |
| ... | @@ -218,10 +218,10 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type | ... | @@ -218,10 +218,10 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type |
| 218 | inline fn hashToBytes(comptime dm: usize, out: *[64 * dm]u8, x: BlockVec) void { | 218 | inline fn hashToBytes(comptime dm: usize, out: *[64 * dm]u8, x: BlockVec) void { |
| 219 | for (0..dm) |d| { | 219 | for (0..dm) |d| { |
| 220 | for (0..4) |i| { | 220 | for (0..4) |i| { |
| 221 | mem.writeInt(u32, out[64 * d + 16 * i + 0 ..][0..4], x[i][0 + 4 * d], .Little); | 221 | mem.writeInt(u32, out[64 * d + 16 * i + 0 ..][0..4], x[i][0 + 4 * d], .little); |
| 222 | mem.writeInt(u32, out[64 * d + 16 * i + 4 ..][0..4], x[i][1 + 4 * d], .Little); | 222 | mem.writeInt(u32, out[64 * d + 16 * i + 4 ..][0..4], x[i][1 + 4 * d], .little); |
| 223 | mem.writeInt(u32, out[64 * d + 16 * i + 8 ..][0..4], x[i][2 + 4 * d], .Little); | 223 | mem.writeInt(u32, out[64 * d + 16 * i + 8 ..][0..4], x[i][2 + 4 * d], .little); |
| 224 | mem.writeInt(u32, out[64 * d + 16 * i + 12 ..][0..4], x[i][3 + 4 * d], .Little); | 224 | mem.writeInt(u32, out[64 * d + 16 * i + 12 ..][0..4], x[i][3 + 4 * d], .little); |
| 225 | } | 225 | } |
| 226 | } | 226 | } |
| 227 | } | 227 | } |
| ... | @@ -309,20 +309,20 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type | ... | @@ -309,20 +309,20 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type |
| 309 | fn hchacha20(input: [16]u8, key: [32]u8) [32]u8 { | 309 | fn hchacha20(input: [16]u8, key: [32]u8) [32]u8 { |
| 310 | var c: [4]u32 = undefined; | 310 | var c: [4]u32 = undefined; |
| 311 | for (c, 0..) |_, i| { | 311 | for (c, 0..) |_, i| { |
| 312 | c[i] = mem.readInt(u32, input[4 * i ..][0..4], .Little); | 312 | c[i] = mem.readInt(u32, input[4 * i ..][0..4], .little); |
| 313 | } | 313 | } |
| 314 | const ctx = initContext(keyToWords(key), c); | 314 | const ctx = initContext(keyToWords(key), c); |
| 315 | var x: BlockVec = undefined; | 315 | var x: BlockVec = undefined; |
| 316 | chacha20Core(x[0..], ctx); | 316 | chacha20Core(x[0..], ctx); |
| 317 | var out: [32]u8 = undefined; | 317 | var out: [32]u8 = undefined; |
| 318 | mem.writeInt(u32, out[0..4], x[0][0], .Little); | 318 | mem.writeInt(u32, out[0..4], x[0][0], .little); |
| 319 | mem.writeInt(u32, out[4..8], x[0][1], .Little); | 319 | mem.writeInt(u32, out[4..8], x[0][1], .little); |
| 320 | mem.writeInt(u32, out[8..12], x[0][2], .Little); | 320 | mem.writeInt(u32, out[8..12], x[0][2], .little); |
| 321 | mem.writeInt(u32, out[12..16], x[0][3], .Little); | 321 | mem.writeInt(u32, out[12..16], x[0][3], .little); |
| 322 | mem.writeInt(u32, out[16..20], x[3][0], .Little); | 322 | mem.writeInt(u32, out[16..20], x[3][0], .little); |
| 323 | mem.writeInt(u32, out[20..24], x[3][1], .Little); | 323 | mem.writeInt(u32, out[20..24], x[3][1], .little); |
| 324 | mem.writeInt(u32, out[24..28], x[3][2], .Little); | 324 | mem.writeInt(u32, out[24..28], x[3][2], .little); |
| 325 | mem.writeInt(u32, out[28..32], x[3][3], .Little); | 325 | mem.writeInt(u32, out[28..32], x[3][3], .little); |
| 326 | return out; | 326 | return out; |
| 327 | } | 327 | } |
| 328 | }; | 328 | }; |
| ... | @@ -336,10 +336,10 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type { | ... | @@ -336,10 +336,10 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type { |
| 336 | fn initContext(key: [8]u32, d: [4]u32) BlockVec { | 336 | fn initContext(key: [8]u32, d: [4]u32) BlockVec { |
| 337 | const c = "expand 32-byte k"; | 337 | const c = "expand 32-byte k"; |
| 338 | const constant_le = comptime [4]u32{ | 338 | const constant_le = comptime [4]u32{ |
| 339 | mem.readInt(u32, c[0..4], .Little), | 339 | mem.readInt(u32, c[0..4], .little), |
| 340 | mem.readInt(u32, c[4..8], .Little), | 340 | mem.readInt(u32, c[4..8], .little), |
| 341 | mem.readInt(u32, c[8..12], .Little), | 341 | mem.readInt(u32, c[8..12], .little), |
| 342 | mem.readInt(u32, c[12..16], .Little), | 342 | mem.readInt(u32, c[12..16], .little), |
| 343 | }; | 343 | }; |
| 344 | return BlockVec{ | 344 | return BlockVec{ |
| 345 | constant_le[0], constant_le[1], constant_le[2], constant_le[3], | 345 | constant_le[0], constant_le[1], constant_le[2], constant_le[3], |
| ... | @@ -396,10 +396,10 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type { | ... | @@ -396,10 +396,10 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type { |
| 396 | 396 | ||
| 397 | inline fn hashToBytes(out: *[64]u8, x: BlockVec) void { | 397 | inline fn hashToBytes(out: *[64]u8, x: BlockVec) void { |
| 398 | for (0..4) |i| { | 398 | for (0..4) |i| { |
| 399 | mem.writeInt(u32, out[16 * i + 0 ..][0..4], x[i * 4 + 0], .Little); | 399 | mem.writeInt(u32, out[16 * i + 0 ..][0..4], x[i * 4 + 0], .little); |
| 400 | mem.writeInt(u32, out[16 * i + 4 ..][0..4], x[i * 4 + 1], .Little); | 400 | mem.writeInt(u32, out[16 * i + 4 ..][0..4], x[i * 4 + 1], .little); |
| 401 | mem.writeInt(u32, out[16 * i + 8 ..][0..4], x[i * 4 + 2], .Little); | 401 | mem.writeInt(u32, out[16 * i + 8 ..][0..4], x[i * 4 + 2], .little); |
| 402 | mem.writeInt(u32, out[16 * i + 12 ..][0..4], x[i * 4 + 3], .Little); | 402 | mem.writeInt(u32, out[16 * i + 12 ..][0..4], x[i * 4 + 3], .little); |
| 403 | } | 403 | } |
| 404 | } | 404 | } |
| 405 | 405 | ||
| ... | @@ -477,20 +477,20 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type { | ... | @@ -477,20 +477,20 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type { |
| 477 | fn hchacha20(input: [16]u8, key: [32]u8) [32]u8 { | 477 | fn hchacha20(input: [16]u8, key: [32]u8) [32]u8 { |
| 478 | var c: [4]u32 = undefined; | 478 | var c: [4]u32 = undefined; |
| 479 | for (c, 0..) |_, i| { | 479 | for (c, 0..) |_, i| { |
| 480 | c[i] = mem.readInt(u32, input[4 * i ..][0..4], .Little); | 480 | c[i] = mem.readInt(u32, input[4 * i ..][0..4], .little); |
| 481 | } | 481 | } |
| 482 | const ctx = initContext(keyToWords(key), c); | 482 | const ctx = initContext(keyToWords(key), c); |
| 483 | var x: BlockVec = undefined; | 483 | var x: BlockVec = undefined; |
| 484 | chacha20Core(x[0..], ctx); | 484 | chacha20Core(x[0..], ctx); |
| 485 | var out: [32]u8 = undefined; | 485 | var out: [32]u8 = undefined; |
| 486 | mem.writeInt(u32, out[0..4], x[0], .Little); | 486 | mem.writeInt(u32, out[0..4], x[0], .little); |
| 487 | mem.writeInt(u32, out[4..8], x[1], .Little); | 487 | mem.writeInt(u32, out[4..8], x[1], .little); |
| 488 | mem.writeInt(u32, out[8..12], x[2], .Little); | 488 | mem.writeInt(u32, out[8..12], x[2], .little); |
| 489 | mem.writeInt(u32, out[12..16], x[3], .Little); | 489 | mem.writeInt(u32, out[12..16], x[3], .little); |
| 490 | mem.writeInt(u32, out[16..20], x[12], .Little); | 490 | mem.writeInt(u32, out[16..20], x[12], .little); |
| 491 | mem.writeInt(u32, out[20..24], x[13], .Little); | 491 | mem.writeInt(u32, out[20..24], x[13], .little); |
| 492 | mem.writeInt(u32, out[24..28], x[14], .Little); | 492 | mem.writeInt(u32, out[24..28], x[14], .little); |
| 493 | mem.writeInt(u32, out[28..32], x[15], .Little); | 493 | mem.writeInt(u32, out[28..32], x[15], .little); |
| 494 | return out; | 494 | return out; |
| 495 | } | 495 | } |
| 496 | }; | 496 | }; |
| ... | @@ -519,7 +519,7 @@ fn ChaChaImpl(comptime rounds_nb: usize) type { | ... | @@ -519,7 +519,7 @@ fn ChaChaImpl(comptime rounds_nb: usize) type { |
| 519 | fn keyToWords(key: [32]u8) [8]u32 { | 519 | fn keyToWords(key: [32]u8) [8]u32 { |
| 520 | var k: [8]u32 = undefined; | 520 | var k: [8]u32 = undefined; |
| 521 | for (0..8) |i| { | 521 | for (0..8) |i| { |
| 522 | k[i] = mem.readInt(u32, key[i * 4 ..][0..4], .Little); | 522 | k[i] = mem.readInt(u32, key[i * 4 ..][0..4], .little); |
| 523 | } | 523 | } |
| 524 | return k; | 524 | return k; |
| 525 | } | 525 | } |
| ... | @@ -552,9 +552,9 @@ fn ChaChaIETF(comptime rounds_nb: usize) type { | ... | @@ -552,9 +552,9 @@ fn ChaChaIETF(comptime rounds_nb: usize) type { |
| 552 | 552 | ||
| 553 | var d: [4]u32 = undefined; | 553 | var d: [4]u32 = undefined; |
| 554 | d[0] = counter; | 554 | d[0] = counter; |
| 555 | d[1] = mem.readInt(u32, nonce[0..4], .Little); | 555 | d[1] = mem.readInt(u32, nonce[0..4], .little); |
| 556 | d[2] = mem.readInt(u32, nonce[4..8], .Little); | 556 | d[2] = mem.readInt(u32, nonce[4..8], .little); |
| 557 | d[3] = mem.readInt(u32, nonce[8..12], .Little); | 557 | d[3] = mem.readInt(u32, nonce[8..12], .little); |
| 558 | ChaChaImpl(rounds_nb).chacha20Xor(out, in, keyToWords(key), d, false); | 558 | ChaChaImpl(rounds_nb).chacha20Xor(out, in, keyToWords(key), d, false); |
| 559 | } | 559 | } |
| 560 | 560 | ||
| ... | @@ -564,9 +564,9 @@ fn ChaChaIETF(comptime rounds_nb: usize) type { | ... | @@ -564,9 +564,9 @@ fn ChaChaIETF(comptime rounds_nb: usize) type { |
| 564 | 564 | ||
| 565 | var d: [4]u32 = undefined; | 565 | var d: [4]u32 = undefined; |
| 566 | d[0] = counter; | 566 | d[0] = counter; |
| 567 | d[1] = mem.readInt(u32, nonce[0..4], .Little); | 567 | d[1] = mem.readInt(u32, nonce[0..4], .little); |
| 568 | d[2] = mem.readInt(u32, nonce[4..8], .Little); | 568 | d[2] = mem.readInt(u32, nonce[4..8], .little); |
| 569 | d[3] = mem.readInt(u32, nonce[8..12], .Little); | 569 | d[3] = mem.readInt(u32, nonce[8..12], .little); |
| 570 | ChaChaImpl(rounds_nb).chacha20Stream(out, keyToWords(key), d, false); | 570 | ChaChaImpl(rounds_nb).chacha20Stream(out, keyToWords(key), d, false); |
| 571 | } | 571 | } |
| 572 | }; | 572 | }; |
| ... | @@ -592,8 +592,8 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type { | ... | @@ -592,8 +592,8 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type { |
| 592 | var c: [4]u32 = undefined; | 592 | var c: [4]u32 = undefined; |
| 593 | c[0] = @as(u32, @truncate(counter)); | 593 | c[0] = @as(u32, @truncate(counter)); |
| 594 | c[1] = @as(u32, @truncate(counter >> 32)); | 594 | c[1] = @as(u32, @truncate(counter >> 32)); |
| 595 | c[2] = mem.readInt(u32, nonce[0..4], .Little); | 595 | c[2] = mem.readInt(u32, nonce[0..4], .little); |
| 596 | c[3] = mem.readInt(u32, nonce[4..8], .Little); | 596 | c[3] = mem.readInt(u32, nonce[4..8], .little); |
| 597 | ChaChaImpl(rounds_nb).chacha20Xor(out, in, k, c, true); | 597 | ChaChaImpl(rounds_nb).chacha20Xor(out, in, k, c, true); |
| 598 | } | 598 | } |
| 599 | 599 | ||
| ... | @@ -605,8 +605,8 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type { | ... | @@ -605,8 +605,8 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type { |
| 605 | var c: [4]u32 = undefined; | 605 | var c: [4]u32 = undefined; |
| 606 | c[0] = @as(u32, @truncate(counter)); | 606 | c[0] = @as(u32, @truncate(counter)); |
| 607 | c[1] = @as(u32, @truncate(counter >> 32)); | 607 | c[1] = @as(u32, @truncate(counter >> 32)); |
| 608 | c[2] = mem.readInt(u32, nonce[0..4], .Little); | 608 | c[2] = mem.readInt(u32, nonce[0..4], .little); |
| 609 | c[3] = mem.readInt(u32, nonce[4..8], .Little); | 609 | c[3] = mem.readInt(u32, nonce[4..8], .little); |
| 610 | ChaChaImpl(rounds_nb).chacha20Stream(out, k, c, true); | 610 | ChaChaImpl(rounds_nb).chacha20Stream(out, k, c, true); |
| 611 | } | 611 | } |
| 612 | }; | 612 | }; |
| ... | @@ -672,8 +672,8 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { | ... | @@ -672,8 +672,8 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { |
| 672 | mac.update(zeros[0..padding]); | 672 | mac.update(zeros[0..padding]); |
| 673 | } | 673 | } |
| 674 | var lens: [16]u8 = undefined; | 674 | var lens: [16]u8 = undefined; |
| 675 | mem.writeInt(u64, lens[0..8], ad.len, .Little); | 675 | mem.writeInt(u64, lens[0..8], ad.len, .little); |
| 676 | mem.writeInt(u64, lens[8..16], m.len, .Little); | 676 | mem.writeInt(u64, lens[8..16], m.len, .little); |
| 677 | mac.update(lens[0..]); | 677 | mac.update(lens[0..]); |
| 678 | mac.final(tag); | 678 | mac.final(tag); |
| 679 | } | 679 | } |
| ... | @@ -708,8 +708,8 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { | ... | @@ -708,8 +708,8 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { |
| 708 | mac.update(zeros[0..padding]); | 708 | mac.update(zeros[0..padding]); |
| 709 | } | 709 | } |
| 710 | var lens: [16]u8 = undefined; | 710 | var lens: [16]u8 = undefined; |
| 711 | mem.writeInt(u64, lens[0..8], ad.len, .Little); | 711 | mem.writeInt(u64, lens[0..8], ad.len, .little); |
| 712 | mem.writeInt(u64, lens[8..16], c.len, .Little); | 712 | mem.writeInt(u64, lens[8..16], c.len, .little); |
| 713 | mac.update(lens[0..]); | 713 | mac.update(lens[0..]); |
| 714 | var computed_tag: [16]u8 = undefined; | 714 | var computed_tag: [16]u8 = undefined; |
| 715 | mac.final(computed_tag[0..]); | 715 | mac.final(computed_tag[0..]); |
lib/std/crypto/cmac.zig+2-2| ... | @@ -76,7 +76,7 @@ pub fn Cmac(comptime BlockCipher: type) type { | ... | @@ -76,7 +76,7 @@ pub fn Cmac(comptime BlockCipher: type) type { |
| 76 | 76 | ||
| 77 | fn double(l: Block) Block { | 77 | fn double(l: Block) Block { |
| 78 | const Int = std.meta.Int(.unsigned, block_length * 8); | 78 | const Int = std.meta.Int(.unsigned, block_length * 8); |
| 79 | const l_ = mem.readInt(Int, &l, .Big); | 79 | const l_ = mem.readInt(Int, &l, .big); |
| 80 | const l_2 = switch (block_length) { | 80 | const l_2 = switch (block_length) { |
| 81 | 8 => (l_ << 1) ^ (0x1b & -%(l_ >> 63)), // mod x^64 + x^4 + x^3 + x + 1 | 81 | 8 => (l_ << 1) ^ (0x1b & -%(l_ >> 63)), // mod x^64 + x^4 + x^3 + x + 1 |
| 82 | 16 => (l_ << 1) ^ (0x87 & -%(l_ >> 127)), // mod x^128 + x^7 + x^2 + x + 1 | 82 | 16 => (l_ << 1) ^ (0x87 & -%(l_ >> 127)), // mod x^128 + x^7 + x^2 + x + 1 |
| ... | @@ -85,7 +85,7 @@ pub fn Cmac(comptime BlockCipher: type) type { | ... | @@ -85,7 +85,7 @@ pub fn Cmac(comptime BlockCipher: type) type { |
| 85 | else => @compileError("unsupported block length"), | 85 | else => @compileError("unsupported block length"), |
| 86 | }; | 86 | }; |
| 87 | var l2: Block = undefined; | 87 | var l2: Block = undefined; |
| 88 | mem.writeInt(Int, &l2, l_2, .Big); | 88 | mem.writeInt(Int, &l2, l_2, .big); |
| 89 | return l2; | 89 | return l2; |
| 90 | } | 90 | } |
| 91 | }; | 91 | }; |
lib/std/crypto/ecdsa.zig+16-16| ... | @@ -209,17 +209,17 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { | ... | @@ -209,17 +209,17 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { |
| 209 | 209 | ||
| 210 | const k = deterministicScalar(h_slice.*, self.secret_key.bytes, self.noise); | 210 | const k = deterministicScalar(h_slice.*, self.secret_key.bytes, self.noise); |
| 211 | 211 | ||
| 212 | const p = try Curve.basePoint.mul(k.toBytes(.Big), .Big); | 212 | const p = try Curve.basePoint.mul(k.toBytes(.big), .big); |
| 213 | const xs = p.affineCoordinates().x.toBytes(.Big); | 213 | const xs = p.affineCoordinates().x.toBytes(.big); |
| 214 | const r = reduceToScalar(Curve.Fe.encoded_length, xs); | 214 | const r = reduceToScalar(Curve.Fe.encoded_length, xs); |
| 215 | if (r.isZero()) return error.IdentityElement; | 215 | if (r.isZero()) return error.IdentityElement; |
| 216 | 216 | ||
| 217 | const k_inv = k.invert(); | 217 | const k_inv = k.invert(); |
| 218 | const zrs = z.add(r.mul(try Curve.scalar.Scalar.fromBytes(self.secret_key.bytes, .Big))); | 218 | const zrs = z.add(r.mul(try Curve.scalar.Scalar.fromBytes(self.secret_key.bytes, .big))); |
| 219 | const s = k_inv.mul(zrs); | 219 | const s = k_inv.mul(zrs); |
| 220 | if (s.isZero()) return error.IdentityElement; | 220 | if (s.isZero()) return error.IdentityElement; |
| 221 | 221 | ||
| 222 | return Signature{ .r = r.toBytes(.Big), .s = s.toBytes(.Big) }; | 222 | return Signature{ .r = r.toBytes(.big), .s = s.toBytes(.big) }; |
| 223 | } | 223 | } |
| 224 | }; | 224 | }; |
| 225 | 225 | ||
| ... | @@ -232,8 +232,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { | ... | @@ -232,8 +232,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { |
| 232 | public_key: PublicKey, | 232 | public_key: PublicKey, |
| 233 | 233 | ||
| 234 | fn init(sig: Signature, public_key: PublicKey) (IdentityElementError || NonCanonicalError)!Verifier { | 234 | fn init(sig: Signature, public_key: PublicKey) (IdentityElementError || NonCanonicalError)!Verifier { |
| 235 | const r = try Curve.scalar.Scalar.fromBytes(sig.r, .Big); | 235 | const r = try Curve.scalar.Scalar.fromBytes(sig.r, .big); |
| 236 | const s = try Curve.scalar.Scalar.fromBytes(sig.s, .Big); | 236 | const s = try Curve.scalar.Scalar.fromBytes(sig.s, .big); |
| 237 | if (r.isZero() or s.isZero()) return error.IdentityElement; | 237 | if (r.isZero() or s.isZero()) return error.IdentityElement; |
| 238 | 238 | ||
| 239 | return Verifier{ | 239 | return Verifier{ |
| ... | @@ -262,11 +262,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { | ... | @@ -262,11 +262,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { |
| 262 | } | 262 | } |
| 263 | 263 | ||
| 264 | const s_inv = self.s.invert(); | 264 | const s_inv = self.s.invert(); |
| 265 | const v1 = z.mul(s_inv).toBytes(.Little); | 265 | const v1 = z.mul(s_inv).toBytes(.little); |
| 266 | const v2 = self.r.mul(s_inv).toBytes(.Little); | 266 | const v2 = self.r.mul(s_inv).toBytes(.little); |
| 267 | const v1g = try Curve.basePoint.mulPublic(v1, .Little); | 267 | const v1g = try Curve.basePoint.mulPublic(v1, .little); |
| 268 | const v2pk = try self.public_key.p.mulPublic(v2, .Little); | 268 | const v2pk = try self.public_key.p.mulPublic(v2, .little); |
| 269 | const vxs = v1g.add(v2pk).affineCoordinates().x.toBytes(.Big); | 269 | const vxs = v1g.add(v2pk).affineCoordinates().x.toBytes(.big); |
| 270 | const vr = reduceToScalar(Curve.Fe.encoded_length, vxs); | 270 | const vr = reduceToScalar(Curve.Fe.encoded_length, vxs); |
| 271 | if (!self.r.equivalent(vr)) { | 271 | if (!self.r.equivalent(vr)) { |
| 272 | return error.SignatureVerificationFailed; | 272 | return error.SignatureVerificationFailed; |
| ... | @@ -295,13 +295,13 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { | ... | @@ -295,13 +295,13 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { |
| 295 | } | 295 | } |
| 296 | const h = [_]u8{0x00} ** Hash.digest_length; | 296 | const h = [_]u8{0x00} ** Hash.digest_length; |
| 297 | const k0 = [_]u8{0x01} ** SecretKey.encoded_length; | 297 | const k0 = [_]u8{0x01} ** SecretKey.encoded_length; |
| 298 | const secret_key = deterministicScalar(h, k0, seed_).toBytes(.Big); | 298 | const secret_key = deterministicScalar(h, k0, seed_).toBytes(.big); |
| 299 | return fromSecretKey(SecretKey{ .bytes = secret_key }); | 299 | return fromSecretKey(SecretKey{ .bytes = secret_key }); |
| 300 | } | 300 | } |
| 301 | 301 | ||
| 302 | /// Return the public key corresponding to the secret key. | 302 | /// Return the public key corresponding to the secret key. |
| 303 | pub fn fromSecretKey(secret_key: SecretKey) IdentityElementError!KeyPair { | 303 | pub fn fromSecretKey(secret_key: SecretKey) IdentityElementError!KeyPair { |
| 304 | const public_key = try Curve.basePoint.mul(secret_key.bytes, .Big); | 304 | const public_key = try Curve.basePoint.mul(secret_key.bytes, .big); |
| 305 | return KeyPair{ .secret_key = secret_key, .public_key = PublicKey{ .p = public_key } }; | 305 | return KeyPair{ .secret_key = secret_key, .public_key = PublicKey{ .p = public_key } }; |
| 306 | } | 306 | } |
| 307 | 307 | ||
| ... | @@ -326,11 +326,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { | ... | @@ -326,11 +326,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { |
| 326 | if (unreduced_len >= 48) { | 326 | if (unreduced_len >= 48) { |
| 327 | var xs = [_]u8{0} ** 64; | 327 | var xs = [_]u8{0} ** 64; |
| 328 | @memcpy(xs[xs.len - s.len ..], s[0..]); | 328 | @memcpy(xs[xs.len - s.len ..], s[0..]); |
| 329 | return Curve.scalar.Scalar.fromBytes64(xs, .Big); | 329 | return Curve.scalar.Scalar.fromBytes64(xs, .big); |
| 330 | } | 330 | } |
| 331 | var xs = [_]u8{0} ** 48; | 331 | var xs = [_]u8{0} ** 48; |
| 332 | @memcpy(xs[xs.len - s.len ..], s[0..]); | 332 | @memcpy(xs[xs.len - s.len ..], s[0..]); |
| 333 | return Curve.scalar.Scalar.fromBytes48(xs, .Big); | 333 | return Curve.scalar.Scalar.fromBytes48(xs, .big); |
| 334 | } | 334 | } |
| 335 | 335 | ||
| 336 | // Create a deterministic scalar according to a secret key and optional noise. | 336 | // Create a deterministic scalar according to a secret key and optional noise. |
| ... | @@ -362,7 +362,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { | ... | @@ -362,7 +362,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { |
| 362 | Hmac.create(m_v, m_v, &k); | 362 | Hmac.create(m_v, m_v, &k); |
| 363 | @memcpy(t[t_off..t_end], m_v[0 .. t_end - t_off]); | 363 | @memcpy(t[t_off..t_end], m_v[0 .. t_end - t_off]); |
| 364 | } | 364 | } |
| 365 | if (Curve.scalar.Scalar.fromBytes(t, .Big)) |s| return s else |_| {} | 365 | if (Curve.scalar.Scalar.fromBytes(t, .big)) |s| return s else |_| {} |
| 366 | m_i.* = 0x00; | 366 | m_i.* = 0x00; |
| 367 | Hmac.create(&k, m[0 .. m_v.len + 1], &k); | 367 | Hmac.create(&k, m[0 .. m_v.len + 1], &k); |
| 368 | Hmac.create(m_v, m_v, &k); | 368 | Hmac.create(m_v, m_v, &k); |
lib/std/crypto/ff.zig+20-20| ... | @@ -137,8 +137,8 @@ pub fn Uint(comptime max_bits: comptime_int) type { | ... | @@ -137,8 +137,8 @@ pub fn Uint(comptime max_bits: comptime_int) type { |
| 137 | @memset(bytes, 0); | 137 | @memset(bytes, 0); |
| 138 | var shift: usize = 0; | 138 | var shift: usize = 0; |
| 139 | var out_i: usize = switch (endian) { | 139 | var out_i: usize = switch (endian) { |
| 140 | .Big => bytes.len - 1, | 140 | .big => bytes.len - 1, |
| 141 | .Little => 0, | 141 | .little => 0, |
| 142 | }; | 142 | }; |
| 143 | for (0..self.limbs.len) |i| { | 143 | for (0..self.limbs.len) |i| { |
| 144 | var remaining_bits = t_bits; | 144 | var remaining_bits = t_bits; |
| ... | @@ -150,7 +150,7 @@ pub fn Uint(comptime max_bits: comptime_int) type { | ... | @@ -150,7 +150,7 @@ pub fn Uint(comptime max_bits: comptime_int) type { |
| 150 | remaining_bits -= consumed; | 150 | remaining_bits -= consumed; |
| 151 | shift = 0; | 151 | shift = 0; |
| 152 | switch (endian) { | 152 | switch (endian) { |
| 153 | .Big => { | 153 | .big => { |
| 154 | if (out_i == 0) { | 154 | if (out_i == 0) { |
| 155 | if (i != self.limbs.len - 1 or limb != 0) { | 155 | if (i != self.limbs.len - 1 or limb != 0) { |
| 156 | return error.Overflow; | 156 | return error.Overflow; |
| ... | @@ -159,7 +159,7 @@ pub fn Uint(comptime max_bits: comptime_int) type { | ... | @@ -159,7 +159,7 @@ pub fn Uint(comptime max_bits: comptime_int) type { |
| 159 | } | 159 | } |
| 160 | out_i -= 1; | 160 | out_i -= 1; |
| 161 | }, | 161 | }, |
| 162 | .Little => { | 162 | .little => { |
| 163 | out_i += 1; | 163 | out_i += 1; |
| 164 | if (out_i == bytes.len) { | 164 | if (out_i == bytes.len) { |
| 165 | if (i != self.limbs.len - 1 or limb != 0) { | 165 | if (i != self.limbs.len - 1 or limb != 0) { |
| ... | @@ -182,8 +182,8 @@ pub fn Uint(comptime max_bits: comptime_int) type { | ... | @@ -182,8 +182,8 @@ pub fn Uint(comptime max_bits: comptime_int) type { |
| 182 | var out = Self.zero; | 182 | var out = Self.zero; |
| 183 | var out_i: usize = 0; | 183 | var out_i: usize = 0; |
| 184 | var i: usize = switch (endian) { | 184 | var i: usize = switch (endian) { |
| 185 | .Big => bytes.len - 1, | 185 | .big => bytes.len - 1, |
| 186 | .Little => 0, | 186 | .little => 0, |
| 187 | }; | 187 | }; |
| 188 | while (true) { | 188 | while (true) { |
| 189 | const bi = bytes[i]; | 189 | const bi = bytes[i]; |
| ... | @@ -203,11 +203,11 @@ pub fn Uint(comptime max_bits: comptime_int) type { | ... | @@ -203,11 +203,11 @@ pub fn Uint(comptime max_bits: comptime_int) type { |
| 203 | out.limbs.set(out_i, overflow); | 203 | out.limbs.set(out_i, overflow); |
| 204 | } | 204 | } |
| 205 | switch (endian) { | 205 | switch (endian) { |
| 206 | .Big => { | 206 | .big => { |
| 207 | if (i == 0) break; | 207 | if (i == 0) break; |
| 208 | i -= 1; | 208 | i -= 1; |
| 209 | }, | 209 | }, |
| 210 | .Little => { | 210 | .little => { |
| 211 | i += 1; | 211 | i += 1; |
| 212 | if (i == bytes.len) break; | 212 | if (i == bytes.len) break; |
| 213 | }, | 213 | }, |
| ... | @@ -227,7 +227,7 @@ pub fn Uint(comptime max_bits: comptime_int) type { | ... | @@ -227,7 +227,7 @@ pub fn Uint(comptime max_bits: comptime_int) type { |
| 227 | Limb, | 227 | Limb, |
| 228 | x.limbs.constSlice(), | 228 | x.limbs.constSlice(), |
| 229 | y.limbs.constSlice(), | 229 | y.limbs.constSlice(), |
| 230 | .Little, | 230 | .little, |
| 231 | ); | 231 | ); |
| 232 | } | 232 | } |
| 233 | 233 | ||
| ... | @@ -667,15 +667,15 @@ pub fn Modulus(comptime max_bits: comptime_int) type { | ... | @@ -667,15 +667,15 @@ pub fn Modulus(comptime max_bits: comptime_int) type { |
| 667 | var out = self.one(); | 667 | var out = self.one(); |
| 668 | self.toMontgomery(&out) catch unreachable; | 668 | self.toMontgomery(&out) catch unreachable; |
| 669 | 669 | ||
| 670 | if (public and e.len < 3 or (e.len == 3 and e[if (endian == .Big) 0 else 2] <= 0b1111)) { | 670 | if (public and e.len < 3 or (e.len == 3 and e[if (endian == .big) 0 else 2] <= 0b1111)) { |
| 671 | // Do not use a precomputation table for short, public exponents | 671 | // Do not use a precomputation table for short, public exponents |
| 672 | var x_m = x; | 672 | var x_m = x; |
| 673 | if (x.montgomery == false) { | 673 | if (x.montgomery == false) { |
| 674 | self.toMontgomery(&x_m) catch unreachable; | 674 | self.toMontgomery(&x_m) catch unreachable; |
| 675 | } | 675 | } |
| 676 | var s = switch (endian) { | 676 | var s = switch (endian) { |
| 677 | .Big => 0, | 677 | .big => 0, |
| 678 | .Little => e.len - 1, | 678 | .little => e.len - 1, |
| 679 | }; | 679 | }; |
| 680 | while (true) { | 680 | while (true) { |
| 681 | const b = e[s]; | 681 | const b = e[s]; |
| ... | @@ -690,11 +690,11 @@ pub fn Modulus(comptime max_bits: comptime_int) type { | ... | @@ -690,11 +690,11 @@ pub fn Modulus(comptime max_bits: comptime_int) type { |
| 690 | if (j == 0) break; | 690 | if (j == 0) break; |
| 691 | } | 691 | } |
| 692 | switch (endian) { | 692 | switch (endian) { |
| 693 | .Big => { | 693 | .big => { |
| 694 | s += 1; | 694 | s += 1; |
| 695 | if (s == e.len) break; | 695 | if (s == e.len) break; |
| 696 | }, | 696 | }, |
| 697 | .Little => { | 697 | .little => { |
| 698 | if (s == 0) break; | 698 | if (s == 0) break; |
| 699 | s -= 1; | 699 | s -= 1; |
| 700 | }, | 700 | }, |
| ... | @@ -711,8 +711,8 @@ pub fn Modulus(comptime max_bits: comptime_int) type { | ... | @@ -711,8 +711,8 @@ pub fn Modulus(comptime max_bits: comptime_int) type { |
| 711 | } | 711 | } |
| 712 | var t0 = self.zero; | 712 | var t0 = self.zero; |
| 713 | var s = switch (endian) { | 713 | var s = switch (endian) { |
| 714 | .Big => 0, | 714 | .big => 0, |
| 715 | .Little => e.len - 1, | 715 | .little => e.len - 1, |
| 716 | }; | 716 | }; |
| 717 | while (true) { | 717 | while (true) { |
| 718 | const b = e[s]; | 718 | const b = e[s]; |
| ... | @@ -737,11 +737,11 @@ pub fn Modulus(comptime max_bits: comptime_int) type { | ... | @@ -737,11 +737,11 @@ pub fn Modulus(comptime max_bits: comptime_int) type { |
| 737 | } | 737 | } |
| 738 | } | 738 | } |
| 739 | switch (endian) { | 739 | switch (endian) { |
| 740 | .Big => { | 740 | .big => { |
| 741 | s += 1; | 741 | s += 1; |
| 742 | if (s == e.len) break; | 742 | if (s == e.len) break; |
| 743 | }, | 743 | }, |
| 744 | .Little => { | 744 | .little => { |
| 745 | if (s == 0) break; | 745 | if (s == 0) break; |
| 746 | s -= 1; | 746 | s -= 1; |
| 747 | }, | 747 | }, |
| ... | @@ -791,10 +791,10 @@ pub fn Modulus(comptime max_bits: comptime_int) type { | ... | @@ -791,10 +791,10 @@ pub fn Modulus(comptime max_bits: comptime_int) type { |
| 791 | var e_normalized = Fe{ .v = e.v.normalize() }; | 791 | var e_normalized = Fe{ .v = e.v.normalize() }; |
| 792 | var buf_: [Fe.encoded_bytes]u8 = undefined; | 792 | var buf_: [Fe.encoded_bytes]u8 = undefined; |
| 793 | var buf = buf_[0 .. math.divCeil(usize, e_normalized.v.limbs_count() * t_bits, 8) catch unreachable]; | 793 | var buf = buf_[0 .. math.divCeil(usize, e_normalized.v.limbs_count() * t_bits, 8) catch unreachable]; |
| 794 | e_normalized.toBytes(buf, .Little) catch unreachable; | 794 | e_normalized.toBytes(buf, .little) catch unreachable; |
| 795 | const leading = @clz(e_normalized.v.limbs.get(e_normalized.v.limbs_count() - carry_bits)); | 795 | const leading = @clz(e_normalized.v.limbs.get(e_normalized.v.limbs_count() - carry_bits)); |
| 796 | buf = buf[0 .. buf.len - leading / 8]; | 796 | buf = buf[0 .. buf.len - leading / 8]; |
| 797 | return self.powWithEncodedPublicExponent(x, buf, .Little); | 797 | return self.powWithEncodedPublicExponent(x, buf, .little); |
| 798 | } | 798 | } |
| 799 | 799 | ||
| 800 | /// Returns x^e (mod m), with the exponent provided as a byte string. | 800 | /// Returns x^e (mod m), with the exponent provided as a byte string. |
lib/std/crypto/ghash_polyval.zig+2-2| ... | @@ -13,7 +13,7 @@ const Precomp = u128; | ... | @@ -13,7 +13,7 @@ const Precomp = u128; |
| 13 | /// It is not a general purpose hash function - The key must be secret, unpredictable and never reused. | 13 | /// It is not a general purpose hash function - The key must be secret, unpredictable and never reused. |
| 14 | /// | 14 | /// |
| 15 | /// GHASH is typically used to compute the authentication tag in the AES-GCM construction. | 15 | /// GHASH is typically used to compute the authentication tag in the AES-GCM construction. |
| 16 | pub const Ghash = Hash(.Big, true); | 16 | pub const Ghash = Hash(.big, true); |
| 17 | 17 | ||
| 18 | /// POLYVAL is a universal hash function that uses multiplication by a fixed | 18 | /// POLYVAL is a universal hash function that uses multiplication by a fixed |
| 19 | /// parameter within a Galois field. | 19 | /// parameter within a Galois field. |
| ... | @@ -21,7 +21,7 @@ pub const Ghash = Hash(.Big, true); | ... | @@ -21,7 +21,7 @@ pub const Ghash = Hash(.Big, true); |
| 21 | /// It is not a general purpose hash function - The key must be secret, unpredictable and never reused. | 21 | /// It is not a general purpose hash function - The key must be secret, unpredictable and never reused. |
| 22 | /// | 22 | /// |
| 23 | /// POLYVAL is typically used to compute the authentication tag in the AES-GCM-SIV construction. | 23 | /// POLYVAL is typically used to compute the authentication tag in the AES-GCM-SIV construction. |
| 24 | pub const Polyval = Hash(.Little, false); | 24 | pub const Polyval = Hash(.little, false); |
| 25 | 25 | ||
| 26 | fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { | 26 | fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { |
| 27 | return struct { | 27 | return struct { |
lib/std/crypto/isap.zig+12-12| ... | @@ -4,7 +4,7 @@ const debug = std.debug; | ... | @@ -4,7 +4,7 @@ const debug = std.debug; |
| 4 | const mem = std.mem; | 4 | const mem = std.mem; |
| 5 | const math = std.math; | 5 | const math = std.math; |
| 6 | const testing = std.testing; | 6 | const testing = std.testing; |
| 7 | const Ascon = crypto.core.Ascon(.Big); | 7 | const Ascon = crypto.core.Ascon(.big); |
| 8 | const AuthenticationError = crypto.errors.AuthenticationError; | 8 | const AuthenticationError = crypto.errors.AuthenticationError; |
| 9 | 9 | ||
| 10 | /// ISAPv2 is an authenticated encryption system hardened against side channels and fault attacks. | 10 | /// ISAPv2 is an authenticated encryption system hardened against side channels and fault attacks. |
| ... | @@ -55,9 +55,9 @@ pub const IsapA128A = struct { | ... | @@ -55,9 +55,9 @@ pub const IsapA128A = struct { |
| 55 | fn trickle(k: [16]u8, iv: [8]u8, y: []const u8, comptime out_len: usize) [out_len]u8 { | 55 | fn trickle(k: [16]u8, iv: [8]u8, y: []const u8, comptime out_len: usize) [out_len]u8 { |
| 56 | var isap = IsapA128A{ | 56 | var isap = IsapA128A{ |
| 57 | .st = Ascon.initFromWords(.{ | 57 | .st = Ascon.initFromWords(.{ |
| 58 | mem.readInt(u64, k[0..8], .Big), | 58 | mem.readInt(u64, k[0..8], .big), |
| 59 | mem.readInt(u64, k[8..16], .Big), | 59 | mem.readInt(u64, k[8..16], .big), |
| 60 | mem.readInt(u64, iv[0..8], .Big), | 60 | mem.readInt(u64, iv[0..8], .big), |
| 61 | 0, | 61 | 0, |
| 62 | 0, | 62 | 0, |
| 63 | }), | 63 | }), |
| ... | @@ -85,9 +85,9 @@ pub const IsapA128A = struct { | ... | @@ -85,9 +85,9 @@ pub const IsapA128A = struct { |
| 85 | fn mac(c: []const u8, ad: []const u8, npub: [16]u8, key: [16]u8) [16]u8 { | 85 | fn mac(c: []const u8, ad: []const u8, npub: [16]u8, key: [16]u8) [16]u8 { |
| 86 | var isap = IsapA128A{ | 86 | var isap = IsapA128A{ |
| 87 | .st = Ascon.initFromWords(.{ | 87 | .st = Ascon.initFromWords(.{ |
| 88 | mem.readInt(u64, npub[0..8], .Big), | 88 | mem.readInt(u64, npub[0..8], .big), |
| 89 | mem.readInt(u64, npub[8..16], .Big), | 89 | mem.readInt(u64, npub[8..16], .big), |
| 90 | mem.readInt(u64, iv1[0..], .Big), | 90 | mem.readInt(u64, iv1[0..], .big), |
| 91 | 0, | 91 | 0, |
| 92 | 0, | 92 | 0, |
| 93 | }), | 93 | }), |
| ... | @@ -116,11 +116,11 @@ pub const IsapA128A = struct { | ... | @@ -116,11 +116,11 @@ pub const IsapA128A = struct { |
| 116 | const nb = trickle(key, iv3, npub[0..], 24); | 116 | const nb = trickle(key, iv3, npub[0..], 24); |
| 117 | var isap = IsapA128A{ | 117 | var isap = IsapA128A{ |
| 118 | .st = Ascon.initFromWords(.{ | 118 | .st = Ascon.initFromWords(.{ |
| 119 | mem.readInt(u64, nb[0..8], .Big), | 119 | mem.readInt(u64, nb[0..8], .big), |
| 120 | mem.readInt(u64, nb[8..16], .Big), | 120 | mem.readInt(u64, nb[8..16], .big), |
| 121 | mem.readInt(u64, nb[16..24], .Big), | 121 | mem.readInt(u64, nb[16..24], .big), |
| 122 | mem.readInt(u64, npub[0..8], .Big), | 122 | mem.readInt(u64, npub[0..8], .big), |
| 123 | mem.readInt(u64, npub[8..16], .Big), | 123 | mem.readInt(u64, npub[8..16], .big), |
| 124 | }), | 124 | }), |
| 125 | }; | 125 | }; |
| 126 | isap.st.permuteR(6); | 126 | isap.st.permuteR(6); |
lib/std/crypto/keccak_p.zig+7-7| ... | @@ -45,7 +45,7 @@ pub fn KeccakF(comptime f: u11) type { | ... | @@ -45,7 +45,7 @@ pub fn KeccakF(comptime f: u11) type { |
| 45 | pub fn init(bytes: [block_bytes]u8) Self { | 45 | pub fn init(bytes: [block_bytes]u8) Self { |
| 46 | var self: Self = undefined; | 46 | var self: Self = undefined; |
| 47 | inline for (&self.st, 0..) |*r, i| { | 47 | inline for (&self.st, 0..) |*r, i| { |
| 48 | r.* = mem.readInt(T, bytes[@sizeOf(T) * i ..][0..@sizeOf(T)], .Little); | 48 | r.* = mem.readInt(T, bytes[@sizeOf(T) * i ..][0..@sizeOf(T)], .little); |
| 49 | } | 49 | } |
| 50 | return self; | 50 | return self; |
| 51 | } | 51 | } |
| ... | @@ -66,12 +66,12 @@ pub fn KeccakF(comptime f: u11) type { | ... | @@ -66,12 +66,12 @@ pub fn KeccakF(comptime f: u11) type { |
| 66 | pub fn setBytes(self: *Self, bytes: []const u8) void { | 66 | pub fn setBytes(self: *Self, bytes: []const u8) void { |
| 67 | var i: usize = 0; | 67 | var i: usize = 0; |
| 68 | while (i + @sizeOf(T) <= bytes.len) : (i += @sizeOf(T)) { | 68 | while (i + @sizeOf(T) <= bytes.len) : (i += @sizeOf(T)) { |
| 69 | self.st[i / @sizeOf(T)] = mem.readInt(T, bytes[i..][0..@sizeOf(T)], .Little); | 69 | self.st[i / @sizeOf(T)] = mem.readInt(T, bytes[i..][0..@sizeOf(T)], .little); |
| 70 | } | 70 | } |
| 71 | if (i < bytes.len) { | 71 | if (i < bytes.len) { |
| 72 | var padded = [_]u8{0} ** @sizeOf(T); | 72 | var padded = [_]u8{0} ** @sizeOf(T); |
| 73 | @memcpy(padded[0 .. bytes.len - i], bytes[i..]); | 73 | @memcpy(padded[0 .. bytes.len - i], bytes[i..]); |
| 74 | self.st[i / @sizeOf(T)] = mem.readInt(T, padded[0..], .Little); | 74 | self.st[i / @sizeOf(T)] = mem.readInt(T, padded[0..], .little); |
| 75 | } | 75 | } |
| 76 | } | 76 | } |
| 77 | 77 | ||
| ... | @@ -85,12 +85,12 @@ pub fn KeccakF(comptime f: u11) type { | ... | @@ -85,12 +85,12 @@ pub fn KeccakF(comptime f: u11) type { |
| 85 | pub fn addBytes(self: *Self, bytes: []const u8) void { | 85 | pub fn addBytes(self: *Self, bytes: []const u8) void { |
| 86 | var i: usize = 0; | 86 | var i: usize = 0; |
| 87 | while (i + @sizeOf(T) <= bytes.len) : (i += @sizeOf(T)) { | 87 | while (i + @sizeOf(T) <= bytes.len) : (i += @sizeOf(T)) { |
| 88 | self.st[i / @sizeOf(T)] ^= mem.readInt(T, bytes[i..][0..@sizeOf(T)], .Little); | 88 | self.st[i / @sizeOf(T)] ^= mem.readInt(T, bytes[i..][0..@sizeOf(T)], .little); |
| 89 | } | 89 | } |
| 90 | if (i < bytes.len) { | 90 | if (i < bytes.len) { |
| 91 | var padded = [_]u8{0} ** @sizeOf(T); | 91 | var padded = [_]u8{0} ** @sizeOf(T); |
| 92 | @memcpy(padded[0 .. bytes.len - i], bytes[i..]); | 92 | @memcpy(padded[0 .. bytes.len - i], bytes[i..]); |
| 93 | self.st[i / @sizeOf(T)] ^= mem.readInt(T, padded[0..], .Little); | 93 | self.st[i / @sizeOf(T)] ^= mem.readInt(T, padded[0..], .little); |
| 94 | } | 94 | } |
| 95 | } | 95 | } |
| 96 | 96 | ||
| ... | @@ -98,11 +98,11 @@ pub fn KeccakF(comptime f: u11) type { | ... | @@ -98,11 +98,11 @@ pub fn KeccakF(comptime f: u11) type { |
| 98 | pub fn extractBytes(self: *Self, out: []u8) void { | 98 | pub fn extractBytes(self: *Self, out: []u8) void { |
| 99 | var i: usize = 0; | 99 | var i: usize = 0; |
| 100 | while (i + @sizeOf(T) <= out.len) : (i += @sizeOf(T)) { | 100 | while (i + @sizeOf(T) <= out.len) : (i += @sizeOf(T)) { |
| 101 | mem.writeInt(T, out[i..][0..@sizeOf(T)], self.st[i / @sizeOf(T)], .Little); | 101 | mem.writeInt(T, out[i..][0..@sizeOf(T)], self.st[i / @sizeOf(T)], .little); |
| 102 | } | 102 | } |
| 103 | if (i < out.len) { | 103 | if (i < out.len) { |
| 104 | var padded = [_]u8{0} ** @sizeOf(T); | 104 | var padded = [_]u8{0} ** @sizeOf(T); |
| 105 | mem.writeInt(T, padded[0..], self.st[i / @sizeOf(T)], .Little); | 105 | mem.writeInt(T, padded[0..], self.st[i / @sizeOf(T)], .little); |
| 106 | @memcpy(out[i..], padded[0 .. out.len - i]); | 106 | @memcpy(out[i..], padded[0 .. out.len - i]); |
| 107 | } | 107 | } |
| 108 | } | 108 | } |
lib/std/crypto/md5.zig+2-2| ... | @@ -112,7 +112,7 @@ pub const Md5 = struct { | ... | @@ -112,7 +112,7 @@ pub const Md5 = struct { |
| 112 | d.round(d.buf[0..]); | 112 | d.round(d.buf[0..]); |
| 113 | 113 | ||
| 114 | for (d.s, 0..) |s, j| { | 114 | for (d.s, 0..) |s, j| { |
| 115 | mem.writeInt(u32, out[4 * j ..][0..4], s, .Little); | 115 | mem.writeInt(u32, out[4 * j ..][0..4], s, .little); |
| 116 | } | 116 | } |
| 117 | } | 117 | } |
| 118 | 118 | ||
| ... | @@ -121,7 +121,7 @@ pub const Md5 = struct { | ... | @@ -121,7 +121,7 @@ pub const Md5 = struct { |
| 121 | 121 | ||
| 122 | var i: usize = 0; | 122 | var i: usize = 0; |
| 123 | while (i < 16) : (i += 1) { | 123 | while (i < 16) : (i += 1) { |
| 124 | s[i] = mem.readInt(u32, b[i * 4 ..][0..4], .Little); | 124 | s[i] = mem.readInt(u32, b[i * 4 ..][0..4], .little); |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | var v: [4]u32 = [_]u32{ | 127 | var v: [4]u32 = [_]u32{ |
lib/std/crypto/pcurves/common.zig+11-11| ... | @@ -51,13 +51,13 @@ pub fn Field(comptime params: FieldParams) type { | ... | @@ -51,13 +51,13 @@ pub fn Field(comptime params: FieldParams) type { |
| 51 | 51 | ||
| 52 | /// Reject non-canonical encodings of an element. | 52 | /// Reject non-canonical encodings of an element. |
| 53 | pub fn rejectNonCanonical(s_: [encoded_length]u8, endian: std.builtin.Endian) NonCanonicalError!void { | 53 | pub fn rejectNonCanonical(s_: [encoded_length]u8, endian: std.builtin.Endian) NonCanonicalError!void { |
| 54 | var s = if (endian == .Little) s_ else orderSwap(s_); | 54 | var s = if (endian == .little) s_ else orderSwap(s_); |
| 55 | const field_order_s = comptime fos: { | 55 | const field_order_s = comptime fos: { |
| 56 | var fos: [encoded_length]u8 = undefined; | 56 | var fos: [encoded_length]u8 = undefined; |
| 57 | mem.writeInt(std.meta.Int(.unsigned, encoded_length * 8), &fos, field_order, .Little); | 57 | mem.writeInt(std.meta.Int(.unsigned, encoded_length * 8), &fos, field_order, .little); |
| 58 | break :fos fos; | 58 | break :fos fos; |
| 59 | }; | 59 | }; |
| 60 | if (crypto.utils.timingSafeCompare(u8, &s, &field_order_s, .Little) != .lt) { | 60 | if (crypto.utils.timingSafeCompare(u8, &s, &field_order_s, .little) != .lt) { |
| 61 | return error.NonCanonical; | 61 | return error.NonCanonical; |
| 62 | } | 62 | } |
| 63 | } | 63 | } |
| ... | @@ -71,8 +71,8 @@ pub fn Field(comptime params: FieldParams) type { | ... | @@ -71,8 +71,8 @@ pub fn Field(comptime params: FieldParams) type { |
| 71 | 71 | ||
| 72 | /// Unpack a field element. | 72 | /// Unpack a field element. |
| 73 | pub fn fromBytes(s_: [encoded_length]u8, endian: std.builtin.Endian) NonCanonicalError!Fe { | 73 | pub fn fromBytes(s_: [encoded_length]u8, endian: std.builtin.Endian) NonCanonicalError!Fe { |
| 74 | var s = if (endian == .Little) s_ else orderSwap(s_); | 74 | var s = if (endian == .little) s_ else orderSwap(s_); |
| 75 | try rejectNonCanonical(s, .Little); | 75 | try rejectNonCanonical(s, .little); |
| 76 | var limbs_z: NonMontgomeryDomainFieldElement = undefined; | 76 | var limbs_z: NonMontgomeryDomainFieldElement = undefined; |
| 77 | fiat.fromBytes(&limbs_z, s); | 77 | fiat.fromBytes(&limbs_z, s); |
| 78 | var limbs: MontgomeryDomainFieldElement = undefined; | 78 | var limbs: MontgomeryDomainFieldElement = undefined; |
| ... | @@ -86,7 +86,7 @@ pub fn Field(comptime params: FieldParams) type { | ... | @@ -86,7 +86,7 @@ pub fn Field(comptime params: FieldParams) type { |
| 86 | fiat.fromMontgomery(&limbs_z, fe.limbs); | 86 | fiat.fromMontgomery(&limbs_z, fe.limbs); |
| 87 | var s: [encoded_length]u8 = undefined; | 87 | var s: [encoded_length]u8 = undefined; |
| 88 | fiat.toBytes(&s, limbs_z); | 88 | fiat.toBytes(&s, limbs_z); |
| 89 | return if (endian == .Little) s else orderSwap(s); | 89 | return if (endian == .little) s else orderSwap(s); |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | /// Element as an integer. | 92 | /// Element as an integer. |
| ... | @@ -95,14 +95,14 @@ pub fn Field(comptime params: FieldParams) type { | ... | @@ -95,14 +95,14 @@ pub fn Field(comptime params: FieldParams) type { |
| 95 | /// Create a field element from an integer. | 95 | /// Create a field element from an integer. |
| 96 | pub fn fromInt(comptime x: IntRepr) NonCanonicalError!Fe { | 96 | pub fn fromInt(comptime x: IntRepr) NonCanonicalError!Fe { |
| 97 | var s: [encoded_length]u8 = undefined; | 97 | var s: [encoded_length]u8 = undefined; |
| 98 | mem.writeInt(IntRepr, &s, x, .Little); | 98 | mem.writeInt(IntRepr, &s, x, .little); |
| 99 | return fromBytes(s, .Little); | 99 | return fromBytes(s, .little); |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | /// Return the field element as an integer. | 102 | /// Return the field element as an integer. |
| 103 | pub fn toInt(fe: Fe) IntRepr { | 103 | pub fn toInt(fe: Fe) IntRepr { |
| 104 | const s = fe.toBytes(.Little); | 104 | const s = fe.toBytes(.little); |
| 105 | return mem.readInt(IntRepr, &s, .Little); | 105 | return mem.readInt(IntRepr, &s, .little); |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | /// Return true if the field element is zero. | 108 | /// Return true if the field element is zero. |
| ... | @@ -119,7 +119,7 @@ pub fn Field(comptime params: FieldParams) type { | ... | @@ -119,7 +119,7 @@ pub fn Field(comptime params: FieldParams) type { |
| 119 | 119 | ||
| 120 | /// Return true if the element is odd. | 120 | /// Return true if the element is odd. |
| 121 | pub fn isOdd(fe: Fe) bool { | 121 | pub fn isOdd(fe: Fe) bool { |
| 122 | const s = fe.toBytes(.Little); | 122 | const s = fe.toBytes(.little); |
| 123 | return @as(u1, @truncate(s[0])) != 0; | 123 | return @as(u1, @truncate(s[0])) != 0; |
| 124 | } | 124 | } |
| 125 | 125 |
lib/std/crypto/pcurves/p256.zig+12-12| ... | @@ -87,15 +87,15 @@ pub const P256 = struct { | ... | @@ -87,15 +87,15 @@ pub const P256 = struct { |
| 87 | }, | 87 | }, |
| 88 | 2, 3 => { | 88 | 2, 3 => { |
| 89 | if (encoded.len != 32) return error.InvalidEncoding; | 89 | if (encoded.len != 32) return error.InvalidEncoding; |
| 90 | const x = try Fe.fromBytes(encoded[0..32].*, .Big); | 90 | const x = try Fe.fromBytes(encoded[0..32].*, .big); |
| 91 | const y_is_odd = (encoding_type == 3); | 91 | const y_is_odd = (encoding_type == 3); |
| 92 | const y = try recoverY(x, y_is_odd); | 92 | const y = try recoverY(x, y_is_odd); |
| 93 | return P256{ .x = x, .y = y }; | 93 | return P256{ .x = x, .y = y }; |
| 94 | }, | 94 | }, |
| 95 | 4 => { | 95 | 4 => { |
| 96 | if (encoded.len != 64) return error.InvalidEncoding; | 96 | if (encoded.len != 64) return error.InvalidEncoding; |
| 97 | const x = try Fe.fromBytes(encoded[0..32].*, .Big); | 97 | const x = try Fe.fromBytes(encoded[0..32].*, .big); |
| 98 | const y = try Fe.fromBytes(encoded[32..64].*, .Big); | 98 | const y = try Fe.fromBytes(encoded[32..64].*, .big); |
| 99 | return P256.fromAffineCoordinates(.{ .x = x, .y = y }); | 99 | return P256.fromAffineCoordinates(.{ .x = x, .y = y }); |
| 100 | }, | 100 | }, |
| 101 | else => return error.InvalidEncoding, | 101 | else => return error.InvalidEncoding, |
| ... | @@ -107,7 +107,7 @@ pub const P256 = struct { | ... | @@ -107,7 +107,7 @@ pub const P256 = struct { |
| 107 | var out: [33]u8 = undefined; | 107 | var out: [33]u8 = undefined; |
| 108 | const xy = p.affineCoordinates(); | 108 | const xy = p.affineCoordinates(); |
| 109 | out[0] = if (xy.y.isOdd()) 3 else 2; | 109 | out[0] = if (xy.y.isOdd()) 3 else 2; |
| 110 | out[1..].* = xy.x.toBytes(.Big); | 110 | out[1..].* = xy.x.toBytes(.big); |
| 111 | return out; | 111 | return out; |
| 112 | } | 112 | } |
| 113 | 113 | ||
| ... | @@ -116,15 +116,15 @@ pub const P256 = struct { | ... | @@ -116,15 +116,15 @@ pub const P256 = struct { |
| 116 | var out: [65]u8 = undefined; | 116 | var out: [65]u8 = undefined; |
| 117 | out[0] = 4; | 117 | out[0] = 4; |
| 118 | const xy = p.affineCoordinates(); | 118 | const xy = p.affineCoordinates(); |
| 119 | out[1..33].* = xy.x.toBytes(.Big); | 119 | out[1..33].* = xy.x.toBytes(.big); |
| 120 | out[33..65].* = xy.y.toBytes(.Big); | 120 | out[33..65].* = xy.y.toBytes(.big); |
| 121 | return out; | 121 | return out; |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | /// Return a random point. | 124 | /// Return a random point. |
| 125 | pub fn random() P256 { | 125 | pub fn random() P256 { |
| 126 | const n = scalar.random(.Little); | 126 | const n = scalar.random(.little); |
| 127 | return basePoint.mul(n, .Little) catch unreachable; | 127 | return basePoint.mul(n, .little) catch unreachable; |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | /// Flip the sign of the X coordinate. | 130 | /// Flip the sign of the X coordinate. |
| ... | @@ -400,7 +400,7 @@ pub const P256 = struct { | ... | @@ -400,7 +400,7 @@ pub const P256 = struct { |
| 400 | /// Multiply an elliptic curve point by a scalar. | 400 | /// Multiply an elliptic curve point by a scalar. |
| 401 | /// Return error.IdentityElement if the result is the identity element. | 401 | /// Return error.IdentityElement if the result is the identity element. |
| 402 | pub fn mul(p: P256, s_: [32]u8, endian: std.builtin.Endian) IdentityElementError!P256 { | 402 | pub fn mul(p: P256, s_: [32]u8, endian: std.builtin.Endian) IdentityElementError!P256 { |
| 403 | const s = if (endian == .Little) s_ else Fe.orderSwap(s_); | 403 | const s = if (endian == .little) s_ else Fe.orderSwap(s_); |
| 404 | if (p.is_base) { | 404 | if (p.is_base) { |
| 405 | return pcMul16(&basePointPc, s, false); | 405 | return pcMul16(&basePointPc, s, false); |
| 406 | } | 406 | } |
| ... | @@ -412,7 +412,7 @@ pub const P256 = struct { | ... | @@ -412,7 +412,7 @@ pub const P256 = struct { |
| 412 | /// Multiply an elliptic curve point by a *PUBLIC* scalar *IN VARIABLE TIME* | 412 | /// Multiply an elliptic curve point by a *PUBLIC* scalar *IN VARIABLE TIME* |
| 413 | /// This can be used for signature verification. | 413 | /// This can be used for signature verification. |
| 414 | pub fn mulPublic(p: P256, s_: [32]u8, endian: std.builtin.Endian) IdentityElementError!P256 { | 414 | pub fn mulPublic(p: P256, s_: [32]u8, endian: std.builtin.Endian) IdentityElementError!P256 { |
| 415 | const s = if (endian == .Little) s_ else Fe.orderSwap(s_); | 415 | const s = if (endian == .little) s_ else Fe.orderSwap(s_); |
| 416 | if (p.is_base) { | 416 | if (p.is_base) { |
| 417 | return pcMul16(&basePointPc, s, true); | 417 | return pcMul16(&basePointPc, s, true); |
| 418 | } | 418 | } |
| ... | @@ -424,8 +424,8 @@ pub const P256 = struct { | ... | @@ -424,8 +424,8 @@ pub const P256 = struct { |
| 424 | /// Double-base multiplication of public parameters - Compute (p1*s1)+(p2*s2) *IN VARIABLE TIME* | 424 | /// Double-base multiplication of public parameters - Compute (p1*s1)+(p2*s2) *IN VARIABLE TIME* |
| 425 | /// This can be used for signature verification. | 425 | /// This can be used for signature verification. |
| 426 | pub fn mulDoubleBasePublic(p1: P256, s1_: [32]u8, p2: P256, s2_: [32]u8, endian: std.builtin.Endian) IdentityElementError!P256 { | 426 | pub fn mulDoubleBasePublic(p1: P256, s1_: [32]u8, p2: P256, s2_: [32]u8, endian: std.builtin.Endian) IdentityElementError!P256 { |
| 427 | const s1 = if (endian == .Little) s1_ else Fe.orderSwap(s1_); | 427 | const s1 = if (endian == .little) s1_ else Fe.orderSwap(s1_); |
| 428 | const s2 = if (endian == .Little) s2_ else Fe.orderSwap(s2_); | 428 | const s2 = if (endian == .little) s2_ else Fe.orderSwap(s2_); |
| 429 | try p1.rejectIdentity(); | 429 | try p1.rejectIdentity(); |
| 430 | var pc1_array: [9]P256 = undefined; | 430 | var pc1_array: [9]P256 = undefined; |
| 431 | const pc1 = if (p1.is_base) basePointPc[0..9] else pc: { | 431 | const pc1 = if (p1.is_base) basePointPc[0..9] else pc: { |
lib/std/crypto/pcurves/p256/scalar.zig+5-5| ... | @@ -174,7 +174,7 @@ pub const Scalar = struct { | ... | @@ -174,7 +174,7 @@ pub const Scalar = struct { |
| 174 | var s: [48]u8 = undefined; | 174 | var s: [48]u8 = undefined; |
| 175 | while (true) { | 175 | while (true) { |
| 176 | crypto.random.bytes(&s); | 176 | crypto.random.bytes(&s); |
| 177 | const n = Scalar.fromBytes48(s, .Little); | 177 | const n = Scalar.fromBytes48(s, .little); |
| 178 | if (!n.isZero()) { | 178 | if (!n.isZero()) { |
| 179 | return n; | 179 | return n; |
| 180 | } | 180 | } |
| ... | @@ -191,7 +191,7 @@ const ScalarDouble = struct { | ... | @@ -191,7 +191,7 @@ const ScalarDouble = struct { |
| 191 | debug.assert(bits > 0 and bits <= 512 and bits >= Fe.saturated_bits and bits <= Fe.saturated_bits * 3); | 191 | debug.assert(bits > 0 and bits <= 512 and bits >= Fe.saturated_bits and bits <= Fe.saturated_bits * 3); |
| 192 | 192 | ||
| 193 | var s = s_; | 193 | var s = s_; |
| 194 | if (endian == .Big) { | 194 | if (endian == .big) { |
| 195 | for (s_, 0..) |x, i| s[s.len - 1 - i] = x; | 195 | for (s_, 0..) |x, i| s[s.len - 1 - i] = x; |
| 196 | } | 196 | } |
| 197 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero }; | 197 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero }; |
| ... | @@ -199,19 +199,19 @@ const ScalarDouble = struct { | ... | @@ -199,19 +199,19 @@ const ScalarDouble = struct { |
| 199 | var b = [_]u8{0} ** encoded_length; | 199 | var b = [_]u8{0} ** encoded_length; |
| 200 | const len = @min(s.len, 24); | 200 | const len = @min(s.len, 24); |
| 201 | b[0..len].* = s[0..len].*; | 201 | b[0..len].* = s[0..len].*; |
| 202 | t.x1 = Fe.fromBytes(b, .Little) catch unreachable; | 202 | t.x1 = Fe.fromBytes(b, .little) catch unreachable; |
| 203 | } | 203 | } |
| 204 | if (s_.len >= 24) { | 204 | if (s_.len >= 24) { |
| 205 | var b = [_]u8{0} ** encoded_length; | 205 | var b = [_]u8{0} ** encoded_length; |
| 206 | const len = @min(s.len - 24, 24); | 206 | const len = @min(s.len - 24, 24); |
| 207 | b[0..len].* = s[24..][0..len].*; | 207 | b[0..len].* = s[24..][0..len].*; |
| 208 | t.x2 = Fe.fromBytes(b, .Little) catch unreachable; | 208 | t.x2 = Fe.fromBytes(b, .little) catch unreachable; |
| 209 | } | 209 | } |
| 210 | if (s_.len >= 48) { | 210 | if (s_.len >= 48) { |
| 211 | var b = [_]u8{0} ** encoded_length; | 211 | var b = [_]u8{0} ** encoded_length; |
| 212 | const len = s.len - 48; | 212 | const len = s.len - 48; |
| 213 | b[0..len].* = s[48..][0..len].*; | 213 | b[0..len].* = s[48..][0..len].*; |
| 214 | t.x3 = Fe.fromBytes(b, .Little) catch unreachable; | 214 | t.x3 = Fe.fromBytes(b, .little) catch unreachable; |
| 215 | } | 215 | } |
| 216 | return t; | 216 | return t; |
| 217 | } | 217 | } |
lib/std/crypto/pcurves/p384.zig+12-12| ... | @@ -87,15 +87,15 @@ pub const P384 = struct { | ... | @@ -87,15 +87,15 @@ pub const P384 = struct { |
| 87 | }, | 87 | }, |
| 88 | 2, 3 => { | 88 | 2, 3 => { |
| 89 | if (encoded.len != 48) return error.InvalidEncoding; | 89 | if (encoded.len != 48) return error.InvalidEncoding; |
| 90 | const x = try Fe.fromBytes(encoded[0..48].*, .Big); | 90 | const x = try Fe.fromBytes(encoded[0..48].*, .big); |
| 91 | const y_is_odd = (encoding_type == 3); | 91 | const y_is_odd = (encoding_type == 3); |
| 92 | const y = try recoverY(x, y_is_odd); | 92 | const y = try recoverY(x, y_is_odd); |
| 93 | return P384{ .x = x, .y = y }; | 93 | return P384{ .x = x, .y = y }; |
| 94 | }, | 94 | }, |
| 95 | 4 => { | 95 | 4 => { |
| 96 | if (encoded.len != 96) return error.InvalidEncoding; | 96 | if (encoded.len != 96) return error.InvalidEncoding; |
| 97 | const x = try Fe.fromBytes(encoded[0..48].*, .Big); | 97 | const x = try Fe.fromBytes(encoded[0..48].*, .big); |
| 98 | const y = try Fe.fromBytes(encoded[48..96].*, .Big); | 98 | const y = try Fe.fromBytes(encoded[48..96].*, .big); |
| 99 | return P384.fromAffineCoordinates(.{ .x = x, .y = y }); | 99 | return P384.fromAffineCoordinates(.{ .x = x, .y = y }); |
| 100 | }, | 100 | }, |
| 101 | else => return error.InvalidEncoding, | 101 | else => return error.InvalidEncoding, |
| ... | @@ -107,7 +107,7 @@ pub const P384 = struct { | ... | @@ -107,7 +107,7 @@ pub const P384 = struct { |
| 107 | var out: [49]u8 = undefined; | 107 | var out: [49]u8 = undefined; |
| 108 | const xy = p.affineCoordinates(); | 108 | const xy = p.affineCoordinates(); |
| 109 | out[0] = if (xy.y.isOdd()) 3 else 2; | 109 | out[0] = if (xy.y.isOdd()) 3 else 2; |
| 110 | out[1..].* = xy.x.toBytes(.Big); | 110 | out[1..].* = xy.x.toBytes(.big); |
| 111 | return out; | 111 | return out; |
| 112 | } | 112 | } |
| 113 | 113 | ||
| ... | @@ -116,15 +116,15 @@ pub const P384 = struct { | ... | @@ -116,15 +116,15 @@ pub const P384 = struct { |
| 116 | var out: [97]u8 = undefined; | 116 | var out: [97]u8 = undefined; |
| 117 | out[0] = 4; | 117 | out[0] = 4; |
| 118 | const xy = p.affineCoordinates(); | 118 | const xy = p.affineCoordinates(); |
| 119 | out[1..49].* = xy.x.toBytes(.Big); | 119 | out[1..49].* = xy.x.toBytes(.big); |
| 120 | out[49..97].* = xy.y.toBytes(.Big); | 120 | out[49..97].* = xy.y.toBytes(.big); |
| 121 | return out; | 121 | return out; |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | /// Return a random point. | 124 | /// Return a random point. |
| 125 | pub fn random() P384 { | 125 | pub fn random() P384 { |
| 126 | const n = scalar.random(.Little); | 126 | const n = scalar.random(.little); |
| 127 | return basePoint.mul(n, .Little) catch unreachable; | 127 | return basePoint.mul(n, .little) catch unreachable; |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | /// Flip the sign of the X coordinate. | 130 | /// Flip the sign of the X coordinate. |
| ... | @@ -400,7 +400,7 @@ pub const P384 = struct { | ... | @@ -400,7 +400,7 @@ pub const P384 = struct { |
| 400 | /// Multiply an elliptic curve point by a scalar. | 400 | /// Multiply an elliptic curve point by a scalar. |
| 401 | /// Return error.IdentityElement if the result is the identity element. | 401 | /// Return error.IdentityElement if the result is the identity element. |
| 402 | pub fn mul(p: P384, s_: [48]u8, endian: std.builtin.Endian) IdentityElementError!P384 { | 402 | pub fn mul(p: P384, s_: [48]u8, endian: std.builtin.Endian) IdentityElementError!P384 { |
| 403 | const s = if (endian == .Little) s_ else Fe.orderSwap(s_); | 403 | const s = if (endian == .little) s_ else Fe.orderSwap(s_); |
| 404 | if (p.is_base) { | 404 | if (p.is_base) { |
| 405 | return pcMul16(&basePointPc, s, false); | 405 | return pcMul16(&basePointPc, s, false); |
| 406 | } | 406 | } |
| ... | @@ -412,7 +412,7 @@ pub const P384 = struct { | ... | @@ -412,7 +412,7 @@ pub const P384 = struct { |
| 412 | /// Multiply an elliptic curve point by a *PUBLIC* scalar *IN VARIABLE TIME* | 412 | /// Multiply an elliptic curve point by a *PUBLIC* scalar *IN VARIABLE TIME* |
| 413 | /// This can be used for signature verification. | 413 | /// This can be used for signature verification. |
| 414 | pub fn mulPublic(p: P384, s_: [48]u8, endian: std.builtin.Endian) IdentityElementError!P384 { | 414 | pub fn mulPublic(p: P384, s_: [48]u8, endian: std.builtin.Endian) IdentityElementError!P384 { |
| 415 | const s = if (endian == .Little) s_ else Fe.orderSwap(s_); | 415 | const s = if (endian == .little) s_ else Fe.orderSwap(s_); |
| 416 | if (p.is_base) { | 416 | if (p.is_base) { |
| 417 | return pcMul16(&basePointPc, s, true); | 417 | return pcMul16(&basePointPc, s, true); |
| 418 | } | 418 | } |
| ... | @@ -424,8 +424,8 @@ pub const P384 = struct { | ... | @@ -424,8 +424,8 @@ pub const P384 = struct { |
| 424 | /// Double-base multiplication of public parameters - Compute (p1*s1)+(p2*s2) *IN VARIABLE TIME* | 424 | /// Double-base multiplication of public parameters - Compute (p1*s1)+(p2*s2) *IN VARIABLE TIME* |
| 425 | /// This can be used for signature verification. | 425 | /// This can be used for signature verification. |
| 426 | pub fn mulDoubleBasePublic(p1: P384, s1_: [48]u8, p2: P384, s2_: [48]u8, endian: std.builtin.Endian) IdentityElementError!P384 { | 426 | pub fn mulDoubleBasePublic(p1: P384, s1_: [48]u8, p2: P384, s2_: [48]u8, endian: std.builtin.Endian) IdentityElementError!P384 { |
| 427 | const s1 = if (endian == .Little) s1_ else Fe.orderSwap(s1_); | 427 | const s1 = if (endian == .little) s1_ else Fe.orderSwap(s1_); |
| 428 | const s2 = if (endian == .Little) s2_ else Fe.orderSwap(s2_); | 428 | const s2 = if (endian == .little) s2_ else Fe.orderSwap(s2_); |
| 429 | try p1.rejectIdentity(); | 429 | try p1.rejectIdentity(); |
| 430 | var pc1_array: [9]P384 = undefined; | 430 | var pc1_array: [9]P384 = undefined; |
| 431 | const pc1 = if (p1.is_base) basePointPc[0..9] else pc: { | 431 | const pc1 = if (p1.is_base) basePointPc[0..9] else pc: { |
lib/std/crypto/pcurves/p384/scalar.zig+4-4| ... | @@ -163,7 +163,7 @@ pub const Scalar = struct { | ... | @@ -163,7 +163,7 @@ pub const Scalar = struct { |
| 163 | var s: [64]u8 = undefined; | 163 | var s: [64]u8 = undefined; |
| 164 | while (true) { | 164 | while (true) { |
| 165 | crypto.random.bytes(&s); | 165 | crypto.random.bytes(&s); |
| 166 | const n = Scalar.fromBytes64(s, .Little); | 166 | const n = Scalar.fromBytes64(s, .little); |
| 167 | if (!n.isZero()) { | 167 | if (!n.isZero()) { |
| 168 | return n; | 168 | return n; |
| 169 | } | 169 | } |
| ... | @@ -179,7 +179,7 @@ const ScalarDouble = struct { | ... | @@ -179,7 +179,7 @@ const ScalarDouble = struct { |
| 179 | debug.assert(bits > 0 and bits <= 512 and bits >= Fe.saturated_bits and bits <= Fe.saturated_bits * 2); | 179 | debug.assert(bits > 0 and bits <= 512 and bits >= Fe.saturated_bits and bits <= Fe.saturated_bits * 2); |
| 180 | 180 | ||
| 181 | var s = s_; | 181 | var s = s_; |
| 182 | if (endian == .Big) { | 182 | if (endian == .big) { |
| 183 | for (s_, 0..) |x, i| s[s.len - 1 - i] = x; | 183 | for (s_, 0..) |x, i| s[s.len - 1 - i] = x; |
| 184 | } | 184 | } |
| 185 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero }; | 185 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero }; |
| ... | @@ -187,13 +187,13 @@ const ScalarDouble = struct { | ... | @@ -187,13 +187,13 @@ const ScalarDouble = struct { |
| 187 | var b = [_]u8{0} ** encoded_length; | 187 | var b = [_]u8{0} ** encoded_length; |
| 188 | const len = @min(s.len, 32); | 188 | const len = @min(s.len, 32); |
| 189 | b[0..len].* = s[0..len].*; | 189 | b[0..len].* = s[0..len].*; |
| 190 | t.x1 = Fe.fromBytes(b, .Little) catch unreachable; | 190 | t.x1 = Fe.fromBytes(b, .little) catch unreachable; |
| 191 | } | 191 | } |
| 192 | if (s_.len >= 32) { | 192 | if (s_.len >= 32) { |
| 193 | var b = [_]u8{0} ** encoded_length; | 193 | var b = [_]u8{0} ** encoded_length; |
| 194 | const len = @min(s.len - 32, 32); | 194 | const len = @min(s.len - 32, 32); |
| 195 | b[0..len].* = s[32..][0..len].*; | 195 | b[0..len].* = s[32..][0..len].*; |
| 196 | t.x2 = Fe.fromBytes(b, .Little) catch unreachable; | 196 | t.x2 = Fe.fromBytes(b, .little) catch unreachable; |
| 197 | } | 197 | } |
| 198 | return t; | 198 | return t; |
| 199 | } | 199 | } |
lib/std/crypto/pcurves/secp256k1.zig+26-26| ... | @@ -41,7 +41,7 @@ pub const Secp256k1 = struct { | ... | @@ -41,7 +41,7 @@ pub const Secp256k1 = struct { |
| 41 | 41 | ||
| 42 | const lambda_s = s: { | 42 | const lambda_s = s: { |
| 43 | var buf: [32]u8 = undefined; | 43 | var buf: [32]u8 = undefined; |
| 44 | mem.writeInt(u256, &buf, Endormorphism.lambda, .Little); | 44 | mem.writeInt(u256, &buf, Endormorphism.lambda, .little); |
| 45 | break :s buf; | 45 | break :s buf; |
| 46 | }; | 46 | }; |
| 47 | 47 | ||
| ... | @@ -54,12 +54,12 @@ pub const Secp256k1 = struct { | ... | @@ -54,12 +54,12 @@ pub const Secp256k1 = struct { |
| 54 | pub fn splitScalar(s: [32]u8, endian: std.builtin.Endian) NonCanonicalError!SplitScalar { | 54 | pub fn splitScalar(s: [32]u8, endian: std.builtin.Endian) NonCanonicalError!SplitScalar { |
| 55 | const b1_neg_s = comptime s: { | 55 | const b1_neg_s = comptime s: { |
| 56 | var buf: [32]u8 = undefined; | 56 | var buf: [32]u8 = undefined; |
| 57 | mem.writeInt(u256, &buf, 303414439467246543595250775667605759171, .Little); | 57 | mem.writeInt(u256, &buf, 303414439467246543595250775667605759171, .little); |
| 58 | break :s buf; | 58 | break :s buf; |
| 59 | }; | 59 | }; |
| 60 | const b2_neg_s = comptime s: { | 60 | const b2_neg_s = comptime s: { |
| 61 | var buf: [32]u8 = undefined; | 61 | var buf: [32]u8 = undefined; |
| 62 | mem.writeInt(u256, &buf, scalar.field_order - 64502973549206556628585045361533709077, .Little); | 62 | mem.writeInt(u256, &buf, scalar.field_order - 64502973549206556628585045361533709077, .little); |
| 63 | break :s buf; | 63 | break :s buf; |
| 64 | }; | 64 | }; |
| 65 | const k = mem.readInt(u256, &s, endian); | 65 | const k = mem.readInt(u256, &s, endian); |
| ... | @@ -72,16 +72,16 @@ pub const Secp256k1 = struct { | ... | @@ -72,16 +72,16 @@ pub const Secp256k1 = struct { |
| 72 | 72 | ||
| 73 | var buf: [32]u8 = undefined; | 73 | var buf: [32]u8 = undefined; |
| 74 | 74 | ||
| 75 | mem.writeInt(u256, &buf, c1, .Little); | 75 | mem.writeInt(u256, &buf, c1, .little); |
| 76 | const c1x = try scalar.mul(buf, b1_neg_s, .Little); | 76 | const c1x = try scalar.mul(buf, b1_neg_s, .little); |
| 77 | 77 | ||
| 78 | mem.writeInt(u256, &buf, c2, .Little); | 78 | mem.writeInt(u256, &buf, c2, .little); |
| 79 | const c2x = try scalar.mul(buf, b2_neg_s, .Little); | 79 | const c2x = try scalar.mul(buf, b2_neg_s, .little); |
| 80 | 80 | ||
| 81 | const r2 = try scalar.add(c1x, c2x, .Little); | 81 | const r2 = try scalar.add(c1x, c2x, .little); |
| 82 | 82 | ||
| 83 | var r1 = try scalar.mul(r2, lambda_s, .Little); | 83 | var r1 = try scalar.mul(r2, lambda_s, .little); |
| 84 | r1 = try scalar.sub(s, r1, .Little); | 84 | r1 = try scalar.sub(s, r1, .little); |
| 85 | 85 | ||
| 86 | return SplitScalar{ .r1 = r1, .r2 = r2 }; | 86 | return SplitScalar{ .r1 = r1, .r2 = r2 }; |
| 87 | } | 87 | } |
| ... | @@ -140,15 +140,15 @@ pub const Secp256k1 = struct { | ... | @@ -140,15 +140,15 @@ pub const Secp256k1 = struct { |
| 140 | }, | 140 | }, |
| 141 | 2, 3 => { | 141 | 2, 3 => { |
| 142 | if (encoded.len != 32) return error.InvalidEncoding; | 142 | if (encoded.len != 32) return error.InvalidEncoding; |
| 143 | const x = try Fe.fromBytes(encoded[0..32].*, .Big); | 143 | const x = try Fe.fromBytes(encoded[0..32].*, .big); |
| 144 | const y_is_odd = (encoding_type == 3); | 144 | const y_is_odd = (encoding_type == 3); |
| 145 | const y = try recoverY(x, y_is_odd); | 145 | const y = try recoverY(x, y_is_odd); |
| 146 | return Secp256k1{ .x = x, .y = y }; | 146 | return Secp256k1{ .x = x, .y = y }; |
| 147 | }, | 147 | }, |
| 148 | 4 => { | 148 | 4 => { |
| 149 | if (encoded.len != 64) return error.InvalidEncoding; | 149 | if (encoded.len != 64) return error.InvalidEncoding; |
| 150 | const x = try Fe.fromBytes(encoded[0..32].*, .Big); | 150 | const x = try Fe.fromBytes(encoded[0..32].*, .big); |
| 151 | const y = try Fe.fromBytes(encoded[32..64].*, .Big); | 151 | const y = try Fe.fromBytes(encoded[32..64].*, .big); |
| 152 | return Secp256k1.fromAffineCoordinates(.{ .x = x, .y = y }); | 152 | return Secp256k1.fromAffineCoordinates(.{ .x = x, .y = y }); |
| 153 | }, | 153 | }, |
| 154 | else => return error.InvalidEncoding, | 154 | else => return error.InvalidEncoding, |
| ... | @@ -160,7 +160,7 @@ pub const Secp256k1 = struct { | ... | @@ -160,7 +160,7 @@ pub const Secp256k1 = struct { |
| 160 | var out: [33]u8 = undefined; | 160 | var out: [33]u8 = undefined; |
| 161 | const xy = p.affineCoordinates(); | 161 | const xy = p.affineCoordinates(); |
| 162 | out[0] = if (xy.y.isOdd()) 3 else 2; | 162 | out[0] = if (xy.y.isOdd()) 3 else 2; |
| 163 | out[1..].* = xy.x.toBytes(.Big); | 163 | out[1..].* = xy.x.toBytes(.big); |
| 164 | return out; | 164 | return out; |
| 165 | } | 165 | } |
| 166 | 166 | ||
| ... | @@ -169,15 +169,15 @@ pub const Secp256k1 = struct { | ... | @@ -169,15 +169,15 @@ pub const Secp256k1 = struct { |
| 169 | var out: [65]u8 = undefined; | 169 | var out: [65]u8 = undefined; |
| 170 | out[0] = 4; | 170 | out[0] = 4; |
| 171 | const xy = p.affineCoordinates(); | 171 | const xy = p.affineCoordinates(); |
| 172 | out[1..33].* = xy.x.toBytes(.Big); | 172 | out[1..33].* = xy.x.toBytes(.big); |
| 173 | out[33..65].* = xy.y.toBytes(.Big); | 173 | out[33..65].* = xy.y.toBytes(.big); |
| 174 | return out; | 174 | return out; |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | /// Return a random point. | 177 | /// Return a random point. |
| 178 | pub fn random() Secp256k1 { | 178 | pub fn random() Secp256k1 { |
| 179 | const n = scalar.random(.Little); | 179 | const n = scalar.random(.little); |
| 180 | return basePoint.mul(n, .Little) catch unreachable; | 180 | return basePoint.mul(n, .little) catch unreachable; |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | /// Flip the sign of the X coordinate. | 183 | /// Flip the sign of the X coordinate. |
| ... | @@ -428,7 +428,7 @@ pub const Secp256k1 = struct { | ... | @@ -428,7 +428,7 @@ pub const Secp256k1 = struct { |
| 428 | /// Multiply an elliptic curve point by a scalar. | 428 | /// Multiply an elliptic curve point by a scalar. |
| 429 | /// Return error.IdentityElement if the result is the identity element. | 429 | /// Return error.IdentityElement if the result is the identity element. |
| 430 | pub fn mul(p: Secp256k1, s_: [32]u8, endian: std.builtin.Endian) IdentityElementError!Secp256k1 { | 430 | pub fn mul(p: Secp256k1, s_: [32]u8, endian: std.builtin.Endian) IdentityElementError!Secp256k1 { |
| 431 | const s = if (endian == .Little) s_ else Fe.orderSwap(s_); | 431 | const s = if (endian == .little) s_ else Fe.orderSwap(s_); |
| 432 | if (p.is_base) { | 432 | if (p.is_base) { |
| 433 | return pcMul16(&basePointPc, s, false); | 433 | return pcMul16(&basePointPc, s, false); |
| 434 | } | 434 | } |
| ... | @@ -440,24 +440,24 @@ pub const Secp256k1 = struct { | ... | @@ -440,24 +440,24 @@ pub const Secp256k1 = struct { |
| 440 | /// Multiply an elliptic curve point by a *PUBLIC* scalar *IN VARIABLE TIME* | 440 | /// Multiply an elliptic curve point by a *PUBLIC* scalar *IN VARIABLE TIME* |
| 441 | /// This can be used for signature verification. | 441 | /// This can be used for signature verification. |
| 442 | pub fn mulPublic(p: Secp256k1, s_: [32]u8, endian: std.builtin.Endian) (IdentityElementError || NonCanonicalError)!Secp256k1 { | 442 | pub fn mulPublic(p: Secp256k1, s_: [32]u8, endian: std.builtin.Endian) (IdentityElementError || NonCanonicalError)!Secp256k1 { |
| 443 | const s = if (endian == .Little) s_ else Fe.orderSwap(s_); | 443 | const s = if (endian == .little) s_ else Fe.orderSwap(s_); |
| 444 | const zero = comptime scalar.Scalar.zero.toBytes(.Little); | 444 | const zero = comptime scalar.Scalar.zero.toBytes(.little); |
| 445 | if (mem.eql(u8, &zero, &s)) { | 445 | if (mem.eql(u8, &zero, &s)) { |
| 446 | return error.IdentityElement; | 446 | return error.IdentityElement; |
| 447 | } | 447 | } |
| 448 | const pc = precompute(p, 8); | 448 | const pc = precompute(p, 8); |
| 449 | var lambda_p = try pcMul(&pc, Endormorphism.lambda_s, true); | 449 | var lambda_p = try pcMul(&pc, Endormorphism.lambda_s, true); |
| 450 | var split_scalar = try Endormorphism.splitScalar(s, .Little); | 450 | var split_scalar = try Endormorphism.splitScalar(s, .little); |
| 451 | var px = p; | 451 | var px = p; |
| 452 | 452 | ||
| 453 | // If a key is negative, flip the sign to keep it half-sized, | 453 | // If a key is negative, flip the sign to keep it half-sized, |
| 454 | // and flip the sign of the Y point coordinate to compensate. | 454 | // and flip the sign of the Y point coordinate to compensate. |
| 455 | if (split_scalar.r1[split_scalar.r1.len / 2] != 0) { | 455 | if (split_scalar.r1[split_scalar.r1.len / 2] != 0) { |
| 456 | split_scalar.r1 = scalar.neg(split_scalar.r1, .Little) catch zero; | 456 | split_scalar.r1 = scalar.neg(split_scalar.r1, .little) catch zero; |
| 457 | px = px.neg(); | 457 | px = px.neg(); |
| 458 | } | 458 | } |
| 459 | if (split_scalar.r2[split_scalar.r2.len / 2] != 0) { | 459 | if (split_scalar.r2[split_scalar.r2.len / 2] != 0) { |
| 460 | split_scalar.r2 = scalar.neg(split_scalar.r2, .Little) catch zero; | 460 | split_scalar.r2 = scalar.neg(split_scalar.r2, .little) catch zero; |
| 461 | lambda_p = lambda_p.neg(); | 461 | lambda_p = lambda_p.neg(); |
| 462 | } | 462 | } |
| 463 | return mulDoubleBasePublicEndo(px, split_scalar.r1, lambda_p, split_scalar.r2); | 463 | return mulDoubleBasePublicEndo(px, split_scalar.r1, lambda_p, split_scalar.r2); |
| ... | @@ -502,8 +502,8 @@ pub const Secp256k1 = struct { | ... | @@ -502,8 +502,8 @@ pub const Secp256k1 = struct { |
| 502 | /// Double-base multiplication of public parameters - Compute (p1*s1)+(p2*s2) *IN VARIABLE TIME* | 502 | /// Double-base multiplication of public parameters - Compute (p1*s1)+(p2*s2) *IN VARIABLE TIME* |
| 503 | /// This can be used for signature verification. | 503 | /// This can be used for signature verification. |
| 504 | pub fn mulDoubleBasePublic(p1: Secp256k1, s1_: [32]u8, p2: Secp256k1, s2_: [32]u8, endian: std.builtin.Endian) IdentityElementError!Secp256k1 { | 504 | pub fn mulDoubleBasePublic(p1: Secp256k1, s1_: [32]u8, p2: Secp256k1, s2_: [32]u8, endian: std.builtin.Endian) IdentityElementError!Secp256k1 { |
| 505 | const s1 = if (endian == .Little) s1_ else Fe.orderSwap(s1_); | 505 | const s1 = if (endian == .little) s1_ else Fe.orderSwap(s1_); |
| 506 | const s2 = if (endian == .Little) s2_ else Fe.orderSwap(s2_); | 506 | const s2 = if (endian == .little) s2_ else Fe.orderSwap(s2_); |
| 507 | try p1.rejectIdentity(); | 507 | try p1.rejectIdentity(); |
| 508 | var pc1_array: [9]Secp256k1 = undefined; | 508 | var pc1_array: [9]Secp256k1 = undefined; |
| 509 | const pc1 = if (p1.is_base) basePointPc[0..9] else pc: { | 509 | const pc1 = if (p1.is_base) basePointPc[0..9] else pc: { |
lib/std/crypto/pcurves/secp256k1/scalar.zig+5-5| ... | @@ -174,7 +174,7 @@ pub const Scalar = struct { | ... | @@ -174,7 +174,7 @@ pub const Scalar = struct { |
| 174 | var s: [48]u8 = undefined; | 174 | var s: [48]u8 = undefined; |
| 175 | while (true) { | 175 | while (true) { |
| 176 | crypto.random.bytes(&s); | 176 | crypto.random.bytes(&s); |
| 177 | const n = Scalar.fromBytes48(s, .Little); | 177 | const n = Scalar.fromBytes48(s, .little); |
| 178 | if (!n.isZero()) { | 178 | if (!n.isZero()) { |
| 179 | return n; | 179 | return n; |
| 180 | } | 180 | } |
| ... | @@ -191,7 +191,7 @@ const ScalarDouble = struct { | ... | @@ -191,7 +191,7 @@ const ScalarDouble = struct { |
| 191 | debug.assert(bits > 0 and bits <= 512 and bits >= Fe.saturated_bits and bits <= Fe.saturated_bits * 3); | 191 | debug.assert(bits > 0 and bits <= 512 and bits >= Fe.saturated_bits and bits <= Fe.saturated_bits * 3); |
| 192 | 192 | ||
| 193 | var s = s_; | 193 | var s = s_; |
| 194 | if (endian == .Big) { | 194 | if (endian == .big) { |
| 195 | for (s_, 0..) |x, i| s[s.len - 1 - i] = x; | 195 | for (s_, 0..) |x, i| s[s.len - 1 - i] = x; |
| 196 | } | 196 | } |
| 197 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero }; | 197 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero }; |
| ... | @@ -199,19 +199,19 @@ const ScalarDouble = struct { | ... | @@ -199,19 +199,19 @@ const ScalarDouble = struct { |
| 199 | var b = [_]u8{0} ** encoded_length; | 199 | var b = [_]u8{0} ** encoded_length; |
| 200 | const len = @min(s.len, 24); | 200 | const len = @min(s.len, 24); |
| 201 | b[0..len].* = s[0..len].*; | 201 | b[0..len].* = s[0..len].*; |
| 202 | t.x1 = Fe.fromBytes(b, .Little) catch unreachable; | 202 | t.x1 = Fe.fromBytes(b, .little) catch unreachable; |
| 203 | } | 203 | } |
| 204 | if (s_.len >= 24) { | 204 | if (s_.len >= 24) { |
| 205 | var b = [_]u8{0} ** encoded_length; | 205 | var b = [_]u8{0} ** encoded_length; |
| 206 | const len = @min(s.len - 24, 24); | 206 | const len = @min(s.len - 24, 24); |
| 207 | b[0..len].* = s[24..][0..len].*; | 207 | b[0..len].* = s[24..][0..len].*; |
| 208 | t.x2 = Fe.fromBytes(b, .Little) catch unreachable; | 208 | t.x2 = Fe.fromBytes(b, .little) catch unreachable; |
| 209 | } | 209 | } |
| 210 | if (s_.len >= 48) { | 210 | if (s_.len >= 48) { |
| 211 | var b = [_]u8{0} ** encoded_length; | 211 | var b = [_]u8{0} ** encoded_length; |
| 212 | const len = s.len - 48; | 212 | const len = s.len - 48; |
| 213 | b[0..len].* = s[48..][0..len].*; | 213 | b[0..len].* = s[48..][0..len].*; |
| 214 | t.x3 = Fe.fromBytes(b, .Little) catch unreachable; | 214 | t.x3 = Fe.fromBytes(b, .little) catch unreachable; |
| 215 | } | 215 | } |
| 216 | return t; | 216 | return t; |
| 217 | } | 217 | } |
lib/std/crypto/pcurves/tests/p256.zig+20-20| ... | @@ -5,12 +5,12 @@ const testing = std.testing; | ... | @@ -5,12 +5,12 @@ const testing = std.testing; |
| 5 | const P256 = @import("../p256.zig").P256; | 5 | const P256 = @import("../p256.zig").P256; |
| 6 | 6 | ||
| 7 | test "p256 ECDH key exchange" { | 7 | test "p256 ECDH key exchange" { |
| 8 | const dha = P256.scalar.random(.Little); | 8 | const dha = P256.scalar.random(.little); |
| 9 | const dhb = P256.scalar.random(.Little); | 9 | const dhb = P256.scalar.random(.little); |
| 10 | const dhA = try P256.basePoint.mul(dha, .Little); | 10 | const dhA = try P256.basePoint.mul(dha, .little); |
| 11 | const dhB = try P256.basePoint.mul(dhb, .Little); | 11 | const dhB = try P256.basePoint.mul(dhb, .little); |
| 12 | const shareda = try dhA.mul(dhb, .Little); | 12 | const shareda = try dhA.mul(dhb, .little); |
| 13 | const sharedb = try dhB.mul(dha, .Little); | 13 | const sharedb = try dhB.mul(dha, .little); |
| 14 | try testing.expect(shareda.equivalent(sharedb)); | 14 | try testing.expect(shareda.equivalent(sharedb)); |
| 15 | } | 15 | } |
| 16 | 16 | ||
| ... | @@ -21,7 +21,7 @@ test "p256 point from affine coordinates" { | ... | @@ -21,7 +21,7 @@ test "p256 point from affine coordinates" { |
| 21 | _ = try fmt.hexToBytes(&xs, xh); | 21 | _ = try fmt.hexToBytes(&xs, xh); |
| 22 | var ys: [32]u8 = undefined; | 22 | var ys: [32]u8 = undefined; |
| 23 | _ = try fmt.hexToBytes(&ys, yh); | 23 | _ = try fmt.hexToBytes(&ys, yh); |
| 24 | var p = try P256.fromSerializedAffineCoordinates(xs, ys, .Big); | 24 | var p = try P256.fromSerializedAffineCoordinates(xs, ys, .big); |
| 25 | try testing.expect(p.equivalent(P256.basePoint)); | 25 | try testing.expect(p.equivalent(P256.basePoint)); |
| 26 | } | 26 | } |
| 27 | 27 | ||
| ... | @@ -44,7 +44,7 @@ test "p256 test vectors" { | ... | @@ -44,7 +44,7 @@ test "p256 test vectors" { |
| 44 | p = p.add(P256.basePoint); | 44 | p = p.add(P256.basePoint); |
| 45 | var xs: [32]u8 = undefined; | 45 | var xs: [32]u8 = undefined; |
| 46 | _ = try fmt.hexToBytes(&xs, xh); | 46 | _ = try fmt.hexToBytes(&xs, xh); |
| 47 | try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs); | 47 | try testing.expectEqualSlices(u8, &x.toBytes(.big), &xs); |
| 48 | } | 48 | } |
| 49 | } | 49 | } |
| 50 | 50 | ||
| ... | @@ -61,7 +61,7 @@ test "p256 test vectors - doubling" { | ... | @@ -61,7 +61,7 @@ test "p256 test vectors - doubling" { |
| 61 | p = p.dbl(); | 61 | p = p.dbl(); |
| 62 | var xs: [32]u8 = undefined; | 62 | var xs: [32]u8 = undefined; |
| 63 | _ = try fmt.hexToBytes(&xs, xh); | 63 | _ = try fmt.hexToBytes(&xs, xh); |
| 64 | try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs); | 64 | try testing.expectEqualSlices(u8, &x.toBytes(.big), &xs); |
| 65 | } | 65 | } |
| 66 | } | 66 | } |
| 67 | 67 | ||
| ... | @@ -80,20 +80,20 @@ test "p256 uncompressed sec1 encoding/decoding" { | ... | @@ -80,20 +80,20 @@ test "p256 uncompressed sec1 encoding/decoding" { |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | test "p256 public key is the neutral element" { | 82 | test "p256 public key is the neutral element" { |
| 83 | const n = P256.scalar.Scalar.zero.toBytes(.Little); | 83 | const n = P256.scalar.Scalar.zero.toBytes(.little); |
| 84 | const p = P256.random(); | 84 | const p = P256.random(); |
| 85 | try testing.expectError(error.IdentityElement, p.mul(n, .Little)); | 85 | try testing.expectError(error.IdentityElement, p.mul(n, .little)); |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | test "p256 public key is the neutral element (public verification)" { | 88 | test "p256 public key is the neutral element (public verification)" { |
| 89 | const n = P256.scalar.Scalar.zero.toBytes(.Little); | 89 | const n = P256.scalar.Scalar.zero.toBytes(.little); |
| 90 | const p = P256.random(); | 90 | const p = P256.random(); |
| 91 | try testing.expectError(error.IdentityElement, p.mulPublic(n, .Little)); | 91 | try testing.expectError(error.IdentityElement, p.mulPublic(n, .little)); |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | test "p256 field element non-canonical encoding" { | 94 | test "p256 field element non-canonical encoding" { |
| 95 | const s = [_]u8{0xff} ** 32; | 95 | const s = [_]u8{0xff} ** 32; |
| 96 | try testing.expectError(error.NonCanonical, P256.Fe.fromBytes(s, .Little)); | 96 | try testing.expectError(error.NonCanonical, P256.Fe.fromBytes(s, .little)); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | test "p256 neutral element decoding" { | 99 | test "p256 neutral element decoding" { |
| ... | @@ -107,8 +107,8 @@ test "p256 double base multiplication" { | ... | @@ -107,8 +107,8 @@ test "p256 double base multiplication" { |
| 107 | const p2 = P256.basePoint.dbl(); | 107 | const p2 = P256.basePoint.dbl(); |
| 108 | const s1 = [_]u8{0x01} ** 32; | 108 | const s1 = [_]u8{0x01} ** 32; |
| 109 | const s2 = [_]u8{0x02} ** 32; | 109 | const s2 = [_]u8{0x02} ** 32; |
| 110 | const pr1 = try P256.mulDoubleBasePublic(p1, s1, p2, s2, .Little); | 110 | const pr1 = try P256.mulDoubleBasePublic(p1, s1, p2, s2, .little); |
| 111 | const pr2 = (try p1.mul(s1, .Little)).add(try p2.mul(s2, .Little)); | 111 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); |
| 112 | try testing.expect(pr1.equivalent(pr2)); | 112 | try testing.expect(pr1.equivalent(pr2)); |
| 113 | } | 113 | } |
| 114 | 114 | ||
| ... | @@ -117,8 +117,8 @@ test "p256 double base multiplication with large scalars" { | ... | @@ -117,8 +117,8 @@ test "p256 double base multiplication with large scalars" { |
| 117 | const p2 = P256.basePoint.dbl(); | 117 | const p2 = P256.basePoint.dbl(); |
| 118 | const s1 = [_]u8{0xee} ** 32; | 118 | const s1 = [_]u8{0xee} ** 32; |
| 119 | const s2 = [_]u8{0xdd} ** 32; | 119 | const s2 = [_]u8{0xdd} ** 32; |
| 120 | const pr1 = try P256.mulDoubleBasePublic(p1, s1, p2, s2, .Little); | 120 | const pr1 = try P256.mulDoubleBasePublic(p1, s1, p2, s2, .little); |
| 121 | const pr2 = (try p1.mul(s1, .Little)).add(try p2.mul(s2, .Little)); | 121 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); |
| 122 | try testing.expect(pr1.equivalent(pr2)); | 122 | try testing.expect(pr1.equivalent(pr2)); |
| 123 | } | 123 | } |
| 124 | 124 | ||
| ... | @@ -130,9 +130,9 @@ test "p256 scalar inverse" { | ... | @@ -130,9 +130,9 @@ test "p256 scalar inverse" { |
| 130 | const scalar = try P256.scalar.Scalar.fromBytes(.{ | 130 | const scalar = try P256.scalar.Scalar.fromBytes(.{ |
| 131 | 0x94, 0xa1, 0xbb, 0xb1, 0x4b, 0x90, 0x6a, 0x61, 0xa2, 0x80, 0xf2, 0x45, 0xf9, 0xe9, 0x3c, 0x7f, | 131 | 0x94, 0xa1, 0xbb, 0xb1, 0x4b, 0x90, 0x6a, 0x61, 0xa2, 0x80, 0xf2, 0x45, 0xf9, 0xe9, 0x3c, 0x7f, |
| 132 | 0x3b, 0x4a, 0x62, 0x47, 0x82, 0x4f, 0x5d, 0x33, 0xb9, 0x67, 0x07, 0x87, 0x64, 0x2a, 0x68, 0xde, | 132 | 0x3b, 0x4a, 0x62, 0x47, 0x82, 0x4f, 0x5d, 0x33, 0xb9, 0x67, 0x07, 0x87, 0x64, 0x2a, 0x68, 0xde, |
| 133 | }, .Big); | 133 | }, .big); |
| 134 | const inverse = scalar.invert(); | 134 | const inverse = scalar.invert(); |
| 135 | try std.testing.expectEqualSlices(u8, &out, &inverse.toBytes(.Big)); | 135 | try std.testing.expectEqualSlices(u8, &out, &inverse.toBytes(.big)); |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | test "p256 scalar parity" { | 138 | test "p256 scalar parity" { |
lib/std/crypto/pcurves/tests/p384.zig+20-20| ... | @@ -5,12 +5,12 @@ const testing = std.testing; | ... | @@ -5,12 +5,12 @@ const testing = std.testing; |
| 5 | const P384 = @import("../p384.zig").P384; | 5 | const P384 = @import("../p384.zig").P384; |
| 6 | 6 | ||
| 7 | test "p384 ECDH key exchange" { | 7 | test "p384 ECDH key exchange" { |
| 8 | const dha = P384.scalar.random(.Little); | 8 | const dha = P384.scalar.random(.little); |
| 9 | const dhb = P384.scalar.random(.Little); | 9 | const dhb = P384.scalar.random(.little); |
| 10 | const dhA = try P384.basePoint.mul(dha, .Little); | 10 | const dhA = try P384.basePoint.mul(dha, .little); |
| 11 | const dhB = try P384.basePoint.mul(dhb, .Little); | 11 | const dhB = try P384.basePoint.mul(dhb, .little); |
| 12 | const shareda = try dhA.mul(dhb, .Little); | 12 | const shareda = try dhA.mul(dhb, .little); |
| 13 | const sharedb = try dhB.mul(dha, .Little); | 13 | const sharedb = try dhB.mul(dha, .little); |
| 14 | try testing.expect(shareda.equivalent(sharedb)); | 14 | try testing.expect(shareda.equivalent(sharedb)); |
| 15 | } | 15 | } |
| 16 | 16 | ||
| ... | @@ -21,7 +21,7 @@ test "p384 point from affine coordinates" { | ... | @@ -21,7 +21,7 @@ test "p384 point from affine coordinates" { |
| 21 | _ = try fmt.hexToBytes(&xs, xh); | 21 | _ = try fmt.hexToBytes(&xs, xh); |
| 22 | var ys: [48]u8 = undefined; | 22 | var ys: [48]u8 = undefined; |
| 23 | _ = try fmt.hexToBytes(&ys, yh); | 23 | _ = try fmt.hexToBytes(&ys, yh); |
| 24 | var p = try P384.fromSerializedAffineCoordinates(xs, ys, .Big); | 24 | var p = try P384.fromSerializedAffineCoordinates(xs, ys, .big); |
| 25 | try testing.expect(p.equivalent(P384.basePoint)); | 25 | try testing.expect(p.equivalent(P384.basePoint)); |
| 26 | } | 26 | } |
| 27 | 27 | ||
| ... | @@ -45,7 +45,7 @@ test "p384 test vectors" { | ... | @@ -45,7 +45,7 @@ test "p384 test vectors" { |
| 45 | p = p.add(P384.basePoint); | 45 | p = p.add(P384.basePoint); |
| 46 | var xs: [48]u8 = undefined; | 46 | var xs: [48]u8 = undefined; |
| 47 | _ = try fmt.hexToBytes(&xs, xh); | 47 | _ = try fmt.hexToBytes(&xs, xh); |
| 48 | try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs); | 48 | try testing.expectEqualSlices(u8, &x.toBytes(.big), &xs); |
| 49 | } | 49 | } |
| 50 | } | 50 | } |
| 51 | 51 | ||
| ... | @@ -62,7 +62,7 @@ test "p384 test vectors - doubling" { | ... | @@ -62,7 +62,7 @@ test "p384 test vectors - doubling" { |
| 62 | p = p.dbl(); | 62 | p = p.dbl(); |
| 63 | var xs: [48]u8 = undefined; | 63 | var xs: [48]u8 = undefined; |
| 64 | _ = try fmt.hexToBytes(&xs, xh); | 64 | _ = try fmt.hexToBytes(&xs, xh); |
| 65 | try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs); | 65 | try testing.expectEqualSlices(u8, &x.toBytes(.big), &xs); |
| 66 | } | 66 | } |
| 67 | } | 67 | } |
| 68 | 68 | ||
| ... | @@ -83,20 +83,20 @@ test "p384 uncompressed sec1 encoding/decoding" { | ... | @@ -83,20 +83,20 @@ test "p384 uncompressed sec1 encoding/decoding" { |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | test "p384 public key is the neutral element" { | 85 | test "p384 public key is the neutral element" { |
| 86 | const n = P384.scalar.Scalar.zero.toBytes(.Little); | 86 | const n = P384.scalar.Scalar.zero.toBytes(.little); |
| 87 | const p = P384.random(); | 87 | const p = P384.random(); |
| 88 | try testing.expectError(error.IdentityElement, p.mul(n, .Little)); | 88 | try testing.expectError(error.IdentityElement, p.mul(n, .little)); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | test "p384 public key is the neutral element (public verification)" { | 91 | test "p384 public key is the neutral element (public verification)" { |
| 92 | const n = P384.scalar.Scalar.zero.toBytes(.Little); | 92 | const n = P384.scalar.Scalar.zero.toBytes(.little); |
| 93 | const p = P384.random(); | 93 | const p = P384.random(); |
| 94 | try testing.expectError(error.IdentityElement, p.mulPublic(n, .Little)); | 94 | try testing.expectError(error.IdentityElement, p.mulPublic(n, .little)); |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | test "p384 field element non-canonical encoding" { | 97 | test "p384 field element non-canonical encoding" { |
| 98 | const s = [_]u8{0xff} ** 48; | 98 | const s = [_]u8{0xff} ** 48; |
| 99 | try testing.expectError(error.NonCanonical, P384.Fe.fromBytes(s, .Little)); | 99 | try testing.expectError(error.NonCanonical, P384.Fe.fromBytes(s, .little)); |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | test "p384 neutral element decoding" { | 102 | test "p384 neutral element decoding" { |
| ... | @@ -110,8 +110,8 @@ test "p384 double base multiplication" { | ... | @@ -110,8 +110,8 @@ test "p384 double base multiplication" { |
| 110 | const p2 = P384.basePoint.dbl(); | 110 | const p2 = P384.basePoint.dbl(); |
| 111 | const s1 = [_]u8{0x01} ** 48; | 111 | const s1 = [_]u8{0x01} ** 48; |
| 112 | const s2 = [_]u8{0x02} ** 48; | 112 | const s2 = [_]u8{0x02} ** 48; |
| 113 | const pr1 = try P384.mulDoubleBasePublic(p1, s1, p2, s2, .Little); | 113 | const pr1 = try P384.mulDoubleBasePublic(p1, s1, p2, s2, .little); |
| 114 | const pr2 = (try p1.mul(s1, .Little)).add(try p2.mul(s2, .Little)); | 114 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); |
| 115 | try testing.expect(pr1.equivalent(pr2)); | 115 | try testing.expect(pr1.equivalent(pr2)); |
| 116 | } | 116 | } |
| 117 | 117 | ||
| ... | @@ -120,8 +120,8 @@ test "p384 double base multiplication with large scalars" { | ... | @@ -120,8 +120,8 @@ test "p384 double base multiplication with large scalars" { |
| 120 | const p2 = P384.basePoint.dbl(); | 120 | const p2 = P384.basePoint.dbl(); |
| 121 | const s1 = [_]u8{0xee} ** 48; | 121 | const s1 = [_]u8{0xee} ** 48; |
| 122 | const s2 = [_]u8{0xdd} ** 48; | 122 | const s2 = [_]u8{0xdd} ** 48; |
| 123 | const pr1 = try P384.mulDoubleBasePublic(p1, s1, p2, s2, .Little); | 123 | const pr1 = try P384.mulDoubleBasePublic(p1, s1, p2, s2, .little); |
| 124 | const pr2 = (try p1.mul(s1, .Little)).add(try p2.mul(s2, .Little)); | 124 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); |
| 125 | try testing.expect(pr1.equivalent(pr2)); | 125 | try testing.expect(pr1.equivalent(pr2)); |
| 126 | } | 126 | } |
| 127 | 127 | ||
| ... | @@ -134,10 +134,10 @@ test "p384 scalar inverse" { | ... | @@ -134,10 +134,10 @@ test "p384 scalar inverse" { |
| 134 | 0x94, 0xa1, 0xbb, 0xb1, 0x4b, 0x90, 0x6a, 0x61, 0xa2, 0x80, 0xf2, 0x45, 0xf9, 0xe9, 0x3c, 0x7f, | 134 | 0x94, 0xa1, 0xbb, 0xb1, 0x4b, 0x90, 0x6a, 0x61, 0xa2, 0x80, 0xf2, 0x45, 0xf9, 0xe9, 0x3c, 0x7f, |
| 135 | 0x3b, 0x4a, 0x62, 0x47, 0x82, 0x4f, 0x5d, 0x33, 0xb9, 0x67, 0x07, 0x87, 0x64, 0x2a, 0x68, 0xde, | 135 | 0x3b, 0x4a, 0x62, 0x47, 0x82, 0x4f, 0x5d, 0x33, 0xb9, 0x67, 0x07, 0x87, 0x64, 0x2a, 0x68, 0xde, |
| 136 | 0x38, 0x36, 0xe8, 0x0f, 0xa2, 0x84, 0x6b, 0x4e, 0xf3, 0x9a, 0x02, 0x31, 0x24, 0x41, 0x22, 0xca, | 136 | 0x38, 0x36, 0xe8, 0x0f, 0xa2, 0x84, 0x6b, 0x4e, 0xf3, 0x9a, 0x02, 0x31, 0x24, 0x41, 0x22, 0xca, |
| 137 | }, .Big); | 137 | }, .big); |
| 138 | const inverse = scalar.invert(); | 138 | const inverse = scalar.invert(); |
| 139 | const inverse2 = inverse.invert(); | 139 | const inverse2 = inverse.invert(); |
| 140 | try testing.expectEqualSlices(u8, &out, &inverse.toBytes(.Big)); | 140 | try testing.expectEqualSlices(u8, &out, &inverse.toBytes(.big)); |
| 141 | try testing.expect(inverse2.equivalent(scalar)); | 141 | try testing.expect(inverse2.equivalent(scalar)); |
| 142 | 142 | ||
| 143 | const sq = scalar.sq(); | 143 | const sq = scalar.sq(); |
lib/std/crypto/pcurves/tests/secp256k1.zig+24-24| ... | @@ -5,22 +5,22 @@ const testing = std.testing; | ... | @@ -5,22 +5,22 @@ const testing = std.testing; |
| 5 | const Secp256k1 = @import("../secp256k1.zig").Secp256k1; | 5 | const Secp256k1 = @import("../secp256k1.zig").Secp256k1; |
| 6 | 6 | ||
| 7 | test "secp256k1 ECDH key exchange" { | 7 | test "secp256k1 ECDH key exchange" { |
| 8 | const dha = Secp256k1.scalar.random(.Little); | 8 | const dha = Secp256k1.scalar.random(.little); |
| 9 | const dhb = Secp256k1.scalar.random(.Little); | 9 | const dhb = Secp256k1.scalar.random(.little); |
| 10 | const dhA = try Secp256k1.basePoint.mul(dha, .Little); | 10 | const dhA = try Secp256k1.basePoint.mul(dha, .little); |
| 11 | const dhB = try Secp256k1.basePoint.mul(dhb, .Little); | 11 | const dhB = try Secp256k1.basePoint.mul(dhb, .little); |
| 12 | const shareda = try dhA.mul(dhb, .Little); | 12 | const shareda = try dhA.mul(dhb, .little); |
| 13 | const sharedb = try dhB.mul(dha, .Little); | 13 | const sharedb = try dhB.mul(dha, .little); |
| 14 | try testing.expect(shareda.equivalent(sharedb)); | 14 | try testing.expect(shareda.equivalent(sharedb)); |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | test "secp256k1 ECDH key exchange including public multiplication" { | 17 | test "secp256k1 ECDH key exchange including public multiplication" { |
| 18 | const dha = Secp256k1.scalar.random(.Little); | 18 | const dha = Secp256k1.scalar.random(.little); |
| 19 | const dhb = Secp256k1.scalar.random(.Little); | 19 | const dhb = Secp256k1.scalar.random(.little); |
| 20 | const dhA = try Secp256k1.basePoint.mul(dha, .Little); | 20 | const dhA = try Secp256k1.basePoint.mul(dha, .little); |
| 21 | const dhB = try Secp256k1.basePoint.mulPublic(dhb, .Little); | 21 | const dhB = try Secp256k1.basePoint.mulPublic(dhb, .little); |
| 22 | const shareda = try dhA.mul(dhb, .Little); | 22 | const shareda = try dhA.mul(dhb, .little); |
| 23 | const sharedb = try dhB.mulPublic(dha, .Little); | 23 | const sharedb = try dhB.mulPublic(dha, .little); |
| 24 | try testing.expect(shareda.equivalent(sharedb)); | 24 | try testing.expect(shareda.equivalent(sharedb)); |
| 25 | } | 25 | } |
| 26 | 26 | ||
| ... | @@ -31,7 +31,7 @@ test "secp256k1 point from affine coordinates" { | ... | @@ -31,7 +31,7 @@ test "secp256k1 point from affine coordinates" { |
| 31 | _ = try fmt.hexToBytes(&xs, xh); | 31 | _ = try fmt.hexToBytes(&xs, xh); |
| 32 | var ys: [32]u8 = undefined; | 32 | var ys: [32]u8 = undefined; |
| 33 | _ = try fmt.hexToBytes(&ys, yh); | 33 | _ = try fmt.hexToBytes(&ys, yh); |
| 34 | var p = try Secp256k1.fromSerializedAffineCoordinates(xs, ys, .Big); | 34 | var p = try Secp256k1.fromSerializedAffineCoordinates(xs, ys, .big); |
| 35 | try testing.expect(p.equivalent(Secp256k1.basePoint)); | 35 | try testing.expect(p.equivalent(Secp256k1.basePoint)); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| ... | @@ -54,7 +54,7 @@ test "secp256k1 test vectors" { | ... | @@ -54,7 +54,7 @@ test "secp256k1 test vectors" { |
| 54 | p = p.add(Secp256k1.basePoint); | 54 | p = p.add(Secp256k1.basePoint); |
| 55 | var xs: [32]u8 = undefined; | 55 | var xs: [32]u8 = undefined; |
| 56 | _ = try fmt.hexToBytes(&xs, xh); | 56 | _ = try fmt.hexToBytes(&xs, xh); |
| 57 | try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs); | 57 | try testing.expectEqualSlices(u8, &x.toBytes(.big), &xs); |
| 58 | } | 58 | } |
| 59 | } | 59 | } |
| 60 | 60 | ||
| ... | @@ -72,7 +72,7 @@ test "secp256k1 test vectors - doubling" { | ... | @@ -72,7 +72,7 @@ test "secp256k1 test vectors - doubling" { |
| 72 | p = p.dbl(); | 72 | p = p.dbl(); |
| 73 | var xs: [32]u8 = undefined; | 73 | var xs: [32]u8 = undefined; |
| 74 | _ = try fmt.hexToBytes(&xs, xh); | 74 | _ = try fmt.hexToBytes(&xs, xh); |
| 75 | try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs); | 75 | try testing.expectEqualSlices(u8, &x.toBytes(.big), &xs); |
| 76 | } | 76 | } |
| 77 | } | 77 | } |
| 78 | 78 | ||
| ... | @@ -91,20 +91,20 @@ test "secp256k1 uncompressed sec1 encoding/decoding" { | ... | @@ -91,20 +91,20 @@ test "secp256k1 uncompressed sec1 encoding/decoding" { |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | test "secp256k1 public key is the neutral element" { | 93 | test "secp256k1 public key is the neutral element" { |
| 94 | const n = Secp256k1.scalar.Scalar.zero.toBytes(.Little); | 94 | const n = Secp256k1.scalar.Scalar.zero.toBytes(.little); |
| 95 | const p = Secp256k1.random(); | 95 | const p = Secp256k1.random(); |
| 96 | try testing.expectError(error.IdentityElement, p.mul(n, .Little)); | 96 | try testing.expectError(error.IdentityElement, p.mul(n, .little)); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | test "secp256k1 public key is the neutral element (public verification)" { | 99 | test "secp256k1 public key is the neutral element (public verification)" { |
| 100 | const n = Secp256k1.scalar.Scalar.zero.toBytes(.Little); | 100 | const n = Secp256k1.scalar.Scalar.zero.toBytes(.little); |
| 101 | const p = Secp256k1.random(); | 101 | const p = Secp256k1.random(); |
| 102 | try testing.expectError(error.IdentityElement, p.mulPublic(n, .Little)); | 102 | try testing.expectError(error.IdentityElement, p.mulPublic(n, .little)); |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | test "secp256k1 field element non-canonical encoding" { | 105 | test "secp256k1 field element non-canonical encoding" { |
| 106 | const s = [_]u8{0xff} ** 32; | 106 | const s = [_]u8{0xff} ** 32; |
| 107 | try testing.expectError(error.NonCanonical, Secp256k1.Fe.fromBytes(s, .Little)); | 107 | try testing.expectError(error.NonCanonical, Secp256k1.Fe.fromBytes(s, .little)); |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | test "secp256k1 neutral element decoding" { | 110 | test "secp256k1 neutral element decoding" { |
| ... | @@ -118,8 +118,8 @@ test "secp256k1 double base multiplication" { | ... | @@ -118,8 +118,8 @@ test "secp256k1 double base multiplication" { |
| 118 | const p2 = Secp256k1.basePoint.dbl(); | 118 | const p2 = Secp256k1.basePoint.dbl(); |
| 119 | const s1 = [_]u8{0x01} ** 32; | 119 | const s1 = [_]u8{0x01} ** 32; |
| 120 | const s2 = [_]u8{0x02} ** 32; | 120 | const s2 = [_]u8{0x02} ** 32; |
| 121 | const pr1 = try Secp256k1.mulDoubleBasePublic(p1, s1, p2, s2, .Little); | 121 | const pr1 = try Secp256k1.mulDoubleBasePublic(p1, s1, p2, s2, .little); |
| 122 | const pr2 = (try p1.mul(s1, .Little)).add(try p2.mul(s2, .Little)); | 122 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); |
| 123 | try testing.expect(pr1.equivalent(pr2)); | 123 | try testing.expect(pr1.equivalent(pr2)); |
| 124 | } | 124 | } |
| 125 | 125 | ||
| ... | @@ -131,9 +131,9 @@ test "secp256k1 scalar inverse" { | ... | @@ -131,9 +131,9 @@ test "secp256k1 scalar inverse" { |
| 131 | const scalar = try Secp256k1.scalar.Scalar.fromBytes(.{ | 131 | const scalar = try Secp256k1.scalar.Scalar.fromBytes(.{ |
| 132 | 0x94, 0xa1, 0xbb, 0xb1, 0x4b, 0x90, 0x6a, 0x61, 0xa2, 0x80, 0xf2, 0x45, 0xf9, 0xe9, 0x3c, 0x7f, | 132 | 0x94, 0xa1, 0xbb, 0xb1, 0x4b, 0x90, 0x6a, 0x61, 0xa2, 0x80, 0xf2, 0x45, 0xf9, 0xe9, 0x3c, 0x7f, |
| 133 | 0x3b, 0x4a, 0x62, 0x47, 0x82, 0x4f, 0x5d, 0x33, 0xb9, 0x67, 0x07, 0x87, 0x64, 0x2a, 0x68, 0xde, | 133 | 0x3b, 0x4a, 0x62, 0x47, 0x82, 0x4f, 0x5d, 0x33, 0xb9, 0x67, 0x07, 0x87, 0x64, 0x2a, 0x68, 0xde, |
| 134 | }, .Big); | 134 | }, .big); |
| 135 | const inverse = scalar.invert(); | 135 | const inverse = scalar.invert(); |
| 136 | try std.testing.expectEqualSlices(u8, &out, &inverse.toBytes(.Big)); | 136 | try std.testing.expectEqualSlices(u8, &out, &inverse.toBytes(.big)); |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | test "secp256k1 scalar parity" { | 139 | test "secp256k1 scalar parity" { |
lib/std/crypto/poly1305.zig+8-8| ... | @@ -22,12 +22,12 @@ pub const Poly1305 = struct { | ... | @@ -22,12 +22,12 @@ pub const Poly1305 = struct { |
| 22 | pub fn init(key: *const [key_length]u8) Poly1305 { | 22 | pub fn init(key: *const [key_length]u8) Poly1305 { |
| 23 | return Poly1305{ | 23 | return Poly1305{ |
| 24 | .r = [_]u64{ | 24 | .r = [_]u64{ |
| 25 | mem.readInt(u64, key[0..8], .Little) & 0x0ffffffc0fffffff, | 25 | mem.readInt(u64, key[0..8], .little) & 0x0ffffffc0fffffff, |
| 26 | mem.readInt(u64, key[8..16], .Little) & 0x0ffffffc0ffffffc, | 26 | mem.readInt(u64, key[8..16], .little) & 0x0ffffffc0ffffffc, |
| 27 | }, | 27 | }, |
| 28 | .pad = [_]u64{ | 28 | .pad = [_]u64{ |
| 29 | mem.readInt(u64, key[16..24], .Little), | 29 | mem.readInt(u64, key[16..24], .little), |
| 30 | mem.readInt(u64, key[24..32], .Little), | 30 | mem.readInt(u64, key[24..32], .little), |
| 31 | }, | 31 | }, |
| 32 | }; | 32 | }; |
| 33 | } | 33 | } |
| ... | @@ -56,8 +56,8 @@ pub const Poly1305 = struct { | ... | @@ -56,8 +56,8 @@ pub const Poly1305 = struct { |
| 56 | var i: usize = 0; | 56 | var i: usize = 0; |
| 57 | 57 | ||
| 58 | while (i + block_length <= m.len) : (i += block_length) { | 58 | while (i + block_length <= m.len) : (i += block_length) { |
| 59 | const in0 = mem.readInt(u64, m[i..][0..8], .Little); | 59 | const in0 = mem.readInt(u64, m[i..][0..8], .little); |
| 60 | const in1 = mem.readInt(u64, m[i + 8 ..][0..8], .Little); | 60 | const in1 = mem.readInt(u64, m[i + 8 ..][0..8], .little); |
| 61 | 61 | ||
| 62 | // Add the input message to H | 62 | // Add the input message to H |
| 63 | var v = @addWithOverflow(h0, in0); | 63 | var v = @addWithOverflow(h0, in0); |
| ... | @@ -182,8 +182,8 @@ pub const Poly1305 = struct { | ... | @@ -182,8 +182,8 @@ pub const Poly1305 = struct { |
| 182 | const c = ((h0 & st.pad[0]) | ((h0 | st.pad[0]) & ~st.h[0])) >> 63; | 182 | const c = ((h0 & st.pad[0]) | ((h0 | st.pad[0]) & ~st.h[0])) >> 63; |
| 183 | st.h[1] = h1 +% st.pad[1] +% c; | 183 | st.h[1] = h1 +% st.pad[1] +% c; |
| 184 | 184 | ||
| 185 | mem.writeInt(u64, out[0..8], st.h[0], .Little); | 185 | mem.writeInt(u64, out[0..8], st.h[0], .little); |
| 186 | mem.writeInt(u64, out[8..16], st.h[1], .Little); | 186 | mem.writeInt(u64, out[8..16], st.h[1], .little); |
| 187 | 187 | ||
| 188 | utils.secureZero(u8, @as([*]u8, @ptrCast(st))[0..@sizeOf(Poly1305)]); | 188 | utils.secureZero(u8, @as([*]u8, @ptrCast(st))[0..@sizeOf(Poly1305)]); |
| 189 | } | 189 | } |
lib/std/crypto/salsa20.zig+34-34| ... | @@ -29,10 +29,10 @@ fn SalsaVecImpl(comptime rounds: comptime_int) type { | ... | @@ -29,10 +29,10 @@ fn SalsaVecImpl(comptime rounds: comptime_int) type { |
| 29 | fn initContext(key: [8]u32, d: [4]u32) BlockVec { | 29 | fn initContext(key: [8]u32, d: [4]u32) BlockVec { |
| 30 | const c = "expand 32-byte k"; | 30 | const c = "expand 32-byte k"; |
| 31 | const constant_le = comptime [4]u32{ | 31 | const constant_le = comptime [4]u32{ |
| 32 | mem.readInt(u32, c[0..4], .Little), | 32 | mem.readInt(u32, c[0..4], .little), |
| 33 | mem.readInt(u32, c[4..8], .Little), | 33 | mem.readInt(u32, c[4..8], .little), |
| 34 | mem.readInt(u32, c[8..12], .Little), | 34 | mem.readInt(u32, c[8..12], .little), |
| 35 | mem.readInt(u32, c[12..16], .Little), | 35 | mem.readInt(u32, c[12..16], .little), |
| 36 | }; | 36 | }; |
| 37 | return BlockVec{ | 37 | return BlockVec{ |
| 38 | Lane{ key[0], key[1], key[2], key[3] }, | 38 | Lane{ key[0], key[1], key[2], key[3] }, |
| ... | @@ -112,10 +112,10 @@ fn SalsaVecImpl(comptime rounds: comptime_int) type { | ... | @@ -112,10 +112,10 @@ fn SalsaVecImpl(comptime rounds: comptime_int) type { |
| 112 | fn hashToBytes(out: *[64]u8, x: BlockVec) void { | 112 | fn hashToBytes(out: *[64]u8, x: BlockVec) void { |
| 113 | var i: usize = 0; | 113 | var i: usize = 0; |
| 114 | while (i < 4) : (i += 1) { | 114 | while (i < 4) : (i += 1) { |
| 115 | mem.writeInt(u32, out[16 * i + 0 ..][0..4], x[i][0], .Little); | 115 | mem.writeInt(u32, out[16 * i + 0 ..][0..4], x[i][0], .little); |
| 116 | mem.writeInt(u32, out[16 * i + 4 ..][0..4], x[i][1], .Little); | 116 | mem.writeInt(u32, out[16 * i + 4 ..][0..4], x[i][1], .little); |
| 117 | mem.writeInt(u32, out[16 * i + 8 ..][0..4], x[i][2], .Little); | 117 | mem.writeInt(u32, out[16 * i + 8 ..][0..4], x[i][2], .little); |
| 118 | mem.writeInt(u32, out[16 * i + 12 ..][0..4], x[i][3], .Little); | 118 | mem.writeInt(u32, out[16 * i + 12 ..][0..4], x[i][3], .little); |
| 119 | } | 119 | } |
| 120 | } | 120 | } |
| 121 | 121 | ||
| ... | @@ -158,20 +158,20 @@ fn SalsaVecImpl(comptime rounds: comptime_int) type { | ... | @@ -158,20 +158,20 @@ fn SalsaVecImpl(comptime rounds: comptime_int) type { |
| 158 | fn hsalsa(input: [16]u8, key: [32]u8) [32]u8 { | 158 | fn hsalsa(input: [16]u8, key: [32]u8) [32]u8 { |
| 159 | var c: [4]u32 = undefined; | 159 | var c: [4]u32 = undefined; |
| 160 | for (c, 0..) |_, i| { | 160 | for (c, 0..) |_, i| { |
| 161 | c[i] = mem.readInt(u32, input[4 * i ..][0..4], .Little); | 161 | c[i] = mem.readInt(u32, input[4 * i ..][0..4], .little); |
| 162 | } | 162 | } |
| 163 | const ctx = initContext(keyToWords(key), c); | 163 | const ctx = initContext(keyToWords(key), c); |
| 164 | var x: BlockVec = undefined; | 164 | var x: BlockVec = undefined; |
| 165 | salsaCore(x[0..], ctx, false); | 165 | salsaCore(x[0..], ctx, false); |
| 166 | var out: [32]u8 = undefined; | 166 | var out: [32]u8 = undefined; |
| 167 | mem.writeInt(u32, out[0..4], x[0][0], .Little); | 167 | mem.writeInt(u32, out[0..4], x[0][0], .little); |
| 168 | mem.writeInt(u32, out[4..8], x[1][1], .Little); | 168 | mem.writeInt(u32, out[4..8], x[1][1], .little); |
| 169 | mem.writeInt(u32, out[8..12], x[2][2], .Little); | 169 | mem.writeInt(u32, out[8..12], x[2][2], .little); |
| 170 | mem.writeInt(u32, out[12..16], x[3][3], .Little); | 170 | mem.writeInt(u32, out[12..16], x[3][3], .little); |
| 171 | mem.writeInt(u32, out[16..20], x[1][2], .Little); | 171 | mem.writeInt(u32, out[16..20], x[1][2], .little); |
| 172 | mem.writeInt(u32, out[20..24], x[1][3], .Little); | 172 | mem.writeInt(u32, out[20..24], x[1][3], .little); |
| 173 | mem.writeInt(u32, out[24..28], x[2][0], .Little); | 173 | mem.writeInt(u32, out[24..28], x[2][0], .little); |
| 174 | mem.writeInt(u32, out[28..32], x[2][1], .Little); | 174 | mem.writeInt(u32, out[28..32], x[2][1], .little); |
| 175 | return out; | 175 | return out; |
| 176 | } | 176 | } |
| 177 | }; | 177 | }; |
| ... | @@ -184,10 +184,10 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type { | ... | @@ -184,10 +184,10 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type { |
| 184 | fn initContext(key: [8]u32, d: [4]u32) BlockVec { | 184 | fn initContext(key: [8]u32, d: [4]u32) BlockVec { |
| 185 | const c = "expand 32-byte k"; | 185 | const c = "expand 32-byte k"; |
| 186 | const constant_le = comptime [4]u32{ | 186 | const constant_le = comptime [4]u32{ |
| 187 | mem.readInt(u32, c[0..4], .Little), | 187 | mem.readInt(u32, c[0..4], .little), |
| 188 | mem.readInt(u32, c[4..8], .Little), | 188 | mem.readInt(u32, c[4..8], .little), |
| 189 | mem.readInt(u32, c[8..12], .Little), | 189 | mem.readInt(u32, c[8..12], .little), |
| 190 | mem.readInt(u32, c[12..16], .Little), | 190 | mem.readInt(u32, c[12..16], .little), |
| 191 | }; | 191 | }; |
| 192 | return BlockVec{ | 192 | return BlockVec{ |
| 193 | constant_le[0], key[0], key[1], key[2], | 193 | constant_le[0], key[0], key[1], key[2], |
| ... | @@ -241,7 +241,7 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type { | ... | @@ -241,7 +241,7 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type { |
| 241 | 241 | ||
| 242 | fn hashToBytes(out: *[64]u8, x: BlockVec) void { | 242 | fn hashToBytes(out: *[64]u8, x: BlockVec) void { |
| 243 | for (x, 0..) |w, i| { | 243 | for (x, 0..) |w, i| { |
| 244 | mem.writeInt(u32, out[i * 4 ..][0..4], w, .Little); | 244 | mem.writeInt(u32, out[i * 4 ..][0..4], w, .little); |
| 245 | } | 245 | } |
| 246 | } | 246 | } |
| 247 | 247 | ||
| ... | @@ -283,20 +283,20 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type { | ... | @@ -283,20 +283,20 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type { |
| 283 | fn hsalsa(input: [16]u8, key: [32]u8) [32]u8 { | 283 | fn hsalsa(input: [16]u8, key: [32]u8) [32]u8 { |
| 284 | var c: [4]u32 = undefined; | 284 | var c: [4]u32 = undefined; |
| 285 | for (c, 0..) |_, i| { | 285 | for (c, 0..) |_, i| { |
| 286 | c[i] = mem.readInt(u32, input[4 * i ..][0..4], .Little); | 286 | c[i] = mem.readInt(u32, input[4 * i ..][0..4], .little); |
| 287 | } | 287 | } |
| 288 | const ctx = initContext(keyToWords(key), c); | 288 | const ctx = initContext(keyToWords(key), c); |
| 289 | var x: BlockVec = undefined; | 289 | var x: BlockVec = undefined; |
| 290 | salsaCore(x[0..], ctx, false); | 290 | salsaCore(x[0..], ctx, false); |
| 291 | var out: [32]u8 = undefined; | 291 | var out: [32]u8 = undefined; |
| 292 | mem.writeInt(u32, out[0..4], x[0], .Little); | 292 | mem.writeInt(u32, out[0..4], x[0], .little); |
| 293 | mem.writeInt(u32, out[4..8], x[5], .Little); | 293 | mem.writeInt(u32, out[4..8], x[5], .little); |
| 294 | mem.writeInt(u32, out[8..12], x[10], .Little); | 294 | mem.writeInt(u32, out[8..12], x[10], .little); |
| 295 | mem.writeInt(u32, out[12..16], x[15], .Little); | 295 | mem.writeInt(u32, out[12..16], x[15], .little); |
| 296 | mem.writeInt(u32, out[16..20], x[6], .Little); | 296 | mem.writeInt(u32, out[16..20], x[6], .little); |
| 297 | mem.writeInt(u32, out[20..24], x[7], .Little); | 297 | mem.writeInt(u32, out[20..24], x[7], .little); |
| 298 | mem.writeInt(u32, out[24..28], x[8], .Little); | 298 | mem.writeInt(u32, out[24..28], x[8], .little); |
| 299 | mem.writeInt(u32, out[28..32], x[9], .Little); | 299 | mem.writeInt(u32, out[28..32], x[9], .little); |
| 300 | return out; | 300 | return out; |
| 301 | } | 301 | } |
| 302 | }; | 302 | }; |
| ... | @@ -308,7 +308,7 @@ fn keyToWords(key: [32]u8) [8]u32 { | ... | @@ -308,7 +308,7 @@ fn keyToWords(key: [32]u8) [8]u32 { |
| 308 | var k: [8]u32 = undefined; | 308 | var k: [8]u32 = undefined; |
| 309 | var i: usize = 0; | 309 | var i: usize = 0; |
| 310 | while (i < 8) : (i += 1) { | 310 | while (i < 8) : (i += 1) { |
| 311 | k[i] = mem.readInt(u32, key[i * 4 ..][0..4], .Little); | 311 | k[i] = mem.readInt(u32, key[i * 4 ..][0..4], .little); |
| 312 | } | 312 | } |
| 313 | return k; | 313 | return k; |
| 314 | } | 314 | } |
| ... | @@ -335,8 +335,8 @@ pub fn Salsa(comptime rounds: comptime_int) type { | ... | @@ -335,8 +335,8 @@ pub fn Salsa(comptime rounds: comptime_int) type { |
| 335 | debug.assert(in.len == out.len); | 335 | debug.assert(in.len == out.len); |
| 336 | 336 | ||
| 337 | var d: [4]u32 = undefined; | 337 | var d: [4]u32 = undefined; |
| 338 | d[0] = mem.readInt(u32, nonce[0..4], .Little); | 338 | d[0] = mem.readInt(u32, nonce[0..4], .little); |
| 339 | d[1] = mem.readInt(u32, nonce[4..8], .Little); | 339 | d[1] = mem.readInt(u32, nonce[4..8], .little); |
| 340 | d[2] = @as(u32, @truncate(counter)); | 340 | d[2] = @as(u32, @truncate(counter)); |
| 341 | d[3] = @as(u32, @truncate(counter >> 32)); | 341 | d[3] = @as(u32, @truncate(counter >> 32)); |
| 342 | SalsaImpl(rounds).salsaXor(out, in, keyToWords(key), d); | 342 | SalsaImpl(rounds).salsaXor(out, in, keyToWords(key), d); |
lib/std/crypto/scrypt.zig+4-4| ... | @@ -91,7 +91,7 @@ fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) | ... | @@ -91,7 +91,7 @@ fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) |
| 91 | var y: []align(16) u32 = @alignCast(xy[32 * r ..]); | 91 | var y: []align(16) u32 = @alignCast(xy[32 * r ..]); |
| 92 | 92 | ||
| 93 | for (x, 0..) |*v1, j| { | 93 | for (x, 0..) |*v1, j| { |
| 94 | v1.* = mem.readInt(u32, b[4 * j ..][0..4], .Little); | 94 | v1.* = mem.readInt(u32, b[4 * j ..][0..4], .little); |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | var tmp: [16]u32 align(16) = undefined; | 97 | var tmp: [16]u32 align(16) = undefined; |
| ... | @@ -116,7 +116,7 @@ fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) | ... | @@ -116,7 +116,7 @@ fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | for (x, 0..) |v1, j| { | 118 | for (x, 0..) |v1, j| { |
| 119 | mem.writeInt(u32, b[4 * j ..][0..4], v1, .Little); | 119 | mem.writeInt(u32, b[4 * j ..][0..4], v1, .little); |
| 120 | } | 120 | } |
| 121 | } | 121 | } |
| 122 | 122 | ||
| ... | @@ -361,7 +361,7 @@ const crypt_format = struct { | ... | @@ -361,7 +361,7 @@ const crypt_format = struct { |
| 361 | std.debug.assert(dst.len == decodedLen(src.len)); | 361 | std.debug.assert(dst.len == decodedLen(src.len)); |
| 362 | var i: usize = 0; | 362 | var i: usize = 0; |
| 363 | while (i < src.len / 4) : (i += 1) { | 363 | while (i < src.len / 4) : (i += 1) { |
| 364 | mem.writeInt(u24, dst[i * 3 ..][0..3], try intDecode(u24, src[i * 4 ..][0..4]), .Little); | 364 | mem.writeInt(u24, dst[i * 3 ..][0..3], try intDecode(u24, src[i * 4 ..][0..4]), .little); |
| 365 | } | 365 | } |
| 366 | const leftover = src[i * 4 ..]; | 366 | const leftover = src[i * 4 ..]; |
| 367 | var v: u24 = 0; | 367 | var v: u24 = 0; |
| ... | @@ -377,7 +377,7 @@ const crypt_format = struct { | ... | @@ -377,7 +377,7 @@ const crypt_format = struct { |
| 377 | std.debug.assert(dst.len == encodedLen(src.len)); | 377 | std.debug.assert(dst.len == encodedLen(src.len)); |
| 378 | var i: usize = 0; | 378 | var i: usize = 0; |
| 379 | while (i < src.len / 3) : (i += 1) { | 379 | while (i < src.len / 3) : (i += 1) { |
| 380 | intEncode(dst[i * 4 ..][0..4], mem.readInt(u24, src[i * 3 ..][0..3], .Little)); | 380 | intEncode(dst[i * 4 ..][0..4], mem.readInt(u24, src[i * 3 ..][0..3], .little)); |
| 381 | } | 381 | } |
| 382 | const leftover = src[i * 3 ..]; | 382 | const leftover = src[i * 3 ..]; |
| 383 | var v: u24 = 0; | 383 | var v: u24 = 0; |
lib/std/crypto/sha1.zig+2-2| ... | @@ -111,7 +111,7 @@ pub const Sha1 = struct { | ... | @@ -111,7 +111,7 @@ pub const Sha1 = struct { |
| 111 | d.round(d.buf[0..]); | 111 | d.round(d.buf[0..]); |
| 112 | 112 | ||
| 113 | for (d.s, 0..) |s, j| { | 113 | for (d.s, 0..) |s, j| { |
| 114 | mem.writeInt(u32, out[4 * j ..][0..4], s, .Big); | 114 | mem.writeInt(u32, out[4 * j ..][0..4], s, .big); |
| 115 | } | 115 | } |
| 116 | } | 116 | } |
| 117 | 117 | ||
| ... | @@ -151,7 +151,7 @@ pub const Sha1 = struct { | ... | @@ -151,7 +151,7 @@ pub const Sha1 = struct { |
| 151 | roundParam(0, 1, 2, 3, 4, 15), | 151 | roundParam(0, 1, 2, 3, 4, 15), |
| 152 | }; | 152 | }; |
| 153 | inline for (round0a) |r| { | 153 | inline for (round0a) |r| { |
| 154 | s[r.i] = mem.readInt(u32, b[r.i * 4 ..][0..4], .Big); | 154 | s[r.i] = mem.readInt(u32, b[r.i * 4 ..][0..4], .big); |
| 155 | 155 | ||
| 156 | v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], @as(u32, 5)) +% 0x5A827999 +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) | (~v[r.b] & v[r.d])); | 156 | v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], @as(u32, 5)) +% 0x5A827999 +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) | (~v[r.b] & v[r.d])); |
| 157 | v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30)); | 157 | v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30)); |
lib/std/crypto/sha2.zig+4-4| ... | @@ -171,7 +171,7 @@ fn Sha2x32(comptime params: Sha2Params32) type { | ... | @@ -171,7 +171,7 @@ fn Sha2x32(comptime params: Sha2Params32) type { |
| 171 | const rr = d.s[0 .. params.digest_bits / 32]; | 171 | const rr = d.s[0 .. params.digest_bits / 32]; |
| 172 | 172 | ||
| 173 | for (rr, 0..) |s, j| { | 173 | for (rr, 0..) |s, j| { |
| 174 | mem.writeInt(u32, out[4 * j ..][0..4], s, .Big); | 174 | mem.writeInt(u32, out[4 * j ..][0..4], s, .big); |
| 175 | } | 175 | } |
| 176 | } | 176 | } |
| 177 | 177 | ||
| ... | @@ -195,7 +195,7 @@ fn Sha2x32(comptime params: Sha2Params32) type { | ... | @@ -195,7 +195,7 @@ fn Sha2x32(comptime params: Sha2Params32) type { |
| 195 | fn round(d: *Self, b: *const [64]u8) void { | 195 | fn round(d: *Self, b: *const [64]u8) void { |
| 196 | var s: [64]u32 align(16) = undefined; | 196 | var s: [64]u32 align(16) = undefined; |
| 197 | for (@as(*align(1) const [16]u32, @ptrCast(b)), 0..) |*elem, i| { | 197 | for (@as(*align(1) const [16]u32, @ptrCast(b)), 0..) |*elem, i| { |
| 198 | s[i] = mem.readInt(u32, mem.asBytes(elem), .Big); | 198 | s[i] = mem.readInt(u32, mem.asBytes(elem), .big); |
| 199 | } | 199 | } |
| 200 | 200 | ||
| 201 | if (!@inComptime()) { | 201 | if (!@inComptime()) { |
| ... | @@ -663,7 +663,7 @@ fn Sha2x64(comptime params: Sha2Params64) type { | ... | @@ -663,7 +663,7 @@ fn Sha2x64(comptime params: Sha2Params64) type { |
| 663 | const rr = d.s[0 .. params.digest_bits / 64]; | 663 | const rr = d.s[0 .. params.digest_bits / 64]; |
| 664 | 664 | ||
| 665 | for (rr, 0..) |s, j| { | 665 | for (rr, 0..) |s, j| { |
| 666 | mem.writeInt(u64, out[8 * j ..][0..8], s, .Big); | 666 | mem.writeInt(u64, out[8 * j ..][0..8], s, .big); |
| 667 | } | 667 | } |
| 668 | } | 668 | } |
| 669 | 669 | ||
| ... | @@ -678,7 +678,7 @@ fn Sha2x64(comptime params: Sha2Params64) type { | ... | @@ -678,7 +678,7 @@ fn Sha2x64(comptime params: Sha2Params64) type { |
| 678 | 678 | ||
| 679 | var i: usize = 0; | 679 | var i: usize = 0; |
| 680 | while (i < 16) : (i += 1) { | 680 | while (i < 16) : (i += 1) { |
| 681 | s[i] = mem.readInt(u64, b[i * 8 ..][0..8], .Big); | 681 | s[i] = mem.readInt(u64, b[i * 8 ..][0..8], .big); |
| 682 | } | 682 | } |
| 683 | while (i < 80) : (i += 1) { | 683 | while (i < 80) : (i += 1) { |
| 684 | s[i] = s[i - 16] +% s[i - 7] +% | 684 | s[i] = s[i - 16] +% s[i - 7] +% |
lib/std/crypto/siphash.zig+4-4| ... | @@ -56,8 +56,8 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round | ... | @@ -56,8 +56,8 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round |
| 56 | msg_len: u8, | 56 | msg_len: u8, |
| 57 | 57 | ||
| 58 | fn init(key: *const [key_length]u8) Self { | 58 | fn init(key: *const [key_length]u8) Self { |
| 59 | const k0 = mem.readInt(u64, key[0..8], .Little); | 59 | const k0 = mem.readInt(u64, key[0..8], .little); |
| 60 | const k1 = mem.readInt(u64, key[8..16], .Little); | 60 | const k1 = mem.readInt(u64, key[8..16], .little); |
| 61 | 61 | ||
| 62 | var d = Self{ | 62 | var d = Self{ |
| 63 | .v0 = k0 ^ 0x736f6d6570736575, | 63 | .v0 = k0 ^ 0x736f6d6570736575, |
| ... | @@ -124,7 +124,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round | ... | @@ -124,7 +124,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round |
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | fn round(self: *Self, b: [8]u8) void { | 126 | fn round(self: *Self, b: [8]u8) void { |
| 127 | const m = mem.readInt(u64, &b, .Little); | 127 | const m = mem.readInt(u64, &b, .little); |
| 128 | self.v3 ^= m; | 128 | self.v3 ^= m; |
| 129 | 129 | ||
| 130 | comptime var i: usize = 0; | 130 | comptime var i: usize = 0; |
| ... | @@ -213,7 +213,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize) | ... | @@ -213,7 +213,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize) |
| 213 | /// Return an authentication tag for the current state | 213 | /// Return an authentication tag for the current state |
| 214 | /// Assumes `out` is less than or equal to `mac_length`. | 214 | /// Assumes `out` is less than or equal to `mac_length`. |
| 215 | pub fn final(self: *Self, out: *[mac_length]u8) void { | 215 | pub fn final(self: *Self, out: *[mac_length]u8) void { |
| 216 | mem.writeInt(T, out, self.state.final(self.buf[0..self.buf_len]), .Little); | 216 | mem.writeInt(T, out, self.state.final(self.buf[0..self.buf_len]), .little); |
| 217 | } | 217 | } |
| 218 | 218 | ||
| 219 | pub fn finalResult(self: *Self) [mac_length]u8 { | 219 | pub fn finalResult(self: *Self) [mac_length]u8 { |
lib/std/crypto/tls.zig+1-1| ... | @@ -370,7 +370,7 @@ pub fn hkdfExpandLabel( | ... | @@ -370,7 +370,7 @@ pub fn hkdfExpandLabel( |
| 370 | const max_context_len = 255; | 370 | const max_context_len = 255; |
| 371 | const tls13 = "tls13 "; | 371 | const tls13 = "tls13 "; |
| 372 | var buf: [2 + 1 + tls13.len + max_label_len + 1 + max_context_len]u8 = undefined; | 372 | var buf: [2 + 1 + tls13.len + max_label_len + 1 + max_context_len]u8 = undefined; |
| 373 | mem.writeInt(u16, buf[0..2], len, .Big); | 373 | mem.writeInt(u16, buf[0..2], len, .big); |
| 374 | buf[2] = @as(u8, @intCast(tls13.len + label.len)); | 374 | buf[2] = @as(u8, @intCast(tls13.len + label.len)); |
| 375 | buf[3..][0..tls13.len].* = tls13.*; | 375 | buf[3..][0..tls13.len].* = tls13.*; |
| 376 | var i: usize = 3 + tls13.len; | 376 | var i: usize = 3 + tls13.len; |
lib/std/crypto/tls/Client.zig+7-7| ... | @@ -332,10 +332,10 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In | ... | @@ -332,10 +332,10 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In |
| 332 | const pk = PublicKey.fromSec1(server_pub_key) catch { | 332 | const pk = PublicKey.fromSec1(server_pub_key) catch { |
| 333 | return error.TlsDecryptFailure; | 333 | return error.TlsDecryptFailure; |
| 334 | }; | 334 | }; |
| 335 | const mul = pk.p.mulPublic(secp256r1_kp.secret_key.bytes, .Big) catch { | 335 | const mul = pk.p.mulPublic(secp256r1_kp.secret_key.bytes, .big) catch { |
| 336 | return error.TlsDecryptFailure; | 336 | return error.TlsDecryptFailure; |
| 337 | }; | 337 | }; |
| 338 | shared_key = &mul.affineCoordinates().x.toBytes(.Big); | 338 | shared_key = &mul.affineCoordinates().x.toBytes(.big); |
| 339 | }, | 339 | }, |
| 340 | else => { | 340 | else => { |
| 341 | return error.TlsIllegalParameter; | 341 | return error.TlsIllegalParameter; |
| ... | @@ -1049,10 +1049,10 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec) | ... | @@ -1049,10 +1049,10 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec) |
| 1049 | } | 1049 | } |
| 1050 | const ct: tls.ContentType = @enumFromInt(frag[in]); | 1050 | const ct: tls.ContentType = @enumFromInt(frag[in]); |
| 1051 | in += 1; | 1051 | in += 1; |
| 1052 | const legacy_version = mem.readInt(u16, frag[in..][0..2], .Big); | 1052 | const legacy_version = mem.readInt(u16, frag[in..][0..2], .big); |
| 1053 | in += 2; | 1053 | in += 2; |
| 1054 | _ = legacy_version; | 1054 | _ = legacy_version; |
| 1055 | const record_len = mem.readInt(u16, frag[in..][0..2], .Big); | 1055 | const record_len = mem.readInt(u16, frag[in..][0..2], .big); |
| 1056 | if (record_len > max_ciphertext_len) return error.TlsRecordOverflow; | 1056 | if (record_len > max_ciphertext_len) return error.TlsRecordOverflow; |
| 1057 | in += 2; | 1057 | in += 2; |
| 1058 | const end = in + record_len; | 1058 | const end = in + record_len; |
| ... | @@ -1136,7 +1136,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec) | ... | @@ -1136,7 +1136,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec) |
| 1136 | while (true) { | 1136 | while (true) { |
| 1137 | const handshake_type: tls.HandshakeType = @enumFromInt(cleartext[ct_i]); | 1137 | const handshake_type: tls.HandshakeType = @enumFromInt(cleartext[ct_i]); |
| 1138 | ct_i += 1; | 1138 | ct_i += 1; |
| 1139 | const handshake_len = mem.readInt(u24, cleartext[ct_i..][0..3], .Big); | 1139 | const handshake_len = mem.readInt(u24, cleartext[ct_i..][0..3], .big); |
| 1140 | ct_i += 3; | 1140 | ct_i += 3; |
| 1141 | const next_handshake_i = ct_i + handshake_len; | 1141 | const next_handshake_i = ct_i + handshake_len; |
| 1142 | if (next_handshake_i > cleartext.len - 1) | 1142 | if (next_handshake_i > cleartext.len - 1) |
| ... | @@ -1284,8 +1284,8 @@ const native_endian = builtin.cpu.arch.endian(); | ... | @@ -1284,8 +1284,8 @@ const native_endian = builtin.cpu.arch.endian(); |
| 1284 | 1284 | ||
| 1285 | inline fn big(x: anytype) @TypeOf(x) { | 1285 | inline fn big(x: anytype) @TypeOf(x) { |
| 1286 | return switch (native_endian) { | 1286 | return switch (native_endian) { |
| 1287 | .Big => x, | 1287 | .big => x, |
| 1288 | .Little => @byteSwap(x), | 1288 | .little => @byteSwap(x), |
| 1289 | }; | 1289 | }; |
| 1290 | } | 1290 | } |
| 1291 | 1291 |
lib/std/crypto/utils.zig+10-10| ... | @@ -54,7 +54,7 @@ pub fn timingSafeCompare(comptime T: type, a: []const T, b: []const T, endian: E | ... | @@ -54,7 +54,7 @@ pub fn timingSafeCompare(comptime T: type, a: []const T, b: []const T, endian: E |
| 54 | const Cext = std.meta.Int(.unsigned, bits + 1); | 54 | const Cext = std.meta.Int(.unsigned, bits + 1); |
| 55 | var gt: T = 0; | 55 | var gt: T = 0; |
| 56 | var eq: T = 1; | 56 | var eq: T = 1; |
| 57 | if (endian == .Little) { | 57 | if (endian == .little) { |
| 58 | var i = a.len; | 58 | var i = a.len; |
| 59 | while (i != 0) { | 59 | while (i != 0) { |
| 60 | i -= 1; | 60 | i -= 1; |
| ... | @@ -84,7 +84,7 @@ pub fn timingSafeAdd(comptime T: type, a: []const T, b: []const T, result: []T, | ... | @@ -84,7 +84,7 @@ pub fn timingSafeAdd(comptime T: type, a: []const T, b: []const T, result: []T, |
| 84 | const len = a.len; | 84 | const len = a.len; |
| 85 | debug.assert(len == b.len and len == result.len); | 85 | debug.assert(len == b.len and len == result.len); |
| 86 | var carry: u1 = 0; | 86 | var carry: u1 = 0; |
| 87 | if (endian == .Little) { | 87 | if (endian == .little) { |
| 88 | var i: usize = 0; | 88 | var i: usize = 0; |
| 89 | while (i < len) : (i += 1) { | 89 | while (i < len) : (i += 1) { |
| 90 | const ov1 = @addWithOverflow(a[i], b[i]); | 90 | const ov1 = @addWithOverflow(a[i], b[i]); |
| ... | @@ -111,7 +111,7 @@ pub fn timingSafeSub(comptime T: type, a: []const T, b: []const T, result: []T, | ... | @@ -111,7 +111,7 @@ pub fn timingSafeSub(comptime T: type, a: []const T, b: []const T, result: []T, |
| 111 | const len = a.len; | 111 | const len = a.len; |
| 112 | debug.assert(len == b.len and len == result.len); | 112 | debug.assert(len == b.len and len == result.len); |
| 113 | var borrow: u1 = 0; | 113 | var borrow: u1 = 0; |
| 114 | if (endian == .Little) { | 114 | if (endian == .little) { |
| 115 | var i: usize = 0; | 115 | var i: usize = 0; |
| 116 | while (i < len) : (i += 1) { | 116 | while (i < len) : (i += 1) { |
| 117 | const ov1 = @subWithOverflow(a[i], b[i]); | 117 | const ov1 = @subWithOverflow(a[i], b[i]); |
| ... | @@ -165,14 +165,14 @@ test "crypto.utils.timingSafeEql (vectors)" { | ... | @@ -165,14 +165,14 @@ test "crypto.utils.timingSafeEql (vectors)" { |
| 165 | test "crypto.utils.timingSafeCompare" { | 165 | test "crypto.utils.timingSafeCompare" { |
| 166 | var a = [_]u8{10} ** 32; | 166 | var a = [_]u8{10} ** 32; |
| 167 | var b = [_]u8{10} ** 32; | 167 | var b = [_]u8{10} ** 32; |
| 168 | try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .eq); | 168 | try testing.expectEqual(timingSafeCompare(u8, &a, &b, .big), .eq); |
| 169 | try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .eq); | 169 | try testing.expectEqual(timingSafeCompare(u8, &a, &b, .little), .eq); |
| 170 | a[31] = 1; | 170 | a[31] = 1; |
| 171 | try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .lt); | 171 | try testing.expectEqual(timingSafeCompare(u8, &a, &b, .big), .lt); |
| 172 | try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt); | 172 | try testing.expectEqual(timingSafeCompare(u8, &a, &b, .little), .lt); |
| 173 | a[0] = 20; | 173 | a[0] = 20; |
| 174 | try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .gt); | 174 | try testing.expectEqual(timingSafeCompare(u8, &a, &b, .big), .gt); |
| 175 | try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt); | 175 | try testing.expectEqual(timingSafeCompare(u8, &a, &b, .little), .lt); |
| 176 | } | 176 | } |
| 177 | 177 | ||
| 178 | test "crypto.utils.timingSafe{Add,Sub}" { | 178 | test "crypto.utils.timingSafe{Add,Sub}" { |
| ... | @@ -185,7 +185,7 @@ test "crypto.utils.timingSafe{Add,Sub}" { | ... | @@ -185,7 +185,7 @@ test "crypto.utils.timingSafe{Add,Sub}" { |
| 185 | while (iterations != 0) : (iterations -= 1) { | 185 | while (iterations != 0) : (iterations -= 1) { |
| 186 | random.bytes(&a); | 186 | random.bytes(&a); |
| 187 | random.bytes(&b); | 187 | random.bytes(&b); |
| 188 | const endian = if (iterations % 2 == 0) Endian.Big else Endian.Little; | 188 | const endian = if (iterations % 2 == 0) Endian.big else Endian.little; |
| 189 | _ = timingSafeSub(u8, &a, &b, &c, endian); // a-b | 189 | _ = timingSafeSub(u8, &a, &b, &c, endian); // a-b |
| 190 | _ = timingSafeAdd(u8, &c, &b, &c, endian); // (a-b)+b | 190 | _ = timingSafeAdd(u8, &c, &b, &c, endian); // (a-b)+b |
| 191 | try testing.expectEqualSlices(u8, &c, &a); | 191 | try testing.expectEqualSlices(u8, &c, &a); |
lib/std/debug.zig+3-3| ... | @@ -1098,8 +1098,8 @@ pub fn readElfDebugInfo( | ... | @@ -1098,8 +1098,8 @@ pub fn readElfDebugInfo( |
| 1098 | if (hdr.e_ident[elf.EI_VERSION] != 1) return error.InvalidElfVersion; | 1098 | if (hdr.e_ident[elf.EI_VERSION] != 1) return error.InvalidElfVersion; |
| 1099 | 1099 | ||
| 1100 | const endian: std.builtin.Endian = switch (hdr.e_ident[elf.EI_DATA]) { | 1100 | const endian: std.builtin.Endian = switch (hdr.e_ident[elf.EI_DATA]) { |
| 1101 | elf.ELFDATA2LSB => .Little, | 1101 | elf.ELFDATA2LSB => .little, |
| 1102 | elf.ELFDATA2MSB => .Big, | 1102 | elf.ELFDATA2MSB => .big, |
| 1103 | else => return error.InvalidElfEndian, | 1103 | else => return error.InvalidElfEndian, |
| 1104 | }; | 1104 | }; |
| 1105 | assert(endian == native_endian); // this is our own debug info | 1105 | assert(endian == native_endian); // this is our own debug info |
| ... | @@ -2040,7 +2040,7 @@ pub const ModuleDebugInfo = switch (native_os) { | ... | @@ -2040,7 +2040,7 @@ pub const ModuleDebugInfo = switch (native_os) { |
| 2040 | if (missing_debug_info) return error.MissingDebugInfo; | 2040 | if (missing_debug_info) return error.MissingDebugInfo; |
| 2041 | 2041 | ||
| 2042 | var di = DW.DwarfInfo{ | 2042 | var di = DW.DwarfInfo{ |
| 2043 | .endian = .Little, | 2043 | .endian = .little, |
| 2044 | .sections = sections, | 2044 | .sections = sections, |
| 2045 | .is_macho = true, | 2045 | .is_macho = true, |
| 2046 | }; | 2046 | }; |
lib/std/elf.zig+2-2| ... | @@ -497,8 +497,8 @@ pub const Header = struct { | ... | @@ -497,8 +497,8 @@ pub const Header = struct { |
| 497 | if (hdr32.e_ident[EI_VERSION] != 1) return error.InvalidElfVersion; | 497 | if (hdr32.e_ident[EI_VERSION] != 1) return error.InvalidElfVersion; |
| 498 | 498 | ||
| 499 | const endian: std.builtin.Endian = switch (hdr32.e_ident[EI_DATA]) { | 499 | const endian: std.builtin.Endian = switch (hdr32.e_ident[EI_DATA]) { |
| 500 | ELFDATA2LSB => .Little, | 500 | ELFDATA2LSB => .little, |
| 501 | ELFDATA2MSB => .Big, | 501 | ELFDATA2MSB => .big, |
| 502 | else => return error.InvalidElfEndian, | 502 | else => return error.InvalidElfEndian, |
| 503 | }; | 503 | }; |
| 504 | const need_bswap = endian != native_endian; | 504 | const need_bswap = endian != native_endian; |
lib/std/fmt/parse_float/FloatStream.zig+1-1| ... | @@ -98,7 +98,7 @@ pub fn skipChars2(self: *FloatStream, c1: u8, c2: u8) void { | ... | @@ -98,7 +98,7 @@ pub fn skipChars2(self: *FloatStream, c1: u8, c2: u8) void { |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | pub fn readU64Unchecked(self: FloatStream) u64 { | 100 | pub fn readU64Unchecked(self: FloatStream) u64 { |
| 101 | return std.mem.readInt(u64, self.slice[self.offset..][0..8], .Little); | 101 | return std.mem.readInt(u64, self.slice[self.offset..][0..8], .little); |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | pub fn readU64(self: FloatStream) ?u64 { | 104 | pub fn readU64(self: FloatStream) ?u64 { |
lib/std/fmt/parse_float/decimal.zig+1-1| ... | @@ -260,7 +260,7 @@ pub fn Decimal(comptime T: type) type { | ... | @@ -260,7 +260,7 @@ pub fn Decimal(comptime T: type) type { |
| 260 | if (!isEightDigits(v)) { | 260 | if (!isEightDigits(v)) { |
| 261 | break; | 261 | break; |
| 262 | } | 262 | } |
| 263 | std.mem.writeInt(u64, d.digits[d.num_digits..][0..8], v - 0x3030_3030_3030_3030, .Little); | 263 | std.mem.writeInt(u64, d.digits[d.num_digits..][0..8], v - 0x3030_3030_3030_3030, .little); |
| 264 | d.num_digits += 8; | 264 | d.num_digits += 8; |
| 265 | stream.advance(8); | 265 | stream.advance(8); |
| 266 | } | 266 | } |
lib/std/fs/path.zig+1-1| ... | @@ -1828,7 +1828,7 @@ test "ComponentIterator windows" { | ... | @@ -1828,7 +1828,7 @@ test "ComponentIterator windows" { |
| 1828 | 1828 | ||
| 1829 | test "ComponentIterator windows UTF-16" { | 1829 | test "ComponentIterator windows UTF-16" { |
| 1830 | // TODO: Fix on big endian architectures | 1830 | // TODO: Fix on big endian architectures |
| 1831 | if (builtin.cpu.arch.endian() != .Little) { | 1831 | if (builtin.cpu.arch.endian() != .little) { |
| 1832 | return error.SkipZigTest; | 1832 | return error.SkipZigTest; |
| 1833 | } | 1833 | } |
| 1834 | 1834 |
lib/std/hash/cityhash.zig+2-2| ... | @@ -6,11 +6,11 @@ inline fn offsetPtr(ptr: [*]const u8, offset: usize) [*]const u8 { | ... | @@ -6,11 +6,11 @@ inline fn offsetPtr(ptr: [*]const u8, offset: usize) [*]const u8 { |
| 6 | } | 6 | } |
| 7 | 7 | ||
| 8 | fn fetch32(ptr: [*]const u8, offset: usize) u32 { | 8 | fn fetch32(ptr: [*]const u8, offset: usize) u32 { |
| 9 | return std.mem.readInt(u32, offsetPtr(ptr, offset)[0..4], .Little); | 9 | return std.mem.readInt(u32, offsetPtr(ptr, offset)[0..4], .little); |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | fn fetch64(ptr: [*]const u8, offset: usize) u64 { | 12 | fn fetch64(ptr: [*]const u8, offset: usize) u64 { |
| 13 | return std.mem.readInt(u64, offsetPtr(ptr, offset)[0..8], .Little); | 13 | return std.mem.readInt(u64, offsetPtr(ptr, offset)[0..8], .little); |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | pub const CityHash32 = struct { | 16 | pub const CityHash32 = struct { |
lib/std/hash/crc.zig+1-1| ... | @@ -163,7 +163,7 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type { | ... | @@ -163,7 +163,7 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type { |
| 163 | const p = input[i..][0..8]; | 163 | const p = input[i..][0..8]; |
| 164 | 164 | ||
| 165 | // Unrolling this way gives ~50Mb/s increase | 165 | // Unrolling this way gives ~50Mb/s increase |
| 166 | self.crc ^= std.mem.readInt(u32, p[0..4], .Little); | 166 | self.crc ^= std.mem.readInt(u32, p[0..4], .little); |
| 167 | 167 | ||
| 168 | self.crc = | 168 | self.crc = |
| 169 | lookup_tables[0][p[7]] ^ | 169 | lookup_tables[0][p[7]] ^ |
lib/std/hash/murmur.zig+7-7| ... | @@ -18,7 +18,7 @@ pub const Murmur2_32 = struct { | ... | @@ -18,7 +18,7 @@ pub const Murmur2_32 = struct { |
| 18 | var h1: u32 = seed ^ len; | 18 | var h1: u32 = seed ^ len; |
| 19 | for (@as([*]align(1) const u32, @ptrCast(str.ptr))[0..(len >> 2)]) |v| { | 19 | for (@as([*]align(1) const u32, @ptrCast(str.ptr))[0..(len >> 2)]) |v| { |
| 20 | var k1: u32 = v; | 20 | var k1: u32 = v; |
| 21 | if (native_endian == .Big) | 21 | if (native_endian == .big) |
| 22 | k1 = @byteSwap(k1); | 22 | k1 = @byteSwap(k1); |
| 23 | k1 *%= m; | 23 | k1 *%= m; |
| 24 | k1 ^= k1 >> 24; | 24 | k1 ^= k1 >> 24; |
| ... | @@ -102,7 +102,7 @@ pub const Murmur2_64 = struct { | ... | @@ -102,7 +102,7 @@ pub const Murmur2_64 = struct { |
| 102 | var h1: u64 = seed ^ (@as(u64, str.len) *% m); | 102 | var h1: u64 = seed ^ (@as(u64, str.len) *% m); |
| 103 | for (@as([*]align(1) const u64, @ptrCast(str.ptr))[0 .. str.len / 8]) |v| { | 103 | for (@as([*]align(1) const u64, @ptrCast(str.ptr))[0 .. str.len / 8]) |v| { |
| 104 | var k1: u64 = v; | 104 | var k1: u64 = v; |
| 105 | if (native_endian == .Big) | 105 | if (native_endian == .big) |
| 106 | k1 = @byteSwap(k1); | 106 | k1 = @byteSwap(k1); |
| 107 | k1 *%= m; | 107 | k1 *%= m; |
| 108 | k1 ^= k1 >> 47; | 108 | k1 ^= k1 >> 47; |
| ... | @@ -115,7 +115,7 @@ pub const Murmur2_64 = struct { | ... | @@ -115,7 +115,7 @@ pub const Murmur2_64 = struct { |
| 115 | if (rest > 0) { | 115 | if (rest > 0) { |
| 116 | var k1: u64 = 0; | 116 | var k1: u64 = 0; |
| 117 | @memcpy(@as([*]u8, @ptrCast(&k1))[0..rest], str[offset..]); | 117 | @memcpy(@as([*]u8, @ptrCast(&k1))[0..rest], str[offset..]); |
| 118 | if (native_endian == .Big) | 118 | if (native_endian == .big) |
| 119 | k1 = @byteSwap(k1); | 119 | k1 = @byteSwap(k1); |
| 120 | h1 ^= k1; | 120 | h1 ^= k1; |
| 121 | h1 *%= m; | 121 | h1 *%= m; |
| ... | @@ -182,7 +182,7 @@ pub const Murmur3_32 = struct { | ... | @@ -182,7 +182,7 @@ pub const Murmur3_32 = struct { |
| 182 | var h1: u32 = seed; | 182 | var h1: u32 = seed; |
| 183 | for (@as([*]align(1) const u32, @ptrCast(str.ptr))[0..(len >> 2)]) |v| { | 183 | for (@as([*]align(1) const u32, @ptrCast(str.ptr))[0..(len >> 2)]) |v| { |
| 184 | var k1: u32 = v; | 184 | var k1: u32 = v; |
| 185 | if (native_endian == .Big) | 185 | if (native_endian == .big) |
| 186 | k1 = @byteSwap(k1); | 186 | k1 = @byteSwap(k1); |
| 187 | k1 *%= c1; | 187 | k1 *%= c1; |
| 188 | k1 = rotl32(k1, 15); | 188 | k1 = rotl32(k1, 15); |
| ... | @@ -286,7 +286,7 @@ test "murmur2_32" { | ... | @@ -286,7 +286,7 @@ test "murmur2_32" { |
| 286 | var v1: u64 = 0x1234567812345678; | 286 | var v1: u64 = 0x1234567812345678; |
| 287 | var v0le: u32 = v0; | 287 | var v0le: u32 = v0; |
| 288 | var v1le: u64 = v1; | 288 | var v1le: u64 = v1; |
| 289 | if (native_endian == .Big) { | 289 | if (native_endian == .big) { |
| 290 | v0le = @byteSwap(v0le); | 290 | v0le = @byteSwap(v0le); |
| 291 | v1le = @byteSwap(v1le); | 291 | v1le = @byteSwap(v1le); |
| 292 | } | 292 | } |
| ... | @@ -310,7 +310,7 @@ test "murmur2_64" { | ... | @@ -310,7 +310,7 @@ test "murmur2_64" { |
| 310 | var v1: u64 = 0x1234567812345678; | 310 | var v1: u64 = 0x1234567812345678; |
| 311 | var v0le: u32 = v0; | 311 | var v0le: u32 = v0; |
| 312 | var v1le: u64 = v1; | 312 | var v1le: u64 = v1; |
| 313 | if (native_endian == .Big) { | 313 | if (native_endian == .big) { |
| 314 | v0le = @byteSwap(v0le); | 314 | v0le = @byteSwap(v0le); |
| 315 | v1le = @byteSwap(v1le); | 315 | v1le = @byteSwap(v1le); |
| 316 | } | 316 | } |
| ... | @@ -334,7 +334,7 @@ test "murmur3_32" { | ... | @@ -334,7 +334,7 @@ test "murmur3_32" { |
| 334 | var v1: u64 = 0x1234567812345678; | 334 | var v1: u64 = 0x1234567812345678; |
| 335 | var v0le: u32 = v0; | 335 | var v0le: u32 = v0; |
| 336 | var v1le: u64 = v1; | 336 | var v1le: u64 = v1; |
| 337 | if (native_endian == .Big) { | 337 | if (native_endian == .big) { |
| 338 | v0le = @byteSwap(v0le); | 338 | v0le = @byteSwap(v0le); |
| 339 | v1le = @byteSwap(v1le); | 339 | v1le = @byteSwap(v1le); |
| 340 | } | 340 | } |
lib/std/hash/verify.zig+1-1| ... | @@ -37,7 +37,7 @@ pub fn smhasher(comptime hash_fn: anytype) u32 { | ... | @@ -37,7 +37,7 @@ pub fn smhasher(comptime hash_fn: anytype) u32 { |
| 37 | for (0..256) |i| { | 37 | for (0..256) |i| { |
| 38 | buf[i] = @intCast(i); | 38 | buf[i] = @intCast(i); |
| 39 | const h = hashMaybeSeed(hash_fn, 256 - i, buf[0..i]); | 39 | const h = hashMaybeSeed(hash_fn, 256 - i, buf[0..i]); |
| 40 | std.mem.writeInt(HashResult, buf_all[i * hash_size ..][0..hash_size], h, .Little); | 40 | std.mem.writeInt(HashResult, buf_all[i * hash_size ..][0..hash_size], h, .little); |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | return @truncate(hashMaybeSeed(hash_fn, 0, buf_all[0..])); | 43 | return @truncate(hashMaybeSeed(hash_fn, 0, buf_all[0..])); |
lib/std/hash/wyhash.zig+1-1| ... | @@ -131,7 +131,7 @@ pub const Wyhash = struct { | ... | @@ -131,7 +131,7 @@ pub const Wyhash = struct { |
| 131 | inline fn read(comptime bytes: usize, data: []const u8) u64 { | 131 | inline fn read(comptime bytes: usize, data: []const u8) u64 { |
| 132 | std.debug.assert(bytes <= 8); | 132 | std.debug.assert(bytes <= 8); |
| 133 | const T = std.meta.Int(.unsigned, 8 * bytes); | 133 | const T = std.meta.Int(.unsigned, 8 * bytes); |
| 134 | return @as(u64, std.mem.readInt(T, data[0..bytes], .Little)); | 134 | return @as(u64, std.mem.readInt(T, data[0..bytes], .little)); |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | inline fn mum(a: *u64, b: *u64) void { | 137 | inline fn mum(a: *u64, b: *u64) void { |
lib/std/hash/xxhash.zig+12-12| ... | @@ -53,10 +53,10 @@ pub const XxHash64 = struct { | ... | @@ -53,10 +53,10 @@ pub const XxHash64 = struct { |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | fn processStripe(self: *Accumulator, buf: *const [32]u8) void { | 55 | fn processStripe(self: *Accumulator, buf: *const [32]u8) void { |
| 56 | self.acc1 = round(self.acc1, mem.readInt(u64, buf[0..8], .Little)); | 56 | self.acc1 = round(self.acc1, mem.readInt(u64, buf[0..8], .little)); |
| 57 | self.acc2 = round(self.acc2, mem.readInt(u64, buf[8..16], .Little)); | 57 | self.acc2 = round(self.acc2, mem.readInt(u64, buf[8..16], .little)); |
| 58 | self.acc3 = round(self.acc3, mem.readInt(u64, buf[16..24], .Little)); | 58 | self.acc3 = round(self.acc3, mem.readInt(u64, buf[16..24], .little)); |
| 59 | self.acc4 = round(self.acc4, mem.readInt(u64, buf[24..32], .Little)); | 59 | self.acc4 = round(self.acc4, mem.readInt(u64, buf[24..32], .little)); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | fn merge(self: Accumulator) u64 { | 62 | fn merge(self: Accumulator) u64 { |
| ... | @@ -139,7 +139,7 @@ pub const XxHash64 = struct { | ... | @@ -139,7 +139,7 @@ pub const XxHash64 = struct { |
| 139 | 139 | ||
| 140 | fn finalize8(v: u64, bytes: *const [8]u8) u64 { | 140 | fn finalize8(v: u64, bytes: *const [8]u8) u64 { |
| 141 | var acc = v; | 141 | var acc = v; |
| 142 | const lane = mem.readInt(u64, bytes, .Little); | 142 | const lane = mem.readInt(u64, bytes, .little); |
| 143 | acc ^= round(0, lane); | 143 | acc ^= round(0, lane); |
| 144 | acc = rotl(u64, acc, 27) *% prime_1; | 144 | acc = rotl(u64, acc, 27) *% prime_1; |
| 145 | acc +%= prime_4; | 145 | acc +%= prime_4; |
| ... | @@ -148,7 +148,7 @@ pub const XxHash64 = struct { | ... | @@ -148,7 +148,7 @@ pub const XxHash64 = struct { |
| 148 | 148 | ||
| 149 | fn finalize4(v: u64, bytes: *const [4]u8) u64 { | 149 | fn finalize4(v: u64, bytes: *const [4]u8) u64 { |
| 150 | var acc = v; | 150 | var acc = v; |
| 151 | const lane = @as(u64, mem.readInt(u32, bytes, .Little)); | 151 | const lane = @as(u64, mem.readInt(u32, bytes, .little)); |
| 152 | acc ^= lane *% prime_1; | 152 | acc ^= lane *% prime_1; |
| 153 | acc = rotl(u64, acc, 23) *% prime_2; | 153 | acc = rotl(u64, acc, 23) *% prime_2; |
| 154 | acc +%= prime_3; | 154 | acc +%= prime_3; |
| ... | @@ -291,10 +291,10 @@ pub const XxHash32 = struct { | ... | @@ -291,10 +291,10 @@ pub const XxHash32 = struct { |
| 291 | } | 291 | } |
| 292 | 292 | ||
| 293 | fn processStripe(self: *Accumulator, buf: *const [16]u8) void { | 293 | fn processStripe(self: *Accumulator, buf: *const [16]u8) void { |
| 294 | self.acc1 = round(self.acc1, mem.readInt(u32, buf[0..4], .Little)); | 294 | self.acc1 = round(self.acc1, mem.readInt(u32, buf[0..4], .little)); |
| 295 | self.acc2 = round(self.acc2, mem.readInt(u32, buf[4..8], .Little)); | 295 | self.acc2 = round(self.acc2, mem.readInt(u32, buf[4..8], .little)); |
| 296 | self.acc3 = round(self.acc3, mem.readInt(u32, buf[8..12], .Little)); | 296 | self.acc3 = round(self.acc3, mem.readInt(u32, buf[8..12], .little)); |
| 297 | self.acc4 = round(self.acc4, mem.readInt(u32, buf[12..16], .Little)); | 297 | self.acc4 = round(self.acc4, mem.readInt(u32, buf[12..16], .little)); |
| 298 | } | 298 | } |
| 299 | 299 | ||
| 300 | fn merge(self: Accumulator) u32 { | 300 | fn merge(self: Accumulator) u32 { |
| ... | @@ -390,7 +390,7 @@ pub const XxHash32 = struct { | ... | @@ -390,7 +390,7 @@ pub const XxHash32 = struct { |
| 390 | 390 | ||
| 391 | fn finalize4(v: u32, bytes: *const [4]u8) u32 { | 391 | fn finalize4(v: u32, bytes: *const [4]u8) u32 { |
| 392 | var acc = v; | 392 | var acc = v; |
| 393 | const lane = mem.readInt(u32, bytes, .Little); | 393 | const lane = mem.readInt(u32, bytes, .little); |
| 394 | acc +%= lane *% prime_3; | 394 | acc +%= lane *% prime_3; |
| 395 | acc = rotl(u32, acc, 17) *% prime_4; | 395 | acc = rotl(u32, acc, 17) *% prime_4; |
| 396 | return acc; | 396 | return acc; |
| ... | @@ -472,7 +472,7 @@ pub const XxHash3 = struct { | ... | @@ -472,7 +472,7 @@ pub const XxHash3 = struct { |
| 472 | } | 472 | } |
| 473 | 473 | ||
| 474 | inline fn swap(x: anytype) @TypeOf(x) { | 474 | inline fn swap(x: anytype) @TypeOf(x) { |
| 475 | return if (builtin.cpu.arch.endian() == .Big) @byteSwap(x) else x; | 475 | return if (builtin.cpu.arch.endian() == .big) @byteSwap(x) else x; |
| 476 | } | 476 | } |
| 477 | 477 | ||
| 478 | inline fn disableAutoVectorization(x: anytype) void { | 478 | inline fn disableAutoVectorization(x: anytype) void { |
lib/std/heap/WasmPageAllocator.zig+1-1| ... | @@ -28,7 +28,7 @@ const PageStatus = enum(u1) { | ... | @@ -28,7 +28,7 @@ const PageStatus = enum(u1) { |
| 28 | const FreeBlock = struct { | 28 | const FreeBlock = struct { |
| 29 | data: []u128, | 29 | data: []u128, |
| 30 | 30 | ||
| 31 | const Io = std.packed_int_array.PackedIntIo(u1, .Little); | 31 | const Io = std.packed_int_array.PackedIntIo(u1, .little); |
| 32 | 32 | ||
| 33 | fn totalPages(self: FreeBlock) usize { | 33 | fn totalPages(self: FreeBlock) usize { |
| 34 | return self.data.len * 128; | 34 | return self.data.len * 128; |
lib/std/http/Client.zig+1-1| ... | @@ -1581,7 +1581,7 @@ pub fn fetch(client: *Client, allocator: Allocator, options: FetchOptions) !Fetc | ... | @@ -1581,7 +1581,7 @@ pub fn fetch(client: *Client, allocator: Allocator, options: FetchOptions) !Fetc |
| 1581 | 1581 | ||
| 1582 | test { | 1582 | test { |
| 1583 | const native_endian = comptime builtin.cpu.arch.endian(); | 1583 | const native_endian = comptime builtin.cpu.arch.endian(); |
| 1584 | if (builtin.zig_backend == .stage2_llvm and native_endian == .Big) { | 1584 | if (builtin.zig_backend == .stage2_llvm and native_endian == .big) { |
| 1585 | // https://github.com/ziglang/zig/issues/13782 | 1585 | // https://github.com/ziglang/zig/issues/13782 |
| 1586 | return error.SkipZigTest; | 1586 | return error.SkipZigTest; |
| 1587 | } | 1587 | } |
lib/std/http/Server.zig+1-1| ... | @@ -739,7 +739,7 @@ test "HTTP server handles a chunked transfer coding request" { | ... | @@ -739,7 +739,7 @@ test "HTTP server handles a chunked transfer coding request" { |
| 739 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 739 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 740 | 740 | ||
| 741 | const native_endian = comptime builtin.cpu.arch.endian(); | 741 | const native_endian = comptime builtin.cpu.arch.endian(); |
| 742 | if (builtin.zig_backend == .stage2_llvm and native_endian == .Big) { | 742 | if (builtin.zig_backend == .stage2_llvm and native_endian == .big) { |
| 743 | // https://github.com/ziglang/zig/issues/13782 | 743 | // https://github.com/ziglang/zig/issues/13782 |
| 744 | return error.SkipZigTest; | 744 | return error.SkipZigTest; |
| 745 | } | 745 | } |
lib/std/http/protocol.zig+2-2| ... | @@ -617,8 +617,8 @@ inline fn int32(array: *const [4]u8) u32 { | ... | @@ -617,8 +617,8 @@ inline fn int32(array: *const [4]u8) u32 { |
| 617 | 617 | ||
| 618 | inline fn intShift(comptime T: type, x: anytype) T { | 618 | inline fn intShift(comptime T: type, x: anytype) T { |
| 619 | switch (@import("builtin").cpu.arch.endian()) { | 619 | switch (@import("builtin").cpu.arch.endian()) { |
| 620 | .Little => return @as(T, @truncate(x >> (@bitSizeOf(@TypeOf(x)) - @bitSizeOf(T)))), | 620 | .little => return @as(T, @truncate(x >> (@bitSizeOf(@TypeOf(x)) - @bitSizeOf(T)))), |
| 621 | .Big => return @as(T, @truncate(x)), | 621 | .big => return @as(T, @truncate(x)), |
| 622 | } | 622 | } |
| 623 | } | 623 | } |
| 624 | 624 |
lib/std/io/Reader.zig+1-1| ... | @@ -334,7 +334,7 @@ pub fn readStruct(self: Self, comptime T: type) anyerror!T { | ... | @@ -334,7 +334,7 @@ pub fn readStruct(self: Self, comptime T: type) anyerror!T { |
| 334 | 334 | ||
| 335 | pub fn readStructBig(self: Self, comptime T: type) anyerror!T { | 335 | pub fn readStructBig(self: Self, comptime T: type) anyerror!T { |
| 336 | var res = try self.readStruct(T); | 336 | var res = try self.readStruct(T); |
| 337 | if (native_endian != std.builtin.Endian.Big) { | 337 | if (native_endian != std.builtin.Endian.big) { |
| 338 | mem.byteSwapAllFields(T, &res); | 338 | mem.byteSwapAllFields(T, &res); |
| 339 | } | 339 | } |
| 340 | return res; | 340 | return res; |
lib/std/io/bit_reader.zig+6-6| ... | @@ -63,14 +63,14 @@ pub fn BitReader(comptime endian: std.builtin.Endian, comptime ReaderType: type) | ... | @@ -63,14 +63,14 @@ pub fn BitReader(comptime endian: std.builtin.Endian, comptime ReaderType: type) |
| 63 | const n = if (self.bit_count >= bits) @as(u3, @intCast(bits)) else self.bit_count; | 63 | const n = if (self.bit_count >= bits) @as(u3, @intCast(bits)) else self.bit_count; |
| 64 | const shift = u7_bit_count - n; | 64 | const shift = u7_bit_count - n; |
| 65 | switch (endian) { | 65 | switch (endian) { |
| 66 | .Big => { | 66 | .big => { |
| 67 | out_buffer = @as(Buf, self.bit_buffer >> shift); | 67 | out_buffer = @as(Buf, self.bit_buffer >> shift); |
| 68 | if (n >= u7_bit_count) | 68 | if (n >= u7_bit_count) |
| 69 | self.bit_buffer = 0 | 69 | self.bit_buffer = 0 |
| 70 | else | 70 | else |
| 71 | self.bit_buffer <<= n; | 71 | self.bit_buffer <<= n; |
| 72 | }, | 72 | }, |
| 73 | .Little => { | 73 | .little => { |
| 74 | const value = (self.bit_buffer << shift) >> shift; | 74 | const value = (self.bit_buffer << shift) >> shift; |
| 75 | out_buffer = @as(Buf, value); | 75 | out_buffer = @as(Buf, value); |
| 76 | if (n >= u7_bit_count) | 76 | if (n >= u7_bit_count) |
| ... | @@ -93,7 +93,7 @@ pub fn BitReader(comptime endian: std.builtin.Endian, comptime ReaderType: type) | ... | @@ -93,7 +93,7 @@ pub fn BitReader(comptime endian: std.builtin.Endian, comptime ReaderType: type) |
| 93 | }; | 93 | }; |
| 94 | 94 | ||
| 95 | switch (endian) { | 95 | switch (endian) { |
| 96 | .Big => { | 96 | .big => { |
| 97 | if (n >= u8_bit_count) { | 97 | if (n >= u8_bit_count) { |
| 98 | out_buffer <<= @as(u3, @intCast(u8_bit_count - 1)); | 98 | out_buffer <<= @as(u3, @intCast(u8_bit_count - 1)); |
| 99 | out_buffer <<= 1; | 99 | out_buffer <<= 1; |
| ... | @@ -109,7 +109,7 @@ pub fn BitReader(comptime endian: std.builtin.Endian, comptime ReaderType: type) | ... | @@ -109,7 +109,7 @@ pub fn BitReader(comptime endian: std.builtin.Endian, comptime ReaderType: type) |
| 109 | self.bit_buffer = @as(u7, @truncate(next_byte << @as(u3, @intCast(n - 1)))); | 109 | self.bit_buffer = @as(u7, @truncate(next_byte << @as(u3, @intCast(n - 1)))); |
| 110 | self.bit_count = shift; | 110 | self.bit_count = shift; |
| 111 | }, | 111 | }, |
| 112 | .Little => { | 112 | .little => { |
| 113 | if (n >= u8_bit_count) { | 113 | if (n >= u8_bit_count) { |
| 114 | out_buffer |= @as(Buf, next_byte) << @as(BufShift, @intCast(out_bits.*)); | 114 | out_buffer |= @as(Buf, next_byte) << @as(BufShift, @intCast(out_bits.*)); |
| 115 | out_bits.* += u8_bit_count; | 115 | out_bits.* += u8_bit_count; |
| ... | @@ -168,7 +168,7 @@ test "api coverage" { | ... | @@ -168,7 +168,7 @@ test "api coverage" { |
| 168 | const mem_le = [_]u8{ 0b00011101, 0b10010101 }; | 168 | const mem_le = [_]u8{ 0b00011101, 0b10010101 }; |
| 169 | 169 | ||
| 170 | var mem_in_be = io.fixedBufferStream(&mem_be); | 170 | var mem_in_be = io.fixedBufferStream(&mem_be); |
| 171 | var bit_stream_be = bitReader(.Big, mem_in_be.reader()); | 171 | var bit_stream_be = bitReader(.big, mem_in_be.reader()); |
| 172 | 172 | ||
| 173 | var out_bits: usize = undefined; | 173 | var out_bits: usize = undefined; |
| 174 | 174 | ||
| ... | @@ -205,7 +205,7 @@ test "api coverage" { | ... | @@ -205,7 +205,7 @@ test "api coverage" { |
| 205 | try expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1)); | 205 | try expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1)); |
| 206 | 206 | ||
| 207 | var mem_in_le = io.fixedBufferStream(&mem_le); | 207 | var mem_in_le = io.fixedBufferStream(&mem_le); |
| 208 | var bit_stream_le = bitReader(.Little, mem_in_le.reader()); | 208 | var bit_stream_le = bitReader(.little, mem_in_le.reader()); |
| 209 | 209 | ||
| 210 | try expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits)); | 210 | try expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits)); |
| 211 | try expect(out_bits == 1); | 211 | try expect(out_bits == 1); |
lib/std/io/bit_writer.zig+10-10| ... | @@ -51,8 +51,8 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type) | ... | @@ -51,8 +51,8 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type) |
| 51 | 51 | ||
| 52 | const high_byte_shift = @as(BufShift, @intCast(buf_bit_count - u8_bit_count)); | 52 | const high_byte_shift = @as(BufShift, @intCast(buf_bit_count - u8_bit_count)); |
| 53 | var in_buffer = switch (endian) { | 53 | var in_buffer = switch (endian) { |
| 54 | .Big => buf_value << @as(BufShift, @intCast(buf_bit_count - bits)), | 54 | .big => buf_value << @as(BufShift, @intCast(buf_bit_count - bits)), |
| 55 | .Little => buf_value, | 55 | .little => buf_value, |
| 56 | }; | 56 | }; |
| 57 | var in_bits = bits; | 57 | var in_bits = bits; |
| 58 | 58 | ||
| ... | @@ -60,13 +60,13 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type) | ... | @@ -60,13 +60,13 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type) |
| 60 | const bits_remaining = u8_bit_count - self.bit_count; | 60 | const bits_remaining = u8_bit_count - self.bit_count; |
| 61 | const n = @as(u3, @intCast(if (bits_remaining > bits) bits else bits_remaining)); | 61 | const n = @as(u3, @intCast(if (bits_remaining > bits) bits else bits_remaining)); |
| 62 | switch (endian) { | 62 | switch (endian) { |
| 63 | .Big => { | 63 | .big => { |
| 64 | const shift = @as(BufShift, @intCast(high_byte_shift + self.bit_count)); | 64 | const shift = @as(BufShift, @intCast(high_byte_shift + self.bit_count)); |
| 65 | const v = @as(u8, @intCast(in_buffer >> shift)); | 65 | const v = @as(u8, @intCast(in_buffer >> shift)); |
| 66 | self.bit_buffer |= v; | 66 | self.bit_buffer |= v; |
| 67 | in_buffer <<= n; | 67 | in_buffer <<= n; |
| 68 | }, | 68 | }, |
| 69 | .Little => { | 69 | .little => { |
| 70 | const v = @as(u8, @truncate(in_buffer)) << @as(u3, @intCast(self.bit_count)); | 70 | const v = @as(u8, @truncate(in_buffer)) << @as(u3, @intCast(self.bit_count)); |
| 71 | self.bit_buffer |= v; | 71 | self.bit_buffer |= v; |
| 72 | in_buffer >>= n; | 72 | in_buffer >>= n; |
| ... | @@ -86,13 +86,13 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type) | ... | @@ -86,13 +86,13 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type) |
| 86 | //copy bytes until we can't fill one anymore, then leave the rest in bit_buffer | 86 | //copy bytes until we can't fill one anymore, then leave the rest in bit_buffer |
| 87 | while (in_bits >= u8_bit_count) { | 87 | while (in_bits >= u8_bit_count) { |
| 88 | switch (endian) { | 88 | switch (endian) { |
| 89 | .Big => { | 89 | .big => { |
| 90 | const v = @as(u8, @intCast(in_buffer >> high_byte_shift)); | 90 | const v = @as(u8, @intCast(in_buffer >> high_byte_shift)); |
| 91 | try self.forward_writer.writeByte(v); | 91 | try self.forward_writer.writeByte(v); |
| 92 | in_buffer <<= @as(u3, @intCast(u8_bit_count - 1)); | 92 | in_buffer <<= @as(u3, @intCast(u8_bit_count - 1)); |
| 93 | in_buffer <<= 1; | 93 | in_buffer <<= 1; |
| 94 | }, | 94 | }, |
| 95 | .Little => { | 95 | .little => { |
| 96 | const v = @as(u8, @truncate(in_buffer)); | 96 | const v = @as(u8, @truncate(in_buffer)); |
| 97 | try self.forward_writer.writeByte(v); | 97 | try self.forward_writer.writeByte(v); |
| 98 | in_buffer >>= @as(u3, @intCast(u8_bit_count - 1)); | 98 | in_buffer >>= @as(u3, @intCast(u8_bit_count - 1)); |
| ... | @@ -105,8 +105,8 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type) | ... | @@ -105,8 +105,8 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type) |
| 105 | if (in_bits > 0) { | 105 | if (in_bits > 0) { |
| 106 | self.bit_count = @as(u4, @intCast(in_bits)); | 106 | self.bit_count = @as(u4, @intCast(in_bits)); |
| 107 | self.bit_buffer = switch (endian) { | 107 | self.bit_buffer = switch (endian) { |
| 108 | .Big => @as(u8, @truncate(in_buffer >> high_byte_shift)), | 108 | .big => @as(u8, @truncate(in_buffer >> high_byte_shift)), |
| 109 | .Little => @as(u8, @truncate(in_buffer)), | 109 | .little => @as(u8, @truncate(in_buffer)), |
| 110 | }; | 110 | }; |
| 111 | } | 111 | } |
| 112 | } | 112 | } |
| ... | @@ -148,7 +148,7 @@ test "api coverage" { | ... | @@ -148,7 +148,7 @@ test "api coverage" { |
| 148 | var mem_le = [_]u8{0} ** 2; | 148 | var mem_le = [_]u8{0} ** 2; |
| 149 | 149 | ||
| 150 | var mem_out_be = io.fixedBufferStream(&mem_be); | 150 | var mem_out_be = io.fixedBufferStream(&mem_be); |
| 151 | var bit_stream_be = bitWriter(.Big, mem_out_be.writer()); | 151 | var bit_stream_be = bitWriter(.big, mem_out_be.writer()); |
| 152 | 152 | ||
| 153 | try bit_stream_be.writeBits(@as(u2, 1), 1); | 153 | try bit_stream_be.writeBits(@as(u2, 1), 1); |
| 154 | try bit_stream_be.writeBits(@as(u5, 2), 2); | 154 | try bit_stream_be.writeBits(@as(u5, 2), 2); |
| ... | @@ -172,7 +172,7 @@ test "api coverage" { | ... | @@ -172,7 +172,7 @@ test "api coverage" { |
| 172 | try bit_stream_be.writeBits(@as(u0, 0), 0); | 172 | try bit_stream_be.writeBits(@as(u0, 0), 0); |
| 173 | 173 | ||
| 174 | var mem_out_le = io.fixedBufferStream(&mem_le); | 174 | var mem_out_le = io.fixedBufferStream(&mem_le); |
| 175 | var bit_stream_le = bitWriter(.Little, mem_out_le.writer()); | 175 | var bit_stream_le = bitWriter(.little, mem_out_le.writer()); |
| 176 | 176 | ||
| 177 | try bit_stream_le.writeBits(@as(u2, 1), 1); | 177 | try bit_stream_le.writeBits(@as(u2, 1), 1); |
| 178 | try bit_stream_le.writeBits(@as(u5, 2), 2); | 178 | try bit_stream_le.writeBits(@as(u5, 2), 2); |
lib/std/io/test.zig+1-1| ... | @@ -183,7 +183,7 @@ test "GenericReader methods can return error.EndOfStream" { | ... | @@ -183,7 +183,7 @@ test "GenericReader methods can return error.EndOfStream" { |
| 183 | var fbs = std.io.fixedBufferStream(""); | 183 | var fbs = std.io.fixedBufferStream(""); |
| 184 | try std.testing.expectError( | 184 | try std.testing.expectError( |
| 185 | error.EndOfStream, | 185 | error.EndOfStream, |
| 186 | fbs.reader().readEnum(enum(u8) { a, b }, .Little), | 186 | fbs.reader().readEnum(enum(u8) { a, b }, .little), |
| 187 | ); | 187 | ); |
| 188 | try std.testing.expectError( | 188 | try std.testing.expectError( |
| 189 | error.EndOfStream, | 189 | error.EndOfStream, |
lib/std/math/big/int.zig+9-9| ... | @@ -798,7 +798,7 @@ pub const Mutable = struct { | ... | @@ -798,7 +798,7 @@ pub const Mutable = struct { |
| 798 | const endian_mask: usize = (@sizeOf(Limb) - 1) << 3; | 798 | const endian_mask: usize = (@sizeOf(Limb) - 1) << 3; |
| 799 | 799 | ||
| 800 | var bytes = std.mem.sliceAsBytes(r.limbs); | 800 | var bytes = std.mem.sliceAsBytes(r.limbs); |
| 801 | var bits = std.packed_int_array.PackedIntSliceEndian(u1, .Little).init(bytes, limbs_required * @bitSizeOf(Limb)); | 801 | var bits = std.packed_int_array.PackedIntSliceEndian(u1, .little).init(bytes, limbs_required * @bitSizeOf(Limb)); |
| 802 | 802 | ||
| 803 | var k: usize = 0; | 803 | var k: usize = 0; |
| 804 | while (k < ((bit_count + 1) / 2)) : (k += 1) { | 804 | while (k < ((bit_count + 1) / 2)) : (k += 1) { |
| ... | @@ -807,7 +807,7 @@ pub const Mutable = struct { | ... | @@ -807,7 +807,7 @@ pub const Mutable = struct { |
| 807 | 807 | ||
| 808 | // This "endian mask" remaps a low (LE) byte to the corresponding high | 808 | // This "endian mask" remaps a low (LE) byte to the corresponding high |
| 809 | // (BE) byte in the Limb, without changing which limbs we are indexing | 809 | // (BE) byte in the Limb, without changing which limbs we are indexing |
| 810 | if (native_endian == .Big) { | 810 | if (native_endian == .big) { |
| 811 | i ^= endian_mask; | 811 | i ^= endian_mask; |
| 812 | rev_i ^= endian_mask; | 812 | rev_i ^= endian_mask; |
| 813 | } | 813 | } |
| ... | @@ -821,8 +821,8 @@ pub const Mutable = struct { | ... | @@ -821,8 +821,8 @@ pub const Mutable = struct { |
| 821 | // Calculate signed-magnitude representation for output | 821 | // Calculate signed-magnitude representation for output |
| 822 | if (signedness == .signed) { | 822 | if (signedness == .signed) { |
| 823 | const last_bit = switch (native_endian) { | 823 | const last_bit = switch (native_endian) { |
| 824 | .Little => bits.get(bit_count - 1), | 824 | .little => bits.get(bit_count - 1), |
| 825 | .Big => bits.get((bit_count - 1) ^ endian_mask), | 825 | .big => bits.get((bit_count - 1) ^ endian_mask), |
| 826 | }; | 826 | }; |
| 827 | if (last_bit == 1) { | 827 | if (last_bit == 1) { |
| 828 | r.bitNotWrap(r.toConst(), .unsigned, bit_count); // Bitwise NOT. | 828 | r.bitNotWrap(r.toConst(), .unsigned, bit_count); // Bitwise NOT. |
| ... | @@ -869,7 +869,7 @@ pub const Mutable = struct { | ... | @@ -869,7 +869,7 @@ pub const Mutable = struct { |
| 869 | 869 | ||
| 870 | // This "endian mask" remaps a low (LE) byte to the corresponding high | 870 | // This "endian mask" remaps a low (LE) byte to the corresponding high |
| 871 | // (BE) byte in the Limb, without changing which limbs we are indexing | 871 | // (BE) byte in the Limb, without changing which limbs we are indexing |
| 872 | if (native_endian == .Big) { | 872 | if (native_endian == .big) { |
| 873 | i ^= endian_mask; | 873 | i ^= endian_mask; |
| 874 | rev_i ^= endian_mask; | 874 | rev_i ^= endian_mask; |
| 875 | } | 875 | } |
| ... | @@ -883,8 +883,8 @@ pub const Mutable = struct { | ... | @@ -883,8 +883,8 @@ pub const Mutable = struct { |
| 883 | // Calculate signed-magnitude representation for output | 883 | // Calculate signed-magnitude representation for output |
| 884 | if (signedness == .signed) { | 884 | if (signedness == .signed) { |
| 885 | const last_byte = switch (native_endian) { | 885 | const last_byte = switch (native_endian) { |
| 886 | .Little => bytes[byte_count - 1], | 886 | .little => bytes[byte_count - 1], |
| 887 | .Big => bytes[(byte_count - 1) ^ endian_mask], | 887 | .big => bytes[(byte_count - 1) ^ endian_mask], |
| 888 | }; | 888 | }; |
| 889 | 889 | ||
| 890 | if (last_byte & (1 << 7) != 0) { // Check sign bit of last byte | 890 | if (last_byte & (1 << 7) != 0) { // Check sign bit of last byte |
| ... | @@ -1912,8 +1912,8 @@ pub const Mutable = struct { | ... | @@ -1912,8 +1912,8 @@ pub const Mutable = struct { |
| 1912 | if (signedness == .signed) { | 1912 | if (signedness == .signed) { |
| 1913 | const total_bits = bit_offset + bit_count; | 1913 | const total_bits = bit_offset + bit_count; |
| 1914 | var last_byte = switch (endian) { | 1914 | var last_byte = switch (endian) { |
| 1915 | .Little => ((total_bits + 7) / 8) - 1, | 1915 | .little => ((total_bits + 7) / 8) - 1, |
| 1916 | .Big => buffer.len - ((total_bits + 7) / 8), | 1916 | .big => buffer.len - ((total_bits + 7) / 8), |
| 1917 | }; | 1917 | }; |
| 1918 | 1918 | ||
| 1919 | const sign_bit = @as(u8, 1) << @as(u3, @intCast((total_bits - 1) % 8)); | 1919 | const sign_bit = @as(u8, 1) << @as(u3, @intCast((total_bits - 1) % 8)); |
lib/std/math/big/int_test.zig+41-41| ... | @@ -2774,7 +2774,7 @@ test "big int conversion read/write twos complement" { | ... | @@ -2774,7 +2774,7 @@ test "big int conversion read/write twos complement" { |
| 2774 | var buffer1 = try testing.allocator.alloc(u8, 64); | 2774 | var buffer1 = try testing.allocator.alloc(u8, 64); |
| 2775 | defer testing.allocator.free(buffer1); | 2775 | defer testing.allocator.free(buffer1); |
| 2776 | 2776 | ||
| 2777 | const endians = [_]std.builtin.Endian{ .Little, .Big }; | 2777 | const endians = [_]std.builtin.Endian{ .little, .big }; |
| 2778 | const abi_size = 64; | 2778 | const abi_size = 64; |
| 2779 | 2779 | ||
| 2780 | for (endians) |endian| { | 2780 | for (endians) |endian| { |
| ... | @@ -2804,26 +2804,26 @@ test "big int conversion read twos complement with padding" { | ... | @@ -2804,26 +2804,26 @@ test "big int conversion read twos complement with padding" { |
| 2804 | // (3) should sign-extend any bits from bit_count to 8 * abi_size | 2804 | // (3) should sign-extend any bits from bit_count to 8 * abi_size |
| 2805 | 2805 | ||
| 2806 | var bit_count: usize = 12 * 8 + 1; | 2806 | var bit_count: usize = 12 * 8 + 1; |
| 2807 | a.toConst().writeTwosComplement(buffer1[0..13], .Little); | 2807 | a.toConst().writeTwosComplement(buffer1[0..13], .little); |
| 2808 | try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1, 0xaa, 0xaa, 0xaa })); | 2808 | try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1, 0xaa, 0xaa, 0xaa })); |
| 2809 | a.toConst().writeTwosComplement(buffer1[0..13], .Big); | 2809 | a.toConst().writeTwosComplement(buffer1[0..13], .big); |
| 2810 | try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xaa, 0xaa, 0xaa })); | 2810 | try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xaa, 0xaa, 0xaa })); |
| 2811 | a.toConst().writeTwosComplement(buffer1[0..16], .Little); | 2811 | a.toConst().writeTwosComplement(buffer1[0..16], .little); |
| 2812 | try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1, 0x0, 0x0, 0x0 })); | 2812 | try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1, 0x0, 0x0, 0x0 })); |
| 2813 | a.toConst().writeTwosComplement(buffer1[0..16], .Big); | 2813 | a.toConst().writeTwosComplement(buffer1[0..16], .big); |
| 2814 | try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0x0, 0x0, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd })); | 2814 | try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0x0, 0x0, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd })); |
| 2815 | 2815 | ||
| 2816 | @memset(buffer1, 0xaa); | 2816 | @memset(buffer1, 0xaa); |
| 2817 | try a.set(-0x01_02030405_06070809_0a0b0c0d); | 2817 | try a.set(-0x01_02030405_06070809_0a0b0c0d); |
| 2818 | bit_count = 12 * 8 + 2; | 2818 | bit_count = 12 * 8 + 2; |
| 2819 | 2819 | ||
| 2820 | a.toConst().writeTwosComplement(buffer1[0..13], .Little); | 2820 | a.toConst().writeTwosComplement(buffer1[0..13], .little); |
| 2821 | try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0xf3, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xaa, 0xaa, 0xaa })); | 2821 | try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0xf3, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xaa, 0xaa, 0xaa })); |
| 2822 | a.toConst().writeTwosComplement(buffer1[0..13], .Big); | 2822 | a.toConst().writeTwosComplement(buffer1[0..13], .big); |
| 2823 | try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf3, 0xaa, 0xaa, 0xaa })); | 2823 | try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf3, 0xaa, 0xaa, 0xaa })); |
| 2824 | a.toConst().writeTwosComplement(buffer1[0..16], .Little); | 2824 | a.toConst().writeTwosComplement(buffer1[0..16], .little); |
| 2825 | try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0xf3, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0xff, 0xff })); | 2825 | try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0xf3, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0xff, 0xff })); |
| 2826 | a.toConst().writeTwosComplement(buffer1[0..16], .Big); | 2826 | a.toConst().writeTwosComplement(buffer1[0..16], .big); |
| 2827 | try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0xff, 0xff, 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf3 })); | 2827 | try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0xff, 0xff, 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf3 })); |
| 2828 | } | 2828 | } |
| 2829 | 2829 | ||
| ... | @@ -2838,13 +2838,13 @@ test "big int write twos complement +/- zero" { | ... | @@ -2838,13 +2838,13 @@ test "big int write twos complement +/- zero" { |
| 2838 | 2838 | ||
| 2839 | // Test zero | 2839 | // Test zero |
| 2840 | 2840 | ||
| 2841 | m.toConst().writeTwosComplement(buffer1[0..13], .Little); | 2841 | m.toConst().writeTwosComplement(buffer1[0..13], .little); |
| 2842 | try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 13) ++ ([_]u8{0xaa} ** 3)))); | 2842 | try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 13) ++ ([_]u8{0xaa} ** 3)))); |
| 2843 | m.toConst().writeTwosComplement(buffer1[0..13], .Big); | 2843 | m.toConst().writeTwosComplement(buffer1[0..13], .big); |
| 2844 | try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 13) ++ ([_]u8{0xaa} ** 3)))); | 2844 | try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 13) ++ ([_]u8{0xaa} ** 3)))); |
| 2845 | m.toConst().writeTwosComplement(buffer1[0..16], .Little); | 2845 | m.toConst().writeTwosComplement(buffer1[0..16], .little); |
| 2846 | try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 16)))); | 2846 | try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 16)))); |
| 2847 | m.toConst().writeTwosComplement(buffer1[0..16], .Big); | 2847 | m.toConst().writeTwosComplement(buffer1[0..16], .big); |
| 2848 | try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 16)))); | 2848 | try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 16)))); |
| 2849 | 2849 | ||
| 2850 | @memset(buffer1, 0xaa); | 2850 | @memset(buffer1, 0xaa); |
| ... | @@ -2852,13 +2852,13 @@ test "big int write twos complement +/- zero" { | ... | @@ -2852,13 +2852,13 @@ test "big int write twos complement +/- zero" { |
| 2852 | 2852 | ||
| 2853 | // Test negative zero | 2853 | // Test negative zero |
| 2854 | 2854 | ||
| 2855 | m.toConst().writeTwosComplement(buffer1[0..13], .Little); | 2855 | m.toConst().writeTwosComplement(buffer1[0..13], .little); |
| 2856 | try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 13) ++ ([_]u8{0xaa} ** 3)))); | 2856 | try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 13) ++ ([_]u8{0xaa} ** 3)))); |
| 2857 | m.toConst().writeTwosComplement(buffer1[0..13], .Big); | 2857 | m.toConst().writeTwosComplement(buffer1[0..13], .big); |
| 2858 | try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 13) ++ ([_]u8{0xaa} ** 3)))); | 2858 | try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 13) ++ ([_]u8{0xaa} ** 3)))); |
| 2859 | m.toConst().writeTwosComplement(buffer1[0..16], .Little); | 2859 | m.toConst().writeTwosComplement(buffer1[0..16], .little); |
| 2860 | try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 16)))); | 2860 | try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 16)))); |
| 2861 | m.toConst().writeTwosComplement(buffer1[0..16], .Big); | 2861 | m.toConst().writeTwosComplement(buffer1[0..16], .big); |
| 2862 | try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 16)))); | 2862 | try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 16)))); |
| 2863 | } | 2863 | } |
| 2864 | 2864 | ||
| ... | @@ -2881,19 +2881,19 @@ test "big int conversion write twos complement with padding" { | ... | @@ -2881,19 +2881,19 @@ test "big int conversion write twos complement with padding" { |
| 2881 | // Test 0x01_02030405_06070809_0a0b0c0d | 2881 | // Test 0x01_02030405_06070809_0a0b0c0d |
| 2882 | 2882 | ||
| 2883 | buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xb }; | 2883 | buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xb }; |
| 2884 | m.readTwosComplement(buffer[0..13], bit_count, .Little, .unsigned); | 2884 | m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); |
| 2885 | try testing.expect(m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d) == .eq); | 2885 | try testing.expect(m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d) == .eq); |
| 2886 | 2886 | ||
| 2887 | buffer = &[_]u8{ 0xb, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd }; | 2887 | buffer = &[_]u8{ 0xb, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd }; |
| 2888 | m.readTwosComplement(buffer[0..13], bit_count, .Big, .unsigned); | 2888 | m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); |
| 2889 | try testing.expect(m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d) == .eq); | 2889 | try testing.expect(m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d) == .eq); |
| 2890 | 2890 | ||
| 2891 | buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xab, 0xaa, 0xaa, 0xaa }; | 2891 | buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xab, 0xaa, 0xaa, 0xaa }; |
| 2892 | m.readTwosComplement(buffer[0..16], bit_count, .Little, .unsigned); | 2892 | m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned); |
| 2893 | try testing.expect(m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d) == .eq); | 2893 | try testing.expect(m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d) == .eq); |
| 2894 | 2894 | ||
| 2895 | buffer = &[_]u8{ 0xaa, 0xaa, 0xaa, 0xab, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd }; | 2895 | buffer = &[_]u8{ 0xaa, 0xaa, 0xaa, 0xab, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd }; |
| 2896 | m.readTwosComplement(buffer[0..16], bit_count, .Big, .unsigned); | 2896 | m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned); |
| 2897 | try testing.expect(m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d) == .eq); | 2897 | try testing.expect(m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d) == .eq); |
| 2898 | 2898 | ||
| 2899 | bit_count = @sizeOf(Limb) * 8; | 2899 | bit_count = @sizeOf(Limb) * 8; |
| ... | @@ -2901,19 +2901,19 @@ test "big int conversion write twos complement with padding" { | ... | @@ -2901,19 +2901,19 @@ test "big int conversion write twos complement with padding" { |
| 2901 | // Test 0x0a0a0a0a_02030405_06070809_0a0b0c0d | 2901 | // Test 0x0a0a0a0a_02030405_06070809_0a0b0c0d |
| 2902 | 2902 | ||
| 2903 | buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xaa }; | 2903 | buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xaa }; |
| 2904 | m.readTwosComplement(buffer[0..13], bit_count, .Little, .unsigned); | 2904 | m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); |
| 2905 | try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaa_02030405_06070809_0a0b0c0d))) == .eq); | 2905 | try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaa_02030405_06070809_0a0b0c0d))) == .eq); |
| 2906 | 2906 | ||
| 2907 | buffer = &[_]u8{ 0xaa, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd }; | 2907 | buffer = &[_]u8{ 0xaa, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd }; |
| 2908 | m.readTwosComplement(buffer[0..13], bit_count, .Big, .unsigned); | 2908 | m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); |
| 2909 | try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaa_02030405_06070809_0a0b0c0d))) == .eq); | 2909 | try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaa_02030405_06070809_0a0b0c0d))) == .eq); |
| 2910 | 2910 | ||
| 2911 | buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xaa, 0xaa, 0xaa, 0xaa }; | 2911 | buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xaa, 0xaa, 0xaa, 0xaa }; |
| 2912 | m.readTwosComplement(buffer[0..16], bit_count, .Little, .unsigned); | 2912 | m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned); |
| 2913 | try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaaaaaaaa_02030405_06070809_0a0b0c0d))) == .eq); | 2913 | try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaaaaaaaa_02030405_06070809_0a0b0c0d))) == .eq); |
| 2914 | 2914 | ||
| 2915 | buffer = &[_]u8{ 0xaa, 0xaa, 0xaa, 0xaa, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd }; | 2915 | buffer = &[_]u8{ 0xaa, 0xaa, 0xaa, 0xaa, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd }; |
| 2916 | m.readTwosComplement(buffer[0..16], bit_count, .Big, .unsigned); | 2916 | m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned); |
| 2917 | try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaaaaaaaa_02030405_06070809_0a0b0c0d))) == .eq); | 2917 | try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaaaaaaaa_02030405_06070809_0a0b0c0d))) == .eq); |
| 2918 | 2918 | ||
| 2919 | bit_count = 12 * 8 + 2; | 2919 | bit_count = 12 * 8 + 2; |
| ... | @@ -2921,42 +2921,42 @@ test "big int conversion write twos complement with padding" { | ... | @@ -2921,42 +2921,42 @@ test "big int conversion write twos complement with padding" { |
| 2921 | // Test -0x01_02030405_06070809_0a0b0c0d | 2921 | // Test -0x01_02030405_06070809_0a0b0c0d |
| 2922 | 2922 | ||
| 2923 | buffer = &[_]u8{ 0xf3, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0x02 }; | 2923 | buffer = &[_]u8{ 0xf3, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0x02 }; |
| 2924 | m.readTwosComplement(buffer[0..13], bit_count, .Little, .signed); | 2924 | m.readTwosComplement(buffer[0..13], bit_count, .little, .signed); |
| 2925 | try testing.expect(m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d) == .eq); | 2925 | try testing.expect(m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d) == .eq); |
| 2926 | 2926 | ||
| 2927 | buffer = &[_]u8{ 0x02, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf3 }; | 2927 | buffer = &[_]u8{ 0x02, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf3 }; |
| 2928 | m.readTwosComplement(buffer[0..13], bit_count, .Big, .signed); | 2928 | m.readTwosComplement(buffer[0..13], bit_count, .big, .signed); |
| 2929 | try testing.expect(m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d) == .eq); | 2929 | try testing.expect(m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d) == .eq); |
| 2930 | 2930 | ||
| 2931 | buffer = &[_]u8{ 0xf3, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0x02, 0xaa, 0xaa, 0xaa }; | 2931 | buffer = &[_]u8{ 0xf3, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0x02, 0xaa, 0xaa, 0xaa }; |
| 2932 | m.readTwosComplement(buffer[0..16], bit_count, .Little, .signed); | 2932 | m.readTwosComplement(buffer[0..16], bit_count, .little, .signed); |
| 2933 | try testing.expect(m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d) == .eq); | 2933 | try testing.expect(m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d) == .eq); |
| 2934 | 2934 | ||
| 2935 | buffer = &[_]u8{ 0xaa, 0xaa, 0xaa, 0x02, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf3 }; | 2935 | buffer = &[_]u8{ 0xaa, 0xaa, 0xaa, 0x02, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf3 }; |
| 2936 | m.readTwosComplement(buffer[0..16], bit_count, .Big, .signed); | 2936 | m.readTwosComplement(buffer[0..16], bit_count, .big, .signed); |
| 2937 | try testing.expect(m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d) == .eq); | 2937 | try testing.expect(m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d) == .eq); |
| 2938 | 2938 | ||
| 2939 | // Test 0 | 2939 | // Test 0 |
| 2940 | 2940 | ||
| 2941 | buffer = &([_]u8{0} ** 16); | 2941 | buffer = &([_]u8{0} ** 16); |
| 2942 | m.readTwosComplement(buffer[0..13], bit_count, .Little, .unsigned); | 2942 | m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); |
| 2943 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); | 2943 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); |
| 2944 | m.readTwosComplement(buffer[0..13], bit_count, .Big, .unsigned); | 2944 | m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); |
| 2945 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); | 2945 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); |
| 2946 | m.readTwosComplement(buffer[0..16], bit_count, .Little, .unsigned); | 2946 | m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned); |
| 2947 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); | 2947 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); |
| 2948 | m.readTwosComplement(buffer[0..16], bit_count, .Big, .unsigned); | 2948 | m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned); |
| 2949 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); | 2949 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); |
| 2950 | 2950 | ||
| 2951 | bit_count = 0; | 2951 | bit_count = 0; |
| 2952 | buffer = &([_]u8{0xaa} ** 16); | 2952 | buffer = &([_]u8{0xaa} ** 16); |
| 2953 | m.readTwosComplement(buffer[0..13], bit_count, .Little, .unsigned); | 2953 | m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); |
| 2954 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); | 2954 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); |
| 2955 | m.readTwosComplement(buffer[0..13], bit_count, .Big, .unsigned); | 2955 | m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); |
| 2956 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); | 2956 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); |
| 2957 | m.readTwosComplement(buffer[0..16], bit_count, .Little, .unsigned); | 2957 | m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned); |
| 2958 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); | 2958 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); |
| 2959 | m.readTwosComplement(buffer[0..16], bit_count, .Big, .unsigned); | 2959 | m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned); |
| 2960 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); | 2960 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); |
| 2961 | } | 2961 | } |
| 2962 | 2962 | ||
| ... | @@ -2975,15 +2975,15 @@ test "big int conversion write twos complement zero" { | ... | @@ -2975,15 +2975,15 @@ test "big int conversion write twos complement zero" { |
| 2975 | var buffer: []const u8 = undefined; | 2975 | var buffer: []const u8 = undefined; |
| 2976 | 2976 | ||
| 2977 | buffer = &([_]u8{0} ** 13); | 2977 | buffer = &([_]u8{0} ** 13); |
| 2978 | m.readTwosComplement(buffer[0..13], bit_count, .Little, .unsigned); | 2978 | m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); |
| 2979 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); | 2979 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); |
| 2980 | m.readTwosComplement(buffer[0..13], bit_count, .Big, .unsigned); | 2980 | m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); |
| 2981 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); | 2981 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); |
| 2982 | 2982 | ||
| 2983 | buffer = &([_]u8{0} ** 16); | 2983 | buffer = &([_]u8{0} ** 16); |
| 2984 | m.readTwosComplement(buffer[0..16], bit_count, .Little, .unsigned); | 2984 | m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned); |
| 2985 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); | 2985 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); |
| 2986 | m.readTwosComplement(buffer[0..16], bit_count, .Big, .unsigned); | 2986 | m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned); |
| 2987 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); | 2987 | try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); |
| 2988 | } | 2988 | } |
| 2989 | 2989 |
lib/std/mem.zig+99-99| ... | @@ -1499,12 +1499,12 @@ test "containsAtLeast" { | ... | @@ -1499,12 +1499,12 @@ test "containsAtLeast" { |
| 1499 | pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: Endian) ReturnType { | 1499 | pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: Endian) ReturnType { |
| 1500 | var result: ReturnType = 0; | 1500 | var result: ReturnType = 0; |
| 1501 | switch (endian) { | 1501 | switch (endian) { |
| 1502 | .Big => { | 1502 | .big => { |
| 1503 | for (bytes) |b| { | 1503 | for (bytes) |b| { |
| 1504 | result = (result << 8) | b; | 1504 | result = (result << 8) | b; |
| 1505 | } | 1505 | } |
| 1506 | }, | 1506 | }, |
| 1507 | .Little => { | 1507 | .little => { |
| 1508 | const ShiftType = math.Log2Int(ReturnType); | 1508 | const ShiftType = math.Log2Int(ReturnType); |
| 1509 | for (bytes, 0..) |b, index| { | 1509 | for (bytes, 0..) |b, index| { |
| 1510 | result = result | (@as(ReturnType, b) << @as(ShiftType, @intCast(index * 8))); | 1510 | result = result | (@as(ReturnType, b) << @as(ShiftType, @intCast(index * 8))); |
| ... | @@ -1539,8 +1539,8 @@ pub fn readVarPackedInt( | ... | @@ -1539,8 +1539,8 @@ pub fn readVarPackedInt( |
| 1539 | const pad = @as(Log2N, @intCast(@bitSizeOf(T) - bit_count)); | 1539 | const pad = @as(Log2N, @intCast(@bitSizeOf(T) - bit_count)); |
| 1540 | 1540 | ||
| 1541 | const lowest_byte = switch (endian) { | 1541 | const lowest_byte = switch (endian) { |
| 1542 | .Big => bytes.len - (bit_offset / 8) - read_size, | 1542 | .big => bytes.len - (bit_offset / 8) - read_size, |
| 1543 | .Little => bit_offset / 8, | 1543 | .little => bit_offset / 8, |
| 1544 | }; | 1544 | }; |
| 1545 | const read_bytes = bytes[lowest_byte..][0..read_size]; | 1545 | const read_bytes = bytes[lowest_byte..][0..read_size]; |
| 1546 | 1546 | ||
| ... | @@ -1550,7 +1550,7 @@ pub fn readVarPackedInt( | ... | @@ -1550,7 +1550,7 @@ pub fn readVarPackedInt( |
| 1550 | const value = if (read_size == 1) b: { | 1550 | const value = if (read_size == 1) b: { |
| 1551 | break :b @as(uN, @truncate(read_bytes[0] >> bit_shift)); | 1551 | break :b @as(uN, @truncate(read_bytes[0] >> bit_shift)); |
| 1552 | } else b: { | 1552 | } else b: { |
| 1553 | const i: u1 = @intFromBool(endian == .Big); | 1553 | const i: u1 = @intFromBool(endian == .big); |
| 1554 | const head = @as(uN, @truncate(read_bytes[i] >> bit_shift)); | 1554 | const head = @as(uN, @truncate(read_bytes[i] >> bit_shift)); |
| 1555 | const tail_shift = @as(Log2N, @intCast(@as(u4, 8) - bit_shift)); | 1555 | const tail_shift = @as(Log2N, @intCast(@as(u4, 8) - bit_shift)); |
| 1556 | const tail = @as(uN, @truncate(read_bytes[1 - i])); | 1556 | const tail = @as(uN, @truncate(read_bytes[1 - i])); |
| ... | @@ -1565,13 +1565,13 @@ pub fn readVarPackedInt( | ... | @@ -1565,13 +1565,13 @@ pub fn readVarPackedInt( |
| 1565 | // Copy the value out (respecting endianness), accounting for bit_shift | 1565 | // Copy the value out (respecting endianness), accounting for bit_shift |
| 1566 | var int: uN = 0; | 1566 | var int: uN = 0; |
| 1567 | switch (endian) { | 1567 | switch (endian) { |
| 1568 | .Big => { | 1568 | .big => { |
| 1569 | for (read_bytes[0 .. read_size - 1]) |elem| { | 1569 | for (read_bytes[0 .. read_size - 1]) |elem| { |
| 1570 | int = elem | (int << 8); | 1570 | int = elem | (int << 8); |
| 1571 | } | 1571 | } |
| 1572 | int = (read_bytes[read_size - 1] >> bit_shift) | (int << (@as(u4, 8) - bit_shift)); | 1572 | int = (read_bytes[read_size - 1] >> bit_shift) | (int << (@as(u4, 8) - bit_shift)); |
| 1573 | }, | 1573 | }, |
| 1574 | .Little => { | 1574 | .little => { |
| 1575 | int = read_bytes[0] >> bit_shift; | 1575 | int = read_bytes[0] >> bit_shift; |
| 1576 | for (read_bytes[1..], 0..) |elem, i| { | 1576 | for (read_bytes[1..], 0..) |elem, i| { |
| 1577 | int |= (@as(uN, elem) << @as(Log2N, @intCast((8 * (i + 1) - bit_shift)))); | 1577 | int |= (@as(uN, elem) << @as(Log2N, @intCast((8 * (i + 1) - bit_shift)))); |
| ... | @@ -1593,23 +1593,23 @@ pub inline fn readInt(comptime T: type, buffer: *const [@divExact(@typeInfo(T).I | ... | @@ -1593,23 +1593,23 @@ pub inline fn readInt(comptime T: type, buffer: *const [@divExact(@typeInfo(T).I |
| 1593 | } | 1593 | } |
| 1594 | 1594 | ||
| 1595 | test readInt { | 1595 | test readInt { |
| 1596 | try testing.expect(readInt(u0, &[_]u8{}, .Big) == 0x0); | 1596 | try testing.expect(readInt(u0, &[_]u8{}, .big) == 0x0); |
| 1597 | try testing.expect(readInt(u0, &[_]u8{}, .Little) == 0x0); | 1597 | try testing.expect(readInt(u0, &[_]u8{}, .little) == 0x0); |
| 1598 | 1598 | ||
| 1599 | try testing.expect(readInt(u8, &[_]u8{0x32}, .Big) == 0x32); | 1599 | try testing.expect(readInt(u8, &[_]u8{0x32}, .big) == 0x32); |
| 1600 | try testing.expect(readInt(u8, &[_]u8{0x12}, .Little) == 0x12); | 1600 | try testing.expect(readInt(u8, &[_]u8{0x12}, .little) == 0x12); |
| 1601 | 1601 | ||
| 1602 | try testing.expect(readInt(u16, &[_]u8{ 0x12, 0x34 }, .Big) == 0x1234); | 1602 | try testing.expect(readInt(u16, &[_]u8{ 0x12, 0x34 }, .big) == 0x1234); |
| 1603 | try testing.expect(readInt(u16, &[_]u8{ 0x12, 0x34 }, .Little) == 0x3412); | 1603 | try testing.expect(readInt(u16, &[_]u8{ 0x12, 0x34 }, .little) == 0x3412); |
| 1604 | 1604 | ||
| 1605 | try testing.expect(readInt(u72, &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }, .Big) == 0x123456789abcdef024); | 1605 | try testing.expect(readInt(u72, &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }, .big) == 0x123456789abcdef024); |
| 1606 | try testing.expect(readInt(u72, &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }, .Little) == 0xfedcba9876543210ec); | 1606 | try testing.expect(readInt(u72, &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }, .little) == 0xfedcba9876543210ec); |
| 1607 | 1607 | ||
| 1608 | try testing.expect(readInt(i8, &[_]u8{0xff}, .Big) == -1); | 1608 | try testing.expect(readInt(i8, &[_]u8{0xff}, .big) == -1); |
| 1609 | try testing.expect(readInt(i8, &[_]u8{0xfe}, .Little) == -2); | 1609 | try testing.expect(readInt(i8, &[_]u8{0xfe}, .little) == -2); |
| 1610 | 1610 | ||
| 1611 | try testing.expect(readInt(i16, &[_]u8{ 0xff, 0xfd }, .Big) == -3); | 1611 | try testing.expect(readInt(i16, &[_]u8{ 0xff, 0xfd }, .big) == -3); |
| 1612 | try testing.expect(readInt(i16, &[_]u8{ 0xfc, 0xff }, .Little) == -4); | 1612 | try testing.expect(readInt(i16, &[_]u8{ 0xfc, 0xff }, .little) == -4); |
| 1613 | } | 1613 | } |
| 1614 | 1614 | ||
| 1615 | fn readPackedIntLittle(comptime T: type, bytes: []const u8, bit_offset: usize) T { | 1615 | fn readPackedIntLittle(comptime T: type, bytes: []const u8, bit_offset: usize) T { |
| ... | @@ -1629,7 +1629,7 @@ fn readPackedIntLittle(comptime T: type, bytes: []const u8, bit_offset: usize) T | ... | @@ -1629,7 +1629,7 @@ fn readPackedIntLittle(comptime T: type, bytes: []const u8, bit_offset: usize) T |
| 1629 | // Read by loading a LoadInt, and then follow it up with a 1-byte read | 1629 | // Read by loading a LoadInt, and then follow it up with a 1-byte read |
| 1630 | // of the tail if bit_offset pushed us over a byte boundary. | 1630 | // of the tail if bit_offset pushed us over a byte boundary. |
| 1631 | const read_bytes = bytes[bit_offset / 8 ..]; | 1631 | const read_bytes = bytes[bit_offset / 8 ..]; |
| 1632 | const val = @as(uN, @truncate(readInt(LoadInt, read_bytes[0..load_size], .Little) >> bit_shift)); | 1632 | const val = @as(uN, @truncate(readInt(LoadInt, read_bytes[0..load_size], .little) >> bit_shift)); |
| 1633 | if (bit_shift > load_tail_bits) { | 1633 | if (bit_shift > load_tail_bits) { |
| 1634 | const tail_bits = @as(Log2N, @intCast(bit_shift - load_tail_bits)); | 1634 | const tail_bits = @as(Log2N, @intCast(bit_shift - load_tail_bits)); |
| 1635 | const tail_byte = read_bytes[load_size]; | 1635 | const tail_byte = read_bytes[load_size]; |
| ... | @@ -1657,7 +1657,7 @@ fn readPackedIntBig(comptime T: type, bytes: []const u8, bit_offset: usize) T { | ... | @@ -1657,7 +1657,7 @@ fn readPackedIntBig(comptime T: type, bytes: []const u8, bit_offset: usize) T { |
| 1657 | // of the tail if bit_offset pushed us over a byte boundary. | 1657 | // of the tail if bit_offset pushed us over a byte boundary. |
| 1658 | const end = bytes.len - (bit_offset / 8); | 1658 | const end = bytes.len - (bit_offset / 8); |
| 1659 | const read_bytes = bytes[(end - byte_count)..end]; | 1659 | const read_bytes = bytes[(end - byte_count)..end]; |
| 1660 | const val = @as(uN, @truncate(readInt(LoadInt, bytes[(end - load_size)..end][0..load_size], .Big) >> bit_shift)); | 1660 | const val = @as(uN, @truncate(readInt(LoadInt, bytes[(end - load_size)..end][0..load_size], .big) >> bit_shift)); |
| 1661 | if (bit_shift > load_tail_bits) { | 1661 | if (bit_shift > load_tail_bits) { |
| 1662 | const tail_bits = @as(Log2N, @intCast(bit_shift - load_tail_bits)); | 1662 | const tail_bits = @as(Log2N, @intCast(bit_shift - load_tail_bits)); |
| 1663 | const tail_byte = if (bit_count < 8) @as(uN, @truncate(read_bytes[0])) else @as(uN, read_bytes[0]); | 1663 | const tail_byte = if (bit_count < 8) @as(uN, @truncate(read_bytes[0])) else @as(uN, read_bytes[0]); |
| ... | @@ -1666,13 +1666,13 @@ fn readPackedIntBig(comptime T: type, bytes: []const u8, bit_offset: usize) T { | ... | @@ -1666,13 +1666,13 @@ fn readPackedIntBig(comptime T: type, bytes: []const u8, bit_offset: usize) T { |
| 1666 | } | 1666 | } |
| 1667 | 1667 | ||
| 1668 | pub const readPackedIntNative = switch (native_endian) { | 1668 | pub const readPackedIntNative = switch (native_endian) { |
| 1669 | .Little => readPackedIntLittle, | 1669 | .little => readPackedIntLittle, |
| 1670 | .Big => readPackedIntBig, | 1670 | .big => readPackedIntBig, |
| 1671 | }; | 1671 | }; |
| 1672 | 1672 | ||
| 1673 | pub const readPackedIntForeign = switch (native_endian) { | 1673 | pub const readPackedIntForeign = switch (native_endian) { |
| 1674 | .Little => readPackedIntBig, | 1674 | .little => readPackedIntBig, |
| 1675 | .Big => readPackedIntLittle, | 1675 | .big => readPackedIntLittle, |
| 1676 | }; | 1676 | }; |
| 1677 | 1677 | ||
| 1678 | /// Loads an integer from packed memory. | 1678 | /// Loads an integer from packed memory. |
| ... | @@ -1685,22 +1685,22 @@ pub const readPackedIntForeign = switch (native_endian) { | ... | @@ -1685,22 +1685,22 @@ pub const readPackedIntForeign = switch (native_endian) { |
| 1685 | /// | 1685 | /// |
| 1686 | pub fn readPackedInt(comptime T: type, bytes: []const u8, bit_offset: usize, endian: Endian) T { | 1686 | pub fn readPackedInt(comptime T: type, bytes: []const u8, bit_offset: usize, endian: Endian) T { |
| 1687 | switch (endian) { | 1687 | switch (endian) { |
| 1688 | .Little => return readPackedIntLittle(T, bytes, bit_offset), | 1688 | .little => return readPackedIntLittle(T, bytes, bit_offset), |
| 1689 | .Big => return readPackedIntBig(T, bytes, bit_offset), | 1689 | .big => return readPackedIntBig(T, bytes, bit_offset), |
| 1690 | } | 1690 | } |
| 1691 | } | 1691 | } |
| 1692 | 1692 | ||
| 1693 | test "comptime read/write int" { | 1693 | test "comptime read/write int" { |
| 1694 | comptime { | 1694 | comptime { |
| 1695 | var bytes: [2]u8 = undefined; | 1695 | var bytes: [2]u8 = undefined; |
| 1696 | writeInt(u16, &bytes, 0x1234, .Little); | 1696 | writeInt(u16, &bytes, 0x1234, .little); |
| 1697 | const result = readInt(u16, &bytes, .Big); | 1697 | const result = readInt(u16, &bytes, .big); |
| 1698 | try testing.expect(result == 0x3412); | 1698 | try testing.expect(result == 0x3412); |
| 1699 | } | 1699 | } |
| 1700 | comptime { | 1700 | comptime { |
| 1701 | var bytes: [2]u8 = undefined; | 1701 | var bytes: [2]u8 = undefined; |
| 1702 | writeInt(u16, &bytes, 0x1234, .Big); | 1702 | writeInt(u16, &bytes, 0x1234, .big); |
| 1703 | const result = readInt(u16, &bytes, .Little); | 1703 | const result = readInt(u16, &bytes, .little); |
| 1704 | try testing.expect(result == 0x3412); | 1704 | try testing.expect(result == 0x3412); |
| 1705 | } | 1705 | } |
| 1706 | } | 1706 | } |
| ... | @@ -1718,34 +1718,34 @@ test writeInt { | ... | @@ -1718,34 +1718,34 @@ test writeInt { |
| 1718 | var buf2: [2]u8 = undefined; | 1718 | var buf2: [2]u8 = undefined; |
| 1719 | var buf9: [9]u8 = undefined; | 1719 | var buf9: [9]u8 = undefined; |
| 1720 | 1720 | ||
| 1721 | writeInt(u0, &buf0, 0x0, .Big); | 1721 | writeInt(u0, &buf0, 0x0, .big); |
| 1722 | try testing.expect(eql(u8, buf0[0..], &[_]u8{})); | 1722 | try testing.expect(eql(u8, buf0[0..], &[_]u8{})); |
| 1723 | writeInt(u0, &buf0, 0x0, .Little); | 1723 | writeInt(u0, &buf0, 0x0, .little); |
| 1724 | try testing.expect(eql(u8, buf0[0..], &[_]u8{})); | 1724 | try testing.expect(eql(u8, buf0[0..], &[_]u8{})); |
| 1725 | 1725 | ||
| 1726 | writeInt(u8, &buf1, 0x12, .Big); | 1726 | writeInt(u8, &buf1, 0x12, .big); |
| 1727 | try testing.expect(eql(u8, buf1[0..], &[_]u8{0x12})); | 1727 | try testing.expect(eql(u8, buf1[0..], &[_]u8{0x12})); |
| 1728 | writeInt(u8, &buf1, 0x34, .Little); | 1728 | writeInt(u8, &buf1, 0x34, .little); |
| 1729 | try testing.expect(eql(u8, buf1[0..], &[_]u8{0x34})); | 1729 | try testing.expect(eql(u8, buf1[0..], &[_]u8{0x34})); |
| 1730 | 1730 | ||
| 1731 | writeInt(u16, &buf2, 0x1234, .Big); | 1731 | writeInt(u16, &buf2, 0x1234, .big); |
| 1732 | try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 })); | 1732 | try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 })); |
| 1733 | writeInt(u16, &buf2, 0x5678, .Little); | 1733 | writeInt(u16, &buf2, 0x5678, .little); |
| 1734 | try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x78, 0x56 })); | 1734 | try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x78, 0x56 })); |
| 1735 | 1735 | ||
| 1736 | writeInt(u72, &buf9, 0x123456789abcdef024, .Big); | 1736 | writeInt(u72, &buf9, 0x123456789abcdef024, .big); |
| 1737 | try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 })); | 1737 | try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 })); |
| 1738 | writeInt(u72, &buf9, 0xfedcba9876543210ec, .Little); | 1738 | writeInt(u72, &buf9, 0xfedcba9876543210ec, .little); |
| 1739 | try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe })); | 1739 | try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe })); |
| 1740 | 1740 | ||
| 1741 | writeInt(i8, &buf1, -1, .Big); | 1741 | writeInt(i8, &buf1, -1, .big); |
| 1742 | try testing.expect(eql(u8, buf1[0..], &[_]u8{0xff})); | 1742 | try testing.expect(eql(u8, buf1[0..], &[_]u8{0xff})); |
| 1743 | writeInt(i8, &buf1, -2, .Little); | 1743 | writeInt(i8, &buf1, -2, .little); |
| 1744 | try testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe})); | 1744 | try testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe})); |
| 1745 | 1745 | ||
| 1746 | writeInt(i16, &buf2, -3, .Big); | 1746 | writeInt(i16, &buf2, -3, .big); |
| 1747 | try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd })); | 1747 | try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd })); |
| 1748 | writeInt(i16, &buf2, -4, .Little); | 1748 | writeInt(i16, &buf2, -4, .little); |
| 1749 | try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff })); | 1749 | try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff })); |
| 1750 | } | 1750 | } |
| 1751 | 1751 | ||
| ... | @@ -1779,7 +1779,7 @@ fn writePackedIntLittle(comptime T: type, bytes: []u8, bit_offset: usize, value: | ... | @@ -1779,7 +1779,7 @@ fn writePackedIntLittle(comptime T: type, bytes: []u8, bit_offset: usize, value: |
| 1779 | write_value |= @as(StoreInt, tail) << (8 * (store_size - 1)); | 1779 | write_value |= @as(StoreInt, tail) << (8 * (store_size - 1)); |
| 1780 | } | 1780 | } |
| 1781 | 1781 | ||
| 1782 | writeInt(StoreInt, write_bytes[0..store_size], write_value, .Little); | 1782 | writeInt(StoreInt, write_bytes[0..store_size], write_value, .little); |
| 1783 | } | 1783 | } |
| 1784 | 1784 | ||
| 1785 | fn writePackedIntBig(comptime T: type, bytes: []u8, bit_offset: usize, value: T) void { | 1785 | fn writePackedIntBig(comptime T: type, bytes: []u8, bit_offset: usize, value: T) void { |
| ... | @@ -1814,17 +1814,17 @@ fn writePackedIntBig(comptime T: type, bytes: []u8, bit_offset: usize, value: T) | ... | @@ -1814,17 +1814,17 @@ fn writePackedIntBig(comptime T: type, bytes: []u8, bit_offset: usize, value: T) |
| 1814 | write_value |= @as(StoreInt, tail) << (8 * (store_size - 1)); | 1814 | write_value |= @as(StoreInt, tail) << (8 * (store_size - 1)); |
| 1815 | } | 1815 | } |
| 1816 | 1816 | ||
| 1817 | writeInt(StoreInt, write_bytes[(byte_count - store_size)..][0..store_size], write_value, .Big); | 1817 | writeInt(StoreInt, write_bytes[(byte_count - store_size)..][0..store_size], write_value, .big); |
| 1818 | } | 1818 | } |
| 1819 | 1819 | ||
| 1820 | pub const writePackedIntNative = switch (native_endian) { | 1820 | pub const writePackedIntNative = switch (native_endian) { |
| 1821 | .Little => writePackedIntLittle, | 1821 | .little => writePackedIntLittle, |
| 1822 | .Big => writePackedIntBig, | 1822 | .big => writePackedIntBig, |
| 1823 | }; | 1823 | }; |
| 1824 | 1824 | ||
| 1825 | pub const writePackedIntForeign = switch (native_endian) { | 1825 | pub const writePackedIntForeign = switch (native_endian) { |
| 1826 | .Little => writePackedIntBig, | 1826 | .little => writePackedIntBig, |
| 1827 | .Big => writePackedIntLittle, | 1827 | .big => writePackedIntLittle, |
| 1828 | }; | 1828 | }; |
| 1829 | 1829 | ||
| 1830 | /// Stores an integer to packed memory. | 1830 | /// Stores an integer to packed memory. |
| ... | @@ -1838,8 +1838,8 @@ pub const writePackedIntForeign = switch (native_endian) { | ... | @@ -1838,8 +1838,8 @@ pub const writePackedIntForeign = switch (native_endian) { |
| 1838 | /// | 1838 | /// |
| 1839 | pub fn writePackedInt(comptime T: type, bytes: []u8, bit_offset: usize, value: T, endian: Endian) void { | 1839 | pub fn writePackedInt(comptime T: type, bytes: []u8, bit_offset: usize, value: T, endian: Endian) void { |
| 1840 | switch (endian) { | 1840 | switch (endian) { |
| 1841 | .Little => writePackedIntLittle(T, bytes, bit_offset, value), | 1841 | .little => writePackedIntLittle(T, bytes, bit_offset, value), |
| 1842 | .Big => writePackedIntBig(T, bytes, bit_offset, value), | 1842 | .big => writePackedIntBig(T, bytes, bit_offset, value), |
| 1843 | } | 1843 | } |
| 1844 | } | 1844 | } |
| 1845 | 1845 | ||
| ... | @@ -1860,8 +1860,8 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value | ... | @@ -1860,8 +1860,8 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value |
| 1860 | const bit_shift = @as(u3, @intCast(bit_offset % 8)); | 1860 | const bit_shift = @as(u3, @intCast(bit_offset % 8)); |
| 1861 | const write_size = (bit_count + bit_shift + 7) / 8; | 1861 | const write_size = (bit_count + bit_shift + 7) / 8; |
| 1862 | const lowest_byte = switch (endian) { | 1862 | const lowest_byte = switch (endian) { |
| 1863 | .Big => bytes.len - (bit_offset / 8) - write_size, | 1863 | .big => bytes.len - (bit_offset / 8) - write_size, |
| 1864 | .Little => bit_offset / 8, | 1864 | .little => bit_offset / 8, |
| 1865 | }; | 1865 | }; |
| 1866 | const write_bytes = bytes[lowest_byte..][0..write_size]; | 1866 | const write_bytes = bytes[lowest_byte..][0..write_size]; |
| 1867 | 1867 | ||
| ... | @@ -1877,8 +1877,8 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value | ... | @@ -1877,8 +1877,8 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value |
| 1877 | var remaining: T = value; | 1877 | var remaining: T = value; |
| 1878 | 1878 | ||
| 1879 | // Iterate bytes forward for Little-endian, backward for Big-endian | 1879 | // Iterate bytes forward for Little-endian, backward for Big-endian |
| 1880 | const delta: i2 = if (endian == .Big) -1 else 1; | 1880 | const delta: i2 = if (endian == .big) -1 else 1; |
| 1881 | const start = if (endian == .Big) @as(isize, @intCast(write_bytes.len - 1)) else 0; | 1881 | const start = if (endian == .big) @as(isize, @intCast(write_bytes.len - 1)) else 0; |
| 1882 | 1882 | ||
| 1883 | var i: isize = start; // isize for signed index arithmetic | 1883 | var i: isize = start; // isize for signed index arithmetic |
| 1884 | 1884 | ||
| ... | @@ -3122,12 +3122,12 @@ fn testReadIntImpl() !void { | ... | @@ -3122,12 +3122,12 @@ fn testReadIntImpl() !void { |
| 3122 | 0x56, | 3122 | 0x56, |
| 3123 | 0x78, | 3123 | 0x78, |
| 3124 | }; | 3124 | }; |
| 3125 | try testing.expect(readInt(u32, &bytes, .Big) == 0x12345678); | 3125 | try testing.expect(readInt(u32, &bytes, .big) == 0x12345678); |
| 3126 | try testing.expect(readInt(u32, &bytes, .Big) == 0x12345678); | 3126 | try testing.expect(readInt(u32, &bytes, .big) == 0x12345678); |
| 3127 | try testing.expect(readInt(i32, &bytes, .Big) == 0x12345678); | 3127 | try testing.expect(readInt(i32, &bytes, .big) == 0x12345678); |
| 3128 | try testing.expect(readInt(u32, &bytes, .Little) == 0x78563412); | 3128 | try testing.expect(readInt(u32, &bytes, .little) == 0x78563412); |
| 3129 | try testing.expect(readInt(u32, &bytes, .Little) == 0x78563412); | 3129 | try testing.expect(readInt(u32, &bytes, .little) == 0x78563412); |
| 3130 | try testing.expect(readInt(i32, &bytes, .Little) == 0x78563412); | 3130 | try testing.expect(readInt(i32, &bytes, .little) == 0x78563412); |
| 3131 | } | 3131 | } |
| 3132 | { | 3132 | { |
| 3133 | const buf = [_]u8{ | 3133 | const buf = [_]u8{ |
| ... | @@ -3136,7 +3136,7 @@ fn testReadIntImpl() !void { | ... | @@ -3136,7 +3136,7 @@ fn testReadIntImpl() !void { |
| 3136 | 0x12, | 3136 | 0x12, |
| 3137 | 0x34, | 3137 | 0x34, |
| 3138 | }; | 3138 | }; |
| 3139 | const answer = readInt(u32, &buf, .Big); | 3139 | const answer = readInt(u32, &buf, .big); |
| 3140 | try testing.expect(answer == 0x00001234); | 3140 | try testing.expect(answer == 0x00001234); |
| 3141 | } | 3141 | } |
| 3142 | { | 3142 | { |
| ... | @@ -3146,7 +3146,7 @@ fn testReadIntImpl() !void { | ... | @@ -3146,7 +3146,7 @@ fn testReadIntImpl() !void { |
| 3146 | 0x00, | 3146 | 0x00, |
| 3147 | 0x00, | 3147 | 0x00, |
| 3148 | }; | 3148 | }; |
| 3149 | const answer = readInt(u32, &buf, .Little); | 3149 | const answer = readInt(u32, &buf, .little); |
| 3150 | try testing.expect(answer == 0x00003412); | 3150 | try testing.expect(answer == 0x00003412); |
| 3151 | } | 3151 | } |
| 3152 | { | 3152 | { |
| ... | @@ -3154,10 +3154,10 @@ fn testReadIntImpl() !void { | ... | @@ -3154,10 +3154,10 @@ fn testReadIntImpl() !void { |
| 3154 | 0xff, | 3154 | 0xff, |
| 3155 | 0xfe, | 3155 | 0xfe, |
| 3156 | }; | 3156 | }; |
| 3157 | try testing.expect(readInt(u16, &bytes, .Big) == 0xfffe); | 3157 | try testing.expect(readInt(u16, &bytes, .big) == 0xfffe); |
| 3158 | try testing.expect(readInt(i16, &bytes, .Big) == -0x0002); | 3158 | try testing.expect(readInt(i16, &bytes, .big) == -0x0002); |
| 3159 | try testing.expect(readInt(u16, &bytes, .Little) == 0xfeff); | 3159 | try testing.expect(readInt(u16, &bytes, .little) == 0xfeff); |
| 3160 | try testing.expect(readInt(i16, &bytes, .Little) == -0x0101); | 3160 | try testing.expect(readInt(i16, &bytes, .little) == -0x0101); |
| 3161 | } | 3161 | } |
| 3162 | } | 3162 | } |
| 3163 | 3163 | ||
| ... | @@ -3603,48 +3603,48 @@ test "replaceOwned" { | ... | @@ -3603,48 +3603,48 @@ test "replaceOwned" { |
| 3603 | /// Converts a little-endian integer to host endianness. | 3603 | /// Converts a little-endian integer to host endianness. |
| 3604 | pub fn littleToNative(comptime T: type, x: T) T { | 3604 | pub fn littleToNative(comptime T: type, x: T) T { |
| 3605 | return switch (native_endian) { | 3605 | return switch (native_endian) { |
| 3606 | .Little => x, | 3606 | .little => x, |
| 3607 | .Big => @byteSwap(x), | 3607 | .big => @byteSwap(x), |
| 3608 | }; | 3608 | }; |
| 3609 | } | 3609 | } |
| 3610 | 3610 | ||
| 3611 | /// Converts a big-endian integer to host endianness. | 3611 | /// Converts a big-endian integer to host endianness. |
| 3612 | pub fn bigToNative(comptime T: type, x: T) T { | 3612 | pub fn bigToNative(comptime T: type, x: T) T { |
| 3613 | return switch (native_endian) { | 3613 | return switch (native_endian) { |
| 3614 | .Little => @byteSwap(x), | 3614 | .little => @byteSwap(x), |
| 3615 | .Big => x, | 3615 | .big => x, |
| 3616 | }; | 3616 | }; |
| 3617 | } | 3617 | } |
| 3618 | 3618 | ||
| 3619 | /// Converts an integer from specified endianness to host endianness. | 3619 | /// Converts an integer from specified endianness to host endianness. |
| 3620 | pub fn toNative(comptime T: type, x: T, endianness_of_x: Endian) T { | 3620 | pub fn toNative(comptime T: type, x: T, endianness_of_x: Endian) T { |
| 3621 | return switch (endianness_of_x) { | 3621 | return switch (endianness_of_x) { |
| 3622 | .Little => littleToNative(T, x), | 3622 | .little => littleToNative(T, x), |
| 3623 | .Big => bigToNative(T, x), | 3623 | .big => bigToNative(T, x), |
| 3624 | }; | 3624 | }; |
| 3625 | } | 3625 | } |
| 3626 | 3626 | ||
| 3627 | /// Converts an integer which has host endianness to the desired endianness. | 3627 | /// Converts an integer which has host endianness to the desired endianness. |
| 3628 | pub fn nativeTo(comptime T: type, x: T, desired_endianness: Endian) T { | 3628 | pub fn nativeTo(comptime T: type, x: T, desired_endianness: Endian) T { |
| 3629 | return switch (desired_endianness) { | 3629 | return switch (desired_endianness) { |
| 3630 | .Little => nativeToLittle(T, x), | 3630 | .little => nativeToLittle(T, x), |
| 3631 | .Big => nativeToBig(T, x), | 3631 | .big => nativeToBig(T, x), |
| 3632 | }; | 3632 | }; |
| 3633 | } | 3633 | } |
| 3634 | 3634 | ||
| 3635 | /// Converts an integer which has host endianness to little endian. | 3635 | /// Converts an integer which has host endianness to little endian. |
| 3636 | pub fn nativeToLittle(comptime T: type, x: T) T { | 3636 | pub fn nativeToLittle(comptime T: type, x: T) T { |
| 3637 | return switch (native_endian) { | 3637 | return switch (native_endian) { |
| 3638 | .Little => x, | 3638 | .little => x, |
| 3639 | .Big => @byteSwap(x), | 3639 | .big => @byteSwap(x), |
| 3640 | }; | 3640 | }; |
| 3641 | } | 3641 | } |
| 3642 | 3642 | ||
| 3643 | /// Converts an integer which has host endianness to big endian. | 3643 | /// Converts an integer which has host endianness to big endian. |
| 3644 | pub fn nativeToBig(comptime T: type, x: T) T { | 3644 | pub fn nativeToBig(comptime T: type, x: T) T { |
| 3645 | return switch (native_endian) { | 3645 | return switch (native_endian) { |
| 3646 | .Little => @byteSwap(x), | 3646 | .little => @byteSwap(x), |
| 3647 | .Big => x, | 3647 | .big => x, |
| 3648 | }; | 3648 | }; |
| 3649 | } | 3649 | } |
| 3650 | 3650 | ||
| ... | @@ -3748,8 +3748,8 @@ pub fn asBytes(ptr: anytype) AsBytesReturnType(@TypeOf(ptr)) { | ... | @@ -3748,8 +3748,8 @@ pub fn asBytes(ptr: anytype) AsBytesReturnType(@TypeOf(ptr)) { |
| 3748 | test "asBytes" { | 3748 | test "asBytes" { |
| 3749 | const deadbeef = @as(u32, 0xDEADBEEF); | 3749 | const deadbeef = @as(u32, 0xDEADBEEF); |
| 3750 | const deadbeef_bytes = switch (native_endian) { | 3750 | const deadbeef_bytes = switch (native_endian) { |
| 3751 | .Big => "\xDE\xAD\xBE\xEF", | 3751 | .big => "\xDE\xAD\xBE\xEF", |
| 3752 | .Little => "\xEF\xBE\xAD\xDE", | 3752 | .little => "\xEF\xBE\xAD\xDE", |
| 3753 | }; | 3753 | }; |
| 3754 | 3754 | ||
| 3755 | try testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes)); | 3755 | try testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes)); |
| ... | @@ -3773,10 +3773,10 @@ test "asBytes" { | ... | @@ -3773,10 +3773,10 @@ test "asBytes" { |
| 3773 | .d = 0xA1, | 3773 | .d = 0xA1, |
| 3774 | }; | 3774 | }; |
| 3775 | switch (native_endian) { | 3775 | switch (native_endian) { |
| 3776 | .Little => { | 3776 | .little => { |
| 3777 | try testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1")); | 3777 | try testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1")); |
| 3778 | }, | 3778 | }, |
| 3779 | .Big => { | 3779 | .big => { |
| 3780 | try testing.expect(eql(u8, asBytes(&inst), "\xA1\xDE\xEF\xBE")); | 3780 | try testing.expect(eql(u8, asBytes(&inst), "\xA1\xDE\xEF\xBE")); |
| 3781 | }, | 3781 | }, |
| 3782 | } | 3782 | } |
| ... | @@ -3808,14 +3808,14 @@ pub fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8 { | ... | @@ -3808,14 +3808,14 @@ pub fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8 { |
| 3808 | test "toBytes" { | 3808 | test "toBytes" { |
| 3809 | var my_bytes = toBytes(@as(u32, 0x12345678)); | 3809 | var my_bytes = toBytes(@as(u32, 0x12345678)); |
| 3810 | switch (native_endian) { | 3810 | switch (native_endian) { |
| 3811 | .Big => try testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")), | 3811 | .big => try testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")), |
| 3812 | .Little => try testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")), | 3812 | .little => try testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")), |
| 3813 | } | 3813 | } |
| 3814 | 3814 | ||
| 3815 | my_bytes[0] = '\x99'; | 3815 | my_bytes[0] = '\x99'; |
| 3816 | switch (native_endian) { | 3816 | switch (native_endian) { |
| 3817 | .Big => try testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")), | 3817 | .big => try testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")), |
| 3818 | .Little => try testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")), | 3818 | .little => try testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")), |
| 3819 | } | 3819 | } |
| 3820 | } | 3820 | } |
| 3821 | 3821 | ||
| ... | @@ -3840,15 +3840,15 @@ pub fn bytesAsValue(comptime T: type, bytes: anytype) BytesAsValueReturnType(T, | ... | @@ -3840,15 +3840,15 @@ pub fn bytesAsValue(comptime T: type, bytes: anytype) BytesAsValueReturnType(T, |
| 3840 | test "bytesAsValue" { | 3840 | test "bytesAsValue" { |
| 3841 | const deadbeef = @as(u32, 0xDEADBEEF); | 3841 | const deadbeef = @as(u32, 0xDEADBEEF); |
| 3842 | const deadbeef_bytes = switch (native_endian) { | 3842 | const deadbeef_bytes = switch (native_endian) { |
| 3843 | .Big => "\xDE\xAD\xBE\xEF", | 3843 | .big => "\xDE\xAD\xBE\xEF", |
| 3844 | .Little => "\xEF\xBE\xAD\xDE", | 3844 | .little => "\xEF\xBE\xAD\xDE", |
| 3845 | }; | 3845 | }; |
| 3846 | 3846 | ||
| 3847 | try testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*); | 3847 | try testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*); |
| 3848 | 3848 | ||
| 3849 | var codeface_bytes: [4]u8 = switch (native_endian) { | 3849 | var codeface_bytes: [4]u8 = switch (native_endian) { |
| 3850 | .Big => "\xC0\xDE\xFA\xCE", | 3850 | .big => "\xC0\xDE\xFA\xCE", |
| 3851 | .Little => "\xCE\xFA\xDE\xC0", | 3851 | .little => "\xCE\xFA\xDE\xC0", |
| 3852 | }.*; | 3852 | }.*; |
| 3853 | var codeface = bytesAsValue(u32, &codeface_bytes); | 3853 | var codeface = bytesAsValue(u32, &codeface_bytes); |
| 3854 | try testing.expect(codeface.* == 0xC0DEFACE); | 3854 | try testing.expect(codeface.* == 0xC0DEFACE); |
| ... | @@ -3870,8 +3870,8 @@ test "bytesAsValue" { | ... | @@ -3870,8 +3870,8 @@ test "bytesAsValue" { |
| 3870 | .d = 0xA1, | 3870 | .d = 0xA1, |
| 3871 | }; | 3871 | }; |
| 3872 | const inst_bytes = switch (native_endian) { | 3872 | const inst_bytes = switch (native_endian) { |
| 3873 | .Little => "\xBE\xEF\xDE\xA1", | 3873 | .little => "\xBE\xEF\xDE\xA1", |
| 3874 | .Big => "\xA1\xDE\xEF\xBE", | 3874 | .big => "\xA1\xDE\xEF\xBE", |
| 3875 | }; | 3875 | }; |
| 3876 | const inst2 = bytesAsValue(S, inst_bytes); | 3876 | const inst2 = bytesAsValue(S, inst_bytes); |
| 3877 | try testing.expect(meta.eql(inst, inst2.*)); | 3877 | try testing.expect(meta.eql(inst, inst2.*)); |
| ... | @@ -3898,8 +3898,8 @@ pub fn bytesToValue(comptime T: type, bytes: anytype) T { | ... | @@ -3898,8 +3898,8 @@ pub fn bytesToValue(comptime T: type, bytes: anytype) T { |
| 3898 | } | 3898 | } |
| 3899 | test "bytesToValue" { | 3899 | test "bytesToValue" { |
| 3900 | const deadbeef_bytes = switch (native_endian) { | 3900 | const deadbeef_bytes = switch (native_endian) { |
| 3901 | .Big => "\xDE\xAD\xBE\xEF", | 3901 | .big => "\xDE\xAD\xBE\xEF", |
| 3902 | .Little => "\xEF\xBE\xAD\xDE", | 3902 | .little => "\xEF\xBE\xAD\xDE", |
| 3903 | }; | 3903 | }; |
| 3904 | 3904 | ||
| 3905 | const deadbeef = bytesToValue(u32, deadbeef_bytes); | 3905 | const deadbeef = bytesToValue(u32, deadbeef_bytes); |
| ... | @@ -4028,8 +4028,8 @@ test "sliceAsBytes" { | ... | @@ -4028,8 +4028,8 @@ test "sliceAsBytes" { |
| 4028 | const slice = sliceAsBytes(bytes[0..]); | 4028 | const slice = sliceAsBytes(bytes[0..]); |
| 4029 | try testing.expect(slice.len == 4); | 4029 | try testing.expect(slice.len == 4); |
| 4030 | try testing.expect(eql(u8, slice, switch (native_endian) { | 4030 | try testing.expect(eql(u8, slice, switch (native_endian) { |
| 4031 | .Big => "\xDE\xAD\xBE\xEF", | 4031 | .big => "\xDE\xAD\xBE\xEF", |
| 4032 | .Little => "\xAD\xDE\xEF\xBE", | 4032 | .little => "\xAD\xDE\xEF\xBE", |
| 4033 | })); | 4033 | })); |
| 4034 | } | 4034 | } |
| 4035 | 4035 | ||
| ... | @@ -4204,7 +4204,7 @@ test "doNotOptimizeAway" { | ... | @@ -4204,7 +4204,7 @@ test "doNotOptimizeAway" { |
| 4204 | doNotOptimizeAway(@as(f64, 0.0)); | 4204 | doNotOptimizeAway(@as(f64, 0.0)); |
| 4205 | doNotOptimizeAway([_]u8{0} ** 4); | 4205 | doNotOptimizeAway([_]u8{0} ** 4); |
| 4206 | doNotOptimizeAway([_]u8{0} ** 100); | 4206 | doNotOptimizeAway([_]u8{0} ** 100); |
| 4207 | doNotOptimizeAway(@as(std.builtin.Endian, .Little)); | 4207 | doNotOptimizeAway(@as(std.builtin.Endian, .little)); |
| 4208 | } | 4208 | } |
| 4209 | 4209 | ||
| 4210 | test "alignForward" { | 4210 | test "alignForward" { |
| ... | @@ -4356,7 +4356,7 @@ test "read/write(Var)PackedInt" { | ... | @@ -4356,7 +4356,7 @@ test "read/write(Var)PackedInt" { |
| 4356 | return error.SkipZigTest; | 4356 | return error.SkipZigTest; |
| 4357 | } | 4357 | } |
| 4358 | 4358 | ||
| 4359 | const foreign_endian: Endian = if (native_endian == .Big) .Little else .Big; | 4359 | const foreign_endian: Endian = if (native_endian == .big) .little else .big; |
| 4360 | const expect = std.testing.expect; | 4360 | const expect = std.testing.expect; |
| 4361 | var prng = std.rand.DefaultPrng.init(1234); | 4361 | var prng = std.rand.DefaultPrng.init(1234); |
| 4362 | const random = prng.random(); | 4362 | const random = prng.random(); |
lib/std/net.zig+2-2| ... | @@ -602,8 +602,8 @@ pub const Ip6Address = extern struct { | ... | @@ -602,8 +602,8 @@ pub const Ip6Address = extern struct { |
| 602 | } | 602 | } |
| 603 | const big_endian_parts = @as(*align(1) const [8]u16, @ptrCast(&self.sa.addr)); | 603 | const big_endian_parts = @as(*align(1) const [8]u16, @ptrCast(&self.sa.addr)); |
| 604 | const native_endian_parts = switch (native_endian) { | 604 | const native_endian_parts = switch (native_endian) { |
| 605 | .Big => big_endian_parts.*, | 605 | .big => big_endian_parts.*, |
| 606 | .Little => blk: { | 606 | .little => blk: { |
| 607 | var buf: [8]u16 = undefined; | 607 | var buf: [8]u16 = undefined; |
| 608 | for (big_endian_parts, 0..) |part, i| { | 608 | for (big_endian_parts, 0..) |part, i| { |
| 609 | buf[i] = mem.bigToNative(u16, part); | 609 | buf[i] = mem.bigToNative(u16, part); |
lib/std/os/linux.zig+3-3| ... | @@ -206,11 +206,11 @@ fn splitValueBE64(val: i64) [2]u32 { | ... | @@ -206,11 +206,11 @@ fn splitValueBE64(val: i64) [2]u32 { |
| 206 | fn splitValue64(val: i64) [2]u32 { | 206 | fn splitValue64(val: i64) [2]u32 { |
| 207 | const u: u64 = @bitCast(val); | 207 | const u: u64 = @bitCast(val); |
| 208 | switch (native_endian) { | 208 | switch (native_endian) { |
| 209 | .Little => return [2]u32{ | 209 | .little => return [2]u32{ |
| 210 | @as(u32, @truncate(u)), | 210 | @as(u32, @truncate(u)), |
| 211 | @as(u32, @truncate(u >> 32)), | 211 | @as(u32, @truncate(u >> 32)), |
| 212 | }, | 212 | }, |
| 213 | .Big => return [2]u32{ | 213 | .big => return [2]u32{ |
| 214 | @as(u32, @truncate(u >> 32)), | 214 | @as(u32, @truncate(u >> 32)), |
| 215 | @as(u32, @truncate(u)), | 215 | @as(u32, @truncate(u)), |
| 216 | }, | 216 | }, |
| ... | @@ -6028,7 +6028,7 @@ pub const AUDIT = struct { | ... | @@ -6028,7 +6028,7 @@ pub const AUDIT = struct { |
| 6028 | 6028 | ||
| 6029 | fn toAudit(arch: std.Target.Cpu.Arch) u32 { | 6029 | fn toAudit(arch: std.Target.Cpu.Arch) u32 { |
| 6030 | var res: u32 = @intFromEnum(arch.toElfMachine()); | 6030 | var res: u32 = @intFromEnum(arch.toElfMachine()); |
| 6031 | if (arch.endian() == .Little) res |= LE; | 6031 | if (arch.endian() == .little) res |= LE; |
| 6032 | switch (arch) { | 6032 | switch (arch) { |
| 6033 | .aarch64, | 6033 | .aarch64, |
| 6034 | .mips64, | 6034 | .mips64, |
lib/std/os/linux/bpf.zig+4-4| ... | @@ -696,8 +696,8 @@ pub const Insn = packed struct { | ... | @@ -696,8 +696,8 @@ pub const Insn = packed struct { |
| 696 | fn endian_swap(endian: std.builtin.Endian, comptime size: Size, dst: Reg) Insn { | 696 | fn endian_swap(endian: std.builtin.Endian, comptime size: Size, dst: Reg) Insn { |
| 697 | return Insn{ | 697 | return Insn{ |
| 698 | .code = switch (endian) { | 698 | .code = switch (endian) { |
| 699 | .Big => 0xdc, | 699 | .big => 0xdc, |
| 700 | .Little => 0xd4, | 700 | .little => 0xd4, |
| 701 | }, | 701 | }, |
| 702 | .dst = @intFromEnum(dst), | 702 | .dst = @intFromEnum(dst), |
| 703 | .src = 0, | 703 | .src = 0, |
| ... | @@ -712,11 +712,11 @@ pub const Insn = packed struct { | ... | @@ -712,11 +712,11 @@ pub const Insn = packed struct { |
| 712 | } | 712 | } |
| 713 | 713 | ||
| 714 | pub fn le(comptime size: Size, dst: Reg) Insn { | 714 | pub fn le(comptime size: Size, dst: Reg) Insn { |
| 715 | return endian_swap(.Little, size, dst); | 715 | return endian_swap(.little, size, dst); |
| 716 | } | 716 | } |
| 717 | 717 | ||
| 718 | pub fn be(comptime size: Size, dst: Reg) Insn { | 718 | pub fn be(comptime size: Size, dst: Reg) Insn { |
| 719 | return endian_swap(.Big, size, dst); | 719 | return endian_swap(.big, size, dst); |
| 720 | } | 720 | } |
| 721 | 721 | ||
| 722 | pub fn call(helper: Helper) Insn { | 722 | pub fn call(helper: Helper) Insn { |
lib/std/os/linux/seccomp.zig+1-1| ... | @@ -54,7 +54,7 @@ | ... | @@ -54,7 +54,7 @@ |
| 54 | //! manner to the OpenSSH example: | 54 | //! manner to the OpenSSH example: |
| 55 | //! | 55 | //! |
| 56 | //! ```zig | 56 | //! ```zig |
| 57 | //! const offset = if (native_endian == .Little) struct { | 57 | //! const offset = if (native_endian == .little) struct { |
| 58 | //! pub const low = 0; | 58 | //! pub const low = 0; |
| 59 | //! pub const high = @sizeOf(u32); | 59 | //! pub const high = @sizeOf(u32); |
| 60 | //! } else struct { | 60 | //! } else struct { |
lib/std/os/test.zig+3-3| ... | @@ -609,7 +609,7 @@ test "mmap" { | ... | @@ -609,7 +609,7 @@ test "mmap" { |
| 609 | 609 | ||
| 610 | var i: u32 = 0; | 610 | var i: u32 = 0; |
| 611 | while (i < alloc_size / @sizeOf(u32)) : (i += 1) { | 611 | while (i < alloc_size / @sizeOf(u32)) : (i += 1) { |
| 612 | try stream.writeInt(u32, i, .Little); | 612 | try stream.writeInt(u32, i, .little); |
| 613 | } | 613 | } |
| 614 | } | 614 | } |
| 615 | 615 | ||
| ... | @@ -633,7 +633,7 @@ test "mmap" { | ... | @@ -633,7 +633,7 @@ test "mmap" { |
| 633 | 633 | ||
| 634 | var i: u32 = 0; | 634 | var i: u32 = 0; |
| 635 | while (i < alloc_size / @sizeOf(u32)) : (i += 1) { | 635 | while (i < alloc_size / @sizeOf(u32)) : (i += 1) { |
| 636 | try testing.expectEqual(i, try stream.readInt(u32, .Little)); | 636 | try testing.expectEqual(i, try stream.readInt(u32, .little)); |
| 637 | } | 637 | } |
| 638 | } | 638 | } |
| 639 | 639 | ||
| ... | @@ -657,7 +657,7 @@ test "mmap" { | ... | @@ -657,7 +657,7 @@ test "mmap" { |
| 657 | 657 | ||
| 658 | var i: u32 = alloc_size / 2 / @sizeOf(u32); | 658 | var i: u32 = alloc_size / 2 / @sizeOf(u32); |
| 659 | while (i < alloc_size / @sizeOf(u32)) : (i += 1) { | 659 | while (i < alloc_size / @sizeOf(u32)) : (i += 1) { |
| 660 | try testing.expectEqual(i, try stream.readInt(u32, .Little)); | 660 | try testing.expectEqual(i, try stream.readInt(u32, .little)); |
| 661 | } | 661 | } |
| 662 | } | 662 | } |
| 663 | 663 |
lib/std/os/windows.zig+2-2| ... | @@ -3360,13 +3360,13 @@ pub const GUID = extern struct { | ... | @@ -3360,13 +3360,13 @@ pub const GUID = extern struct { |
| 3360 | Data4: [8]u8, | 3360 | Data4: [8]u8, |
| 3361 | 3361 | ||
| 3362 | const hex_offsets = switch (builtin.target.cpu.arch.endian()) { | 3362 | const hex_offsets = switch (builtin.target.cpu.arch.endian()) { |
| 3363 | .Big => [16]u6{ | 3363 | .big => [16]u6{ |
| 3364 | 0, 2, 4, 6, | 3364 | 0, 2, 4, 6, |
| 3365 | 9, 11, 14, 16, | 3365 | 9, 11, 14, 16, |
| 3366 | 19, 21, 24, 26, | 3366 | 19, 21, 24, 26, |
| 3367 | 28, 30, 32, 34, | 3367 | 28, 30, 32, 34, |
| 3368 | }, | 3368 | }, |
| 3369 | .Little => [16]u6{ | 3369 | .little => [16]u6{ |
| 3370 | 6, 4, 2, 0, | 3370 | 6, 4, 2, 0, |
| 3371 | 11, 9, 16, 14, | 3371 | 11, 9, 16, 14, |
| 3372 | 19, 21, 24, 26, | 3372 | 19, 21, 24, 26, |
lib/std/packed_int_array.zig+20-20| ... | @@ -79,12 +79,12 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type { | ... | @@ -79,12 +79,12 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type { |
| 79 | if (endian != native_endian) value = @byteSwap(value); | 79 | if (endian != native_endian) value = @byteSwap(value); |
| 80 | 80 | ||
| 81 | switch (endian) { | 81 | switch (endian) { |
| 82 | .Big => { | 82 | .big => { |
| 83 | value <<= @as(Shift, @intCast(head_keep_bits)); | 83 | value <<= @as(Shift, @intCast(head_keep_bits)); |
| 84 | value >>= @as(Shift, @intCast(head_keep_bits)); | 84 | value >>= @as(Shift, @intCast(head_keep_bits)); |
| 85 | value >>= @as(Shift, @intCast(tail_keep_bits)); | 85 | value >>= @as(Shift, @intCast(tail_keep_bits)); |
| 86 | }, | 86 | }, |
| 87 | .Little => { | 87 | .little => { |
| 88 | value <<= @as(Shift, @intCast(tail_keep_bits)); | 88 | value <<= @as(Shift, @intCast(tail_keep_bits)); |
| 89 | value >>= @as(Shift, @intCast(tail_keep_bits)); | 89 | value >>= @as(Shift, @intCast(tail_keep_bits)); |
| 90 | value >>= @as(Shift, @intCast(head_keep_bits)); | 90 | value >>= @as(Shift, @intCast(head_keep_bits)); |
| ... | @@ -115,8 +115,8 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type { | ... | @@ -115,8 +115,8 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type { |
| 115 | const head_keep_bits = bit_index - (start_byte * 8); | 115 | const head_keep_bits = bit_index - (start_byte * 8); |
| 116 | const tail_keep_bits = container_bits - (int_bits + head_keep_bits); | 116 | const tail_keep_bits = container_bits - (int_bits + head_keep_bits); |
| 117 | const keep_shift = switch (endian) { | 117 | const keep_shift = switch (endian) { |
| 118 | .Big => @as(Shift, @intCast(tail_keep_bits)), | 118 | .big => @as(Shift, @intCast(tail_keep_bits)), |
| 119 | .Little => @as(Shift, @intCast(head_keep_bits)), | 119 | .little => @as(Shift, @intCast(head_keep_bits)), |
| 120 | }; | 120 | }; |
| 121 | 121 | ||
| 122 | //position the bits where they need to be in the container | 122 | //position the bits where they need to be in the container |
| ... | @@ -388,10 +388,10 @@ test "PackedIntArray" { | ... | @@ -388,10 +388,10 @@ test "PackedIntArray" { |
| 388 | 388 | ||
| 389 | test "PackedIntIo" { | 389 | test "PackedIntIo" { |
| 390 | const bytes = [_]u8{ 0b01101_000, 0b01011_110, 0b00011_101 }; | 390 | const bytes = [_]u8{ 0b01101_000, 0b01011_110, 0b00011_101 }; |
| 391 | try testing.expectEqual(@as(u15, 0x2bcd), PackedIntIo(u15, .Little).get(&bytes, 0, 3)); | 391 | try testing.expectEqual(@as(u15, 0x2bcd), PackedIntIo(u15, .little).get(&bytes, 0, 3)); |
| 392 | try testing.expectEqual(@as(u16, 0xabcd), PackedIntIo(u16, .Little).get(&bytes, 0, 3)); | 392 | try testing.expectEqual(@as(u16, 0xabcd), PackedIntIo(u16, .little).get(&bytes, 0, 3)); |
| 393 | try testing.expectEqual(@as(u17, 0x1abcd), PackedIntIo(u17, .Little).get(&bytes, 0, 3)); | 393 | try testing.expectEqual(@as(u17, 0x1abcd), PackedIntIo(u17, .little).get(&bytes, 0, 3)); |
| 394 | try testing.expectEqual(@as(u18, 0x3abcd), PackedIntIo(u18, .Little).get(&bytes, 0, 3)); | 394 | try testing.expectEqual(@as(u18, 0x3abcd), PackedIntIo(u18, .little).get(&bytes, 0, 3)); |
| 395 | } | 395 | } |
| 396 | 396 | ||
| 397 | test "PackedIntArray init" { | 397 | test "PackedIntArray init" { |
| ... | @@ -555,16 +555,16 @@ test "PackedInt(Array/Slice) sliceCast" { | ... | @@ -555,16 +555,16 @@ test "PackedInt(Array/Slice) sliceCast" { |
| 555 | var i = @as(usize, 0); | 555 | var i = @as(usize, 0); |
| 556 | while (i < packed_slice_cast_2.len) : (i += 1) { | 556 | while (i < packed_slice_cast_2.len) : (i += 1) { |
| 557 | const val = switch (native_endian) { | 557 | const val = switch (native_endian) { |
| 558 | .Big => 0b01, | 558 | .big => 0b01, |
| 559 | .Little => 0b10, | 559 | .little => 0b10, |
| 560 | }; | 560 | }; |
| 561 | try testing.expect(packed_slice_cast_2.get(i) == val); | 561 | try testing.expect(packed_slice_cast_2.get(i) == val); |
| 562 | } | 562 | } |
| 563 | i = 0; | 563 | i = 0; |
| 564 | while (i < packed_slice_cast_4.len) : (i += 1) { | 564 | while (i < packed_slice_cast_4.len) : (i += 1) { |
| 565 | const val = switch (native_endian) { | 565 | const val = switch (native_endian) { |
| 566 | .Big => 0b0101, | 566 | .big => 0b0101, |
| 567 | .Little => 0b1010, | 567 | .little => 0b1010, |
| 568 | }; | 568 | }; |
| 569 | try testing.expect(packed_slice_cast_4.get(i) == val); | 569 | try testing.expect(packed_slice_cast_4.get(i) == val); |
| 570 | } | 570 | } |
| ... | @@ -577,8 +577,8 @@ test "PackedInt(Array/Slice) sliceCast" { | ... | @@ -577,8 +577,8 @@ test "PackedInt(Array/Slice) sliceCast" { |
| 577 | i = 0; | 577 | i = 0; |
| 578 | while (i < packed_slice_cast_3.len) : (i += 1) { | 578 | while (i < packed_slice_cast_3.len) : (i += 1) { |
| 579 | const val = switch (native_endian) { | 579 | const val = switch (native_endian) { |
| 580 | .Big => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000), | 580 | .big => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000), |
| 581 | .Little => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000), | 581 | .little => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000), |
| 582 | }; | 582 | }; |
| 583 | try testing.expect(packed_slice_cast_3.get(i) == val); | 583 | try testing.expect(packed_slice_cast_3.get(i) == val); |
| 584 | } | 584 | } |
| ... | @@ -586,7 +586,7 @@ test "PackedInt(Array/Slice) sliceCast" { | ... | @@ -586,7 +586,7 @@ test "PackedInt(Array/Slice) sliceCast" { |
| 586 | 586 | ||
| 587 | test "PackedInt(Array/Slice)Endian" { | 587 | test "PackedInt(Array/Slice)Endian" { |
| 588 | { | 588 | { |
| 589 | const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8); | 589 | const PackedArrayBe = PackedIntArrayEndian(u4, .big, 8); |
| 590 | var packed_array_be = PackedArrayBe.init([_]u4{ 0, 1, 2, 3, 4, 5, 6, 7 }); | 590 | var packed_array_be = PackedArrayBe.init([_]u4{ 0, 1, 2, 3, 4, 5, 6, 7 }); |
| 591 | try testing.expect(packed_array_be.bytes[0] == 0b00000001); | 591 | try testing.expect(packed_array_be.bytes[0] == 0b00000001); |
| 592 | try testing.expect(packed_array_be.bytes[1] == 0b00100011); | 592 | try testing.expect(packed_array_be.bytes[1] == 0b00100011); |
| ... | @@ -596,14 +596,14 @@ test "PackedInt(Array/Slice)Endian" { | ... | @@ -596,14 +596,14 @@ test "PackedInt(Array/Slice)Endian" { |
| 596 | try testing.expect(packed_array_be.get(i) == i); | 596 | try testing.expect(packed_array_be.get(i) == i); |
| 597 | } | 597 | } |
| 598 | 598 | ||
| 599 | var packed_slice_le = packed_array_be.sliceCastEndian(u4, .Little); | 599 | var packed_slice_le = packed_array_be.sliceCastEndian(u4, .little); |
| 600 | i = 0; | 600 | i = 0; |
| 601 | while (i < packed_slice_le.len) : (i += 1) { | 601 | while (i < packed_slice_le.len) : (i += 1) { |
| 602 | const val = if (i % 2 == 0) i + 1 else i - 1; | 602 | const val = if (i % 2 == 0) i + 1 else i - 1; |
| 603 | try testing.expect(packed_slice_le.get(i) == val); | 603 | try testing.expect(packed_slice_le.get(i) == val); |
| 604 | } | 604 | } |
| 605 | 605 | ||
| 606 | var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u4, .Little); | 606 | var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u4, .little); |
| 607 | i = 0; | 607 | i = 0; |
| 608 | while (i < packed_slice_le_shift.len) : (i += 1) { | 608 | while (i < packed_slice_le_shift.len) : (i += 1) { |
| 609 | const val = if (i % 2 == 0) i else i + 2; | 609 | const val = if (i % 2 == 0) i else i + 2; |
| ... | @@ -612,7 +612,7 @@ test "PackedInt(Array/Slice)Endian" { | ... | @@ -612,7 +612,7 @@ test "PackedInt(Array/Slice)Endian" { |
| 612 | } | 612 | } |
| 613 | 613 | ||
| 614 | { | 614 | { |
| 615 | const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8); | 615 | const PackedArrayBe = PackedIntArrayEndian(u11, .big, 8); |
| 616 | var packed_array_be = PackedArrayBe.init([_]u11{ 0, 1, 2, 3, 4, 5, 6, 7 }); | 616 | var packed_array_be = PackedArrayBe.init([_]u11{ 0, 1, 2, 3, 4, 5, 6, 7 }); |
| 617 | try testing.expect(packed_array_be.bytes[0] == 0b00000000); | 617 | try testing.expect(packed_array_be.bytes[0] == 0b00000000); |
| 618 | try testing.expect(packed_array_be.bytes[1] == 0b00000000); | 618 | try testing.expect(packed_array_be.bytes[1] == 0b00000000); |
| ... | @@ -625,7 +625,7 @@ test "PackedInt(Array/Slice)Endian" { | ... | @@ -625,7 +625,7 @@ test "PackedInt(Array/Slice)Endian" { |
| 625 | try testing.expect(packed_array_be.get(i) == i); | 625 | try testing.expect(packed_array_be.get(i) == i); |
| 626 | } | 626 | } |
| 627 | 627 | ||
| 628 | var packed_slice_le = packed_array_be.sliceCastEndian(u11, .Little); | 628 | var packed_slice_le = packed_array_be.sliceCastEndian(u11, .little); |
| 629 | try testing.expect(packed_slice_le.get(0) == 0b00000000000); | 629 | try testing.expect(packed_slice_le.get(0) == 0b00000000000); |
| 630 | try testing.expect(packed_slice_le.get(1) == 0b00010000000); | 630 | try testing.expect(packed_slice_le.get(1) == 0b00010000000); |
| 631 | try testing.expect(packed_slice_le.get(2) == 0b00000000100); | 631 | try testing.expect(packed_slice_le.get(2) == 0b00000000100); |
| ... | @@ -635,7 +635,7 @@ test "PackedInt(Array/Slice)Endian" { | ... | @@ -635,7 +635,7 @@ test "PackedInt(Array/Slice)Endian" { |
| 635 | try testing.expect(packed_slice_le.get(6) == 0b10000010000); | 635 | try testing.expect(packed_slice_le.get(6) == 0b10000010000); |
| 636 | try testing.expect(packed_slice_le.get(7) == 0b00000111001); | 636 | try testing.expect(packed_slice_le.get(7) == 0b00000111001); |
| 637 | 637 | ||
| 638 | var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u11, .Little); | 638 | var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u11, .little); |
| 639 | try testing.expect(packed_slice_le_shift.get(0) == 0b00010000000); | 639 | try testing.expect(packed_slice_le_shift.get(0) == 0b00010000000); |
| 640 | try testing.expect(packed_slice_le_shift.get(1) == 0b00000000100); | 640 | try testing.expect(packed_slice_le_shift.get(1) == 0b00000000100); |
| 641 | try testing.expect(packed_slice_le_shift.get(2) == 0b00000000000); | 641 | try testing.expect(packed_slice_le_shift.get(2) == 0b00000000000); |
lib/std/pdb.zig+14-14| ... | @@ -464,12 +464,12 @@ pub const PDBStringTableHeader = extern struct { | ... | @@ -464,12 +464,12 @@ pub const PDBStringTableHeader = extern struct { |
| 464 | }; | 464 | }; |
| 465 | 465 | ||
| 466 | fn readSparseBitVector(stream: anytype, allocator: mem.Allocator) ![]u32 { | 466 | fn readSparseBitVector(stream: anytype, allocator: mem.Allocator) ![]u32 { |
| 467 | const num_words = try stream.readInt(u32, .Little); | 467 | const num_words = try stream.readInt(u32, .little); |
| 468 | var list = ArrayList(u32).init(allocator); | 468 | var list = ArrayList(u32).init(allocator); |
| 469 | errdefer list.deinit(); | 469 | errdefer list.deinit(); |
| 470 | var word_i: u32 = 0; | 470 | var word_i: u32 = 0; |
| 471 | while (word_i != num_words) : (word_i += 1) { | 471 | while (word_i != num_words) : (word_i += 1) { |
| 472 | const word = try stream.readInt(u32, .Little); | 472 | const word = try stream.readInt(u32, .little); |
| 473 | var bit_i: u5 = 0; | 473 | var bit_i: u5 = 0; |
| 474 | while (true) : (bit_i += 1) { | 474 | while (true) : (bit_i += 1) { |
| 475 | if (word & (@as(u32, 1) << bit_i) != 0) { | 475 | if (word & (@as(u32, 1) << bit_i) != 0) { |
| ... | @@ -599,7 +599,7 @@ pub const Pdb = struct { | ... | @@ -599,7 +599,7 @@ pub const Pdb = struct { |
| 599 | 599 | ||
| 600 | var sect_cont_offset: usize = 0; | 600 | var sect_cont_offset: usize = 0; |
| 601 | if (section_contrib_size != 0) { | 601 | if (section_contrib_size != 0) { |
| 602 | const version = reader.readEnum(SectionContrSubstreamVersion, .Little) catch |err| switch (err) { | 602 | const version = reader.readEnum(SectionContrSubstreamVersion, .little) catch |err| switch (err) { |
| 603 | error.InvalidValue => return error.InvalidDebugInfo, | 603 | error.InvalidValue => return error.InvalidDebugInfo, |
| 604 | else => |e| return e, | 604 | else => |e| return e, |
| 605 | }; | 605 | }; |
| ... | @@ -625,10 +625,10 @@ pub const Pdb = struct { | ... | @@ -625,10 +625,10 @@ pub const Pdb = struct { |
| 625 | const reader = stream.reader(); | 625 | const reader = stream.reader(); |
| 626 | 626 | ||
| 627 | // Parse the InfoStreamHeader. | 627 | // Parse the InfoStreamHeader. |
| 628 | const version = try reader.readInt(u32, .Little); | 628 | const version = try reader.readInt(u32, .little); |
| 629 | const signature = try reader.readInt(u32, .Little); | 629 | const signature = try reader.readInt(u32, .little); |
| 630 | _ = signature; | 630 | _ = signature; |
| 631 | const age = try reader.readInt(u32, .Little); | 631 | const age = try reader.readInt(u32, .little); |
| 632 | const guid = try reader.readBytesNoEof(16); | 632 | const guid = try reader.readBytesNoEof(16); |
| 633 | 633 | ||
| 634 | if (version != 20000404) // VC70, only value observed by LLVM team | 634 | if (version != 20000404) // VC70, only value observed by LLVM team |
| ... | @@ -639,7 +639,7 @@ pub const Pdb = struct { | ... | @@ -639,7 +639,7 @@ pub const Pdb = struct { |
| 639 | 639 | ||
| 640 | // Find the string table. | 640 | // Find the string table. |
| 641 | const string_table_index = str_tab_index: { | 641 | const string_table_index = str_tab_index: { |
| 642 | const name_bytes_len = try reader.readInt(u32, .Little); | 642 | const name_bytes_len = try reader.readInt(u32, .little); |
| 643 | const name_bytes = try self.allocator.alloc(u8, name_bytes_len); | 643 | const name_bytes = try self.allocator.alloc(u8, name_bytes_len); |
| 644 | defer self.allocator.free(name_bytes); | 644 | defer self.allocator.free(name_bytes); |
| 645 | try reader.readNoEof(name_bytes); | 645 | try reader.readNoEof(name_bytes); |
| ... | @@ -667,8 +667,8 @@ pub const Pdb = struct { | ... | @@ -667,8 +667,8 @@ pub const Pdb = struct { |
| 667 | defer self.allocator.free(deleted); | 667 | defer self.allocator.free(deleted); |
| 668 | 668 | ||
| 669 | for (present) |_| { | 669 | for (present) |_| { |
| 670 | const name_offset = try reader.readInt(u32, .Little); | 670 | const name_offset = try reader.readInt(u32, .little); |
| 671 | const name_index = try reader.readInt(u32, .Little); | 671 | const name_index = try reader.readInt(u32, .little); |
| 672 | if (name_offset > name_bytes.len) | 672 | if (name_offset > name_bytes.len) |
| 673 | return error.InvalidDebugInfo; | 673 | return error.InvalidDebugInfo; |
| 674 | const name = mem.sliceTo(name_bytes[name_offset..], 0); | 674 | const name = mem.sliceTo(name_bytes[name_offset..], 0); |
| ... | @@ -821,7 +821,7 @@ pub const Pdb = struct { | ... | @@ -821,7 +821,7 @@ pub const Pdb = struct { |
| 821 | return error.MissingDebugInfo; | 821 | return error.MissingDebugInfo; |
| 822 | const reader = stream.reader(); | 822 | const reader = stream.reader(); |
| 823 | 823 | ||
| 824 | const signature = try reader.readInt(u32, .Little); | 824 | const signature = try reader.readInt(u32, .little); |
| 825 | if (signature != 4) | 825 | if (signature != 4) |
| 826 | return error.InvalidDebugInfo; | 826 | return error.InvalidDebugInfo; |
| 827 | 827 | ||
| ... | @@ -899,7 +899,7 @@ const Msf = struct { | ... | @@ -899,7 +899,7 @@ const Msf = struct { |
| 899 | try file.seekTo(superblock.BlockSize * superblock.BlockMapAddr); | 899 | try file.seekTo(superblock.BlockSize * superblock.BlockMapAddr); |
| 900 | var dir_blocks = try allocator.alloc(u32, dir_block_count); | 900 | var dir_blocks = try allocator.alloc(u32, dir_block_count); |
| 901 | for (dir_blocks) |*b| { | 901 | for (dir_blocks) |*b| { |
| 902 | b.* = try in.readInt(u32, .Little); | 902 | b.* = try in.readInt(u32, .little); |
| 903 | } | 903 | } |
| 904 | var directory = MsfStream.init( | 904 | var directory = MsfStream.init( |
| 905 | superblock.BlockSize, | 905 | superblock.BlockSize, |
| ... | @@ -908,7 +908,7 @@ const Msf = struct { | ... | @@ -908,7 +908,7 @@ const Msf = struct { |
| 908 | ); | 908 | ); |
| 909 | 909 | ||
| 910 | const begin = directory.pos; | 910 | const begin = directory.pos; |
| 911 | const stream_count = try directory.reader().readInt(u32, .Little); | 911 | const stream_count = try directory.reader().readInt(u32, .little); |
| 912 | const stream_sizes = try allocator.alloc(u32, stream_count); | 912 | const stream_sizes = try allocator.alloc(u32, stream_count); |
| 913 | defer allocator.free(stream_sizes); | 913 | defer allocator.free(stream_sizes); |
| 914 | 914 | ||
| ... | @@ -917,7 +917,7 @@ const Msf = struct { | ... | @@ -917,7 +917,7 @@ const Msf = struct { |
| 917 | // and must be taken into account when resolving stream indices. | 917 | // and must be taken into account when resolving stream indices. |
| 918 | const Nil = 0xFFFFFFFF; | 918 | const Nil = 0xFFFFFFFF; |
| 919 | for (stream_sizes) |*s| { | 919 | for (stream_sizes) |*s| { |
| 920 | const size = try directory.reader().readInt(u32, .Little); | 920 | const size = try directory.reader().readInt(u32, .little); |
| 921 | s.* = if (size == Nil) 0 else blockCountFromSize(size, superblock.BlockSize); | 921 | s.* = if (size == Nil) 0 else blockCountFromSize(size, superblock.BlockSize); |
| 922 | } | 922 | } |
| 923 | 923 | ||
| ... | @@ -932,7 +932,7 @@ const Msf = struct { | ... | @@ -932,7 +932,7 @@ const Msf = struct { |
| 932 | var blocks = try allocator.alloc(u32, size); | 932 | var blocks = try allocator.alloc(u32, size); |
| 933 | var j: u32 = 0; | 933 | var j: u32 = 0; |
| 934 | while (j < size) : (j += 1) { | 934 | while (j < size) : (j += 1) { |
| 935 | const block_id = try directory.reader().readInt(u32, .Little); | 935 | const block_id = try directory.reader().readInt(u32, .little); |
| 936 | const n = (block_id % superblock.BlockSize); | 936 | const n = (block_id % superblock.BlockSize); |
| 937 | // 0 is for SuperBlock, 1 and 2 for FPMs. | 937 | // 0 is for SuperBlock, 1 and 2 for FPMs. |
| 938 | if (block_id == 0 or n == 1 or n == 2 or block_id * superblock.BlockSize > file_len) | 938 | if (block_id == 0 or n == 1 or n == 2 or block_id * superblock.BlockSize > file_len) |
lib/std/rand.zig+1-1| ... | @@ -113,7 +113,7 @@ pub const Random = struct { | ... | @@ -113,7 +113,7 @@ pub const Random = struct { |
| 113 | // use LE instead of native endian for better portability maybe? | 113 | // use LE instead of native endian for better portability maybe? |
| 114 | // TODO: endian portability is pointless if the underlying prng isn't endian portable. | 114 | // TODO: endian portability is pointless if the underlying prng isn't endian portable. |
| 115 | // TODO: document the endian portability of this library. | 115 | // TODO: document the endian portability of this library. |
| 116 | const byte_aligned_result = mem.readInt(ByteAlignedT, &rand_bytes, .Little); | 116 | const byte_aligned_result = mem.readInt(ByteAlignedT, &rand_bytes, .little); |
| 117 | const unsigned_result: UnsignedT = @truncate(byte_aligned_result); | 117 | const unsigned_result: UnsignedT = @truncate(byte_aligned_result); |
| 118 | return @bitCast(unsigned_result); | 118 | return @bitCast(unsigned_result); |
| 119 | } | 119 | } |
lib/std/rand/Ascon.zig+1-1| ... | @@ -13,7 +13,7 @@ const mem = std.mem; | ... | @@ -13,7 +13,7 @@ const mem = std.mem; |
| 13 | const Random = std.rand.Random; | 13 | const Random = std.rand.Random; |
| 14 | const Self = @This(); | 14 | const Self = @This(); |
| 15 | 15 | ||
| 16 | const Ascon = std.crypto.core.Ascon(.Little); | 16 | const Ascon = std.crypto.core.Ascon(.little); |
| 17 | 17 | ||
| 18 | state: Ascon, | 18 | state: Ascon, |
| 19 | 19 |
lib/std/rand/Isaac64.zig+1-1| ... | @@ -228,7 +228,7 @@ test "isaac64 fill" { | ... | @@ -228,7 +228,7 @@ test "isaac64 fill" { |
| 228 | for (seq) |s| { | 228 | for (seq) |s| { |
| 229 | var buf0: [8]u8 = undefined; | 229 | var buf0: [8]u8 = undefined; |
| 230 | var buf1: [7]u8 = undefined; | 230 | var buf1: [7]u8 = undefined; |
| 231 | std.mem.writeInt(u64, &buf0, s, .Little); | 231 | std.mem.writeInt(u64, &buf0, s, .little); |
| 232 | r.fill(&buf1); | 232 | r.fill(&buf1); |
| 233 | try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); | 233 | try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); |
| 234 | } | 234 | } |
lib/std/rand/Pcg.zig+2-2| ... | @@ -111,8 +111,8 @@ test "pcg fill" { | ... | @@ -111,8 +111,8 @@ test "pcg fill" { |
| 111 | var i: u32 = 0; | 111 | var i: u32 = 0; |
| 112 | while (i < seq.len) : (i += 2) { | 112 | while (i < seq.len) : (i += 2) { |
| 113 | var buf0: [8]u8 = undefined; | 113 | var buf0: [8]u8 = undefined; |
| 114 | std.mem.writeInt(u32, buf0[0..4], seq[i], .Little); | 114 | std.mem.writeInt(u32, buf0[0..4], seq[i], .little); |
| 115 | std.mem.writeInt(u32, buf0[4..8], seq[i + 1], .Little); | 115 | std.mem.writeInt(u32, buf0[4..8], seq[i + 1], .little); |
| 116 | 116 | ||
| 117 | var buf1: [7]u8 = undefined; | 117 | var buf1: [7]u8 = undefined; |
| 118 | r.fill(&buf1); | 118 | r.fill(&buf1); |
lib/std/rand/RomuTrio.zig+1-1| ... | @@ -115,7 +115,7 @@ test "RomuTrio fill" { | ... | @@ -115,7 +115,7 @@ test "RomuTrio fill" { |
| 115 | for (seq) |s| { | 115 | for (seq) |s| { |
| 116 | var buf0: [8]u8 = undefined; | 116 | var buf0: [8]u8 = undefined; |
| 117 | var buf1: [7]u8 = undefined; | 117 | var buf1: [7]u8 = undefined; |
| 118 | std.mem.writeInt(u64, &buf0, s, .Little); | 118 | std.mem.writeInt(u64, &buf0, s, .little); |
| 119 | r.fill(&buf1); | 119 | r.fill(&buf1); |
| 120 | try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); | 120 | try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); |
| 121 | } | 121 | } |
lib/std/rand/Sfc64.zig+1-1| ... | @@ -125,7 +125,7 @@ test "Sfc64 fill" { | ... | @@ -125,7 +125,7 @@ test "Sfc64 fill" { |
| 125 | for (seq) |s| { | 125 | for (seq) |s| { |
| 126 | var buf0: [8]u8 = undefined; | 126 | var buf0: [8]u8 = undefined; |
| 127 | var buf1: [7]u8 = undefined; | 127 | var buf1: [7]u8 = undefined; |
| 128 | std.mem.writeInt(u64, &buf0, s, .Little); | 128 | std.mem.writeInt(u64, &buf0, s, .little); |
| 129 | r.fill(&buf1); | 129 | r.fill(&buf1); |
| 130 | try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); | 130 | try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); |
| 131 | } | 131 | } |
lib/std/rand/Xoroshiro128.zig+1-1| ... | @@ -140,7 +140,7 @@ test "xoroshiro fill" { | ... | @@ -140,7 +140,7 @@ test "xoroshiro fill" { |
| 140 | for (seq) |s| { | 140 | for (seq) |s| { |
| 141 | var buf0: [8]u8 = undefined; | 141 | var buf0: [8]u8 = undefined; |
| 142 | var buf1: [7]u8 = undefined; | 142 | var buf1: [7]u8 = undefined; |
| 143 | std.mem.writeInt(u64, &buf0, s, .Little); | 143 | std.mem.writeInt(u64, &buf0, s, .little); |
| 144 | r.fill(&buf1); | 144 | r.fill(&buf1); |
| 145 | try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); | 145 | try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); |
| 146 | } | 146 | } |
lib/std/rand/Xoshiro256.zig+1-1| ... | @@ -139,7 +139,7 @@ test "xoroshiro fill" { | ... | @@ -139,7 +139,7 @@ test "xoroshiro fill" { |
| 139 | for (seq) |s| { | 139 | for (seq) |s| { |
| 140 | var buf0: [8]u8 = undefined; | 140 | var buf0: [8]u8 = undefined; |
| 141 | var buf1: [7]u8 = undefined; | 141 | var buf1: [7]u8 = undefined; |
| 142 | std.mem.writeInt(u64, &buf0, s, .Little); | 142 | std.mem.writeInt(u64, &buf0, s, .little); |
| 143 | r.fill(&buf1); | 143 | r.fill(&buf1); |
| 144 | try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); | 144 | try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); |
| 145 | } | 145 | } |
lib/std/rand/test.zig+1-1| ... | @@ -71,7 +71,7 @@ const Dilbert = struct { | ... | @@ -71,7 +71,7 @@ const Dilbert = struct { |
| 71 | for (seq) |s| { | 71 | for (seq) |s| { |
| 72 | var buf0: [8]u8 = undefined; | 72 | var buf0: [8]u8 = undefined; |
| 73 | var buf1: [8]u8 = undefined; | 73 | var buf1: [8]u8 = undefined; |
| 74 | std.mem.writeInt(u64, &buf0, s, .Big); | 74 | std.mem.writeInt(u64, &buf0, s, .big); |
| 75 | r.fill(&buf1); | 75 | r.fill(&buf1); |
| 76 | try std.testing.expect(std.mem.eql(u8, buf0[0..], buf1[0..])); | 76 | try std.testing.expect(std.mem.eql(u8, buf0[0..], buf1[0..])); |
| 77 | } | 77 | } |
lib/std/target.zig+2-2| ... | @@ -1191,7 +1191,7 @@ pub const Target = struct { | ... | @@ -1191,7 +1191,7 @@ pub const Target = struct { |
| 1191 | .loongarch32, | 1191 | .loongarch32, |
| 1192 | .loongarch64, | 1192 | .loongarch64, |
| 1193 | .arc, | 1193 | .arc, |
| 1194 | => .Little, | 1194 | => .little, |
| 1195 | 1195 | ||
| 1196 | .armeb, | 1196 | .armeb, |
| 1197 | .aarch64_be, | 1197 | .aarch64_be, |
| ... | @@ -1207,7 +1207,7 @@ pub const Target = struct { | ... | @@ -1207,7 +1207,7 @@ pub const Target = struct { |
| 1207 | .tce, | 1207 | .tce, |
| 1208 | .lanai, | 1208 | .lanai, |
| 1209 | .s390x, | 1209 | .s390x, |
| 1210 | => .Big, | 1210 | => .big, |
| 1211 | }; | 1211 | }; |
| 1212 | } | 1212 | } |
| 1213 | 1213 |
lib/std/tz.zig+6-6| ... | @@ -59,7 +59,7 @@ pub const Tz = struct { | ... | @@ -59,7 +59,7 @@ pub const Tz = struct { |
| 59 | if (!std.mem.eql(u8, &legacy_header.magic, "TZif")) return error.BadHeader; | 59 | if (!std.mem.eql(u8, &legacy_header.magic, "TZif")) return error.BadHeader; |
| 60 | if (legacy_header.version != 0 and legacy_header.version != '2' and legacy_header.version != '3') return error.BadVersion; | 60 | if (legacy_header.version != 0 and legacy_header.version != '2' and legacy_header.version != '3') return error.BadVersion; |
| 61 | 61 | ||
| 62 | if (builtin.target.cpu.arch.endian() != std.builtin.Endian.Big) { | 62 | if (builtin.target.cpu.arch.endian() != std.builtin.Endian.big) { |
| 63 | std.mem.byteSwapAllFields(@TypeOf(legacy_header.counts), &legacy_header.counts); | 63 | std.mem.byteSwapAllFields(@TypeOf(legacy_header.counts), &legacy_header.counts); |
| 64 | } | 64 | } |
| 65 | 65 | ||
| ... | @@ -73,7 +73,7 @@ pub const Tz = struct { | ... | @@ -73,7 +73,7 @@ pub const Tz = struct { |
| 73 | var header = try reader.readStruct(Header); | 73 | var header = try reader.readStruct(Header); |
| 74 | if (!std.mem.eql(u8, &header.magic, "TZif")) return error.BadHeader; | 74 | if (!std.mem.eql(u8, &header.magic, "TZif")) return error.BadHeader; |
| 75 | if (header.version != '2' and header.version != '3') return error.BadVersion; | 75 | if (header.version != '2' and header.version != '3') return error.BadVersion; |
| 76 | if (builtin.target.cpu.arch.endian() != std.builtin.Endian.Big) { | 76 | if (builtin.target.cpu.arch.endian() != std.builtin.Endian.big) { |
| 77 | std.mem.byteSwapAllFields(@TypeOf(header.counts), &header.counts); | 77 | std.mem.byteSwapAllFields(@TypeOf(header.counts), &header.counts); |
| 78 | } | 78 | } |
| 79 | 79 | ||
| ... | @@ -98,7 +98,7 @@ pub const Tz = struct { | ... | @@ -98,7 +98,7 @@ pub const Tz = struct { |
| 98 | // Parse transition types | 98 | // Parse transition types |
| 99 | var i: usize = 0; | 99 | var i: usize = 0; |
| 100 | while (i < header.counts.timecnt) : (i += 1) { | 100 | while (i < header.counts.timecnt) : (i += 1) { |
| 101 | transitions[i].ts = if (legacy) try reader.readInt(i32, .Big) else try reader.readInt(i64, .Big); | 101 | transitions[i].ts = if (legacy) try reader.readInt(i32, .big) else try reader.readInt(i64, .big); |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | i = 0; | 104 | i = 0; |
| ... | @@ -111,7 +111,7 @@ pub const Tz = struct { | ... | @@ -111,7 +111,7 @@ pub const Tz = struct { |
| 111 | // Parse time types | 111 | // Parse time types |
| 112 | i = 0; | 112 | i = 0; |
| 113 | while (i < header.counts.typecnt) : (i += 1) { | 113 | while (i < header.counts.typecnt) : (i += 1) { |
| 114 | const offset = try reader.readInt(i32, .Big); | 114 | const offset = try reader.readInt(i32, .big); |
| 115 | if (offset < -2147483648) return error.Malformed; // rfc8536: utoff [...] MUST NOT be -2**31 | 115 | if (offset < -2147483648) return error.Malformed; // rfc8536: utoff [...] MUST NOT be -2**31 |
| 116 | const dst = try reader.readByte(); | 116 | const dst = try reader.readByte(); |
| 117 | if (dst != 0 and dst != 1) return error.Malformed; // rfc8536: (is)dst [...] The value MUST be 0 or 1. | 117 | if (dst != 0 and dst != 1) return error.Malformed; // rfc8536: (is)dst [...] The value MUST be 0 or 1. |
| ... | @@ -144,12 +144,12 @@ pub const Tz = struct { | ... | @@ -144,12 +144,12 @@ pub const Tz = struct { |
| 144 | // Parse leap seconds | 144 | // Parse leap seconds |
| 145 | i = 0; | 145 | i = 0; |
| 146 | while (i < header.counts.leapcnt) : (i += 1) { | 146 | while (i < header.counts.leapcnt) : (i += 1) { |
| 147 | const occur: i64 = if (legacy) try reader.readInt(i32, .Big) else try reader.readInt(i64, .Big); | 147 | const occur: i64 = if (legacy) try reader.readInt(i32, .big) else try reader.readInt(i64, .big); |
| 148 | if (occur < 0) return error.Malformed; // rfc8536: occur [...] MUST be nonnegative | 148 | if (occur < 0) return error.Malformed; // rfc8536: occur [...] MUST be nonnegative |
| 149 | if (i > 0 and leapseconds[i - 1].occurrence + 2419199 > occur) return error.Malformed; // rfc8536: occur [...] each later value MUST be at least 2419199 greater than the previous value | 149 | if (i > 0 and leapseconds[i - 1].occurrence + 2419199 > occur) return error.Malformed; // rfc8536: occur [...] each later value MUST be at least 2419199 greater than the previous value |
| 150 | if (occur > std.math.maxInt(i48)) return error.Malformed; // Unreasonably far into the future | 150 | if (occur > std.math.maxInt(i48)) return error.Malformed; // Unreasonably far into the future |
| 151 | 151 | ||
| 152 | const corr = try reader.readInt(i32, .Big); | 152 | const corr = try reader.readInt(i32, .big); |
| 153 | if (i == 0 and corr != -1 and corr != 1) return error.Malformed; // rfc8536: The correction value in the first leap-second record, if present, MUST be either one (1) or minus one (-1) | 153 | if (i == 0 and corr != -1 and corr != 1) return error.Malformed; // rfc8536: The correction value in the first leap-second record, if present, MUST be either one (1) or minus one (-1) |
| 154 | if (i > 0 and leapseconds[i - 1].correction != corr + 1 and leapseconds[i - 1].correction != corr - 1) return error.Malformed; // rfc8536: The correction values in adjacent leap-second records MUST differ by exactly one (1) | 154 | if (i > 0 and leapseconds[i - 1].correction != corr + 1 and leapseconds[i - 1].correction != corr - 1) return error.Malformed; // rfc8536: The correction values in adjacent leap-second records MUST differ by exactly one (1) |
| 155 | if (corr > std.math.maxInt(i16)) return error.Malformed; // Unreasonably large correction | 155 | if (corr > std.math.maxInt(i16)) return error.Malformed; // Unreasonably large correction |
lib/std/unicode.zig+16-16| ... | @@ -452,12 +452,12 @@ pub const Utf16LeIterator = struct { | ... | @@ -452,12 +452,12 @@ pub const Utf16LeIterator = struct { |
| 452 | assert(it.i <= it.bytes.len); | 452 | assert(it.i <= it.bytes.len); |
| 453 | if (it.i == it.bytes.len) return null; | 453 | if (it.i == it.bytes.len) return null; |
| 454 | var code_units: [2]u16 = undefined; | 454 | var code_units: [2]u16 = undefined; |
| 455 | code_units[0] = mem.readInt(u16, it.bytes[it.i..][0..2], .Little); | 455 | code_units[0] = mem.readInt(u16, it.bytes[it.i..][0..2], .little); |
| 456 | it.i += 2; | 456 | it.i += 2; |
| 457 | if (utf16IsHighSurrogate(code_units[0])) { | 457 | if (utf16IsHighSurrogate(code_units[0])) { |
| 458 | // surrogate pair | 458 | // surrogate pair |
| 459 | if (it.i >= it.bytes.len) return error.DanglingSurrogateHalf; | 459 | if (it.i >= it.bytes.len) return error.DanglingSurrogateHalf; |
| 460 | code_units[1] = mem.readInt(u16, it.bytes[it.i..][0..2], .Little); | 460 | code_units[1] = mem.readInt(u16, it.bytes[it.i..][0..2], .little); |
| 461 | const codepoint = try utf16DecodeSurrogatePair(&code_units); | 461 | const codepoint = try utf16DecodeSurrogatePair(&code_units); |
| 462 | it.i += 2; | 462 | it.i += 2; |
| 463 | return codepoint; | 463 | return codepoint; |
| ... | @@ -878,16 +878,16 @@ test "utf16leToUtf8" { | ... | @@ -878,16 +878,16 @@ test "utf16leToUtf8" { |
| 878 | const utf16le_as_bytes = mem.sliceAsBytes(utf16le[0..]); | 878 | const utf16le_as_bytes = mem.sliceAsBytes(utf16le[0..]); |
| 879 | 879 | ||
| 880 | { | 880 | { |
| 881 | mem.writeInt(u16, utf16le_as_bytes[0..2], 'A', .Little); | 881 | mem.writeInt(u16, utf16le_as_bytes[0..2], 'A', .little); |
| 882 | mem.writeInt(u16, utf16le_as_bytes[2..4], 'a', .Little); | 882 | mem.writeInt(u16, utf16le_as_bytes[2..4], 'a', .little); |
| 883 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); | 883 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); |
| 884 | defer std.testing.allocator.free(utf8); | 884 | defer std.testing.allocator.free(utf8); |
| 885 | try testing.expect(mem.eql(u8, utf8, "Aa")); | 885 | try testing.expect(mem.eql(u8, utf8, "Aa")); |
| 886 | } | 886 | } |
| 887 | 887 | ||
| 888 | { | 888 | { |
| 889 | mem.writeInt(u16, utf16le_as_bytes[0..2], 0x80, .Little); | 889 | mem.writeInt(u16, utf16le_as_bytes[0..2], 0x80, .little); |
| 890 | mem.writeInt(u16, utf16le_as_bytes[2..4], 0xffff, .Little); | 890 | mem.writeInt(u16, utf16le_as_bytes[2..4], 0xffff, .little); |
| 891 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); | 891 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); |
| 892 | defer std.testing.allocator.free(utf8); | 892 | defer std.testing.allocator.free(utf8); |
| 893 | try testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf")); | 893 | try testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf")); |
| ... | @@ -895,8 +895,8 @@ test "utf16leToUtf8" { | ... | @@ -895,8 +895,8 @@ test "utf16leToUtf8" { |
| 895 | 895 | ||
| 896 | { | 896 | { |
| 897 | // the values just outside the surrogate half range | 897 | // the values just outside the surrogate half range |
| 898 | mem.writeInt(u16, utf16le_as_bytes[0..2], 0xd7ff, .Little); | 898 | mem.writeInt(u16, utf16le_as_bytes[0..2], 0xd7ff, .little); |
| 899 | mem.writeInt(u16, utf16le_as_bytes[2..4], 0xe000, .Little); | 899 | mem.writeInt(u16, utf16le_as_bytes[2..4], 0xe000, .little); |
| 900 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); | 900 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); |
| 901 | defer std.testing.allocator.free(utf8); | 901 | defer std.testing.allocator.free(utf8); |
| 902 | try testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80")); | 902 | try testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80")); |
| ... | @@ -904,8 +904,8 @@ test "utf16leToUtf8" { | ... | @@ -904,8 +904,8 @@ test "utf16leToUtf8" { |
| 904 | 904 | ||
| 905 | { | 905 | { |
| 906 | // smallest surrogate pair | 906 | // smallest surrogate pair |
| 907 | mem.writeInt(u16, utf16le_as_bytes[0..2], 0xd800, .Little); | 907 | mem.writeInt(u16, utf16le_as_bytes[0..2], 0xd800, .little); |
| 908 | mem.writeInt(u16, utf16le_as_bytes[2..4], 0xdc00, .Little); | 908 | mem.writeInt(u16, utf16le_as_bytes[2..4], 0xdc00, .little); |
| 909 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); | 909 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); |
| 910 | defer std.testing.allocator.free(utf8); | 910 | defer std.testing.allocator.free(utf8); |
| 911 | try testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80")); | 911 | try testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80")); |
| ... | @@ -913,24 +913,24 @@ test "utf16leToUtf8" { | ... | @@ -913,24 +913,24 @@ test "utf16leToUtf8" { |
| 913 | 913 | ||
| 914 | { | 914 | { |
| 915 | // largest surrogate pair | 915 | // largest surrogate pair |
| 916 | mem.writeInt(u16, utf16le_as_bytes[0..2], 0xdbff, .Little); | 916 | mem.writeInt(u16, utf16le_as_bytes[0..2], 0xdbff, .little); |
| 917 | mem.writeInt(u16, utf16le_as_bytes[2..4], 0xdfff, .Little); | 917 | mem.writeInt(u16, utf16le_as_bytes[2..4], 0xdfff, .little); |
| 918 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); | 918 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); |
| 919 | defer std.testing.allocator.free(utf8); | 919 | defer std.testing.allocator.free(utf8); |
| 920 | try testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf")); | 920 | try testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf")); |
| 921 | } | 921 | } |
| 922 | 922 | ||
| 923 | { | 923 | { |
| 924 | mem.writeInt(u16, utf16le_as_bytes[0..2], 0xdbff, .Little); | 924 | mem.writeInt(u16, utf16le_as_bytes[0..2], 0xdbff, .little); |
| 925 | mem.writeInt(u16, utf16le_as_bytes[2..4], 0xdc00, .Little); | 925 | mem.writeInt(u16, utf16le_as_bytes[2..4], 0xdc00, .little); |
| 926 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); | 926 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); |
| 927 | defer std.testing.allocator.free(utf8); | 927 | defer std.testing.allocator.free(utf8); |
| 928 | try testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80")); | 928 | try testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80")); |
| 929 | } | 929 | } |
| 930 | 930 | ||
| 931 | { | 931 | { |
| 932 | mem.writeInt(u16, utf16le_as_bytes[0..2], 0xdcdc, .Little); | 932 | mem.writeInt(u16, utf16le_as_bytes[0..2], 0xdcdc, .little); |
| 933 | mem.writeInt(u16, utf16le_as_bytes[2..4], 0xdcdc, .Little); | 933 | mem.writeInt(u16, utf16le_as_bytes[2..4], 0xdcdc, .little); |
| 934 | const result = utf16leToUtf8Alloc(std.testing.allocator, &utf16le); | 934 | const result = utf16leToUtf8Alloc(std.testing.allocator, &utf16le); |
| 935 | try std.testing.expectError(error.UnexpectedSecondSurrogateHalf, result); | 935 | try std.testing.expectError(error.UnexpectedSecondSurrogateHalf, result); |
| 936 | } | 936 | } |
lib/std/zig/Server.zig+3-3| ... | @@ -279,12 +279,12 @@ fn bswap_u32_array(slice: []u32) void { | ... | @@ -279,12 +279,12 @@ fn bswap_u32_array(slice: []u32) void { |
| 279 | 279 | ||
| 280 | /// workaround for https://github.com/ziglang/zig/issues/14904 | 280 | /// workaround for https://github.com/ziglang/zig/issues/14904 |
| 281 | fn bswap_and_workaround_u32(bytes_ptr: *const [4]u8) u32 { | 281 | fn bswap_and_workaround_u32(bytes_ptr: *const [4]u8) u32 { |
| 282 | return std.mem.readInt(u32, bytes_ptr, .Little); | 282 | return std.mem.readInt(u32, bytes_ptr, .little); |
| 283 | } | 283 | } |
| 284 | 284 | ||
| 285 | /// workaround for https://github.com/ziglang/zig/issues/14904 | 285 | /// workaround for https://github.com/ziglang/zig/issues/14904 |
| 286 | fn bswap_and_workaround_tag(bytes_ptr: *const [4]u8) InMessage.Tag { | 286 | fn bswap_and_workaround_tag(bytes_ptr: *const [4]u8) InMessage.Tag { |
| 287 | const int = std.mem.readInt(u32, bytes_ptr, .Little); | 287 | const int = std.mem.readInt(u32, bytes_ptr, .little); |
| 288 | return @as(InMessage.Tag, @enumFromInt(int)); | 288 | return @as(InMessage.Tag, @enumFromInt(int)); |
| 289 | } | 289 | } |
| 290 | 290 | ||
| ... | @@ -297,4 +297,4 @@ const std = @import("std"); | ... | @@ -297,4 +297,4 @@ const std = @import("std"); |
| 297 | const Allocator = std.mem.Allocator; | 297 | const Allocator = std.mem.Allocator; |
| 298 | const assert = std.debug.assert; | 298 | const assert = std.debug.assert; |
| 299 | const native_endian = builtin.target.cpu.arch.endian(); | 299 | const native_endian = builtin.target.cpu.arch.endian(); |
| 300 | const need_bswap = native_endian != .Little; | 300 | const need_bswap = native_endian != .little; |
lib/std/zig/system/NativeTargetInfo.zig+4-4| ... | @@ -488,8 +488,8 @@ fn glibcVerFromSoFile(file: fs.File) !std.SemanticVersion { | ... | @@ -488,8 +488,8 @@ fn glibcVerFromSoFile(file: fs.File) !std.SemanticVersion { |
| 488 | const hdr64 = @as(*elf.Elf64_Ehdr, @ptrCast(&hdr_buf)); | 488 | const hdr64 = @as(*elf.Elf64_Ehdr, @ptrCast(&hdr_buf)); |
| 489 | if (!mem.eql(u8, hdr32.e_ident[0..4], elf.MAGIC)) return error.InvalidElfMagic; | 489 | if (!mem.eql(u8, hdr32.e_ident[0..4], elf.MAGIC)) return error.InvalidElfMagic; |
| 490 | const elf_endian: std.builtin.Endian = switch (hdr32.e_ident[elf.EI_DATA]) { | 490 | const elf_endian: std.builtin.Endian = switch (hdr32.e_ident[elf.EI_DATA]) { |
| 491 | elf.ELFDATA2LSB => .Little, | 491 | elf.ELFDATA2LSB => .little, |
| 492 | elf.ELFDATA2MSB => .Big, | 492 | elf.ELFDATA2MSB => .big, |
| 493 | else => return error.InvalidElfEndian, | 493 | else => return error.InvalidElfEndian, |
| 494 | }; | 494 | }; |
| 495 | const need_bswap = elf_endian != native_endian; | 495 | const need_bswap = elf_endian != native_endian; |
| ... | @@ -635,8 +635,8 @@ pub fn abiAndDynamicLinkerFromFile( | ... | @@ -635,8 +635,8 @@ pub fn abiAndDynamicLinkerFromFile( |
| 635 | const hdr64 = @as(*elf.Elf64_Ehdr, @ptrCast(&hdr_buf)); | 635 | const hdr64 = @as(*elf.Elf64_Ehdr, @ptrCast(&hdr_buf)); |
| 636 | if (!mem.eql(u8, hdr32.e_ident[0..4], elf.MAGIC)) return error.InvalidElfMagic; | 636 | if (!mem.eql(u8, hdr32.e_ident[0..4], elf.MAGIC)) return error.InvalidElfMagic; |
| 637 | const elf_endian: std.builtin.Endian = switch (hdr32.e_ident[elf.EI_DATA]) { | 637 | const elf_endian: std.builtin.Endian = switch (hdr32.e_ident[elf.EI_DATA]) { |
| 638 | elf.ELFDATA2LSB => .Little, | 638 | elf.ELFDATA2LSB => .little, |
| 639 | elf.ELFDATA2MSB => .Big, | 639 | elf.ELFDATA2MSB => .big, |
| 640 | else => return error.InvalidElfEndian, | 640 | else => return error.InvalidElfEndian, |
| 641 | }; | 641 | }; |
| 642 | const need_bswap = elf_endian != native_endian; | 642 | const need_bswap = elf_endian != native_endian; |
src/Package/Fetch/git.zig+12-12| ... | @@ -305,12 +305,12 @@ const Odb = struct { | ... | @@ -305,12 +305,12 @@ const Odb = struct { |
| 305 | const n_objects = odb.index_header.fan_out_table[255]; | 305 | const n_objects = odb.index_header.fan_out_table[255]; |
| 306 | const offset_values_start = IndexHeader.size + n_objects * (oid_length + 4); | 306 | const offset_values_start = IndexHeader.size + n_objects * (oid_length + 4); |
| 307 | try odb.index_file.seekTo(offset_values_start + found_index * 4); | 307 | try odb.index_file.seekTo(offset_values_start + found_index * 4); |
| 308 | const l1_offset: packed struct { value: u31, big: bool } = @bitCast(try odb.index_file.reader().readInt(u32, .Big)); | 308 | const l1_offset: packed struct { value: u31, big: bool } = @bitCast(try odb.index_file.reader().readInt(u32, .big)); |
| 309 | const pack_offset = pack_offset: { | 309 | const pack_offset = pack_offset: { |
| 310 | if (l1_offset.big) { | 310 | if (l1_offset.big) { |
| 311 | const l2_offset_values_start = offset_values_start + n_objects * 4; | 311 | const l2_offset_values_start = offset_values_start + n_objects * 4; |
| 312 | try odb.index_file.seekTo(l2_offset_values_start + l1_offset.value * 4); | 312 | try odb.index_file.seekTo(l2_offset_values_start + l1_offset.value * 4); |
| 313 | break :pack_offset try odb.index_file.reader().readInt(u64, .Big); | 313 | break :pack_offset try odb.index_file.reader().readInt(u64, .big); |
| 314 | } else { | 314 | } else { |
| 315 | break :pack_offset l1_offset.value; | 315 | break :pack_offset l1_offset.value; |
| 316 | } | 316 | } |
| ... | @@ -845,12 +845,12 @@ const PackHeader = struct { | ... | @@ -845,12 +845,12 @@ const PackHeader = struct { |
| 845 | else => |other| return other, | 845 | else => |other| return other, |
| 846 | }; | 846 | }; |
| 847 | if (!mem.eql(u8, &actual_signature, signature)) return error.InvalidHeader; | 847 | if (!mem.eql(u8, &actual_signature, signature)) return error.InvalidHeader; |
| 848 | const version = reader.readInt(u32, .Big) catch |e| switch (e) { | 848 | const version = reader.readInt(u32, .big) catch |e| switch (e) { |
| 849 | error.EndOfStream => return error.InvalidHeader, | 849 | error.EndOfStream => return error.InvalidHeader, |
| 850 | else => |other| return other, | 850 | else => |other| return other, |
| 851 | }; | 851 | }; |
| 852 | if (version != supported_version) return error.UnsupportedVersion; | 852 | if (version != supported_version) return error.UnsupportedVersion; |
| 853 | const total_objects = reader.readInt(u32, .Big) catch |e| switch (e) { | 853 | const total_objects = reader.readInt(u32, .big) catch |e| switch (e) { |
| 854 | error.EndOfStream => return error.InvalidHeader, | 854 | error.EndOfStream => return error.InvalidHeader, |
| 855 | else => |other| return other, | 855 | else => |other| return other, |
| 856 | }; | 856 | }; |
| ... | @@ -966,14 +966,14 @@ const IndexHeader = struct { | ... | @@ -966,14 +966,14 @@ const IndexHeader = struct { |
| 966 | fn read(reader: anytype) !IndexHeader { | 966 | fn read(reader: anytype) !IndexHeader { |
| 967 | var header_bytes = try reader.readBytesNoEof(size); | 967 | var header_bytes = try reader.readBytesNoEof(size); |
| 968 | if (!mem.eql(u8, header_bytes[0..4], signature)) return error.InvalidHeader; | 968 | if (!mem.eql(u8, header_bytes[0..4], signature)) return error.InvalidHeader; |
| 969 | const version = mem.readInt(u32, header_bytes[4..8], .Big); | 969 | const version = mem.readInt(u32, header_bytes[4..8], .big); |
| 970 | if (version != supported_version) return error.UnsupportedVersion; | 970 | if (version != supported_version) return error.UnsupportedVersion; |
| 971 | 971 | ||
| 972 | var fan_out_table: [256]u32 = undefined; | 972 | var fan_out_table: [256]u32 = undefined; |
| 973 | var fan_out_table_stream = std.io.fixedBufferStream(header_bytes[8..]); | 973 | var fan_out_table_stream = std.io.fixedBufferStream(header_bytes[8..]); |
| 974 | const fan_out_table_reader = fan_out_table_stream.reader(); | 974 | const fan_out_table_reader = fan_out_table_stream.reader(); |
| 975 | for (&fan_out_table) |*entry| { | 975 | for (&fan_out_table) |*entry| { |
| 976 | entry.* = fan_out_table_reader.readInt(u32, .Big) catch unreachable; | 976 | entry.* = fan_out_table_reader.readInt(u32, .big) catch unreachable; |
| 977 | } | 977 | } |
| 978 | return .{ .fan_out_table = fan_out_table }; | 978 | return .{ .fan_out_table = fan_out_table }; |
| 979 | } | 979 | } |
| ... | @@ -1041,9 +1041,9 @@ pub fn indexPack(allocator: Allocator, pack: std.fs.File, index_writer: anytype) | ... | @@ -1041,9 +1041,9 @@ pub fn indexPack(allocator: Allocator, pack: std.fs.File, index_writer: anytype) |
| 1041 | var index_hashed_writer = hashedWriter(index_writer, Sha1.init(.{})); | 1041 | var index_hashed_writer = hashedWriter(index_writer, Sha1.init(.{})); |
| 1042 | const writer = index_hashed_writer.writer(); | 1042 | const writer = index_hashed_writer.writer(); |
| 1043 | try writer.writeAll(IndexHeader.signature); | 1043 | try writer.writeAll(IndexHeader.signature); |
| 1044 | try writer.writeInt(u32, IndexHeader.supported_version, .Big); | 1044 | try writer.writeInt(u32, IndexHeader.supported_version, .big); |
| 1045 | for (fan_out_table) |fan_out_entry| { | 1045 | for (fan_out_table) |fan_out_entry| { |
| 1046 | try writer.writeInt(u32, fan_out_entry, .Big); | 1046 | try writer.writeInt(u32, fan_out_entry, .big); |
| 1047 | } | 1047 | } |
| 1048 | 1048 | ||
| 1049 | for (oids.items) |oid| { | 1049 | for (oids.items) |oid| { |
| ... | @@ -1051,7 +1051,7 @@ pub fn indexPack(allocator: Allocator, pack: std.fs.File, index_writer: anytype) | ... | @@ -1051,7 +1051,7 @@ pub fn indexPack(allocator: Allocator, pack: std.fs.File, index_writer: anytype) |
| 1051 | } | 1051 | } |
| 1052 | 1052 | ||
| 1053 | for (oids.items) |oid| { | 1053 | for (oids.items) |oid| { |
| 1054 | try writer.writeInt(u32, index_entries.get(oid).?.crc32, .Big); | 1054 | try writer.writeInt(u32, index_entries.get(oid).?.crc32, .big); |
| 1055 | } | 1055 | } |
| 1056 | 1056 | ||
| 1057 | var big_offsets = std.ArrayListUnmanaged(u64){}; | 1057 | var big_offsets = std.ArrayListUnmanaged(u64){}; |
| ... | @@ -1059,15 +1059,15 @@ pub fn indexPack(allocator: Allocator, pack: std.fs.File, index_writer: anytype) | ... | @@ -1059,15 +1059,15 @@ pub fn indexPack(allocator: Allocator, pack: std.fs.File, index_writer: anytype) |
| 1059 | for (oids.items) |oid| { | 1059 | for (oids.items) |oid| { |
| 1060 | const offset = index_entries.get(oid).?.offset; | 1060 | const offset = index_entries.get(oid).?.offset; |
| 1061 | if (offset <= std.math.maxInt(u31)) { | 1061 | if (offset <= std.math.maxInt(u31)) { |
| 1062 | try writer.writeInt(u32, @intCast(offset), .Big); | 1062 | try writer.writeInt(u32, @intCast(offset), .big); |
| 1063 | } else { | 1063 | } else { |
| 1064 | const index = big_offsets.items.len; | 1064 | const index = big_offsets.items.len; |
| 1065 | try big_offsets.append(allocator, offset); | 1065 | try big_offsets.append(allocator, offset); |
| 1066 | try writer.writeInt(u32, @as(u32, @intCast(index)) | (1 << 31), .Big); | 1066 | try writer.writeInt(u32, @as(u32, @intCast(index)) | (1 << 31), .big); |
| 1067 | } | 1067 | } |
| 1068 | } | 1068 | } |
| 1069 | for (big_offsets.items) |offset| { | 1069 | for (big_offsets.items) |offset| { |
| 1070 | try writer.writeInt(u64, offset, .Big); | 1070 | try writer.writeInt(u64, offset, .big); |
| 1071 | } | 1071 | } |
| 1072 | 1072 | ||
| 1073 | try writer.writeAll(&pack_checksum); | 1073 | try writer.writeAll(&pack_checksum); |
src/Sema.zig+4-4| ... | @@ -26835,7 +26835,7 @@ fn structFieldPtrByIndex( | ... | @@ -26835,7 +26835,7 @@ fn structFieldPtrByIndex( |
| 26835 | // cause miscompilations; it only means the field pointer uses bit masking when it | 26835 | // cause miscompilations; it only means the field pointer uses bit masking when it |
| 26836 | // might not be strictly necessary. | 26836 | // might not be strictly necessary. |
| 26837 | if (parent_align != .none and ptr_ty_data.packed_offset.bit_offset % 8 == 0 and | 26837 | if (parent_align != .none and ptr_ty_data.packed_offset.bit_offset % 8 == 0 and |
| 26838 | target.cpu.arch.endian() == .Little) | 26838 | target.cpu.arch.endian() == .little) |
| 26839 | { | 26839 | { |
| 26840 | const elem_size_bytes = try sema.typeAbiSize(ptr_ty_data.child.toType()); | 26840 | const elem_size_bytes = try sema.typeAbiSize(ptr_ty_data.child.toType()); |
| 26841 | const elem_size_bits = ptr_ty_data.child.toType().bitSize(mod); | 26841 | const elem_size_bits = ptr_ty_data.child.toType().bitSize(mod); |
| ... | @@ -30736,8 +30736,8 @@ fn bitCastUnionFieldVal( | ... | @@ -30736,8 +30736,8 @@ fn bitCastUnionFieldVal( |
| 30736 | if (field_size > old_size) { | 30736 | if (field_size > old_size) { |
| 30737 | const min_size = @max(old_size, 1); | 30737 | const min_size = @max(old_size, 1); |
| 30738 | switch (endian) { | 30738 | switch (endian) { |
| 30739 | .Little => @memset(buffer[min_size - 1 ..], 0xaa), | 30739 | .little => @memset(buffer[min_size - 1 ..], 0xaa), |
| 30740 | .Big => @memset(buffer[0 .. buffer.len - min_size + 1], 0xaa), | 30740 | .big => @memset(buffer[0 .. buffer.len - min_size + 1], 0xaa), |
| 30741 | } | 30741 | } |
| 30742 | } | 30742 | } |
| 30743 | 30743 | ||
| ... | @@ -30746,7 +30746,7 @@ fn bitCastUnionFieldVal( | ... | @@ -30746,7 +30746,7 @@ fn bitCastUnionFieldVal( |
| 30746 | error.ReinterpretDeclRef => return null, | 30746 | error.ReinterpretDeclRef => return null, |
| 30747 | }; | 30747 | }; |
| 30748 | 30748 | ||
| 30749 | break :offset if (endian == .Big) buffer.len - field_size else 0; | 30749 | break :offset if (endian == .big) buffer.len - field_size else 0; |
| 30750 | }, | 30750 | }, |
| 30751 | .Auto => unreachable, | 30751 | .Auto => unreachable, |
| 30752 | }; | 30752 | }; |
src/arch/sparc64/CodeGen.zig+2-2| ... | @@ -1231,8 +1231,8 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -1231,8 +1231,8 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void { |
| 1231 | const abi_size = int_info.bits >> 3; | 1231 | const abi_size = int_info.bits >> 3; |
| 1232 | const abi_align = operand_ty.abiAlignment(mod); | 1232 | const abi_align = operand_ty.abiAlignment(mod); |
| 1233 | const opposite_endian_asi = switch (self.target.cpu.arch.endian()) { | 1233 | const opposite_endian_asi = switch (self.target.cpu.arch.endian()) { |
| 1234 | Endian.Big => ASI.asi_primary_little, | 1234 | Endian.big => ASI.asi_primary_little, |
| 1235 | Endian.Little => ASI.asi_primary, | 1235 | Endian.little => ASI.asi_primary, |
| 1236 | }; | 1236 | }; |
| 1237 | 1237 | ||
| 1238 | switch (operand) { | 1238 | switch (operand) { |
src/arch/sparc64/Emit.zig+1-1| ... | @@ -677,7 +677,7 @@ fn writeInstruction(emit: *Emit, instruction: Instruction) !void { | ... | @@ -677,7 +677,7 @@ fn writeInstruction(emit: *Emit, instruction: Instruction) !void { |
| 677 | // SPARCv9 instructions are always arranged in BE regardless of the | 677 | // SPARCv9 instructions are always arranged in BE regardless of the |
| 678 | // endianness mode the CPU is running in (Section 3.1 of the ISA specification). | 678 | // endianness mode the CPU is running in (Section 3.1 of the ISA specification). |
| 679 | // This is to ease porting in case someone wants to do a LE SPARCv9 backend. | 679 | // This is to ease porting in case someone wants to do a LE SPARCv9 backend. |
| 680 | const endian = Endian.Big; | 680 | const endian = Endian.big; |
| 681 | 681 | ||
| 682 | std.mem.writeInt(u32, try emit.code.addManyAsArray(4), instruction.toU32(), endian); | 682 | std.mem.writeInt(u32, try emit.code.addManyAsArray(4), instruction.toU32(), endian); |
| 683 | } | 683 | } |
src/arch/wasm/CodeGen.zig+1-1| ... | @@ -3364,7 +3364,7 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue { | ... | @@ -3364,7 +3364,7 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue { |
| 3364 | const backing_int_ty = struct_type.backingIntType(ip).toType(); | 3364 | const backing_int_ty = struct_type.backingIntType(ip).toType(); |
| 3365 | const int_val = try mod.intValue( | 3365 | const int_val = try mod.intValue( |
| 3366 | backing_int_ty, | 3366 | backing_int_ty, |
| 3367 | mem.readInt(u64, &buf, .Little), | 3367 | mem.readInt(u64, &buf, .little), |
| 3368 | ); | 3368 | ); |
| 3369 | return func.lowerConstant(int_val, backing_int_ty); | 3369 | return func.lowerConstant(int_val, backing_int_ty); |
| 3370 | }, | 3370 | }, |
src/arch/wasm/Emit.zig+2-2| ... | @@ -330,14 +330,14 @@ fn emitImm64(emit: *Emit, inst: Mir.Inst.Index) !void { | ... | @@ -330,14 +330,14 @@ fn emitImm64(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 330 | fn emitFloat32(emit: *Emit, inst: Mir.Inst.Index) !void { | 330 | fn emitFloat32(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 331 | const value: f32 = emit.mir.instructions.items(.data)[inst].float32; | 331 | const value: f32 = emit.mir.instructions.items(.data)[inst].float32; |
| 332 | try emit.code.append(std.wasm.opcode(.f32_const)); | 332 | try emit.code.append(std.wasm.opcode(.f32_const)); |
| 333 | try emit.code.writer().writeInt(u32, @bitCast(value), .Little); | 333 | try emit.code.writer().writeInt(u32, @bitCast(value), .little); |
| 334 | } | 334 | } |
| 335 | 335 | ||
| 336 | fn emitFloat64(emit: *Emit, inst: Mir.Inst.Index) !void { | 336 | fn emitFloat64(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 337 | const extra_index = emit.mir.instructions.items(.data)[inst].payload; | 337 | const extra_index = emit.mir.instructions.items(.data)[inst].payload; |
| 338 | const value = emit.mir.extraData(Mir.Float64, extra_index); | 338 | const value = emit.mir.extraData(Mir.Float64, extra_index); |
| 339 | try emit.code.append(std.wasm.opcode(.f64_const)); | 339 | try emit.code.append(std.wasm.opcode(.f64_const)); |
| 340 | try emit.code.writer().writeInt(u64, value.data.toU64(), .Little); | 340 | try emit.code.writer().writeInt(u64, value.data.toU64(), .little); |
| 341 | } | 341 | } |
| 342 | 342 | ||
| 343 | fn emitMemArg(emit: *Emit, tag: Mir.Inst.Tag, inst: Mir.Inst.Index) !void { | 343 | fn emitMemArg(emit: *Emit, tag: Mir.Inst.Tag, inst: Mir.Inst.Index) !void { |
src/arch/x86_64/Disassembler.zig+12-12| ... | @@ -360,13 +360,13 @@ fn parseImm(dis: *Disassembler, kind: Encoding.Op) !Immediate { | ... | @@ -360,13 +360,13 @@ fn parseImm(dis: *Disassembler, kind: Encoding.Op) !Immediate { |
| 360 | var creader = std.io.countingReader(stream.reader()); | 360 | var creader = std.io.countingReader(stream.reader()); |
| 361 | const reader = creader.reader(); | 361 | const reader = creader.reader(); |
| 362 | const imm = switch (kind) { | 362 | const imm = switch (kind) { |
| 363 | .imm8s, .rel8 => Immediate.s(try reader.readInt(i8, .Little)), | 363 | .imm8s, .rel8 => Immediate.s(try reader.readInt(i8, .little)), |
| 364 | .imm16s, .rel16 => Immediate.s(try reader.readInt(i16, .Little)), | 364 | .imm16s, .rel16 => Immediate.s(try reader.readInt(i16, .little)), |
| 365 | .imm32s, .rel32 => Immediate.s(try reader.readInt(i32, .Little)), | 365 | .imm32s, .rel32 => Immediate.s(try reader.readInt(i32, .little)), |
| 366 | .imm8 => Immediate.u(try reader.readInt(u8, .Little)), | 366 | .imm8 => Immediate.u(try reader.readInt(u8, .little)), |
| 367 | .imm16 => Immediate.u(try reader.readInt(u16, .Little)), | 367 | .imm16 => Immediate.u(try reader.readInt(u16, .little)), |
| 368 | .imm32 => Immediate.u(try reader.readInt(u32, .Little)), | 368 | .imm32 => Immediate.u(try reader.readInt(u32, .little)), |
| 369 | .imm64 => Immediate.u(try reader.readInt(u64, .Little)), | 369 | .imm64 => Immediate.u(try reader.readInt(u64, .little)), |
| 370 | else => unreachable, | 370 | else => unreachable, |
| 371 | }; | 371 | }; |
| 372 | dis.pos += std.math.cast(usize, creader.bytes_read) orelse return error.Overflow; | 372 | dis.pos += std.math.cast(usize, creader.bytes_read) orelse return error.Overflow; |
| ... | @@ -376,7 +376,7 @@ fn parseImm(dis: *Disassembler, kind: Encoding.Op) !Immediate { | ... | @@ -376,7 +376,7 @@ fn parseImm(dis: *Disassembler, kind: Encoding.Op) !Immediate { |
| 376 | fn parseOffset(dis: *Disassembler) !u64 { | 376 | fn parseOffset(dis: *Disassembler) !u64 { |
| 377 | var stream = std.io.fixedBufferStream(dis.code[dis.pos..]); | 377 | var stream = std.io.fixedBufferStream(dis.code[dis.pos..]); |
| 378 | const reader = stream.reader(); | 378 | const reader = stream.reader(); |
| 379 | const offset = try reader.readInt(u64, .Little); | 379 | const offset = try reader.readInt(u64, .little); |
| 380 | dis.pos += 8; | 380 | dis.pos += 8; |
| 381 | return offset; | 381 | return offset; |
| 382 | } | 382 | } |
| ... | @@ -457,16 +457,16 @@ fn parseDisplacement(dis: *Disassembler, modrm: ModRm, sib: ?Sib) !i32 { | ... | @@ -457,16 +457,16 @@ fn parseDisplacement(dis: *Disassembler, modrm: ModRm, sib: ?Sib) !i32 { |
| 457 | const disp = disp: { | 457 | const disp = disp: { |
| 458 | if (sib) |info| { | 458 | if (sib) |info| { |
| 459 | if (info.base == 0b101 and modrm.mod == 0) { | 459 | if (info.base == 0b101 and modrm.mod == 0) { |
| 460 | break :disp try reader.readInt(i32, .Little); | 460 | break :disp try reader.readInt(i32, .little); |
| 461 | } | 461 | } |
| 462 | } | 462 | } |
| 463 | if (modrm.rip()) { | 463 | if (modrm.rip()) { |
| 464 | break :disp try reader.readInt(i32, .Little); | 464 | break :disp try reader.readInt(i32, .little); |
| 465 | } | 465 | } |
| 466 | break :disp switch (modrm.mod) { | 466 | break :disp switch (modrm.mod) { |
| 467 | 0b00 => 0, | 467 | 0b00 => 0, |
| 468 | 0b01 => try reader.readInt(i8, .Little), | 468 | 0b01 => try reader.readInt(i8, .little), |
| 469 | 0b10 => try reader.readInt(i32, .Little), | 469 | 0b10 => try reader.readInt(i32, .little), |
| 470 | 0b11 => unreachable, | 470 | 0b11 => unreachable, |
| 471 | }; | 471 | }; |
| 472 | }; | 472 | }; |
src/arch/x86_64/Emit.zig+1-1| ... | @@ -253,7 +253,7 @@ fn fixupRelocs(emit: *Emit) Error!void { | ... | @@ -253,7 +253,7 @@ fn fixupRelocs(emit: *Emit) Error!void { |
| 253 | const target = emit.code_offset_mapping.get(reloc.target) orelse | 253 | const target = emit.code_offset_mapping.get(reloc.target) orelse |
| 254 | return emit.fail("JMP/CALL relocation target not found!", .{}); | 254 | return emit.fail("JMP/CALL relocation target not found!", .{}); |
| 255 | const disp = @as(i32, @intCast(@as(i64, @intCast(target)) - @as(i64, @intCast(reloc.source + reloc.length)))); | 255 | const disp = @as(i32, @intCast(@as(i64, @intCast(target)) - @as(i64, @intCast(reloc.source + reloc.length)))); |
| 256 | mem.writeInt(i32, emit.code.items[reloc.offset..][0..4], disp, .Little); | 256 | mem.writeInt(i32, emit.code.items[reloc.offset..][0..4], disp, .little); |
| 257 | } | 257 | } |
| 258 | } | 258 | } |
| 259 | 259 |
src/arch/x86_64/encoder.zig+4-4| ... | @@ -998,7 +998,7 @@ fn Encoder(comptime T: type, comptime opts: Options) type { | ... | @@ -998,7 +998,7 @@ fn Encoder(comptime T: type, comptime opts: Options) type { |
| 998 | /// | 998 | /// |
| 999 | /// It is sign-extended to 64 bits by the cpu. | 999 | /// It is sign-extended to 64 bits by the cpu. |
| 1000 | pub fn disp32(self: Self, disp: i32) !void { | 1000 | pub fn disp32(self: Self, disp: i32) !void { |
| 1001 | try self.writer.writeInt(i32, disp, .Little); | 1001 | try self.writer.writeInt(i32, disp, .little); |
| 1002 | } | 1002 | } |
| 1003 | 1003 | ||
| 1004 | /// Encode an 8 bit immediate | 1004 | /// Encode an 8 bit immediate |
| ... | @@ -1012,21 +1012,21 @@ fn Encoder(comptime T: type, comptime opts: Options) type { | ... | @@ -1012,21 +1012,21 @@ fn Encoder(comptime T: type, comptime opts: Options) type { |
| 1012 | /// | 1012 | /// |
| 1013 | /// It is sign-extended to 64 bits by the cpu. | 1013 | /// It is sign-extended to 64 bits by the cpu. |
| 1014 | pub fn imm16(self: Self, imm: u16) !void { | 1014 | pub fn imm16(self: Self, imm: u16) !void { |
| 1015 | try self.writer.writeInt(u16, imm, .Little); | 1015 | try self.writer.writeInt(u16, imm, .little); |
| 1016 | } | 1016 | } |
| 1017 | 1017 | ||
| 1018 | /// Encode an 32 bit immediate | 1018 | /// Encode an 32 bit immediate |
| 1019 | /// | 1019 | /// |
| 1020 | /// It is sign-extended to 64 bits by the cpu. | 1020 | /// It is sign-extended to 64 bits by the cpu. |
| 1021 | pub fn imm32(self: Self, imm: u32) !void { | 1021 | pub fn imm32(self: Self, imm: u32) !void { |
| 1022 | try self.writer.writeInt(u32, imm, .Little); | 1022 | try self.writer.writeInt(u32, imm, .little); |
| 1023 | } | 1023 | } |
| 1024 | 1024 | ||
| 1025 | /// Encode an 64 bit immediate | 1025 | /// Encode an 64 bit immediate |
| 1026 | /// | 1026 | /// |
| 1027 | /// It is sign-extended to 64 bits by the cpu. | 1027 | /// It is sign-extended to 64 bits by the cpu. |
| 1028 | pub fn imm64(self: Self, imm: u64) !void { | 1028 | pub fn imm64(self: Self, imm: u64) !void { |
| 1029 | try self.writer.writeInt(u64, imm, .Little); | 1029 | try self.writer.writeInt(u64, imm, .little); |
| 1030 | } | 1030 | } |
| 1031 | }; | 1031 | }; |
| 1032 | } | 1032 | } |
src/codegen/c.zig+8-8| ... | @@ -4666,8 +4666,8 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca | ... | @@ -4666,8 +4666,8 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca |
| 4666 | try f.writeCValue(writer, local, .Other); | 4666 | try f.writeCValue(writer, local, .Other); |
| 4667 | if (dest_cty.castTag(.array)) |pl| { | 4667 | if (dest_cty.castTag(.array)) |pl| { |
| 4668 | try writer.print("[{d}]", .{switch (target.cpu.arch.endian()) { | 4668 | try writer.print("[{d}]", .{switch (target.cpu.arch.endian()) { |
| 4669 | .Little => pl.data.len - 1, | 4669 | .little => pl.data.len - 1, |
| 4670 | .Big => 0, | 4670 | .big => 0, |
| 4671 | }}); | 4671 | }}); |
| 4672 | const elem_cty = f.indexToCType(pl.data.elem_type); | 4672 | const elem_cty = f.indexToCType(pl.data.elem_type); |
| 4673 | wrap_cty = elem_cty.toSignedness(dest_info.signedness); | 4673 | wrap_cty = elem_cty.toSignedness(dest_info.signedness); |
| ... | @@ -4697,8 +4697,8 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca | ... | @@ -4697,8 +4697,8 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca |
| 4697 | try f.writeCValue(writer, local, .Other); | 4697 | try f.writeCValue(writer, local, .Other); |
| 4698 | if (dest_cty.castTag(.array)) |pl| { | 4698 | if (dest_cty.castTag(.array)) |pl| { |
| 4699 | try writer.print("[{d}]", .{switch (target.cpu.arch.endian()) { | 4699 | try writer.print("[{d}]", .{switch (target.cpu.arch.endian()) { |
| 4700 | .Little => pl.data.len - 1, | 4700 | .little => pl.data.len - 1, |
| 4701 | .Big => 0, | 4701 | .big => 0, |
| 4702 | }}); | 4702 | }}); |
| 4703 | } | 4703 | } |
| 4704 | if (need_bitcasts) try writer.writeByte(')'); | 4704 | if (need_bitcasts) try writer.writeByte(')'); |
| ... | @@ -7652,13 +7652,13 @@ fn formatIntLiteral( | ... | @@ -7652,13 +7652,13 @@ fn formatIntLiteral( |
| 7652 | else => .{ | 7652 | else => .{ |
| 7653 | .cty = CType.initTag(.void), | 7653 | .cty = CType.initTag(.void), |
| 7654 | .count = 1, | 7654 | .count = 1, |
| 7655 | .endian = .Little, | 7655 | .endian = .little, |
| 7656 | .homogeneous = true, | 7656 | .homogeneous = true, |
| 7657 | }, | 7657 | }, |
| 7658 | .zig_u128, .zig_i128 => .{ | 7658 | .zig_u128, .zig_i128 => .{ |
| 7659 | .cty = CType.initTag(.uint64_t), | 7659 | .cty = CType.initTag(.uint64_t), |
| 7660 | .count = 2, | 7660 | .count = 2, |
| 7661 | .endian = .Big, | 7661 | .endian = .big, |
| 7662 | .homogeneous = false, | 7662 | .homogeneous = false, |
| 7663 | }, | 7663 | }, |
| 7664 | .array => info: { | 7664 | .array => info: { |
| ... | @@ -7729,8 +7729,8 @@ fn formatIntLiteral( | ... | @@ -7729,8 +7729,8 @@ fn formatIntLiteral( |
| 7729 | const most_significant_limb_i = wrap.len - limbs_per_c_limb; | 7729 | const most_significant_limb_i = wrap.len - limbs_per_c_limb; |
| 7730 | while (limb_offset < wrap.len) : (limb_offset += limbs_per_c_limb) { | 7730 | while (limb_offset < wrap.len) : (limb_offset += limbs_per_c_limb) { |
| 7731 | const limb_i = switch (c_limb_info.endian) { | 7731 | const limb_i = switch (c_limb_info.endian) { |
| 7732 | .Little => limb_offset, | 7732 | .little => limb_offset, |
| 7733 | .Big => most_significant_limb_i - limb_offset, | 7733 | .big => most_significant_limb_i - limb_offset, |
| 7734 | }; | 7734 | }; |
| 7735 | var c_limb_mut = BigInt.Mutable{ | 7735 | var c_limb_mut = BigInt.Mutable{ |
| 7736 | .limbs = wrap.limbs[limb_i..][0..limbs_per_c_limb], | 7736 | .limbs = wrap.limbs[limb_i..][0..limbs_per_c_limb], |
src/codegen/llvm.zig+3-3| ... | @@ -342,8 +342,8 @@ const DataLayoutBuilder = struct { | ... | @@ -342,8 +342,8 @@ const DataLayoutBuilder = struct { |
| 342 | writer: anytype, | 342 | writer: anytype, |
| 343 | ) @TypeOf(writer).Error!void { | 343 | ) @TypeOf(writer).Error!void { |
| 344 | try writer.writeByte(switch (self.target.cpu.arch.endian()) { | 344 | try writer.writeByte(switch (self.target.cpu.arch.endian()) { |
| 345 | .Little => 'e', | 345 | .little => 'e', |
| 346 | .Big => 'E', | 346 | .big => 'E', |
| 347 | }); | 347 | }); |
| 348 | switch (self.target.cpu.arch) { | 348 | switch (self.target.cpu.arch) { |
| 349 | .amdgcn, | 349 | .amdgcn, |
| ... | @@ -10453,7 +10453,7 @@ pub const FuncGen = struct { | ... | @@ -10453,7 +10453,7 @@ pub const FuncGen = struct { |
| 10453 | else | 10453 | else |
| 10454 | payload_llvm_ty; | 10454 | payload_llvm_ty; |
| 10455 | const loaded = try fg.wip.load(access_kind, load_llvm_ty, payload_ptr, payload_alignment, ""); | 10455 | const loaded = try fg.wip.load(access_kind, load_llvm_ty, payload_ptr, payload_alignment, ""); |
| 10456 | const shifted = if (payload_llvm_ty != load_llvm_ty and o.target.cpu.arch.endian() == .Big) | 10456 | const shifted = if (payload_llvm_ty != load_llvm_ty and o.target.cpu.arch.endian() == .big) |
| 10457 | try fg.wip.bin(.lshr, loaded, try o.builder.intValue( | 10457 | try fg.wip.bin(.lshr, loaded, try o.builder.intValue( |
| 10458 | load_llvm_ty, | 10458 | load_llvm_ty, |
| 10459 | (payload_ty.abiSize(mod) - (std.math.divCeil(u64, payload_ty.bitSize(mod), 8) catch unreachable)) * 8, | 10459 | (payload_ty.abiSize(mod) - (std.math.divCeil(u64, payload_ty.bitSize(mod), 8) catch unreachable)) * 8, |
src/glibc.zig+5-5| ... | @@ -751,7 +751,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo | ... | @@ -751,7 +751,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo |
| 751 | 751 | ||
| 752 | var inc_i: usize = 0; | 752 | var inc_i: usize = 0; |
| 753 | 753 | ||
| 754 | const fn_inclusions_len = mem.readInt(u16, metadata.inclusions[inc_i..][0..2], .Little); | 754 | const fn_inclusions_len = mem.readInt(u16, metadata.inclusions[inc_i..][0..2], .little); |
| 755 | inc_i += 2; | 755 | inc_i += 2; |
| 756 | 756 | ||
| 757 | var sym_i: usize = 0; | 757 | var sym_i: usize = 0; |
| ... | @@ -768,7 +768,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo | ... | @@ -768,7 +768,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo |
| 768 | versions_len = 0; | 768 | versions_len = 0; |
| 769 | break :n name; | 769 | break :n name; |
| 770 | }; | 770 | }; |
| 771 | const targets = mem.readInt(u32, metadata.inclusions[inc_i..][0..4], .Little); | 771 | const targets = mem.readInt(u32, metadata.inclusions[inc_i..][0..4], .little); |
| 772 | inc_i += 4; | 772 | inc_i += 4; |
| 773 | 773 | ||
| 774 | const lib_index = metadata.inclusions[inc_i]; | 774 | const lib_index = metadata.inclusions[inc_i]; |
| ... | @@ -882,7 +882,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo | ... | @@ -882,7 +882,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo |
| 882 | 882 | ||
| 883 | try stubs_asm.appendSlice(".data\n"); | 883 | try stubs_asm.appendSlice(".data\n"); |
| 884 | 884 | ||
| 885 | const obj_inclusions_len = mem.readInt(u16, metadata.inclusions[inc_i..][0..2], .Little); | 885 | const obj_inclusions_len = mem.readInt(u16, metadata.inclusions[inc_i..][0..2], .little); |
| 886 | inc_i += 2; | 886 | inc_i += 2; |
| 887 | 887 | ||
| 888 | sym_i = 0; | 888 | sym_i = 0; |
| ... | @@ -899,10 +899,10 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo | ... | @@ -899,10 +899,10 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo |
| 899 | versions_len = 0; | 899 | versions_len = 0; |
| 900 | break :n name; | 900 | break :n name; |
| 901 | }; | 901 | }; |
| 902 | const targets = mem.readInt(u32, metadata.inclusions[inc_i..][0..4], .Little); | 902 | const targets = mem.readInt(u32, metadata.inclusions[inc_i..][0..4], .little); |
| 903 | inc_i += 4; | 903 | inc_i += 4; |
| 904 | 904 | ||
| 905 | const size = mem.readInt(u16, metadata.inclusions[inc_i..][0..2], .Little); | 905 | const size = mem.readInt(u16, metadata.inclusions[inc_i..][0..2], .little); |
| 906 | inc_i += 2; | 906 | inc_i += 2; |
| 907 | 907 | ||
| 908 | const lib_index = metadata.inclusions[inc_i]; | 908 | const lib_index = metadata.inclusions[inc_i]; |
src/link/Coff.zig+9-9| ... | @@ -856,12 +856,12 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void { | ... | @@ -856,12 +856,12 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void { |
| 856 | switch (self.ptr_width) { | 856 | switch (self.ptr_width) { |
| 857 | .p32 => { | 857 | .p32 => { |
| 858 | var buf: [4]u8 = undefined; | 858 | var buf: [4]u8 = undefined; |
| 859 | mem.writeInt(u32, &buf, @as(u32, @intCast(entry_value + self.getImageBase())), .Little); | 859 | mem.writeInt(u32, &buf, @as(u32, @intCast(entry_value + self.getImageBase())), .little); |
| 860 | try self.base.file.?.pwriteAll(&buf, file_offset); | 860 | try self.base.file.?.pwriteAll(&buf, file_offset); |
| 861 | }, | 861 | }, |
| 862 | .p64 => { | 862 | .p64 => { |
| 863 | var buf: [8]u8 = undefined; | 863 | var buf: [8]u8 = undefined; |
| 864 | mem.writeInt(u64, &buf, entry_value + self.getImageBase(), .Little); | 864 | mem.writeInt(u64, &buf, entry_value + self.getImageBase(), .little); |
| 865 | try self.base.file.?.pwriteAll(&buf, file_offset); | 865 | try self.base.file.?.pwriteAll(&buf, file_offset); |
| 866 | }, | 866 | }, |
| 867 | } | 867 | } |
| ... | @@ -889,14 +889,14 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void { | ... | @@ -889,14 +889,14 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void { |
| 889 | switch (self.ptr_width) { | 889 | switch (self.ptr_width) { |
| 890 | .p32 => { | 890 | .p32 => { |
| 891 | var buf: [4]u8 = undefined; | 891 | var buf: [4]u8 = undefined; |
| 892 | mem.writeInt(u32, &buf, @as(u32, @intCast(entry_value + slide)), .Little); | 892 | mem.writeInt(u32, &buf, @as(u32, @intCast(entry_value + slide)), .little); |
| 893 | writeMem(handle, pvaddr, &buf) catch |err| { | 893 | writeMem(handle, pvaddr, &buf) catch |err| { |
| 894 | log.warn("writing to protected memory failed with error: {s}", .{@errorName(err)}); | 894 | log.warn("writing to protected memory failed with error: {s}", .{@errorName(err)}); |
| 895 | }; | 895 | }; |
| 896 | }, | 896 | }, |
| 897 | .p64 => { | 897 | .p64 => { |
| 898 | var buf: [8]u8 = undefined; | 898 | var buf: [8]u8 = undefined; |
| 899 | mem.writeInt(u64, &buf, entry_value + slide, .Little); | 899 | mem.writeInt(u64, &buf, entry_value + slide, .little); |
| 900 | writeMem(handle, pvaddr, &buf) catch |err| { | 900 | writeMem(handle, pvaddr, &buf) catch |err| { |
| 901 | log.warn("writing to protected memory failed with error: {s}", .{@errorName(err)}); | 901 | log.warn("writing to protected memory failed with error: {s}", .{@errorName(err)}); |
| 902 | }; | 902 | }; |
| ... | @@ -2076,7 +2076,7 @@ fn writeImportTables(self: *Coff) !void { | ... | @@ -2076,7 +2076,7 @@ fn writeImportTables(self: *Coff) !void { |
| 2076 | lookup_table_offset += lookup_entry_size; | 2076 | lookup_table_offset += lookup_entry_size; |
| 2077 | 2077 | ||
| 2078 | // Names table entry | 2078 | // Names table entry |
| 2079 | mem.writeInt(u16, buffer.items[names_table_offset..][0..2], 0, .Little); // Hint set to 0 until we learn how to parse DLLs | 2079 | mem.writeInt(u16, buffer.items[names_table_offset..][0..2], 0, .little); // Hint set to 0 until we learn how to parse DLLs |
| 2080 | names_table_offset += 2; | 2080 | names_table_offset += 2; |
| 2081 | @memcpy(buffer.items[names_table_offset..][0..import_name.len], import_name); | 2081 | @memcpy(buffer.items[names_table_offset..][0..import_name.len], import_name); |
| 2082 | names_table_offset += @as(u32, @intCast(import_name.len)); | 2082 | names_table_offset += @as(u32, @intCast(import_name.len)); |
| ... | @@ -2089,7 +2089,7 @@ fn writeImportTables(self: *Coff) !void { | ... | @@ -2089,7 +2089,7 @@ fn writeImportTables(self: *Coff) !void { |
| 2089 | } | 2089 | } |
| 2090 | 2090 | ||
| 2091 | // IAT sentinel | 2091 | // IAT sentinel |
| 2092 | mem.writeInt(u64, buffer.items[iat_offset..][0..lookup_entry_size], 0, .Little); | 2092 | mem.writeInt(u64, buffer.items[iat_offset..][0..lookup_entry_size], 0, .little); |
| 2093 | iat_offset += 8; | 2093 | iat_offset += 8; |
| 2094 | 2094 | ||
| 2095 | // Lookup table sentinel | 2095 | // Lookup table sentinel |
| ... | @@ -2157,7 +2157,7 @@ fn writeStrtab(self: *Coff) !void { | ... | @@ -2157,7 +2157,7 @@ fn writeStrtab(self: *Coff) !void { |
| 2157 | buffer.appendSliceAssumeCapacity(self.strtab.items()); | 2157 | buffer.appendSliceAssumeCapacity(self.strtab.items()); |
| 2158 | // Here, we do a trick in that we do not commit the size of the strtab to strtab buffer, instead | 2158 | // Here, we do a trick in that we do not commit the size of the strtab to strtab buffer, instead |
| 2159 | // we write the length of the strtab to a temporary buffer that goes to file. | 2159 | // we write the length of the strtab to a temporary buffer that goes to file. |
| 2160 | mem.writeInt(u32, buffer.items[0..4], @as(u32, @intCast(self.strtab.len())), .Little); | 2160 | mem.writeInt(u32, buffer.items[0..4], @as(u32, @intCast(self.strtab.len())), .little); |
| 2161 | 2161 | ||
| 2162 | try self.base.file.?.pwriteAll(buffer.items, self.strtab_offset.?); | 2162 | try self.base.file.?.pwriteAll(buffer.items, self.strtab_offset.?); |
| 2163 | } | 2163 | } |
| ... | @@ -2180,7 +2180,7 @@ fn writeHeader(self: *Coff) !void { | ... | @@ -2180,7 +2180,7 @@ fn writeHeader(self: *Coff) !void { |
| 2180 | 2180 | ||
| 2181 | try buffer.ensureTotalCapacity(self.getSizeOfHeaders()); | 2181 | try buffer.ensureTotalCapacity(self.getSizeOfHeaders()); |
| 2182 | writer.writeAll(msdos_stub) catch unreachable; | 2182 | writer.writeAll(msdos_stub) catch unreachable; |
| 2183 | mem.writeInt(u32, buffer.items[0x3c..][0..4], msdos_stub.len, .Little); | 2183 | mem.writeInt(u32, buffer.items[0x3c..][0..4], msdos_stub.len, .little); |
| 2184 | 2184 | ||
| 2185 | writer.writeAll("PE\x00\x00") catch unreachable; | 2185 | writer.writeAll("PE\x00\x00") catch unreachable; |
| 2186 | var flags = coff.CoffHeaderFlags{ | 2186 | var flags = coff.CoffHeaderFlags{ |
| ... | @@ -2548,7 +2548,7 @@ fn setSymbolName(self: *Coff, symbol: *coff.Symbol, name: []const u8) !void { | ... | @@ -2548,7 +2548,7 @@ fn setSymbolName(self: *Coff, symbol: *coff.Symbol, name: []const u8) !void { |
| 2548 | } | 2548 | } |
| 2549 | const offset = try self.strtab.insert(self.base.allocator, name); | 2549 | const offset = try self.strtab.insert(self.base.allocator, name); |
| 2550 | @memset(symbol.name[0..4], 0); | 2550 | @memset(symbol.name[0..4], 0); |
| 2551 | mem.writeInt(u32, symbol.name[4..8], offset, .Little); | 2551 | mem.writeInt(u32, symbol.name[4..8], offset, .little); |
| 2552 | } | 2552 | } |
| 2553 | 2553 | ||
| 2554 | fn logSymAttributes(sym: *const coff.Symbol, buf: *[4]u8) []const u8 { | 2554 | fn logSymAttributes(sym: *const coff.Symbol, buf: *[4]u8) []const u8 { |
src/link/Coff/Relocation.zig+10-10| ... | @@ -137,7 +137,7 @@ fn resolveAarch64(self: Relocation, ctx: Context) void { | ... | @@ -137,7 +137,7 @@ fn resolveAarch64(self: Relocation, ctx: Context) void { |
| 137 | }; | 137 | }; |
| 138 | inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2)); | 138 | inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2)); |
| 139 | inst.pc_relative_address.immlo = @as(u2, @truncate(pages)); | 139 | inst.pc_relative_address.immlo = @as(u2, @truncate(pages)); |
| 140 | mem.writeInt(u32, buffer[0..4], inst.toU32(), .Little); | 140 | mem.writeInt(u32, buffer[0..4], inst.toU32(), .little); |
| 141 | }, | 141 | }, |
| 142 | .got_pageoff, .import_pageoff, .pageoff => { | 142 | .got_pageoff, .import_pageoff, .pageoff => { |
| 143 | assert(!self.pcrel); | 143 | assert(!self.pcrel); |
| ... | @@ -151,7 +151,7 @@ fn resolveAarch64(self: Relocation, ctx: Context) void { | ... | @@ -151,7 +151,7 @@ fn resolveAarch64(self: Relocation, ctx: Context) void { |
| 151 | ), buffer[0..4]), | 151 | ), buffer[0..4]), |
| 152 | }; | 152 | }; |
| 153 | inst.add_subtract_immediate.imm12 = narrowed; | 153 | inst.add_subtract_immediate.imm12 = narrowed; |
| 154 | mem.writeInt(u32, buffer[0..4], inst.toU32(), .Little); | 154 | mem.writeInt(u32, buffer[0..4], inst.toU32(), .little); |
| 155 | } else { | 155 | } else { |
| 156 | var inst = aarch64.Instruction{ | 156 | var inst = aarch64.Instruction{ |
| 157 | .load_store_register = mem.bytesToValue(meta.TagPayload( | 157 | .load_store_register = mem.bytesToValue(meta.TagPayload( |
| ... | @@ -173,7 +173,7 @@ fn resolveAarch64(self: Relocation, ctx: Context) void { | ... | @@ -173,7 +173,7 @@ fn resolveAarch64(self: Relocation, ctx: Context) void { |
| 173 | } | 173 | } |
| 174 | }; | 174 | }; |
| 175 | inst.load_store_register.offset = offset; | 175 | inst.load_store_register.offset = offset; |
| 176 | mem.writeInt(u32, buffer[0..4], inst.toU32(), .Little); | 176 | mem.writeInt(u32, buffer[0..4], inst.toU32(), .little); |
| 177 | } | 177 | } |
| 178 | }, | 178 | }, |
| 179 | .direct => { | 179 | .direct => { |
| ... | @@ -183,9 +183,9 @@ fn resolveAarch64(self: Relocation, ctx: Context) void { | ... | @@ -183,9 +183,9 @@ fn resolveAarch64(self: Relocation, ctx: Context) void { |
| 183 | u32, | 183 | u32, |
| 184 | buffer[0..4], | 184 | buffer[0..4], |
| 185 | @as(u32, @truncate(ctx.target_vaddr + ctx.image_base)), | 185 | @as(u32, @truncate(ctx.target_vaddr + ctx.image_base)), |
| 186 | .Little, | 186 | .little, |
| 187 | ), | 187 | ), |
| 188 | 3 => mem.writeInt(u64, buffer[0..8], ctx.target_vaddr + ctx.image_base, .Little), | 188 | 3 => mem.writeInt(u64, buffer[0..8], ctx.target_vaddr + ctx.image_base, .little), |
| 189 | else => unreachable, | 189 | else => unreachable, |
| 190 | } | 190 | } |
| 191 | }, | 191 | }, |
| ... | @@ -208,17 +208,17 @@ fn resolveX86(self: Relocation, ctx: Context) void { | ... | @@ -208,17 +208,17 @@ fn resolveX86(self: Relocation, ctx: Context) void { |
| 208 | .got, .import => { | 208 | .got, .import => { |
| 209 | assert(self.pcrel); | 209 | assert(self.pcrel); |
| 210 | const disp = @as(i32, @intCast(ctx.target_vaddr)) - @as(i32, @intCast(ctx.source_vaddr)) - 4; | 210 | const disp = @as(i32, @intCast(ctx.target_vaddr)) - @as(i32, @intCast(ctx.source_vaddr)) - 4; |
| 211 | mem.writeInt(i32, buffer[0..4], disp, .Little); | 211 | mem.writeInt(i32, buffer[0..4], disp, .little); |
| 212 | }, | 212 | }, |
| 213 | .direct => { | 213 | .direct => { |
| 214 | if (self.pcrel) { | 214 | if (self.pcrel) { |
| 215 | const disp = @as(i32, @intCast(ctx.target_vaddr)) - @as(i32, @intCast(ctx.source_vaddr)) - 4; | 215 | const disp = @as(i32, @intCast(ctx.target_vaddr)) - @as(i32, @intCast(ctx.source_vaddr)) - 4; |
| 216 | mem.writeInt(i32, buffer[0..4], disp, .Little); | 216 | mem.writeInt(i32, buffer[0..4], disp, .little); |
| 217 | } else switch (ctx.ptr_width) { | 217 | } else switch (ctx.ptr_width) { |
| 218 | .p32 => mem.writeInt(u32, buffer[0..4], @as(u32, @intCast(ctx.target_vaddr + ctx.image_base)), .Little), | 218 | .p32 => mem.writeInt(u32, buffer[0..4], @as(u32, @intCast(ctx.target_vaddr + ctx.image_base)), .little), |
| 219 | .p64 => switch (self.length) { | 219 | .p64 => switch (self.length) { |
| 220 | 2 => mem.writeInt(u32, buffer[0..4], @as(u32, @truncate(ctx.target_vaddr + ctx.image_base)), .Little), | 220 | 2 => mem.writeInt(u32, buffer[0..4], @as(u32, @truncate(ctx.target_vaddr + ctx.image_base)), .little), |
| 221 | 3 => mem.writeInt(u64, buffer[0..8], ctx.target_vaddr + ctx.image_base, .Little), | 221 | 3 => mem.writeInt(u64, buffer[0..8], ctx.target_vaddr + ctx.image_base, .little), |
| 222 | else => unreachable, | 222 | else => unreachable, |
| 223 | }, | 223 | }, |
| 224 | } | 224 | } |
src/link/Elf.zig+2-2| ... | @@ -2719,8 +2719,8 @@ fn writeHeader(self: *Elf) !void { | ... | @@ -2719,8 +2719,8 @@ fn writeHeader(self: *Elf) !void { |
| 2719 | 2719 | ||
| 2720 | const endian = self.base.options.target.cpu.arch.endian(); | 2720 | const endian = self.base.options.target.cpu.arch.endian(); |
| 2721 | hdr_buf[index] = switch (endian) { | 2721 | hdr_buf[index] = switch (endian) { |
| 2722 | .Little => elf.ELFDATA2LSB, | 2722 | .little => elf.ELFDATA2LSB, |
| 2723 | .Big => elf.ELFDATA2MSB, | 2723 | .big => elf.ELFDATA2MSB, |
| 2724 | }; | 2724 | }; |
| 2725 | index += 1; | 2725 | index += 1; |
| 2726 | 2726 |
src/link/Elf/Atom.zig+42-42| ... | @@ -786,43 +786,43 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void { | ... | @@ -786,43 +786,43 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void { |
| 786 | 786 | ||
| 787 | elf.R_X86_64_PLT32, | 787 | elf.R_X86_64_PLT32, |
| 788 | elf.R_X86_64_PC32, | 788 | elf.R_X86_64_PC32, |
| 789 | => try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .Little), | 789 | => try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .little), |
| 790 | 790 | ||
| 791 | elf.R_X86_64_GOTPCREL => try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .Little), | 791 | elf.R_X86_64_GOTPCREL => try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .little), |
| 792 | elf.R_X86_64_GOTPC32 => try cwriter.writeInt(i32, @as(i32, @intCast(GOT + A - P)), .Little), | 792 | elf.R_X86_64_GOTPC32 => try cwriter.writeInt(i32, @as(i32, @intCast(GOT + A - P)), .little), |
| 793 | elf.R_X86_64_GOTPC64 => try cwriter.writeInt(i64, GOT + A - P, .Little), | 793 | elf.R_X86_64_GOTPC64 => try cwriter.writeInt(i64, GOT + A - P, .little), |
| 794 | 794 | ||
| 795 | elf.R_X86_64_GOTPCRELX => { | 795 | elf.R_X86_64_GOTPCRELX => { |
| 796 | if (!target.flags.import and !target.isIFunc(elf_file) and !target.isAbs(elf_file)) blk: { | 796 | if (!target.flags.import and !target.isIFunc(elf_file) and !target.isAbs(elf_file)) blk: { |
| 797 | x86_64.relaxGotpcrelx(code[r_offset - 2 ..]) catch break :blk; | 797 | x86_64.relaxGotpcrelx(code[r_offset - 2 ..]) catch break :blk; |
| 798 | try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .Little); | 798 | try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .little); |
| 799 | continue; | 799 | continue; |
| 800 | } | 800 | } |
| 801 | try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .Little); | 801 | try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .little); |
| 802 | }, | 802 | }, |
| 803 | 803 | ||
| 804 | elf.R_X86_64_REX_GOTPCRELX => { | 804 | elf.R_X86_64_REX_GOTPCRELX => { |
| 805 | if (!target.flags.import and !target.isIFunc(elf_file) and !target.isAbs(elf_file)) blk: { | 805 | if (!target.flags.import and !target.isIFunc(elf_file) and !target.isAbs(elf_file)) blk: { |
| 806 | x86_64.relaxRexGotpcrelx(code[r_offset - 3 ..]) catch break :blk; | 806 | x86_64.relaxRexGotpcrelx(code[r_offset - 3 ..]) catch break :blk; |
| 807 | try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .Little); | 807 | try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .little); |
| 808 | continue; | 808 | continue; |
| 809 | } | 809 | } |
| 810 | try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .Little); | 810 | try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .little); |
| 811 | }, | 811 | }, |
| 812 | 812 | ||
| 813 | elf.R_X86_64_32 => try cwriter.writeInt(u32, @as(u32, @truncate(@as(u64, @intCast(S + A)))), .Little), | 813 | elf.R_X86_64_32 => try cwriter.writeInt(u32, @as(u32, @truncate(@as(u64, @intCast(S + A)))), .little), |
| 814 | elf.R_X86_64_32S => try cwriter.writeInt(i32, @as(i32, @truncate(S + A)), .Little), | 814 | elf.R_X86_64_32S => try cwriter.writeInt(i32, @as(i32, @truncate(S + A)), .little), |
| 815 | 815 | ||
| 816 | elf.R_X86_64_TPOFF32 => try cwriter.writeInt(i32, @as(i32, @truncate(S + A - TP)), .Little), | 816 | elf.R_X86_64_TPOFF32 => try cwriter.writeInt(i32, @as(i32, @truncate(S + A - TP)), .little), |
| 817 | elf.R_X86_64_TPOFF64 => try cwriter.writeInt(i64, S + A - TP, .Little), | 817 | elf.R_X86_64_TPOFF64 => try cwriter.writeInt(i64, S + A - TP, .little), |
| 818 | 818 | ||
| 819 | elf.R_X86_64_DTPOFF32 => try cwriter.writeInt(i32, @as(i32, @truncate(S + A - DTP)), .Little), | 819 | elf.R_X86_64_DTPOFF32 => try cwriter.writeInt(i32, @as(i32, @truncate(S + A - DTP)), .little), |
| 820 | elf.R_X86_64_DTPOFF64 => try cwriter.writeInt(i64, S + A - DTP, .Little), | 820 | elf.R_X86_64_DTPOFF64 => try cwriter.writeInt(i64, S + A - DTP, .little), |
| 821 | 821 | ||
| 822 | elf.R_X86_64_TLSGD => { | 822 | elf.R_X86_64_TLSGD => { |
| 823 | if (target.flags.has_tlsgd) { | 823 | if (target.flags.has_tlsgd) { |
| 824 | const S_ = @as(i64, @intCast(target.tlsGdAddress(elf_file))); | 824 | const S_ = @as(i64, @intCast(target.tlsGdAddress(elf_file))); |
| 825 | try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .Little); | 825 | try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .little); |
| 826 | } else if (target.flags.has_gottp) { | 826 | } else if (target.flags.has_gottp) { |
| 827 | const S_ = @as(i64, @intCast(target.gotTpAddress(elf_file))); | 827 | const S_ = @as(i64, @intCast(target.gotTpAddress(elf_file))); |
| 828 | try x86_64.relaxTlsGdToIe(self, rels[i .. i + 2], @intCast(S_ - P), elf_file, &stream); | 828 | try x86_64.relaxTlsGdToIe(self, rels[i .. i + 2], @intCast(S_ - P), elf_file, &stream); |
| ... | @@ -843,7 +843,7 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void { | ... | @@ -843,7 +843,7 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void { |
| 843 | if (elf_file.got.tlsld_index) |entry_index| { | 843 | if (elf_file.got.tlsld_index) |entry_index| { |
| 844 | const tlsld_entry = elf_file.got.entries.items[entry_index]; | 844 | const tlsld_entry = elf_file.got.entries.items[entry_index]; |
| 845 | const S_ = @as(i64, @intCast(tlsld_entry.address(elf_file))); | 845 | const S_ = @as(i64, @intCast(tlsld_entry.address(elf_file))); |
| 846 | try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .Little); | 846 | try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .little); |
| 847 | } else { | 847 | } else { |
| 848 | try x86_64.relaxTlsLdToLe( | 848 | try x86_64.relaxTlsLdToLe( |
| 849 | self, | 849 | self, |
| ... | @@ -859,10 +859,10 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void { | ... | @@ -859,10 +859,10 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void { |
| 859 | elf.R_X86_64_GOTPC32_TLSDESC => { | 859 | elf.R_X86_64_GOTPC32_TLSDESC => { |
| 860 | if (target.flags.has_tlsdesc) { | 860 | if (target.flags.has_tlsdesc) { |
| 861 | const S_ = @as(i64, @intCast(target.tlsDescAddress(elf_file))); | 861 | const S_ = @as(i64, @intCast(target.tlsDescAddress(elf_file))); |
| 862 | try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .Little); | 862 | try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .little); |
| 863 | } else { | 863 | } else { |
| 864 | try x86_64.relaxGotPcTlsDesc(code[r_offset - 3 ..]); | 864 | try x86_64.relaxGotPcTlsDesc(code[r_offset - 3 ..]); |
| 865 | try cwriter.writeInt(i32, @as(i32, @intCast(S - TP)), .Little); | 865 | try cwriter.writeInt(i32, @as(i32, @intCast(S - TP)), .little); |
| 866 | } | 866 | } |
| 867 | }, | 867 | }, |
| 868 | 868 | ||
| ... | @@ -874,18 +874,18 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void { | ... | @@ -874,18 +874,18 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void { |
| 874 | elf.R_X86_64_GOTTPOFF => { | 874 | elf.R_X86_64_GOTTPOFF => { |
| 875 | if (target.flags.has_gottp) { | 875 | if (target.flags.has_gottp) { |
| 876 | const S_ = @as(i64, @intCast(target.gotTpAddress(elf_file))); | 876 | const S_ = @as(i64, @intCast(target.gotTpAddress(elf_file))); |
| 877 | try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .Little); | 877 | try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .little); |
| 878 | } else { | 878 | } else { |
| 879 | x86_64.relaxGotTpOff(code[r_offset - 3 ..]) catch unreachable; | 879 | x86_64.relaxGotTpOff(code[r_offset - 3 ..]) catch unreachable; |
| 880 | try cwriter.writeInt(i32, @as(i32, @intCast(S - TP)), .Little); | 880 | try cwriter.writeInt(i32, @as(i32, @intCast(S - TP)), .little); |
| 881 | } | 881 | } |
| 882 | }, | 882 | }, |
| 883 | 883 | ||
| 884 | elf.R_X86_64_GOT32 => try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A)), .Little), | 884 | elf.R_X86_64_GOT32 => try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A)), .little), |
| 885 | 885 | ||
| 886 | // Zig custom relocations | 886 | // Zig custom relocations |
| 887 | Elf.R_X86_64_ZIG_GOT32 => try cwriter.writeInt(u32, @as(u32, @intCast(ZIG_GOT + A)), .Little), | 887 | Elf.R_X86_64_ZIG_GOT32 => try cwriter.writeInt(u32, @as(u32, @intCast(ZIG_GOT + A)), .little), |
| 888 | Elf.R_X86_64_ZIG_GOTPCREL => try cwriter.writeInt(i32, @as(i32, @intCast(ZIG_GOT + A - P)), .Little), | 888 | Elf.R_X86_64_ZIG_GOTPCREL => try cwriter.writeInt(i32, @as(i32, @intCast(ZIG_GOT + A - P)), .little), |
| 889 | 889 | ||
| 890 | else => {}, | 890 | else => {}, |
| 891 | } | 891 | } |
| ... | @@ -920,7 +920,7 @@ fn resolveDynAbsReloc( | ... | @@ -920,7 +920,7 @@ fn resolveDynAbsReloc( |
| 920 | .copyrel, | 920 | .copyrel, |
| 921 | .cplt, | 921 | .cplt, |
| 922 | .none, | 922 | .none, |
| 923 | => try writer.writeInt(i32, @as(i32, @truncate(S + A)), .Little), | 923 | => try writer.writeInt(i32, @as(i32, @truncate(S + A)), .little), |
| 924 | 924 | ||
| 925 | .dyn_copyrel => { | 925 | .dyn_copyrel => { |
| 926 | if (is_writeable or elf_file.base.options.z_nocopyreloc) { | 926 | if (is_writeable or elf_file.base.options.z_nocopyreloc) { |
| ... | @@ -932,7 +932,7 @@ fn resolveDynAbsReloc( | ... | @@ -932,7 +932,7 @@ fn resolveDynAbsReloc( |
| 932 | }); | 932 | }); |
| 933 | try applyDynamicReloc(A, elf_file, writer); | 933 | try applyDynamicReloc(A, elf_file, writer); |
| 934 | } else { | 934 | } else { |
| 935 | try writer.writeInt(i32, @as(i32, @truncate(S + A)), .Little); | 935 | try writer.writeInt(i32, @as(i32, @truncate(S + A)), .little); |
| 936 | } | 936 | } |
| 937 | }, | 937 | }, |
| 938 | 938 | ||
| ... | @@ -946,7 +946,7 @@ fn resolveDynAbsReloc( | ... | @@ -946,7 +946,7 @@ fn resolveDynAbsReloc( |
| 946 | }); | 946 | }); |
| 947 | try applyDynamicReloc(A, elf_file, writer); | 947 | try applyDynamicReloc(A, elf_file, writer); |
| 948 | } else { | 948 | } else { |
| 949 | try writer.writeInt(i32, @as(i32, @truncate(S + A)), .Little); | 949 | try writer.writeInt(i32, @as(i32, @truncate(S + A)), .little); |
| 950 | } | 950 | } |
| 951 | }, | 951 | }, |
| 952 | 952 | ||
| ... | @@ -984,7 +984,7 @@ fn resolveDynAbsReloc( | ... | @@ -984,7 +984,7 @@ fn resolveDynAbsReloc( |
| 984 | fn applyDynamicReloc(value: i64, elf_file: *Elf, writer: anytype) !void { | 984 | fn applyDynamicReloc(value: i64, elf_file: *Elf, writer: anytype) !void { |
| 985 | _ = elf_file; | 985 | _ = elf_file; |
| 986 | // if (elf_file.options.apply_dynamic_relocs) { | 986 | // if (elf_file.options.apply_dynamic_relocs) { |
| 987 | try writer.writeInt(i64, value, .Little); | 987 | try writer.writeInt(i64, value, .little); |
| 988 | // } | 988 | // } |
| 989 | } | 989 | } |
| 990 | 990 | ||
| ... | @@ -1058,22 +1058,22 @@ pub fn resolveRelocsNonAlloc(self: Atom, elf_file: *Elf, code: []u8, undefs: any | ... | @@ -1058,22 +1058,22 @@ pub fn resolveRelocsNonAlloc(self: Atom, elf_file: *Elf, code: []u8, undefs: any |
| 1058 | 1058 | ||
| 1059 | switch (r_type) { | 1059 | switch (r_type) { |
| 1060 | elf.R_X86_64_NONE => unreachable, | 1060 | elf.R_X86_64_NONE => unreachable, |
| 1061 | elf.R_X86_64_8 => try cwriter.writeInt(u8, @as(u8, @bitCast(@as(i8, @intCast(S + A)))), .Little), | 1061 | elf.R_X86_64_8 => try cwriter.writeInt(u8, @as(u8, @bitCast(@as(i8, @intCast(S + A)))), .little), |
| 1062 | elf.R_X86_64_16 => try cwriter.writeInt(u16, @as(u16, @bitCast(@as(i16, @intCast(S + A)))), .Little), | 1062 | elf.R_X86_64_16 => try cwriter.writeInt(u16, @as(u16, @bitCast(@as(i16, @intCast(S + A)))), .little), |
| 1063 | elf.R_X86_64_32 => try cwriter.writeInt(u32, @as(u32, @bitCast(@as(i32, @intCast(S + A)))), .Little), | 1063 | elf.R_X86_64_32 => try cwriter.writeInt(u32, @as(u32, @bitCast(@as(i32, @intCast(S + A)))), .little), |
| 1064 | elf.R_X86_64_32S => try cwriter.writeInt(i32, @as(i32, @intCast(S + A)), .Little), | 1064 | elf.R_X86_64_32S => try cwriter.writeInt(i32, @as(i32, @intCast(S + A)), .little), |
| 1065 | elf.R_X86_64_64 => try cwriter.writeInt(i64, S + A, .Little), | 1065 | elf.R_X86_64_64 => try cwriter.writeInt(i64, S + A, .little), |
| 1066 | elf.R_X86_64_DTPOFF32 => try cwriter.writeInt(i32, @as(i32, @intCast(S + A - DTP)), .Little), | 1066 | elf.R_X86_64_DTPOFF32 => try cwriter.writeInt(i32, @as(i32, @intCast(S + A - DTP)), .little), |
| 1067 | elf.R_X86_64_DTPOFF64 => try cwriter.writeInt(i64, S + A - DTP, .Little), | 1067 | elf.R_X86_64_DTPOFF64 => try cwriter.writeInt(i64, S + A - DTP, .little), |
| 1068 | elf.R_X86_64_GOTOFF64 => try cwriter.writeInt(i64, S + A - GOT, .Little), | 1068 | elf.R_X86_64_GOTOFF64 => try cwriter.writeInt(i64, S + A - GOT, .little), |
| 1069 | elf.R_X86_64_GOTPC64 => try cwriter.writeInt(i64, GOT + A, .Little), | 1069 | elf.R_X86_64_GOTPC64 => try cwriter.writeInt(i64, GOT + A, .little), |
| 1070 | elf.R_X86_64_SIZE32 => { | 1070 | elf.R_X86_64_SIZE32 => { |
| 1071 | const size = @as(i64, @intCast(target.elfSym(elf_file).st_size)); | 1071 | const size = @as(i64, @intCast(target.elfSym(elf_file).st_size)); |
| 1072 | try cwriter.writeInt(u32, @as(u32, @bitCast(@as(i32, @intCast(size + A)))), .Little); | 1072 | try cwriter.writeInt(u32, @as(u32, @bitCast(@as(i32, @intCast(size + A)))), .little); |
| 1073 | }, | 1073 | }, |
| 1074 | elf.R_X86_64_SIZE64 => { | 1074 | elf.R_X86_64_SIZE64 => { |
| 1075 | const size = @as(i64, @intCast(target.elfSym(elf_file).st_size)); | 1075 | const size = @as(i64, @intCast(target.elfSym(elf_file).st_size)); |
| 1076 | try cwriter.writeInt(i64, @as(i64, @intCast(size + A)), .Little); | 1076 | try cwriter.writeInt(i64, @as(i64, @intCast(size + A)), .little); |
| 1077 | }, | 1077 | }, |
| 1078 | else => try self.reportUnhandledRelocError(rel, elf_file), | 1078 | else => try self.reportUnhandledRelocError(rel, elf_file), |
| 1079 | } | 1079 | } |
| ... | @@ -1254,7 +1254,7 @@ const x86_64 = struct { | ... | @@ -1254,7 +1254,7 @@ const x86_64 = struct { |
| 1254 | 0x64, 0x48, 0x8b, 0x04, 0x25, 0, 0, 0, 0, // movq %fs:0,%rax | 1254 | 0x64, 0x48, 0x8b, 0x04, 0x25, 0, 0, 0, 0, // movq %fs:0,%rax |
| 1255 | 0x48, 0x03, 0x05, 0, 0, 0, 0, // add foo@gottpoff(%rip), %rax | 1255 | 0x48, 0x03, 0x05, 0, 0, 0, 0, // add foo@gottpoff(%rip), %rax |
| 1256 | }; | 1256 | }; |
| 1257 | std.mem.writeInt(i32, insts[12..][0..4], value - 12, .Little); | 1257 | std.mem.writeInt(i32, insts[12..][0..4], value - 12, .little); |
| 1258 | try stream.seekBy(-4); | 1258 | try stream.seekBy(-4); |
| 1259 | try writer.writeAll(&insts); | 1259 | try writer.writeAll(&insts); |
| 1260 | }, | 1260 | }, |
| ... | @@ -1292,7 +1292,7 @@ const x86_64 = struct { | ... | @@ -1292,7 +1292,7 @@ const x86_64 = struct { |
| 1292 | 0x64, 0x48, 0x8b, 0, // mov %fs:(%rax), %rax | 1292 | 0x64, 0x48, 0x8b, 0, // mov %fs:(%rax), %rax |
| 1293 | 0x48, 0x2d, 0, 0, 0, 0, // sub $tls_size, %rax | 1293 | 0x48, 0x2d, 0, 0, 0, 0, // sub $tls_size, %rax |
| 1294 | }; | 1294 | }; |
| 1295 | std.mem.writeInt(i32, insts[8..][0..4], value, .Little); | 1295 | std.mem.writeInt(i32, insts[8..][0..4], value, .little); |
| 1296 | try stream.seekBy(-3); | 1296 | try stream.seekBy(-3); |
| 1297 | try writer.writeAll(&insts); | 1297 | try writer.writeAll(&insts); |
| 1298 | }, | 1298 | }, |
| ... | @@ -1306,7 +1306,7 @@ const x86_64 = struct { | ... | @@ -1306,7 +1306,7 @@ const x86_64 = struct { |
| 1306 | 0x48, 0x2d, 0, 0, 0, 0, // sub $tls_size, %rax | 1306 | 0x48, 0x2d, 0, 0, 0, 0, // sub $tls_size, %rax |
| 1307 | 0x90, // nop | 1307 | 0x90, // nop |
| 1308 | }; | 1308 | }; |
| 1309 | std.mem.writeInt(i32, insts[8..][0..4], value, .Little); | 1309 | std.mem.writeInt(i32, insts[8..][0..4], value, .little); |
| 1310 | try stream.seekBy(-3); | 1310 | try stream.seekBy(-3); |
| 1311 | try writer.writeAll(&insts); | 1311 | try writer.writeAll(&insts); |
| 1312 | }, | 1312 | }, |
| ... | @@ -1392,7 +1392,7 @@ const x86_64 = struct { | ... | @@ -1392,7 +1392,7 @@ const x86_64 = struct { |
| 1392 | 0x64, 0x48, 0x8b, 0x04, 0x25, 0, 0, 0, 0, // movq %fs:0,%rax | 1392 | 0x64, 0x48, 0x8b, 0x04, 0x25, 0, 0, 0, 0, // movq %fs:0,%rax |
| 1393 | 0x48, 0x81, 0xc0, 0, 0, 0, 0, // add $tp_offset, %rax | 1393 | 0x48, 0x81, 0xc0, 0, 0, 0, 0, // add $tp_offset, %rax |
| 1394 | }; | 1394 | }; |
| 1395 | std.mem.writeInt(i32, insts[12..][0..4], value, .Little); | 1395 | std.mem.writeInt(i32, insts[12..][0..4], value, .little); |
| 1396 | try stream.seekBy(-4); | 1396 | try stream.seekBy(-4); |
| 1397 | try writer.writeAll(&insts); | 1397 | try writer.writeAll(&insts); |
| 1398 | relocs_log.debug(" relaxing {} and {}", .{ | 1398 | relocs_log.debug(" relaxing {} and {}", .{ |
src/link/Elf/eh_frame.zig+11-11| ... | @@ -33,7 +33,7 @@ pub const Fde = struct { | ... | @@ -33,7 +33,7 @@ pub const Fde = struct { |
| 33 | 33 | ||
| 34 | pub fn ciePointer(fde: Fde, elf_file: *Elf) u32 { | 34 | pub fn ciePointer(fde: Fde, elf_file: *Elf) u32 { |
| 35 | const fde_data = fde.data(elf_file); | 35 | const fde_data = fde.data(elf_file); |
| 36 | return std.mem.readInt(u32, fde_data[4..8], .Little); | 36 | return std.mem.readInt(u32, fde_data[4..8], .little); |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | pub fn calcSize(fde: Fde) usize { | 39 | pub fn calcSize(fde: Fde) usize { |
| ... | @@ -217,10 +217,10 @@ pub const Iterator = struct { | ... | @@ -217,10 +217,10 @@ pub const Iterator = struct { |
| 217 | var stream = std.io.fixedBufferStream(it.data[it.pos..]); | 217 | var stream = std.io.fixedBufferStream(it.data[it.pos..]); |
| 218 | const reader = stream.reader(); | 218 | const reader = stream.reader(); |
| 219 | 219 | ||
| 220 | var size = try reader.readInt(u32, .Little); | 220 | var size = try reader.readInt(u32, .little); |
| 221 | if (size == 0xFFFFFFFF) @panic("TODO"); | 221 | if (size == 0xFFFFFFFF) @panic("TODO"); |
| 222 | 222 | ||
| 223 | const id = try reader.readInt(u32, .Little); | 223 | const id = try reader.readInt(u32, .little); |
| 224 | const record = Record{ | 224 | const record = Record{ |
| 225 | .tag = if (id == 0) .cie else .fde, | 225 | .tag = if (id == 0) .cie else .fde, |
| 226 | .offset = it.pos, | 226 | .offset = it.pos, |
| ... | @@ -298,10 +298,10 @@ fn resolveReloc(rec: anytype, sym: *const Symbol, rel: elf.Elf64_Rela, elf_file: | ... | @@ -298,10 +298,10 @@ fn resolveReloc(rec: anytype, sym: *const Symbol, rel: elf.Elf64_Rela, elf_file: |
| 298 | 298 | ||
| 299 | var where = contents[offset..]; | 299 | var where = contents[offset..]; |
| 300 | switch (rel.r_type()) { | 300 | switch (rel.r_type()) { |
| 301 | elf.R_X86_64_32 => std.mem.writeInt(i32, where[0..4], @as(i32, @truncate(S + A)), .Little), | 301 | elf.R_X86_64_32 => std.mem.writeInt(i32, where[0..4], @as(i32, @truncate(S + A)), .little), |
| 302 | elf.R_X86_64_64 => std.mem.writeInt(i64, where[0..8], S + A, .Little), | 302 | elf.R_X86_64_64 => std.mem.writeInt(i64, where[0..8], S + A, .little), |
| 303 | elf.R_X86_64_PC32 => std.mem.writeInt(i32, where[0..4], @as(i32, @intCast(S - P + A)), .Little), | 303 | elf.R_X86_64_PC32 => std.mem.writeInt(i32, where[0..4], @as(i32, @intCast(S - P + A)), .little), |
| 304 | elf.R_X86_64_PC64 => std.mem.writeInt(i64, where[0..8], S - P + A, .Little), | 304 | elf.R_X86_64_PC64 => std.mem.writeInt(i64, where[0..8], S - P + A, .little), |
| 305 | else => unreachable, | 305 | else => unreachable, |
| 306 | } | 306 | } |
| 307 | } | 307 | } |
| ... | @@ -342,7 +342,7 @@ pub fn writeEhFrame(elf_file: *Elf, writer: anytype) !void { | ... | @@ -342,7 +342,7 @@ pub fn writeEhFrame(elf_file: *Elf, writer: anytype) !void { |
| 342 | i32, | 342 | i32, |
| 343 | contents[4..8], | 343 | contents[4..8], |
| 344 | @truncate(@as(i64, @intCast(fde.out_offset + 4)) - @as(i64, @intCast(fde.cie(elf_file).out_offset))), | 344 | @truncate(@as(i64, @intCast(fde.out_offset + 4)) - @as(i64, @intCast(fde.cie(elf_file).out_offset))), |
| 345 | .Little, | 345 | .little, |
| 346 | ); | 346 | ); |
| 347 | 347 | ||
| 348 | for (fde.relocs(elf_file)) |rel| { | 348 | for (fde.relocs(elf_file)) |rel| { |
| ... | @@ -354,7 +354,7 @@ pub fn writeEhFrame(elf_file: *Elf, writer: anytype) !void { | ... | @@ -354,7 +354,7 @@ pub fn writeEhFrame(elf_file: *Elf, writer: anytype) !void { |
| 354 | } | 354 | } |
| 355 | } | 355 | } |
| 356 | 356 | ||
| 357 | try writer.writeInt(u32, 0, .Little); | 357 | try writer.writeInt(u32, 0, .little); |
| 358 | } | 358 | } |
| 359 | 359 | ||
| 360 | pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void { | 360 | pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void { |
| ... | @@ -372,9 +372,9 @@ pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void { | ... | @@ -372,9 +372,9 @@ pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void { |
| 372 | i32, | 372 | i32, |
| 373 | @truncate(@as(i64, @intCast(eh_frame_shdr.sh_addr)) - @as(i64, @intCast(eh_frame_hdr_shdr.sh_addr)) - 4), | 373 | @truncate(@as(i64, @intCast(eh_frame_shdr.sh_addr)) - @as(i64, @intCast(eh_frame_hdr_shdr.sh_addr)) - 4), |
| 374 | ))), | 374 | ))), |
| 375 | .Little, | 375 | .little, |
| 376 | ); | 376 | ); |
| 377 | try writer.writeInt(u32, num_fdes, .Little); | 377 | try writer.writeInt(u32, num_fdes, .little); |
| 378 | 378 | ||
| 379 | const Entry = struct { | 379 | const Entry = struct { |
| 380 | init_addr: u32, | 380 | init_addr: u32, |
src/link/Elf/synthetic_sections.zig+15-15| ... | @@ -878,9 +878,9 @@ pub const PltSection = struct { | ... | @@ -878,9 +878,9 @@ pub const PltSection = struct { |
| 878 | 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp qword ptr [rip] -> .got.plt[2] | 878 | 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp qword ptr [rip] -> .got.plt[2] |
| 879 | }; | 879 | }; |
| 880 | var disp = @as(i64, @intCast(got_plt_addr + 8)) - @as(i64, @intCast(plt_addr + 8)) - 4; | 880 | var disp = @as(i64, @intCast(got_plt_addr + 8)) - @as(i64, @intCast(plt_addr + 8)) - 4; |
| 881 | mem.writeInt(i32, preamble[8..][0..4], @as(i32, @intCast(disp)), .Little); | 881 | mem.writeInt(i32, preamble[8..][0..4], @as(i32, @intCast(disp)), .little); |
| 882 | disp = @as(i64, @intCast(got_plt_addr + 16)) - @as(i64, @intCast(plt_addr + 14)) - 4; | 882 | disp = @as(i64, @intCast(got_plt_addr + 16)) - @as(i64, @intCast(plt_addr + 14)) - 4; |
| 883 | mem.writeInt(i32, preamble[14..][0..4], @as(i32, @intCast(disp)), .Little); | 883 | mem.writeInt(i32, preamble[14..][0..4], @as(i32, @intCast(disp)), .little); |
| 884 | try writer.writeAll(&preamble); | 884 | try writer.writeAll(&preamble); |
| 885 | try writer.writeByteNTimes(0xcc, preamble_size - preamble.len); | 885 | try writer.writeByteNTimes(0xcc, preamble_size - preamble.len); |
| 886 | 886 | ||
| ... | @@ -894,8 +894,8 @@ pub const PltSection = struct { | ... | @@ -894,8 +894,8 @@ pub const PltSection = struct { |
| 894 | 0x41, 0xbb, 0x00, 0x00, 0x00, 0x00, // mov r11d, N | 894 | 0x41, 0xbb, 0x00, 0x00, 0x00, 0x00, // mov r11d, N |
| 895 | 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp qword ptr [rip] -> .got.plt[N] | 895 | 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp qword ptr [rip] -> .got.plt[N] |
| 896 | }; | 896 | }; |
| 897 | mem.writeInt(i32, entry[6..][0..4], @as(i32, @intCast(i)), .Little); | 897 | mem.writeInt(i32, entry[6..][0..4], @as(i32, @intCast(i)), .little); |
| 898 | mem.writeInt(i32, entry[12..][0..4], @as(i32, @intCast(disp)), .Little); | 898 | mem.writeInt(i32, entry[12..][0..4], @as(i32, @intCast(disp)), .little); |
| 899 | try writer.writeAll(&entry); | 899 | try writer.writeAll(&entry); |
| 900 | } | 900 | } |
| 901 | } | 901 | } |
| ... | @@ -971,17 +971,17 @@ pub const GotPltSection = struct { | ... | @@ -971,17 +971,17 @@ pub const GotPltSection = struct { |
| 971 | { | 971 | { |
| 972 | // [0]: _DYNAMIC | 972 | // [0]: _DYNAMIC |
| 973 | const symbol = elf_file.symbol(elf_file.dynamic_index.?); | 973 | const symbol = elf_file.symbol(elf_file.dynamic_index.?); |
| 974 | try writer.writeInt(u64, symbol.value, .Little); | 974 | try writer.writeInt(u64, symbol.value, .little); |
| 975 | } | 975 | } |
| 976 | // [1]: 0x0 | 976 | // [1]: 0x0 |
| 977 | // [2]: 0x0 | 977 | // [2]: 0x0 |
| 978 | try writer.writeInt(u64, 0x0, .Little); | 978 | try writer.writeInt(u64, 0x0, .little); |
| 979 | try writer.writeInt(u64, 0x0, .Little); | 979 | try writer.writeInt(u64, 0x0, .little); |
| 980 | if (elf_file.plt_section_index) |shndx| { | 980 | if (elf_file.plt_section_index) |shndx| { |
| 981 | const plt_addr = elf_file.shdrs.items[shndx].sh_addr; | 981 | const plt_addr = elf_file.shdrs.items[shndx].sh_addr; |
| 982 | for (0..elf_file.plt.symbols.items.len) |_| { | 982 | for (0..elf_file.plt.symbols.items.len) |_| { |
| 983 | // [N]: .plt | 983 | // [N]: .plt |
| 984 | try writer.writeInt(u64, plt_addr, .Little); | 984 | try writer.writeInt(u64, plt_addr, .little); |
| 985 | } | 985 | } |
| 986 | } | 986 | } |
| 987 | } | 987 | } |
| ... | @@ -1023,7 +1023,7 @@ pub const PltGotSection = struct { | ... | @@ -1023,7 +1023,7 @@ pub const PltGotSection = struct { |
| 1023 | 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp qword ptr [rip] -> .got[N] | 1023 | 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp qword ptr [rip] -> .got[N] |
| 1024 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, | 1024 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, |
| 1025 | }; | 1025 | }; |
| 1026 | mem.writeInt(i32, entry[6..][0..4], @as(i32, @intCast(disp)), .Little); | 1026 | mem.writeInt(i32, entry[6..][0..4], @as(i32, @intCast(disp)), .little); |
| 1027 | try writer.writeAll(&entry); | 1027 | try writer.writeAll(&entry); |
| 1028 | } | 1028 | } |
| 1029 | } | 1029 | } |
| ... | @@ -1258,8 +1258,8 @@ pub const HashSection = struct { | ... | @@ -1258,8 +1258,8 @@ pub const HashSection = struct { |
| 1258 | } | 1258 | } |
| 1259 | 1259 | ||
| 1260 | try hs.buffer.ensureTotalCapacityPrecise(gpa, (2 + nsyms * 2) * 4); | 1260 | try hs.buffer.ensureTotalCapacityPrecise(gpa, (2 + nsyms * 2) * 4); |
| 1261 | hs.buffer.writer(gpa).writeInt(u32, @as(u32, @intCast(nsyms)), .Little) catch unreachable; | 1261 | hs.buffer.writer(gpa).writeInt(u32, @as(u32, @intCast(nsyms)), .little) catch unreachable; |
| 1262 | hs.buffer.writer(gpa).writeInt(u32, @as(u32, @intCast(nsyms)), .Little) catch unreachable; | 1262 | hs.buffer.writer(gpa).writeInt(u32, @as(u32, @intCast(nsyms)), .little) catch unreachable; |
| 1263 | hs.buffer.writer(gpa).writeAll(mem.sliceAsBytes(buckets)) catch unreachable; | 1263 | hs.buffer.writer(gpa).writeAll(mem.sliceAsBytes(buckets)) catch unreachable; |
| 1264 | hs.buffer.writer(gpa).writeAll(mem.sliceAsBytes(chains)) catch unreachable; | 1264 | hs.buffer.writer(gpa).writeAll(mem.sliceAsBytes(chains)) catch unreachable; |
| 1265 | } | 1265 | } |
| ... | @@ -1322,10 +1322,10 @@ pub const GnuHashSection = struct { | ... | @@ -1322,10 +1322,10 @@ pub const GnuHashSection = struct { |
| 1322 | var counting = std.io.countingWriter(writer); | 1322 | var counting = std.io.countingWriter(writer); |
| 1323 | const cwriter = counting.writer(); | 1323 | const cwriter = counting.writer(); |
| 1324 | 1324 | ||
| 1325 | try cwriter.writeInt(u32, hash.num_buckets, .Little); | 1325 | try cwriter.writeInt(u32, hash.num_buckets, .little); |
| 1326 | try cwriter.writeInt(u32, export_off, .Little); | 1326 | try cwriter.writeInt(u32, export_off, .little); |
| 1327 | try cwriter.writeInt(u32, hash.num_bloom, .Little); | 1327 | try cwriter.writeInt(u32, hash.num_bloom, .little); |
| 1328 | try cwriter.writeInt(u32, bloom_shift, .Little); | 1328 | try cwriter.writeInt(u32, bloom_shift, .little); |
| 1329 | 1329 | ||
| 1330 | const gpa = elf_file.base.allocator; | 1330 | const gpa = elf_file.base.allocator; |
| 1331 | const hashes = try gpa.alloc(u32, exports.len); | 1331 | const hashes = try gpa.alloc(u32, exports.len); |
src/link/MachO.zig+7-7| ... | @@ -1222,7 +1222,7 @@ fn writeOffsetTableEntry(self: *MachO, index: usize) !void { | ... | @@ -1222,7 +1222,7 @@ fn writeOffsetTableEntry(self: *MachO, index: usize) !void { |
| 1222 | log.debug("writing GOT entry {d}: @{x} => {x}", .{ index, vmaddr, entry_value }); | 1222 | log.debug("writing GOT entry {d}: @{x} => {x}", .{ index, vmaddr, entry_value }); |
| 1223 | 1223 | ||
| 1224 | var buf: [@sizeOf(u64)]u8 = undefined; | 1224 | var buf: [@sizeOf(u64)]u8 = undefined; |
| 1225 | mem.writeInt(u64, &buf, entry_value, .Little); | 1225 | mem.writeInt(u64, &buf, entry_value, .little); |
| 1226 | try self.base.file.?.pwriteAll(&buf, file_offset); | 1226 | try self.base.file.?.pwriteAll(&buf, file_offset); |
| 1227 | 1227 | ||
| 1228 | if (is_hot_update_compatible) { | 1228 | if (is_hot_update_compatible) { |
| ... | @@ -1329,7 +1329,7 @@ fn writeStubTableEntry(self: *MachO, index: usize) !void { | ... | @@ -1329,7 +1329,7 @@ fn writeStubTableEntry(self: *MachO, index: usize) !void { |
| 1329 | 1329 | ||
| 1330 | { | 1330 | { |
| 1331 | var buf: [@sizeOf(u64)]u8 = undefined; | 1331 | var buf: [@sizeOf(u64)]u8 = undefined; |
| 1332 | mem.writeInt(u64, &buf, stub_helper_addr, .Little); | 1332 | mem.writeInt(u64, &buf, stub_helper_addr, .little); |
| 1333 | const off = laptr_header.offset + @sizeOf(u64) * index; | 1333 | const off = laptr_header.offset + @sizeOf(u64) * index; |
| 1334 | try self.base.file.?.pwriteAll(&buf, off); | 1334 | try self.base.file.?.pwriteAll(&buf, off); |
| 1335 | } | 1335 | } |
| ... | @@ -3773,7 +3773,7 @@ fn collectBindData(self: *MachO, bind: anytype, raw_bindings: anytype) !void { | ... | @@ -3773,7 +3773,7 @@ fn collectBindData(self: *MachO, bind: anytype, raw_bindings: anytype) !void { |
| 3773 | const base_offset = sym.n_value - segment.vmaddr; | 3773 | const base_offset = sym.n_value - segment.vmaddr; |
| 3774 | const rel_offset = @as(u32, @intCast(rel.r_address - ctx.base_offset)); | 3774 | const rel_offset = @as(u32, @intCast(rel.r_address - ctx.base_offset)); |
| 3775 | const offset = @as(u64, @intCast(base_offset + rel_offset)); | 3775 | const offset = @as(u64, @intCast(base_offset + rel_offset)); |
| 3776 | const addend = mem.readInt(i64, code[rel_offset..][0..8], .Little); | 3776 | const addend = mem.readInt(i64, code[rel_offset..][0..8], .little); |
| 3777 | 3777 | ||
| 3778 | const dylib_ordinal = @divTrunc(@as(i16, @bitCast(bind_sym.n_desc)), macho.N_SYMBOL_RESOLVER); | 3778 | const dylib_ordinal = @divTrunc(@as(i16, @bitCast(bind_sym.n_desc)), macho.N_SYMBOL_RESOLVER); |
| 3779 | log.debug(" | bind at {x}, import('{s}') in dylib({d})", .{ | 3779 | log.debug(" | bind at {x}, import('{s}') in dylib({d})", .{ |
| ... | @@ -4502,7 +4502,7 @@ pub fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void { | ... | @@ -4502,7 +4502,7 @@ pub fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void { |
| 4502 | if (!self.stub_table.lookup.contains(entry)) continue; | 4502 | if (!self.stub_table.lookup.contains(entry)) continue; |
| 4503 | const target_sym = self.getSymbol(entry); | 4503 | const target_sym = self.getSymbol(entry); |
| 4504 | assert(target_sym.undf()); | 4504 | assert(target_sym.undf()); |
| 4505 | try writer.writeInt(u32, iundefsym + ctx.imports_table.get(entry).?, .Little); | 4505 | try writer.writeInt(u32, iundefsym + ctx.imports_table.get(entry).?, .little); |
| 4506 | } | 4506 | } |
| 4507 | } | 4507 | } |
| 4508 | 4508 | ||
| ... | @@ -4513,9 +4513,9 @@ pub fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void { | ... | @@ -4513,9 +4513,9 @@ pub fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void { |
| 4513 | if (!self.got_table.lookup.contains(entry)) continue; | 4513 | if (!self.got_table.lookup.contains(entry)) continue; |
| 4514 | const target_sym = self.getSymbol(entry); | 4514 | const target_sym = self.getSymbol(entry); |
| 4515 | if (target_sym.undf()) { | 4515 | if (target_sym.undf()) { |
| 4516 | try writer.writeInt(u32, iundefsym + ctx.imports_table.get(entry).?, .Little); | 4516 | try writer.writeInt(u32, iundefsym + ctx.imports_table.get(entry).?, .little); |
| 4517 | } else { | 4517 | } else { |
| 4518 | try writer.writeInt(u32, macho.INDIRECT_SYMBOL_LOCAL, .Little); | 4518 | try writer.writeInt(u32, macho.INDIRECT_SYMBOL_LOCAL, .little); |
| 4519 | } | 4519 | } |
| 4520 | } | 4520 | } |
| 4521 | } | 4521 | } |
| ... | @@ -4527,7 +4527,7 @@ pub fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void { | ... | @@ -4527,7 +4527,7 @@ pub fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void { |
| 4527 | if (!self.stub_table.lookup.contains(entry)) continue; | 4527 | if (!self.stub_table.lookup.contains(entry)) continue; |
| 4528 | const target_sym = self.getSymbol(entry); | 4528 | const target_sym = self.getSymbol(entry); |
| 4529 | assert(target_sym.undf()); | 4529 | assert(target_sym.undf()); |
| 4530 | try writer.writeInt(u32, iundefsym + ctx.imports_table.get(entry).?, .Little); | 4530 | try writer.writeInt(u32, iundefsym + ctx.imports_table.get(entry).?, .little); |
| 4531 | } | 4531 | } |
| 4532 | } | 4532 | } |
| 4533 | 4533 |
src/link/MachO/Archive.zig+4-4| ... | @@ -123,7 +123,7 @@ fn parseName(allocator: Allocator, name_or_length: ar_hdr.NameOrLength, reader: | ... | @@ -123,7 +123,7 @@ fn parseName(allocator: Allocator, name_or_length: ar_hdr.NameOrLength, reader: |
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) !void { | 125 | fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) !void { |
| 126 | const symtab_size = try reader.readInt(u32, .Little); | 126 | const symtab_size = try reader.readInt(u32, .little); |
| 127 | var symtab = try allocator.alloc(u8, symtab_size); | 127 | var symtab = try allocator.alloc(u8, symtab_size); |
| 128 | defer allocator.free(symtab); | 128 | defer allocator.free(symtab); |
| 129 | 129 | ||
| ... | @@ -132,7 +132,7 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) ! | ... | @@ -132,7 +132,7 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) ! |
| 132 | return error.MalformedArchive; | 132 | return error.MalformedArchive; |
| 133 | }; | 133 | }; |
| 134 | 134 | ||
| 135 | const strtab_size = try reader.readInt(u32, .Little); | 135 | const strtab_size = try reader.readInt(u32, .little); |
| 136 | var strtab = try allocator.alloc(u8, strtab_size); | 136 | var strtab = try allocator.alloc(u8, strtab_size); |
| 137 | defer allocator.free(strtab); | 137 | defer allocator.free(strtab); |
| 138 | 138 | ||
| ... | @@ -145,11 +145,11 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) ! | ... | @@ -145,11 +145,11 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) ! |
| 145 | var symtab_reader = symtab_stream.reader(); | 145 | var symtab_reader = symtab_stream.reader(); |
| 146 | 146 | ||
| 147 | while (true) { | 147 | while (true) { |
| 148 | const n_strx = symtab_reader.readInt(u32, .Little) catch |err| switch (err) { | 148 | const n_strx = symtab_reader.readInt(u32, .little) catch |err| switch (err) { |
| 149 | error.EndOfStream => break, | 149 | error.EndOfStream => break, |
| 150 | else => |e| return e, | 150 | else => |e| return e, |
| 151 | }; | 151 | }; |
| 152 | const object_offset = try symtab_reader.readInt(u32, .Little); | 152 | const object_offset = try symtab_reader.readInt(u32, .little); |
| 153 | 153 | ||
| 154 | const sym_name = mem.sliceTo(@as([*:0]const u8, @ptrCast(strtab.ptr + n_strx)), 0); | 154 | const sym_name = mem.sliceTo(@as([*:0]const u8, @ptrCast(strtab.ptr + n_strx)), 0); |
| 155 | const owned_name = try allocator.dupe(u8, sym_name); | 155 | const owned_name = try allocator.dupe(u8, sym_name); |
src/link/MachO/Atom.zig+26-26| ... | @@ -443,9 +443,9 @@ pub fn parseRelocTarget(macho_file: *MachO, ctx: struct { | ... | @@ -443,9 +443,9 @@ pub fn parseRelocTarget(macho_file: *MachO, ctx: struct { |
| 443 | 443 | ||
| 444 | const address_in_section = if (ctx.rel.r_pcrel == 0) blk: { | 444 | const address_in_section = if (ctx.rel.r_pcrel == 0) blk: { |
| 445 | break :blk if (ctx.rel.r_length == 3) | 445 | break :blk if (ctx.rel.r_length == 3) |
| 446 | mem.readInt(u64, ctx.code[rel_offset..][0..8], .Little) | 446 | mem.readInt(u64, ctx.code[rel_offset..][0..8], .little) |
| 447 | else | 447 | else |
| 448 | mem.readInt(u32, ctx.code[rel_offset..][0..4], .Little); | 448 | mem.readInt(u32, ctx.code[rel_offset..][0..4], .little); |
| 449 | } else blk: { | 449 | } else blk: { |
| 450 | assert(macho_file.base.options.target.cpu.arch == .x86_64); | 450 | assert(macho_file.base.options.target.cpu.arch == .x86_64); |
| 451 | const correction: u3 = switch (@as(macho.reloc_type_x86_64, @enumFromInt(ctx.rel.r_type))) { | 451 | const correction: u3 = switch (@as(macho.reloc_type_x86_64, @enumFromInt(ctx.rel.r_type))) { |
| ... | @@ -455,7 +455,7 @@ pub fn parseRelocTarget(macho_file: *MachO, ctx: struct { | ... | @@ -455,7 +455,7 @@ pub fn parseRelocTarget(macho_file: *MachO, ctx: struct { |
| 455 | .X86_64_RELOC_SIGNED_4 => 4, | 455 | .X86_64_RELOC_SIGNED_4 => 4, |
| 456 | else => unreachable, | 456 | else => unreachable, |
| 457 | }; | 457 | }; |
| 458 | const addend = mem.readInt(i32, ctx.code[rel_offset..][0..4], .Little); | 458 | const addend = mem.readInt(i32, ctx.code[rel_offset..][0..4], .little); |
| 459 | const target_address = @as(i64, @intCast(ctx.base_addr)) + ctx.rel.r_address + 4 + correction + addend; | 459 | const target_address = @as(i64, @intCast(ctx.base_addr)) + ctx.rel.r_address + 4 + correction + addend; |
| 460 | break :blk @as(u64, @intCast(target_address)); | 460 | break :blk @as(u64, @intCast(target_address)); |
| 461 | }; | 461 | }; |
| ... | @@ -781,7 +781,7 @@ fn resolveRelocsArm64( | ... | @@ -781,7 +781,7 @@ fn resolveRelocsArm64( |
| 781 | ), code), | 781 | ), code), |
| 782 | }; | 782 | }; |
| 783 | inst.unconditional_branch_immediate.imm26 = @as(u26, @truncate(@as(u28, @bitCast(displacement >> 2)))); | 783 | inst.unconditional_branch_immediate.imm26 = @as(u26, @truncate(@as(u28, @bitCast(displacement >> 2)))); |
| 784 | mem.writeInt(u32, code, inst.toU32(), .Little); | 784 | mem.writeInt(u32, code, inst.toU32(), .little); |
| 785 | }, | 785 | }, |
| 786 | 786 | ||
| 787 | .ARM64_RELOC_PAGE21, | 787 | .ARM64_RELOC_PAGE21, |
| ... | @@ -802,7 +802,7 @@ fn resolveRelocsArm64( | ... | @@ -802,7 +802,7 @@ fn resolveRelocsArm64( |
| 802 | }; | 802 | }; |
| 803 | inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2)); | 803 | inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2)); |
| 804 | inst.pc_relative_address.immlo = @as(u2, @truncate(pages)); | 804 | inst.pc_relative_address.immlo = @as(u2, @truncate(pages)); |
| 805 | mem.writeInt(u32, code, inst.toU32(), .Little); | 805 | mem.writeInt(u32, code, inst.toU32(), .little); |
| 806 | addend = null; | 806 | addend = null; |
| 807 | }, | 807 | }, |
| 808 | 808 | ||
| ... | @@ -821,7 +821,7 @@ fn resolveRelocsArm64( | ... | @@ -821,7 +821,7 @@ fn resolveRelocsArm64( |
| 821 | ), code), | 821 | ), code), |
| 822 | }; | 822 | }; |
| 823 | inst.add_subtract_immediate.imm12 = off; | 823 | inst.add_subtract_immediate.imm12 = off; |
| 824 | mem.writeInt(u32, code, inst.toU32(), .Little); | 824 | mem.writeInt(u32, code, inst.toU32(), .little); |
| 825 | } else { | 825 | } else { |
| 826 | var inst = aarch64.Instruction{ | 826 | var inst = aarch64.Instruction{ |
| 827 | .load_store_register = mem.bytesToValue(meta.TagPayload( | 827 | .load_store_register = mem.bytesToValue(meta.TagPayload( |
| ... | @@ -839,7 +839,7 @@ fn resolveRelocsArm64( | ... | @@ -839,7 +839,7 @@ fn resolveRelocsArm64( |
| 839 | 3 => .load_store_64, | 839 | 3 => .load_store_64, |
| 840 | }); | 840 | }); |
| 841 | inst.load_store_register.offset = off; | 841 | inst.load_store_register.offset = off; |
| 842 | mem.writeInt(u32, code, inst.toU32(), .Little); | 842 | mem.writeInt(u32, code, inst.toU32(), .little); |
| 843 | } | 843 | } |
| 844 | addend = null; | 844 | addend = null; |
| 845 | }, | 845 | }, |
| ... | @@ -858,7 +858,7 @@ fn resolveRelocsArm64( | ... | @@ -858,7 +858,7 @@ fn resolveRelocsArm64( |
| 858 | ), code), | 858 | ), code), |
| 859 | }; | 859 | }; |
| 860 | inst.load_store_register.offset = off; | 860 | inst.load_store_register.offset = off; |
| 861 | mem.writeInt(u32, code, inst.toU32(), .Little); | 861 | mem.writeInt(u32, code, inst.toU32(), .little); |
| 862 | addend = null; | 862 | addend = null; |
| 863 | }, | 863 | }, |
| 864 | 864 | ||
| ... | @@ -918,7 +918,7 @@ fn resolveRelocsArm64( | ... | @@ -918,7 +918,7 @@ fn resolveRelocsArm64( |
| 918 | .sf = @as(u1, @truncate(reg_info.size)), | 918 | .sf = @as(u1, @truncate(reg_info.size)), |
| 919 | }, | 919 | }, |
| 920 | }; | 920 | }; |
| 921 | mem.writeInt(u32, code, inst.toU32(), .Little); | 921 | mem.writeInt(u32, code, inst.toU32(), .little); |
| 922 | addend = null; | 922 | addend = null; |
| 923 | }, | 923 | }, |
| 924 | 924 | ||
| ... | @@ -926,14 +926,14 @@ fn resolveRelocsArm64( | ... | @@ -926,14 +926,14 @@ fn resolveRelocsArm64( |
| 926 | relocs_log.debug(" | target_addr = 0x{x}", .{target_addr}); | 926 | relocs_log.debug(" | target_addr = 0x{x}", .{target_addr}); |
| 927 | const result = math.cast(i32, @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr))) orelse | 927 | const result = math.cast(i32, @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr))) orelse |
| 928 | return error.Overflow; | 928 | return error.Overflow; |
| 929 | mem.writeInt(u32, atom_code[rel_offset..][0..4], @as(u32, @bitCast(result)), .Little); | 929 | mem.writeInt(u32, atom_code[rel_offset..][0..4], @as(u32, @bitCast(result)), .little); |
| 930 | }, | 930 | }, |
| 931 | 931 | ||
| 932 | .ARM64_RELOC_UNSIGNED => { | 932 | .ARM64_RELOC_UNSIGNED => { |
| 933 | var ptr_addend = if (rel.r_length == 3) | 933 | var ptr_addend = if (rel.r_length == 3) |
| 934 | mem.readInt(i64, atom_code[rel_offset..][0..8], .Little) | 934 | mem.readInt(i64, atom_code[rel_offset..][0..8], .little) |
| 935 | else | 935 | else |
| 936 | mem.readInt(i32, atom_code[rel_offset..][0..4], .Little); | 936 | mem.readInt(i32, atom_code[rel_offset..][0..4], .little); |
| 937 | 937 | ||
| 938 | if (rel.r_extern == 0) { | 938 | if (rel.r_extern == 0) { |
| 939 | const base_addr = if (target.sym_index >= object.source_address_lookup.len) | 939 | const base_addr = if (target.sym_index >= object.source_address_lookup.len) |
| ... | @@ -954,9 +954,9 @@ fn resolveRelocsArm64( | ... | @@ -954,9 +954,9 @@ fn resolveRelocsArm64( |
| 954 | relocs_log.debug(" | target_addr = 0x{x}", .{result}); | 954 | relocs_log.debug(" | target_addr = 0x{x}", .{result}); |
| 955 | 955 | ||
| 956 | if (rel.r_length == 3) { | 956 | if (rel.r_length == 3) { |
| 957 | mem.writeInt(u64, atom_code[rel_offset..][0..8], @as(u64, @bitCast(result)), .Little); | 957 | mem.writeInt(u64, atom_code[rel_offset..][0..8], @as(u64, @bitCast(result)), .little); |
| 958 | } else { | 958 | } else { |
| 959 | mem.writeInt(u32, atom_code[rel_offset..][0..4], @as(u32, @truncate(@as(u64, @bitCast(result)))), .Little); | 959 | mem.writeInt(u32, atom_code[rel_offset..][0..4], @as(u32, @truncate(@as(u64, @bitCast(result)))), .little); |
| 960 | } | 960 | } |
| 961 | 961 | ||
| 962 | subtractor = null; | 962 | subtractor = null; |
| ... | @@ -1045,25 +1045,25 @@ fn resolveRelocsX86( | ... | @@ -1045,25 +1045,25 @@ fn resolveRelocsX86( |
| 1045 | 1045 | ||
| 1046 | switch (rel_type) { | 1046 | switch (rel_type) { |
| 1047 | .X86_64_RELOC_BRANCH => { | 1047 | .X86_64_RELOC_BRANCH => { |
| 1048 | const addend = mem.readInt(i32, atom_code[rel_offset..][0..4], .Little); | 1048 | const addend = mem.readInt(i32, atom_code[rel_offset..][0..4], .little); |
| 1049 | const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend)); | 1049 | const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend)); |
| 1050 | relocs_log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr}); | 1050 | relocs_log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr}); |
| 1051 | const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0); | 1051 | const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0); |
| 1052 | mem.writeInt(i32, atom_code[rel_offset..][0..4], disp, .Little); | 1052 | mem.writeInt(i32, atom_code[rel_offset..][0..4], disp, .little); |
| 1053 | }, | 1053 | }, |
| 1054 | 1054 | ||
| 1055 | .X86_64_RELOC_GOT, | 1055 | .X86_64_RELOC_GOT, |
| 1056 | .X86_64_RELOC_GOT_LOAD, | 1056 | .X86_64_RELOC_GOT_LOAD, |
| 1057 | => { | 1057 | => { |
| 1058 | const addend = mem.readInt(i32, atom_code[rel_offset..][0..4], .Little); | 1058 | const addend = mem.readInt(i32, atom_code[rel_offset..][0..4], .little); |
| 1059 | const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend)); | 1059 | const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend)); |
| 1060 | relocs_log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr}); | 1060 | relocs_log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr}); |
| 1061 | const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0); | 1061 | const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0); |
| 1062 | mem.writeInt(i32, atom_code[rel_offset..][0..4], disp, .Little); | 1062 | mem.writeInt(i32, atom_code[rel_offset..][0..4], disp, .little); |
| 1063 | }, | 1063 | }, |
| 1064 | 1064 | ||
| 1065 | .X86_64_RELOC_TLV => { | 1065 | .X86_64_RELOC_TLV => { |
| 1066 | const addend = mem.readInt(i32, atom_code[rel_offset..][0..4], .Little); | 1066 | const addend = mem.readInt(i32, atom_code[rel_offset..][0..4], .little); |
| 1067 | const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend)); | 1067 | const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend)); |
| 1068 | relocs_log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr}); | 1068 | relocs_log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr}); |
| 1069 | const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0); | 1069 | const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0); |
| ... | @@ -1073,7 +1073,7 @@ fn resolveRelocsX86( | ... | @@ -1073,7 +1073,7 @@ fn resolveRelocsX86( |
| 1073 | atom_code[rel_offset - 2] = 0x8d; | 1073 | atom_code[rel_offset - 2] = 0x8d; |
| 1074 | } | 1074 | } |
| 1075 | 1075 | ||
| 1076 | mem.writeInt(i32, atom_code[rel_offset..][0..4], disp, .Little); | 1076 | mem.writeInt(i32, atom_code[rel_offset..][0..4], disp, .little); |
| 1077 | }, | 1077 | }, |
| 1078 | 1078 | ||
| 1079 | .X86_64_RELOC_SIGNED, | 1079 | .X86_64_RELOC_SIGNED, |
| ... | @@ -1088,7 +1088,7 @@ fn resolveRelocsX86( | ... | @@ -1088,7 +1088,7 @@ fn resolveRelocsX86( |
| 1088 | .X86_64_RELOC_SIGNED_4 => 4, | 1088 | .X86_64_RELOC_SIGNED_4 => 4, |
| 1089 | else => unreachable, | 1089 | else => unreachable, |
| 1090 | }; | 1090 | }; |
| 1091 | var addend = mem.readInt(i32, atom_code[rel_offset..][0..4], .Little) + correction; | 1091 | var addend = mem.readInt(i32, atom_code[rel_offset..][0..4], .little) + correction; |
| 1092 | 1092 | ||
| 1093 | if (rel.r_extern == 0) { | 1093 | if (rel.r_extern == 0) { |
| 1094 | const base_addr = if (target.sym_index >= object.source_address_lookup.len) | 1094 | const base_addr = if (target.sym_index >= object.source_address_lookup.len) |
| ... | @@ -1104,14 +1104,14 @@ fn resolveRelocsX86( | ... | @@ -1104,14 +1104,14 @@ fn resolveRelocsX86( |
| 1104 | relocs_log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr}); | 1104 | relocs_log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr}); |
| 1105 | 1105 | ||
| 1106 | const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, correction); | 1106 | const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, correction); |
| 1107 | mem.writeInt(i32, atom_code[rel_offset..][0..4], disp, .Little); | 1107 | mem.writeInt(i32, atom_code[rel_offset..][0..4], disp, .little); |
| 1108 | }, | 1108 | }, |
| 1109 | 1109 | ||
| 1110 | .X86_64_RELOC_UNSIGNED => { | 1110 | .X86_64_RELOC_UNSIGNED => { |
| 1111 | var addend = if (rel.r_length == 3) | 1111 | var addend = if (rel.r_length == 3) |
| 1112 | mem.readInt(i64, atom_code[rel_offset..][0..8], .Little) | 1112 | mem.readInt(i64, atom_code[rel_offset..][0..8], .little) |
| 1113 | else | 1113 | else |
| 1114 | mem.readInt(i32, atom_code[rel_offset..][0..4], .Little); | 1114 | mem.readInt(i32, atom_code[rel_offset..][0..4], .little); |
| 1115 | 1115 | ||
| 1116 | if (rel.r_extern == 0) { | 1116 | if (rel.r_extern == 0) { |
| 1117 | const base_addr = if (target.sym_index >= object.source_address_lookup.len) | 1117 | const base_addr = if (target.sym_index >= object.source_address_lookup.len) |
| ... | @@ -1132,9 +1132,9 @@ fn resolveRelocsX86( | ... | @@ -1132,9 +1132,9 @@ fn resolveRelocsX86( |
| 1132 | relocs_log.debug(" | target_addr = 0x{x}", .{result}); | 1132 | relocs_log.debug(" | target_addr = 0x{x}", .{result}); |
| 1133 | 1133 | ||
| 1134 | if (rel.r_length == 3) { | 1134 | if (rel.r_length == 3) { |
| 1135 | mem.writeInt(u64, atom_code[rel_offset..][0..8], @as(u64, @bitCast(result)), .Little); | 1135 | mem.writeInt(u64, atom_code[rel_offset..][0..8], @as(u64, @bitCast(result)), .little); |
| 1136 | } else { | 1136 | } else { |
| 1137 | mem.writeInt(u32, atom_code[rel_offset..][0..4], @as(u32, @truncate(@as(u64, @bitCast(result)))), .Little); | 1137 | mem.writeInt(u32, atom_code[rel_offset..][0..4], @as(u32, @truncate(@as(u64, @bitCast(result)))), .little); |
| 1138 | } | 1138 | } |
| 1139 | 1139 | ||
| 1140 | subtractor = null; | 1140 | subtractor = null; |
src/link/MachO/CodeSignature.zig+29-29| ... | @@ -115,14 +115,14 @@ pub fn writeAdhocSignature( | ... | @@ -115,14 +115,14 @@ pub fn writeAdhocSignature( |
| 115 | self.code_directory.inner.length = self.code_directory.size(); | 115 | self.code_directory.inner.length = self.code_directory.size(); |
| 116 | header.length += self.code_directory.size(); | 116 | header.length += self.code_directory.size(); |
| 117 | 117 | ||
| 118 | try writer.writeInt(u32, header.magic, .Big); | 118 | try writer.writeInt(u32, header.magic, .big); |
| 119 | try writer.writeInt(u32, header.length, .Big); | 119 | try writer.writeInt(u32, header.length, .big); |
| 120 | try writer.writeInt(u32, header.count, .Big); | 120 | try writer.writeInt(u32, header.count, .big); |
| 121 | 121 | ||
| 122 | var offset: u32 = @sizeOf(macho.SuperBlob) + @sizeOf(macho.BlobIndex) * @as(u32, @intCast(blobs.items.len)); | 122 | var offset: u32 = @sizeOf(macho.SuperBlob) + @sizeOf(macho.BlobIndex) * @as(u32, @intCast(blobs.items.len)); |
| 123 | for (blobs.items) |blob| { | 123 | for (blobs.items) |blob| { |
| 124 | try writer.writeInt(u32, blob.slotType(), .Big); | 124 | try writer.writeInt(u32, blob.slotType(), .big); |
| 125 | try writer.writeInt(u32, offset, .Big); | 125 | try writer.writeInt(u32, offset, .big); |
| 126 | offset += blob.size(); | 126 | offset += blob.size(); |
| 127 | } | 127 | } |
| 128 | 128 | ||
| ... | @@ -272,27 +272,27 @@ const CodeDirectory = struct { | ... | @@ -272,27 +272,27 @@ const CodeDirectory = struct { |
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | fn write(self: CodeDirectory, writer: anytype) !void { | 274 | fn write(self: CodeDirectory, writer: anytype) !void { |
| 275 | try writer.writeInt(u32, self.inner.magic, .Big); | 275 | try writer.writeInt(u32, self.inner.magic, .big); |
| 276 | try writer.writeInt(u32, self.inner.length, .Big); | 276 | try writer.writeInt(u32, self.inner.length, .big); |
| 277 | try writer.writeInt(u32, self.inner.version, .Big); | 277 | try writer.writeInt(u32, self.inner.version, .big); |
| 278 | try writer.writeInt(u32, self.inner.flags, .Big); | 278 | try writer.writeInt(u32, self.inner.flags, .big); |
| 279 | try writer.writeInt(u32, self.inner.hashOffset, .Big); | 279 | try writer.writeInt(u32, self.inner.hashOffset, .big); |
| 280 | try writer.writeInt(u32, self.inner.identOffset, .Big); | 280 | try writer.writeInt(u32, self.inner.identOffset, .big); |
| 281 | try writer.writeInt(u32, self.inner.nSpecialSlots, .Big); | 281 | try writer.writeInt(u32, self.inner.nSpecialSlots, .big); |
| 282 | try writer.writeInt(u32, self.inner.nCodeSlots, .Big); | 282 | try writer.writeInt(u32, self.inner.nCodeSlots, .big); |
| 283 | try writer.writeInt(u32, self.inner.codeLimit, .Big); | 283 | try writer.writeInt(u32, self.inner.codeLimit, .big); |
| 284 | try writer.writeByte(self.inner.hashSize); | 284 | try writer.writeByte(self.inner.hashSize); |
| 285 | try writer.writeByte(self.inner.hashType); | 285 | try writer.writeByte(self.inner.hashType); |
| 286 | try writer.writeByte(self.inner.platform); | 286 | try writer.writeByte(self.inner.platform); |
| 287 | try writer.writeByte(self.inner.pageSize); | 287 | try writer.writeByte(self.inner.pageSize); |
| 288 | try writer.writeInt(u32, self.inner.spare2, .Big); | 288 | try writer.writeInt(u32, self.inner.spare2, .big); |
| 289 | try writer.writeInt(u32, self.inner.scatterOffset, .Big); | 289 | try writer.writeInt(u32, self.inner.scatterOffset, .big); |
| 290 | try writer.writeInt(u32, self.inner.teamOffset, .Big); | 290 | try writer.writeInt(u32, self.inner.teamOffset, .big); |
| 291 | try writer.writeInt(u32, self.inner.spare3, .Big); | 291 | try writer.writeInt(u32, self.inner.spare3, .big); |
| 292 | try writer.writeInt(u64, self.inner.codeLimit64, .Big); | 292 | try writer.writeInt(u64, self.inner.codeLimit64, .big); |
| 293 | try writer.writeInt(u64, self.inner.execSegBase, .Big); | 293 | try writer.writeInt(u64, self.inner.execSegBase, .big); |
| 294 | try writer.writeInt(u64, self.inner.execSegLimit, .Big); | 294 | try writer.writeInt(u64, self.inner.execSegLimit, .big); |
| 295 | try writer.writeInt(u64, self.inner.execSegFlags, .Big); | 295 | try writer.writeInt(u64, self.inner.execSegFlags, .big); |
| 296 | 296 | ||
| 297 | try writer.writeAll(self.ident); | 297 | try writer.writeAll(self.ident); |
| 298 | try writer.writeByte(0); | 298 | try writer.writeByte(0); |
| ... | @@ -325,9 +325,9 @@ const Requirements = struct { | ... | @@ -325,9 +325,9 @@ const Requirements = struct { |
| 325 | } | 325 | } |
| 326 | 326 | ||
| 327 | fn write(self: Requirements, writer: anytype) !void { | 327 | fn write(self: Requirements, writer: anytype) !void { |
| 328 | try writer.writeInt(u32, macho.CSMAGIC_REQUIREMENTS, .Big); | 328 | try writer.writeInt(u32, macho.CSMAGIC_REQUIREMENTS, .big); |
| 329 | try writer.writeInt(u32, self.size(), .Big); | 329 | try writer.writeInt(u32, self.size(), .big); |
| 330 | try writer.writeInt(u32, 0, .Big); | 330 | try writer.writeInt(u32, 0, .big); |
| 331 | } | 331 | } |
| 332 | }; | 332 | }; |
| 333 | 333 | ||
| ... | @@ -348,8 +348,8 @@ const Entitlements = struct { | ... | @@ -348,8 +348,8 @@ const Entitlements = struct { |
| 348 | } | 348 | } |
| 349 | 349 | ||
| 350 | fn write(self: Entitlements, writer: anytype) !void { | 350 | fn write(self: Entitlements, writer: anytype) !void { |
| 351 | try writer.writeInt(u32, macho.CSMAGIC_EMBEDDED_ENTITLEMENTS, .Big); | 351 | try writer.writeInt(u32, macho.CSMAGIC_EMBEDDED_ENTITLEMENTS, .big); |
| 352 | try writer.writeInt(u32, self.size(), .Big); | 352 | try writer.writeInt(u32, self.size(), .big); |
| 353 | try writer.writeAll(self.inner); | 353 | try writer.writeAll(self.inner); |
| 354 | } | 354 | } |
| 355 | }; | 355 | }; |
| ... | @@ -371,8 +371,8 @@ const Signature = struct { | ... | @@ -371,8 +371,8 @@ const Signature = struct { |
| 371 | } | 371 | } |
| 372 | 372 | ||
| 373 | fn write(self: Signature, writer: anytype) !void { | 373 | fn write(self: Signature, writer: anytype) !void { |
| 374 | try writer.writeInt(u32, macho.CSMAGIC_BLOBWRAPPER, .Big); | 374 | try writer.writeInt(u32, macho.CSMAGIC_BLOBWRAPPER, .big); |
| 375 | try writer.writeInt(u32, self.size(), .Big); | 375 | try writer.writeInt(u32, self.size(), .big); |
| 376 | } | 376 | } |
| 377 | }; | 377 | }; |
| 378 | 378 |
src/link/MachO/DwarfInfo.zig+17-17| ... | @@ -121,19 +121,19 @@ pub const CompileUnit = struct { | ... | @@ -121,19 +121,19 @@ pub const CompileUnit = struct { |
| 121 | address_size: u8, | 121 | address_size: u8, |
| 122 | 122 | ||
| 123 | fn read(reader: anytype) !Header { | 123 | fn read(reader: anytype) !Header { |
| 124 | var length: u64 = try reader.readInt(u32, .Little); | 124 | var length: u64 = try reader.readInt(u32, .little); |
| 125 | 125 | ||
| 126 | const is_64bit = length == 0xffffffff; | 126 | const is_64bit = length == 0xffffffff; |
| 127 | if (is_64bit) { | 127 | if (is_64bit) { |
| 128 | length = try reader.readInt(u64, .Little); | 128 | length = try reader.readInt(u64, .little); |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | const version = try reader.readInt(u16, .Little); | 131 | const version = try reader.readInt(u16, .little); |
| 132 | const debug_abbrev_offset = if (is_64bit) | 132 | const debug_abbrev_offset = if (is_64bit) |
| 133 | try reader.readInt(u64, .Little) | 133 | try reader.readInt(u64, .little) |
| 134 | else | 134 | else |
| 135 | try reader.readInt(u32, .Little); | 135 | try reader.readInt(u32, .little); |
| 136 | const address_size = try reader.readInt(u8, .Little); | 136 | const address_size = try reader.readInt(u8, .little); |
| 137 | 137 | ||
| 138 | return Header{ | 138 | return Header{ |
| 139 | .is_64bit = is_64bit, | 139 | .is_64bit = is_64bit, |
| ... | @@ -251,9 +251,9 @@ pub const Attribute = struct { | ... | @@ -251,9 +251,9 @@ pub const Attribute = struct { |
| 251 | }, | 251 | }, |
| 252 | dwarf.FORM.strp => { | 252 | dwarf.FORM.strp => { |
| 253 | const off = if (cuh.is_64bit) | 253 | const off = if (cuh.is_64bit) |
| 254 | mem.readInt(u64, debug_info[0..8], .Little) | 254 | mem.readInt(u64, debug_info[0..8], .little) |
| 255 | else | 255 | else |
| 256 | mem.readInt(u32, debug_info[0..4], .Little); | 256 | mem.readInt(u32, debug_info[0..4], .little); |
| 257 | return ctx.getString(off); | 257 | return ctx.getString(off); |
| 258 | }, | 258 | }, |
| 259 | else => return null, | 259 | else => return null, |
| ... | @@ -267,9 +267,9 @@ pub const Attribute = struct { | ... | @@ -267,9 +267,9 @@ pub const Attribute = struct { |
| 267 | 267 | ||
| 268 | return switch (self.form) { | 268 | return switch (self.form) { |
| 269 | dwarf.FORM.data1 => debug_info[0], | 269 | dwarf.FORM.data1 => debug_info[0], |
| 270 | dwarf.FORM.data2 => mem.readInt(u16, debug_info[0..2], .Little), | 270 | dwarf.FORM.data2 => mem.readInt(u16, debug_info[0..2], .little), |
| 271 | dwarf.FORM.data4 => mem.readInt(u32, debug_info[0..4], .Little), | 271 | dwarf.FORM.data4 => mem.readInt(u32, debug_info[0..4], .little), |
| 272 | dwarf.FORM.data8 => mem.readInt(u64, debug_info[0..8], .Little), | 272 | dwarf.FORM.data8 => mem.readInt(u64, debug_info[0..8], .little), |
| 273 | dwarf.FORM.udata => try leb.readULEB128(u64, reader), | 273 | dwarf.FORM.udata => try leb.readULEB128(u64, reader), |
| 274 | dwarf.FORM.sdata => try leb.readILEB128(i64, reader), | 274 | dwarf.FORM.sdata => try leb.readILEB128(i64, reader), |
| 275 | else => null, | 275 | else => null, |
| ... | @@ -281,9 +281,9 @@ pub const Attribute = struct { | ... | @@ -281,9 +281,9 @@ pub const Attribute = struct { |
| 281 | const debug_info = self.getDebugInfo(ctx); | 281 | const debug_info = self.getDebugInfo(ctx); |
| 282 | return switch (cuh.address_size) { | 282 | return switch (cuh.address_size) { |
| 283 | 1 => debug_info[0], | 283 | 1 => debug_info[0], |
| 284 | 2 => mem.readInt(u16, debug_info[0..2], .Little), | 284 | 2 => mem.readInt(u16, debug_info[0..2], .little), |
| 285 | 4 => mem.readInt(u32, debug_info[0..4], .Little), | 285 | 4 => mem.readInt(u32, debug_info[0..4], .little), |
| 286 | 8 => mem.readInt(u64, debug_info[0..8], .Little), | 286 | 8 => mem.readInt(u64, debug_info[0..8], .little), |
| 287 | else => unreachable, | 287 | else => unreachable, |
| 288 | }; | 288 | }; |
| 289 | } | 289 | } |
| ... | @@ -380,9 +380,9 @@ fn findFormSize(self: DwarfInfo, form: u64, di_off: usize, cuh: CompileUnit.Head | ... | @@ -380,9 +380,9 @@ fn findFormSize(self: DwarfInfo, form: u64, di_off: usize, cuh: CompileUnit.Head |
| 380 | dwarf.FORM.block, | 380 | dwarf.FORM.block, |
| 381 | => { | 381 | => { |
| 382 | const len: u64 = switch (form) { | 382 | const len: u64 = switch (form) { |
| 383 | dwarf.FORM.block1 => try reader.readInt(u8, .Little), | 383 | dwarf.FORM.block1 => try reader.readInt(u8, .little), |
| 384 | dwarf.FORM.block2 => try reader.readInt(u16, .Little), | 384 | dwarf.FORM.block2 => try reader.readInt(u16, .little), |
| 385 | dwarf.FORM.block4 => try reader.readInt(u32, .Little), | 385 | dwarf.FORM.block4 => try reader.readInt(u32, .little), |
| 386 | dwarf.FORM.block => try leb.readULEB128(u64, reader), | 386 | dwarf.FORM.block => try leb.readULEB128(u64, reader), |
| 387 | else => unreachable, | 387 | else => unreachable, |
| 388 | }; | 388 | }; |
src/link/MachO/Relocation.zig+9-9| ... | @@ -128,7 +128,7 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: [] | ... | @@ -128,7 +128,7 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: [] |
| 128 | ), buffer[0..4]), | 128 | ), buffer[0..4]), |
| 129 | }; | 129 | }; |
| 130 | inst.unconditional_branch_immediate.imm26 = @as(u26, @truncate(@as(u28, @bitCast(displacement >> 2)))); | 130 | inst.unconditional_branch_immediate.imm26 = @as(u26, @truncate(@as(u28, @bitCast(displacement >> 2)))); |
| 131 | mem.writeInt(u32, buffer[0..4], inst.toU32(), .Little); | 131 | mem.writeInt(u32, buffer[0..4], inst.toU32(), .little); |
| 132 | }, | 132 | }, |
| 133 | .page, .got_page => { | 133 | .page, .got_page => { |
| 134 | const source_page = @as(i32, @intCast(source_addr >> 12)); | 134 | const source_page = @as(i32, @intCast(source_addr >> 12)); |
| ... | @@ -142,7 +142,7 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: [] | ... | @@ -142,7 +142,7 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: [] |
| 142 | }; | 142 | }; |
| 143 | inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2)); | 143 | inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2)); |
| 144 | inst.pc_relative_address.immlo = @as(u2, @truncate(pages)); | 144 | inst.pc_relative_address.immlo = @as(u2, @truncate(pages)); |
| 145 | mem.writeInt(u32, buffer[0..4], inst.toU32(), .Little); | 145 | mem.writeInt(u32, buffer[0..4], inst.toU32(), .little); |
| 146 | }, | 146 | }, |
| 147 | .pageoff, .got_pageoff => { | 147 | .pageoff, .got_pageoff => { |
| 148 | const narrowed = @as(u12, @truncate(@as(u64, @intCast(target_addr)))); | 148 | const narrowed = @as(u12, @truncate(@as(u64, @intCast(target_addr)))); |
| ... | @@ -154,7 +154,7 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: [] | ... | @@ -154,7 +154,7 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: [] |
| 154 | ), buffer[0..4]), | 154 | ), buffer[0..4]), |
| 155 | }; | 155 | }; |
| 156 | inst.add_subtract_immediate.imm12 = narrowed; | 156 | inst.add_subtract_immediate.imm12 = narrowed; |
| 157 | mem.writeInt(u32, buffer[0..4], inst.toU32(), .Little); | 157 | mem.writeInt(u32, buffer[0..4], inst.toU32(), .little); |
| 158 | } else { | 158 | } else { |
| 159 | var inst = aarch64.Instruction{ | 159 | var inst = aarch64.Instruction{ |
| 160 | .load_store_register = mem.bytesToValue(meta.TagPayload( | 160 | .load_store_register = mem.bytesToValue(meta.TagPayload( |
| ... | @@ -176,12 +176,12 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: [] | ... | @@ -176,12 +176,12 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: [] |
| 176 | } | 176 | } |
| 177 | }; | 177 | }; |
| 178 | inst.load_store_register.offset = offset; | 178 | inst.load_store_register.offset = offset; |
| 179 | mem.writeInt(u32, buffer[0..4], inst.toU32(), .Little); | 179 | mem.writeInt(u32, buffer[0..4], inst.toU32(), .little); |
| 180 | } | 180 | } |
| 181 | }, | 181 | }, |
| 182 | .tlv_initializer, .unsigned => switch (self.length) { | 182 | .tlv_initializer, .unsigned => switch (self.length) { |
| 183 | 2 => mem.writeInt(u32, buffer[0..4], @as(u32, @truncate(@as(u64, @bitCast(target_addr)))), .Little), | 183 | 2 => mem.writeInt(u32, buffer[0..4], @as(u32, @truncate(@as(u64, @bitCast(target_addr)))), .little), |
| 184 | 3 => mem.writeInt(u64, buffer[0..8], @as(u64, @bitCast(target_addr)), .Little), | 184 | 3 => mem.writeInt(u64, buffer[0..8], @as(u64, @bitCast(target_addr)), .little), |
| 185 | else => unreachable, | 185 | else => unreachable, |
| 186 | }, | 186 | }, |
| 187 | .got, .signed, .tlv => unreachable, // Invalid target architecture. | 187 | .got, .signed, .tlv => unreachable, // Invalid target architecture. |
| ... | @@ -192,15 +192,15 @@ fn resolveX8664(self: Relocation, source_addr: u64, target_addr: i64, code: []u8 | ... | @@ -192,15 +192,15 @@ fn resolveX8664(self: Relocation, source_addr: u64, target_addr: i64, code: []u8 |
| 192 | switch (self.type) { | 192 | switch (self.type) { |
| 193 | .branch, .got, .tlv, .signed => { | 193 | .branch, .got, .tlv, .signed => { |
| 194 | const displacement = @as(i32, @intCast(@as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr)) - 4)); | 194 | const displacement = @as(i32, @intCast(@as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr)) - 4)); |
| 195 | mem.writeInt(u32, code[self.offset..][0..4], @as(u32, @bitCast(displacement)), .Little); | 195 | mem.writeInt(u32, code[self.offset..][0..4], @as(u32, @bitCast(displacement)), .little); |
| 196 | }, | 196 | }, |
| 197 | .tlv_initializer, .unsigned => { | 197 | .tlv_initializer, .unsigned => { |
| 198 | switch (self.length) { | 198 | switch (self.length) { |
| 199 | 2 => { | 199 | 2 => { |
| 200 | mem.writeInt(u32, code[self.offset..][0..4], @as(u32, @truncate(@as(u64, @bitCast(target_addr)))), .Little); | 200 | mem.writeInt(u32, code[self.offset..][0..4], @as(u32, @truncate(@as(u64, @bitCast(target_addr)))), .little); |
| 201 | }, | 201 | }, |
| 202 | 3 => { | 202 | 3 => { |
| 203 | mem.writeInt(u64, code[self.offset..][0..8], @as(u64, @bitCast(target_addr)), .Little); | 203 | mem.writeInt(u64, code[self.offset..][0..8], @as(u64, @bitCast(target_addr)), .little); |
| 204 | }, | 204 | }, |
| 205 | else => unreachable, | 205 | else => unreachable, |
| 206 | } | 206 | } |
src/link/MachO/UnwindInfo.zig+1-1| ... | @@ -149,7 +149,7 @@ const Page = struct { | ... | @@ -149,7 +149,7 @@ const Page = struct { |
| 149 | 149 | ||
| 150 | for (page.page_encodings[0..page.page_encodings_count]) |record_id| { | 150 | for (page.page_encodings[0..page.page_encodings_count]) |record_id| { |
| 151 | const enc = info.records.items[record_id].compactUnwindEncoding; | 151 | const enc = info.records.items[record_id].compactUnwindEncoding; |
| 152 | try writer.writeInt(u32, enc, .Little); | 152 | try writer.writeInt(u32, enc, .little); |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | assert(page.count > 0); | 155 | assert(page.count > 0); |
src/link/MachO/eh_frame.zig+26-26| ... | @@ -209,7 +209,7 @@ pub fn write(macho_file: *MachO, unwind_info: *UnwindInfo) !void { | ... | @@ -209,7 +209,7 @@ pub fn write(macho_file: *MachO, unwind_info: *UnwindInfo) !void { |
| 209 | const writer = buffer.writer(); | 209 | const writer = buffer.writer(); |
| 210 | 210 | ||
| 211 | for (eh_records.values()) |record| { | 211 | for (eh_records.values()) |record| { |
| 212 | try writer.writeInt(u32, record.size, .Little); | 212 | try writer.writeInt(u32, record.size, .little); |
| 213 | try buffer.appendSlice(record.data); | 213 | try buffer.appendSlice(record.data); |
| 214 | } | 214 | } |
| 215 | 215 | ||
| ... | @@ -259,7 +259,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { | ... | @@ -259,7 +259,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { |
| 259 | base_offset: u64, | 259 | base_offset: u64, |
| 260 | }) u64 { | 260 | }) u64 { |
| 261 | assert(rec.tag == .fde); | 261 | assert(rec.tag == .fde); |
| 262 | const addend = mem.readInt(i64, rec.data[4..][0..8], .Little); | 262 | const addend = mem.readInt(i64, rec.data[4..][0..8], .little); |
| 263 | return @as(u64, @intCast(@as(i64, @intCast(ctx.base_addr + ctx.base_offset + 8)) + addend)); | 263 | return @as(u64, @intCast(@as(i64, @intCast(ctx.base_addr + ctx.base_offset + 8)) + addend)); |
| 264 | } | 264 | } |
| 265 | 265 | ||
| ... | @@ -269,7 +269,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { | ... | @@ -269,7 +269,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { |
| 269 | }) !void { | 269 | }) !void { |
| 270 | assert(rec.tag == .fde); | 270 | assert(rec.tag == .fde); |
| 271 | const addend = @as(i64, @intCast(value)) - @as(i64, @intCast(ctx.base_addr + ctx.base_offset + 8)); | 271 | const addend = @as(i64, @intCast(value)) - @as(i64, @intCast(ctx.base_addr + ctx.base_offset + 8)); |
| 272 | mem.writeInt(i64, rec.data[4..][0..8], addend, .Little); | 272 | mem.writeInt(i64, rec.data[4..][0..8], addend, .little); |
| 273 | } | 273 | } |
| 274 | 274 | ||
| 275 | pub fn getPersonalityPointerReloc( | 275 | pub fn getPersonalityPointerReloc( |
| ... | @@ -343,13 +343,13 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { | ... | @@ -343,13 +343,13 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { |
| 343 | const target_addr = macho_file.getGotEntryAddress(target).?; | 343 | const target_addr = macho_file.getGotEntryAddress(target).?; |
| 344 | const result = math.cast(i32, @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr))) orelse | 344 | const result = math.cast(i32, @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr))) orelse |
| 345 | return error.Overflow; | 345 | return error.Overflow; |
| 346 | mem.writeInt(i32, rec.data[rel_offset..][0..4], result, .Little); | 346 | mem.writeInt(i32, rec.data[rel_offset..][0..4], result, .little); |
| 347 | }, | 347 | }, |
| 348 | .ARM64_RELOC_UNSIGNED => { | 348 | .ARM64_RELOC_UNSIGNED => { |
| 349 | assert(rel.r_extern == 1); | 349 | assert(rel.r_extern == 1); |
| 350 | const target_addr = Atom.getRelocTargetAddress(macho_file, target, false); | 350 | const target_addr = Atom.getRelocTargetAddress(macho_file, target, false); |
| 351 | const result = @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr)); | 351 | const result = @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr)); |
| 352 | mem.writeInt(i64, rec.data[rel_offset..][0..8], @as(i64, @intCast(result)), .Little); | 352 | mem.writeInt(i64, rec.data[rel_offset..][0..8], @as(i64, @intCast(result)), .little); |
| 353 | }, | 353 | }, |
| 354 | else => unreachable, | 354 | else => unreachable, |
| 355 | } | 355 | } |
| ... | @@ -359,10 +359,10 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { | ... | @@ -359,10 +359,10 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { |
| 359 | switch (rel_type) { | 359 | switch (rel_type) { |
| 360 | .X86_64_RELOC_GOT => { | 360 | .X86_64_RELOC_GOT => { |
| 361 | const target_addr = macho_file.getGotEntryAddress(target).?; | 361 | const target_addr = macho_file.getGotEntryAddress(target).?; |
| 362 | const addend = mem.readInt(i32, rec.data[rel_offset..][0..4], .Little); | 362 | const addend = mem.readInt(i32, rec.data[rel_offset..][0..4], .little); |
| 363 | const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend)); | 363 | const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend)); |
| 364 | const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0); | 364 | const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0); |
| 365 | mem.writeInt(i32, rec.data[rel_offset..][0..4], disp, .Little); | 365 | mem.writeInt(i32, rec.data[rel_offset..][0..4], disp, .little); |
| 366 | }, | 366 | }, |
| 367 | else => unreachable, | 367 | else => unreachable, |
| 368 | } | 368 | } |
| ... | @@ -375,7 +375,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { | ... | @@ -375,7 +375,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { |
| 375 | pub fn getCiePointerSource(rec: Record, object_id: u32, macho_file: *MachO, offset: u32) u32 { | 375 | pub fn getCiePointerSource(rec: Record, object_id: u32, macho_file: *MachO, offset: u32) u32 { |
| 376 | assert(rec.tag == .fde); | 376 | assert(rec.tag == .fde); |
| 377 | const cpu_arch = macho_file.base.options.target.cpu.arch; | 377 | const cpu_arch = macho_file.base.options.target.cpu.arch; |
| 378 | const addend = mem.readInt(u32, rec.data[0..4], .Little); | 378 | const addend = mem.readInt(u32, rec.data[0..4], .little); |
| 379 | switch (cpu_arch) { | 379 | switch (cpu_arch) { |
| 380 | .aarch64 => { | 380 | .aarch64 => { |
| 381 | const relocs = getRelocs(macho_file, object_id, offset); | 381 | const relocs = getRelocs(macho_file, object_id, offset); |
| ... | @@ -397,12 +397,12 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { | ... | @@ -397,12 +397,12 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { |
| 397 | 397 | ||
| 398 | pub fn getCiePointer(rec: Record) u32 { | 398 | pub fn getCiePointer(rec: Record) u32 { |
| 399 | assert(rec.tag == .fde); | 399 | assert(rec.tag == .fde); |
| 400 | return mem.readInt(u32, rec.data[0..4], .Little); | 400 | return mem.readInt(u32, rec.data[0..4], .little); |
| 401 | } | 401 | } |
| 402 | 402 | ||
| 403 | pub fn setCiePointer(rec: *Record, ptr: u32) void { | 403 | pub fn setCiePointer(rec: *Record, ptr: u32) void { |
| 404 | assert(rec.tag == .fde); | 404 | assert(rec.tag == .fde); |
| 405 | mem.writeInt(u32, rec.data[0..4], ptr, .Little); | 405 | mem.writeInt(u32, rec.data[0..4], ptr, .little); |
| 406 | } | 406 | } |
| 407 | 407 | ||
| 408 | pub fn getAugmentationString(rec: Record) []const u8 { | 408 | pub fn getAugmentationString(rec: Record) []const u8 { |
| ... | @@ -509,14 +509,14 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { | ... | @@ -509,14 +509,14 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { |
| 509 | if (enc == EH_PE.omit) return null; | 509 | if (enc == EH_PE.omit) return null; |
| 510 | 510 | ||
| 511 | var ptr: i64 = switch (enc & 0x0F) { | 511 | var ptr: i64 = switch (enc & 0x0F) { |
| 512 | EH_PE.absptr => @as(i64, @bitCast(try reader.readInt(u64, .Little))), | 512 | EH_PE.absptr => @as(i64, @bitCast(try reader.readInt(u64, .little))), |
| 513 | EH_PE.udata2 => @as(i16, @bitCast(try reader.readInt(u16, .Little))), | 513 | EH_PE.udata2 => @as(i16, @bitCast(try reader.readInt(u16, .little))), |
| 514 | EH_PE.udata4 => @as(i32, @bitCast(try reader.readInt(u32, .Little))), | 514 | EH_PE.udata4 => @as(i32, @bitCast(try reader.readInt(u32, .little))), |
| 515 | EH_PE.udata8 => @as(i64, @bitCast(try reader.readInt(u64, .Little))), | 515 | EH_PE.udata8 => @as(i64, @bitCast(try reader.readInt(u64, .little))), |
| 516 | EH_PE.uleb128 => @as(i64, @bitCast(try leb.readULEB128(u64, reader))), | 516 | EH_PE.uleb128 => @as(i64, @bitCast(try leb.readULEB128(u64, reader))), |
| 517 | EH_PE.sdata2 => try reader.readInt(i16, .Little), | 517 | EH_PE.sdata2 => try reader.readInt(i16, .little), |
| 518 | EH_PE.sdata4 => try reader.readInt(i32, .Little), | 518 | EH_PE.sdata4 => try reader.readInt(i32, .little), |
| 519 | EH_PE.sdata8 => try reader.readInt(i64, .Little), | 519 | EH_PE.sdata8 => try reader.readInt(i64, .little), |
| 520 | EH_PE.sleb128 => try leb.readILEB128(i64, reader), | 520 | EH_PE.sleb128 => try leb.readILEB128(i64, reader), |
| 521 | else => return null, | 521 | else => return null, |
| 522 | }; | 522 | }; |
| ... | @@ -552,14 +552,14 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { | ... | @@ -552,14 +552,14 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { |
| 552 | } | 552 | } |
| 553 | 553 | ||
| 554 | switch (enc & 0x0F) { | 554 | switch (enc & 0x0F) { |
| 555 | EH_PE.absptr => try writer.writeInt(u64, @as(u64, @bitCast(actual)), .Little), | 555 | EH_PE.absptr => try writer.writeInt(u64, @as(u64, @bitCast(actual)), .little), |
| 556 | EH_PE.udata2 => try writer.writeInt(u16, @as(u16, @bitCast(@as(i16, @intCast(actual)))), .Little), | 556 | EH_PE.udata2 => try writer.writeInt(u16, @as(u16, @bitCast(@as(i16, @intCast(actual)))), .little), |
| 557 | EH_PE.udata4 => try writer.writeInt(u32, @as(u32, @bitCast(@as(i32, @intCast(actual)))), .Little), | 557 | EH_PE.udata4 => try writer.writeInt(u32, @as(u32, @bitCast(@as(i32, @intCast(actual)))), .little), |
| 558 | EH_PE.udata8 => try writer.writeInt(u64, @as(u64, @bitCast(actual)), .Little), | 558 | EH_PE.udata8 => try writer.writeInt(u64, @as(u64, @bitCast(actual)), .little), |
| 559 | EH_PE.uleb128 => try leb.writeULEB128(writer, @as(u64, @bitCast(actual))), | 559 | EH_PE.uleb128 => try leb.writeULEB128(writer, @as(u64, @bitCast(actual))), |
| 560 | EH_PE.sdata2 => try writer.writeInt(i16, @as(i16, @intCast(actual)), .Little), | 560 | EH_PE.sdata2 => try writer.writeInt(i16, @as(i16, @intCast(actual)), .little), |
| 561 | EH_PE.sdata4 => try writer.writeInt(i32, @as(i32, @intCast(actual)), .Little), | 561 | EH_PE.sdata4 => try writer.writeInt(i32, @as(i32, @intCast(actual)), .little), |
| 562 | EH_PE.sdata8 => try writer.writeInt(i64, actual, .Little), | 562 | EH_PE.sdata8 => try writer.writeInt(i64, actual, .little), |
| 563 | EH_PE.sleb128 => try leb.writeILEB128(writer, actual), | 563 | EH_PE.sleb128 => try leb.writeILEB128(writer, actual), |
| 564 | else => unreachable, | 564 | else => unreachable, |
| 565 | } | 565 | } |
| ... | @@ -586,13 +586,13 @@ pub const Iterator = struct { | ... | @@ -586,13 +586,13 @@ pub const Iterator = struct { |
| 586 | var stream = std.io.fixedBufferStream(it.data[it.pos..]); | 586 | var stream = std.io.fixedBufferStream(it.data[it.pos..]); |
| 587 | const reader = stream.reader(); | 587 | const reader = stream.reader(); |
| 588 | 588 | ||
| 589 | var size = try reader.readInt(u32, .Little); | 589 | var size = try reader.readInt(u32, .little); |
| 590 | if (size == 0xFFFFFFFF) { | 590 | if (size == 0xFFFFFFFF) { |
| 591 | log.debug("MachO doesn't support 64bit DWARF CFI __eh_frame records", .{}); | 591 | log.debug("MachO doesn't support 64bit DWARF CFI __eh_frame records", .{}); |
| 592 | return error.BadDwarfCfi; | 592 | return error.BadDwarfCfi; |
| 593 | } | 593 | } |
| 594 | 594 | ||
| 595 | const id = try reader.readInt(u32, .Little); | 595 | const id = try reader.readInt(u32, .little); |
| 596 | const tag: EhFrameRecordTag = if (id == 0) .cie else .fde; | 596 | const tag: EhFrameRecordTag = if (id == 0) .cie else .fde; |
| 597 | const offset: u32 = 4; | 597 | const offset: u32 = 4; |
| 598 | const record = EhFrameRecord(false){ | 598 | const record = EhFrameRecord(false){ |
src/link/MachO/stubs.zig+15-15| ... | @@ -53,7 +53,7 @@ pub fn writeStubHelperPreambleCode(args: struct { | ... | @@ -53,7 +53,7 @@ pub fn writeStubHelperPreambleCode(args: struct { |
| 53 | args.dyld_private_addr, | 53 | args.dyld_private_addr, |
| 54 | 0, | 54 | 0, |
| 55 | ); | 55 | ); |
| 56 | try writer.writeInt(i32, disp, .Little); | 56 | try writer.writeInt(i32, disp, .little); |
| 57 | } | 57 | } |
| 58 | try writer.writeAll(&.{ 0x41, 0x53, 0xff, 0x25 }); | 58 | try writer.writeAll(&.{ 0x41, 0x53, 0xff, 0x25 }); |
| 59 | { | 59 | { |
| ... | @@ -62,27 +62,27 @@ pub fn writeStubHelperPreambleCode(args: struct { | ... | @@ -62,27 +62,27 @@ pub fn writeStubHelperPreambleCode(args: struct { |
| 62 | args.dyld_stub_binder_got_addr, | 62 | args.dyld_stub_binder_got_addr, |
| 63 | 0, | 63 | 0, |
| 64 | ); | 64 | ); |
| 65 | try writer.writeInt(i32, disp, .Little); | 65 | try writer.writeInt(i32, disp, .little); |
| 66 | } | 66 | } |
| 67 | }, | 67 | }, |
| 68 | .aarch64 => { | 68 | .aarch64 => { |
| 69 | { | 69 | { |
| 70 | const pages = Relocation.calcNumberOfPages(args.source_addr, args.dyld_private_addr); | 70 | const pages = Relocation.calcNumberOfPages(args.source_addr, args.dyld_private_addr); |
| 71 | try writer.writeInt(u32, aarch64.Instruction.adrp(.x17, pages).toU32(), .Little); | 71 | try writer.writeInt(u32, aarch64.Instruction.adrp(.x17, pages).toU32(), .little); |
| 72 | } | 72 | } |
| 73 | { | 73 | { |
| 74 | const off = try Relocation.calcPageOffset(args.dyld_private_addr, .arithmetic); | 74 | const off = try Relocation.calcPageOffset(args.dyld_private_addr, .arithmetic); |
| 75 | try writer.writeInt(u32, aarch64.Instruction.add(.x17, .x17, off, false).toU32(), .Little); | 75 | try writer.writeInt(u32, aarch64.Instruction.add(.x17, .x17, off, false).toU32(), .little); |
| 76 | } | 76 | } |
| 77 | try writer.writeInt(u32, aarch64.Instruction.stp( | 77 | try writer.writeInt(u32, aarch64.Instruction.stp( |
| 78 | .x16, | 78 | .x16, |
| 79 | .x17, | 79 | .x17, |
| 80 | aarch64.Register.sp, | 80 | aarch64.Register.sp, |
| 81 | aarch64.Instruction.LoadStorePairOffset.pre_index(-16), | 81 | aarch64.Instruction.LoadStorePairOffset.pre_index(-16), |
| 82 | ).toU32(), .Little); | 82 | ).toU32(), .little); |
| 83 | { | 83 | { |
| 84 | const pages = Relocation.calcNumberOfPages(args.source_addr + 12, args.dyld_stub_binder_got_addr); | 84 | const pages = Relocation.calcNumberOfPages(args.source_addr + 12, args.dyld_stub_binder_got_addr); |
| 85 | try writer.writeInt(u32, aarch64.Instruction.adrp(.x16, pages).toU32(), .Little); | 85 | try writer.writeInt(u32, aarch64.Instruction.adrp(.x16, pages).toU32(), .little); |
| 86 | } | 86 | } |
| 87 | { | 87 | { |
| 88 | const off = try Relocation.calcPageOffset(args.dyld_stub_binder_got_addr, .load_store_64); | 88 | const off = try Relocation.calcPageOffset(args.dyld_stub_binder_got_addr, .load_store_64); |
| ... | @@ -90,9 +90,9 @@ pub fn writeStubHelperPreambleCode(args: struct { | ... | @@ -90,9 +90,9 @@ pub fn writeStubHelperPreambleCode(args: struct { |
| 90 | .x16, | 90 | .x16, |
| 91 | .x16, | 91 | .x16, |
| 92 | aarch64.Instruction.LoadStoreOffset.imm(off), | 92 | aarch64.Instruction.LoadStoreOffset.imm(off), |
| 93 | ).toU32(), .Little); | 93 | ).toU32(), .little); |
| 94 | } | 94 | } |
| 95 | try writer.writeInt(u32, aarch64.Instruction.br(.x16).toU32(), .Little); | 95 | try writer.writeInt(u32, aarch64.Instruction.br(.x16).toU32(), .little); |
| 96 | }, | 96 | }, |
| 97 | else => unreachable, | 97 | else => unreachable, |
| 98 | } | 98 | } |
| ... | @@ -108,7 +108,7 @@ pub fn writeStubHelperCode(args: struct { | ... | @@ -108,7 +108,7 @@ pub fn writeStubHelperCode(args: struct { |
| 108 | try writer.writeAll(&.{ 0x68, 0x0, 0x0, 0x0, 0x0, 0xe9 }); | 108 | try writer.writeAll(&.{ 0x68, 0x0, 0x0, 0x0, 0x0, 0xe9 }); |
| 109 | { | 109 | { |
| 110 | const disp = try Relocation.calcPcRelativeDisplacementX86(args.source_addr + 6, args.target_addr, 0); | 110 | const disp = try Relocation.calcPcRelativeDisplacementX86(args.source_addr + 6, args.target_addr, 0); |
| 111 | try writer.writeInt(i32, disp, .Little); | 111 | try writer.writeInt(i32, disp, .little); |
| 112 | } | 112 | } |
| 113 | }, | 113 | }, |
| 114 | .aarch64 => { | 114 | .aarch64 => { |
| ... | @@ -120,10 +120,10 @@ pub fn writeStubHelperCode(args: struct { | ... | @@ -120,10 +120,10 @@ pub fn writeStubHelperCode(args: struct { |
| 120 | try writer.writeInt(u32, aarch64.Instruction.ldrLiteral( | 120 | try writer.writeInt(u32, aarch64.Instruction.ldrLiteral( |
| 121 | .w16, | 121 | .w16, |
| 122 | literal, | 122 | literal, |
| 123 | ).toU32(), .Little); | 123 | ).toU32(), .little); |
| 124 | { | 124 | { |
| 125 | const disp = try Relocation.calcPcRelativeDisplacementArm64(args.source_addr + 4, args.target_addr); | 125 | const disp = try Relocation.calcPcRelativeDisplacementArm64(args.source_addr + 4, args.target_addr); |
| 126 | try writer.writeInt(u32, aarch64.Instruction.b(disp).toU32(), .Little); | 126 | try writer.writeInt(u32, aarch64.Instruction.b(disp).toU32(), .little); |
| 127 | } | 127 | } |
| 128 | try writer.writeAll(&.{ 0x0, 0x0, 0x0, 0x0 }); | 128 | try writer.writeAll(&.{ 0x0, 0x0, 0x0, 0x0 }); |
| 129 | }, | 129 | }, |
| ... | @@ -141,13 +141,13 @@ pub fn writeStubCode(args: struct { | ... | @@ -141,13 +141,13 @@ pub fn writeStubCode(args: struct { |
| 141 | try writer.writeAll(&.{ 0xff, 0x25 }); | 141 | try writer.writeAll(&.{ 0xff, 0x25 }); |
| 142 | { | 142 | { |
| 143 | const disp = try Relocation.calcPcRelativeDisplacementX86(args.source_addr + 2, args.target_addr, 0); | 143 | const disp = try Relocation.calcPcRelativeDisplacementX86(args.source_addr + 2, args.target_addr, 0); |
| 144 | try writer.writeInt(i32, disp, .Little); | 144 | try writer.writeInt(i32, disp, .little); |
| 145 | } | 145 | } |
| 146 | }, | 146 | }, |
| 147 | .aarch64 => { | 147 | .aarch64 => { |
| 148 | { | 148 | { |
| 149 | const pages = Relocation.calcNumberOfPages(args.source_addr, args.target_addr); | 149 | const pages = Relocation.calcNumberOfPages(args.source_addr, args.target_addr); |
| 150 | try writer.writeInt(u32, aarch64.Instruction.adrp(.x16, pages).toU32(), .Little); | 150 | try writer.writeInt(u32, aarch64.Instruction.adrp(.x16, pages).toU32(), .little); |
| 151 | } | 151 | } |
| 152 | { | 152 | { |
| 153 | const off = try Relocation.calcPageOffset(args.target_addr, .load_store_64); | 153 | const off = try Relocation.calcPageOffset(args.target_addr, .load_store_64); |
| ... | @@ -155,9 +155,9 @@ pub fn writeStubCode(args: struct { | ... | @@ -155,9 +155,9 @@ pub fn writeStubCode(args: struct { |
| 155 | .x16, | 155 | .x16, |
| 156 | .x16, | 156 | .x16, |
| 157 | aarch64.Instruction.LoadStoreOffset.imm(off), | 157 | aarch64.Instruction.LoadStoreOffset.imm(off), |
| 158 | ).toU32(), .Little); | 158 | ).toU32(), .little); |
| 159 | } | 159 | } |
| 160 | try writer.writeInt(u32, aarch64.Instruction.br(.x16).toU32(), .Little); | 160 | try writer.writeInt(u32, aarch64.Instruction.br(.x16).toU32(), .little); |
| 161 | }, | 161 | }, |
| 162 | else => unreachable, | 162 | else => unreachable, |
| 163 | } | 163 | } |
src/link/MachO/thunks.zig+3-3| ... | @@ -349,10 +349,10 @@ pub fn writeThunkCode(macho_file: *MachO, thunk: *const Thunk, writer: anytype) | ... | @@ -349,10 +349,10 @@ pub fn writeThunkCode(macho_file: *MachO, thunk: *const Thunk, writer: anytype) |
| 349 | .atom => macho_file.getSymbol(target).n_value, | 349 | .atom => macho_file.getSymbol(target).n_value, |
| 350 | }; | 350 | }; |
| 351 | const pages = Relocation.calcNumberOfPages(source_addr, target_addr); | 351 | const pages = Relocation.calcNumberOfPages(source_addr, target_addr); |
| 352 | try writer.writeInt(u32, aarch64.Instruction.adrp(.x16, pages).toU32(), .Little); | 352 | try writer.writeInt(u32, aarch64.Instruction.adrp(.x16, pages).toU32(), .little); |
| 353 | const off = try Relocation.calcPageOffset(target_addr, .arithmetic); | 353 | const off = try Relocation.calcPageOffset(target_addr, .arithmetic); |
| 354 | try writer.writeInt(u32, aarch64.Instruction.add(.x16, .x16, off, false).toU32(), .Little); | 354 | try writer.writeInt(u32, aarch64.Instruction.add(.x16, .x16, off, false).toU32(), .little); |
| 355 | try writer.writeInt(u32, aarch64.Instruction.br(.x16).toU32(), .Little); | 355 | try writer.writeInt(u32, aarch64.Instruction.br(.x16).toU32(), .little); |
| 356 | } | 356 | } |
| 357 | } | 357 | } |
| 358 | 358 |
src/link/MachO/zld.zig+2-2| ... | @@ -796,7 +796,7 @@ fn writePointerEntries(macho_file: *MachO, sect_id: u8, table: anytype) !void { | ... | @@ -796,7 +796,7 @@ fn writePointerEntries(macho_file: *MachO, sect_id: u8, table: anytype) !void { |
| 796 | defer buffer.deinit(); | 796 | defer buffer.deinit(); |
| 797 | for (table.entries.items) |entry| { | 797 | for (table.entries.items) |entry| { |
| 798 | const sym = macho_file.getSymbol(entry); | 798 | const sym = macho_file.getSymbol(entry); |
| 799 | buffer.writer().writeInt(u64, sym.n_value, .Little) catch unreachable; | 799 | buffer.writer().writeInt(u64, sym.n_value, .little) catch unreachable; |
| 800 | } | 800 | } |
| 801 | log.debug("writing __DATA_CONST,__got contents at file offset 0x{x}", .{header.offset}); | 801 | log.debug("writing __DATA_CONST,__got contents at file offset 0x{x}", .{header.offset}); |
| 802 | try macho_file.base.file.?.pwriteAll(buffer.items, header.offset); | 802 | try macho_file.base.file.?.pwriteAll(buffer.items, header.offset); |
| ... | @@ -880,7 +880,7 @@ fn writeLaSymbolPtrs(macho_file: *MachO) !void { | ... | @@ -880,7 +880,7 @@ fn writeLaSymbolPtrs(macho_file: *MachO) !void { |
| 880 | for (0..macho_file.stub_table.count()) |index| { | 880 | for (0..macho_file.stub_table.count()) |index| { |
| 881 | const target_addr = stub_helper_header.addr + stubs.stubHelperPreambleSize(cpu_arch) + | 881 | const target_addr = stub_helper_header.addr + stubs.stubHelperPreambleSize(cpu_arch) + |
| 882 | stubs.stubHelperSize(cpu_arch) * index; | 882 | stubs.stubHelperSize(cpu_arch) * index; |
| 883 | buffer.writer().writeInt(u64, target_addr, .Little) catch unreachable; | 883 | buffer.writer().writeInt(u64, target_addr, .little) catch unreachable; |
| 884 | } | 884 | } |
| 885 | 885 | ||
| 886 | log.debug("writing __DATA,__la_symbol_ptr contents at file offset 0x{x}", .{ | 886 | log.debug("writing __DATA,__la_symbol_ptr contents at file offset 0x{x}", .{ |
src/link/Plan9.zig+7-7| ... | @@ -348,7 +348,7 @@ fn putFn(self: *Plan9, decl_index: Module.Decl.Index, out: FnDeclOutput) !void { | ... | @@ -348,7 +348,7 @@ fn putFn(self: *Plan9, decl_index: Module.Decl.Index, out: FnDeclOutput) !void { |
| 348 | // every 'z' starts with 0 | 348 | // every 'z' starts with 0 |
| 349 | try a.append(0); | 349 | try a.append(0); |
| 350 | // path component value of '/' | 350 | // path component value of '/' |
| 351 | try a.writer().writeInt(u16, 1, .Big); | 351 | try a.writer().writeInt(u16, 1, .big); |
| 352 | 352 | ||
| 353 | // getting the full file path | 353 | // getting the full file path |
| 354 | var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; | 354 | var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; |
| ... | @@ -381,11 +381,11 @@ fn addPathComponents(self: *Plan9, path: []const u8, a: *std.ArrayList(u8)) !voi | ... | @@ -381,11 +381,11 @@ fn addPathComponents(self: *Plan9, path: []const u8, a: *std.ArrayList(u8)) !voi |
| 381 | var it = std.mem.tokenizeScalar(u8, path, sep); | 381 | var it = std.mem.tokenizeScalar(u8, path, sep); |
| 382 | while (it.next()) |component| { | 382 | while (it.next()) |component| { |
| 383 | if (self.file_segments.get(component)) |num| { | 383 | if (self.file_segments.get(component)) |num| { |
| 384 | try a.writer().writeInt(u16, num, .Big); | 384 | try a.writer().writeInt(u16, num, .big); |
| 385 | } else { | 385 | } else { |
| 386 | self.file_segments_i += 1; | 386 | self.file_segments_i += 1; |
| 387 | try self.file_segments.put(self.base.allocator, component, self.file_segments_i); | 387 | try self.file_segments.put(self.base.allocator, component, self.file_segments_i); |
| 388 | try a.writer().writeInt(u16, self.file_segments_i, .Big); | 388 | try a.writer().writeInt(u16, self.file_segments_i, .big); |
| 389 | } | 389 | } |
| 390 | } | 390 | } |
| 391 | } | 391 | } |
| ... | @@ -607,7 +607,7 @@ pub fn changeLine(l: *std.ArrayList(u8), delta_line: i32) !void { | ... | @@ -607,7 +607,7 @@ pub fn changeLine(l: *std.ArrayList(u8), delta_line: i32) !void { |
| 607 | try l.append(toadd); | 607 | try l.append(toadd); |
| 608 | } else if (delta_line != 0) { | 608 | } else if (delta_line != 0) { |
| 609 | try l.append(0); | 609 | try l.append(0); |
| 610 | try l.writer().writeInt(i32, delta_line, .Big); | 610 | try l.writer().writeInt(i32, delta_line, .big); |
| 611 | } | 611 | } |
| 612 | } | 612 | } |
| 613 | 613 | ||
| ... | @@ -922,7 +922,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No | ... | @@ -922,7 +922,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No |
| 922 | @memcpy(hdr_slice, self.hdr.toU8s()[0..hdr_size]); | 922 | @memcpy(hdr_slice, self.hdr.toU8s()[0..hdr_size]); |
| 923 | // write the fat header for 64 bit entry points | 923 | // write the fat header for 64 bit entry points |
| 924 | if (self.sixtyfour_bit) { | 924 | if (self.sixtyfour_bit) { |
| 925 | mem.writeInt(u64, hdr_buf[32..40], self.entry_val.?, .Big); | 925 | mem.writeInt(u64, hdr_buf[32..40], self.entry_val.?, .big); |
| 926 | } | 926 | } |
| 927 | // perform the relocs | 927 | // perform the relocs |
| 928 | { | 928 | { |
| ... | @@ -1311,9 +1311,9 @@ pub fn writeSym(self: *Plan9, w: anytype, sym: aout.Sym) !void { | ... | @@ -1311,9 +1311,9 @@ pub fn writeSym(self: *Plan9, w: anytype, sym: aout.Sym) !void { |
| 1311 | // log.debug("write sym{{name: {s}, value: {x}}}", .{ sym.name, sym.value }); | 1311 | // log.debug("write sym{{name: {s}, value: {x}}}", .{ sym.name, sym.value }); |
| 1312 | if (sym.type == .bad) return; // we don't want to write free'd symbols | 1312 | if (sym.type == .bad) return; // we don't want to write free'd symbols |
| 1313 | if (!self.sixtyfour_bit) { | 1313 | if (!self.sixtyfour_bit) { |
| 1314 | try w.writeInt(u32, @as(u32, @intCast(sym.value)), .Big); | 1314 | try w.writeInt(u32, @as(u32, @intCast(sym.value)), .big); |
| 1315 | } else { | 1315 | } else { |
| 1316 | try w.writeInt(u64, sym.value, .Big); | 1316 | try w.writeInt(u64, sym.value, .big); |
| 1317 | } | 1317 | } |
| 1318 | try w.writeByte(@intFromEnum(sym.type)); | 1318 | try w.writeByte(@intFromEnum(sym.type)); |
| 1319 | try w.writeAll(sym.name); | 1319 | try w.writeAll(sym.name); |
src/link/Plan9/aout.zig+1-1| ... | @@ -21,7 +21,7 @@ pub const ExecHdr = extern struct { | ... | @@ -21,7 +21,7 @@ pub const ExecHdr = extern struct { |
| 21 | var buf: [40]u8 = undefined; | 21 | var buf: [40]u8 = undefined; |
| 22 | var i: u8 = 0; | 22 | var i: u8 = 0; |
| 23 | inline for (std.meta.fields(@This())) |f| { | 23 | inline for (std.meta.fields(@This())) |f| { |
| 24 | std.mem.writeInt(u32, buf[i..][0..4], @field(self, f.name), .Big); | 24 | std.mem.writeInt(u32, buf[i..][0..4], @field(self, f.name), .big); |
| 25 | i += 4; | 25 | i += 4; |
| 26 | } | 26 | } |
| 27 | return buf; | 27 | return buf; |
src/link/Wasm.zig+4-4| ... | @@ -2380,7 +2380,7 @@ fn setupErrorsLen(wasm: *Wasm) !void { | ... | @@ -2380,7 +2380,7 @@ fn setupErrorsLen(wasm: *Wasm) !void { |
| 2380 | atom.* = Atom.empty; | 2380 | atom.* = Atom.empty; |
| 2381 | atom.sym_index = loc.index; | 2381 | atom.sym_index = loc.index; |
| 2382 | atom.size = 2; | 2382 | atom.size = 2; |
| 2383 | try atom.code.writer(wasm.base.allocator).writeInt(u16, @intCast(errors_len), .Little); | 2383 | try atom.code.writer(wasm.base.allocator).writeInt(u16, @intCast(errors_len), .little); |
| 2384 | 2384 | ||
| 2385 | try wasm.parseAtom(atom_index, .{ .data = .read_only }); | 2385 | try wasm.parseAtom(atom_index, .{ .data = .read_only }); |
| 2386 | } | 2386 | } |
| ... | @@ -3151,7 +3151,7 @@ fn populateErrorNameTable(wasm: *Wasm) !void { | ... | @@ -3151,7 +3151,7 @@ fn populateErrorNameTable(wasm: *Wasm) !void { |
| 3151 | const offset = @as(u32, @intCast(atom.code.items.len)); | 3151 | const offset = @as(u32, @intCast(atom.code.items.len)); |
| 3152 | // first we create the data for the slice of the name | 3152 | // first we create the data for the slice of the name |
| 3153 | try atom.code.appendNTimes(wasm.base.allocator, 0, 4); // ptr to name, will be relocated | 3153 | try atom.code.appendNTimes(wasm.base.allocator, 0, 4); // ptr to name, will be relocated |
| 3154 | try atom.code.writer(wasm.base.allocator).writeInt(u32, len - 1, .Little); | 3154 | try atom.code.writer(wasm.base.allocator).writeInt(u32, len - 1, .little); |
| 3155 | // create relocation to the error name | 3155 | // create relocation to the error name |
| 3156 | try atom.relocs.append(wasm.base.allocator, .{ | 3156 | try atom.relocs.append(wasm.base.allocator, .{ |
| 3157 | .index = names_atom.sym_index, | 3157 | .index = names_atom.sym_index, |
| ... | @@ -4286,11 +4286,11 @@ fn emitInit(writer: anytype, init_expr: std.wasm.InitExpression) !void { | ... | @@ -4286,11 +4286,11 @@ fn emitInit(writer: anytype, init_expr: std.wasm.InitExpression) !void { |
| 4286 | }, | 4286 | }, |
| 4287 | .f32_const => |val| { | 4287 | .f32_const => |val| { |
| 4288 | try writer.writeByte(std.wasm.opcode(.f32_const)); | 4288 | try writer.writeByte(std.wasm.opcode(.f32_const)); |
| 4289 | try writer.writeInt(u32, @bitCast(val), .Little); | 4289 | try writer.writeInt(u32, @bitCast(val), .little); |
| 4290 | }, | 4290 | }, |
| 4291 | .f64_const => |val| { | 4291 | .f64_const => |val| { |
| 4292 | try writer.writeByte(std.wasm.opcode(.f64_const)); | 4292 | try writer.writeByte(std.wasm.opcode(.f64_const)); |
| 4293 | try writer.writeInt(u64, @bitCast(val), .Little); | 4293 | try writer.writeInt(u64, @bitCast(val), .little); |
| 4294 | }, | 4294 | }, |
| 4295 | .global_get => |val| { | 4295 | .global_get => |val| { |
| 4296 | try writer.writeByte(std.wasm.opcode(.global_get)); | 4296 | try writer.writeByte(std.wasm.opcode(.global_get)); |
src/link/Wasm/Archive.zig+2-2| ... | @@ -141,11 +141,11 @@ fn parseTableOfContents(archive: *Archive, allocator: Allocator, reader: anytype | ... | @@ -141,11 +141,11 @@ fn parseTableOfContents(archive: *Archive, allocator: Allocator, reader: anytype |
| 141 | const size_trimmed = mem.trim(u8, &archive.header.ar_size, " "); | 141 | const size_trimmed = mem.trim(u8, &archive.header.ar_size, " "); |
| 142 | const sym_tab_size = try std.fmt.parseInt(u32, size_trimmed, 10); | 142 | const sym_tab_size = try std.fmt.parseInt(u32, size_trimmed, 10); |
| 143 | 143 | ||
| 144 | const num_symbols = try reader.readInt(u32, .Big); | 144 | const num_symbols = try reader.readInt(u32, .big); |
| 145 | const symbol_positions = try allocator.alloc(u32, num_symbols); | 145 | const symbol_positions = try allocator.alloc(u32, num_symbols); |
| 146 | defer allocator.free(symbol_positions); | 146 | defer allocator.free(symbol_positions); |
| 147 | for (symbol_positions) |*index| { | 147 | for (symbol_positions) |*index| { |
| 148 | index.* = try reader.readInt(u32, .Big); | 148 | index.* = try reader.readInt(u32, .big); |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | const sym_tab = try allocator.alloc(u8, sym_tab_size - 4 - (4 * num_symbols)); | 151 | const sym_tab = try allocator.alloc(u8, sym_tab_size - 4 - (4 * num_symbols)); |
src/link/Wasm/Atom.zig+2-2| ... | @@ -114,10 +114,10 @@ pub fn resolveRelocs(atom: *Atom, wasm_bin: *const Wasm) void { | ... | @@ -114,10 +114,10 @@ pub fn resolveRelocs(atom: *Atom, wasm_bin: *const Wasm) void { |
| 114 | .R_WASM_GLOBAL_INDEX_I32, | 114 | .R_WASM_GLOBAL_INDEX_I32, |
| 115 | .R_WASM_MEMORY_ADDR_I32, | 115 | .R_WASM_MEMORY_ADDR_I32, |
| 116 | .R_WASM_SECTION_OFFSET_I32, | 116 | .R_WASM_SECTION_OFFSET_I32, |
| 117 | => std.mem.writeInt(u32, atom.code.items[reloc.offset..][0..4], @as(u32, @intCast(value)), .Little), | 117 | => std.mem.writeInt(u32, atom.code.items[reloc.offset..][0..4], @as(u32, @intCast(value)), .little), |
| 118 | .R_WASM_TABLE_INDEX_I64, | 118 | .R_WASM_TABLE_INDEX_I64, |
| 119 | .R_WASM_MEMORY_ADDR_I64, | 119 | .R_WASM_MEMORY_ADDR_I64, |
| 120 | => std.mem.writeInt(u64, atom.code.items[reloc.offset..][0..8], value, .Little), | 120 | => std.mem.writeInt(u64, atom.code.items[reloc.offset..][0..8], value, .little), |
| 121 | .R_WASM_GLOBAL_INDEX_LEB, | 121 | .R_WASM_GLOBAL_INDEX_LEB, |
| 122 | .R_WASM_EVENT_INDEX_LEB, | 122 | .R_WASM_EVENT_INDEX_LEB, |
| 123 | .R_WASM_FUNCTION_INDEX_LEB, | 123 | .R_WASM_FUNCTION_INDEX_LEB, |
src/link/Wasm/Object.zig+1-1| ... | @@ -344,7 +344,7 @@ fn Parser(comptime ReaderType: type) type { | ... | @@ -344,7 +344,7 @@ fn Parser(comptime ReaderType: type) type { |
| 344 | fn parseObject(parser: *ObjectParser, gpa: Allocator, is_object_file: *bool) Error!void { | 344 | fn parseObject(parser: *ObjectParser, gpa: Allocator, is_object_file: *bool) Error!void { |
| 345 | errdefer parser.object.deinit(gpa); | 345 | errdefer parser.object.deinit(gpa); |
| 346 | try parser.verifyMagicBytes(); | 346 | try parser.verifyMagicBytes(); |
| 347 | const version = try parser.reader.reader().readInt(u32, .Little); | 347 | const version = try parser.reader.reader().readInt(u32, .little); |
| 348 | 348 | ||
| 349 | parser.object.version = version; | 349 | parser.object.version = version; |
| 350 | var relocatable_data = std.ArrayList(RelocatableData).init(gpa); | 350 | var relocatable_data = std.ArrayList(RelocatableData).init(gpa); |
src/resinator/ani.zig+2-2| ... | @@ -25,14 +25,14 @@ fn getAniheaderFlags(reader: anytype) !u32 { | ... | @@ -25,14 +25,14 @@ fn getAniheaderFlags(reader: anytype) !u32 { |
| 25 | const riff_header = try reader.readBytesNoEof(4); | 25 | const riff_header = try reader.readBytesNoEof(4); |
| 26 | if (!std.mem.eql(u8, &riff_header, "RIFF")) return error.InvalidFormat; | 26 | if (!std.mem.eql(u8, &riff_header, "RIFF")) return error.InvalidFormat; |
| 27 | 27 | ||
| 28 | _ = try reader.readInt(u32, .Little); // size of RIFF chunk | 28 | _ = try reader.readInt(u32, .little); // size of RIFF chunk |
| 29 | 29 | ||
| 30 | const form_type = try reader.readBytesNoEof(4); | 30 | const form_type = try reader.readBytesNoEof(4); |
| 31 | if (!std.mem.eql(u8, &form_type, "ACON")) return error.InvalidFormat; | 31 | if (!std.mem.eql(u8, &form_type, "ACON")) return error.InvalidFormat; |
| 32 | 32 | ||
| 33 | while (true) { | 33 | while (true) { |
| 34 | const chunk_id = try reader.readBytesNoEof(4); | 34 | const chunk_id = try reader.readBytesNoEof(4); |
| 35 | const chunk_len = try reader.readInt(u32, .Little); | 35 | const chunk_len = try reader.readInt(u32, .little); |
| 36 | if (!std.mem.eql(u8, &chunk_id, "anih")) { | 36 | if (!std.mem.eql(u8, &chunk_id, "anih")) { |
| 37 | // TODO: Move file cursor instead of skipBytes | 37 | // TODO: Move file cursor instead of skipBytes |
| 38 | try reader.skipBytes(chunk_len, .{}); | 38 | try reader.skipBytes(chunk_len, .{}); |
src/resinator/bmp.zig+4-4| ... | @@ -94,16 +94,16 @@ pub fn read(reader: anytype, max_size: u64) ReadError!BitmapInfo { | ... | @@ -94,16 +94,16 @@ pub fn read(reader: anytype, max_size: u64) ReadError!BitmapInfo { |
| 94 | const id = std.mem.readInt(u16, file_header[0..2], native_endian); | 94 | const id = std.mem.readInt(u16, file_header[0..2], native_endian); |
| 95 | if (id != windows_format_id) return error.InvalidFileHeader; | 95 | if (id != windows_format_id) return error.InvalidFileHeader; |
| 96 | 96 | ||
| 97 | bitmap_info.pixel_data_offset = std.mem.readInt(u32, file_header[10..14], .Little); | 97 | bitmap_info.pixel_data_offset = std.mem.readInt(u32, file_header[10..14], .little); |
| 98 | if (bitmap_info.pixel_data_offset > max_size) return error.ImpossiblePixelDataOffset; | 98 | if (bitmap_info.pixel_data_offset > max_size) return error.ImpossiblePixelDataOffset; |
| 99 | 99 | ||
| 100 | bitmap_info.dib_header_size = reader.readInt(u32, .Little) catch return error.UnexpectedEOF; | 100 | bitmap_info.dib_header_size = reader.readInt(u32, .little) catch return error.UnexpectedEOF; |
| 101 | if (bitmap_info.pixel_data_offset < file_header_len + bitmap_info.dib_header_size) return error.ImpossiblePixelDataOffset; | 101 | if (bitmap_info.pixel_data_offset < file_header_len + bitmap_info.dib_header_size) return error.ImpossiblePixelDataOffset; |
| 102 | const dib_version = BitmapHeader.Version.get(bitmap_info.dib_header_size); | 102 | const dib_version = BitmapHeader.Version.get(bitmap_info.dib_header_size); |
| 103 | switch (dib_version) { | 103 | switch (dib_version) { |
| 104 | .@"nt3.1", .@"nt4.0", .@"nt5.0" => { | 104 | .@"nt3.1", .@"nt4.0", .@"nt5.0" => { |
| 105 | var dib_header_buf: [@sizeOf(BITMAPINFOHEADER)]u8 align(@alignOf(BITMAPINFOHEADER)) = undefined; | 105 | var dib_header_buf: [@sizeOf(BITMAPINFOHEADER)]u8 align(@alignOf(BITMAPINFOHEADER)) = undefined; |
| 106 | std.mem.writeInt(u32, dib_header_buf[0..4], bitmap_info.dib_header_size, .Little); | 106 | std.mem.writeInt(u32, dib_header_buf[0..4], bitmap_info.dib_header_size, .little); |
| 107 | reader.readNoEof(dib_header_buf[4..]) catch return error.UnexpectedEOF; | 107 | reader.readNoEof(dib_header_buf[4..]) catch return error.UnexpectedEOF; |
| 108 | var dib_header: *BITMAPINFOHEADER = @ptrCast(&dib_header_buf); | 108 | var dib_header: *BITMAPINFOHEADER = @ptrCast(&dib_header_buf); |
| 109 | structFieldsLittleToNative(BITMAPINFOHEADER, dib_header); | 109 | structFieldsLittleToNative(BITMAPINFOHEADER, dib_header); |
| ... | @@ -118,7 +118,7 @@ pub fn read(reader: anytype, max_size: u64) ReadError!BitmapInfo { | ... | @@ -118,7 +118,7 @@ pub fn read(reader: anytype, max_size: u64) ReadError!BitmapInfo { |
| 118 | }, | 118 | }, |
| 119 | .@"win2.0" => { | 119 | .@"win2.0" => { |
| 120 | var dib_header_buf: [@sizeOf(BITMAPCOREHEADER)]u8 align(@alignOf(BITMAPCOREHEADER)) = undefined; | 120 | var dib_header_buf: [@sizeOf(BITMAPCOREHEADER)]u8 align(@alignOf(BITMAPCOREHEADER)) = undefined; |
| 121 | std.mem.writeInt(u32, dib_header_buf[0..4], bitmap_info.dib_header_size, .Little); | 121 | std.mem.writeInt(u32, dib_header_buf[0..4], bitmap_info.dib_header_size, .little); |
| 122 | reader.readNoEof(dib_header_buf[4..]) catch return error.UnexpectedEOF; | 122 | reader.readNoEof(dib_header_buf[4..]) catch return error.UnexpectedEOF; |
| 123 | var dib_header: *BITMAPCOREHEADER = @ptrCast(&dib_header_buf); | 123 | var dib_header: *BITMAPCOREHEADER = @ptrCast(&dib_header_buf); |
| 124 | structFieldsLittleToNative(BITMAPCOREHEADER, dib_header); | 124 | structFieldsLittleToNative(BITMAPCOREHEADER, dib_header); |
src/resinator/compile.zig+89-89| ... | @@ -585,8 +585,8 @@ pub const Compiler = struct { | ... | @@ -585,8 +585,8 @@ pub const Compiler = struct { |
| 585 | // > resource if a RESDIR structure contains information about a cursor. | 585 | // > resource if a RESDIR structure contains information about a cursor. |
| 586 | // where LOCALHEADER is `struct { WORD xHotSpot; WORD yHotSpot; }` | 586 | // where LOCALHEADER is `struct { WORD xHotSpot; WORD yHotSpot; }` |
| 587 | if (icon_dir.image_type == .cursor) { | 587 | if (icon_dir.image_type == .cursor) { |
| 588 | try writer.writeInt(u16, entry.type_specific_data.cursor.hotspot_x, .Little); | 588 | try writer.writeInt(u16, entry.type_specific_data.cursor.hotspot_x, .little); |
| 589 | try writer.writeInt(u16, entry.type_specific_data.cursor.hotspot_y, .Little); | 589 | try writer.writeInt(u16, entry.type_specific_data.cursor.hotspot_y, .little); |
| 590 | } | 590 | } |
| 591 | 591 | ||
| 592 | try file.seekTo(entry.data_offset_from_start_of_file); | 592 | try file.seekTo(entry.data_offset_from_start_of_file); |
| ... | @@ -667,7 +667,7 @@ pub const Compiler = struct { | ... | @@ -667,7 +667,7 @@ pub const Compiler = struct { |
| 667 | }, | 667 | }, |
| 668 | .dib => { | 668 | .dib => { |
| 669 | var bitmap_header: *ico.BitmapHeader = @ptrCast(@alignCast(&header_bytes)); | 669 | var bitmap_header: *ico.BitmapHeader = @ptrCast(@alignCast(&header_bytes)); |
| 670 | if (native_endian == .Big) { | 670 | if (native_endian == .big) { |
| 671 | std.mem.byteSwapAllFields(ico.BitmapHeader, bitmap_header); | 671 | std.mem.byteSwapAllFields(ico.BitmapHeader, bitmap_header); |
| 672 | } | 672 | } |
| 673 | const bitmap_version = ico.BitmapHeader.Version.get(bitmap_header.bcSize); | 673 | const bitmap_version = ico.BitmapHeader.Version.get(bitmap_header.bcSize); |
| ... | @@ -985,8 +985,8 @@ pub const Compiler = struct { | ... | @@ -985,8 +985,8 @@ pub const Compiler = struct { |
| 985 | pub fn write(self: Data, writer: anytype) !void { | 985 | pub fn write(self: Data, writer: anytype) !void { |
| 986 | switch (self) { | 986 | switch (self) { |
| 987 | .number => |number| switch (number.is_long) { | 987 | .number => |number| switch (number.is_long) { |
| 988 | false => try writer.writeInt(WORD, number.asWord(), .Little), | 988 | false => try writer.writeInt(WORD, number.asWord(), .little), |
| 989 | true => try writer.writeInt(DWORD, number.value, .Little), | 989 | true => try writer.writeInt(DWORD, number.value, .little), |
| 990 | }, | 990 | }, |
| 991 | .ascii_string => |ascii_string| { | 991 | .ascii_string => |ascii_string| { |
| 992 | try writer.writeAll(ascii_string); | 992 | try writer.writeAll(ascii_string); |
| ... | @@ -1316,9 +1316,9 @@ pub const Compiler = struct { | ... | @@ -1316,9 +1316,9 @@ pub const Compiler = struct { |
| 1316 | 1316 | ||
| 1317 | try data_writer.writeByte(modifiers.value); | 1317 | try data_writer.writeByte(modifiers.value); |
| 1318 | try data_writer.writeByte(0); // padding | 1318 | try data_writer.writeByte(0); // padding |
| 1319 | try data_writer.writeInt(u16, key, .Little); | 1319 | try data_writer.writeInt(u16, key, .little); |
| 1320 | try data_writer.writeInt(u16, cmd_id.asWord(), .Little); | 1320 | try data_writer.writeInt(u16, cmd_id.asWord(), .little); |
| 1321 | try data_writer.writeInt(u16, 0, .Little); // padding | 1321 | try data_writer.writeInt(u16, 0, .little); // padding |
| 1322 | } | 1322 | } |
| 1323 | } | 1323 | } |
| 1324 | 1324 | ||
| ... | @@ -1701,34 +1701,34 @@ pub const Compiler = struct { | ... | @@ -1701,34 +1701,34 @@ pub const Compiler = struct { |
| 1701 | if (node.help_id == null) break :help_id 0; | 1701 | if (node.help_id == null) break :help_id 0; |
| 1702 | break :help_id evaluateNumberExpression(node.help_id.?, self.source, self.input_code_pages).value; | 1702 | break :help_id evaluateNumberExpression(node.help_id.?, self.source, self.input_code_pages).value; |
| 1703 | }; | 1703 | }; |
| 1704 | try data_writer.writeInt(u16, 1, .Little); // version number, always 1 | 1704 | try data_writer.writeInt(u16, 1, .little); // version number, always 1 |
| 1705 | try data_writer.writeInt(u16, 0xFFFF, .Little); // signature, always 0xFFFF | 1705 | try data_writer.writeInt(u16, 0xFFFF, .little); // signature, always 0xFFFF |
| 1706 | try data_writer.writeInt(u32, help_id, .Little); | 1706 | try data_writer.writeInt(u32, help_id, .little); |
| 1707 | try data_writer.writeInt(u32, optional_statement_values.exstyle, .Little); | 1707 | try data_writer.writeInt(u32, optional_statement_values.exstyle, .little); |
| 1708 | try data_writer.writeInt(u32, optional_statement_values.style, .Little); | 1708 | try data_writer.writeInt(u32, optional_statement_values.style, .little); |
| 1709 | } else { | 1709 | } else { |
| 1710 | try data_writer.writeInt(u32, optional_statement_values.style, .Little); | 1710 | try data_writer.writeInt(u32, optional_statement_values.style, .little); |
| 1711 | try data_writer.writeInt(u32, optional_statement_values.exstyle, .Little); | 1711 | try data_writer.writeInt(u32, optional_statement_values.exstyle, .little); |
| 1712 | } | 1712 | } |
| 1713 | // This limit is enforced by the parser, so we know the number of controls | 1713 | // This limit is enforced by the parser, so we know the number of controls |
| 1714 | // is within the range of a u16. | 1714 | // is within the range of a u16. |
| 1715 | try data_writer.writeInt(u16, @as(u16, @intCast(node.controls.len)), .Little); | 1715 | try data_writer.writeInt(u16, @as(u16, @intCast(node.controls.len)), .little); |
| 1716 | try data_writer.writeInt(u16, x.asWord(), .Little); | 1716 | try data_writer.writeInt(u16, x.asWord(), .little); |
| 1717 | try data_writer.writeInt(u16, y.asWord(), .Little); | 1717 | try data_writer.writeInt(u16, y.asWord(), .little); |
| 1718 | try data_writer.writeInt(u16, width.asWord(), .Little); | 1718 | try data_writer.writeInt(u16, width.asWord(), .little); |
| 1719 | try data_writer.writeInt(u16, height.asWord(), .Little); | 1719 | try data_writer.writeInt(u16, height.asWord(), .little); |
| 1720 | 1720 | ||
| 1721 | // Menu | 1721 | // Menu |
| 1722 | if (optional_statement_values.menu) |menu| { | 1722 | if (optional_statement_values.menu) |menu| { |
| 1723 | try menu.write(data_writer); | 1723 | try menu.write(data_writer); |
| 1724 | } else { | 1724 | } else { |
| 1725 | try data_writer.writeInt(u16, 0, .Little); | 1725 | try data_writer.writeInt(u16, 0, .little); |
| 1726 | } | 1726 | } |
| 1727 | // Class | 1727 | // Class |
| 1728 | if (optional_statement_values.class) |class| { | 1728 | if (optional_statement_values.class) |class| { |
| 1729 | try class.write(data_writer); | 1729 | try class.write(data_writer); |
| 1730 | } else { | 1730 | } else { |
| 1731 | try data_writer.writeInt(u16, 0, .Little); | 1731 | try data_writer.writeInt(u16, 0, .little); |
| 1732 | } | 1732 | } |
| 1733 | // Caption | 1733 | // Caption |
| 1734 | if (optional_statement_values.caption) |caption| { | 1734 | if (optional_statement_values.caption) |caption| { |
| ... | @@ -1736,7 +1736,7 @@ pub const Compiler = struct { | ... | @@ -1736,7 +1736,7 @@ pub const Compiler = struct { |
| 1736 | defer self.allocator.free(parsed); | 1736 | defer self.allocator.free(parsed); |
| 1737 | try data_writer.writeAll(std.mem.sliceAsBytes(parsed[0 .. parsed.len + 1])); | 1737 | try data_writer.writeAll(std.mem.sliceAsBytes(parsed[0 .. parsed.len + 1])); |
| 1738 | } else { | 1738 | } else { |
| 1739 | try data_writer.writeInt(u16, 0, .Little); | 1739 | try data_writer.writeInt(u16, 0, .little); |
| 1740 | } | 1740 | } |
| 1741 | // Font | 1741 | // Font |
| 1742 | if (optional_statement_values.font) |font| { | 1742 | if (optional_statement_values.font) |font| { |
| ... | @@ -1787,18 +1787,18 @@ pub const Compiler = struct { | ... | @@ -1787,18 +1787,18 @@ pub const Compiler = struct { |
| 1787 | switch (resource) { | 1787 | switch (resource) { |
| 1788 | .dialog => { | 1788 | .dialog => { |
| 1789 | // Note: Reverse order from DIALOGEX | 1789 | // Note: Reverse order from DIALOGEX |
| 1790 | try data_writer.writeInt(u32, style, .Little); | 1790 | try data_writer.writeInt(u32, style, .little); |
| 1791 | try data_writer.writeInt(u32, exstyle, .Little); | 1791 | try data_writer.writeInt(u32, exstyle, .little); |
| 1792 | }, | 1792 | }, |
| 1793 | .dialogex => { | 1793 | .dialogex => { |
| 1794 | const help_id: u32 = if (control.help_id) |help_id_expression| | 1794 | const help_id: u32 = if (control.help_id) |help_id_expression| |
| 1795 | evaluateNumberExpression(help_id_expression, self.source, self.input_code_pages).value | 1795 | evaluateNumberExpression(help_id_expression, self.source, self.input_code_pages).value |
| 1796 | else | 1796 | else |
| 1797 | 0; | 1797 | 0; |
| 1798 | try data_writer.writeInt(u32, help_id, .Little); | 1798 | try data_writer.writeInt(u32, help_id, .little); |
| 1799 | // Note: Reverse order from DIALOG | 1799 | // Note: Reverse order from DIALOG |
| 1800 | try data_writer.writeInt(u32, exstyle, .Little); | 1800 | try data_writer.writeInt(u32, exstyle, .little); |
| 1801 | try data_writer.writeInt(u32, style, .Little); | 1801 | try data_writer.writeInt(u32, style, .little); |
| 1802 | }, | 1802 | }, |
| 1803 | else => unreachable, | 1803 | else => unreachable, |
| 1804 | } | 1804 | } |
| ... | @@ -1808,15 +1808,15 @@ pub const Compiler = struct { | ... | @@ -1808,15 +1808,15 @@ pub const Compiler = struct { |
| 1808 | const control_width = evaluateNumberExpression(control.width, self.source, self.input_code_pages); | 1808 | const control_width = evaluateNumberExpression(control.width, self.source, self.input_code_pages); |
| 1809 | const control_height = evaluateNumberExpression(control.height, self.source, self.input_code_pages); | 1809 | const control_height = evaluateNumberExpression(control.height, self.source, self.input_code_pages); |
| 1810 | 1810 | ||
| 1811 | try data_writer.writeInt(u16, control_x.asWord(), .Little); | 1811 | try data_writer.writeInt(u16, control_x.asWord(), .little); |
| 1812 | try data_writer.writeInt(u16, control_y.asWord(), .Little); | 1812 | try data_writer.writeInt(u16, control_y.asWord(), .little); |
| 1813 | try data_writer.writeInt(u16, control_width.asWord(), .Little); | 1813 | try data_writer.writeInt(u16, control_width.asWord(), .little); |
| 1814 | try data_writer.writeInt(u16, control_height.asWord(), .Little); | 1814 | try data_writer.writeInt(u16, control_height.asWord(), .little); |
| 1815 | 1815 | ||
| 1816 | const control_id = evaluateNumberExpression(control.id, self.source, self.input_code_pages); | 1816 | const control_id = evaluateNumberExpression(control.id, self.source, self.input_code_pages); |
| 1817 | switch (resource) { | 1817 | switch (resource) { |
| 1818 | .dialog => try data_writer.writeInt(u16, control_id.asWord(), .Little), | 1818 | .dialog => try data_writer.writeInt(u16, control_id.asWord(), .little), |
| 1819 | .dialogex => try data_writer.writeInt(u32, control_id.value, .Little), | 1819 | .dialogex => try data_writer.writeInt(u32, control_id.value, .little), |
| 1820 | else => unreachable, | 1820 | else => unreachable, |
| 1821 | } | 1821 | } |
| 1822 | 1822 | ||
| ... | @@ -1949,7 +1949,7 @@ pub const Compiler = struct { | ... | @@ -1949,7 +1949,7 @@ pub const Compiler = struct { |
| 1949 | } | 1949 | } |
| 1950 | // We know the extra_data_buf size fits within a u16. | 1950 | // We know the extra_data_buf size fits within a u16. |
| 1951 | const extra_data_size: u16 = @intCast(extra_data_buf.items.len); | 1951 | const extra_data_size: u16 = @intCast(extra_data_buf.items.len); |
| 1952 | try data_writer.writeInt(u16, extra_data_size, .Little); | 1952 | try data_writer.writeInt(u16, extra_data_size, .little); |
| 1953 | try data_writer.writeAll(extra_data_buf.items); | 1953 | try data_writer.writeAll(extra_data_buf.items); |
| 1954 | } | 1954 | } |
| 1955 | 1955 | ||
| ... | @@ -1963,21 +1963,21 @@ pub const Compiler = struct { | ... | @@ -1963,21 +1963,21 @@ pub const Compiler = struct { |
| 1963 | 1963 | ||
| 1964 | // I'm assuming this is some sort of version | 1964 | // I'm assuming this is some sort of version |
| 1965 | // TODO: Try to find something mentioning this | 1965 | // TODO: Try to find something mentioning this |
| 1966 | try data_writer.writeInt(u16, 1, .Little); | 1966 | try data_writer.writeInt(u16, 1, .little); |
| 1967 | try data_writer.writeInt(u16, button_width.asWord(), .Little); | 1967 | try data_writer.writeInt(u16, button_width.asWord(), .little); |
| 1968 | try data_writer.writeInt(u16, button_height.asWord(), .Little); | 1968 | try data_writer.writeInt(u16, button_height.asWord(), .little); |
| 1969 | try data_writer.writeInt(u16, @as(u16, @intCast(node.buttons.len)), .Little); | 1969 | try data_writer.writeInt(u16, @as(u16, @intCast(node.buttons.len)), .little); |
| 1970 | 1970 | ||
| 1971 | for (node.buttons) |button_or_sep| { | 1971 | for (node.buttons) |button_or_sep| { |
| 1972 | switch (button_or_sep.id) { | 1972 | switch (button_or_sep.id) { |
| 1973 | .literal => { // This is always SEPARATOR | 1973 | .literal => { // This is always SEPARATOR |
| 1974 | std.debug.assert(button_or_sep.cast(.literal).?.token.id == .literal); | 1974 | std.debug.assert(button_or_sep.cast(.literal).?.token.id == .literal); |
| 1975 | try data_writer.writeInt(u16, 0, .Little); | 1975 | try data_writer.writeInt(u16, 0, .little); |
| 1976 | }, | 1976 | }, |
| 1977 | .simple_statement => { | 1977 | .simple_statement => { |
| 1978 | const value_node = button_or_sep.cast(.simple_statement).?.value; | 1978 | const value_node = button_or_sep.cast(.simple_statement).?.value; |
| 1979 | const value = evaluateNumberExpression(value_node, self.source, self.input_code_pages); | 1979 | const value = evaluateNumberExpression(value_node, self.source, self.input_code_pages); |
| 1980 | try data_writer.writeInt(u16, value.asWord(), .Little); | 1980 | try data_writer.writeInt(u16, value.asWord(), .little); |
| 1981 | }, | 1981 | }, |
| 1982 | else => unreachable, // This is a bug in the parser | 1982 | else => unreachable, // This is a bug in the parser |
| 1983 | } | 1983 | } |
| ... | @@ -2008,21 +2008,21 @@ pub const Compiler = struct { | ... | @@ -2008,21 +2008,21 @@ pub const Compiler = struct { |
| 2008 | pub fn writeDialogFont(self: *Compiler, resource: Resource, values: FontStatementValues, writer: anytype) !void { | 2008 | pub fn writeDialogFont(self: *Compiler, resource: Resource, values: FontStatementValues, writer: anytype) !void { |
| 2009 | const node = values.node; | 2009 | const node = values.node; |
| 2010 | const point_size = evaluateNumberExpression(node.point_size, self.source, self.input_code_pages); | 2010 | const point_size = evaluateNumberExpression(node.point_size, self.source, self.input_code_pages); |
| 2011 | try writer.writeInt(u16, point_size.asWord(), .Little); | 2011 | try writer.writeInt(u16, point_size.asWord(), .little); |
| 2012 | 2012 | ||
| 2013 | if (resource == .dialogex) { | 2013 | if (resource == .dialogex) { |
| 2014 | try writer.writeInt(u16, values.weight, .Little); | 2014 | try writer.writeInt(u16, values.weight, .little); |
| 2015 | } | 2015 | } |
| 2016 | 2016 | ||
| 2017 | if (resource == .dialogex) { | 2017 | if (resource == .dialogex) { |
| 2018 | try writer.writeInt(u8, @intFromBool(values.italic), .Little); | 2018 | try writer.writeInt(u8, @intFromBool(values.italic), .little); |
| 2019 | } | 2019 | } |
| 2020 | 2020 | ||
| 2021 | if (node.char_set) |char_set| { | 2021 | if (node.char_set) |char_set| { |
| 2022 | const value = evaluateNumberExpression(char_set, self.source, self.input_code_pages); | 2022 | const value = evaluateNumberExpression(char_set, self.source, self.input_code_pages); |
| 2023 | try writer.writeInt(u8, @as(u8, @truncate(value.value)), .Little); | 2023 | try writer.writeInt(u8, @as(u8, @truncate(value.value)), .little); |
| 2024 | } else if (resource == .dialogex) { | 2024 | } else if (resource == .dialogex) { |
| 2025 | try writer.writeInt(u8, 1, .Little); // DEFAULT_CHARSET | 2025 | try writer.writeInt(u8, 1, .little); // DEFAULT_CHARSET |
| 2026 | } | 2026 | } |
| 2027 | 2027 | ||
| 2028 | const typeface = try self.parseQuotedStringAsWideString(node.typeface); | 2028 | const typeface = try self.parseQuotedStringAsWideString(node.typeface); |
| ... | @@ -2077,9 +2077,9 @@ pub const Compiler = struct { | ... | @@ -2077,9 +2077,9 @@ pub const Compiler = struct { |
| 2077 | pub fn writeMenuData(self: *Compiler, node: *Node.Menu, data_writer: anytype, resource: Resource) !void { | 2077 | pub fn writeMenuData(self: *Compiler, node: *Node.Menu, data_writer: anytype, resource: Resource) !void { |
| 2078 | // menu header | 2078 | // menu header |
| 2079 | const version: u16 = if (resource == .menu) 0 else 1; | 2079 | const version: u16 = if (resource == .menu) 0 else 1; |
| 2080 | try data_writer.writeInt(u16, version, .Little); | 2080 | try data_writer.writeInt(u16, version, .little); |
| 2081 | const header_size: u16 = if (resource == .menu) 0 else 4; | 2081 | const header_size: u16 = if (resource == .menu) 0 else 4; |
| 2082 | try data_writer.writeInt(u16, header_size, .Little); // cbHeaderSize | 2082 | try data_writer.writeInt(u16, header_size, .little); // cbHeaderSize |
| 2083 | // Note: There can be extra bytes at the end of this header (`rgbExtra`), | 2083 | // Note: There can be extra bytes at the end of this header (`rgbExtra`), |
| 2084 | // but they are always zero-length for us, so we don't write anything | 2084 | // but they are always zero-length for us, so we don't write anything |
| 2085 | // (the length of the rgbExtra field is inferred from the header_size). | 2085 | // (the length of the rgbExtra field is inferred from the header_size). |
| ... | @@ -2089,9 +2089,9 @@ pub const Compiler = struct { | ... | @@ -2089,9 +2089,9 @@ pub const Compiler = struct { |
| 2089 | if (resource == .menuex) { | 2089 | if (resource == .menuex) { |
| 2090 | if (node.help_id) |help_id_node| { | 2090 | if (node.help_id) |help_id_node| { |
| 2091 | const help_id = evaluateNumberExpression(help_id_node, self.source, self.input_code_pages); | 2091 | const help_id = evaluateNumberExpression(help_id_node, self.source, self.input_code_pages); |
| 2092 | try data_writer.writeInt(u32, help_id.value, .Little); | 2092 | try data_writer.writeInt(u32, help_id.value, .little); |
| 2093 | } else { | 2093 | } else { |
| 2094 | try data_writer.writeInt(u32, 0, .Little); | 2094 | try data_writer.writeInt(u32, 0, .little); |
| 2095 | } | 2095 | } |
| 2096 | } | 2096 | } |
| 2097 | 2097 | ||
| ... | @@ -2111,9 +2111,9 @@ pub const Compiler = struct { | ... | @@ -2111,9 +2111,9 @@ pub const Compiler = struct { |
| 2111 | // compiler still uses this alternate form, so that's what we use too. | 2111 | // compiler still uses this alternate form, so that's what we use too. |
| 2112 | var flags = res.MenuItemFlags{}; | 2112 | var flags = res.MenuItemFlags{}; |
| 2113 | if (is_last_of_parent) flags.markLast(); | 2113 | if (is_last_of_parent) flags.markLast(); |
| 2114 | try writer.writeInt(u16, flags.value, .Little); | 2114 | try writer.writeInt(u16, flags.value, .little); |
| 2115 | try writer.writeInt(u16, 0, .Little); // id | 2115 | try writer.writeInt(u16, 0, .little); // id |
| 2116 | try writer.writeInt(u16, 0, .Little); // null-terminated UTF-16 text | 2116 | try writer.writeInt(u16, 0, .little); // null-terminated UTF-16 text |
| 2117 | }, | 2117 | }, |
| 2118 | .menu_item => { | 2118 | .menu_item => { |
| 2119 | const menu_item = @fieldParentPtr(Node.MenuItem, "base", node); | 2119 | const menu_item = @fieldParentPtr(Node.MenuItem, "base", node); |
| ... | @@ -2124,10 +2124,10 @@ pub const Compiler = struct { | ... | @@ -2124,10 +2124,10 @@ pub const Compiler = struct { |
| 2124 | flags.apply(option); | 2124 | flags.apply(option); |
| 2125 | } | 2125 | } |
| 2126 | if (is_last_of_parent) flags.markLast(); | 2126 | if (is_last_of_parent) flags.markLast(); |
| 2127 | try writer.writeInt(u16, flags.value, .Little); | 2127 | try writer.writeInt(u16, flags.value, .little); |
| 2128 | 2128 | ||
| 2129 | var result = evaluateNumberExpression(menu_item.result, self.source, self.input_code_pages); | 2129 | var result = evaluateNumberExpression(menu_item.result, self.source, self.input_code_pages); |
| 2130 | try writer.writeInt(u16, result.asWord(), .Little); | 2130 | try writer.writeInt(u16, result.asWord(), .little); |
| 2131 | 2131 | ||
| 2132 | var text = try self.parseQuotedStringAsWideString(menu_item.text); | 2132 | var text = try self.parseQuotedStringAsWideString(menu_item.text); |
| 2133 | defer self.allocator.free(text); | 2133 | defer self.allocator.free(text); |
| ... | @@ -2142,7 +2142,7 @@ pub const Compiler = struct { | ... | @@ -2142,7 +2142,7 @@ pub const Compiler = struct { |
| 2142 | flags.apply(option); | 2142 | flags.apply(option); |
| 2143 | } | 2143 | } |
| 2144 | if (is_last_of_parent) flags.markLast(); | 2144 | if (is_last_of_parent) flags.markLast(); |
| 2145 | try writer.writeInt(u16, flags.value, .Little); | 2145 | try writer.writeInt(u16, flags.value, .little); |
| 2146 | 2146 | ||
| 2147 | var text = try self.parseQuotedStringAsWideString(popup.text); | 2147 | var text = try self.parseQuotedStringAsWideString(popup.text); |
| 2148 | defer self.allocator.free(text); | 2148 | defer self.allocator.free(text); |
| ... | @@ -2158,30 +2158,30 @@ pub const Compiler = struct { | ... | @@ -2158,30 +2158,30 @@ pub const Compiler = struct { |
| 2158 | 2158 | ||
| 2159 | if (menu_item.type) |flags| { | 2159 | if (menu_item.type) |flags| { |
| 2160 | const value = evaluateNumberExpression(flags, self.source, self.input_code_pages); | 2160 | const value = evaluateNumberExpression(flags, self.source, self.input_code_pages); |
| 2161 | try writer.writeInt(u32, value.value, .Little); | 2161 | try writer.writeInt(u32, value.value, .little); |
| 2162 | } else { | 2162 | } else { |
| 2163 | try writer.writeInt(u32, 0, .Little); | 2163 | try writer.writeInt(u32, 0, .little); |
| 2164 | } | 2164 | } |
| 2165 | 2165 | ||
| 2166 | if (menu_item.state) |state| { | 2166 | if (menu_item.state) |state| { |
| 2167 | const value = evaluateNumberExpression(state, self.source, self.input_code_pages); | 2167 | const value = evaluateNumberExpression(state, self.source, self.input_code_pages); |
| 2168 | try writer.writeInt(u32, value.value, .Little); | 2168 | try writer.writeInt(u32, value.value, .little); |
| 2169 | } else { | 2169 | } else { |
| 2170 | try writer.writeInt(u32, 0, .Little); | 2170 | try writer.writeInt(u32, 0, .little); |
| 2171 | } | 2171 | } |
| 2172 | 2172 | ||
| 2173 | if (menu_item.id) |id| { | 2173 | if (menu_item.id) |id| { |
| 2174 | const value = evaluateNumberExpression(id, self.source, self.input_code_pages); | 2174 | const value = evaluateNumberExpression(id, self.source, self.input_code_pages); |
| 2175 | try writer.writeInt(u32, value.value, .Little); | 2175 | try writer.writeInt(u32, value.value, .little); |
| 2176 | } else { | 2176 | } else { |
| 2177 | try writer.writeInt(u32, 0, .Little); | 2177 | try writer.writeInt(u32, 0, .little); |
| 2178 | } | 2178 | } |
| 2179 | 2179 | ||
| 2180 | var flags: u16 = 0; | 2180 | var flags: u16 = 0; |
| 2181 | if (is_last_of_parent) flags |= comptime @as(u16, @intCast(res.MF.END)); | 2181 | if (is_last_of_parent) flags |= comptime @as(u16, @intCast(res.MF.END)); |
| 2182 | // This constant doesn't seem to have a named #define, it's different than MF_POPUP | 2182 | // This constant doesn't seem to have a named #define, it's different than MF_POPUP |
| 2183 | if (node_type == .popup_ex) flags |= 0x01; | 2183 | if (node_type == .popup_ex) flags |= 0x01; |
| 2184 | try writer.writeInt(u16, flags, .Little); | 2184 | try writer.writeInt(u16, flags, .little); |
| 2185 | 2185 | ||
| 2186 | var text = try self.parseQuotedStringAsWideString(menu_item.text); | 2186 | var text = try self.parseQuotedStringAsWideString(menu_item.text); |
| 2187 | defer self.allocator.free(text); | 2187 | defer self.allocator.free(text); |
| ... | @@ -2196,9 +2196,9 @@ pub const Compiler = struct { | ... | @@ -2196,9 +2196,9 @@ pub const Compiler = struct { |
| 2196 | if (node_type == .popup_ex) { | 2196 | if (node_type == .popup_ex) { |
| 2197 | if (menu_item.help_id) |help_id_node| { | 2197 | if (menu_item.help_id) |help_id_node| { |
| 2198 | const help_id = evaluateNumberExpression(help_id_node, self.source, self.input_code_pages); | 2198 | const help_id = evaluateNumberExpression(help_id_node, self.source, self.input_code_pages); |
| 2199 | try writer.writeInt(u32, help_id.value, .Little); | 2199 | try writer.writeInt(u32, help_id.value, .little); |
| 2200 | } else { | 2200 | } else { |
| 2201 | try writer.writeInt(u32, 0, .Little); | 2201 | try writer.writeInt(u32, 0, .little); |
| 2202 | } | 2202 | } |
| 2203 | 2203 | ||
| 2204 | for (menu_item.items, 0..) |item, i| { | 2204 | for (menu_item.items, 0..) |item, i| { |
| ... | @@ -2219,15 +2219,15 @@ pub const Compiler = struct { | ... | @@ -2219,15 +2219,15 @@ pub const Compiler = struct { |
| 2219 | var limited_writer = limitedWriter(data_buffer.writer(), std.math.maxInt(u16)); | 2219 | var limited_writer = limitedWriter(data_buffer.writer(), std.math.maxInt(u16)); |
| 2220 | const data_writer = limited_writer.writer(); | 2220 | const data_writer = limited_writer.writer(); |
| 2221 | 2221 | ||
| 2222 | try data_writer.writeInt(u16, 0, .Little); // placeholder size | 2222 | try data_writer.writeInt(u16, 0, .little); // placeholder size |
| 2223 | try data_writer.writeInt(u16, res.FixedFileInfo.byte_len, .Little); | 2223 | try data_writer.writeInt(u16, res.FixedFileInfo.byte_len, .little); |
| 2224 | try data_writer.writeInt(u16, res.VersionNode.type_binary, .Little); | 2224 | try data_writer.writeInt(u16, res.VersionNode.type_binary, .little); |
| 2225 | const key_bytes = std.mem.sliceAsBytes(res.FixedFileInfo.key[0 .. res.FixedFileInfo.key.len + 1]); | 2225 | const key_bytes = std.mem.sliceAsBytes(res.FixedFileInfo.key[0 .. res.FixedFileInfo.key.len + 1]); |
| 2226 | try data_writer.writeAll(key_bytes); | 2226 | try data_writer.writeAll(key_bytes); |
| 2227 | // The number of bytes written up to this point is always the same, since the name | 2227 | // The number of bytes written up to this point is always the same, since the name |
| 2228 | // of the node is a constant (FixedFileInfo.key). The total number of bytes | 2228 | // of the node is a constant (FixedFileInfo.key). The total number of bytes |
| 2229 | // written so far is 38, so we need 2 padding bytes to get back to DWORD alignment | 2229 | // written so far is 38, so we need 2 padding bytes to get back to DWORD alignment |
| 2230 | try data_writer.writeInt(u16, 0, .Little); | 2230 | try data_writer.writeInt(u16, 0, .little); |
| 2231 | 2231 | ||
| 2232 | var fixed_file_info = res.FixedFileInfo{}; | 2232 | var fixed_file_info = res.FixedFileInfo{}; |
| 2233 | for (node.fixed_info) |fixed_info| { | 2233 | for (node.fixed_info) |fixed_info| { |
| ... | @@ -2322,7 +2322,7 @@ pub const Compiler = struct { | ... | @@ -2322,7 +2322,7 @@ pub const Compiler = struct { |
| 2322 | // limited the writer to maxInt(u16) | 2322 | // limited the writer to maxInt(u16) |
| 2323 | const data_size: u16 = @intCast(data_buffer.items.len); | 2323 | const data_size: u16 = @intCast(data_buffer.items.len); |
| 2324 | // And now that we know the full size of this node (including its children), set its size | 2324 | // And now that we know the full size of this node (including its children), set its size |
| 2325 | std.mem.writeInt(u16, data_buffer.items[0..2], data_size, .Little); | 2325 | std.mem.writeInt(u16, data_buffer.items[0..2], data_size, .little); |
| 2326 | 2326 | ||
| 2327 | var header = try self.resourceHeader(node.id, node.versioninfo, .{ | 2327 | var header = try self.resourceHeader(node.id, node.versioninfo, .{ |
| 2328 | .data_size = data_size, | 2328 | .data_size = data_size, |
| ... | @@ -2345,12 +2345,12 @@ pub const Compiler = struct { | ... | @@ -2345,12 +2345,12 @@ pub const Compiler = struct { |
| 2345 | try writeDataPadding(writer, @as(u16, @intCast(buf.items.len))); | 2345 | try writeDataPadding(writer, @as(u16, @intCast(buf.items.len))); |
| 2346 | 2346 | ||
| 2347 | const node_and_children_size_offset = buf.items.len; | 2347 | const node_and_children_size_offset = buf.items.len; |
| 2348 | try writer.writeInt(u16, 0, .Little); // placeholder for size | 2348 | try writer.writeInt(u16, 0, .little); // placeholder for size |
| 2349 | const data_size_offset = buf.items.len; | 2349 | const data_size_offset = buf.items.len; |
| 2350 | try writer.writeInt(u16, 0, .Little); // placeholder for data size | 2350 | try writer.writeInt(u16, 0, .little); // placeholder for data size |
| 2351 | const data_type_offset = buf.items.len; | 2351 | const data_type_offset = buf.items.len; |
| 2352 | // Data type is string unless the node contains values that are numbers. | 2352 | // Data type is string unless the node contains values that are numbers. |
| 2353 | try writer.writeInt(u16, res.VersionNode.type_string, .Little); | 2353 | try writer.writeInt(u16, res.VersionNode.type_string, .little); |
| 2354 | 2354 | ||
| 2355 | switch (node.id) { | 2355 | switch (node.id) { |
| 2356 | inline .block, .block_value => |node_type| { | 2356 | inline .block, .block_value => |node_type| { |
| ... | @@ -2412,17 +2412,17 @@ pub const Compiler = struct { | ... | @@ -2412,17 +2412,17 @@ pub const Compiler = struct { |
| 2412 | const is_empty = parsed_to_first_null.len == 0; | 2412 | const is_empty = parsed_to_first_null.len == 0; |
| 2413 | const is_only = block_or_value.values.len == 1; | 2413 | const is_only = block_or_value.values.len == 1; |
| 2414 | if ((!is_empty or !is_only) and (is_last or value_value_node.trailing_comma)) { | 2414 | if ((!is_empty or !is_only) and (is_last or value_value_node.trailing_comma)) { |
| 2415 | try writer.writeInt(u16, 0, .Little); | 2415 | try writer.writeInt(u16, 0, .little); |
| 2416 | values_size += if (has_number_value) 2 else 1; | 2416 | values_size += if (has_number_value) 2 else 1; |
| 2417 | } | 2417 | } |
| 2418 | } | 2418 | } |
| 2419 | } | 2419 | } |
| 2420 | var data_size_slice = buf.items[data_size_offset..]; | 2420 | var data_size_slice = buf.items[data_size_offset..]; |
| 2421 | std.mem.writeInt(u16, data_size_slice[0..@sizeOf(u16)], @as(u16, @intCast(values_size)), .Little); | 2421 | std.mem.writeInt(u16, data_size_slice[0..@sizeOf(u16)], @as(u16, @intCast(values_size)), .little); |
| 2422 | 2422 | ||
| 2423 | if (has_number_value) { | 2423 | if (has_number_value) { |
| 2424 | const data_type_slice = buf.items[data_type_offset..]; | 2424 | const data_type_slice = buf.items[data_type_offset..]; |
| 2425 | std.mem.writeInt(u16, data_type_slice[0..@sizeOf(u16)], res.VersionNode.type_binary, .Little); | 2425 | std.mem.writeInt(u16, data_type_slice[0..@sizeOf(u16)], res.VersionNode.type_binary, .little); |
| 2426 | } | 2426 | } |
| 2427 | 2427 | ||
| 2428 | if (node_type == .block) { | 2428 | if (node_type == .block) { |
| ... | @@ -2437,7 +2437,7 @@ pub const Compiler = struct { | ... | @@ -2437,7 +2437,7 @@ pub const Compiler = struct { |
| 2437 | 2437 | ||
| 2438 | const node_and_children_size = buf.items.len - node_and_children_size_offset; | 2438 | const node_and_children_size = buf.items.len - node_and_children_size_offset; |
| 2439 | const node_and_children_size_slice = buf.items[node_and_children_size_offset..]; | 2439 | const node_and_children_size_slice = buf.items[node_and_children_size_offset..]; |
| 2440 | std.mem.writeInt(u16, node_and_children_size_slice[0..@sizeOf(u16)], @as(u16, @intCast(node_and_children_size)), .Little); | 2440 | std.mem.writeInt(u16, node_and_children_size_slice[0..@sizeOf(u16)], @as(u16, @intCast(node_and_children_size)), .little); |
| 2441 | } | 2441 | } |
| 2442 | 2442 | ||
| 2443 | pub fn writeStringTable(self: *Compiler, node: *Node.StringTable) !void { | 2443 | pub fn writeStringTable(self: *Compiler, node: *Node.StringTable) !void { |
| ... | @@ -2645,17 +2645,17 @@ pub const Compiler = struct { | ... | @@ -2645,17 +2645,17 @@ pub const Compiler = struct { |
| 2645 | } | 2645 | } |
| 2646 | 2646 | ||
| 2647 | fn writeSizeInfo(self: ResourceHeader, writer: anytype, size_info: SizeInfo) !void { | 2647 | fn writeSizeInfo(self: ResourceHeader, writer: anytype, size_info: SizeInfo) !void { |
| 2648 | try writer.writeInt(DWORD, self.data_size, .Little); // DataSize | 2648 | try writer.writeInt(DWORD, self.data_size, .little); // DataSize |
| 2649 | try writer.writeInt(DWORD, size_info.bytes, .Little); // HeaderSize | 2649 | try writer.writeInt(DWORD, size_info.bytes, .little); // HeaderSize |
| 2650 | try self.type_value.write(writer); // TYPE | 2650 | try self.type_value.write(writer); // TYPE |
| 2651 | try self.name_value.write(writer); // NAME | 2651 | try self.name_value.write(writer); // NAME |
| 2652 | try writer.writeByteNTimes(0, size_info.padding_after_name); | 2652 | try writer.writeByteNTimes(0, size_info.padding_after_name); |
| 2653 | 2653 | ||
| 2654 | try writer.writeInt(DWORD, self.data_version, .Little); // DataVersion | 2654 | try writer.writeInt(DWORD, self.data_version, .little); // DataVersion |
| 2655 | try writer.writeInt(WORD, self.memory_flags.value, .Little); // MemoryFlags | 2655 | try writer.writeInt(WORD, self.memory_flags.value, .little); // MemoryFlags |
| 2656 | try writer.writeInt(WORD, self.language.asInt(), .Little); // LanguageId | 2656 | try writer.writeInt(WORD, self.language.asInt(), .little); // LanguageId |
| 2657 | try writer.writeInt(DWORD, self.version, .Little); // Version | 2657 | try writer.writeInt(DWORD, self.version, .little); // Version |
| 2658 | try writer.writeInt(DWORD, self.characteristics, .Little); // Characteristics | 2658 | try writer.writeInt(DWORD, self.characteristics, .little); // Characteristics |
| 2659 | } | 2659 | } |
| 2660 | 2660 | ||
| 2661 | pub fn predefinedResourceType(self: ResourceHeader) ?res.RT { | 2661 | pub fn predefinedResourceType(self: ResourceHeader) ?res.RT { |
| ... | @@ -2998,7 +2998,7 @@ pub const FontDir = struct { | ... | @@ -2998,7 +2998,7 @@ pub const FontDir = struct { |
| 2998 | defer header.deinit(compiler.allocator); | 2998 | defer header.deinit(compiler.allocator); |
| 2999 | 2999 | ||
| 3000 | try header.writeAssertNoOverflow(writer); | 3000 | try header.writeAssertNoOverflow(writer); |
| 3001 | try writer.writeInt(u16, num_fonts, .Little); | 3001 | try writer.writeInt(u16, num_fonts, .little); |
| 3002 | for (self.fonts.items) |font| { | 3002 | for (self.fonts.items) |font| { |
| 3003 | // The format of the FONTDIR is a strange beast. | 3003 | // The format of the FONTDIR is a strange beast. |
| 3004 | // Technically, each FONT is seemingly meant to be written as a | 3004 | // Technically, each FONT is seemingly meant to be written as a |
| ... | @@ -3050,7 +3050,7 @@ pub const FontDir = struct { | ... | @@ -3050,7 +3050,7 @@ pub const FontDir = struct { |
| 3050 | // device name/face name in the FONTDIR is reliable. | 3050 | // device name/face name in the FONTDIR is reliable. |
| 3051 | 3051 | ||
| 3052 | // First, the ID is written, though | 3052 | // First, the ID is written, though |
| 3053 | try writer.writeInt(u16, font.id, .Little); | 3053 | try writer.writeInt(u16, font.id, .little); |
| 3054 | try writer.writeAll(&font.header_bytes); | 3054 | try writer.writeAll(&font.header_bytes); |
| 3055 | try writer.writeByteNTimes(0, 2); | 3055 | try writer.writeByteNTimes(0, 2); |
| 3056 | } | 3056 | } |
| ... | @@ -3187,7 +3187,7 @@ pub const StringTable = struct { | ... | @@ -3187,7 +3187,7 @@ pub const StringTable = struct { |
| 3187 | var string_i: u8 = 0; | 3187 | var string_i: u8 = 0; |
| 3188 | while (true) : (i += 1) { | 3188 | while (true) : (i += 1) { |
| 3189 | if (!self.set_indexes.isSet(i)) { | 3189 | if (!self.set_indexes.isSet(i)) { |
| 3190 | try data_writer.writeInt(u16, 0, .Little); | 3190 | try data_writer.writeInt(u16, 0, .little); |
| 3191 | if (i == 15) break else continue; | 3191 | if (i == 15) break else continue; |
| 3192 | } | 3192 | } |
| 3193 | 3193 | ||
| ... | @@ -3218,10 +3218,10 @@ pub const StringTable = struct { | ... | @@ -3218,10 +3218,10 @@ pub const StringTable = struct { |
| 3218 | // If the option is set, then a NUL terminator is added unconditionally. | 3218 | // If the option is set, then a NUL terminator is added unconditionally. |
| 3219 | // We already trimmed any trailing NULs, so we know it will be a new addition to the string. | 3219 | // We already trimmed any trailing NULs, so we know it will be a new addition to the string. |
| 3220 | if (compiler.null_terminate_string_table_strings) string_len_in_utf16_code_units += 1; | 3220 | if (compiler.null_terminate_string_table_strings) string_len_in_utf16_code_units += 1; |
| 3221 | try data_writer.writeInt(u16, string_len_in_utf16_code_units, .Little); | 3221 | try data_writer.writeInt(u16, string_len_in_utf16_code_units, .little); |
| 3222 | try data_writer.writeAll(std.mem.sliceAsBytes(trimmed_string)); | 3222 | try data_writer.writeAll(std.mem.sliceAsBytes(trimmed_string)); |
| 3223 | if (compiler.null_terminate_string_table_strings) { | 3223 | if (compiler.null_terminate_string_table_strings) { |
| 3224 | try data_writer.writeInt(u16, 0, .Little); | 3224 | try data_writer.writeInt(u16, 0, .little); |
| 3225 | } | 3225 | } |
| 3226 | 3226 | ||
| 3227 | if (i == 15) break; | 3227 | if (i == 15) break; |
src/resinator/ico.zig+25-25| ... | @@ -39,17 +39,17 @@ pub fn read(allocator: std.mem.Allocator, reader: anytype, max_size: u64) ReadEr | ... | @@ -39,17 +39,17 @@ pub fn read(allocator: std.mem.Allocator, reader: anytype, max_size: u64) ReadEr |
| 39 | // to do this. Maybe it makes more sense to handle the translation | 39 | // to do this. Maybe it makes more sense to handle the translation |
| 40 | // at the call site instead of having a helper function here. | 40 | // at the call site instead of having a helper function here. |
| 41 | pub fn readAnyError(allocator: std.mem.Allocator, reader: anytype, max_size: u64) !IconDir { | 41 | pub fn readAnyError(allocator: std.mem.Allocator, reader: anytype, max_size: u64) !IconDir { |
| 42 | const reserved = try reader.readInt(u16, .Little); | 42 | const reserved = try reader.readInt(u16, .little); |
| 43 | if (reserved != 0) { | 43 | if (reserved != 0) { |
| 44 | return error.InvalidHeader; | 44 | return error.InvalidHeader; |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | const image_type = reader.readEnum(ImageType, .Little) catch |err| switch (err) { | 47 | const image_type = reader.readEnum(ImageType, .little) catch |err| switch (err) { |
| 48 | error.InvalidValue => return error.InvalidImageType, | 48 | error.InvalidValue => return error.InvalidImageType, |
| 49 | else => |e| return e, | 49 | else => |e| return e, |
| 50 | }; | 50 | }; |
| 51 | 51 | ||
| 52 | const num_images = try reader.readInt(u16, .Little); | 52 | const num_images = try reader.readInt(u16, .little); |
| 53 | 53 | ||
| 54 | // To avoid over-allocation in the case of a file that says it has way more | 54 | // To avoid over-allocation in the case of a file that says it has way more |
| 55 | // entries than it actually does, we use an ArrayList with a conservatively | 55 | // entries than it actually does, we use an ArrayList with a conservatively |
| ... | @@ -68,19 +68,19 @@ pub fn readAnyError(allocator: std.mem.Allocator, reader: anytype, max_size: u64 | ... | @@ -68,19 +68,19 @@ pub fn readAnyError(allocator: std.mem.Allocator, reader: anytype, max_size: u64 |
| 68 | switch (image_type) { | 68 | switch (image_type) { |
| 69 | .icon => { | 69 | .icon => { |
| 70 | entry.type_specific_data = .{ .icon = .{ | 70 | entry.type_specific_data = .{ .icon = .{ |
| 71 | .color_planes = try reader.readInt(u16, .Little), | 71 | .color_planes = try reader.readInt(u16, .little), |
| 72 | .bits_per_pixel = try reader.readInt(u16, .Little), | 72 | .bits_per_pixel = try reader.readInt(u16, .little), |
| 73 | } }; | 73 | } }; |
| 74 | }, | 74 | }, |
| 75 | .cursor => { | 75 | .cursor => { |
| 76 | entry.type_specific_data = .{ .cursor = .{ | 76 | entry.type_specific_data = .{ .cursor = .{ |
| 77 | .hotspot_x = try reader.readInt(u16, .Little), | 77 | .hotspot_x = try reader.readInt(u16, .little), |
| 78 | .hotspot_y = try reader.readInt(u16, .Little), | 78 | .hotspot_y = try reader.readInt(u16, .little), |
| 79 | } }; | 79 | } }; |
| 80 | }, | 80 | }, |
| 81 | } | 81 | } |
| 82 | entry.data_size_in_bytes = try reader.readInt(u32, .Little); | 82 | entry.data_size_in_bytes = try reader.readInt(u32, .little); |
| 83 | entry.data_offset_from_start_of_file = try reader.readInt(u32, .Little); | 83 | entry.data_offset_from_start_of_file = try reader.readInt(u32, .little); |
| 84 | // Validate that the offset/data size is feasible | 84 | // Validate that the offset/data size is feasible |
| 85 | if (@as(u64, entry.data_offset_from_start_of_file) + entry.data_size_in_bytes > max_size) { | 85 | if (@as(u64, entry.data_offset_from_start_of_file) + entry.data_size_in_bytes > max_size) { |
| 86 | return error.ImpossibleDataSize; | 86 | return error.ImpossibleDataSize; |
| ... | @@ -135,10 +135,10 @@ pub const IconDir = struct { | ... | @@ -135,10 +135,10 @@ pub const IconDir = struct { |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | pub fn writeResData(self: IconDir, writer: anytype, first_image_id: u16) !void { | 137 | pub fn writeResData(self: IconDir, writer: anytype, first_image_id: u16) !void { |
| 138 | try writer.writeInt(u16, 0, .Little); | 138 | try writer.writeInt(u16, 0, .little); |
| 139 | try writer.writeInt(u16, @intFromEnum(self.image_type), .Little); | 139 | try writer.writeInt(u16, @intFromEnum(self.image_type), .little); |
| 140 | // We know that entries.len must fit into a u16 | 140 | // We know that entries.len must fit into a u16 |
| 141 | try writer.writeInt(u16, @as(u16, @intCast(self.entries.len)), .Little); | 141 | try writer.writeInt(u16, @as(u16, @intCast(self.entries.len)), .little); |
| 142 | 142 | ||
| 143 | var image_id = first_image_id; | 143 | var image_id = first_image_id; |
| 144 | for (self.entries) |entry| { | 144 | for (self.entries) |entry| { |
| ... | @@ -175,23 +175,23 @@ pub const Entry = struct { | ... | @@ -175,23 +175,23 @@ pub const Entry = struct { |
| 175 | pub fn writeResData(self: Entry, writer: anytype, id: u16) !void { | 175 | pub fn writeResData(self: Entry, writer: anytype, id: u16) !void { |
| 176 | switch (self.type_specific_data) { | 176 | switch (self.type_specific_data) { |
| 177 | .icon => |icon_data| { | 177 | .icon => |icon_data| { |
| 178 | try writer.writeInt(u8, @as(u8, @truncate(self.width)), .Little); | 178 | try writer.writeInt(u8, @as(u8, @truncate(self.width)), .little); |
| 179 | try writer.writeInt(u8, @as(u8, @truncate(self.height)), .Little); | 179 | try writer.writeInt(u8, @as(u8, @truncate(self.height)), .little); |
| 180 | try writer.writeInt(u8, self.num_colors, .Little); | 180 | try writer.writeInt(u8, self.num_colors, .little); |
| 181 | try writer.writeInt(u8, self.reserved, .Little); | 181 | try writer.writeInt(u8, self.reserved, .little); |
| 182 | try writer.writeInt(u16, icon_data.color_planes, .Little); | 182 | try writer.writeInt(u16, icon_data.color_planes, .little); |
| 183 | try writer.writeInt(u16, icon_data.bits_per_pixel, .Little); | 183 | try writer.writeInt(u16, icon_data.bits_per_pixel, .little); |
| 184 | try writer.writeInt(u32, self.data_size_in_bytes, .Little); | 184 | try writer.writeInt(u32, self.data_size_in_bytes, .little); |
| 185 | }, | 185 | }, |
| 186 | .cursor => |cursor_data| { | 186 | .cursor => |cursor_data| { |
| 187 | try writer.writeInt(u16, self.width, .Little); | 187 | try writer.writeInt(u16, self.width, .little); |
| 188 | try writer.writeInt(u16, self.height, .Little); | 188 | try writer.writeInt(u16, self.height, .little); |
| 189 | try writer.writeInt(u16, cursor_data.hotspot_x, .Little); | 189 | try writer.writeInt(u16, cursor_data.hotspot_x, .little); |
| 190 | try writer.writeInt(u16, cursor_data.hotspot_y, .Little); | 190 | try writer.writeInt(u16, cursor_data.hotspot_y, .little); |
| 191 | try writer.writeInt(u32, self.data_size_in_bytes + 4, .Little); | 191 | try writer.writeInt(u32, self.data_size_in_bytes + 4, .little); |
| 192 | }, | 192 | }, |
| 193 | } | 193 | } |
| 194 | try writer.writeInt(u16, id, .Little); | 194 | try writer.writeInt(u16, id, .little); |
| 195 | } | 195 | } |
| 196 | }; | 196 | }; |
| 197 | 197 |
src/resinator/res.zig+16-16| ... | @@ -249,14 +249,14 @@ pub const NameOrOrdinal = union(enum) { | ... | @@ -249,14 +249,14 @@ pub const NameOrOrdinal = union(enum) { |
| 249 | try writer.writeAll(std.mem.sliceAsBytes(name[0 .. name.len + 1])); | 249 | try writer.writeAll(std.mem.sliceAsBytes(name[0 .. name.len + 1])); |
| 250 | }, | 250 | }, |
| 251 | .ordinal => |ordinal| { | 251 | .ordinal => |ordinal| { |
| 252 | try writer.writeInt(u16, 0xffff, .Little); | 252 | try writer.writeInt(u16, 0xffff, .little); |
| 253 | try writer.writeInt(u16, ordinal, .Little); | 253 | try writer.writeInt(u16, ordinal, .little); |
| 254 | }, | 254 | }, |
| 255 | } | 255 | } |
| 256 | } | 256 | } |
| 257 | 257 | ||
| 258 | pub fn writeEmpty(writer: anytype) !void { | 258 | pub fn writeEmpty(writer: anytype) !void { |
| 259 | try writer.writeInt(u16, 0, .Little); | 259 | try writer.writeInt(u16, 0, .little); |
| 260 | } | 260 | } |
| 261 | 261 | ||
| 262 | pub fn fromString(allocator: Allocator, bytes: SourceBytes) !NameOrOrdinal { | 262 | pub fn fromString(allocator: Allocator, bytes: SourceBytes) !NameOrOrdinal { |
| ... | @@ -963,19 +963,19 @@ pub const FixedFileInfo = struct { | ... | @@ -963,19 +963,19 @@ pub const FixedFileInfo = struct { |
| 963 | }; | 963 | }; |
| 964 | 964 | ||
| 965 | pub fn write(self: FixedFileInfo, writer: anytype) !void { | 965 | pub fn write(self: FixedFileInfo, writer: anytype) !void { |
| 966 | try writer.writeInt(u32, signature, .Little); | 966 | try writer.writeInt(u32, signature, .little); |
| 967 | try writer.writeInt(u32, version, .Little); | 967 | try writer.writeInt(u32, version, .little); |
| 968 | try writer.writeInt(u32, self.file_version.mostSignificantCombinedParts(), .Little); | 968 | try writer.writeInt(u32, self.file_version.mostSignificantCombinedParts(), .little); |
| 969 | try writer.writeInt(u32, self.file_version.leastSignificantCombinedParts(), .Little); | 969 | try writer.writeInt(u32, self.file_version.leastSignificantCombinedParts(), .little); |
| 970 | try writer.writeInt(u32, self.product_version.mostSignificantCombinedParts(), .Little); | 970 | try writer.writeInt(u32, self.product_version.mostSignificantCombinedParts(), .little); |
| 971 | try writer.writeInt(u32, self.product_version.leastSignificantCombinedParts(), .Little); | 971 | try writer.writeInt(u32, self.product_version.leastSignificantCombinedParts(), .little); |
| 972 | try writer.writeInt(u32, self.file_flags_mask, .Little); | 972 | try writer.writeInt(u32, self.file_flags_mask, .little); |
| 973 | try writer.writeInt(u32, self.file_flags, .Little); | 973 | try writer.writeInt(u32, self.file_flags, .little); |
| 974 | try writer.writeInt(u32, self.file_os, .Little); | 974 | try writer.writeInt(u32, self.file_os, .little); |
| 975 | try writer.writeInt(u32, self.file_type, .Little); | 975 | try writer.writeInt(u32, self.file_type, .little); |
| 976 | try writer.writeInt(u32, self.file_subtype, .Little); | 976 | try writer.writeInt(u32, self.file_subtype, .little); |
| 977 | try writer.writeInt(u32, self.file_date.mostSignificantCombinedParts(), .Little); | 977 | try writer.writeInt(u32, self.file_date.mostSignificantCombinedParts(), .little); |
| 978 | try writer.writeInt(u32, self.file_date.leastSignificantCombinedParts(), .Little); | 978 | try writer.writeInt(u32, self.file_date.leastSignificantCombinedParts(), .little); |
| 979 | } | 979 | } |
| 980 | }; | 980 | }; |
| 981 | 981 |
src/value.zig+6-6| ... | @@ -778,8 +778,8 @@ pub const Value = struct { | ... | @@ -778,8 +778,8 @@ pub const Value = struct { |
| 778 | .Void => {}, | 778 | .Void => {}, |
| 779 | .Bool => { | 779 | .Bool => { |
| 780 | const byte_index = switch (endian) { | 780 | const byte_index = switch (endian) { |
| 781 | .Little => bit_offset / 8, | 781 | .little => bit_offset / 8, |
| 782 | .Big => buffer.len - bit_offset / 8 - 1, | 782 | .big => buffer.len - bit_offset / 8 - 1, |
| 783 | }; | 783 | }; |
| 784 | if (val.toBool()) { | 784 | if (val.toBool()) { |
| 785 | buffer[byte_index] |= (@as(u8, 1) << @as(u3, @intCast(bit_offset % 8))); | 785 | buffer[byte_index] |= (@as(u8, 1) << @as(u3, @intCast(bit_offset % 8))); |
| ... | @@ -815,7 +815,7 @@ pub const Value = struct { | ... | @@ -815,7 +815,7 @@ pub const Value = struct { |
| 815 | var elem_i: usize = 0; | 815 | var elem_i: usize = 0; |
| 816 | while (elem_i < len) : (elem_i += 1) { | 816 | while (elem_i < len) : (elem_i += 1) { |
| 817 | // On big-endian systems, LLVM reverses the element order of vectors by default | 817 | // On big-endian systems, LLVM reverses the element order of vectors by default |
| 818 | const tgt_elem_i = if (endian == .Big) len - elem_i - 1 else elem_i; | 818 | const tgt_elem_i = if (endian == .big) len - elem_i - 1 else elem_i; |
| 819 | const elem_val = try val.elemValue(mod, tgt_elem_i); | 819 | const elem_val = try val.elemValue(mod, tgt_elem_i); |
| 820 | try elem_val.writeToPackedMemory(elem_ty, mod, buffer, bit_offset + bits); | 820 | try elem_val.writeToPackedMemory(elem_ty, mod, buffer, bit_offset + bits); |
| 821 | bits += elem_bit_size; | 821 | bits += elem_bit_size; |
| ... | @@ -1064,8 +1064,8 @@ pub const Value = struct { | ... | @@ -1064,8 +1064,8 @@ pub const Value = struct { |
| 1064 | .Void => return Value.void, | 1064 | .Void => return Value.void, |
| 1065 | .Bool => { | 1065 | .Bool => { |
| 1066 | const byte = switch (endian) { | 1066 | const byte = switch (endian) { |
| 1067 | .Big => buffer[buffer.len - bit_offset / 8 - 1], | 1067 | .big => buffer[buffer.len - bit_offset / 8 - 1], |
| 1068 | .Little => buffer[bit_offset / 8], | 1068 | .little => buffer[bit_offset / 8], |
| 1069 | }; | 1069 | }; |
| 1070 | if (((byte >> @as(u3, @intCast(bit_offset % 8))) & 1) == 0) { | 1070 | if (((byte >> @as(u3, @intCast(bit_offset % 8))) & 1) == 0) { |
| 1071 | return Value.false; | 1071 | return Value.false; |
| ... | @@ -1127,7 +1127,7 @@ pub const Value = struct { | ... | @@ -1127,7 +1127,7 @@ pub const Value = struct { |
| 1127 | const elem_bit_size = @as(u16, @intCast(elem_ty.bitSize(mod))); | 1127 | const elem_bit_size = @as(u16, @intCast(elem_ty.bitSize(mod))); |
| 1128 | for (elems, 0..) |_, i| { | 1128 | for (elems, 0..) |_, i| { |
| 1129 | // On big-endian systems, LLVM reverses the element order of vectors by default | 1129 | // On big-endian systems, LLVM reverses the element order of vectors by default |
| 1130 | const tgt_elem_i = if (endian == .Big) elems.len - i - 1 else i; | 1130 | const tgt_elem_i = if (endian == .big) elems.len - i - 1 else i; |
| 1131 | elems[tgt_elem_i] = try (try readFromPackedMemory(elem_ty, mod, buffer, bit_offset + bits, arena)).intern(elem_ty, mod); | 1131 | elems[tgt_elem_i] = try (try readFromPackedMemory(elem_ty, mod, buffer, bit_offset + bits, arena)).intern(elem_ty, mod); |
| 1132 | bits += elem_bit_size; | 1132 | bits += elem_bit_size; |
| 1133 | } | 1133 | } |
test/behavior/align.zig+2-2| ... | @@ -616,8 +616,8 @@ test "sub-aligned pointer field access" { | ... | @@ -616,8 +616,8 @@ test "sub-aligned pointer field access" { |
| 616 | const ptr: *align(1) Header = @ptrCast(buf[1..][0..8]); | 616 | const ptr: *align(1) Header = @ptrCast(buf[1..][0..8]); |
| 617 | const x = ptr.bytes_len; | 617 | const x = ptr.bytes_len; |
| 618 | switch (builtin.cpu.arch.endian()) { | 618 | switch (builtin.cpu.arch.endian()) { |
| 619 | .Big => try expect(x == 0x06070809), | 619 | .big => try expect(x == 0x06070809), |
| 620 | .Little => try expect(x == 0x09080706), | 620 | .little => try expect(x == 0x09080706), |
| 621 | } | 621 | } |
| 622 | } | 622 | } |
| 623 | 623 |
test/behavior/bitcast.zig+5-5| ... | @@ -107,14 +107,14 @@ fn testBitCastuXToBytes(comptime N: usize) !void { | ... | @@ -107,14 +107,14 @@ fn testBitCastuXToBytes(comptime N: usize) !void { |
| 107 | 107 | ||
| 108 | const byte_count = (N + 7) / 8; | 108 | const byte_count = (N + 7) / 8; |
| 109 | switch (native_endian) { | 109 | switch (native_endian) { |
| 110 | .Little => { | 110 | .little => { |
| 111 | var byte_i = 0; | 111 | var byte_i = 0; |
| 112 | while (byte_i < (byte_count - 1)) : (byte_i += 1) { | 112 | while (byte_i < (byte_count - 1)) : (byte_i += 1) { |
| 113 | try expect(bytes[byte_i] == 0xff); | 113 | try expect(bytes[byte_i] == 0xff); |
| 114 | } | 114 | } |
| 115 | try expect(((bytes[byte_i] ^ 0xff) << -%@as(u3, @truncate(N))) == 0); | 115 | try expect(((bytes[byte_i] ^ 0xff) << -%@as(u3, @truncate(N))) == 0); |
| 116 | }, | 116 | }, |
| 117 | .Big => { | 117 | .big => { |
| 118 | var byte_i = byte_count - 1; | 118 | var byte_i = byte_count - 1; |
| 119 | while (byte_i > 0) : (byte_i -= 1) { | 119 | while (byte_i > 0) : (byte_i -= 1) { |
| 120 | try expect(bytes[byte_i] == 0xff); | 120 | try expect(bytes[byte_i] == 0xff); |
| ... | @@ -197,11 +197,11 @@ test "@bitCast extern structs at runtime and comptime" { | ... | @@ -197,11 +197,11 @@ test "@bitCast extern structs at runtime and comptime" { |
| 197 | var full = Full{ .number = 0x1234 }; | 197 | var full = Full{ .number = 0x1234 }; |
| 198 | var two_halves = @as(TwoHalves, @bitCast(full)); | 198 | var two_halves = @as(TwoHalves, @bitCast(full)); |
| 199 | switch (native_endian) { | 199 | switch (native_endian) { |
| 200 | .Big => { | 200 | .big => { |
| 201 | try expect(two_halves.half1 == 0x12); | 201 | try expect(two_halves.half1 == 0x12); |
| 202 | try expect(two_halves.half2 == 0x34); | 202 | try expect(two_halves.half2 == 0x34); |
| 203 | }, | 203 | }, |
| 204 | .Little => { | 204 | .little => { |
| 205 | try expect(two_halves.half1 == 0x34); | 205 | try expect(two_halves.half1 == 0x34); |
| 206 | try expect(two_halves.half2 == 0x12); | 206 | try expect(two_halves.half2 == 0x12); |
| 207 | }, | 207 | }, |
| ... | @@ -332,7 +332,7 @@ test "comptime @bitCast packed struct to int and back" { | ... | @@ -332,7 +332,7 @@ test "comptime @bitCast packed struct to int and back" { |
| 332 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 332 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 333 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 333 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 334 | 334 | ||
| 335 | if (builtin.zig_backend == .stage2_llvm and native_endian == .Big) { | 335 | if (builtin.zig_backend == .stage2_llvm and native_endian == .big) { |
| 336 | // https://github.com/ziglang/zig/issues/13782 | 336 | // https://github.com/ziglang/zig/issues/13782 |
| 337 | return error.SkipZigTest; | 337 | return error.SkipZigTest; |
| 338 | } | 338 | } |
test/behavior/bugs/12169.zig+1-1| ... | @@ -7,7 +7,7 @@ test { | ... | @@ -7,7 +7,7 @@ test { |
| 7 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 7 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 8 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 8 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 9 | 9 | ||
| 10 | if (comptime builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.endian() == .Big) { | 10 | if (comptime builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.endian() == .big) { |
| 11 | // https://github.com/ziglang/zig/issues/13782 | 11 | // https://github.com/ziglang/zig/issues/13782 |
| 12 | return error.SkipZigTest; | 12 | return error.SkipZigTest; |
| 13 | } | 13 | } |
test/behavior/cast.zig+1-1| ... | @@ -1077,7 +1077,7 @@ test "pointer reinterpret const float to int" { | ... | @@ -1077,7 +1077,7 @@ test "pointer reinterpret const float to int" { |
| 1077 | const float_ptr = &float; | 1077 | const float_ptr = &float; |
| 1078 | const int_ptr = @as(*const i32, @ptrCast(float_ptr)); | 1078 | const int_ptr = @as(*const i32, @ptrCast(float_ptr)); |
| 1079 | const int_val = int_ptr.*; | 1079 | const int_val = int_ptr.*; |
| 1080 | if (native_endian == .Little) | 1080 | if (native_endian == .little) |
| 1081 | try expect(int_val == 0x33333303) | 1081 | try expect(int_val == 0x33333303) |
| 1082 | else | 1082 | else |
| 1083 | try expect(int_val == 0x3fe33333); | 1083 | try expect(int_val == 0x3fe33333); |
test/behavior/cast_int.zig+1-1| ... | @@ -163,7 +163,7 @@ test "load non byte-sized optional value" { | ... | @@ -163,7 +163,7 @@ test "load non byte-sized optional value" { |
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | test "load non byte-sized value in struct" { | 165 | test "load non byte-sized value in struct" { |
| 166 | if (builtin.cpu.arch.endian() != .Little) return error.SkipZigTest; // packed struct TODO | 166 | if (builtin.cpu.arch.endian() != .little) return error.SkipZigTest; // packed struct TODO |
| 167 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 167 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 168 | 168 | ||
| 169 | // note: this bug is triggered by the == operator, expectEqual will hide it | 169 | // note: this bug is triggered by the == operator, expectEqual will hide it |
test/behavior/comptime_memory.zig+2-2| ... | @@ -73,7 +73,7 @@ test "type pun value and struct" { | ... | @@ -73,7 +73,7 @@ test "type pun value and struct" { |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | fn bigToNativeEndian(comptime T: type, v: T) T { | 75 | fn bigToNativeEndian(comptime T: type, v: T) T { |
| 76 | return if (endian == .Big) v else @byteSwap(v); | 76 | return if (endian == .big) v else @byteSwap(v); |
| 77 | } | 77 | } |
| 78 | test "type pun endianness" { | 78 | test "type pun endianness" { |
| 79 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 79 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| ... | @@ -385,7 +385,7 @@ test "accessing reinterpreted memory of parent object" { | ... | @@ -385,7 +385,7 @@ test "accessing reinterpreted memory of parent object" { |
| 385 | b: [4]u8, | 385 | b: [4]u8, |
| 386 | c: f32, | 386 | c: f32, |
| 387 | }; | 387 | }; |
| 388 | const expected = if (endian == .Little) 102 else 38; | 388 | const expected = if (endian == .little) 102 else 38; |
| 389 | 389 | ||
| 390 | comptime { | 390 | comptime { |
| 391 | const x = S{ | 391 | const x = S{ |
test/behavior/packed-struct.zig+12-12| ... | @@ -165,7 +165,7 @@ test "correct sizeOf and offsets in packed structs" { | ... | @@ -165,7 +165,7 @@ test "correct sizeOf and offsets in packed structs" { |
| 165 | try expectEqual(22, @bitOffsetOf(PStruct, "u10_b")); | 165 | try expectEqual(22, @bitOffsetOf(PStruct, "u10_b")); |
| 166 | try expectEqual(4, @sizeOf(PStruct)); | 166 | try expectEqual(4, @sizeOf(PStruct)); |
| 167 | 167 | ||
| 168 | if (native_endian == .Little) { | 168 | if (native_endian == .little) { |
| 169 | const s1 = @as(PStruct, @bitCast(@as(u32, 0x12345678))); | 169 | const s1 = @as(PStruct, @bitCast(@as(u32, 0x12345678))); |
| 170 | try expectEqual(false, s1.bool_a); | 170 | try expectEqual(false, s1.bool_a); |
| 171 | try expectEqual(false, s1.bool_b); | 171 | try expectEqual(false, s1.bool_b); |
| ... | @@ -206,7 +206,7 @@ test "nested packed structs" { | ... | @@ -206,7 +206,7 @@ test "nested packed structs" { |
| 206 | try expectEqual(3, @offsetOf(S3, "y")); | 206 | try expectEqual(3, @offsetOf(S3, "y")); |
| 207 | try expectEqual(24, @bitOffsetOf(S3, "y")); | 207 | try expectEqual(24, @bitOffsetOf(S3, "y")); |
| 208 | 208 | ||
| 209 | if (native_endian == .Little) { | 209 | if (native_endian == .little) { |
| 210 | const s3 = @as(S3Padded, @bitCast(@as(u64, 0xe952d5c71ff4))).s3; | 210 | const s3 = @as(S3Padded, @bitCast(@as(u64, 0xe952d5c71ff4))).s3; |
| 211 | try expectEqual(@as(u8, 0xf4), s3.x.a); | 211 | try expectEqual(@as(u8, 0xf4), s3.x.a); |
| 212 | try expectEqual(@as(u8, 0x1f), s3.x.b); | 212 | try expectEqual(@as(u8, 0x1f), s3.x.b); |
| ... | @@ -258,7 +258,7 @@ test "nested packed struct unaligned" { | ... | @@ -258,7 +258,7 @@ test "nested packed struct unaligned" { |
| 258 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | 258 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 259 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 259 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 260 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 260 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 261 | if (native_endian != .Little) return error.SkipZigTest; // Byte aligned packed struct field pointers have not been implemented yet | 261 | if (native_endian != .little) return error.SkipZigTest; // Byte aligned packed struct field pointers have not been implemented yet |
| 262 | 262 | ||
| 263 | const S1 = packed struct { | 263 | const S1 = packed struct { |
| 264 | a: u4, | 264 | a: u4, |
| ... | @@ -352,13 +352,13 @@ test "byte-aligned field pointer offsets" { | ... | @@ -352,13 +352,13 @@ test "byte-aligned field pointer offsets" { |
| 352 | .d = 4, | 352 | .d = 4, |
| 353 | }; | 353 | }; |
| 354 | switch (comptime builtin.cpu.arch.endian()) { | 354 | switch (comptime builtin.cpu.arch.endian()) { |
| 355 | .Little => { | 355 | .little => { |
| 356 | comptime assert(@TypeOf(&a.a) == *align(4) u8); | 356 | comptime assert(@TypeOf(&a.a) == *align(4) u8); |
| 357 | comptime assert(@TypeOf(&a.b) == *u8); | 357 | comptime assert(@TypeOf(&a.b) == *u8); |
| 358 | comptime assert(@TypeOf(&a.c) == *align(2) u8); | 358 | comptime assert(@TypeOf(&a.c) == *align(2) u8); |
| 359 | comptime assert(@TypeOf(&a.d) == *u8); | 359 | comptime assert(@TypeOf(&a.d) == *u8); |
| 360 | }, | 360 | }, |
| 361 | .Big => { | 361 | .big => { |
| 362 | // TODO re-evaluate packed struct endianness | 362 | // TODO re-evaluate packed struct endianness |
| 363 | comptime assert(@TypeOf(&a.a) == *align(4:0:4) u8); | 363 | comptime assert(@TypeOf(&a.a) == *align(4:0:4) u8); |
| 364 | comptime assert(@TypeOf(&a.b) == *align(4:8:4) u8); | 364 | comptime assert(@TypeOf(&a.b) == *align(4:8:4) u8); |
| ... | @@ -400,11 +400,11 @@ test "byte-aligned field pointer offsets" { | ... | @@ -400,11 +400,11 @@ test "byte-aligned field pointer offsets" { |
| 400 | .b = 2, | 400 | .b = 2, |
| 401 | }; | 401 | }; |
| 402 | switch (comptime builtin.cpu.arch.endian()) { | 402 | switch (comptime builtin.cpu.arch.endian()) { |
| 403 | .Little => { | 403 | .little => { |
| 404 | comptime assert(@TypeOf(&b.a) == *align(4) u16); | 404 | comptime assert(@TypeOf(&b.a) == *align(4) u16); |
| 405 | comptime assert(@TypeOf(&b.b) == *u16); | 405 | comptime assert(@TypeOf(&b.b) == *u16); |
| 406 | }, | 406 | }, |
| 407 | .Big => { | 407 | .big => { |
| 408 | comptime assert(@TypeOf(&b.a) == *align(4:0:4) u16); | 408 | comptime assert(@TypeOf(&b.a) == *align(4:0:4) u16); |
| 409 | comptime assert(@TypeOf(&b.b) == *align(4:16:4) u16); | 409 | comptime assert(@TypeOf(&b.b) == *align(4:16:4) u16); |
| 410 | }, | 410 | }, |
| ... | @@ -433,7 +433,7 @@ test "nested packed struct field pointers" { | ... | @@ -433,7 +433,7 @@ test "nested packed struct field pointers" { |
| 433 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 433 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 434 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // ubsan unaligned pointer access | 434 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // ubsan unaligned pointer access |
| 435 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 435 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 436 | if (native_endian != .Little) return error.SkipZigTest; // Byte aligned packed struct field pointers have not been implemented yet | 436 | if (native_endian != .little) return error.SkipZigTest; // Byte aligned packed struct field pointers have not been implemented yet |
| 437 | 437 | ||
| 438 | const S2 = packed struct { | 438 | const S2 = packed struct { |
| 439 | base: u8, | 439 | base: u8, |
| ... | @@ -491,7 +491,7 @@ test "@intFromPtr on a packed struct field" { | ... | @@ -491,7 +491,7 @@ test "@intFromPtr on a packed struct field" { |
| 491 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | 491 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 492 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 492 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 493 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 493 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 494 | if (native_endian != .Little) return error.SkipZigTest; | 494 | if (native_endian != .little) return error.SkipZigTest; |
| 495 | 495 | ||
| 496 | const S = struct { | 496 | const S = struct { |
| 497 | const P = packed struct { | 497 | const P = packed struct { |
| ... | @@ -515,7 +515,7 @@ test "@intFromPtr on a packed struct field unaligned and nested" { | ... | @@ -515,7 +515,7 @@ test "@intFromPtr on a packed struct field unaligned and nested" { |
| 515 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 515 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 516 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 516 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 517 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 517 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 518 | if (native_endian != .Little) return error.SkipZigTest; // Byte aligned packed struct field pointers have not been implemented yet | 518 | if (native_endian != .little) return error.SkipZigTest; // Byte aligned packed struct field pointers have not been implemented yet |
| 519 | 519 | ||
| 520 | const S1 = packed struct { | 520 | const S1 = packed struct { |
| 521 | a: u4, | 521 | a: u4, |
| ... | @@ -921,11 +921,11 @@ test "overaligned pointer to packed struct" { | ... | @@ -921,11 +921,11 @@ test "overaligned pointer to packed struct" { |
| 921 | var foo: S align(4) = .{ .a = 123, .b = 456 }; | 921 | var foo: S align(4) = .{ .a = 123, .b = 456 }; |
| 922 | const ptr: *align(4) S = &foo; | 922 | const ptr: *align(4) S = &foo; |
| 923 | switch (comptime builtin.cpu.arch.endian()) { | 923 | switch (comptime builtin.cpu.arch.endian()) { |
| 924 | .Little => { | 924 | .little => { |
| 925 | const ptr_to_b: *u32 = &ptr.b; | 925 | const ptr_to_b: *u32 = &ptr.b; |
| 926 | try expect(ptr_to_b.* == 456); | 926 | try expect(ptr_to_b.* == 456); |
| 927 | }, | 927 | }, |
| 928 | .Big => { | 928 | .big => { |
| 929 | // Byte aligned packed struct field pointers have not been implemented yet. | 929 | // Byte aligned packed struct field pointers have not been implemented yet. |
| 930 | const ptr_to_a: *align(4:0:8) u32 = &ptr.a; | 930 | const ptr_to_a: *align(4:0:8) u32 = &ptr.a; |
| 931 | try expect(ptr_to_a.* == 123); | 931 | try expect(ptr_to_a.* == 123); |
test/behavior/packed_struct_explicit_backing_int.zig+1-1| ... | @@ -24,7 +24,7 @@ test "packed struct explicit backing integer" { | ... | @@ -24,7 +24,7 @@ test "packed struct explicit backing integer" { |
| 24 | try expectEqual(3, @offsetOf(S3, "y")); | 24 | try expectEqual(3, @offsetOf(S3, "y")); |
| 25 | try expectEqual(24, @bitOffsetOf(S3, "y")); | 25 | try expectEqual(24, @bitOffsetOf(S3, "y")); |
| 26 | 26 | ||
| 27 | if (native_endian == .Little) { | 27 | if (native_endian == .little) { |
| 28 | const s3 = @as(S3Padded, @bitCast(@as(u64, 0xe952d5c71ff4))).s3; | 28 | const s3 = @as(S3Padded, @bitCast(@as(u64, 0xe952d5c71ff4))).s3; |
| 29 | try expectEqual(@as(u8, 0xf4), s3.x.a); | 29 | try expectEqual(@as(u8, 0xf4), s3.x.a); |
| 30 | try expectEqual(@as(u8, 0x1f), s3.x.b); | 30 | try expectEqual(@as(u8, 0x1f), s3.x.b); |
test/behavior/ptrcast.zig+7-7| ... | @@ -13,8 +13,8 @@ test "reinterpret bytes as integer with nonzero offset" { | ... | @@ -13,8 +13,8 @@ test "reinterpret bytes as integer with nonzero offset" { |
| 13 | fn testReinterpretBytesAsInteger() !void { | 13 | fn testReinterpretBytesAsInteger() !void { |
| 14 | const bytes = "\x12\x34\x56\x78\xab"; | 14 | const bytes = "\x12\x34\x56\x78\xab"; |
| 15 | const expected = switch (native_endian) { | 15 | const expected = switch (native_endian) { |
| 16 | .Little => 0xab785634, | 16 | .little => 0xab785634, |
| 17 | .Big => 0x345678ab, | 17 | .big => 0x345678ab, |
| 18 | }; | 18 | }; |
| 19 | try expect(@as(*align(1) const u32, @ptrCast(bytes[1..5])).* == expected); | 19 | try expect(@as(*align(1) const u32, @ptrCast(bytes[1..5])).* == expected); |
| 20 | } | 20 | } |
| ... | @@ -48,8 +48,8 @@ fn testReinterpretStructWrappedBytesAsInteger() !void { | ... | @@ -48,8 +48,8 @@ fn testReinterpretStructWrappedBytesAsInteger() !void { |
| 48 | const S = struct { bytes: [5:0]u8 }; | 48 | const S = struct { bytes: [5:0]u8 }; |
| 49 | const obj = S{ .bytes = "\x12\x34\x56\x78\xab".* }; | 49 | const obj = S{ .bytes = "\x12\x34\x56\x78\xab".* }; |
| 50 | const expected = switch (native_endian) { | 50 | const expected = switch (native_endian) { |
| 51 | .Little => 0xab785634, | 51 | .little => 0xab785634, |
| 52 | .Big => 0x345678ab, | 52 | .big => 0x345678ab, |
| 53 | }; | 53 | }; |
| 54 | try expect(@as(*align(1) const u32, @ptrCast(obj.bytes[1..5])).* == expected); | 54 | try expect(@as(*align(1) const u32, @ptrCast(obj.bytes[1..5])).* == expected); |
| 55 | } | 55 | } |
| ... | @@ -176,7 +176,7 @@ test "reinterpret struct field at comptime" { | ... | @@ -176,7 +176,7 @@ test "reinterpret struct field at comptime" { |
| 176 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | 176 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 177 | 177 | ||
| 178 | const numNative = comptime Bytes.init(0x12345678); | 178 | const numNative = comptime Bytes.init(0x12345678); |
| 179 | if (native_endian != .Little) { | 179 | if (native_endian != .little) { |
| 180 | try expect(std.mem.eql(u8, &[_]u8{ 0x12, 0x34, 0x56, 0x78 }, &numNative.bytes)); | 180 | try expect(std.mem.eql(u8, &[_]u8{ 0x12, 0x34, 0x56, 0x78 }, &numNative.bytes)); |
| 181 | } else { | 181 | } else { |
| 182 | try expect(std.mem.eql(u8, &[_]u8{ 0x78, 0x56, 0x34, 0x12 }, &numNative.bytes)); | 182 | try expect(std.mem.eql(u8, &[_]u8{ 0x78, 0x56, 0x34, 0x12 }, &numNative.bytes)); |
| ... | @@ -201,7 +201,7 @@ test "ptrcast of const integer has the correct object size" { | ... | @@ -201,7 +201,7 @@ test "ptrcast of const integer has the correct object size" { |
| 201 | const is_bytes = @as([*]const u8, @ptrCast(&is_value))[0..@sizeOf(isize)]; | 201 | const is_bytes = @as([*]const u8, @ptrCast(&is_value))[0..@sizeOf(isize)]; |
| 202 | if (@sizeOf(isize) == 8) { | 202 | if (@sizeOf(isize) == 8) { |
| 203 | switch (native_endian) { | 203 | switch (native_endian) { |
| 204 | .Little => { | 204 | .little => { |
| 205 | try expect(is_bytes[0] == 0xff); | 205 | try expect(is_bytes[0] == 0xff); |
| 206 | try expect(is_bytes[1] == 0xff); | 206 | try expect(is_bytes[1] == 0xff); |
| 207 | try expect(is_bytes[2] == 0xff); | 207 | try expect(is_bytes[2] == 0xff); |
| ... | @@ -212,7 +212,7 @@ test "ptrcast of const integer has the correct object size" { | ... | @@ -212,7 +212,7 @@ test "ptrcast of const integer has the correct object size" { |
| 212 | try expect(is_bytes[6] == 0xff); | 212 | try expect(is_bytes[6] == 0xff); |
| 213 | try expect(is_bytes[7] == 0x7f); | 213 | try expect(is_bytes[7] == 0x7f); |
| 214 | }, | 214 | }, |
| 215 | .Big => { | 215 | .big => { |
| 216 | try expect(is_bytes[0] == 0x7f); | 216 | try expect(is_bytes[0] == 0x7f); |
| 217 | try expect(is_bytes[1] == 0xff); | 217 | try expect(is_bytes[1] == 0xff); |
| 218 | try expect(is_bytes[2] == 0xff); | 218 | try expect(is_bytes[2] == 0xff); |
test/behavior/union.zig+3-3| ... | @@ -1686,7 +1686,7 @@ test "memset packed union" { | ... | @@ -1686,7 +1686,7 @@ test "memset packed union" { |
| 1686 | } | 1686 | } |
| 1687 | 1687 | ||
| 1688 | fn littleToNativeEndian(comptime T: type, v: T) T { | 1688 | fn littleToNativeEndian(comptime T: type, v: T) T { |
| 1689 | return if (endian == .Little) v else @byteSwap(v); | 1689 | return if (endian == .little) v else @byteSwap(v); |
| 1690 | } | 1690 | } |
| 1691 | 1691 | ||
| 1692 | test "reinterpret extern union" { | 1692 | test "reinterpret extern union" { |
| ... | @@ -1723,8 +1723,8 @@ test "reinterpret extern union" { | ... | @@ -1723,8 +1723,8 @@ test "reinterpret extern union" { |
| 1723 | 1723 | ||
| 1724 | { | 1724 | { |
| 1725 | const expected, const mask = switch (endian) { | 1725 | const expected, const mask = switch (endian) { |
| 1726 | .Little => .{ 0x2a, 0xff }, | 1726 | .little => .{ 0x2a, 0xff }, |
| 1727 | .Big => .{ 0x2a000000, 0xff000000 }, | 1727 | .big => .{ 0x2a000000, 0xff000000 }, |
| 1728 | }; | 1728 | }; |
| 1729 | 1729 | ||
| 1730 | try expectEqual(@as(u8, 0x2a), u.foo); | 1730 | try expectEqual(@as(u8, 0x2a), u.foo); |
tools/gen_stubs.zig+4-4| ... | @@ -234,12 +234,12 @@ pub fn main() !void { | ... | @@ -234,12 +234,12 @@ pub fn main() !void { |
| 234 | 234 | ||
| 235 | switch (header.is_64) { | 235 | switch (header.is_64) { |
| 236 | true => switch (header.endian) { | 236 | true => switch (header.endian) { |
| 237 | .Big => try parseElf(parse, true, .Big), | 237 | .big => try parseElf(parse, true, .big), |
| 238 | .Little => try parseElf(parse, true, .Little), | 238 | .little => try parseElf(parse, true, .little), |
| 239 | }, | 239 | }, |
| 240 | false => switch (header.endian) { | 240 | false => switch (header.endian) { |
| 241 | .Big => try parseElf(parse, false, .Big), | 241 | .big => try parseElf(parse, false, .big), |
| 242 | .Little => try parseElf(parse, false, .Little), | 242 | .little => try parseElf(parse, false, .little), |
| 243 | }, | 243 | }, |
| 244 | } | 244 | } |
| 245 | } | 245 | } |