authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-11-01 06:33:40-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-11-01 06:33:40-04:00
log725f765c376dda291d3d5afe5446221a97c189f7
treed2c1d77794ba13140aa4a3f0303d56bbec2bd27f
parent46062f1c13d8ee9eebf49806660c2271f2acc613
parent13b1e10b8f3d8df92417999ed972e5f682c82a46
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #17802 from jacobly0/read-write-int

mem: fix UB in `readInt`/`writeInt` and delete variants

169 files changed, 1472 insertions(+), 1821 deletions(-)

deps/aro/Compilation.zig+1-1
......@@ -402,7 +402,7 @@ pub fn generateBuiltinMacros(comp: *Compilation) !Source {
402402 \\#define __ORDER_PDP_ENDIAN__ 3412
403403 \\
404404 );
405 if (comp.target.cpu.arch.endian() == .Little) try w.writeAll(
405 if (comp.target.cpu.arch.endian() == .little) try w.writeAll(
406406 \\#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
407407 \\#define __LITTLE_ENDIAN__ 1
408408 \\
deps/aro/target.zig+2-2
......@@ -398,8 +398,8 @@ pub fn ldEmulationOption(target: std.Target, arm_endianness: ?std.builtin.Endian
398398 .thumb,
399399 .thumbeb,
400400 => switch (arm_endianness orelse target.cpu.arch.endian()) {
401 .Little => "armelf_linux_eabi",
402 .Big => "armelfb_linux_eabi",
401 .little => "armelf_linux_eabi",
402 .big => "armelfb_linux_eabi",
403403 },
404404 .aarch64 => "aarch64linux",
405405 .aarch64_be => "aarch64linuxb",
doc/langref.html.in+2-2
......@@ -3376,11 +3376,11 @@ fn doTheTest() !void {
33763376
33773377 var ordered: [2]u8 = @bitCast(full);
33783378 switch (native_endian) {
3379 .Big => {
3379 .big => {
33803380 try expect(ordered[0] == 0x12);
33813381 try expect(ordered[1] == 0x34);
33823382 },
3383 .Little => {
3383 .little => {
33843384 try expect(ordered[0] == 0x34);
33853385 try expect(ordered[1] == 0x12);
33863386 },
lib/compiler_rt/common.zig+1-1
......@@ -249,7 +249,7 @@ pub fn HalveInt(comptime T: type, comptime signed_half: bool) type {
249249 pub const HalfT = if (signed_half) HalfTS else HalfTU;
250250
251251 all: T,
252 s: if (native_endian == .Little)
252 s: if (native_endian == .little)
253253 extern struct { low: HalfT, high: HalfT }
254254 else
255255 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 {
142142 const bPtr_u16: [*]u16 = @ptrCast(&bmod);
143143
144144 const exp_and_sign_index = comptime switch (builtin.target.cpu.arch.endian()) {
145 .Little => 7,
146 .Big => 0,
145 .little => 7,
146 .big => 0,
147147 };
148148 const low_index = comptime switch (builtin.target.cpu.arch.endian()) {
149 .Little => 0,
150 .Big => 1,
149 .little => 0,
150 .big => 1,
151151 };
152152 const high_index = comptime switch (builtin.target.cpu.arch.endian()) {
153 .Little => 1,
154 .Big => 0,
153 .little => 1,
154 .big => 0,
155155 };
156156
157157 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;
55const HalveInt = @import("common.zig").HalveInt;
66
77const lo = switch (builtin.cpu.arch.endian()) {
8 .Big => 1,
9 .Little => 0,
8 .big => 1,
9 .little => 0,
1010};
1111const hi = 1 - lo;
1212
lib/compiler_rt/udivmodei4.zig+2-2
......@@ -15,12 +15,12 @@ const endian = builtin.cpu.arch.endian();
1515
1616/// Get the value of a limb.
1717inline 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];
1919}
2020
2121/// Change the value of a limb.
2222inline fn limb_set(x: []u32, i: usize, v: u32) void {
23 if (endian == .Little) {
23 if (endian == .little) {
2424 x[i] = v;
2525 } else {
2626 x[x.len - 1 - i] = v;
lib/std/Build/Step/CheckObject.zig+2-2
......@@ -1624,8 +1624,8 @@ const WasmDumper = struct {
16241624 switch (opcode) {
16251625 .i32_const => try writer.print("i32.const {x}\n", .{try std.leb.readILEB128(i32, reader)}),
16261626 .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.readIntLittle(u32)))}),
1628 .f64_const => try writer.print("f64.const {x}\n", .{@as(f64, @bitCast(try reader.readIntLittle(u64)))}),
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)))}),
16291629 .global_get => try writer.print("global.get {x}\n", .{try std.leb.readULEB128(u32, reader)}),
16301630 else => unreachable,
16311631 }
lib/std/base64.zig+4-4
......@@ -104,14 +104,14 @@ pub const Base64Encoder = struct {
104104 var idx: usize = 0;
105105 var out_idx: usize = 0;
106106 while (idx + 15 < source.len) : (idx += 12) {
107 const bits = std.mem.readIntBig(u128, source[idx..][0..16]);
107 const bits = std.mem.readInt(u128, source[idx..][0..16], .big);
108108 inline for (0..16) |i| {
109109 dest[out_idx + i] = encoder.alphabet_chars[@truncate((bits >> (122 - i * 6)) & 0x3f)];
110110 }
111111 out_idx += 16;
112112 }
113113 while (idx + 3 < source.len) : (idx += 3) {
114 const bits = std.mem.readIntBig(u32, source[idx..][0..4]);
114 const bits = std.mem.readInt(u32, source[idx..][0..4], .big);
115115 dest[out_idx] = encoder.alphabet_chars[(bits >> 26) & 0x3f];
116116 dest[out_idx + 1] = encoder.alphabet_chars[(bits >> 20) & 0x3f];
117117 dest[out_idx + 2] = encoder.alphabet_chars[(bits >> 14) & 0x3f];
......@@ -226,7 +226,7 @@ pub const Base64Decoder = struct {
226226 if ((new_bits & invalid_char_tst) != 0) return error.InvalidCharacter;
227227 bits |= (new_bits << (24 * i));
228228 }
229 std.mem.writeIntLittle(u128, dest[dest_idx..][0..16], bits);
229 std.mem.writeInt(u128, dest[dest_idx..][0..16], bits, .little);
230230 }
231231 while (fast_src_idx + 4 < source.len and dest_idx + 3 < dest.len) : ({
232232 fast_src_idx += 4;
......@@ -237,7 +237,7 @@ pub const Base64Decoder = struct {
237237 bits |= decoder.fast_char_to_index[2][source[fast_src_idx + 2]];
238238 bits |= decoder.fast_char_to_index[3][source[fast_src_idx + 3]];
239239 if ((bits & invalid_char_tst) != 0) return error.InvalidCharacter;
240 std.mem.writeIntLittle(u32, dest[dest_idx..][0..4], bits);
240 std.mem.writeInt(u32, dest[dest_idx..][0..4], bits, .little);
241241 }
242242 var remaining = source[fast_src_idx..];
243243 for (remaining, fast_src_idx..) |c, src_idx| {
lib/std/builtin.zig+2-2
......@@ -450,8 +450,8 @@ pub const FloatMode = enum {
450450/// This data structure is used by the Zig language code generation and
451451/// therefore must be kept in sync with the compiler implementation.
452452pub const Endian = enum {
453 Big,
454 Little,
453 big,
454 little,
455455};
456456
457457/// 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 {
13761376 .capable_io_mode = .blocking,
13771377 .intended_io_mode = .blocking,
13781378 };
1379 file.writer().writeIntNative(u64, @as(u64, @intCast(value))) catch return error.SystemResources;
1379 file.writer().writeInt(u64, @intCast(value), .little) catch return error.SystemResources;
13801380}
13811381
13821382fn readIntFd(fd: i32) !ErrInt {
......@@ -1385,7 +1385,7 @@ fn readIntFd(fd: i32) !ErrInt {
13851385 .capable_io_mode = .blocking,
13861386 .intended_io_mode = .blocking,
13871387 };
1388 return @as(ErrInt, @intCast(file.reader().readIntNative(u64) catch return error.SystemResources));
1388 return @as(ErrInt, @intCast(file.reader().readInt(u64, .little) catch return error.SystemResources));
13891389}
13901390
13911391/// Caller must free result.
lib/std/coff.zig+20-20
......@@ -663,7 +663,7 @@ pub const Symbol = struct {
663663
664664 pub fn getNameOffset(self: Symbol) ?u32 {
665665 if (!std.mem.eql(u8, self.name[0..4], "\x00\x00\x00\x00")) return null;
666 const offset = std.mem.readIntLittle(u32, self.name[4..8]);
666 const offset = std.mem.readInt(u32, self.name[4..8], .little);
667667 return offset;
668668 }
669669};
......@@ -1075,7 +1075,7 @@ pub const Coff = struct {
10751075 var stream = std.io.fixedBufferStream(data);
10761076 const reader = stream.reader();
10771077 try stream.seekTo(pe_pointer_offset);
1078 var coff_header_offset = try reader.readIntLittle(u32);
1078 var coff_header_offset = try reader.readInt(u32, .little);
10791079 try stream.seekTo(coff_header_offset);
10801080 var buf: [4]u8 = undefined;
10811081 try reader.readNoEof(&buf);
......@@ -1142,7 +1142,7 @@ pub const Coff = struct {
11421142 if (!mem.eql(u8, &cv_signature, "RSDS"))
11431143 return error.InvalidPEMagic;
11441144 try reader.readNoEof(self.guid[0..]);
1145 self.age = try reader.readIntLittle(u32);
1145 self.age = try reader.readInt(u32, .little);
11461146
11471147 // Finally read the null-terminated string.
11481148 var byte = try reader.readByte();
......@@ -1223,7 +1223,7 @@ pub const Coff = struct {
12231223 if (coff_header.pointer_to_symbol_table == 0) return null;
12241224
12251225 const offset = coff_header.pointer_to_symbol_table + Symbol.sizeOf() * coff_header.number_of_symbols;
1226 const size = mem.readIntLittle(u32, self.data[offset..][0..4]);
1226 const size = mem.readInt(u32, self.data[offset..][0..4], .little);
12271227 if ((offset + size) > self.data.len) return error.InvalidStrtabSize;
12281228
12291229 return Strtab{ .buffer = self.data[offset..][0..size] };
......@@ -1324,9 +1324,9 @@ pub const Symtab = struct {
13241324 fn asSymbol(raw: []const u8) Symbol {
13251325 return .{
13261326 .name = raw[0..8].*,
1327 .value = mem.readIntLittle(u32, raw[8..12]),
1328 .section_number = @as(SectionNumber, @enumFromInt(mem.readIntLittle(u16, raw[12..14]))),
1329 .type = @as(SymType, @bitCast(mem.readIntLittle(u16, raw[14..16]))),
1327 .value = mem.readInt(u32, raw[8..12], .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))),
13301330 .storage_class = @as(StorageClass, @enumFromInt(raw[16])),
13311331 .number_of_aux_symbols = raw[17],
13321332 };
......@@ -1335,27 +1335,27 @@ pub const Symtab = struct {
13351335 fn asDebugInfo(raw: []const u8) DebugInfoDefinition {
13361336 return .{
13371337 .unused_1 = raw[0..4].*,
1338 .linenumber = mem.readIntLittle(u16, raw[4..6]),
1338 .linenumber = mem.readInt(u16, raw[4..6], .little),
13391339 .unused_2 = raw[6..12].*,
1340 .pointer_to_next_function = mem.readIntLittle(u32, raw[12..16]),
1340 .pointer_to_next_function = mem.readInt(u32, raw[12..16], .little),
13411341 .unused_3 = raw[16..18].*,
13421342 };
13431343 }
13441344
13451345 fn asFuncDef(raw: []const u8) FunctionDefinition {
13461346 return .{
1347 .tag_index = mem.readIntLittle(u32, raw[0..4]),
1348 .total_size = mem.readIntLittle(u32, raw[4..8]),
1349 .pointer_to_linenumber = mem.readIntLittle(u32, raw[8..12]),
1350 .pointer_to_next_function = mem.readIntLittle(u32, raw[12..16]),
1347 .tag_index = mem.readInt(u32, raw[0..4], .little),
1348 .total_size = mem.readInt(u32, raw[4..8], .little),
1349 .pointer_to_linenumber = mem.readInt(u32, raw[8..12], .little),
1350 .pointer_to_next_function = mem.readInt(u32, raw[12..16], .little),
13511351 .unused = raw[16..18].*,
13521352 };
13531353 }
13541354
13551355 fn asWeakExtDef(raw: []const u8) WeakExternalDefinition {
13561356 return .{
1357 .tag_index = mem.readIntLittle(u32, raw[0..4]),
1358 .flag = @as(WeakExternalFlag, @enumFromInt(mem.readIntLittle(u32, raw[4..8]))),
1357 .tag_index = mem.readInt(u32, raw[0..4], .little),
1358 .flag = @as(WeakExternalFlag, @enumFromInt(mem.readInt(u32, raw[4..8], .little))),
13591359 .unused = raw[8..18].*,
13601360 };
13611361 }
......@@ -1368,11 +1368,11 @@ pub const Symtab = struct {
13681368
13691369 fn asSectDef(raw: []const u8) SectionDefinition {
13701370 return .{
1371 .length = mem.readIntLittle(u32, raw[0..4]),
1372 .number_of_relocations = mem.readIntLittle(u16, raw[4..6]),
1373 .number_of_linenumbers = mem.readIntLittle(u16, raw[6..8]),
1374 .checksum = mem.readIntLittle(u32, raw[8..12]),
1375 .number = mem.readIntLittle(u16, raw[12..14]),
1371 .length = mem.readInt(u32, raw[0..4], .little),
1372 .number_of_relocations = mem.readInt(u16, raw[4..6], .little),
1373 .number_of_linenumbers = mem.readInt(u16, raw[6..8], .little),
1374 .checksum = mem.readInt(u32, raw[8..12], .little),
1375 .number = mem.readInt(u16, raw[12..14], .little),
13761376 .selection = @as(ComdatSelection, @enumFromInt(raw[14])),
13771377 .unused = raw[15..18].*,
13781378 };
lib/std/compress/gzip.zig+5-5
......@@ -58,7 +58,7 @@ pub fn Decompress(comptime ReaderType: type) type {
5858 const FLG = header[3];
5959 // Modification time, as a Unix timestamp.
6060 // If zero there's no timestamp available.
61 const MTIME = mem.readIntLittle(u32, header[4..8]);
61 const MTIME = mem.readInt(u32, header[4..8], .little);
6262 // Extra flags
6363 const XFL = header[8];
6464 // Operating system where the compression took place
......@@ -66,7 +66,7 @@ pub fn Decompress(comptime ReaderType: type) type {
6666 _ = XFL;
6767
6868 const extra = if (FLG & FEXTRA != 0) blk: {
69 const len = try hashed_reader.readIntLittle(u16);
69 const len = try hashed_reader.readInt(u16, .little);
7070 const tmp_buf = try allocator.alloc(u8, len);
7171 errdefer allocator.free(tmp_buf);
7272
......@@ -88,7 +88,7 @@ pub fn Decompress(comptime ReaderType: type) type {
8888 errdefer if (comment) |p| allocator.free(p);
8989
9090 if (FLG & FHCRC != 0) {
91 const hash = try source.readIntLittle(u16);
91 const hash = try source.readInt(u16, .little);
9292 if (hash != @as(u16, @truncate(hasher.hasher.final())))
9393 return error.WrongChecksum;
9494 }
......@@ -133,12 +133,12 @@ pub fn Decompress(comptime ReaderType: type) type {
133133 }
134134
135135 // We've reached the end of stream, check if the checksum matches
136 const hash = try self.in_reader.readIntLittle(u32);
136 const hash = try self.in_reader.readInt(u32, .little);
137137 if (hash != self.hasher.final())
138138 return error.WrongChecksum;
139139
140140 // The ISIZE field is the size of the uncompressed input modulo 2^32
141 const input_size = try self.in_reader.readIntLittle(u32);
141 const input_size = try self.in_reader.readInt(u32, .little);
142142 if (self.read_amt & 0xffffffff != input_size)
143143 return error.CorruptedData;
144144
lib/std/compress/lzma/decode.zig+3-3
......@@ -58,12 +58,12 @@ pub const Params = struct {
5858 props /= 5;
5959 const pb = @as(u3, @intCast(props));
6060
61 const dict_size_provided = try reader.readIntLittle(u32);
61 const dict_size_provided = try reader.readInt(u32, .little);
6262 const dict_size = @max(0x1000, dict_size_provided);
6363
6464 const unpacked_size = switch (options.unpacked_size) {
6565 .read_from_header => blk: {
66 const unpacked_size_provided = try reader.readIntLittle(u64);
66 const unpacked_size_provided = try reader.readInt(u64, .little);
6767 const marker_mandatory = unpacked_size_provided == 0xFFFF_FFFF_FFFF_FFFF;
6868 break :blk if (marker_mandatory)
6969 null
......@@ -71,7 +71,7 @@ pub const Params = struct {
7171 unpacked_size_provided;
7272 },
7373 .read_header_but_use_provided => |x| blk: {
74 _ = try reader.readIntLittle(u64);
74 _ = try reader.readInt(u64, .little);
7575 break :blk x;
7676 },
7777 .use_provided => |x| x,
lib/std/compress/lzma/decode/rangecoder.zig+1-1
......@@ -12,7 +12,7 @@ pub const RangeDecoder = struct {
1212 }
1313 return RangeDecoder{
1414 .range = 0xFFFF_FFFF,
15 .code = try reader.readIntBig(u32),
15 .code = try reader.readInt(u32, .big),
1616 };
1717 }
1818
lib/std/compress/lzma2/decode.zig+3-3
......@@ -97,12 +97,12 @@ pub const Decoder = struct {
9797 const unpacked_size = blk: {
9898 var tmp: u64 = status & 0x1F;
9999 tmp <<= 16;
100 tmp |= try reader.readIntBig(u16);
100 tmp |= try reader.readInt(u16, .big);
101101 break :blk tmp + 1;
102102 };
103103
104104 const packed_size = blk: {
105 const tmp: u17 = try reader.readIntBig(u16);
105 const tmp: u17 = try reader.readInt(u16, .big);
106106 break :blk tmp + 1;
107107 };
108108
......@@ -155,7 +155,7 @@ pub const Decoder = struct {
155155 accum: *LzAccumBuffer,
156156 reset_dict: bool,
157157 ) !void {
158 const unpacked_size = @as(u17, try reader.readIntBig(u16)) + 1;
158 const unpacked_size = @as(u17, try reader.readInt(u16, .big)) + 1;
159159
160160 if (reset_dict) {
161161 try accum.reset(writer);
lib/std/compress/xz.zig+5-5
......@@ -12,7 +12,7 @@ pub const Check = enum(u4) {
1212};
1313
1414fn readStreamFlags(reader: anytype, check: *Check) !void {
15 var bit_reader = std.io.bitReader(.Little, reader);
15 var bit_reader = std.io.bitReader(.little, reader);
1616
1717 const reserved1 = try bit_reader.readBitsNoEof(u8, 8);
1818 if (reserved1 != 0)
......@@ -52,7 +52,7 @@ pub fn Decompress(comptime ReaderType: type) type {
5252 break :blk hasher.hasher.final();
5353 };
5454
55 const hash_b = try source.readIntLittle(u32);
55 const hash_b = try source.readInt(u32, .little);
5656 if (hash_a != hash_b)
5757 return error.WrongChecksum;
5858
......@@ -105,20 +105,20 @@ pub fn Decompress(comptime ReaderType: type) type {
105105 }
106106
107107 const hash_a = hasher.hasher.final();
108 const hash_b = try counting_reader.readIntLittle(u32);
108 const hash_b = try counting_reader.readInt(u32, .little);
109109 if (hash_a != hash_b)
110110 return error.WrongChecksum;
111111
112112 break :blk counter.bytes_read;
113113 };
114114
115 const hash_a = try self.in_reader.readIntLittle(u32);
115 const hash_a = try self.in_reader.readInt(u32, .little);
116116
117117 const hash_b = blk: {
118118 var hasher = std.compress.hashedReader(self.in_reader, Crc32.init());
119119 const hashed_reader = hasher.reader();
120120
121 const backward_size = (@as(u64, try hashed_reader.readIntLittle(u32)) + 1) * 4;
121 const backward_size = (@as(u64, try hashed_reader.readInt(u32, .little)) + 1) * 4;
122122 if (backward_size != index_size)
123123 return error.CorruptInput;
124124
lib/std/compress/xz/block.zig+3-3
......@@ -148,7 +148,7 @@ pub fn Decoder(comptime ReaderType: type) type {
148148 }
149149
150150 const hash_a = header_hasher.hasher.final();
151 const hash_b = try header_reader.readIntLittle(u32);
151 const hash_b = try header_reader.readInt(u32, .little);
152152 if (hash_a != hash_b)
153153 return error.WrongChecksum;
154154 }
......@@ -182,13 +182,13 @@ pub fn Decoder(comptime ReaderType: type) type {
182182 .none => {},
183183 .crc32 => {
184184 const hash_a = Crc32.hash(unpacked_bytes);
185 const hash_b = try self.inner_reader.readIntLittle(u32);
185 const hash_b = try self.inner_reader.readInt(u32, .little);
186186 if (hash_a != hash_b)
187187 return error.WrongChecksum;
188188 },
189189 .crc64 => {
190190 const hash_a = Crc64.hash(unpacked_bytes);
191 const hash_b = try self.inner_reader.readIntLittle(u64);
191 const hash_b = try self.inner_reader.readInt(u64, .little);
192192 if (hash_a != hash_b)
193193 return error.WrongChecksum;
194194 },
lib/std/compress/zlib.zig+4-4
......@@ -36,7 +36,7 @@ pub fn DecompressStream(comptime ReaderType: type) type {
3636
3737 fn init(allocator: mem.Allocator, source: ReaderType) !Self {
3838 // Zlib header format is specified in RFC1950
39 const header_u16 = try source.readIntBig(u16);
39 const header_u16 = try source.readInt(u16, .big);
4040
4141 // verify the header checksum
4242 if (header_u16 % 31 != 0)
......@@ -81,7 +81,7 @@ pub fn DecompressStream(comptime ReaderType: type) type {
8181 }
8282
8383 // We've reached the end of stream, check if the checksum matches
84 const hash = try self.in_reader.readIntBig(u32);
84 const hash = try self.in_reader.readInt(u32, .big);
8585 if (hash != self.hasher.final())
8686 return error.WrongChecksum;
8787
......@@ -132,7 +132,7 @@ pub fn CompressStream(comptime WriterType: type) type {
132132 };
133133 header.checksum = @as(u5, @truncate(31 - @as(u16, @bitCast(header)) % 31));
134134
135 try dest.writeIntBig(u16, @as(u16, @bitCast(header)));
135 try dest.writeInt(u16, @as(u16, @bitCast(header)), .big);
136136
137137 const compression_level: deflate.Compression = switch (options.level) {
138138 .no_compression => .no_compression,
......@@ -171,7 +171,7 @@ pub fn CompressStream(comptime WriterType: type) type {
171171 pub fn finish(self: *Self) !void {
172172 const hash = self.hasher.final();
173173 try self.deflator.close();
174 try self.in_writer.writeIntBig(u32, hash);
174 try self.in_writer.writeInt(u32, hash, .big);
175175 }
176176 };
177177}
lib/std/compress/zstandard.zig+1-1
......@@ -201,7 +201,7 @@ pub fn DecompressStream(
201201 if (block_header.last_block) {
202202 self.state = .LastBlock;
203203 if (self.frame_context.has_checksum) {
204 const checksum = source_reader.readIntLittle(u32) catch
204 const checksum = source_reader.readInt(u32, .little) catch
205205 return error.MalformedFrame;
206206 if (comptime options.verify_checksum) {
207207 if (self.frame_context.hasher_opt) |*hasher| {
lib/std/compress/zstandard/decode/block.zig+3-5
......@@ -13,8 +13,6 @@ const readers = @import("../readers.zig");
1313
1414const decodeFseTable = @import("fse.zig").decodeFseTable;
1515
16const readInt = std.mem.readIntLittle;
17
1816pub const Error = error{
1917 BlockSizeOverMaximum,
2018 MalformedBlockSize,
......@@ -1031,9 +1029,9 @@ fn decodeStreams(size_format: u2, stream_data: []const u8) !LiteralsSection.Stre
10311029
10321030 if (stream_data.len < 6) return error.MalformedLiteralsSection;
10331031
1034 const stream_1_length = @as(usize, readInt(u16, stream_data[0..2]));
1035 const stream_2_length = @as(usize, readInt(u16, stream_data[2..4]));
1036 const stream_3_length = @as(usize, readInt(u16, stream_data[4..6]));
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);
1034 const stream_3_length: usize = std.mem.readInt(u16, stream_data[4..6], .little);
10371035
10381036 const stream_1_start = 6;
10391037 const stream_2_start = stream_1_start + stream_1_length;
lib/std/compress/zstandard/decompress.zig+14-17
......@@ -15,9 +15,6 @@ pub const block = @import("decode/block.zig");
1515
1616const readers = @import("readers.zig");
1717
18const readInt = std.mem.readIntLittle;
19const readIntSlice = std.mem.readIntSliceLittle;
20
2118/// Returns `true` is `magic` is a valid magic number for a skippable frame
2219pub fn isSkippableMagic(magic: u32) bool {
2320 return frame.Skippable.magic_number_min <= magic and magic <= frame.Skippable.magic_number_max;
......@@ -31,7 +28,7 @@ pub fn isSkippableMagic(magic: u32) bool {
3128/// skippable frames.
3229/// - `error.EndOfStream` if `source` contains fewer than 4 bytes
3330pub fn decodeFrameType(source: anytype) error{ BadMagic, EndOfStream }!frame.Kind {
34 const magic = try source.readIntLittle(u32);
31 const magic = try source.readInt(u32, .little);
3532 return frameType(magic);
3633}
3734
......@@ -65,14 +62,14 @@ pub const HeaderError = error{ BadMagic, EndOfStream, ReservedBitSet };
6562/// - `error.ReservedBitSet` if the frame is a Zstandard frame and any of the
6663/// reserved bits are set
6764pub fn decodeFrameHeader(source: anytype) (@TypeOf(source).Error || HeaderError)!FrameHeader {
68 const magic = try source.readIntLittle(u32);
65 const magic = try source.readInt(u32, .little);
6966 const frame_type = try frameType(magic);
7067 switch (frame_type) {
7168 .zstandard => return FrameHeader{ .zstandard = try decodeZstandardHeader(source) },
7269 .skippable => return FrameHeader{
7370 .skippable = .{
7471 .magic_number = magic,
75 .frame_size = try source.readIntLittle(u32),
72 .frame_size = try source.readInt(u32, .little),
7673 },
7774 },
7875 }
......@@ -193,7 +190,7 @@ pub fn decodeFrame(
193190 switch (try decodeFrameType(fbs.reader())) {
194191 .zstandard => return decodeZstandardFrame(dest, src, verify_checksum),
195192 .skippable => {
196 const content_size = try fbs.reader().readIntLittle(u32);
193 const content_size = try fbs.reader().readInt(u32, .little);
197194 if (content_size > std.math.maxInt(usize) - 8) return error.SkippableSizeTooLarge;
198195 const read_count = @as(usize, content_size) + 8;
199196 if (read_count > src.len) return error.SkippableSizeTooLarge;
......@@ -238,7 +235,7 @@ pub fn decodeFrameArrayList(
238235) (error{ BadMagic, OutOfMemory, SkippableSizeTooLarge } || FrameContext.Error || FrameError)!usize {
239236 var fbs = std.io.fixedBufferStream(src);
240237 const reader = fbs.reader();
241 const magic = try reader.readIntLittle(u32);
238 const magic = try reader.readInt(u32, .little);
242239 switch (try frameType(magic)) {
243240 .zstandard => return decodeZstandardFrameArrayList(
244241 allocator,
......@@ -248,7 +245,7 @@ pub fn decodeFrameArrayList(
248245 window_size_max,
249246 ),
250247 .skippable => {
251 const content_size = try fbs.reader().readIntLittle(u32);
248 const content_size = try fbs.reader().readInt(u32, .little);
252249 if (content_size > std.math.maxInt(usize) - 8) return error.SkippableSizeTooLarge;
253250 const read_count = @as(usize, content_size) + 8;
254251 if (read_count > src.len) return error.SkippableSizeTooLarge;
......@@ -302,7 +299,7 @@ pub fn decodeZstandardFrame(
302299 WindowSizeUnknown,
303300 DictionaryIdFlagUnsupported,
304301} || FrameError)!ReadWriteCount {
305 assert(readInt(u32, src[0..4]) == frame.Zstandard.magic_number);
302 assert(std.mem.readInt(u32, src[0..4], .little) == frame.Zstandard.magic_number);
306303 var consumed_count: usize = 4;
307304
308305 var frame_context = context: {
......@@ -354,7 +351,7 @@ pub fn decodeZStandardFrameBlocks(
354351 if (written_count != content_size) return error.BadContentSize;
355352 if (frame_context.has_checksum) {
356353 if (src.len < consumed_count + 4) return error.EndOfStream;
357 const checksum = readIntSlice(u32, src[consumed_count .. consumed_count + 4]);
354 const checksum = std.mem.readInt(u32, src[consumed_count..][0..4], .little);
358355 consumed_count += 4;
359356 if (frame_context.hasher_opt) |*hasher| {
360357 if (checksum != computeChecksum(hasher)) return error.ChecksumFailure;
......@@ -445,7 +442,7 @@ pub fn decodeZstandardFrameArrayList(
445442 verify_checksum: bool,
446443 window_size_max: usize,
447444) (error{OutOfMemory} || FrameContext.Error || FrameError)!usize {
448 assert(readInt(u32, src[0..4]) == frame.Zstandard.magic_number);
445 assert(std.mem.readInt(u32, src[0..4], .little) == frame.Zstandard.magic_number);
449446 var consumed_count: usize = 4;
450447
451448 var frame_context = context: {
......@@ -520,7 +517,7 @@ pub fn decodeZstandardFrameBlocksArrayList(
520517
521518 if (frame_context.has_checksum) {
522519 if (src.len < consumed_count + 4) return error.EndOfStream;
523 const checksum = readIntSlice(u32, src[consumed_count .. consumed_count + 4]);
520 const checksum = std.mem.readInt(u32, src[consumed_count..][0..4], .little);
524521 consumed_count += 4;
525522 if (frame_context.hasher_opt) |*hasher| {
526523 if (checksum != computeChecksum(hasher)) return error.ChecksumFailure;
......@@ -569,9 +566,9 @@ fn decodeFrameBlocksInner(
569566/// Decode the header of a skippable frame. The first four bytes of `src` must
570567/// be a valid magic number for a skippable frame.
571568pub fn decodeSkippableHeader(src: *const [8]u8) SkippableHeader {
572 const magic = readInt(u32, src[0..4]);
569 const magic = std.mem.readInt(u32, src[0..4], .little);
573570 assert(isSkippableMagic(magic));
574 const frame_size = readInt(u32, src[4..8]);
571 const frame_size = std.mem.readInt(u32, src[4..8], .little);
575572 return .{
576573 .magic_number = magic,
577574 .frame_size = frame_size,
......@@ -612,13 +609,13 @@ pub fn decodeZstandardHeader(
612609 if (descriptor.dictionary_id_flag > 0) {
613610 // if flag is 3 then field_size = 4, else field_size = flag
614611 const field_size = (@as(u4, 1) << descriptor.dictionary_id_flag) >> 1;
615 dictionary_id = try source.readVarInt(u32, .Little, field_size);
612 dictionary_id = try source.readVarInt(u32, .little, field_size);
616613 }
617614
618615 var content_size: ?u64 = null;
619616 if (descriptor.single_segment_flag or descriptor.content_size_flag > 0) {
620617 const field_size = @as(u4, 1) << descriptor.content_size_flag;
621 content_size = try source.readVarInt(u64, .Little, field_size);
618 content_size = try source.readVarInt(u64, .little, field_size);
622619 if (field_size == 2) content_size.? += 256;
623620 }
624621
lib/std/compress/zstandard/readers.zig+4-4
......@@ -31,11 +31,11 @@ pub const ReversedByteReader = struct {
3131/// FSE compressed data.
3232pub const ReverseBitReader = struct {
3333 byte_reader: ReversedByteReader,
34 bit_reader: std.io.BitReader(.Big, ReversedByteReader.Reader),
34 bit_reader: std.io.BitReader(.big, ReversedByteReader.Reader),
3535
3636 pub fn init(self: *ReverseBitReader, bytes: []const u8) error{BitStreamHasNoStartBit}!void {
3737 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());
3939 if (bytes.len == 0) return;
4040 var i: usize = 0;
4141 while (i < 8 and 0 == self.readBitsNoEof(u1, 1) catch unreachable) : (i += 1) {}
......@@ -61,7 +61,7 @@ pub const ReverseBitReader = struct {
6161
6262pub fn BitReader(comptime Reader: type) type {
6363 return struct {
64 underlying: std.io.BitReader(.Little, Reader),
64 underlying: std.io.BitReader(.little, Reader),
6565
6666 pub fn readBitsNoEof(self: *@This(), comptime U: type, num_bits: usize) !U {
6767 return self.underlying.readBitsNoEof(U, num_bits);
......@@ -78,5 +78,5 @@ pub fn BitReader(comptime Reader: type) type {
7878}
7979
8080pub fn bitReader(reader: anytype) BitReader(@TypeOf(reader)) {
81 return .{ .underlying = std.io.bitReader(.Little, reader) };
81 return .{ .underlying = std.io.bitReader(.little, reader) };
8282}
lib/std/crypto/25519/field.zig+9-11
......@@ -1,8 +1,6 @@
11const std = @import("std");
22const builtin = @import("builtin");
33const crypto = std.crypto;
4const readIntLittle = std.mem.readIntLittle;
5const writeIntLittle = std.mem.writeIntLittle;
64
75const NonCanonicalError = crypto.errors.NonCanonicalError;
86const NotSquareError = crypto.errors.NotSquareError;
......@@ -73,11 +71,11 @@ pub const Fe = struct {
7371 /// Unpack a field element
7472 pub fn fromBytes(s: [32]u8) Fe {
7573 var fe: Fe = undefined;
76 fe.limbs[0] = readIntLittle(u64, s[0..8]) & MASK51;
77 fe.limbs[1] = (readIntLittle(u64, s[6..14]) >> 3) & MASK51;
78 fe.limbs[2] = (readIntLittle(u64, s[12..20]) >> 6) & MASK51;
79 fe.limbs[3] = (readIntLittle(u64, s[19..27]) >> 1) & MASK51;
80 fe.limbs[4] = (readIntLittle(u64, s[24..32]) >> 12) & 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;
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;
78 fe.limbs[4] = (std.mem.readInt(u64, s[24..32], .little) >> 12) & MASK51;
8179
8280 return fe;
8381 }
......@@ -87,10 +85,10 @@ pub const Fe = struct {
8785 var reduced = fe;
8886 reduced.reduce();
8987 var s: [32]u8 = undefined;
90 writeIntLittle(u64, s[0..8], reduced.limbs[0] | (reduced.limbs[1] << 51));
91 writeIntLittle(u64, s[8..16], (reduced.limbs[1] >> 13) | (reduced.limbs[2] << 38));
92 writeIntLittle(u64, s[16..24], (reduced.limbs[2] >> 26) | (reduced.limbs[3] << 25));
93 writeIntLittle(u64, s[24..32], (reduced.limbs[3] >> 39) | (reduced.limbs[4] << 12));
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);
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);
9492
9593 return s;
9694 }
lib/std/crypto/25519/scalar.zig+6-6
......@@ -15,7 +15,7 @@ pub const zero = [_]u8{0} ** 32;
1515
1616const field_order_s = s: {
1717 var s: [32]u8 = undefined;
18 mem.writeIntLittle(u256, &s, field_order);
18 mem.writeInt(u256, &s, field_order, .little);
1919 break :s s;
2020};
2121
......@@ -127,9 +127,9 @@ pub const Scalar = struct {
127127 var bytes: CompressedScalar = undefined;
128128 var i: usize = 0;
129129 while (i < 4) : (i += 1) {
130 mem.writeIntLittle(u64, bytes[i * 7 ..][0..8], expanded.limbs[i]);
130 mem.writeInt(u64, bytes[i * 7 ..][0..8], expanded.limbs[i], .little);
131131 }
132 mem.writeIntLittle(u32, bytes[i * 7 ..][0..4], @as(u32, @intCast(expanded.limbs[i])));
132 mem.writeInt(u32, bytes[i * 7 ..][0..4], @intCast(expanded.limbs[i]), .little);
133133 return bytes;
134134 }
135135
......@@ -580,7 +580,7 @@ const ScalarDouble = struct {
580580 var limbs: Limbs = undefined;
581581 var i: usize = 0;
582582 while (i < 9) : (i += 1) {
583 limbs[i] = mem.readIntLittle(u64, bytes[i * 7 ..][0..8]) & 0xffffffffffffff;
583 limbs[i] = mem.readInt(u64, bytes[i * 7 ..][0..8], .little) & 0xffffffffffffff;
584584 }
585585 limbs[i] = @as(u64, bytes[i * 7]);
586586 return ScalarDouble{ .limbs = limbs };
......@@ -590,9 +590,9 @@ const ScalarDouble = struct {
590590 var limbs: Limbs = undefined;
591591 var i: usize = 0;
592592 while (i < 4) : (i += 1) {
593 limbs[i] = mem.readIntLittle(u64, bytes[i * 7 ..][0..8]) & 0xffffffffffffff;
593 limbs[i] = mem.readInt(u64, bytes[i * 7 ..][0..8], .little) & 0xffffffffffffff;
594594 }
595 limbs[i] = @as(u64, mem.readIntLittle(u32, bytes[i * 7 ..][0..4]));
595 limbs[i] = @as(u64, mem.readInt(u32, bytes[i * 7 ..][0..4], .little));
596596 @memset(limbs[5..], 0);
597597 return ScalarDouble{ .limbs = limbs };
598598 }
lib/std/crypto/Certificate.zig+4-4
......@@ -1075,7 +1075,7 @@ pub const rsa = struct {
10751075 // Reject modulus below 512 bits.
10761076 // 512-bit RSA was factored in 1999, so this limit barely means anything,
10771077 // 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;
10791079 if (_n.bits() < 512) return error.CertificatePublicKeyInvalid;
10801080
10811081 // Exponent must be odd and greater than 2.
......@@ -1085,7 +1085,7 @@ pub const rsa = struct {
10851085 // Windows commonly does.
10861086 // [1] https://learn.microsoft.com/en-us/windows/win32/api/wincrypt/ns-wincrypt-rsapubkey
10871087 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;
10891089 if (!_e.isOdd()) return error.CertificatePublicKeyInvalid;
10901090 const e_v = _e.toPrimitive(u32) catch return error.CertificatePublicKeyInvalid;
10911091 if (e_v < 2) return error.CertificatePublicKeyInvalid;
......@@ -1116,10 +1116,10 @@ pub const rsa = struct {
11161116 };
11171117
11181118 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;
11201120 const e = public_key.n.powPublic(m, public_key.e) catch unreachable;
11211121 var res: [modulus_len]u8 = undefined;
1122 e.toBytes(&res, .Big) catch unreachable;
1122 e.toBytes(&res, .big) catch unreachable;
11231123 return res;
11241124 }
11251125};
lib/std/crypto/Certificate/Bundle/macos.zig+2-2
......@@ -32,7 +32,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
3232
3333 var table_idx: u32 = 0;
3434 while (table_idx < table_list.len) : (table_idx += 1) {
35 table_list[table_idx] = try reader.readIntBig(u32);
35 table_list[table_idx] = try reader.readInt(u32, .big);
3636 }
3737
3838 const now_sec = std.time.timestamp();
......@@ -51,7 +51,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
5151
5252 var record_idx: u32 = 0;
5353 while (record_idx < record_list.len) : (record_idx += 1) {
54 record_list[record_idx] = try reader.readIntBig(u32);
54 record_list[record_idx] = try reader.readInt(u32, .big);
5555 }
5656
5757 for (record_list) |record_offset| {
lib/std/crypto/aegis.zig+4-4
......@@ -106,8 +106,8 @@ const State128L = struct {
106106 fn mac(state: *State128L, comptime tag_bits: u9, adlen: usize, mlen: usize) [tag_bits / 8]u8 {
107107 const blocks = &state.blocks;
108108 var sizes: [16]u8 = undefined;
109 mem.writeIntLittle(u64, sizes[0..8], adlen * 8);
110 mem.writeIntLittle(u64, sizes[8..16], mlen * 8);
109 mem.writeInt(u64, sizes[0..8], adlen * 8, .little);
110 mem.writeInt(u64, sizes[8..16], mlen * 8, .little);
111111 const tmp = AesBlock.fromBytes(&sizes).xorBlocks(blocks[2]);
112112 var i: usize = 0;
113113 while (i < 7) : (i += 1) {
......@@ -284,8 +284,8 @@ const State256 = struct {
284284 fn mac(state: *State256, comptime tag_bits: u9, adlen: usize, mlen: usize) [tag_bits / 8]u8 {
285285 const blocks = &state.blocks;
286286 var sizes: [16]u8 = undefined;
287 mem.writeIntLittle(u64, sizes[0..8], adlen * 8);
288 mem.writeIntLittle(u64, sizes[8..16], mlen * 8);
287 mem.writeInt(u64, sizes[0..8], adlen * 8, .little);
288 mem.writeInt(u64, sizes[8..16], mlen * 8, .little);
289289 const tmp = AesBlock.fromBytes(&sizes).xorBlocks(blocks[3]);
290290 var i: usize = 0;
291291 while (i < 7) : (i += 1) {
lib/std/crypto/aes.zig+1-1
......@@ -50,7 +50,7 @@ test "ctr" {
5050
5151 var out: [exp_out.len]u8 = undefined;
5252 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);
5454 try testing.expectEqualSlices(u8, exp_out[0..], out[0..]);
5555}
5656
lib/std/crypto/aes/soft.zig+18-18
......@@ -15,20 +15,20 @@ pub const Block = struct {
1515
1616 /// Convert a byte sequence into an internal representation.
1717 pub inline fn fromBytes(bytes: *const [16]u8) Block {
18 const s0 = mem.readIntLittle(u32, bytes[0..4]);
19 const s1 = mem.readIntLittle(u32, bytes[4..8]);
20 const s2 = mem.readIntLittle(u32, bytes[8..12]);
21 const s3 = mem.readIntLittle(u32, bytes[12..16]);
18 const s0 = mem.readInt(u32, bytes[0..4], .little);
19 const s1 = mem.readInt(u32, bytes[4..8], .little);
20 const s2 = mem.readInt(u32, bytes[8..12], .little);
21 const s3 = mem.readInt(u32, bytes[12..16], .little);
2222 return Block{ .repr = BlockVec{ s0, s1, s2, s3 } };
2323 }
2424
2525 /// Convert the internal representation of a block into a byte sequence.
2626 pub inline fn toBytes(block: Block) [16]u8 {
2727 var bytes: [16]u8 = undefined;
28 mem.writeIntLittle(u32, bytes[0..4], block.repr[0]);
29 mem.writeIntLittle(u32, bytes[4..8], block.repr[1]);
30 mem.writeIntLittle(u32, bytes[8..12], block.repr[2]);
31 mem.writeIntLittle(u32, bytes[12..16], block.repr[3]);
28 mem.writeInt(u32, bytes[0..4], block.repr[0], .little);
29 mem.writeInt(u32, bytes[4..8], block.repr[1], .little);
30 mem.writeInt(u32, bytes[8..12], block.repr[2], .little);
31 mem.writeInt(u32, bytes[12..16], block.repr[3], .little);
3232 return bytes;
3333 }
3434
......@@ -123,13 +123,13 @@ pub const Block = struct {
123123 // Last round uses s-box directly and XORs to produce output.
124124 var x: [4]u8 = undefined;
125125 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.readIntLittle(u32, &x);
126 var t0 = mem.readInt(u32, &x, .little);
127127 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.readIntLittle(u32, &x);
128 var t1 = mem.readInt(u32, &x, .little);
129129 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.readIntLittle(u32, &x);
130 var t2 = mem.readInt(u32, &x, .little);
131131 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.readIntLittle(u32, &x);
132 var t3 = mem.readInt(u32, &x, .little);
133133
134134 t0 ^= round_key.repr[0];
135135 t1 ^= round_key.repr[1];
......@@ -219,13 +219,13 @@ pub const Block = struct {
219219 // Last round uses s-box directly and XORs to produce output.
220220 var x: [4]u8 = undefined;
221221 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.readIntLittle(u32, &x);
222 var t0 = mem.readInt(u32, &x, .little);
223223 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.readIntLittle(u32, &x);
224 var t1 = mem.readInt(u32, &x, .little);
225225 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.readIntLittle(u32, &x);
226 var t2 = mem.readInt(u32, &x, .little);
227227 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.readIntLittle(u32, &x);
228 var t3 = mem.readInt(u32, &x, .little);
229229
230230 t0 ^= round_key.repr[0];
231231 t1 ^= round_key.repr[1];
......@@ -349,14 +349,14 @@ fn KeySchedule(comptime Aes: type) type {
349349 // Apply sbox_encrypt to each byte in w.
350350 fn func(w: u32) u32 {
351351 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.readIntLittle(u32, &x);
352 return mem.readInt(u32, &x, .little);
353353 }
354354 }.func;
355355
356356 var round_keys: [rounds + 1]Block = undefined;
357357 comptime var i: usize = 0;
358358 inline while (i < words_in_key) : (i += 1) {
359 round_keys[i / 4].repr[i % 4] = mem.readIntBig(u32, key[4 * i ..][0..4]);
359 round_keys[i / 4].repr[i % 4] = mem.readInt(u32, key[4 * i ..][0..4], .big);
360360 }
361361 inline while (i < round_keys.len * 4) : (i += 1) {
362362 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 {
3333 var t: [16]u8 = undefined;
3434 var j: [16]u8 = undefined;
3535 j[0..nonce_length].* = npub;
36 mem.writeIntBig(u32, j[nonce_length..][0..4], 1);
36 mem.writeInt(u32, j[nonce_length..][0..4], 1, .big);
3737 aes.encrypt(&t, &j);
3838
3939 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 {
4141 mac.update(ad);
4242 mac.pad();
4343
44 mem.writeIntBig(u32, j[nonce_length..][0..4], 2);
45 modes.ctr(@TypeOf(aes), aes, c, m, j, std.builtin.Endian.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);
4646 mac.update(c[0..m.len][0..]);
4747 mac.pad();
4848
4949 var final_block = h;
50 mem.writeIntBig(u64, final_block[0..8], ad.len * 8);
51 mem.writeIntBig(u64, final_block[8..16], m.len * 8);
50 mem.writeInt(u64, final_block[0..8], ad.len * 8, .big);
51 mem.writeInt(u64, final_block[8..16], m.len * 8, .big);
5252 mac.update(&final_block);
5353 mac.final(tag);
5454 for (t, 0..) |x, i| {
......@@ -75,7 +75,7 @@ fn AesGcm(comptime Aes: anytype) type {
7575 var t: [16]u8 = undefined;
7676 var j: [16]u8 = undefined;
7777 j[0..nonce_length].* = npub;
78 mem.writeIntBig(u32, j[nonce_length..][0..4], 1);
78 mem.writeInt(u32, j[nonce_length..][0..4], 1, .big);
7979 aes.encrypt(&t, &j);
8080
8181 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 {
8787 mac.pad();
8888
8989 var final_block = h;
90 mem.writeIntBig(u64, final_block[0..8], ad.len * 8);
91 mem.writeIntBig(u64, final_block[8..16], m.len * 8);
90 mem.writeInt(u64, final_block[0..8], ad.len * 8, .big);
91 mem.writeInt(u64, final_block[8..16], m.len * 8, .big);
9292 mac.update(&final_block);
9393 var computed_tag: [Ghash.mac_length]u8 = undefined;
9494 mac.final(&computed_tag);
......@@ -103,8 +103,8 @@ fn AesGcm(comptime Aes: anytype) type {
103103 return error.AuthenticationFailed;
104104 }
105105
106 mem.writeIntBig(u32, j[nonce_length..][0..4], 2);
107 modes.ctr(@TypeOf(aes), aes, m, c, j, std.builtin.Endian.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);
108108 }
109109 };
110110}
lib/std/crypto/aes_ocb.zig+4-4
......@@ -29,10 +29,10 @@ fn AesOcb(comptime Aes: anytype) type {
2929 upto: usize,
3030
3131 inline fn double(l: Block) Block {
32 const l_ = mem.readIntBig(u128, &l);
32 const l_ = mem.readInt(u128, &l, .big);
3333 const l_2 = (l_ << 1) ^ (0x87 & -%(l_ >> 127));
3434 var l2: Block = undefined;
35 mem.writeIntBig(u128, &l2, l_2);
35 mem.writeInt(u128, &l2, l_2, .big);
3636 return l2;
3737 }
3838
......@@ -94,10 +94,10 @@ fn AesOcb(comptime Aes: anytype) type {
9494 nx[15] &= 0xc0;
9595 var ktop_: Block = undefined;
9696 aes_enc_ctx.encrypt(&ktop_, &nx);
97 const ktop = mem.readIntBig(u128, &ktop_);
97 const ktop = mem.readInt(u128, &ktop_, .big);
9898 var stretch = (@as(u192, ktop) << 64) | @as(u192, @as(u64, @truncate(ktop >> 64)) ^ @as(u64, @truncate(ktop >> 56)));
9999 var offset: Block = undefined;
100 mem.writeIntBig(u128, &offset, @as(u128, @truncate(stretch >> (64 - @as(u7, bottom)))));
100 mem.writeInt(u128, &offset, @as(u128, @truncate(stretch >> (64 - @as(u7, bottom)))), .big);
101101 return offset;
102102 }
103103
lib/std/crypto/argon2.zig+17-17
......@@ -110,27 +110,27 @@ fn initHash(
110110 var parameters: [24]u8 = undefined;
111111 var tmp: [4]u8 = undefined;
112112 var b2 = Blake2b512.init(.{});
113 mem.writeIntLittle(u32, parameters[0..4], params.p);
114 mem.writeIntLittle(u32, parameters[4..8], @as(u32, @intCast(dk_len)));
115 mem.writeIntLittle(u32, parameters[8..12], params.m);
116 mem.writeIntLittle(u32, parameters[12..16], params.t);
117 mem.writeIntLittle(u32, parameters[16..20], version);
118 mem.writeIntLittle(u32, parameters[20..24], @intFromEnum(mode));
113 mem.writeInt(u32, parameters[0..4], params.p, .little);
114 mem.writeInt(u32, parameters[4..8], @as(u32, @intCast(dk_len)), .little);
115 mem.writeInt(u32, parameters[8..12], params.m, .little);
116 mem.writeInt(u32, parameters[12..16], params.t, .little);
117 mem.writeInt(u32, parameters[16..20], version, .little);
118 mem.writeInt(u32, parameters[20..24], @intFromEnum(mode), .little);
119119 b2.update(&parameters);
120 mem.writeIntLittle(u32, &tmp, @as(u32, @intCast(password.len)));
120 mem.writeInt(u32, &tmp, @as(u32, @intCast(password.len)), .little);
121121 b2.update(&tmp);
122122 b2.update(password);
123 mem.writeIntLittle(u32, &tmp, @as(u32, @intCast(salt.len)));
123 mem.writeInt(u32, &tmp, @as(u32, @intCast(salt.len)), .little);
124124 b2.update(&tmp);
125125 b2.update(salt);
126126 const secret = params.secret orelse "";
127127 std.debug.assert(secret.len <= max_int);
128 mem.writeIntLittle(u32, &tmp, @as(u32, @intCast(secret.len)));
128 mem.writeInt(u32, &tmp, @as(u32, @intCast(secret.len)), .little);
129129 b2.update(&tmp);
130130 b2.update(secret);
131131 const ad = params.ad orelse "";
132132 std.debug.assert(ad.len <= max_int);
133 mem.writeIntLittle(u32, &tmp, @as(u32, @intCast(ad.len)));
133 mem.writeInt(u32, &tmp, @as(u32, @intCast(ad.len)), .little);
134134 b2.update(&tmp);
135135 b2.update(ad);
136136 b2.final(h0[0..Blake2b512.digest_length]);
......@@ -140,7 +140,7 @@ fn initHash(
140140fn blake2bLong(out: []u8, in: []const u8) void {
141141 const H = Blake2b512;
142142 var outlen_bytes: [4]u8 = undefined;
143 mem.writeIntLittle(u32, &outlen_bytes, @as(u32, @intCast(out.len)));
143 mem.writeInt(u32, &outlen_bytes, @as(u32, @intCast(out.len)), .little);
144144
145145 var out_buf: [H.digest_length]u8 = undefined;
146146
......@@ -183,18 +183,18 @@ fn initBlocks(
183183 var lane: u24 = 0;
184184 while (lane < threads) : (lane += 1) {
185185 const j = lane * (memory / threads);
186 mem.writeIntLittle(u32, h0[Blake2b512.digest_length + 4 ..][0..4], lane);
186 mem.writeInt(u32, h0[Blake2b512.digest_length + 4 ..][0..4], lane, .little);
187187
188 mem.writeIntLittle(u32, h0[Blake2b512.digest_length..][0..4], 0);
188 mem.writeInt(u32, h0[Blake2b512.digest_length..][0..4], 0, .little);
189189 blake2bLong(&block0, h0);
190190 for (&blocks.items[j + 0], 0..) |*v, i| {
191 v.* = mem.readIntLittle(u64, block0[i * 8 ..][0..8]);
191 v.* = mem.readInt(u64, block0[i * 8 ..][0..8], .little);
192192 }
193193
194 mem.writeIntLittle(u32, h0[Blake2b512.digest_length..][0..4], 1);
194 mem.writeInt(u32, h0[Blake2b512.digest_length..][0..4], 1, .little);
195195 blake2bLong(&block0, h0);
196196 for (&blocks.items[j + 1], 0..) |*v, i| {
197 v.* = mem.readIntLittle(u64, block0[i * 8 ..][0..8]);
197 v.* = mem.readInt(u64, block0[i * 8 ..][0..8], .little);
198198 }
199199 }
200200}
......@@ -433,7 +433,7 @@ fn finalize(
433433 }
434434 var block: [1024]u8 = undefined;
435435 for (blocks.items[memory - 1], 0..) |v, i| {
436 mem.writeIntLittle(u64, block[i * 8 ..][0..8], v);
436 mem.writeInt(u64, block[i * 8 ..][0..8], v, .little);
437437 }
438438 blake2bLong(out, &block);
439439}
lib/std/crypto/ascon.zig+10-9
......@@ -8,11 +8,12 @@
88//! It is not meant to be used directly, but as a building block for symmetric cryptography.
99
1010const std = @import("std");
11const builtin = std.builtin;
11const builtin = @import("builtin");
1212const debug = std.debug;
1313const mem = std.mem;
1414const testing = std.testing;
1515const rotr = std.math.rotr;
16const native_endian = builtin.cpu.arch.endian();
1617
1718/// An Ascon state.
1819///
......@@ -20,7 +21,7 @@ const rotr = std.math.rotr;
2021///
2122/// The NIST submission (v1.2) serializes these words as big-endian,
2223/// but software implementations are free to use native endianness.
23pub fn State(comptime endian: builtin.Endian) type {
24pub fn State(comptime endian: std.builtin.Endian) type {
2425 return struct {
2526 const Self = @This();
2627
......@@ -95,8 +96,8 @@ pub fn State(comptime endian: builtin.Endian) type {
9596 /// XOR a byte into the state at a given offset.
9697 pub fn addByte(self: *Self, byte: u8, offset: usize) void {
9798 const z = switch (endian) {
98 .Big => 64 - 8 - 8 * @as(u6, @truncate(offset % 8)),
99 .Little => 8 * @as(u6, @truncate(offset % 8)),
99 .big => 64 - 8 - 8 * @as(u6, @truncate(offset % 8)),
100 .little => 8 * @as(u6, @truncate(offset % 8)),
100101 };
101102 self.st[offset / 8] ^= @as(u64, byte) << z;
102103 }
......@@ -133,14 +134,14 @@ pub fn State(comptime endian: builtin.Endian) type {
133134
134135 var i: usize = 0;
135136 while (i + 8 <= in.len) : (i += 8) {
136 const x = mem.readIntNative(u64, in[i..][0..8]) ^ mem.nativeTo(u64, self.st[i / 8], endian);
137 mem.writeIntNative(u64, out[i..][0..8], x);
137 const x = mem.readInt(u64, in[i..][0..8], native_endian) ^ mem.nativeTo(u64, self.st[i / 8], endian);
138 mem.writeInt(u64, out[i..][0..8], x, native_endian);
138139 }
139140 if (i < in.len) {
140141 var padded = [_]u8{0} ** 8;
141142 @memcpy(padded[0 .. in.len - i], in[i..]);
142 const x = mem.readIntNative(u64, &padded) ^ mem.nativeTo(u64, self.st[i / 8], endian);
143 mem.writeIntNative(u64, &padded, x);
143 const x = mem.readInt(u64, &padded, native_endian) ^ mem.nativeTo(u64, self.st[i / 8], endian);
144 mem.writeInt(u64, &padded, x, native_endian);
144145 @memcpy(out[i..], padded[0 .. in.len - i]);
145146 }
146147 }
......@@ -214,7 +215,7 @@ pub fn State(comptime endian: builtin.Endian) type {
214215}
215216
216217test "ascon" {
217 const Ascon = State(.Big);
218 const Ascon = State(.big);
218219 const bytes = [_]u8{0x01} ** Ascon.block_bytes;
219220 var st = Ascon.init(bytes);
220221 var out: [Ascon.block_bytes]u8 = undefined;
lib/std/crypto/bcrypt.zig+2-2
......@@ -451,7 +451,7 @@ pub fn bcrypt(
451451
452452 var ct: [ct_length]u8 = undefined;
453453 for (cdata, 0..) |c, i| {
454 mem.writeIntBig(u32, ct[i * 4 ..][0..4], c);
454 mem.writeInt(u32, ct[i * 4 ..][0..4], c, .big);
455455 }
456456 return ct[0..dk_length].*;
457457}
......@@ -547,7 +547,7 @@ const pbkdf_prf = struct {
547547 // copy out
548548 var out: [32]u8 = undefined;
549549 for (cdata, 0..) |v, i| {
550 std.mem.writeIntLittle(u32, out[4 * i ..][0..4], v);
550 std.mem.writeInt(u32, out[4 * i ..][0..4], v, .little);
551551 }
552552
553553 // zap
lib/std/crypto/blake2.zig+10-10
......@@ -85,12 +85,12 @@ pub fn Blake2s(comptime out_bits: usize) type {
8585 d.buf_len = 0;
8686
8787 if (options.salt) |salt| {
88 d.h[4] ^= mem.readIntLittle(u32, salt[0..4]);
89 d.h[5] ^= mem.readIntLittle(u32, salt[4..8]);
88 d.h[4] ^= mem.readInt(u32, salt[0..4], .little);
89 d.h[5] ^= mem.readInt(u32, salt[4..8], .little);
9090 }
9191 if (options.context) |context| {
92 d.h[6] ^= mem.readIntLittle(u32, context[0..4]);
93 d.h[7] ^= mem.readIntLittle(u32, context[4..8]);
92 d.h[6] ^= mem.readInt(u32, context[0..4], .little);
93 d.h[7] ^= mem.readInt(u32, context[4..8], .little);
9494 }
9595 if (key_len > 0) {
9696 @memset(d.buf[key_len..], 0);
......@@ -143,7 +143,7 @@ pub fn Blake2s(comptime out_bits: usize) type {
143143 var v: [16]u32 = undefined;
144144
145145 for (&m, 0..) |*r, i| {
146 r.* = mem.readIntLittle(u32, b[4 * i ..][0..4]);
146 r.* = mem.readInt(u32, b[4 * i ..][0..4], .little);
147147 }
148148
149149 var k: usize = 0;
......@@ -521,12 +521,12 @@ pub fn Blake2b(comptime out_bits: usize) type {
521521 d.buf_len = 0;
522522
523523 if (options.salt) |salt| {
524 d.h[4] ^= mem.readIntLittle(u64, salt[0..8]);
525 d.h[5] ^= mem.readIntLittle(u64, salt[8..16]);
524 d.h[4] ^= mem.readInt(u64, salt[0..8], .little);
525 d.h[5] ^= mem.readInt(u64, salt[8..16], .little);
526526 }
527527 if (options.context) |context| {
528 d.h[6] ^= mem.readIntLittle(u64, context[0..8]);
529 d.h[7] ^= mem.readIntLittle(u64, context[8..16]);
528 d.h[6] ^= mem.readInt(u64, context[0..8], .little);
529 d.h[7] ^= mem.readInt(u64, context[8..16], .little);
530530 }
531531 if (key_len > 0) {
532532 @memset(d.buf[key_len..], 0);
......@@ -579,7 +579,7 @@ pub fn Blake2b(comptime out_bits: usize) type {
579579 var v: [16]u64 = undefined;
580580
581581 for (&m, 0..) |*r, i| {
582 r.* = mem.readIntLittle(u64, b[8 * i ..][0..8]);
582 r.* = mem.readInt(u64, b[8 * i ..][0..8], .little);
583583 }
584584
585585 var k: usize = 0;
lib/std/crypto/blake3.zig+2-2
......@@ -212,7 +212,7 @@ fn first8Words(words: [16]u32) [8]u32 {
212212fn wordsFromLittleEndianBytes(comptime count: usize, bytes: [count * 4]u8) [count]u32 {
213213 var words: [count]u32 = undefined;
214214 for (&words, 0..) |*word, i| {
215 word.* = mem.readIntSliceLittle(u32, bytes[4 * i ..]);
215 word.* = mem.readInt(u32, bytes[4 * i ..][0..4], .little);
216216 }
217217 return words;
218218}
......@@ -252,7 +252,7 @@ const Output = struct {
252252 var word_counter: usize = 0;
253253 while (out_word_it.next()) |out_word| {
254254 var word_bytes: [4]u8 = undefined;
255 mem.writeIntLittle(u32, &word_bytes, words[word_counter]);
255 mem.writeInt(u32, &word_bytes, words[word_counter], .little);
256256 @memcpy(out_word, word_bytes[0..out_word.len]);
257257 word_counter += 1;
258258 }
lib/std/crypto/chacha20.zig+73-73
......@@ -87,10 +87,10 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type
8787 switch (degree) {
8888 1 => {
8989 const constant_le = Lane{
90 mem.readIntLittle(u32, c[0..4]),
91 mem.readIntLittle(u32, c[4..8]),
92 mem.readIntLittle(u32, c[8..12]),
93 mem.readIntLittle(u32, c[12..16]),
90 mem.readInt(u32, c[0..4], .little),
91 mem.readInt(u32, c[4..8], .little),
92 mem.readInt(u32, c[8..12], .little),
93 mem.readInt(u32, c[12..16], .little),
9494 };
9595 return BlockVec{
9696 constant_le,
......@@ -101,14 +101,14 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type
101101 },
102102 2 => {
103103 const constant_le = Lane{
104 mem.readIntLittle(u32, c[0..4]),
105 mem.readIntLittle(u32, c[4..8]),
106 mem.readIntLittle(u32, c[8..12]),
107 mem.readIntLittle(u32, c[12..16]),
108 mem.readIntLittle(u32, c[0..4]),
109 mem.readIntLittle(u32, c[4..8]),
110 mem.readIntLittle(u32, c[8..12]),
111 mem.readIntLittle(u32, c[12..16]),
104 mem.readInt(u32, c[0..4], .little),
105 mem.readInt(u32, c[4..8], .little),
106 mem.readInt(u32, c[8..12], .little),
107 mem.readInt(u32, c[12..16], .little),
108 mem.readInt(u32, c[0..4], .little),
109 mem.readInt(u32, c[4..8], .little),
110 mem.readInt(u32, c[8..12], .little),
111 mem.readInt(u32, c[12..16], .little),
112112 };
113113 const n1 = @addWithOverflow(d[0], 1);
114114 return BlockVec{
......@@ -123,22 +123,22 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type
123123 const n2 = @addWithOverflow(d[0], 2);
124124 const n3 = @addWithOverflow(d[0], 3);
125125 const constant_le = Lane{
126 mem.readIntLittle(u32, c[0..4]),
127 mem.readIntLittle(u32, c[4..8]),
128 mem.readIntLittle(u32, c[8..12]),
129 mem.readIntLittle(u32, c[12..16]),
130 mem.readIntLittle(u32, c[0..4]),
131 mem.readIntLittle(u32, c[4..8]),
132 mem.readIntLittle(u32, c[8..12]),
133 mem.readIntLittle(u32, c[12..16]),
134 mem.readIntLittle(u32, c[0..4]),
135 mem.readIntLittle(u32, c[4..8]),
136 mem.readIntLittle(u32, c[8..12]),
137 mem.readIntLittle(u32, c[12..16]),
138 mem.readIntLittle(u32, c[0..4]),
139 mem.readIntLittle(u32, c[4..8]),
140 mem.readIntLittle(u32, c[8..12]),
141 mem.readIntLittle(u32, c[12..16]),
126 mem.readInt(u32, c[0..4], .little),
127 mem.readInt(u32, c[4..8], .little),
128 mem.readInt(u32, c[8..12], .little),
129 mem.readInt(u32, c[12..16], .little),
130 mem.readInt(u32, c[0..4], .little),
131 mem.readInt(u32, c[4..8], .little),
132 mem.readInt(u32, c[8..12], .little),
133 mem.readInt(u32, c[12..16], .little),
134 mem.readInt(u32, c[0..4], .little),
135 mem.readInt(u32, c[4..8], .little),
136 mem.readInt(u32, c[8..12], .little),
137 mem.readInt(u32, c[12..16], .little),
138 mem.readInt(u32, c[0..4], .little),
139 mem.readInt(u32, c[4..8], .little),
140 mem.readInt(u32, c[8..12], .little),
141 mem.readInt(u32, c[12..16], .little),
142142 };
143143 return BlockVec{
144144 constant_le,
......@@ -218,10 +218,10 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type
218218 inline fn hashToBytes(comptime dm: usize, out: *[64 * dm]u8, x: BlockVec) void {
219219 for (0..dm) |d| {
220220 for (0..4) |i| {
221 mem.writeIntLittle(u32, out[64 * d + 16 * i + 0 ..][0..4], x[i][0 + 4 * d]);
222 mem.writeIntLittle(u32, out[64 * d + 16 * i + 4 ..][0..4], x[i][1 + 4 * d]);
223 mem.writeIntLittle(u32, out[64 * d + 16 * i + 8 ..][0..4], x[i][2 + 4 * d]);
224 mem.writeIntLittle(u32, out[64 * d + 16 * i + 12 ..][0..4], x[i][3 + 4 * d]);
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);
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);
225225 }
226226 }
227227 }
......@@ -309,20 +309,20 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type
309309 fn hchacha20(input: [16]u8, key: [32]u8) [32]u8 {
310310 var c: [4]u32 = undefined;
311311 for (c, 0..) |_, i| {
312 c[i] = mem.readIntLittle(u32, input[4 * i ..][0..4]);
312 c[i] = mem.readInt(u32, input[4 * i ..][0..4], .little);
313313 }
314314 const ctx = initContext(keyToWords(key), c);
315315 var x: BlockVec = undefined;
316316 chacha20Core(x[0..], ctx);
317317 var out: [32]u8 = undefined;
318 mem.writeIntLittle(u32, out[0..4], x[0][0]);
319 mem.writeIntLittle(u32, out[4..8], x[0][1]);
320 mem.writeIntLittle(u32, out[8..12], x[0][2]);
321 mem.writeIntLittle(u32, out[12..16], x[0][3]);
322 mem.writeIntLittle(u32, out[16..20], x[3][0]);
323 mem.writeIntLittle(u32, out[20..24], x[3][1]);
324 mem.writeIntLittle(u32, out[24..28], x[3][2]);
325 mem.writeIntLittle(u32, out[28..32], x[3][3]);
318 mem.writeInt(u32, out[0..4], x[0][0], .little);
319 mem.writeInt(u32, out[4..8], x[0][1], .little);
320 mem.writeInt(u32, out[8..12], x[0][2], .little);
321 mem.writeInt(u32, out[12..16], x[0][3], .little);
322 mem.writeInt(u32, out[16..20], x[3][0], .little);
323 mem.writeInt(u32, out[20..24], x[3][1], .little);
324 mem.writeInt(u32, out[24..28], x[3][2], .little);
325 mem.writeInt(u32, out[28..32], x[3][3], .little);
326326 return out;
327327 }
328328 };
......@@ -336,10 +336,10 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type {
336336 fn initContext(key: [8]u32, d: [4]u32) BlockVec {
337337 const c = "expand 32-byte k";
338338 const constant_le = comptime [4]u32{
339 mem.readIntLittle(u32, c[0..4]),
340 mem.readIntLittle(u32, c[4..8]),
341 mem.readIntLittle(u32, c[8..12]),
342 mem.readIntLittle(u32, c[12..16]),
339 mem.readInt(u32, c[0..4], .little),
340 mem.readInt(u32, c[4..8], .little),
341 mem.readInt(u32, c[8..12], .little),
342 mem.readInt(u32, c[12..16], .little),
343343 };
344344 return BlockVec{
345345 constant_le[0], constant_le[1], constant_le[2], constant_le[3],
......@@ -396,10 +396,10 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type {
396396
397397 inline fn hashToBytes(out: *[64]u8, x: BlockVec) void {
398398 for (0..4) |i| {
399 mem.writeIntLittle(u32, out[16 * i + 0 ..][0..4], x[i * 4 + 0]);
400 mem.writeIntLittle(u32, out[16 * i + 4 ..][0..4], x[i * 4 + 1]);
401 mem.writeIntLittle(u32, out[16 * i + 8 ..][0..4], x[i * 4 + 2]);
402 mem.writeIntLittle(u32, out[16 * i + 12 ..][0..4], x[i * 4 + 3]);
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);
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);
403403 }
404404 }
405405
......@@ -477,20 +477,20 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type {
477477 fn hchacha20(input: [16]u8, key: [32]u8) [32]u8 {
478478 var c: [4]u32 = undefined;
479479 for (c, 0..) |_, i| {
480 c[i] = mem.readIntLittle(u32, input[4 * i ..][0..4]);
480 c[i] = mem.readInt(u32, input[4 * i ..][0..4], .little);
481481 }
482482 const ctx = initContext(keyToWords(key), c);
483483 var x: BlockVec = undefined;
484484 chacha20Core(x[0..], ctx);
485485 var out: [32]u8 = undefined;
486 mem.writeIntLittle(u32, out[0..4], x[0]);
487 mem.writeIntLittle(u32, out[4..8], x[1]);
488 mem.writeIntLittle(u32, out[8..12], x[2]);
489 mem.writeIntLittle(u32, out[12..16], x[3]);
490 mem.writeIntLittle(u32, out[16..20], x[12]);
491 mem.writeIntLittle(u32, out[20..24], x[13]);
492 mem.writeIntLittle(u32, out[24..28], x[14]);
493 mem.writeIntLittle(u32, out[28..32], x[15]);
486 mem.writeInt(u32, out[0..4], x[0], .little);
487 mem.writeInt(u32, out[4..8], x[1], .little);
488 mem.writeInt(u32, out[8..12], x[2], .little);
489 mem.writeInt(u32, out[12..16], x[3], .little);
490 mem.writeInt(u32, out[16..20], x[12], .little);
491 mem.writeInt(u32, out[20..24], x[13], .little);
492 mem.writeInt(u32, out[24..28], x[14], .little);
493 mem.writeInt(u32, out[28..32], x[15], .little);
494494 return out;
495495 }
496496 };
......@@ -519,7 +519,7 @@ fn ChaChaImpl(comptime rounds_nb: usize) type {
519519fn keyToWords(key: [32]u8) [8]u32 {
520520 var k: [8]u32 = undefined;
521521 for (0..8) |i| {
522 k[i] = mem.readIntLittle(u32, key[i * 4 ..][0..4]);
522 k[i] = mem.readInt(u32, key[i * 4 ..][0..4], .little);
523523 }
524524 return k;
525525}
......@@ -552,9 +552,9 @@ fn ChaChaIETF(comptime rounds_nb: usize) type {
552552
553553 var d: [4]u32 = undefined;
554554 d[0] = counter;
555 d[1] = mem.readIntLittle(u32, nonce[0..4]);
556 d[2] = mem.readIntLittle(u32, nonce[4..8]);
557 d[3] = mem.readIntLittle(u32, nonce[8..12]);
555 d[1] = mem.readInt(u32, nonce[0..4], .little);
556 d[2] = mem.readInt(u32, nonce[4..8], .little);
557 d[3] = mem.readInt(u32, nonce[8..12], .little);
558558 ChaChaImpl(rounds_nb).chacha20Xor(out, in, keyToWords(key), d, false);
559559 }
560560
......@@ -564,9 +564,9 @@ fn ChaChaIETF(comptime rounds_nb: usize) type {
564564
565565 var d: [4]u32 = undefined;
566566 d[0] = counter;
567 d[1] = mem.readIntLittle(u32, nonce[0..4]);
568 d[2] = mem.readIntLittle(u32, nonce[4..8]);
569 d[3] = mem.readIntLittle(u32, nonce[8..12]);
567 d[1] = mem.readInt(u32, nonce[0..4], .little);
568 d[2] = mem.readInt(u32, nonce[4..8], .little);
569 d[3] = mem.readInt(u32, nonce[8..12], .little);
570570 ChaChaImpl(rounds_nb).chacha20Stream(out, keyToWords(key), d, false);
571571 }
572572 };
......@@ -592,8 +592,8 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type {
592592 var c: [4]u32 = undefined;
593593 c[0] = @as(u32, @truncate(counter));
594594 c[1] = @as(u32, @truncate(counter >> 32));
595 c[2] = mem.readIntLittle(u32, nonce[0..4]);
596 c[3] = mem.readIntLittle(u32, nonce[4..8]);
595 c[2] = mem.readInt(u32, nonce[0..4], .little);
596 c[3] = mem.readInt(u32, nonce[4..8], .little);
597597 ChaChaImpl(rounds_nb).chacha20Xor(out, in, k, c, true);
598598 }
599599
......@@ -605,8 +605,8 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type {
605605 var c: [4]u32 = undefined;
606606 c[0] = @as(u32, @truncate(counter));
607607 c[1] = @as(u32, @truncate(counter >> 32));
608 c[2] = mem.readIntLittle(u32, nonce[0..4]);
609 c[3] = mem.readIntLittle(u32, nonce[4..8]);
608 c[2] = mem.readInt(u32, nonce[0..4], .little);
609 c[3] = mem.readInt(u32, nonce[4..8], .little);
610610 ChaChaImpl(rounds_nb).chacha20Stream(out, k, c, true);
611611 }
612612 };
......@@ -672,8 +672,8 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type {
672672 mac.update(zeros[0..padding]);
673673 }
674674 var lens: [16]u8 = undefined;
675 mem.writeIntLittle(u64, lens[0..8], ad.len);
676 mem.writeIntLittle(u64, lens[8..16], m.len);
675 mem.writeInt(u64, lens[0..8], ad.len, .little);
676 mem.writeInt(u64, lens[8..16], m.len, .little);
677677 mac.update(lens[0..]);
678678 mac.final(tag);
679679 }
......@@ -708,8 +708,8 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type {
708708 mac.update(zeros[0..padding]);
709709 }
710710 var lens: [16]u8 = undefined;
711 mem.writeIntLittle(u64, lens[0..8], ad.len);
712 mem.writeIntLittle(u64, lens[8..16], c.len);
711 mem.writeInt(u64, lens[0..8], ad.len, .little);
712 mem.writeInt(u64, lens[8..16], c.len, .little);
713713 mac.update(lens[0..]);
714714 var computed_tag: [16]u8 = undefined;
715715 mac.final(computed_tag[0..]);
lib/std/crypto/cmac.zig+2-2
......@@ -76,7 +76,7 @@ pub fn Cmac(comptime BlockCipher: type) type {
7676
7777 fn double(l: Block) Block {
7878 const Int = std.meta.Int(.unsigned, block_length * 8);
79 const l_ = mem.readIntBig(Int, &l);
79 const l_ = mem.readInt(Int, &l, .big);
8080 const l_2 = switch (block_length) {
8181 8 => (l_ << 1) ^ (0x1b & -%(l_ >> 63)), // mod x^64 + x^4 + x^3 + x + 1
8282 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 {
8585 else => @compileError("unsupported block length"),
8686 };
8787 var l2: Block = undefined;
88 mem.writeIntBig(Int, &l2, l_2);
88 mem.writeInt(Int, &l2, l_2, .big);
8989 return l2;
9090 }
9191 };
lib/std/crypto/ecdsa.zig+16-16
......@@ -209,17 +209,17 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
209209
210210 const k = deterministicScalar(h_slice.*, self.secret_key.bytes, self.noise);
211211
212 const p = try Curve.basePoint.mul(k.toBytes(.Big), .Big);
213 const xs = p.affineCoordinates().x.toBytes(.Big);
212 const p = try Curve.basePoint.mul(k.toBytes(.big), .big);
213 const xs = p.affineCoordinates().x.toBytes(.big);
214214 const r = reduceToScalar(Curve.Fe.encoded_length, xs);
215215 if (r.isZero()) return error.IdentityElement;
216216
217217 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)));
219219 const s = k_inv.mul(zrs);
220220 if (s.isZero()) return error.IdentityElement;
221221
222 return Signature{ .r = r.toBytes(.Big), .s = s.toBytes(.Big) };
222 return Signature{ .r = r.toBytes(.big), .s = s.toBytes(.big) };
223223 }
224224 };
225225
......@@ -232,8 +232,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
232232 public_key: PublicKey,
233233
234234 fn init(sig: Signature, public_key: PublicKey) (IdentityElementError || NonCanonicalError)!Verifier {
235 const r = try Curve.scalar.Scalar.fromBytes(sig.r, .Big);
236 const s = try Curve.scalar.Scalar.fromBytes(sig.s, .Big);
235 const r = try Curve.scalar.Scalar.fromBytes(sig.r, .big);
236 const s = try Curve.scalar.Scalar.fromBytes(sig.s, .big);
237237 if (r.isZero() or s.isZero()) return error.IdentityElement;
238238
239239 return Verifier{
......@@ -262,11 +262,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
262262 }
263263
264264 const s_inv = self.s.invert();
265 const v1 = z.mul(s_inv).toBytes(.Little);
266 const v2 = self.r.mul(s_inv).toBytes(.Little);
267 const v1g = try Curve.basePoint.mulPublic(v1, .Little);
268 const v2pk = try self.public_key.p.mulPublic(v2, .Little);
269 const vxs = v1g.add(v2pk).affineCoordinates().x.toBytes(.Big);
265 const v1 = z.mul(s_inv).toBytes(.little);
266 const v2 = self.r.mul(s_inv).toBytes(.little);
267 const v1g = try Curve.basePoint.mulPublic(v1, .little);
268 const v2pk = try self.public_key.p.mulPublic(v2, .little);
269 const vxs = v1g.add(v2pk).affineCoordinates().x.toBytes(.big);
270270 const vr = reduceToScalar(Curve.Fe.encoded_length, vxs);
271271 if (!self.r.equivalent(vr)) {
272272 return error.SignatureVerificationFailed;
......@@ -295,13 +295,13 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
295295 }
296296 const h = [_]u8{0x00} ** Hash.digest_length;
297297 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);
299299 return fromSecretKey(SecretKey{ .bytes = secret_key });
300300 }
301301
302302 /// Return the public key corresponding to the secret key.
303303 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);
305305 return KeyPair{ .secret_key = secret_key, .public_key = PublicKey{ .p = public_key } };
306306 }
307307
......@@ -326,11 +326,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
326326 if (unreduced_len >= 48) {
327327 var xs = [_]u8{0} ** 64;
328328 @memcpy(xs[xs.len - s.len ..], s[0..]);
329 return Curve.scalar.Scalar.fromBytes64(xs, .Big);
329 return Curve.scalar.Scalar.fromBytes64(xs, .big);
330330 }
331331 var xs = [_]u8{0} ** 48;
332332 @memcpy(xs[xs.len - s.len ..], s[0..]);
333 return Curve.scalar.Scalar.fromBytes48(xs, .Big);
333 return Curve.scalar.Scalar.fromBytes48(xs, .big);
334334 }
335335
336336 // 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 {
362362 Hmac.create(m_v, m_v, &k);
363363 @memcpy(t[t_off..t_end], m_v[0 .. t_end - t_off]);
364364 }
365 if (Curve.scalar.Scalar.fromBytes(t, .Big)) |s| return s else |_| {}
365 if (Curve.scalar.Scalar.fromBytes(t, .big)) |s| return s else |_| {}
366366 m_i.* = 0x00;
367367 Hmac.create(&k, m[0 .. m_v.len + 1], &k);
368368 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 {
137137 @memset(bytes, 0);
138138 var shift: usize = 0;
139139 var out_i: usize = switch (endian) {
140 .Big => bytes.len - 1,
141 .Little => 0,
140 .big => bytes.len - 1,
141 .little => 0,
142142 };
143143 for (0..self.limbs.len) |i| {
144144 var remaining_bits = t_bits;
......@@ -150,7 +150,7 @@ pub fn Uint(comptime max_bits: comptime_int) type {
150150 remaining_bits -= consumed;
151151 shift = 0;
152152 switch (endian) {
153 .Big => {
153 .big => {
154154 if (out_i == 0) {
155155 if (i != self.limbs.len - 1 or limb != 0) {
156156 return error.Overflow;
......@@ -159,7 +159,7 @@ pub fn Uint(comptime max_bits: comptime_int) type {
159159 }
160160 out_i -= 1;
161161 },
162 .Little => {
162 .little => {
163163 out_i += 1;
164164 if (out_i == bytes.len) {
165165 if (i != self.limbs.len - 1 or limb != 0) {
......@@ -182,8 +182,8 @@ pub fn Uint(comptime max_bits: comptime_int) type {
182182 var out = Self.zero;
183183 var out_i: usize = 0;
184184 var i: usize = switch (endian) {
185 .Big => bytes.len - 1,
186 .Little => 0,
185 .big => bytes.len - 1,
186 .little => 0,
187187 };
188188 while (true) {
189189 const bi = bytes[i];
......@@ -203,11 +203,11 @@ pub fn Uint(comptime max_bits: comptime_int) type {
203203 out.limbs.set(out_i, overflow);
204204 }
205205 switch (endian) {
206 .Big => {
206 .big => {
207207 if (i == 0) break;
208208 i -= 1;
209209 },
210 .Little => {
210 .little => {
211211 i += 1;
212212 if (i == bytes.len) break;
213213 },
......@@ -227,7 +227,7 @@ pub fn Uint(comptime max_bits: comptime_int) type {
227227 Limb,
228228 x.limbs.constSlice(),
229229 y.limbs.constSlice(),
230 .Little,
230 .little,
231231 );
232232 }
233233
......@@ -667,15 +667,15 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
667667 var out = self.one();
668668 self.toMontgomery(&out) catch unreachable;
669669
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)) {
671671 // Do not use a precomputation table for short, public exponents
672672 var x_m = x;
673673 if (x.montgomery == false) {
674674 self.toMontgomery(&x_m) catch unreachable;
675675 }
676676 var s = switch (endian) {
677 .Big => 0,
678 .Little => e.len - 1,
677 .big => 0,
678 .little => e.len - 1,
679679 };
680680 while (true) {
681681 const b = e[s];
......@@ -690,11 +690,11 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
690690 if (j == 0) break;
691691 }
692692 switch (endian) {
693 .Big => {
693 .big => {
694694 s += 1;
695695 if (s == e.len) break;
696696 },
697 .Little => {
697 .little => {
698698 if (s == 0) break;
699699 s -= 1;
700700 },
......@@ -711,8 +711,8 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
711711 }
712712 var t0 = self.zero;
713713 var s = switch (endian) {
714 .Big => 0,
715 .Little => e.len - 1,
714 .big => 0,
715 .little => e.len - 1,
716716 };
717717 while (true) {
718718 const b = e[s];
......@@ -737,11 +737,11 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
737737 }
738738 }
739739 switch (endian) {
740 .Big => {
740 .big => {
741741 s += 1;
742742 if (s == e.len) break;
743743 },
744 .Little => {
744 .little => {
745745 if (s == 0) break;
746746 s -= 1;
747747 },
......@@ -791,10 +791,10 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
791791 var e_normalized = Fe{ .v = e.v.normalize() };
792792 var buf_: [Fe.encoded_bytes]u8 = undefined;
793793 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;
795795 const leading = @clz(e_normalized.v.limbs.get(e_normalized.v.limbs_count() - carry_bits));
796796 buf = buf[0 .. buf.len - leading / 8];
797 return self.powWithEncodedPublicExponent(x, buf, .Little);
797 return self.powWithEncodedPublicExponent(x, buf, .little);
798798 }
799799
800800 /// 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;
1313/// It is not a general purpose hash function - The key must be secret, unpredictable and never reused.
1414///
1515/// GHASH is typically used to compute the authentication tag in the AES-GCM construction.
16pub const Ghash = Hash(.Big, true);
16pub const Ghash = Hash(.big, true);
1717
1818/// POLYVAL is a universal hash function that uses multiplication by a fixed
1919/// parameter within a Galois field.
......@@ -21,7 +21,7 @@ pub const Ghash = Hash(.Big, true);
2121/// It is not a general purpose hash function - The key must be secret, unpredictable and never reused.
2222///
2323/// POLYVAL is typically used to compute the authentication tag in the AES-GCM-SIV construction.
24pub const Polyval = Hash(.Little, false);
24pub const Polyval = Hash(.little, false);
2525
2626fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {
2727 return struct {
lib/std/crypto/isap.zig+12-12
......@@ -4,7 +4,7 @@ const debug = std.debug;
44const mem = std.mem;
55const math = std.math;
66const testing = std.testing;
7const Ascon = crypto.core.Ascon(.Big);
7const Ascon = crypto.core.Ascon(.big);
88const AuthenticationError = crypto.errors.AuthenticationError;
99
1010/// ISAPv2 is an authenticated encryption system hardened against side channels and fault attacks.
......@@ -55,9 +55,9 @@ pub const IsapA128A = struct {
5555 fn trickle(k: [16]u8, iv: [8]u8, y: []const u8, comptime out_len: usize) [out_len]u8 {
5656 var isap = IsapA128A{
5757 .st = Ascon.initFromWords(.{
58 mem.readIntBig(u64, k[0..8]),
59 mem.readIntBig(u64, k[8..16]),
60 mem.readIntBig(u64, iv[0..8]),
58 mem.readInt(u64, k[0..8], .big),
59 mem.readInt(u64, k[8..16], .big),
60 mem.readInt(u64, iv[0..8], .big),
6161 0,
6262 0,
6363 }),
......@@ -85,9 +85,9 @@ pub const IsapA128A = struct {
8585 fn mac(c: []const u8, ad: []const u8, npub: [16]u8, key: [16]u8) [16]u8 {
8686 var isap = IsapA128A{
8787 .st = Ascon.initFromWords(.{
88 mem.readIntBig(u64, npub[0..8]),
89 mem.readIntBig(u64, npub[8..16]),
90 mem.readIntBig(u64, iv1[0..]),
88 mem.readInt(u64, npub[0..8], .big),
89 mem.readInt(u64, npub[8..16], .big),
90 mem.readInt(u64, iv1[0..], .big),
9191 0,
9292 0,
9393 }),
......@@ -116,11 +116,11 @@ pub const IsapA128A = struct {
116116 const nb = trickle(key, iv3, npub[0..], 24);
117117 var isap = IsapA128A{
118118 .st = Ascon.initFromWords(.{
119 mem.readIntBig(u64, nb[0..8]),
120 mem.readIntBig(u64, nb[8..16]),
121 mem.readIntBig(u64, nb[16..24]),
122 mem.readIntBig(u64, npub[0..8]),
123 mem.readIntBig(u64, npub[8..16]),
119 mem.readInt(u64, nb[0..8], .big),
120 mem.readInt(u64, nb[8..16], .big),
121 mem.readInt(u64, nb[16..24], .big),
122 mem.readInt(u64, npub[0..8], .big),
123 mem.readInt(u64, npub[8..16], .big),
124124 }),
125125 };
126126 isap.st.permuteR(6);
lib/std/crypto/keccak_p.zig+13-11
......@@ -1,7 +1,9 @@
11const std = @import("std");
2const builtin = @import("builtin");
23const assert = std.debug.assert;
34const math = std.math;
45const mem = std.mem;
6const native_endian = builtin.cpu.arch.endian();
57
68/// The Keccak-f permutation.
79pub fn KeccakF(comptime f: u11) type {
......@@ -43,7 +45,7 @@ pub fn KeccakF(comptime f: u11) type {
4345 pub fn init(bytes: [block_bytes]u8) Self {
4446 var self: Self = undefined;
4547 inline for (&self.st, 0..) |*r, i| {
46 r.* = mem.readIntLittle(T, bytes[@sizeOf(T) * i ..][0..@sizeOf(T)]);
48 r.* = mem.readInt(T, bytes[@sizeOf(T) * i ..][0..@sizeOf(T)], .little);
4749 }
4850 return self;
4951 }
......@@ -64,12 +66,12 @@ pub fn KeccakF(comptime f: u11) type {
6466 pub fn setBytes(self: *Self, bytes: []const u8) void {
6567 var i: usize = 0;
6668 while (i + @sizeOf(T) <= bytes.len) : (i += @sizeOf(T)) {
67 self.st[i / @sizeOf(T)] = mem.readIntLittle(T, bytes[i..][0..@sizeOf(T)]);
69 self.st[i / @sizeOf(T)] = mem.readInt(T, bytes[i..][0..@sizeOf(T)], .little);
6870 }
6971 if (i < bytes.len) {
7072 var padded = [_]u8{0} ** @sizeOf(T);
7173 @memcpy(padded[0 .. bytes.len - i], bytes[i..]);
72 self.st[i / @sizeOf(T)] = mem.readIntLittle(T, padded[0..]);
74 self.st[i / @sizeOf(T)] = mem.readInt(T, padded[0..], .little);
7375 }
7476 }
7577
......@@ -83,12 +85,12 @@ pub fn KeccakF(comptime f: u11) type {
8385 pub fn addBytes(self: *Self, bytes: []const u8) void {
8486 var i: usize = 0;
8587 while (i + @sizeOf(T) <= bytes.len) : (i += @sizeOf(T)) {
86 self.st[i / @sizeOf(T)] ^= mem.readIntLittle(T, bytes[i..][0..@sizeOf(T)]);
88 self.st[i / @sizeOf(T)] ^= mem.readInt(T, bytes[i..][0..@sizeOf(T)], .little);
8789 }
8890 if (i < bytes.len) {
8991 var padded = [_]u8{0} ** @sizeOf(T);
9092 @memcpy(padded[0 .. bytes.len - i], bytes[i..]);
91 self.st[i / @sizeOf(T)] ^= mem.readIntLittle(T, padded[0..]);
93 self.st[i / @sizeOf(T)] ^= mem.readInt(T, padded[0..], .little);
9294 }
9395 }
9496
......@@ -96,11 +98,11 @@ pub fn KeccakF(comptime f: u11) type {
9698 pub fn extractBytes(self: *Self, out: []u8) void {
9799 var i: usize = 0;
98100 while (i + @sizeOf(T) <= out.len) : (i += @sizeOf(T)) {
99 mem.writeIntLittle(T, out[i..][0..@sizeOf(T)], self.st[i / @sizeOf(T)]);
101 mem.writeInt(T, out[i..][0..@sizeOf(T)], self.st[i / @sizeOf(T)], .little);
100102 }
101103 if (i < out.len) {
102104 var padded = [_]u8{0} ** @sizeOf(T);
103 mem.writeIntLittle(T, padded[0..], self.st[i / @sizeOf(T)]);
105 mem.writeInt(T, padded[0..], self.st[i / @sizeOf(T)], .little);
104106 @memcpy(out[i..], padded[0 .. out.len - i]);
105107 }
106108 }
......@@ -111,14 +113,14 @@ pub fn KeccakF(comptime f: u11) type {
111113
112114 var i: usize = 0;
113115 while (i + @sizeOf(T) <= in.len) : (i += @sizeOf(T)) {
114 const x = mem.readIntNative(T, in[i..][0..@sizeOf(T)]) ^ mem.nativeToLittle(T, self.st[i / @sizeOf(T)]);
115 mem.writeIntNative(T, out[i..][0..@sizeOf(T)], x);
116 const x = mem.readInt(T, in[i..][0..@sizeOf(T)], native_endian) ^ mem.nativeToLittle(T, self.st[i / @sizeOf(T)]);
117 mem.writeInt(T, out[i..][0..@sizeOf(T)], x, native_endian);
116118 }
117119 if (i < in.len) {
118120 var padded = [_]u8{0} ** @sizeOf(T);
119121 @memcpy(padded[0 .. in.len - i], in[i..]);
120 const x = mem.readIntNative(T, &padded) ^ mem.nativeToLittle(T, self.st[i / @sizeOf(T)]);
121 mem.writeIntNative(T, &padded, x);
122 const x = mem.readInt(T, &padded, native_endian) ^ mem.nativeToLittle(T, self.st[i / @sizeOf(T)]);
123 mem.writeInt(T, &padded, x, native_endian);
122124 @memcpy(out[i..], padded[0 .. in.len - i]);
123125 }
124126 }
lib/std/crypto/md5.zig+2-2
......@@ -112,7 +112,7 @@ pub const Md5 = struct {
112112 d.round(d.buf[0..]);
113113
114114 for (d.s, 0..) |s, j| {
115 mem.writeIntLittle(u32, out[4 * j ..][0..4], s);
115 mem.writeInt(u32, out[4 * j ..][0..4], s, .little);
116116 }
117117 }
118118
......@@ -121,7 +121,7 @@ pub const Md5 = struct {
121121
122122 var i: usize = 0;
123123 while (i < 16) : (i += 1) {
124 s[i] = mem.readIntLittle(u32, b[i * 4 ..][0..4]);
124 s[i] = mem.readInt(u32, b[i * 4 ..][0..4], .little);
125125 }
126126
127127 var v: [4]u32 = [_]u32{
lib/std/crypto/pcurves/common.zig+11-11
......@@ -51,13 +51,13 @@ pub fn Field(comptime params: FieldParams) type {
5151
5252 /// Reject non-canonical encodings of an element.
5353 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_);
5555 const field_order_s = comptime fos: {
5656 var fos: [encoded_length]u8 = undefined;
57 mem.writeIntLittle(std.meta.Int(.unsigned, encoded_length * 8), &fos, field_order);
57 mem.writeInt(std.meta.Int(.unsigned, encoded_length * 8), &fos, field_order, .little);
5858 break :fos fos;
5959 };
60 if (crypto.utils.timingSafeCompare(u8, &s, &field_order_s, .Little) != .lt) {
60 if (crypto.utils.timingSafeCompare(u8, &s, &field_order_s, .little) != .lt) {
6161 return error.NonCanonical;
6262 }
6363 }
......@@ -71,8 +71,8 @@ pub fn Field(comptime params: FieldParams) type {
7171
7272 /// Unpack a field element.
7373 pub fn fromBytes(s_: [encoded_length]u8, endian: std.builtin.Endian) NonCanonicalError!Fe {
74 var s = if (endian == .Little) s_ else orderSwap(s_);
75 try rejectNonCanonical(s, .Little);
74 var s = if (endian == .little) s_ else orderSwap(s_);
75 try rejectNonCanonical(s, .little);
7676 var limbs_z: NonMontgomeryDomainFieldElement = undefined;
7777 fiat.fromBytes(&limbs_z, s);
7878 var limbs: MontgomeryDomainFieldElement = undefined;
......@@ -86,7 +86,7 @@ pub fn Field(comptime params: FieldParams) type {
8686 fiat.fromMontgomery(&limbs_z, fe.limbs);
8787 var s: [encoded_length]u8 = undefined;
8888 fiat.toBytes(&s, limbs_z);
89 return if (endian == .Little) s else orderSwap(s);
89 return if (endian == .little) s else orderSwap(s);
9090 }
9191
9292 /// Element as an integer.
......@@ -95,14 +95,14 @@ pub fn Field(comptime params: FieldParams) type {
9595 /// Create a field element from an integer.
9696 pub fn fromInt(comptime x: IntRepr) NonCanonicalError!Fe {
9797 var s: [encoded_length]u8 = undefined;
98 mem.writeIntLittle(IntRepr, &s, x);
99 return fromBytes(s, .Little);
98 mem.writeInt(IntRepr, &s, x, .little);
99 return fromBytes(s, .little);
100100 }
101101
102102 /// Return the field element as an integer.
103103 pub fn toInt(fe: Fe) IntRepr {
104 const s = fe.toBytes(.Little);
105 return mem.readIntLittle(IntRepr, &s);
104 const s = fe.toBytes(.little);
105 return mem.readInt(IntRepr, &s, .little);
106106 }
107107
108108 /// Return true if the field element is zero.
......@@ -119,7 +119,7 @@ pub fn Field(comptime params: FieldParams) type {
119119
120120 /// Return true if the element is odd.
121121 pub fn isOdd(fe: Fe) bool {
122 const s = fe.toBytes(.Little);
122 const s = fe.toBytes(.little);
123123 return @as(u1, @truncate(s[0])) != 0;
124124 }
125125
lib/std/crypto/pcurves/p256.zig+12-12
......@@ -87,15 +87,15 @@ pub const P256 = struct {
8787 },
8888 2, 3 => {
8989 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);
9191 const y_is_odd = (encoding_type == 3);
9292 const y = try recoverY(x, y_is_odd);
9393 return P256{ .x = x, .y = y };
9494 },
9595 4 => {
9696 if (encoded.len != 64) return error.InvalidEncoding;
97 const x = try Fe.fromBytes(encoded[0..32].*, .Big);
98 const y = try Fe.fromBytes(encoded[32..64].*, .Big);
97 const x = try Fe.fromBytes(encoded[0..32].*, .big);
98 const y = try Fe.fromBytes(encoded[32..64].*, .big);
9999 return P256.fromAffineCoordinates(.{ .x = x, .y = y });
100100 },
101101 else => return error.InvalidEncoding,
......@@ -107,7 +107,7 @@ pub const P256 = struct {
107107 var out: [33]u8 = undefined;
108108 const xy = p.affineCoordinates();
109109 out[0] = if (xy.y.isOdd()) 3 else 2;
110 out[1..].* = xy.x.toBytes(.Big);
110 out[1..].* = xy.x.toBytes(.big);
111111 return out;
112112 }
113113
......@@ -116,15 +116,15 @@ pub const P256 = struct {
116116 var out: [65]u8 = undefined;
117117 out[0] = 4;
118118 const xy = p.affineCoordinates();
119 out[1..33].* = xy.x.toBytes(.Big);
120 out[33..65].* = xy.y.toBytes(.Big);
119 out[1..33].* = xy.x.toBytes(.big);
120 out[33..65].* = xy.y.toBytes(.big);
121121 return out;
122122 }
123123
124124 /// Return a random point.
125125 pub fn random() P256 {
126 const n = scalar.random(.Little);
127 return basePoint.mul(n, .Little) catch unreachable;
126 const n = scalar.random(.little);
127 return basePoint.mul(n, .little) catch unreachable;
128128 }
129129
130130 /// Flip the sign of the X coordinate.
......@@ -400,7 +400,7 @@ pub const P256 = struct {
400400 /// Multiply an elliptic curve point by a scalar.
401401 /// Return error.IdentityElement if the result is the identity element.
402402 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_);
404404 if (p.is_base) {
405405 return pcMul16(&basePointPc, s, false);
406406 }
......@@ -412,7 +412,7 @@ pub const P256 = struct {
412412 /// Multiply an elliptic curve point by a *PUBLIC* scalar *IN VARIABLE TIME*
413413 /// This can be used for signature verification.
414414 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_);
416416 if (p.is_base) {
417417 return pcMul16(&basePointPc, s, true);
418418 }
......@@ -424,8 +424,8 @@ pub const P256 = struct {
424424 /// Double-base multiplication of public parameters - Compute (p1*s1)+(p2*s2) *IN VARIABLE TIME*
425425 /// This can be used for signature verification.
426426 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_);
428 const s2 = if (endian == .Little) s2_ else Fe.orderSwap(s2_);
427 const s1 = if (endian == .little) s1_ else Fe.orderSwap(s1_);
428 const s2 = if (endian == .little) s2_ else Fe.orderSwap(s2_);
429429 try p1.rejectIdentity();
430430 var pc1_array: [9]P256 = undefined;
431431 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 {
174174 var s: [48]u8 = undefined;
175175 while (true) {
176176 crypto.random.bytes(&s);
177 const n = Scalar.fromBytes48(s, .Little);
177 const n = Scalar.fromBytes48(s, .little);
178178 if (!n.isZero()) {
179179 return n;
180180 }
......@@ -191,7 +191,7 @@ const ScalarDouble = struct {
191191 debug.assert(bits > 0 and bits <= 512 and bits >= Fe.saturated_bits and bits <= Fe.saturated_bits * 3);
192192
193193 var s = s_;
194 if (endian == .Big) {
194 if (endian == .big) {
195195 for (s_, 0..) |x, i| s[s.len - 1 - i] = x;
196196 }
197197 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };
......@@ -199,19 +199,19 @@ const ScalarDouble = struct {
199199 var b = [_]u8{0} ** encoded_length;
200200 const len = @min(s.len, 24);
201201 b[0..len].* = s[0..len].*;
202 t.x1 = Fe.fromBytes(b, .Little) catch unreachable;
202 t.x1 = Fe.fromBytes(b, .little) catch unreachable;
203203 }
204204 if (s_.len >= 24) {
205205 var b = [_]u8{0} ** encoded_length;
206206 const len = @min(s.len - 24, 24);
207207 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;
209209 }
210210 if (s_.len >= 48) {
211211 var b = [_]u8{0} ** encoded_length;
212212 const len = s.len - 48;
213213 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;
215215 }
216216 return t;
217217 }
lib/std/crypto/pcurves/p384.zig+12-12
......@@ -87,15 +87,15 @@ pub const P384 = struct {
8787 },
8888 2, 3 => {
8989 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);
9191 const y_is_odd = (encoding_type == 3);
9292 const y = try recoverY(x, y_is_odd);
9393 return P384{ .x = x, .y = y };
9494 },
9595 4 => {
9696 if (encoded.len != 96) return error.InvalidEncoding;
97 const x = try Fe.fromBytes(encoded[0..48].*, .Big);
98 const y = try Fe.fromBytes(encoded[48..96].*, .Big);
97 const x = try Fe.fromBytes(encoded[0..48].*, .big);
98 const y = try Fe.fromBytes(encoded[48..96].*, .big);
9999 return P384.fromAffineCoordinates(.{ .x = x, .y = y });
100100 },
101101 else => return error.InvalidEncoding,
......@@ -107,7 +107,7 @@ pub const P384 = struct {
107107 var out: [49]u8 = undefined;
108108 const xy = p.affineCoordinates();
109109 out[0] = if (xy.y.isOdd()) 3 else 2;
110 out[1..].* = xy.x.toBytes(.Big);
110 out[1..].* = xy.x.toBytes(.big);
111111 return out;
112112 }
113113
......@@ -116,15 +116,15 @@ pub const P384 = struct {
116116 var out: [97]u8 = undefined;
117117 out[0] = 4;
118118 const xy = p.affineCoordinates();
119 out[1..49].* = xy.x.toBytes(.Big);
120 out[49..97].* = xy.y.toBytes(.Big);
119 out[1..49].* = xy.x.toBytes(.big);
120 out[49..97].* = xy.y.toBytes(.big);
121121 return out;
122122 }
123123
124124 /// Return a random point.
125125 pub fn random() P384 {
126 const n = scalar.random(.Little);
127 return basePoint.mul(n, .Little) catch unreachable;
126 const n = scalar.random(.little);
127 return basePoint.mul(n, .little) catch unreachable;
128128 }
129129
130130 /// Flip the sign of the X coordinate.
......@@ -400,7 +400,7 @@ pub const P384 = struct {
400400 /// Multiply an elliptic curve point by a scalar.
401401 /// Return error.IdentityElement if the result is the identity element.
402402 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_);
404404 if (p.is_base) {
405405 return pcMul16(&basePointPc, s, false);
406406 }
......@@ -412,7 +412,7 @@ pub const P384 = struct {
412412 /// Multiply an elliptic curve point by a *PUBLIC* scalar *IN VARIABLE TIME*
413413 /// This can be used for signature verification.
414414 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_);
416416 if (p.is_base) {
417417 return pcMul16(&basePointPc, s, true);
418418 }
......@@ -424,8 +424,8 @@ pub const P384 = struct {
424424 /// Double-base multiplication of public parameters - Compute (p1*s1)+(p2*s2) *IN VARIABLE TIME*
425425 /// This can be used for signature verification.
426426 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_);
428 const s2 = if (endian == .Little) s2_ else Fe.orderSwap(s2_);
427 const s1 = if (endian == .little) s1_ else Fe.orderSwap(s1_);
428 const s2 = if (endian == .little) s2_ else Fe.orderSwap(s2_);
429429 try p1.rejectIdentity();
430430 var pc1_array: [9]P384 = undefined;
431431 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 {
163163 var s: [64]u8 = undefined;
164164 while (true) {
165165 crypto.random.bytes(&s);
166 const n = Scalar.fromBytes64(s, .Little);
166 const n = Scalar.fromBytes64(s, .little);
167167 if (!n.isZero()) {
168168 return n;
169169 }
......@@ -179,7 +179,7 @@ const ScalarDouble = struct {
179179 debug.assert(bits > 0 and bits <= 512 and bits >= Fe.saturated_bits and bits <= Fe.saturated_bits * 2);
180180
181181 var s = s_;
182 if (endian == .Big) {
182 if (endian == .big) {
183183 for (s_, 0..) |x, i| s[s.len - 1 - i] = x;
184184 }
185185 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero };
......@@ -187,13 +187,13 @@ const ScalarDouble = struct {
187187 var b = [_]u8{0} ** encoded_length;
188188 const len = @min(s.len, 32);
189189 b[0..len].* = s[0..len].*;
190 t.x1 = Fe.fromBytes(b, .Little) catch unreachable;
190 t.x1 = Fe.fromBytes(b, .little) catch unreachable;
191191 }
192192 if (s_.len >= 32) {
193193 var b = [_]u8{0} ** encoded_length;
194194 const len = @min(s.len - 32, 32);
195195 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;
197197 }
198198 return t;
199199 }
lib/std/crypto/pcurves/secp256k1.zig+26-26
......@@ -41,7 +41,7 @@ pub const Secp256k1 = struct {
4141
4242 const lambda_s = s: {
4343 var buf: [32]u8 = undefined;
44 mem.writeIntLittle(u256, &buf, Endormorphism.lambda);
44 mem.writeInt(u256, &buf, Endormorphism.lambda, .little);
4545 break :s buf;
4646 };
4747
......@@ -54,12 +54,12 @@ pub const Secp256k1 = struct {
5454 pub fn splitScalar(s: [32]u8, endian: std.builtin.Endian) NonCanonicalError!SplitScalar {
5555 const b1_neg_s = comptime s: {
5656 var buf: [32]u8 = undefined;
57 mem.writeIntLittle(u256, &buf, 303414439467246543595250775667605759171);
57 mem.writeInt(u256, &buf, 303414439467246543595250775667605759171, .little);
5858 break :s buf;
5959 };
6060 const b2_neg_s = comptime s: {
6161 var buf: [32]u8 = undefined;
62 mem.writeIntLittle(u256, &buf, scalar.field_order - 64502973549206556628585045361533709077);
62 mem.writeInt(u256, &buf, scalar.field_order - 64502973549206556628585045361533709077, .little);
6363 break :s buf;
6464 };
6565 const k = mem.readInt(u256, &s, endian);
......@@ -72,16 +72,16 @@ pub const Secp256k1 = struct {
7272
7373 var buf: [32]u8 = undefined;
7474
75 mem.writeIntLittle(u256, &buf, c1);
76 const c1x = try scalar.mul(buf, b1_neg_s, .Little);
75 mem.writeInt(u256, &buf, c1, .little);
76 const c1x = try scalar.mul(buf, b1_neg_s, .little);
7777
78 mem.writeIntLittle(u256, &buf, c2);
79 const c2x = try scalar.mul(buf, b2_neg_s, .Little);
78 mem.writeInt(u256, &buf, c2, .little);
79 const c2x = try scalar.mul(buf, b2_neg_s, .little);
8080
81 const r2 = try scalar.add(c1x, c2x, .Little);
81 const r2 = try scalar.add(c1x, c2x, .little);
8282
83 var r1 = try scalar.mul(r2, lambda_s, .Little);
84 r1 = try scalar.sub(s, r1, .Little);
83 var r1 = try scalar.mul(r2, lambda_s, .little);
84 r1 = try scalar.sub(s, r1, .little);
8585
8686 return SplitScalar{ .r1 = r1, .r2 = r2 };
8787 }
......@@ -140,15 +140,15 @@ pub const Secp256k1 = struct {
140140 },
141141 2, 3 => {
142142 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);
144144 const y_is_odd = (encoding_type == 3);
145145 const y = try recoverY(x, y_is_odd);
146146 return Secp256k1{ .x = x, .y = y };
147147 },
148148 4 => {
149149 if (encoded.len != 64) return error.InvalidEncoding;
150 const x = try Fe.fromBytes(encoded[0..32].*, .Big);
151 const y = try Fe.fromBytes(encoded[32..64].*, .Big);
150 const x = try Fe.fromBytes(encoded[0..32].*, .big);
151 const y = try Fe.fromBytes(encoded[32..64].*, .big);
152152 return Secp256k1.fromAffineCoordinates(.{ .x = x, .y = y });
153153 },
154154 else => return error.InvalidEncoding,
......@@ -160,7 +160,7 @@ pub const Secp256k1 = struct {
160160 var out: [33]u8 = undefined;
161161 const xy = p.affineCoordinates();
162162 out[0] = if (xy.y.isOdd()) 3 else 2;
163 out[1..].* = xy.x.toBytes(.Big);
163 out[1..].* = xy.x.toBytes(.big);
164164 return out;
165165 }
166166
......@@ -169,15 +169,15 @@ pub const Secp256k1 = struct {
169169 var out: [65]u8 = undefined;
170170 out[0] = 4;
171171 const xy = p.affineCoordinates();
172 out[1..33].* = xy.x.toBytes(.Big);
173 out[33..65].* = xy.y.toBytes(.Big);
172 out[1..33].* = xy.x.toBytes(.big);
173 out[33..65].* = xy.y.toBytes(.big);
174174 return out;
175175 }
176176
177177 /// Return a random point.
178178 pub fn random() Secp256k1 {
179 const n = scalar.random(.Little);
180 return basePoint.mul(n, .Little) catch unreachable;
179 const n = scalar.random(.little);
180 return basePoint.mul(n, .little) catch unreachable;
181181 }
182182
183183 /// Flip the sign of the X coordinate.
......@@ -428,7 +428,7 @@ pub const Secp256k1 = struct {
428428 /// Multiply an elliptic curve point by a scalar.
429429 /// Return error.IdentityElement if the result is the identity element.
430430 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_);
432432 if (p.is_base) {
433433 return pcMul16(&basePointPc, s, false);
434434 }
......@@ -440,24 +440,24 @@ pub const Secp256k1 = struct {
440440 /// Multiply an elliptic curve point by a *PUBLIC* scalar *IN VARIABLE TIME*
441441 /// This can be used for signature verification.
442442 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_);
444 const zero = comptime scalar.Scalar.zero.toBytes(.Little);
443 const s = if (endian == .little) s_ else Fe.orderSwap(s_);
444 const zero = comptime scalar.Scalar.zero.toBytes(.little);
445445 if (mem.eql(u8, &zero, &s)) {
446446 return error.IdentityElement;
447447 }
448448 const pc = precompute(p, 8);
449449 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);
451451 var px = p;
452452
453453 // If a key is negative, flip the sign to keep it half-sized,
454454 // and flip the sign of the Y point coordinate to compensate.
455455 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;
457457 px = px.neg();
458458 }
459459 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;
461461 lambda_p = lambda_p.neg();
462462 }
463463 return mulDoubleBasePublicEndo(px, split_scalar.r1, lambda_p, split_scalar.r2);
......@@ -502,8 +502,8 @@ pub const Secp256k1 = struct {
502502 /// Double-base multiplication of public parameters - Compute (p1*s1)+(p2*s2) *IN VARIABLE TIME*
503503 /// This can be used for signature verification.
504504 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_);
506 const s2 = if (endian == .Little) s2_ else Fe.orderSwap(s2_);
505 const s1 = if (endian == .little) s1_ else Fe.orderSwap(s1_);
506 const s2 = if (endian == .little) s2_ else Fe.orderSwap(s2_);
507507 try p1.rejectIdentity();
508508 var pc1_array: [9]Secp256k1 = undefined;
509509 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 {
174174 var s: [48]u8 = undefined;
175175 while (true) {
176176 crypto.random.bytes(&s);
177 const n = Scalar.fromBytes48(s, .Little);
177 const n = Scalar.fromBytes48(s, .little);
178178 if (!n.isZero()) {
179179 return n;
180180 }
......@@ -191,7 +191,7 @@ const ScalarDouble = struct {
191191 debug.assert(bits > 0 and bits <= 512 and bits >= Fe.saturated_bits and bits <= Fe.saturated_bits * 3);
192192
193193 var s = s_;
194 if (endian == .Big) {
194 if (endian == .big) {
195195 for (s_, 0..) |x, i| s[s.len - 1 - i] = x;
196196 }
197197 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };
......@@ -199,19 +199,19 @@ const ScalarDouble = struct {
199199 var b = [_]u8{0} ** encoded_length;
200200 const len = @min(s.len, 24);
201201 b[0..len].* = s[0..len].*;
202 t.x1 = Fe.fromBytes(b, .Little) catch unreachable;
202 t.x1 = Fe.fromBytes(b, .little) catch unreachable;
203203 }
204204 if (s_.len >= 24) {
205205 var b = [_]u8{0} ** encoded_length;
206206 const len = @min(s.len - 24, 24);
207207 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;
209209 }
210210 if (s_.len >= 48) {
211211 var b = [_]u8{0} ** encoded_length;
212212 const len = s.len - 48;
213213 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;
215215 }
216216 return t;
217217 }
lib/std/crypto/pcurves/tests/p256.zig+20-20
......@@ -5,12 +5,12 @@ const testing = std.testing;
55const P256 = @import("../p256.zig").P256;
66
77test "p256 ECDH key exchange" {
8 const dha = P256.scalar.random(.Little);
9 const dhb = P256.scalar.random(.Little);
10 const dhA = try P256.basePoint.mul(dha, .Little);
11 const dhB = try P256.basePoint.mul(dhb, .Little);
12 const shareda = try dhA.mul(dhb, .Little);
13 const sharedb = try dhB.mul(dha, .Little);
8 const dha = P256.scalar.random(.little);
9 const dhb = P256.scalar.random(.little);
10 const dhA = try P256.basePoint.mul(dha, .little);
11 const dhB = try P256.basePoint.mul(dhb, .little);
12 const shareda = try dhA.mul(dhb, .little);
13 const sharedb = try dhB.mul(dha, .little);
1414 try testing.expect(shareda.equivalent(sharedb));
1515}
1616
......@@ -21,7 +21,7 @@ test "p256 point from affine coordinates" {
2121 _ = try fmt.hexToBytes(&xs, xh);
2222 var ys: [32]u8 = undefined;
2323 _ = try fmt.hexToBytes(&ys, yh);
24 var p = try P256.fromSerializedAffineCoordinates(xs, ys, .Big);
24 var p = try P256.fromSerializedAffineCoordinates(xs, ys, .big);
2525 try testing.expect(p.equivalent(P256.basePoint));
2626}
2727
......@@ -44,7 +44,7 @@ test "p256 test vectors" {
4444 p = p.add(P256.basePoint);
4545 var xs: [32]u8 = undefined;
4646 _ = try fmt.hexToBytes(&xs, xh);
47 try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
47 try testing.expectEqualSlices(u8, &x.toBytes(.big), &xs);
4848 }
4949}
5050
......@@ -61,7 +61,7 @@ test "p256 test vectors - doubling" {
6161 p = p.dbl();
6262 var xs: [32]u8 = undefined;
6363 _ = try fmt.hexToBytes(&xs, xh);
64 try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
64 try testing.expectEqualSlices(u8, &x.toBytes(.big), &xs);
6565 }
6666}
6767
......@@ -80,20 +80,20 @@ test "p256 uncompressed sec1 encoding/decoding" {
8080}
8181
8282test "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);
8484 const p = P256.random();
85 try testing.expectError(error.IdentityElement, p.mul(n, .Little));
85 try testing.expectError(error.IdentityElement, p.mul(n, .little));
8686}
8787
8888test "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);
9090 const p = P256.random();
91 try testing.expectError(error.IdentityElement, p.mulPublic(n, .Little));
91 try testing.expectError(error.IdentityElement, p.mulPublic(n, .little));
9292}
9393
9494test "p256 field element non-canonical encoding" {
9595 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));
9797}
9898
9999test "p256 neutral element decoding" {
......@@ -107,8 +107,8 @@ test "p256 double base multiplication" {
107107 const p2 = P256.basePoint.dbl();
108108 const s1 = [_]u8{0x01} ** 32;
109109 const s2 = [_]u8{0x02} ** 32;
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));
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));
112112 try testing.expect(pr1.equivalent(pr2));
113113}
114114
......@@ -117,8 +117,8 @@ test "p256 double base multiplication with large scalars" {
117117 const p2 = P256.basePoint.dbl();
118118 const s1 = [_]u8{0xee} ** 32;
119119 const s2 = [_]u8{0xdd} ** 32;
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));
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));
122122 try testing.expect(pr1.equivalent(pr2));
123123}
124124
......@@ -130,9 +130,9 @@ test "p256 scalar inverse" {
130130 const scalar = try P256.scalar.Scalar.fromBytes(.{
131131 0x94, 0xa1, 0xbb, 0xb1, 0x4b, 0x90, 0x6a, 0x61, 0xa2, 0x80, 0xf2, 0x45, 0xf9, 0xe9, 0x3c, 0x7f,
132132 0x3b, 0x4a, 0x62, 0x47, 0x82, 0x4f, 0x5d, 0x33, 0xb9, 0x67, 0x07, 0x87, 0x64, 0x2a, 0x68, 0xde,
133 }, .Big);
133 }, .big);
134134 const inverse = scalar.invert();
135 try std.testing.expectEqualSlices(u8, &out, &inverse.toBytes(.Big));
135 try std.testing.expectEqualSlices(u8, &out, &inverse.toBytes(.big));
136136}
137137
138138test "p256 scalar parity" {
lib/std/crypto/pcurves/tests/p384.zig+20-20
......@@ -5,12 +5,12 @@ const testing = std.testing;
55const P384 = @import("../p384.zig").P384;
66
77test "p384 ECDH key exchange" {
8 const dha = P384.scalar.random(.Little);
9 const dhb = P384.scalar.random(.Little);
10 const dhA = try P384.basePoint.mul(dha, .Little);
11 const dhB = try P384.basePoint.mul(dhb, .Little);
12 const shareda = try dhA.mul(dhb, .Little);
13 const sharedb = try dhB.mul(dha, .Little);
8 const dha = P384.scalar.random(.little);
9 const dhb = P384.scalar.random(.little);
10 const dhA = try P384.basePoint.mul(dha, .little);
11 const dhB = try P384.basePoint.mul(dhb, .little);
12 const shareda = try dhA.mul(dhb, .little);
13 const sharedb = try dhB.mul(dha, .little);
1414 try testing.expect(shareda.equivalent(sharedb));
1515}
1616
......@@ -21,7 +21,7 @@ test "p384 point from affine coordinates" {
2121 _ = try fmt.hexToBytes(&xs, xh);
2222 var ys: [48]u8 = undefined;
2323 _ = try fmt.hexToBytes(&ys, yh);
24 var p = try P384.fromSerializedAffineCoordinates(xs, ys, .Big);
24 var p = try P384.fromSerializedAffineCoordinates(xs, ys, .big);
2525 try testing.expect(p.equivalent(P384.basePoint));
2626}
2727
......@@ -45,7 +45,7 @@ test "p384 test vectors" {
4545 p = p.add(P384.basePoint);
4646 var xs: [48]u8 = undefined;
4747 _ = try fmt.hexToBytes(&xs, xh);
48 try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
48 try testing.expectEqualSlices(u8, &x.toBytes(.big), &xs);
4949 }
5050}
5151
......@@ -62,7 +62,7 @@ test "p384 test vectors - doubling" {
6262 p = p.dbl();
6363 var xs: [48]u8 = undefined;
6464 _ = try fmt.hexToBytes(&xs, xh);
65 try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
65 try testing.expectEqualSlices(u8, &x.toBytes(.big), &xs);
6666 }
6767}
6868
......@@ -83,20 +83,20 @@ test "p384 uncompressed sec1 encoding/decoding" {
8383}
8484
8585test "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);
8787 const p = P384.random();
88 try testing.expectError(error.IdentityElement, p.mul(n, .Little));
88 try testing.expectError(error.IdentityElement, p.mul(n, .little));
8989}
9090
9191test "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);
9393 const p = P384.random();
94 try testing.expectError(error.IdentityElement, p.mulPublic(n, .Little));
94 try testing.expectError(error.IdentityElement, p.mulPublic(n, .little));
9595}
9696
9797test "p384 field element non-canonical encoding" {
9898 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));
100100}
101101
102102test "p384 neutral element decoding" {
......@@ -110,8 +110,8 @@ test "p384 double base multiplication" {
110110 const p2 = P384.basePoint.dbl();
111111 const s1 = [_]u8{0x01} ** 48;
112112 const s2 = [_]u8{0x02} ** 48;
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));
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));
115115 try testing.expect(pr1.equivalent(pr2));
116116}
117117
......@@ -120,8 +120,8 @@ test "p384 double base multiplication with large scalars" {
120120 const p2 = P384.basePoint.dbl();
121121 const s1 = [_]u8{0xee} ** 48;
122122 const s2 = [_]u8{0xdd} ** 48;
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));
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));
125125 try testing.expect(pr1.equivalent(pr2));
126126}
127127
......@@ -134,10 +134,10 @@ test "p384 scalar inverse" {
134134 0x94, 0xa1, 0xbb, 0xb1, 0x4b, 0x90, 0x6a, 0x61, 0xa2, 0x80, 0xf2, 0x45, 0xf9, 0xe9, 0x3c, 0x7f,
135135 0x3b, 0x4a, 0x62, 0x47, 0x82, 0x4f, 0x5d, 0x33, 0xb9, 0x67, 0x07, 0x87, 0x64, 0x2a, 0x68, 0xde,
136136 0x38, 0x36, 0xe8, 0x0f, 0xa2, 0x84, 0x6b, 0x4e, 0xf3, 0x9a, 0x02, 0x31, 0x24, 0x41, 0x22, 0xca,
137 }, .Big);
137 }, .big);
138138 const inverse = scalar.invert();
139139 const inverse2 = inverse.invert();
140 try testing.expectEqualSlices(u8, &out, &inverse.toBytes(.Big));
140 try testing.expectEqualSlices(u8, &out, &inverse.toBytes(.big));
141141 try testing.expect(inverse2.equivalent(scalar));
142142
143143 const sq = scalar.sq();
lib/std/crypto/pcurves/tests/secp256k1.zig+24-24
......@@ -5,22 +5,22 @@ const testing = std.testing;
55const Secp256k1 = @import("../secp256k1.zig").Secp256k1;
66
77test "secp256k1 ECDH key exchange" {
8 const dha = Secp256k1.scalar.random(.Little);
9 const dhb = Secp256k1.scalar.random(.Little);
10 const dhA = try Secp256k1.basePoint.mul(dha, .Little);
11 const dhB = try Secp256k1.basePoint.mul(dhb, .Little);
12 const shareda = try dhA.mul(dhb, .Little);
13 const sharedb = try dhB.mul(dha, .Little);
8 const dha = Secp256k1.scalar.random(.little);
9 const dhb = Secp256k1.scalar.random(.little);
10 const dhA = try Secp256k1.basePoint.mul(dha, .little);
11 const dhB = try Secp256k1.basePoint.mul(dhb, .little);
12 const shareda = try dhA.mul(dhb, .little);
13 const sharedb = try dhB.mul(dha, .little);
1414 try testing.expect(shareda.equivalent(sharedb));
1515}
1616
1717test "secp256k1 ECDH key exchange including public multiplication" {
18 const dha = Secp256k1.scalar.random(.Little);
19 const dhb = Secp256k1.scalar.random(.Little);
20 const dhA = try Secp256k1.basePoint.mul(dha, .Little);
21 const dhB = try Secp256k1.basePoint.mulPublic(dhb, .Little);
22 const shareda = try dhA.mul(dhb, .Little);
23 const sharedb = try dhB.mulPublic(dha, .Little);
18 const dha = Secp256k1.scalar.random(.little);
19 const dhb = Secp256k1.scalar.random(.little);
20 const dhA = try Secp256k1.basePoint.mul(dha, .little);
21 const dhB = try Secp256k1.basePoint.mulPublic(dhb, .little);
22 const shareda = try dhA.mul(dhb, .little);
23 const sharedb = try dhB.mulPublic(dha, .little);
2424 try testing.expect(shareda.equivalent(sharedb));
2525}
2626
......@@ -31,7 +31,7 @@ test "secp256k1 point from affine coordinates" {
3131 _ = try fmt.hexToBytes(&xs, xh);
3232 var ys: [32]u8 = undefined;
3333 _ = try fmt.hexToBytes(&ys, yh);
34 var p = try Secp256k1.fromSerializedAffineCoordinates(xs, ys, .Big);
34 var p = try Secp256k1.fromSerializedAffineCoordinates(xs, ys, .big);
3535 try testing.expect(p.equivalent(Secp256k1.basePoint));
3636}
3737
......@@ -54,7 +54,7 @@ test "secp256k1 test vectors" {
5454 p = p.add(Secp256k1.basePoint);
5555 var xs: [32]u8 = undefined;
5656 _ = try fmt.hexToBytes(&xs, xh);
57 try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
57 try testing.expectEqualSlices(u8, &x.toBytes(.big), &xs);
5858 }
5959}
6060
......@@ -72,7 +72,7 @@ test "secp256k1 test vectors - doubling" {
7272 p = p.dbl();
7373 var xs: [32]u8 = undefined;
7474 _ = try fmt.hexToBytes(&xs, xh);
75 try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs);
75 try testing.expectEqualSlices(u8, &x.toBytes(.big), &xs);
7676 }
7777}
7878
......@@ -91,20 +91,20 @@ test "secp256k1 uncompressed sec1 encoding/decoding" {
9191}
9292
9393test "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);
9595 const p = Secp256k1.random();
96 try testing.expectError(error.IdentityElement, p.mul(n, .Little));
96 try testing.expectError(error.IdentityElement, p.mul(n, .little));
9797}
9898
9999test "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);
101101 const p = Secp256k1.random();
102 try testing.expectError(error.IdentityElement, p.mulPublic(n, .Little));
102 try testing.expectError(error.IdentityElement, p.mulPublic(n, .little));
103103}
104104
105105test "secp256k1 field element non-canonical encoding" {
106106 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));
108108}
109109
110110test "secp256k1 neutral element decoding" {
......@@ -118,8 +118,8 @@ test "secp256k1 double base multiplication" {
118118 const p2 = Secp256k1.basePoint.dbl();
119119 const s1 = [_]u8{0x01} ** 32;
120120 const s2 = [_]u8{0x02} ** 32;
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));
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));
123123 try testing.expect(pr1.equivalent(pr2));
124124}
125125
......@@ -131,9 +131,9 @@ test "secp256k1 scalar inverse" {
131131 const scalar = try Secp256k1.scalar.Scalar.fromBytes(.{
132132 0x94, 0xa1, 0xbb, 0xb1, 0x4b, 0x90, 0x6a, 0x61, 0xa2, 0x80, 0xf2, 0x45, 0xf9, 0xe9, 0x3c, 0x7f,
133133 0x3b, 0x4a, 0x62, 0x47, 0x82, 0x4f, 0x5d, 0x33, 0xb9, 0x67, 0x07, 0x87, 0x64, 0x2a, 0x68, 0xde,
134 }, .Big);
134 }, .big);
135135 const inverse = scalar.invert();
136 try std.testing.expectEqualSlices(u8, &out, &inverse.toBytes(.Big));
136 try std.testing.expectEqualSlices(u8, &out, &inverse.toBytes(.big));
137137}
138138
139139test "secp256k1 scalar parity" {
lib/std/crypto/poly1305.zig+8-8
......@@ -22,12 +22,12 @@ pub const Poly1305 = struct {
2222 pub fn init(key: *const [key_length]u8) Poly1305 {
2323 return Poly1305{
2424 .r = [_]u64{
25 mem.readIntLittle(u64, key[0..8]) & 0x0ffffffc0fffffff,
26 mem.readIntLittle(u64, key[8..16]) & 0x0ffffffc0ffffffc,
25 mem.readInt(u64, key[0..8], .little) & 0x0ffffffc0fffffff,
26 mem.readInt(u64, key[8..16], .little) & 0x0ffffffc0ffffffc,
2727 },
2828 .pad = [_]u64{
29 mem.readIntLittle(u64, key[16..24]),
30 mem.readIntLittle(u64, key[24..32]),
29 mem.readInt(u64, key[16..24], .little),
30 mem.readInt(u64, key[24..32], .little),
3131 },
3232 };
3333 }
......@@ -56,8 +56,8 @@ pub const Poly1305 = struct {
5656 var i: usize = 0;
5757
5858 while (i + block_length <= m.len) : (i += block_length) {
59 const in0 = mem.readIntLittle(u64, m[i..][0..8]);
60 const in1 = mem.readIntLittle(u64, m[i + 8 ..][0..8]);
59 const in0 = mem.readInt(u64, m[i..][0..8], .little);
60 const in1 = mem.readInt(u64, m[i + 8 ..][0..8], .little);
6161
6262 // Add the input message to H
6363 var v = @addWithOverflow(h0, in0);
......@@ -182,8 +182,8 @@ pub const Poly1305 = struct {
182182 const c = ((h0 & st.pad[0]) | ((h0 | st.pad[0]) & ~st.h[0])) >> 63;
183183 st.h[1] = h1 +% st.pad[1] +% c;
184184
185 mem.writeIntLittle(u64, out[0..8], st.h[0]);
186 mem.writeIntLittle(u64, out[8..16], st.h[1]);
185 mem.writeInt(u64, out[0..8], st.h[0], .little);
186 mem.writeInt(u64, out[8..16], st.h[1], .little);
187187
188188 utils.secureZero(u8, @as([*]u8, @ptrCast(st))[0..@sizeOf(Poly1305)]);
189189 }
lib/std/crypto/salsa20.zig+34-34
......@@ -29,10 +29,10 @@ fn SalsaVecImpl(comptime rounds: comptime_int) type {
2929 fn initContext(key: [8]u32, d: [4]u32) BlockVec {
3030 const c = "expand 32-byte k";
3131 const constant_le = comptime [4]u32{
32 mem.readIntLittle(u32, c[0..4]),
33 mem.readIntLittle(u32, c[4..8]),
34 mem.readIntLittle(u32, c[8..12]),
35 mem.readIntLittle(u32, c[12..16]),
32 mem.readInt(u32, c[0..4], .little),
33 mem.readInt(u32, c[4..8], .little),
34 mem.readInt(u32, c[8..12], .little),
35 mem.readInt(u32, c[12..16], .little),
3636 };
3737 return BlockVec{
3838 Lane{ key[0], key[1], key[2], key[3] },
......@@ -112,10 +112,10 @@ fn SalsaVecImpl(comptime rounds: comptime_int) type {
112112 fn hashToBytes(out: *[64]u8, x: BlockVec) void {
113113 var i: usize = 0;
114114 while (i < 4) : (i += 1) {
115 mem.writeIntLittle(u32, out[16 * i + 0 ..][0..4], x[i][0]);
116 mem.writeIntLittle(u32, out[16 * i + 4 ..][0..4], x[i][1]);
117 mem.writeIntLittle(u32, out[16 * i + 8 ..][0..4], x[i][2]);
118 mem.writeIntLittle(u32, out[16 * i + 12 ..][0..4], x[i][3]);
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);
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);
119119 }
120120 }
121121
......@@ -158,20 +158,20 @@ fn SalsaVecImpl(comptime rounds: comptime_int) type {
158158 fn hsalsa(input: [16]u8, key: [32]u8) [32]u8 {
159159 var c: [4]u32 = undefined;
160160 for (c, 0..) |_, i| {
161 c[i] = mem.readIntLittle(u32, input[4 * i ..][0..4]);
161 c[i] = mem.readInt(u32, input[4 * i ..][0..4], .little);
162162 }
163163 const ctx = initContext(keyToWords(key), c);
164164 var x: BlockVec = undefined;
165165 salsaCore(x[0..], ctx, false);
166166 var out: [32]u8 = undefined;
167 mem.writeIntLittle(u32, out[0..4], x[0][0]);
168 mem.writeIntLittle(u32, out[4..8], x[1][1]);
169 mem.writeIntLittle(u32, out[8..12], x[2][2]);
170 mem.writeIntLittle(u32, out[12..16], x[3][3]);
171 mem.writeIntLittle(u32, out[16..20], x[1][2]);
172 mem.writeIntLittle(u32, out[20..24], x[1][3]);
173 mem.writeIntLittle(u32, out[24..28], x[2][0]);
174 mem.writeIntLittle(u32, out[28..32], x[2][1]);
167 mem.writeInt(u32, out[0..4], x[0][0], .little);
168 mem.writeInt(u32, out[4..8], x[1][1], .little);
169 mem.writeInt(u32, out[8..12], x[2][2], .little);
170 mem.writeInt(u32, out[12..16], x[3][3], .little);
171 mem.writeInt(u32, out[16..20], x[1][2], .little);
172 mem.writeInt(u32, out[20..24], x[1][3], .little);
173 mem.writeInt(u32, out[24..28], x[2][0], .little);
174 mem.writeInt(u32, out[28..32], x[2][1], .little);
175175 return out;
176176 }
177177 };
......@@ -184,10 +184,10 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type {
184184 fn initContext(key: [8]u32, d: [4]u32) BlockVec {
185185 const c = "expand 32-byte k";
186186 const constant_le = comptime [4]u32{
187 mem.readIntLittle(u32, c[0..4]),
188 mem.readIntLittle(u32, c[4..8]),
189 mem.readIntLittle(u32, c[8..12]),
190 mem.readIntLittle(u32, c[12..16]),
187 mem.readInt(u32, c[0..4], .little),
188 mem.readInt(u32, c[4..8], .little),
189 mem.readInt(u32, c[8..12], .little),
190 mem.readInt(u32, c[12..16], .little),
191191 };
192192 return BlockVec{
193193 constant_le[0], key[0], key[1], key[2],
......@@ -241,7 +241,7 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type {
241241
242242 fn hashToBytes(out: *[64]u8, x: BlockVec) void {
243243 for (x, 0..) |w, i| {
244 mem.writeIntLittle(u32, out[i * 4 ..][0..4], w);
244 mem.writeInt(u32, out[i * 4 ..][0..4], w, .little);
245245 }
246246 }
247247
......@@ -283,20 +283,20 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type {
283283 fn hsalsa(input: [16]u8, key: [32]u8) [32]u8 {
284284 var c: [4]u32 = undefined;
285285 for (c, 0..) |_, i| {
286 c[i] = mem.readIntLittle(u32, input[4 * i ..][0..4]);
286 c[i] = mem.readInt(u32, input[4 * i ..][0..4], .little);
287287 }
288288 const ctx = initContext(keyToWords(key), c);
289289 var x: BlockVec = undefined;
290290 salsaCore(x[0..], ctx, false);
291291 var out: [32]u8 = undefined;
292 mem.writeIntLittle(u32, out[0..4], x[0]);
293 mem.writeIntLittle(u32, out[4..8], x[5]);
294 mem.writeIntLittle(u32, out[8..12], x[10]);
295 mem.writeIntLittle(u32, out[12..16], x[15]);
296 mem.writeIntLittle(u32, out[16..20], x[6]);
297 mem.writeIntLittle(u32, out[20..24], x[7]);
298 mem.writeIntLittle(u32, out[24..28], x[8]);
299 mem.writeIntLittle(u32, out[28..32], x[9]);
292 mem.writeInt(u32, out[0..4], x[0], .little);
293 mem.writeInt(u32, out[4..8], x[5], .little);
294 mem.writeInt(u32, out[8..12], x[10], .little);
295 mem.writeInt(u32, out[12..16], x[15], .little);
296 mem.writeInt(u32, out[16..20], x[6], .little);
297 mem.writeInt(u32, out[20..24], x[7], .little);
298 mem.writeInt(u32, out[24..28], x[8], .little);
299 mem.writeInt(u32, out[28..32], x[9], .little);
300300 return out;
301301 }
302302 };
......@@ -308,7 +308,7 @@ fn keyToWords(key: [32]u8) [8]u32 {
308308 var k: [8]u32 = undefined;
309309 var i: usize = 0;
310310 while (i < 8) : (i += 1) {
311 k[i] = mem.readIntLittle(u32, key[i * 4 ..][0..4]);
311 k[i] = mem.readInt(u32, key[i * 4 ..][0..4], .little);
312312 }
313313 return k;
314314}
......@@ -335,8 +335,8 @@ pub fn Salsa(comptime rounds: comptime_int) type {
335335 debug.assert(in.len == out.len);
336336
337337 var d: [4]u32 = undefined;
338 d[0] = mem.readIntLittle(u32, nonce[0..4]);
339 d[1] = mem.readIntLittle(u32, nonce[4..8]);
338 d[0] = mem.readInt(u32, nonce[0..4], .little);
339 d[1] = mem.readInt(u32, nonce[4..8], .little);
340340 d[2] = @as(u32, @truncate(counter));
341341 d[3] = @as(u32, @truncate(counter >> 32));
342342 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)
9191 var y: []align(16) u32 = @alignCast(xy[32 * r ..]);
9292
9393 for (x, 0..) |*v1, j| {
94 v1.* = mem.readIntSliceLittle(u32, b[4 * j ..]);
94 v1.* = mem.readInt(u32, b[4 * j ..][0..4], .little);
9595 }
9696
9797 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)
116116 }
117117
118118 for (x, 0..) |v1, j| {
119 mem.writeIntLittle(u32, b[4 * j ..][0..4], v1);
119 mem.writeInt(u32, b[4 * j ..][0..4], v1, .little);
120120 }
121121}
122122
......@@ -361,7 +361,7 @@ const crypt_format = struct {
361361 std.debug.assert(dst.len == decodedLen(src.len));
362362 var i: usize = 0;
363363 while (i < src.len / 4) : (i += 1) {
364 mem.writeIntSliceLittle(u24, dst[i * 3 ..], try intDecode(u24, src[i * 4 ..][0..4]));
364 mem.writeInt(u24, dst[i * 3 ..][0..3], try intDecode(u24, src[i * 4 ..][0..4]), .little);
365365 }
366366 const leftover = src[i * 4 ..];
367367 var v: u24 = 0;
......@@ -377,7 +377,7 @@ const crypt_format = struct {
377377 std.debug.assert(dst.len == encodedLen(src.len));
378378 var i: usize = 0;
379379 while (i < src.len / 3) : (i += 1) {
380 intEncode(dst[i * 4 ..][0..4], mem.readIntSliceLittle(u24, src[i * 3 ..]));
380 intEncode(dst[i * 4 ..][0..4], mem.readInt(u24, src[i * 3 ..][0..3], .little));
381381 }
382382 const leftover = src[i * 3 ..];
383383 var v: u24 = 0;
lib/std/crypto/sha1.zig+2-2
......@@ -111,7 +111,7 @@ pub const Sha1 = struct {
111111 d.round(d.buf[0..]);
112112
113113 for (d.s, 0..) |s, j| {
114 mem.writeIntBig(u32, out[4 * j ..][0..4], s);
114 mem.writeInt(u32, out[4 * j ..][0..4], s, .big);
115115 }
116116 }
117117
......@@ -151,7 +151,7 @@ pub const Sha1 = struct {
151151 roundParam(0, 1, 2, 3, 4, 15),
152152 };
153153 inline for (round0a) |r| {
154 s[r.i] = mem.readIntBig(u32, b[r.i * 4 ..][0..4]);
154 s[r.i] = mem.readInt(u32, b[r.i * 4 ..][0..4], .big);
155155
156156 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]));
157157 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 {
171171 const rr = d.s[0 .. params.digest_bits / 32];
172172
173173 for (rr, 0..) |s, j| {
174 mem.writeIntBig(u32, out[4 * j ..][0..4], s);
174 mem.writeInt(u32, out[4 * j ..][0..4], s, .big);
175175 }
176176 }
177177
......@@ -195,7 +195,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
195195 fn round(d: *Self, b: *const [64]u8) void {
196196 var s: [64]u32 align(16) = undefined;
197197 for (@as(*align(1) const [16]u32, @ptrCast(b)), 0..) |*elem, i| {
198 s[i] = mem.readIntBig(u32, mem.asBytes(elem));
198 s[i] = mem.readInt(u32, mem.asBytes(elem), .big);
199199 }
200200
201201 if (!@inComptime()) {
......@@ -663,7 +663,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
663663 const rr = d.s[0 .. params.digest_bits / 64];
664664
665665 for (rr, 0..) |s, j| {
666 mem.writeIntBig(u64, out[8 * j ..][0..8], s);
666 mem.writeInt(u64, out[8 * j ..][0..8], s, .big);
667667 }
668668 }
669669
......@@ -678,7 +678,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
678678
679679 var i: usize = 0;
680680 while (i < 16) : (i += 1) {
681 s[i] = mem.readIntBig(u64, b[i * 8 ..][0..8]);
681 s[i] = mem.readInt(u64, b[i * 8 ..][0..8], .big);
682682 }
683683 while (i < 80) : (i += 1) {
684684 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
5656 msg_len: u8,
5757
5858 fn init(key: *const [key_length]u8) Self {
59 const k0 = mem.readIntLittle(u64, key[0..8]);
60 const k1 = mem.readIntLittle(u64, key[8..16]);
59 const k0 = mem.readInt(u64, key[0..8], .little);
60 const k1 = mem.readInt(u64, key[8..16], .little);
6161
6262 var d = Self{
6363 .v0 = k0 ^ 0x736f6d6570736575,
......@@ -124,7 +124,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round
124124 }
125125
126126 fn round(self: *Self, b: [8]u8) void {
127 const m = mem.readIntLittle(u64, &b);
127 const m = mem.readInt(u64, &b, .little);
128128 self.v3 ^= m;
129129
130130 comptime var i: usize = 0;
......@@ -213,7 +213,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
213213 /// Return an authentication tag for the current state
214214 /// Assumes `out` is less than or equal to `mac_length`.
215215 pub fn final(self: *Self, out: *[mac_length]u8) void {
216 mem.writeIntLittle(T, out, self.state.final(self.buf[0..self.buf_len]));
216 mem.writeInt(T, out, self.state.final(self.buf[0..self.buf_len]), .little);
217217 }
218218
219219 pub fn finalResult(self: *Self) [mac_length]u8 {
lib/std/crypto/tls.zig+1-1
......@@ -370,7 +370,7 @@ pub fn hkdfExpandLabel(
370370 const max_context_len = 255;
371371 const tls13 = "tls13 ";
372372 var buf: [2 + 1 + tls13.len + max_label_len + 1 + max_context_len]u8 = undefined;
373 mem.writeIntBig(u16, buf[0..2], len);
373 mem.writeInt(u16, buf[0..2], len, .big);
374374 buf[2] = @as(u8, @intCast(tls13.len + label.len));
375375 buf[3..][0..tls13.len].* = tls13.*;
376376 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
332332 const pk = PublicKey.fromSec1(server_pub_key) catch {
333333 return error.TlsDecryptFailure;
334334 };
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 {
336336 return error.TlsDecryptFailure;
337337 };
338 shared_key = &mul.affineCoordinates().x.toBytes(.Big);
338 shared_key = &mul.affineCoordinates().x.toBytes(.big);
339339 },
340340 else => {
341341 return error.TlsIllegalParameter;
......@@ -1049,10 +1049,10 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
10491049 }
10501050 const ct: tls.ContentType = @enumFromInt(frag[in]);
10511051 in += 1;
1052 const legacy_version = mem.readIntBig(u16, frag[in..][0..2]);
1052 const legacy_version = mem.readInt(u16, frag[in..][0..2], .big);
10531053 in += 2;
10541054 _ = legacy_version;
1055 const record_len = mem.readIntBig(u16, frag[in..][0..2]);
1055 const record_len = mem.readInt(u16, frag[in..][0..2], .big);
10561056 if (record_len > max_ciphertext_len) return error.TlsRecordOverflow;
10571057 in += 2;
10581058 const end = in + record_len;
......@@ -1136,7 +1136,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec)
11361136 while (true) {
11371137 const handshake_type: tls.HandshakeType = @enumFromInt(cleartext[ct_i]);
11381138 ct_i += 1;
1139 const handshake_len = mem.readIntBig(u24, cleartext[ct_i..][0..3]);
1139 const handshake_len = mem.readInt(u24, cleartext[ct_i..][0..3], .big);
11401140 ct_i += 3;
11411141 const next_handshake_i = ct_i + handshake_len;
11421142 if (next_handshake_i > cleartext.len - 1)
......@@ -1284,8 +1284,8 @@ const native_endian = builtin.cpu.arch.endian();
12841284
12851285inline fn big(x: anytype) @TypeOf(x) {
12861286 return switch (native_endian) {
1287 .Big => x,
1288 .Little => @byteSwap(x),
1287 .big => x,
1288 .little => @byteSwap(x),
12891289 };
12901290}
12911291
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
5454 const Cext = std.meta.Int(.unsigned, bits + 1);
5555 var gt: T = 0;
5656 var eq: T = 1;
57 if (endian == .Little) {
57 if (endian == .little) {
5858 var i = a.len;
5959 while (i != 0) {
6060 i -= 1;
......@@ -84,7 +84,7 @@ pub fn timingSafeAdd(comptime T: type, a: []const T, b: []const T, result: []T,
8484 const len = a.len;
8585 debug.assert(len == b.len and len == result.len);
8686 var carry: u1 = 0;
87 if (endian == .Little) {
87 if (endian == .little) {
8888 var i: usize = 0;
8989 while (i < len) : (i += 1) {
9090 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,
111111 const len = a.len;
112112 debug.assert(len == b.len and len == result.len);
113113 var borrow: u1 = 0;
114 if (endian == .Little) {
114 if (endian == .little) {
115115 var i: usize = 0;
116116 while (i < len) : (i += 1) {
117117 const ov1 = @subWithOverflow(a[i], b[i]);
......@@ -165,14 +165,14 @@ test "crypto.utils.timingSafeEql (vectors)" {
165165test "crypto.utils.timingSafeCompare" {
166166 var a = [_]u8{10} ** 32;
167167 var b = [_]u8{10} ** 32;
168 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .eq);
169 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .eq);
168 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .big), .eq);
169 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .little), .eq);
170170 a[31] = 1;
171 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .lt);
172 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
171 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .big), .lt);
172 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .little), .lt);
173173 a[0] = 20;
174 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .gt);
175 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt);
174 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .big), .gt);
175 try testing.expectEqual(timingSafeCompare(u8, &a, &b, .little), .lt);
176176}
177177
178178test "crypto.utils.timingSafe{Add,Sub}" {
......@@ -185,7 +185,7 @@ test "crypto.utils.timingSafe{Add,Sub}" {
185185 while (iterations != 0) : (iterations -= 1) {
186186 random.bytes(&a);
187187 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;
189189 _ = timingSafeSub(u8, &a, &b, &c, endian); // a-b
190190 _ = timingSafeAdd(u8, &c, &b, &c, endian); // (a-b)+b
191191 try testing.expectEqualSlices(u8, &c, &a);
lib/std/debug.zig+8-8
......@@ -1098,8 +1098,8 @@ pub fn readElfDebugInfo(
10981098 if (hdr.e_ident[elf.EI_VERSION] != 1) return error.InvalidElfVersion;
10991099
11001100 const endian: std.builtin.Endian = switch (hdr.e_ident[elf.EI_DATA]) {
1101 elf.ELFDATA2LSB => .Little,
1102 elf.ELFDATA2MSB => .Big,
1101 elf.ELFDATA2LSB => .little,
1102 elf.ELFDATA2MSB => .big,
11031103 else => return error.InvalidElfEndian,
11041104 };
11051105 assert(endian == native_endian); // this is our own debug info
......@@ -1135,8 +1135,8 @@ pub fn readElfDebugInfo(
11351135 const gnu_debuglink = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size);
11361136 const debug_filename = mem.sliceTo(@as([*:0]const u8, @ptrCast(gnu_debuglink.ptr)), 0);
11371137 const crc_offset = mem.alignForward(usize, @intFromPtr(&debug_filename[debug_filename.len]) + 1, 4) - @intFromPtr(gnu_debuglink.ptr);
1138 const crc_bytes = gnu_debuglink[crc_offset .. crc_offset + 4];
1139 separate_debug_crc = mem.readIntSliceNative(u32, crc_bytes);
1138 const crc_bytes = gnu_debuglink[crc_offset..][0..4];
1139 separate_debug_crc = mem.readInt(u32, crc_bytes, native_endian);
11401140 separate_debug_filename = debug_filename;
11411141 continue;
11421142 }
......@@ -1868,10 +1868,10 @@ pub const DebugInfo = struct {
18681868 elf.PT_NOTE => {
18691869 // Look for .note.gnu.build-id
18701870 const note_bytes = @as([*]const u8, @ptrFromInt(info.dlpi_addr + phdr.p_vaddr))[0..phdr.p_memsz];
1871 const name_size = mem.readIntSliceNative(u32, note_bytes[0..4]);
1871 const name_size = mem.readInt(u32, note_bytes[0..4], native_endian);
18721872 if (name_size != 4) continue;
1873 const desc_size = mem.readIntSliceNative(u32, note_bytes[4..8]);
1874 const note_type = mem.readIntSliceNative(u32, note_bytes[8..12]);
1873 const desc_size = mem.readInt(u32, note_bytes[4..8], native_endian);
1874 const note_type = mem.readInt(u32, note_bytes[8..12], native_endian);
18751875 if (note_type != elf.NT_GNU_BUILD_ID) continue;
18761876 if (!mem.eql(u8, "GNU\x00", note_bytes[12..16])) continue;
18771877 context.build_id = note_bytes[16..][0..desc_size];
......@@ -2040,7 +2040,7 @@ pub const ModuleDebugInfo = switch (native_os) {
20402040 if (missing_debug_info) return error.MissingDebugInfo;
20412041
20422042 var di = DW.DwarfInfo{
2043 .endian = .Little,
2043 .endian = .little,
20442044 .sections = sections,
20452045 .is_macho = true,
20462046 };
lib/std/dwarf.zig+4-3
......@@ -7,6 +7,7 @@ const mem = std.mem;
77const math = std.math;
88const leb = @import("leb128.zig");
99const assert = std.debug.assert;
10const native_endian = builtin.cpu.arch.endian();
1011
1112pub const TAG = @import("dwarf/TAG.zig");
1213pub const AT = @import("dwarf/AT.zig");
......@@ -1741,7 +1742,7 @@ pub const DwarfInfo = struct {
17411742 context.cfa = switch (row.cfa.rule) {
17421743 .val_offset => |offset| blk: {
17431744 const register = row.cfa.register orelse return error.InvalidCFARule;
1744 const value = mem.readIntSliceNative(usize, try abi.regBytes(context.thread_context, register, context.reg_context));
1745 const value = mem.readInt(usize, (try abi.regBytes(context.thread_context, register, context.reg_context))[0..@sizeOf(usize)], native_endian);
17451746 break :blk try call_frame.applyOffset(value, offset);
17461747 },
17471748 .expression => |expression| blk: {
......@@ -1814,11 +1815,11 @@ pub const DwarfInfo = struct {
18141815 }
18151816
18161817 if (has_return_address) {
1817 context.pc = abi.stripInstructionPtrAuthCode(mem.readIntSliceNative(usize, try abi.regBytes(
1818 context.pc = abi.stripInstructionPtrAuthCode(mem.readInt(usize, (try abi.regBytes(
18181819 context.thread_context,
18191820 cie.return_address_register,
18201821 context.reg_context,
1821 )));
1822 ))[0..@sizeOf(usize)], native_endian));
18221823 } else {
18231824 context.pc = 0;
18241825 }
lib/std/dwarf/call_frame.zig+5-4
......@@ -7,6 +7,7 @@ const dwarf = std.dwarf;
77const abi = dwarf.abi;
88const expressions = dwarf.expressions;
99const assert = std.debug.assert;
10const native_endian = builtin.cpu.arch.endian();
1011
1112const Opcode = enum(u8) {
1213 advance_loc = 0x1 << 6,
......@@ -386,12 +387,12 @@ pub const VirtualMachine = struct {
386387 const addr = try applyOffset(cfa, offset);
387388 if (expression_context.isValidMemory) |isValidMemory| if (!isValidMemory(addr)) return error.InvalidAddress;
388389 const ptr: *const usize = @ptrFromInt(addr);
389 mem.writeIntSliceNative(usize, out, ptr.*);
390 mem.writeInt(usize, out[0..@sizeOf(usize)], ptr.*, native_endian);
390391 } else return error.InvalidCFA;
391392 },
392393 .val_offset => |offset| {
393394 if (context.cfa) |cfa| {
394 mem.writeIntSliceNative(usize, out, try applyOffset(cfa, offset));
395 mem.writeInt(usize, out[0..@sizeOf(usize)], try applyOffset(cfa, offset), native_endian);
395396 } else return error.InvalidCFA;
396397 },
397398 .register => |register| {
......@@ -409,14 +410,14 @@ pub const VirtualMachine = struct {
409410
410411 if (!context.isValidMemory(addr)) return error.InvalidExpressionAddress;
411412 const ptr: *usize = @ptrFromInt(addr);
412 mem.writeIntSliceNative(usize, out, ptr.*);
413 mem.writeInt(usize, out[0..@sizeOf(usize)], ptr.*, native_endian);
413414 },
414415 .val_expression => |expression| {
415416 context.stack_machine.reset();
416417 const value = try context.stack_machine.run(expression, context.allocator, expression_context, context.cfa.?);
417418 if (value) |v| {
418419 if (v != .generic) return error.InvalidExpressionValue;
419 mem.writeIntSliceNative(usize, out, v.generic);
420 mem.writeInt(usize, out[0..@sizeOf(usize)], v.generic, native_endian);
420421 } else return error.NoExpressionValue;
421422 },
422423 .architectural => return error.UnimplementedRegisterRule,
lib/std/dwarf/expressions.zig+17-16
......@@ -6,6 +6,7 @@ const dwarf = std.dwarf;
66const abi = dwarf.abi;
77const mem = std.mem;
88const assert = std.debug.assert;
9const native_endian = builtin.cpu.arch.endian();
910
1011/// Expressions can be evaluated in different contexts, each requiring its own set of inputs.
1112/// Callers should specify all the fields relevant to their context. If a field is required
......@@ -147,10 +148,10 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
147148 .regval_type => |regval_type| regval_type.value,
148149 .const_type => |const_type| {
149150 const value: u64 = switch (const_type.value_bytes.len) {
150 1 => mem.readIntSliceNative(u8, const_type.value_bytes),
151 2 => mem.readIntSliceNative(u16, const_type.value_bytes),
152 4 => mem.readIntSliceNative(u32, const_type.value_bytes),
153 8 => mem.readIntSliceNative(u64, const_type.value_bytes),
151 1 => mem.readInt(u8, const_type.value_bytes[0..1], native_endian),
152 2 => mem.readInt(u16, const_type.value_bytes[0..2], native_endian),
153 4 => mem.readInt(u32, const_type.value_bytes[0..4], native_endian),
154 8 => mem.readInt(u64, const_type.value_bytes[0..8], native_endian),
154155 else => return error.InvalidIntegralTypeSize,
155156 };
156157
......@@ -352,7 +353,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
352353 const debug_addr_index = operand.?.generic;
353354 const offset = context.compile_unit.?.addr_base + debug_addr_index;
354355 if (offset >= context.debug_addr.?.len) return error.InvalidExpression;
355 const value = mem.readIntSliceNative(usize, context.debug_addr.?[offset..][0..@sizeOf(usize)]);
356 const value = mem.readInt(usize, context.debug_addr.?[offset..][0..@sizeOf(usize)], native_endian);
356357 try self.stack.append(allocator, .{ .generic = value });
357358 },
358359
......@@ -386,21 +387,21 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
386387 if (context.thread_context == null) return error.IncompleteExpressionContext;
387388
388389 const base_register = operand.?.base_register;
389 var value: i64 = @intCast(mem.readIntSliceNative(usize, try abi.regBytes(
390 var value: i64 = @intCast(mem.readInt(usize, (try abi.regBytes(
390391 context.thread_context.?,
391392 base_register.base_register,
392393 context.reg_context,
393 )));
394 ))[0..@sizeOf(usize)], native_endian));
394395 value += base_register.offset;
395396 try self.stack.append(allocator, .{ .generic = @intCast(value) });
396397 },
397398 OP.regval_type => {
398399 const register_type = operand.?.register_type;
399 const value = mem.readIntSliceNative(usize, try abi.regBytes(
400 const value = mem.readInt(usize, (try abi.regBytes(
400401 context.thread_context.?,
401402 register_type.register,
402403 context.reg_context,
403 ));
404 ))[0..@sizeOf(usize)], native_endian);
404405 try self.stack.append(allocator, .{
405406 .regval_type = .{
406407 .type_offset = register_type.type_offset,
......@@ -756,7 +757,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type {
756757
757758 var block_stream = std.io.fixedBufferStream(block);
758759 const register = (try readOperand(&block_stream, block[0], context)).?.register;
759 const value = mem.readIntSliceNative(usize, try abi.regBytes(context.thread_context.?, register, context.reg_context));
760 const value = mem.readInt(usize, (try abi.regBytes(context.thread_context.?, register, context.reg_context))[0..@sizeOf(usize)], native_endian);
760761 try self.stack.append(allocator, .{ .generic = value });
761762 } else {
762763 var stack_machine: Self = .{};
......@@ -1121,9 +1122,9 @@ test "DWARF expressions" {
11211122 var mock_debug_addr = std.ArrayList(u8).init(allocator);
11221123 defer mock_debug_addr.deinit();
11231124
1124 try mock_debug_addr.writer().writeIntNative(u16, 0);
1125 try mock_debug_addr.writer().writeIntNative(usize, input[11]);
1126 try mock_debug_addr.writer().writeIntNative(usize, input[12]);
1125 try mock_debug_addr.writer().writeInt(u16, 0, native_endian);
1126 try mock_debug_addr.writer().writeInt(usize, input[11], native_endian);
1127 try mock_debug_addr.writer().writeInt(usize, input[12], native_endian);
11271128
11281129 const context = ExpressionContext{
11291130 .compile_unit = &mock_compile_unit,
......@@ -1185,7 +1186,7 @@ test "DWARF expressions" {
11851186
11861187 // TODO: Test fbreg (once implemented): mock a DIE and point compile_unit.frame_base at it
11871188
1188 mem.writeIntSliceNative(usize, reg_bytes, 0xee);
1189 mem.writeInt(usize, reg_bytes[0..@sizeOf(usize)], 0xee, native_endian);
11891190 (try abi.regValueNative(usize, &thread_context, abi.fpRegNum(reg_context), reg_context)).* = 1;
11901191 (try abi.regValueNative(usize, &thread_context, abi.spRegNum(reg_context), reg_context)).* = 2;
11911192 (try abi.regValueNative(usize, &thread_context, abi.ipRegNum(), reg_context)).* = 3;
......@@ -1538,7 +1539,7 @@ test "DWARF expressions" {
15381539
15391540 const value: usize = @truncate(0xffeeffee_ffeeffee);
15401541 var value_bytes: [options.addr_size]u8 = undefined;
1541 mem.writeIntSliceNative(usize, &value_bytes, value);
1542 mem.writeInt(usize, &value_bytes, value, native_endian);
15421543
15431544 // Convert to generic type
15441545 stack_machine.reset();
......@@ -1613,7 +1614,7 @@ test "DWARF expressions" {
16131614 };
16141615
16151616 if (abi.regBytes(&thread_context, 0, reg_context)) |reg_bytes| {
1616 mem.writeIntSliceNative(usize, reg_bytes, 0xee);
1617 mem.writeInt(usize, reg_bytes[0..@sizeOf(usize)], 0xee, native_endian);
16171618
16181619 var sub_program = std.ArrayList(u8).init(allocator);
16191620 defer sub_program.deinit();
lib/std/elf.zig+2-2
......@@ -497,8 +497,8 @@ pub const Header = struct {
497497 if (hdr32.e_ident[EI_VERSION] != 1) return error.InvalidElfVersion;
498498
499499 const endian: std.builtin.Endian = switch (hdr32.e_ident[EI_DATA]) {
500 ELFDATA2LSB => .Little,
501 ELFDATA2MSB => .Big,
500 ELFDATA2LSB => .little,
501 ELFDATA2MSB => .big,
502502 else => return error.InvalidElfEndian,
503503 };
504504 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 {
9898}
9999
100100pub fn readU64Unchecked(self: FloatStream) u64 {
101 return std.mem.readIntSliceLittle(u64, self.slice[self.offset..]);
101 return std.mem.readInt(u64, self.slice[self.offset..][0..8], .little);
102102}
103103
104104pub 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 {
260260 if (!isEightDigits(v)) {
261261 break;
262262 }
263 std.mem.writeIntSliceLittle(u64, d.digits[d.num_digits..], v - 0x3030_3030_3030_3030);
263 std.mem.writeInt(u64, d.digits[d.num_digits..][0..8], v - 0x3030_3030_3030_3030, .little);
264264 d.num_digits += 8;
265265 stream.advance(8);
266266 }
lib/std/fs/path.zig+1-1
......@@ -1828,7 +1828,7 @@ test "ComponentIterator windows" {
18281828
18291829test "ComponentIterator windows UTF-16" {
18301830 // TODO: Fix on big endian architectures
1831 if (builtin.cpu.arch.endian() != .Little) {
1831 if (builtin.cpu.arch.endian() != .little) {
18321832 return error.SkipZigTest;
18331833 }
18341834
lib/std/hash/cityhash.zig+2-2
......@@ -6,11 +6,11 @@ inline fn offsetPtr(ptr: [*]const u8, offset: usize) [*]const u8 {
66}
77
88fn fetch32(ptr: [*]const u8, offset: usize) u32 {
9 return std.mem.readIntLittle(u32, offsetPtr(ptr, offset)[0..4]);
9 return std.mem.readInt(u32, offsetPtr(ptr, offset)[0..4], .little);
1010}
1111
1212fn fetch64(ptr: [*]const u8, offset: usize) u64 {
13 return std.mem.readIntLittle(u64, offsetPtr(ptr, offset)[0..8]);
13 return std.mem.readInt(u64, offsetPtr(ptr, offset)[0..8], .little);
1414}
1515
1616pub const CityHash32 = struct {
lib/std/hash/crc.zig+1-1
......@@ -163,7 +163,7 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type {
163163 const p = input[i..][0..8];
164164
165165 // Unrolling this way gives ~50Mb/s increase
166 self.crc ^= std.mem.readIntLittle(u32, p[0..4]);
166 self.crc ^= std.mem.readInt(u32, p[0..4], .little);
167167
168168 self.crc =
169169 lookup_tables[0][p[7]] ^
lib/std/hash/murmur.zig+7-7
......@@ -18,7 +18,7 @@ pub const Murmur2_32 = struct {
1818 var h1: u32 = seed ^ len;
1919 for (@as([*]align(1) const u32, @ptrCast(str.ptr))[0..(len >> 2)]) |v| {
2020 var k1: u32 = v;
21 if (native_endian == .Big)
21 if (native_endian == .big)
2222 k1 = @byteSwap(k1);
2323 k1 *%= m;
2424 k1 ^= k1 >> 24;
......@@ -102,7 +102,7 @@ pub const Murmur2_64 = struct {
102102 var h1: u64 = seed ^ (@as(u64, str.len) *% m);
103103 for (@as([*]align(1) const u64, @ptrCast(str.ptr))[0 .. str.len / 8]) |v| {
104104 var k1: u64 = v;
105 if (native_endian == .Big)
105 if (native_endian == .big)
106106 k1 = @byteSwap(k1);
107107 k1 *%= m;
108108 k1 ^= k1 >> 47;
......@@ -115,7 +115,7 @@ pub const Murmur2_64 = struct {
115115 if (rest > 0) {
116116 var k1: u64 = 0;
117117 @memcpy(@as([*]u8, @ptrCast(&k1))[0..rest], str[offset..]);
118 if (native_endian == .Big)
118 if (native_endian == .big)
119119 k1 = @byteSwap(k1);
120120 h1 ^= k1;
121121 h1 *%= m;
......@@ -182,7 +182,7 @@ pub const Murmur3_32 = struct {
182182 var h1: u32 = seed;
183183 for (@as([*]align(1) const u32, @ptrCast(str.ptr))[0..(len >> 2)]) |v| {
184184 var k1: u32 = v;
185 if (native_endian == .Big)
185 if (native_endian == .big)
186186 k1 = @byteSwap(k1);
187187 k1 *%= c1;
188188 k1 = rotl32(k1, 15);
......@@ -286,7 +286,7 @@ test "murmur2_32" {
286286 var v1: u64 = 0x1234567812345678;
287287 var v0le: u32 = v0;
288288 var v1le: u64 = v1;
289 if (native_endian == .Big) {
289 if (native_endian == .big) {
290290 v0le = @byteSwap(v0le);
291291 v1le = @byteSwap(v1le);
292292 }
......@@ -310,7 +310,7 @@ test "murmur2_64" {
310310 var v1: u64 = 0x1234567812345678;
311311 var v0le: u32 = v0;
312312 var v1le: u64 = v1;
313 if (native_endian == .Big) {
313 if (native_endian == .big) {
314314 v0le = @byteSwap(v0le);
315315 v1le = @byteSwap(v1le);
316316 }
......@@ -334,7 +334,7 @@ test "murmur3_32" {
334334 var v1: u64 = 0x1234567812345678;
335335 var v0le: u32 = v0;
336336 var v1le: u64 = v1;
337 if (native_endian == .Big) {
337 if (native_endian == .big) {
338338 v0le = @byteSwap(v0le);
339339 v1le = @byteSwap(v1le);
340340 }
lib/std/hash/verify.zig+1-1
......@@ -37,7 +37,7 @@ pub fn smhasher(comptime hash_fn: anytype) u32 {
3737 for (0..256) |i| {
3838 buf[i] = @intCast(i);
3939 const h = hashMaybeSeed(hash_fn, 256 - i, buf[0..i]);
40 std.mem.writeIntLittle(HashResult, buf_all[i * hash_size ..][0..hash_size], h);
40 std.mem.writeInt(HashResult, buf_all[i * hash_size ..][0..hash_size], h, .little);
4141 }
4242
4343 return @truncate(hashMaybeSeed(hash_fn, 0, buf_all[0..]));
lib/std/hash/wyhash.zig+1-1
......@@ -131,7 +131,7 @@ pub const Wyhash = struct {
131131 inline fn read(comptime bytes: usize, data: []const u8) u64 {
132132 std.debug.assert(bytes <= 8);
133133 const T = std.meta.Int(.unsigned, 8 * bytes);
134 return @as(u64, std.mem.readIntLittle(T, data[0..bytes]));
134 return @as(u64, std.mem.readInt(T, data[0..bytes], .little));
135135 }
136136
137137 inline fn mum(a: *u64, b: *u64) void {
lib/std/hash/xxhash.zig+12-12
......@@ -53,10 +53,10 @@ pub const XxHash64 = struct {
5353 }
5454
5555 fn processStripe(self: *Accumulator, buf: *const [32]u8) void {
56 self.acc1 = round(self.acc1, mem.readIntLittle(u64, buf[0..8]));
57 self.acc2 = round(self.acc2, mem.readIntLittle(u64, buf[8..16]));
58 self.acc3 = round(self.acc3, mem.readIntLittle(u64, buf[16..24]));
59 self.acc4 = round(self.acc4, mem.readIntLittle(u64, buf[24..32]));
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));
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));
6060 }
6161
6262 fn merge(self: Accumulator) u64 {
......@@ -139,7 +139,7 @@ pub const XxHash64 = struct {
139139
140140 fn finalize8(v: u64, bytes: *const [8]u8) u64 {
141141 var acc = v;
142 const lane = mem.readIntLittle(u64, bytes);
142 const lane = mem.readInt(u64, bytes, .little);
143143 acc ^= round(0, lane);
144144 acc = rotl(u64, acc, 27) *% prime_1;
145145 acc +%= prime_4;
......@@ -148,7 +148,7 @@ pub const XxHash64 = struct {
148148
149149 fn finalize4(v: u64, bytes: *const [4]u8) u64 {
150150 var acc = v;
151 const lane = @as(u64, mem.readIntLittle(u32, bytes));
151 const lane = @as(u64, mem.readInt(u32, bytes, .little));
152152 acc ^= lane *% prime_1;
153153 acc = rotl(u64, acc, 23) *% prime_2;
154154 acc +%= prime_3;
......@@ -291,10 +291,10 @@ pub const XxHash32 = struct {
291291 }
292292
293293 fn processStripe(self: *Accumulator, buf: *const [16]u8) void {
294 self.acc1 = round(self.acc1, mem.readIntLittle(u32, buf[0..4]));
295 self.acc2 = round(self.acc2, mem.readIntLittle(u32, buf[4..8]));
296 self.acc3 = round(self.acc3, mem.readIntLittle(u32, buf[8..12]));
297 self.acc4 = round(self.acc4, mem.readIntLittle(u32, buf[12..16]));
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));
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));
298298 }
299299
300300 fn merge(self: Accumulator) u32 {
......@@ -390,7 +390,7 @@ pub const XxHash32 = struct {
390390
391391 fn finalize4(v: u32, bytes: *const [4]u8) u32 {
392392 var acc = v;
393 const lane = mem.readIntLittle(u32, bytes);
393 const lane = mem.readInt(u32, bytes, .little);
394394 acc +%= lane *% prime_3;
395395 acc = rotl(u32, acc, 17) *% prime_4;
396396 return acc;
......@@ -472,7 +472,7 @@ pub const XxHash3 = struct {
472472 }
473473
474474 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;
476476 }
477477
478478 inline fn disableAutoVectorization(x: anytype) void {
lib/std/heap/WasmPageAllocator.zig+1-1
......@@ -28,7 +28,7 @@ const PageStatus = enum(u1) {
2828const FreeBlock = struct {
2929 data: []u128,
3030
31 const Io = std.packed_int_array.PackedIntIo(u1, .Little);
31 const Io = std.packed_int_array.PackedIntIo(u1, .little);
3232
3333 fn totalPages(self: FreeBlock) usize {
3434 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
15811581
15821582test {
15831583 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) {
15851585 // https://github.com/ziglang/zig/issues/13782
15861586 return error.SkipZigTest;
15871587 }
lib/std/http/Server.zig+1-1
......@@ -739,7 +739,7 @@ test "HTTP server handles a chunked transfer coding request" {
739739 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
740740
741741 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) {
743743 // https://github.com/ziglang/zig/issues/13782
744744 return error.SkipZigTest;
745745 }
lib/std/http/protocol.zig+2-2
......@@ -617,8 +617,8 @@ inline fn int32(array: *const [4]u8) u32 {
617617
618618inline fn intShift(comptime T: type, x: anytype) T {
619619 switch (@import("builtin").cpu.arch.endian()) {
620 .Little => return @as(T, @truncate(x >> (@bitSizeOf(@TypeOf(x)) - @bitSizeOf(T)))),
621 .Big => return @as(T, @truncate(x)),
620 .little => return @as(T, @truncate(x >> (@bitSizeOf(@TypeOf(x)) - @bitSizeOf(T)))),
621 .big => return @as(T, @truncate(x)),
622622 }
623623}
624624
lib/std/io.zig-16
......@@ -269,22 +269,6 @@ pub fn GenericReader(
269269 return @errorCast(self.any().readBoundedBytes(num_bytes));
270270 }
271271
272 pub inline fn readIntNative(self: Self, comptime T: type) NoEofError!T {
273 return @errorCast(self.any().readIntNative(T));
274 }
275
276 pub inline fn readIntForeign(self: Self, comptime T: type) NoEofError!T {
277 return @errorCast(self.any().readIntForeign(T));
278 }
279
280 pub inline fn readIntLittle(self: Self, comptime T: type) NoEofError!T {
281 return @errorCast(self.any().readIntLittle(T));
282 }
283
284 pub inline fn readIntBig(self: Self, comptime T: type) NoEofError!T {
285 return @errorCast(self.any().readIntBig(T));
286 }
287
288272 pub inline fn readInt(self: Self, comptime T: type, endian: std.builtin.Endian) NoEofError!T {
289273 return @errorCast(self.any().readInt(T, endian));
290274 }
lib/std/io/Reader.zig+3-25
......@@ -276,30 +276,8 @@ pub fn readBoundedBytes(self: Self, comptime num_bytes: usize) anyerror!std.Boun
276276 return result;
277277}
278278
279/// Reads a native-endian integer
280pub fn readIntNative(self: Self, comptime T: type) anyerror!T {
281 const bytes = try self.readBytesNoEof(@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8)));
282 return mem.readIntNative(T, &bytes);
283}
284
285/// Reads a foreign-endian integer
286pub fn readIntForeign(self: Self, comptime T: type) anyerror!T {
287 const bytes = try self.readBytesNoEof(@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8)));
288 return mem.readIntForeign(T, &bytes);
289}
290
291pub fn readIntLittle(self: Self, comptime T: type) anyerror!T {
292 const bytes = try self.readBytesNoEof(@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8)));
293 return mem.readIntLittle(T, &bytes);
294}
295
296pub fn readIntBig(self: Self, comptime T: type) anyerror!T {
297 const bytes = try self.readBytesNoEof(@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8)));
298 return mem.readIntBig(T, &bytes);
299}
300
301pub fn readInt(self: Self, comptime T: type, endian: std.builtin.Endian) anyerror!T {
302 const bytes = try self.readBytesNoEof(@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8)));
279pub inline fn readInt(self: Self, comptime T: type, endian: std.builtin.Endian) anyerror!T {
280 const bytes = try self.readBytesNoEof(@divExact(@typeInfo(T).Int.bits, 8));
303281 return mem.readInt(T, &bytes, endian);
304282}
305283
......@@ -356,7 +334,7 @@ pub fn readStruct(self: Self, comptime T: type) anyerror!T {
356334
357335pub fn readStructBig(self: Self, comptime T: type) anyerror!T {
358336 var res = try self.readStruct(T);
359 if (native_endian != std.builtin.Endian.Big) {
337 if (native_endian != std.builtin.Endian.big) {
360338 mem.byteSwapAllFields(T, &res);
361339 }
362340 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)
6363 const n = if (self.bit_count >= bits) @as(u3, @intCast(bits)) else self.bit_count;
6464 const shift = u7_bit_count - n;
6565 switch (endian) {
66 .Big => {
66 .big => {
6767 out_buffer = @as(Buf, self.bit_buffer >> shift);
6868 if (n >= u7_bit_count)
6969 self.bit_buffer = 0
7070 else
7171 self.bit_buffer <<= n;
7272 },
73 .Little => {
73 .little => {
7474 const value = (self.bit_buffer << shift) >> shift;
7575 out_buffer = @as(Buf, value);
7676 if (n >= u7_bit_count)
......@@ -93,7 +93,7 @@ pub fn BitReader(comptime endian: std.builtin.Endian, comptime ReaderType: type)
9393 };
9494
9595 switch (endian) {
96 .Big => {
96 .big => {
9797 if (n >= u8_bit_count) {
9898 out_buffer <<= @as(u3, @intCast(u8_bit_count - 1));
9999 out_buffer <<= 1;
......@@ -109,7 +109,7 @@ pub fn BitReader(comptime endian: std.builtin.Endian, comptime ReaderType: type)
109109 self.bit_buffer = @as(u7, @truncate(next_byte << @as(u3, @intCast(n - 1))));
110110 self.bit_count = shift;
111111 },
112 .Little => {
112 .little => {
113113 if (n >= u8_bit_count) {
114114 out_buffer |= @as(Buf, next_byte) << @as(BufShift, @intCast(out_bits.*));
115115 out_bits.* += u8_bit_count;
......@@ -168,7 +168,7 @@ test "api coverage" {
168168 const mem_le = [_]u8{ 0b00011101, 0b10010101 };
169169
170170 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());
172172
173173 var out_bits: usize = undefined;
174174
......@@ -205,7 +205,7 @@ test "api coverage" {
205205 try expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1));
206206
207207 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());
209209
210210 try expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits));
211211 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)
5151
5252 const high_byte_shift = @as(BufShift, @intCast(buf_bit_count - u8_bit_count));
5353 var in_buffer = switch (endian) {
54 .Big => buf_value << @as(BufShift, @intCast(buf_bit_count - bits)),
55 .Little => buf_value,
54 .big => buf_value << @as(BufShift, @intCast(buf_bit_count - bits)),
55 .little => buf_value,
5656 };
5757 var in_bits = bits;
5858
......@@ -60,13 +60,13 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type)
6060 const bits_remaining = u8_bit_count - self.bit_count;
6161 const n = @as(u3, @intCast(if (bits_remaining > bits) bits else bits_remaining));
6262 switch (endian) {
63 .Big => {
63 .big => {
6464 const shift = @as(BufShift, @intCast(high_byte_shift + self.bit_count));
6565 const v = @as(u8, @intCast(in_buffer >> shift));
6666 self.bit_buffer |= v;
6767 in_buffer <<= n;
6868 },
69 .Little => {
69 .little => {
7070 const v = @as(u8, @truncate(in_buffer)) << @as(u3, @intCast(self.bit_count));
7171 self.bit_buffer |= v;
7272 in_buffer >>= n;
......@@ -86,13 +86,13 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type)
8686 //copy bytes until we can't fill one anymore, then leave the rest in bit_buffer
8787 while (in_bits >= u8_bit_count) {
8888 switch (endian) {
89 .Big => {
89 .big => {
9090 const v = @as(u8, @intCast(in_buffer >> high_byte_shift));
9191 try self.forward_writer.writeByte(v);
9292 in_buffer <<= @as(u3, @intCast(u8_bit_count - 1));
9393 in_buffer <<= 1;
9494 },
95 .Little => {
95 .little => {
9696 const v = @as(u8, @truncate(in_buffer));
9797 try self.forward_writer.writeByte(v);
9898 in_buffer >>= @as(u3, @intCast(u8_bit_count - 1));
......@@ -105,8 +105,8 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type)
105105 if (in_bits > 0) {
106106 self.bit_count = @as(u4, @intCast(in_bits));
107107 self.bit_buffer = switch (endian) {
108 .Big => @as(u8, @truncate(in_buffer >> high_byte_shift)),
109 .Little => @as(u8, @truncate(in_buffer)),
108 .big => @as(u8, @truncate(in_buffer >> high_byte_shift)),
109 .little => @as(u8, @truncate(in_buffer)),
110110 };
111111 }
112112 }
......@@ -148,7 +148,7 @@ test "api coverage" {
148148 var mem_le = [_]u8{0} ** 2;
149149
150150 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());
152152
153153 try bit_stream_be.writeBits(@as(u2, 1), 1);
154154 try bit_stream_be.writeBits(@as(u5, 2), 2);
......@@ -172,7 +172,7 @@ test "api coverage" {
172172 try bit_stream_be.writeBits(@as(u0, 0), 0);
173173
174174 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());
176176
177177 try bit_stream_le.writeBits(@as(u2, 1), 1);
178178 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" {
183183 var fbs = std.io.fixedBufferStream("");
184184 try std.testing.expectError(
185185 error.EndOfStream,
186 fbs.reader().readEnum(enum(u8) { a, b }, .Little),
186 fbs.reader().readEnum(enum(u8) { a, b }, .little),
187187 );
188188 try std.testing.expectError(
189189 error.EndOfStream,
lib/std/io/writer.zig+2-28
......@@ -45,34 +45,8 @@ pub fn Writer(
4545 }
4646 }
4747
48 /// Write a native-endian integer.
49 pub fn writeIntNative(self: Self, comptime T: type, value: T) Error!void {
50 var bytes: [@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8))]u8 = undefined;
51 mem.writeIntNative(std.math.ByteAlignedInt(@TypeOf(value)), &bytes, value);
52 return self.writeAll(&bytes);
53 }
54
55 /// Write a foreign-endian integer.
56 pub fn writeIntForeign(self: Self, comptime T: type, value: T) Error!void {
57 var bytes: [@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8))]u8 = undefined;
58 mem.writeIntForeign(std.math.ByteAlignedInt(@TypeOf(value)), &bytes, value);
59 return self.writeAll(&bytes);
60 }
61
62 pub fn writeIntLittle(self: Self, comptime T: type, value: T) Error!void {
63 var bytes: [@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8))]u8 = undefined;
64 mem.writeIntLittle(std.math.ByteAlignedInt(@TypeOf(value)), &bytes, value);
65 return self.writeAll(&bytes);
66 }
67
68 pub fn writeIntBig(self: Self, comptime T: type, value: T) Error!void {
69 var bytes: [@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8))]u8 = undefined;
70 mem.writeIntBig(std.math.ByteAlignedInt(@TypeOf(value)), &bytes, value);
71 return self.writeAll(&bytes);
72 }
73
74 pub fn writeInt(self: Self, comptime T: type, value: T, endian: std.builtin.Endian) Error!void {
75 var bytes: [@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8))]u8 = undefined;
48 pub inline fn writeInt(self: Self, comptime T: type, value: T, endian: std.builtin.Endian) Error!void {
49 var bytes: [@divExact(@typeInfo(T).Int.bits, 8)]u8 = undefined;
7650 mem.writeInt(std.math.ByteAlignedInt(@TypeOf(value)), &bytes, value, endian);
7751 return self.writeAll(&bytes);
7852 }
lib/std/math/big/int.zig+9-9
......@@ -798,7 +798,7 @@ pub const Mutable = struct {
798798 const endian_mask: usize = (@sizeOf(Limb) - 1) << 3;
799799
800800 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));
802802
803803 var k: usize = 0;
804804 while (k < ((bit_count + 1) / 2)) : (k += 1) {
......@@ -807,7 +807,7 @@ pub const Mutable = struct {
807807
808808 // This "endian mask" remaps a low (LE) byte to the corresponding high
809809 // (BE) byte in the Limb, without changing which limbs we are indexing
810 if (native_endian == .Big) {
810 if (native_endian == .big) {
811811 i ^= endian_mask;
812812 rev_i ^= endian_mask;
813813 }
......@@ -821,8 +821,8 @@ pub const Mutable = struct {
821821 // Calculate signed-magnitude representation for output
822822 if (signedness == .signed) {
823823 const last_bit = switch (native_endian) {
824 .Little => bits.get(bit_count - 1),
825 .Big => bits.get((bit_count - 1) ^ endian_mask),
824 .little => bits.get(bit_count - 1),
825 .big => bits.get((bit_count - 1) ^ endian_mask),
826826 };
827827 if (last_bit == 1) {
828828 r.bitNotWrap(r.toConst(), .unsigned, bit_count); // Bitwise NOT.
......@@ -869,7 +869,7 @@ pub const Mutable = struct {
869869
870870 // This "endian mask" remaps a low (LE) byte to the corresponding high
871871 // (BE) byte in the Limb, without changing which limbs we are indexing
872 if (native_endian == .Big) {
872 if (native_endian == .big) {
873873 i ^= endian_mask;
874874 rev_i ^= endian_mask;
875875 }
......@@ -883,8 +883,8 @@ pub const Mutable = struct {
883883 // Calculate signed-magnitude representation for output
884884 if (signedness == .signed) {
885885 const last_byte = switch (native_endian) {
886 .Little => bytes[byte_count - 1],
887 .Big => bytes[(byte_count - 1) ^ endian_mask],
886 .little => bytes[byte_count - 1],
887 .big => bytes[(byte_count - 1) ^ endian_mask],
888888 };
889889
890890 if (last_byte & (1 << 7) != 0) { // Check sign bit of last byte
......@@ -1912,8 +1912,8 @@ pub const Mutable = struct {
19121912 if (signedness == .signed) {
19131913 const total_bits = bit_offset + bit_count;
19141914 var last_byte = switch (endian) {
1915 .Little => ((total_bits + 7) / 8) - 1,
1916 .Big => buffer.len - ((total_bits + 7) / 8),
1915 .little => ((total_bits + 7) / 8) - 1,
1916 .big => buffer.len - ((total_bits + 7) / 8),
19171917 };
19181918
19191919 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" {
27742774 var buffer1 = try testing.allocator.alloc(u8, 64);
27752775 defer testing.allocator.free(buffer1);
27762776
2777 const endians = [_]std.builtin.Endian{ .Little, .Big };
2777 const endians = [_]std.builtin.Endian{ .little, .big };
27782778 const abi_size = 64;
27792779
27802780 for (endians) |endian| {
......@@ -2804,26 +2804,26 @@ test "big int conversion read twos complement with padding" {
28042804 // (3) should sign-extend any bits from bit_count to 8 * abi_size
28052805
28062806 var bit_count: usize = 12 * 8 + 1;
2807 a.toConst().writeTwosComplement(buffer1[0..13], .Little);
2807 a.toConst().writeTwosComplement(buffer1[0..13], .little);
28082808 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);
28102810 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);
28122812 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);
28142814 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 }));
28152815
28162816 @memset(buffer1, 0xaa);
28172817 try a.set(-0x01_02030405_06070809_0a0b0c0d);
28182818 bit_count = 12 * 8 + 2;
28192819
2820 a.toConst().writeTwosComplement(buffer1[0..13], .Little);
2820 a.toConst().writeTwosComplement(buffer1[0..13], .little);
28212821 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);
28232823 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);
28252825 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);
28272827 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 }));
28282828}
28292829
......@@ -2838,13 +2838,13 @@ test "big int write twos complement +/- zero" {
28382838
28392839 // Test zero
28402840
2841 m.toConst().writeTwosComplement(buffer1[0..13], .Little);
2841 m.toConst().writeTwosComplement(buffer1[0..13], .little);
28422842 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);
28442844 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);
28462846 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);
28482848 try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 16))));
28492849
28502850 @memset(buffer1, 0xaa);
......@@ -2852,13 +2852,13 @@ test "big int write twos complement +/- zero" {
28522852
28532853 // Test negative zero
28542854
2855 m.toConst().writeTwosComplement(buffer1[0..13], .Little);
2855 m.toConst().writeTwosComplement(buffer1[0..13], .little);
28562856 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);
28582858 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);
28602860 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);
28622862 try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 16))));
28632863}
28642864
......@@ -2881,19 +2881,19 @@ test "big int conversion write twos complement with padding" {
28812881 // Test 0x01_02030405_06070809_0a0b0c0d
28822882
28832883 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);
28852885 try testing.expect(m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d) == .eq);
28862886
28872887 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);
28892889 try testing.expect(m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d) == .eq);
28902890
28912891 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);
28932893 try testing.expect(m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d) == .eq);
28942894
28952895 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);
28972897 try testing.expect(m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d) == .eq);
28982898
28992899 bit_count = @sizeOf(Limb) * 8;
......@@ -2901,19 +2901,19 @@ test "big int conversion write twos complement with padding" {
29012901 // Test 0x0a0a0a0a_02030405_06070809_0a0b0c0d
29022902
29032903 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);
29052905 try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaa_02030405_06070809_0a0b0c0d))) == .eq);
29062906
29072907 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);
29092909 try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaa_02030405_06070809_0a0b0c0d))) == .eq);
29102910
29112911 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);
29132913 try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaaaaaaaa_02030405_06070809_0a0b0c0d))) == .eq);
29142914
29152915 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);
29172917 try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaaaaaaaa_02030405_06070809_0a0b0c0d))) == .eq);
29182918
29192919 bit_count = 12 * 8 + 2;
......@@ -2921,42 +2921,42 @@ test "big int conversion write twos complement with padding" {
29212921 // Test -0x01_02030405_06070809_0a0b0c0d
29222922
29232923 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);
29252925 try testing.expect(m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d) == .eq);
29262926
29272927 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);
29292929 try testing.expect(m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d) == .eq);
29302930
29312931 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);
29332933 try testing.expect(m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d) == .eq);
29342934
29352935 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);
29372937 try testing.expect(m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d) == .eq);
29382938
29392939 // Test 0
29402940
29412941 buffer = &([_]u8{0} ** 16);
2942 m.readTwosComplement(buffer[0..13], bit_count, .Little, .unsigned);
2942 m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned);
29432943 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);
29452945 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);
29472947 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);
29492949 try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq);
29502950
29512951 bit_count = 0;
29522952 buffer = &([_]u8{0xaa} ** 16);
2953 m.readTwosComplement(buffer[0..13], bit_count, .Little, .unsigned);
2953 m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned);
29542954 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);
29562956 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);
29582958 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);
29602960 try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq);
29612961}
29622962
......@@ -2975,15 +2975,15 @@ test "big int conversion write twos complement zero" {
29752975 var buffer: []const u8 = undefined;
29762976
29772977 buffer = &([_]u8{0} ** 13);
2978 m.readTwosComplement(buffer[0..13], bit_count, .Little, .unsigned);
2978 m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned);
29792979 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);
29812981 try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq);
29822982
29832983 buffer = &([_]u8{0} ** 16);
2984 m.readTwosComplement(buffer[0..16], bit_count, .Little, .unsigned);
2984 m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned);
29852985 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);
29872987 try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq);
29882988}
29892989
lib/std/mem.zig+126-456
......@@ -1499,12 +1499,12 @@ test "containsAtLeast" {
14991499pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: Endian) ReturnType {
15001500 var result: ReturnType = 0;
15011501 switch (endian) {
1502 .Big => {
1502 .big => {
15031503 for (bytes) |b| {
15041504 result = (result << 8) | b;
15051505 }
15061506 },
1507 .Little => {
1507 .little => {
15081508 const ShiftType = math.Log2Int(ReturnType);
15091509 for (bytes, 0..) |b, index| {
15101510 result = result | (@as(ReturnType, b) << @as(ShiftType, @intCast(index * 8)));
......@@ -1539,8 +1539,8 @@ pub fn readVarPackedInt(
15391539 const pad = @as(Log2N, @intCast(@bitSizeOf(T) - bit_count));
15401540
15411541 const lowest_byte = switch (endian) {
1542 .Big => bytes.len - (bit_offset / 8) - read_size,
1543 .Little => bit_offset / 8,
1542 .big => bytes.len - (bit_offset / 8) - read_size,
1543 .little => bit_offset / 8,
15441544 };
15451545 const read_bytes = bytes[lowest_byte..][0..read_size];
15461546
......@@ -1550,7 +1550,7 @@ pub fn readVarPackedInt(
15501550 const value = if (read_size == 1) b: {
15511551 break :b @as(uN, @truncate(read_bytes[0] >> bit_shift));
15521552 } else b: {
1553 const i: u1 = @intFromBool(endian == .Big);
1553 const i: u1 = @intFromBool(endian == .big);
15541554 const head = @as(uN, @truncate(read_bytes[i] >> bit_shift));
15551555 const tail_shift = @as(Log2N, @intCast(@as(u4, 8) - bit_shift));
15561556 const tail = @as(uN, @truncate(read_bytes[1 - i]));
......@@ -1565,13 +1565,13 @@ pub fn readVarPackedInt(
15651565 // Copy the value out (respecting endianness), accounting for bit_shift
15661566 var int: uN = 0;
15671567 switch (endian) {
1568 .Big => {
1568 .big => {
15691569 for (read_bytes[0 .. read_size - 1]) |elem| {
15701570 int = elem | (int << 8);
15711571 }
15721572 int = (read_bytes[read_size - 1] >> bit_shift) | (int << (@as(u4, 8) - bit_shift));
15731573 },
1574 .Little => {
1574 .little => {
15751575 int = read_bytes[0] >> bit_shift;
15761576 for (read_bytes[1..], 0..) |elem, i| {
15771577 int |= (@as(uN, elem) << @as(Log2N, @intCast((8 * (i + 1) - bit_shift))));
......@@ -1587,68 +1587,29 @@ pub fn readVarPackedInt(
15871587/// Reads an integer from memory with bit count specified by T.
15881588/// The bit count of T must be evenly divisible by 8.
15891589/// This function cannot fail and cannot cause undefined behavior.
1590/// Assumes the endianness of memory is native. This means the function can
1591/// simply pointer cast memory.
1592pub fn readIntNative(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8) T {
1593 return @as(*align(1) const T, @ptrCast(bytes)).*;
1590pub inline fn readInt(comptime T: type, buffer: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8, endian: Endian) T {
1591 const value: T = @bitCast(buffer.*);
1592 return if (endian == native_endian) value else @byteSwap(value);
15941593}
15951594
1596/// Reads an integer from memory with bit count specified by T.
1597/// The bit count of T must be evenly divisible by 8.
1598/// This function cannot fail and cannot cause undefined behavior.
1599/// Assumes the endianness of memory is foreign, so it must byte-swap.
1600pub fn readIntForeign(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8) T {
1601 return @byteSwap(readIntNative(T, bytes));
1602}
1595test readInt {
1596 try testing.expect(readInt(u0, &[_]u8{}, .big) == 0x0);
1597 try testing.expect(readInt(u0, &[_]u8{}, .little) == 0x0);
16031598
1604pub const readIntLittle = switch (native_endian) {
1605 .Little => readIntNative,
1606 .Big => readIntForeign,
1607};
1608
1609pub const readIntBig = switch (native_endian) {
1610 .Little => readIntForeign,
1611 .Big => readIntNative,
1612};
1613
1614/// Asserts that bytes.len >= @typeInfo(T).Int.bits / 8. Reads the integer starting from index 0
1615/// and ignores extra bytes.
1616/// The bit count of T must be evenly divisible by 8.
1617/// Assumes the endianness of memory is native. This means the function can
1618/// simply pointer cast memory.
1619pub fn readIntSliceNative(comptime T: type, bytes: []const u8) T {
1620 const n = @divExact(@typeInfo(T).Int.bits, 8);
1621 assert(bytes.len >= n);
1622 return readIntNative(T, bytes[0..n]);
1623}
1599 try testing.expect(readInt(u8, &[_]u8{0x32}, .big) == 0x32);
1600 try testing.expect(readInt(u8, &[_]u8{0x12}, .little) == 0x12);
16241601
1625/// Asserts that bytes.len >= @typeInfo(T).Int.bits / 8. Reads the integer starting from index 0
1626/// and ignores extra bytes.
1627/// The bit count of T must be evenly divisible by 8.
1628/// Assumes the endianness of memory is foreign, so it must byte-swap.
1629pub fn readIntSliceForeign(comptime T: type, bytes: []const u8) T {
1630 return @byteSwap(readIntSliceNative(T, bytes));
1631}
1602 try testing.expect(readInt(u16, &[_]u8{ 0x12, 0x34 }, .big) == 0x1234);
1603 try testing.expect(readInt(u16, &[_]u8{ 0x12, 0x34 }, .little) == 0x3412);
16321604
1633pub const readIntSliceLittle = switch (native_endian) {
1634 .Little => readIntSliceNative,
1635 .Big => readIntSliceForeign,
1636};
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);
16371607
1638pub const readIntSliceBig = switch (native_endian) {
1639 .Little => readIntSliceForeign,
1640 .Big => readIntSliceNative,
1641};
1608 try testing.expect(readInt(i8, &[_]u8{0xff}, .big) == -1);
1609 try testing.expect(readInt(i8, &[_]u8{0xfe}, .little) == -2);
16421610
1643/// Reads an integer from memory with bit count specified by T.
1644/// The bit count of T must be evenly divisible by 8.
1645/// This function cannot fail and cannot cause undefined behavior.
1646pub fn readInt(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8, endian: Endian) T {
1647 if (endian == native_endian) {
1648 return readIntNative(T, bytes);
1649 } else {
1650 return readIntForeign(T, bytes);
1651 }
1611 try testing.expect(readInt(i16, &[_]u8{ 0xff, 0xfd }, .big) == -3);
1612 try testing.expect(readInt(i16, &[_]u8{ 0xfc, 0xff }, .little) == -4);
16521613}
16531614
16541615fn readPackedIntLittle(comptime T: type, bytes: []const u8, bit_offset: usize) T {
......@@ -1668,7 +1629,7 @@ fn readPackedIntLittle(comptime T: type, bytes: []const u8, bit_offset: usize) T
16681629 // Read by loading a LoadInt, and then follow it up with a 1-byte read
16691630 // of the tail if bit_offset pushed us over a byte boundary.
16701631 const read_bytes = bytes[bit_offset / 8 ..];
1671 const val = @as(uN, @truncate(readIntLittle(LoadInt, read_bytes[0..load_size]) >> bit_shift));
1632 const val = @as(uN, @truncate(readInt(LoadInt, read_bytes[0..load_size], .little) >> bit_shift));
16721633 if (bit_shift > load_tail_bits) {
16731634 const tail_bits = @as(Log2N, @intCast(bit_shift - load_tail_bits));
16741635 const tail_byte = read_bytes[load_size];
......@@ -1696,7 +1657,7 @@ fn readPackedIntBig(comptime T: type, bytes: []const u8, bit_offset: usize) T {
16961657 // of the tail if bit_offset pushed us over a byte boundary.
16971658 const end = bytes.len - (bit_offset / 8);
16981659 const read_bytes = bytes[(end - byte_count)..end];
1699 const val = @as(uN, @truncate(readIntBig(LoadInt, bytes[(end - load_size)..end][0..load_size]) >> bit_shift));
1660 const val = @as(uN, @truncate(readInt(LoadInt, bytes[(end - load_size)..end][0..load_size], .big) >> bit_shift));
17001661 if (bit_shift > load_tail_bits) {
17011662 const tail_bits = @as(Log2N, @intCast(bit_shift - load_tail_bits));
17021663 const tail_byte = if (bit_count < 8) @as(uN, @truncate(read_bytes[0])) else @as(uN, read_bytes[0]);
......@@ -1705,13 +1666,13 @@ fn readPackedIntBig(comptime T: type, bytes: []const u8, bit_offset: usize) T {
17051666}
17061667
17071668pub const readPackedIntNative = switch (native_endian) {
1708 .Little => readPackedIntLittle,
1709 .Big => readPackedIntBig,
1669 .little => readPackedIntLittle,
1670 .big => readPackedIntBig,
17101671};
17111672
17121673pub const readPackedIntForeign = switch (native_endian) {
1713 .Little => readPackedIntBig,
1714 .Big => readPackedIntLittle,
1674 .little => readPackedIntBig,
1675 .big => readPackedIntLittle,
17151676};
17161677
17171678/// Loads an integer from packed memory.
......@@ -1724,94 +1685,68 @@ pub const readPackedIntForeign = switch (native_endian) {
17241685///
17251686pub fn readPackedInt(comptime T: type, bytes: []const u8, bit_offset: usize, endian: Endian) T {
17261687 switch (endian) {
1727 .Little => return readPackedIntLittle(T, bytes, bit_offset),
1728 .Big => return readPackedIntBig(T, bytes, bit_offset),
1688 .little => return readPackedIntLittle(T, bytes, bit_offset),
1689 .big => return readPackedIntBig(T, bytes, bit_offset),
17291690 }
17301691}
17311692
1732/// Asserts that bytes.len >= @typeInfo(T).Int.bits / 8. Reads the integer starting from index 0
1733/// and ignores extra bytes.
1734/// The bit count of T must be evenly divisible by 8.
1735pub fn readIntSlice(comptime T: type, bytes: []const u8, endian: Endian) T {
1736 const n = @divExact(@typeInfo(T).Int.bits, 8);
1737 assert(bytes.len >= n);
1738 return readInt(T, bytes[0..n], endian);
1739}
1740
17411693test "comptime read/write int" {
17421694 comptime {
17431695 var bytes: [2]u8 = undefined;
1744 writeIntLittle(u16, &bytes, 0x1234);
1745 const result = readIntBig(u16, &bytes);
1696 writeInt(u16, &bytes, 0x1234, .little);
1697 const result = readInt(u16, &bytes, .big);
17461698 try testing.expect(result == 0x3412);
17471699 }
17481700 comptime {
17491701 var bytes: [2]u8 = undefined;
1750 writeIntBig(u16, &bytes, 0x1234);
1751 const result = readIntLittle(u16, &bytes);
1702 writeInt(u16, &bytes, 0x1234, .big);
1703 const result = readInt(u16, &bytes, .little);
17521704 try testing.expect(result == 0x3412);
17531705 }
17541706}
17551707
1756test "readIntBig and readIntLittle" {
1757 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
1758 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
1759
1760 try testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0);
1761 try testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0);
1762
1763 try testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32);
1764 try testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12);
1765
1766 try testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234);
1767 try testing.expect(readIntSliceLittle(u16, &[_]u8{ 0x12, 0x34 }) == 0x3412);
1768
1769 try testing.expect(readIntSliceBig(u72, &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
1770 try testing.expect(readIntSliceLittle(u72, &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
1771
1772 try testing.expect(readIntSliceBig(i8, &[_]u8{0xff}) == -1);
1773 try testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2);
1774
1775 try testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3);
1776 try testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4);
1777}
1778
1779/// Writes an integer to memory, storing it in twos-complement.
1780/// This function always succeeds, has defined behavior for all inputs, and
1781/// accepts any integer bit width.
1782/// This function stores in native endian, which means it is implemented as a simple
1783/// memory store.
1784pub fn writeIntNative(comptime T: type, buf: *[@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8))]u8, value: T) void {
1785 @as(*align(1) T, @ptrCast(buf)).* = value;
1786}
1787
17881708/// Writes an integer to memory, storing it in twos-complement.
17891709/// This function always succeeds, has defined behavior for all inputs, but
17901710/// the integer bit width must be divisible by 8.
1791/// This function stores in foreign endian, which means it does a @byteSwap first.
1792pub fn writeIntForeign(comptime T: type, buf: *[@divExact(@typeInfo(T).Int.bits, 8)]u8, value: T) void {
1793 writeIntNative(T, buf, @byteSwap(value));
1711pub inline fn writeInt(comptime T: type, buffer: *[@divExact(@typeInfo(T).Int.bits, 8)]u8, value: T, endian: Endian) void {
1712 buffer.* = @bitCast(if (endian == native_endian) value else @byteSwap(value));
17941713}
17951714
1796pub const writeIntLittle = switch (native_endian) {
1797 .Little => writeIntNative,
1798 .Big => writeIntForeign,
1799};
1715test writeInt {
1716 var buf0: [0]u8 = undefined;
1717 var buf1: [1]u8 = undefined;
1718 var buf2: [2]u8 = undefined;
1719 var buf9: [9]u8 = undefined;
18001720
1801pub const writeIntBig = switch (native_endian) {
1802 .Little => writeIntForeign,
1803 .Big => writeIntNative,
1804};
1721 writeInt(u0, &buf0, 0x0, .big);
1722 try testing.expect(eql(u8, buf0[0..], &[_]u8{}));
1723 writeInt(u0, &buf0, 0x0, .little);
1724 try testing.expect(eql(u8, buf0[0..], &[_]u8{}));
18051725
1806/// Writes an integer to memory, storing it in twos-complement.
1807/// This function always succeeds, has defined behavior for all inputs, but
1808/// the integer bit width must be divisible by 8.
1809pub fn writeInt(comptime T: type, buffer: *[@divExact(@typeInfo(T).Int.bits, 8)]u8, value: T, endian: Endian) void {
1810 if (endian == native_endian) {
1811 return writeIntNative(T, buffer, value);
1812 } else {
1813 return writeIntForeign(T, buffer, value);
1814 }
1726 writeInt(u8, &buf1, 0x12, .big);
1727 try testing.expect(eql(u8, buf1[0..], &[_]u8{0x12}));
1728 writeInt(u8, &buf1, 0x34, .little);
1729 try testing.expect(eql(u8, buf1[0..], &[_]u8{0x34}));
1730
1731 writeInt(u16, &buf2, 0x1234, .big);
1732 try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 }));
1733 writeInt(u16, &buf2, 0x5678, .little);
1734 try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x78, 0x56 }));
1735
1736 writeInt(u72, &buf9, 0x123456789abcdef024, .big);
1737 try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
1738 writeInt(u72, &buf9, 0xfedcba9876543210ec, .little);
1739 try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
1740
1741 writeInt(i8, &buf1, -1, .big);
1742 try testing.expect(eql(u8, buf1[0..], &[_]u8{0xff}));
1743 writeInt(i8, &buf1, -2, .little);
1744 try testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe}));
1745
1746 writeInt(i16, &buf2, -3, .big);
1747 try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd }));
1748 writeInt(i16, &buf2, -4, .little);
1749 try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff }));
18151750}
18161751
18171752fn writePackedIntLittle(comptime T: type, bytes: []u8, bit_offset: usize, value: T) void {
......@@ -1844,7 +1779,7 @@ fn writePackedIntLittle(comptime T: type, bytes: []u8, bit_offset: usize, value:
18441779 write_value |= @as(StoreInt, tail) << (8 * (store_size - 1));
18451780 }
18461781
1847 writeIntLittle(StoreInt, write_bytes[0..store_size], write_value);
1782 writeInt(StoreInt, write_bytes[0..store_size], write_value, .little);
18481783}
18491784
18501785fn writePackedIntBig(comptime T: type, bytes: []u8, bit_offset: usize, value: T) void {
......@@ -1879,17 +1814,17 @@ fn writePackedIntBig(comptime T: type, bytes: []u8, bit_offset: usize, value: T)
18791814 write_value |= @as(StoreInt, tail) << (8 * (store_size - 1));
18801815 }
18811816
1882 writeIntBig(StoreInt, write_bytes[(byte_count - store_size)..][0..store_size], write_value);
1817 writeInt(StoreInt, write_bytes[(byte_count - store_size)..][0..store_size], write_value, .big);
18831818}
18841819
18851820pub const writePackedIntNative = switch (native_endian) {
1886 .Little => writePackedIntLittle,
1887 .Big => writePackedIntBig,
1821 .little => writePackedIntLittle,
1822 .big => writePackedIntBig,
18881823};
18891824
18901825pub const writePackedIntForeign = switch (native_endian) {
1891 .Little => writePackedIntBig,
1892 .Big => writePackedIntLittle,
1826 .little => writePackedIntBig,
1827 .big => writePackedIntLittle,
18931828};
18941829
18951830/// Stores an integer to packed memory.
......@@ -1903,94 +1838,9 @@ pub const writePackedIntForeign = switch (native_endian) {
19031838///
19041839pub fn writePackedInt(comptime T: type, bytes: []u8, bit_offset: usize, value: T, endian: Endian) void {
19051840 switch (endian) {
1906 .Little => writePackedIntLittle(T, bytes, bit_offset, value),
1907 .Big => writePackedIntBig(T, bytes, bit_offset, value),
1908 }
1909}
1910
1911/// Writes a twos-complement little-endian integer to memory.
1912/// Asserts that buf.len >= @typeInfo(T).Int.bits / 8.
1913/// The bit count of T must be divisible by 8.
1914/// Any extra bytes in buffer after writing the integer are set to zero. To
1915/// avoid the branch to check for extra buffer bytes, use writeIntLittle
1916/// instead.
1917fn writeIntSliceLittleNative(comptime T: type, buffer: []u8, value: T) void {
1918 assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));
1919
1920 if (@typeInfo(T).Int.bits == 0) {
1921 return @memset(buffer, 0);
1922 } else if (@typeInfo(T).Int.bits == 8) {
1923 @memset(buffer, 0);
1924 buffer[0] = @as(u8, @bitCast(value));
1925 return;
1926 }
1927
1928 const write_end = @divExact(@typeInfo(T).Int.bits, 8);
1929 @as(*align(1) T, @ptrCast(buffer)).* = value;
1930 @memset(buffer[write_end..], 0);
1931}
1932
1933fn writeIntSliceLittleForeign(comptime T: type, buffer: []u8, value: T) void {
1934 return writeIntSliceLittleNative(T, buffer, @byteSwap(value));
1935}
1936
1937pub const writeIntSliceLittle = switch (native_endian) {
1938 .Little => writeIntSliceLittleNative,
1939 .Big => writeIntSliceLittleForeign,
1940};
1941
1942/// Writes a twos-complement big-endian integer to memory.
1943/// Asserts that buffer.len >= @typeInfo(T).Int.bits / 8.
1944/// The bit count of T must be divisible by 8.
1945/// Any extra bytes in buffer before writing the integer are set to zero. To
1946/// avoid the branch to check for extra buffer bytes, use writeIntBig instead.
1947fn writeIntSliceBigNative(comptime T: type, buffer: []u8, value: T) void {
1948 assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));
1949
1950 if (@typeInfo(T).Int.bits == 0) {
1951 return @memset(buffer, 0);
1952 } else if (@typeInfo(T).Int.bits == 8) {
1953 @memset(buffer, 0);
1954 buffer[buffer.len - 1] = @as(u8, @bitCast(value));
1955 return;
1841 .little => writePackedIntLittle(T, bytes, bit_offset, value),
1842 .big => writePackedIntBig(T, bytes, bit_offset, value),
19561843 }
1957
1958 const write_start = buffer.len - @divExact(@typeInfo(T).Int.bits, 8);
1959 @memset(buffer[0..write_start], 0);
1960 @as(*align(1) T, @ptrCast(buffer[write_start..])).* = value;
1961}
1962
1963fn writeIntSliceBigForeign(comptime T: type, buffer: []u8, value: T) void {
1964 return writeIntSliceBigNative(T, buffer, @byteSwap(value));
1965}
1966
1967pub const writeIntSliceBig = switch (native_endian) {
1968 .Little => writeIntSliceBigForeign,
1969 .Big => writeIntSliceBigNative,
1970};
1971
1972pub const writeIntSliceNative = switch (native_endian) {
1973 .Little => writeIntSliceLittleNative,
1974 .Big => writeIntSliceBigNative,
1975};
1976
1977pub const writeIntSliceForeign = switch (native_endian) {
1978 .Little => writeIntSliceBigForeign,
1979 .Big => writeIntSliceLittleForeign,
1980};
1981
1982/// Writes a twos-complement integer to memory, with the specified endianness.
1983/// Asserts that buf.len >= @typeInfo(T).Int.bits / 8.
1984/// The bit count of T must be evenly divisible by 8.
1985/// Any extra bytes in buffer not part of the integer are set to zero, with
1986/// respect to endianness. To avoid the branch to check for extra buffer bytes,
1987/// use writeInt instead.
1988pub fn writeIntSlice(comptime T: type, buffer: []u8, value: T, endian: Endian) void {
1989 comptime assert(@typeInfo(T).Int.bits % 8 == 0);
1990 return switch (endian) {
1991 .Little => writeIntSliceLittle(T, buffer, value),
1992 .Big => writeIntSliceBig(T, buffer, value),
1993 };
19941844}
19951845
19961846/// Stores an integer to packed memory with provided bit_count, bit_offset, and signedness.
......@@ -2010,8 +1860,8 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value
20101860 const bit_shift = @as(u3, @intCast(bit_offset % 8));
20111861 const write_size = (bit_count + bit_shift + 7) / 8;
20121862 const lowest_byte = switch (endian) {
2013 .Big => bytes.len - (bit_offset / 8) - write_size,
2014 .Little => bit_offset / 8,
1863 .big => bytes.len - (bit_offset / 8) - write_size,
1864 .little => bit_offset / 8,
20151865 };
20161866 const write_bytes = bytes[lowest_byte..][0..write_size];
20171867
......@@ -2027,8 +1877,8 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value
20271877 var remaining: T = value;
20281878
20291879 // Iterate bytes forward for Little-endian, backward for Big-endian
2030 const delta: i2 = if (endian == .Big) -1 else 1;
2031 const start = if (endian == .Big) @as(isize, @intCast(write_bytes.len - 1)) else 0;
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;
20321882
20331883 var i: isize = start; // isize for signed index arithmetic
20341884
......@@ -2055,45 +1905,6 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value
20551905 write_bytes[@as(usize, @intCast(i))] |= @as(u8, @intCast(@as(uN, @bitCast(remaining)) & tail_mask));
20561906}
20571907
2058test "writeIntBig and writeIntLittle" {
2059 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
2060
2061 var buf0: [0]u8 = undefined;
2062 var buf1: [1]u8 = undefined;
2063 var buf2: [2]u8 = undefined;
2064 var buf9: [9]u8 = undefined;
2065
2066 writeIntBig(u0, &buf0, 0x0);
2067 try testing.expect(eql(u8, buf0[0..], &[_]u8{}));
2068 writeIntLittle(u0, &buf0, 0x0);
2069 try testing.expect(eql(u8, buf0[0..], &[_]u8{}));
2070
2071 writeIntBig(u8, &buf1, 0x12);
2072 try testing.expect(eql(u8, buf1[0..], &[_]u8{0x12}));
2073 writeIntLittle(u8, &buf1, 0x34);
2074 try testing.expect(eql(u8, buf1[0..], &[_]u8{0x34}));
2075
2076 writeIntBig(u16, &buf2, 0x1234);
2077 try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 }));
2078 writeIntLittle(u16, &buf2, 0x5678);
2079 try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x78, 0x56 }));
2080
2081 writeIntBig(u72, &buf9, 0x123456789abcdef024);
2082 try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
2083 writeIntLittle(u72, &buf9, 0xfedcba9876543210ec);
2084 try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
2085
2086 writeIntBig(i8, &buf1, -1);
2087 try testing.expect(eql(u8, buf1[0..], &[_]u8{0xff}));
2088 writeIntLittle(i8, &buf1, -2);
2089 try testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe}));
2090
2091 writeIntBig(i16, &buf2, -3);
2092 try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd }));
2093 writeIntLittle(i16, &buf2, -4);
2094 try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff }));
2095}
2096
20971908/// Swap the byte order of all the members of the fields of a struct
20981909/// (Changing their endianness)
20991910pub fn byteSwapAllFields(comptime S: type, ptr: *S) void {
......@@ -3311,12 +3122,12 @@ fn testReadIntImpl() !void {
33113122 0x56,
33123123 0x78,
33133124 };
3314 try testing.expect(readInt(u32, &bytes, Endian.Big) == 0x12345678);
3315 try testing.expect(readIntBig(u32, &bytes) == 0x12345678);
3316 try testing.expect(readIntBig(i32, &bytes) == 0x12345678);
3317 try testing.expect(readInt(u32, &bytes, Endian.Little) == 0x78563412);
3318 try testing.expect(readIntLittle(u32, &bytes) == 0x78563412);
3319 try testing.expect(readIntLittle(i32, &bytes) == 0x78563412);
3125 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);
3128 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);
33203131 }
33213132 {
33223133 const buf = [_]u8{
......@@ -3325,7 +3136,7 @@ fn testReadIntImpl() !void {
33253136 0x12,
33263137 0x34,
33273138 };
3328 const answer = readInt(u32, &buf, Endian.Big);
3139 const answer = readInt(u32, &buf, .big);
33293140 try testing.expect(answer == 0x00001234);
33303141 }
33313142 {
......@@ -3335,7 +3146,7 @@ fn testReadIntImpl() !void {
33353146 0x00,
33363147 0x00,
33373148 };
3338 const answer = readInt(u32, &buf, Endian.Little);
3149 const answer = readInt(u32, &buf, .little);
33393150 try testing.expect(answer == 0x00003412);
33403151 }
33413152 {
......@@ -3343,153 +3154,13 @@ fn testReadIntImpl() !void {
33433154 0xff,
33443155 0xfe,
33453156 };
3346 try testing.expect(readIntBig(u16, &bytes) == 0xfffe);
3347 try testing.expect(readIntBig(i16, &bytes) == -0x0002);
3348 try testing.expect(readIntLittle(u16, &bytes) == 0xfeff);
3349 try testing.expect(readIntLittle(i16, &bytes) == -0x0101);
3157 try testing.expect(readInt(u16, &bytes, .big) == 0xfffe);
3158 try testing.expect(readInt(i16, &bytes, .big) == -0x0002);
3159 try testing.expect(readInt(u16, &bytes, .little) == 0xfeff);
3160 try testing.expect(readInt(i16, &bytes, .little) == -0x0101);
33503161 }
33513162}
33523163
3353test writeIntSlice {
3354 try testWriteIntImpl();
3355 try comptime testWriteIntImpl();
3356}
3357fn testWriteIntImpl() !void {
3358 var bytes: [8]u8 = undefined;
3359
3360 writeIntSlice(u0, bytes[0..], 0, Endian.Big);
3361 try testing.expect(eql(u8, &bytes, &[_]u8{
3362 0x00, 0x00, 0x00, 0x00,
3363 0x00, 0x00, 0x00, 0x00,
3364 }));
3365
3366 writeIntSlice(u0, bytes[0..], 0, Endian.Little);
3367 try testing.expect(eql(u8, &bytes, &[_]u8{
3368 0x00, 0x00, 0x00, 0x00,
3369 0x00, 0x00, 0x00, 0x00,
3370 }));
3371
3372 writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, Endian.Big);
3373 try testing.expect(eql(u8, &bytes, &[_]u8{
3374 0x12,
3375 0x34,
3376 0x56,
3377 0x78,
3378 0xCA,
3379 0xFE,
3380 0xBA,
3381 0xBE,
3382 }));
3383
3384 writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, Endian.Little);
3385 try testing.expect(eql(u8, &bytes, &[_]u8{
3386 0x12,
3387 0x34,
3388 0x56,
3389 0x78,
3390 0xCA,
3391 0xFE,
3392 0xBA,
3393 0xBE,
3394 }));
3395
3396 writeIntSlice(u32, bytes[0..], 0x12345678, Endian.Big);
3397 try testing.expect(eql(u8, &bytes, &[_]u8{
3398 0x00,
3399 0x00,
3400 0x00,
3401 0x00,
3402 0x12,
3403 0x34,
3404 0x56,
3405 0x78,
3406 }));
3407
3408 writeIntSlice(u32, bytes[0..], 0x78563412, Endian.Little);
3409 try testing.expect(eql(u8, &bytes, &[_]u8{
3410 0x12,
3411 0x34,
3412 0x56,
3413 0x78,
3414 0x00,
3415 0x00,
3416 0x00,
3417 0x00,
3418 }));
3419
3420 writeIntSlice(u16, bytes[0..], 0x1234, Endian.Big);
3421 try testing.expect(eql(u8, &bytes, &[_]u8{
3422 0x00,
3423 0x00,
3424 0x00,
3425 0x00,
3426 0x00,
3427 0x00,
3428 0x12,
3429 0x34,
3430 }));
3431
3432 writeIntSlice(u16, bytes[0..], 0x1234, Endian.Little);
3433 try testing.expect(eql(u8, &bytes, &[_]u8{
3434 0x34,
3435 0x12,
3436 0x00,
3437 0x00,
3438 0x00,
3439 0x00,
3440 0x00,
3441 0x00,
3442 }));
3443
3444 writeIntSlice(i16, bytes[0..], @as(i16, -21555), Endian.Little);
3445 try testing.expect(eql(u8, &bytes, &[_]u8{
3446 0xCD,
3447 0xAB,
3448 0x00,
3449 0x00,
3450 0x00,
3451 0x00,
3452 0x00,
3453 0x00,
3454 }));
3455
3456 writeIntSlice(i16, bytes[0..], @as(i16, -21555), Endian.Big);
3457 try testing.expect(eql(u8, &bytes, &[_]u8{
3458 0x00,
3459 0x00,
3460 0x00,
3461 0x00,
3462 0x00,
3463 0x00,
3464 0xAB,
3465 0xCD,
3466 }));
3467
3468 writeIntSlice(u8, bytes[0..], 0x12, Endian.Big);
3469 try testing.expect(eql(u8, &bytes, &[_]u8{
3470 0x00, 0x00, 0x00, 0x00,
3471 0x00, 0x00, 0x00, 0x12,
3472 }));
3473
3474 writeIntSlice(u8, bytes[0..], 0x12, Endian.Little);
3475 try testing.expect(eql(u8, &bytes, &[_]u8{
3476 0x12, 0x00, 0x00, 0x00,
3477 0x00, 0x00, 0x00, 0x00,
3478 }));
3479
3480 writeIntSlice(i8, bytes[0..], -1, Endian.Big);
3481 try testing.expect(eql(u8, &bytes, &[_]u8{
3482 0x00, 0x00, 0x00, 0x00,
3483 0x00, 0x00, 0x00, 0xff,
3484 }));
3485
3486 writeIntSlice(i8, bytes[0..], -1, Endian.Little);
3487 try testing.expect(eql(u8, &bytes, &[_]u8{
3488 0xff, 0x00, 0x00, 0x00,
3489 0x00, 0x00, 0x00, 0x00,
3490 }));
3491}
3492
34933164/// Returns the smallest number in a slice. O(n).
34943165/// `slice` must not be empty.
34953166pub fn min(comptime T: type, slice: []const T) T {
......@@ -3932,48 +3603,48 @@ test "replaceOwned" {
39323603/// Converts a little-endian integer to host endianness.
39333604pub fn littleToNative(comptime T: type, x: T) T {
39343605 return switch (native_endian) {
3935 .Little => x,
3936 .Big => @byteSwap(x),
3606 .little => x,
3607 .big => @byteSwap(x),
39373608 };
39383609}
39393610
39403611/// Converts a big-endian integer to host endianness.
39413612pub fn bigToNative(comptime T: type, x: T) T {
39423613 return switch (native_endian) {
3943 .Little => @byteSwap(x),
3944 .Big => x,
3614 .little => @byteSwap(x),
3615 .big => x,
39453616 };
39463617}
39473618
39483619/// Converts an integer from specified endianness to host endianness.
39493620pub fn toNative(comptime T: type, x: T, endianness_of_x: Endian) T {
39503621 return switch (endianness_of_x) {
3951 .Little => littleToNative(T, x),
3952 .Big => bigToNative(T, x),
3622 .little => littleToNative(T, x),
3623 .big => bigToNative(T, x),
39533624 };
39543625}
39553626
39563627/// Converts an integer which has host endianness to the desired endianness.
39573628pub fn nativeTo(comptime T: type, x: T, desired_endianness: Endian) T {
39583629 return switch (desired_endianness) {
3959 .Little => nativeToLittle(T, x),
3960 .Big => nativeToBig(T, x),
3630 .little => nativeToLittle(T, x),
3631 .big => nativeToBig(T, x),
39613632 };
39623633}
39633634
39643635/// Converts an integer which has host endianness to little endian.
39653636pub fn nativeToLittle(comptime T: type, x: T) T {
39663637 return switch (native_endian) {
3967 .Little => x,
3968 .Big => @byteSwap(x),
3638 .little => x,
3639 .big => @byteSwap(x),
39693640 };
39703641}
39713642
39723643/// Converts an integer which has host endianness to big endian.
39733644pub fn nativeToBig(comptime T: type, x: T) T {
39743645 return switch (native_endian) {
3975 .Little => @byteSwap(x),
3976 .Big => x,
3646 .little => @byteSwap(x),
3647 .big => x,
39773648 };
39783649}
39793650
......@@ -4077,8 +3748,8 @@ pub fn asBytes(ptr: anytype) AsBytesReturnType(@TypeOf(ptr)) {
40773748test "asBytes" {
40783749 const deadbeef = @as(u32, 0xDEADBEEF);
40793750 const deadbeef_bytes = switch (native_endian) {
4080 .Big => "\xDE\xAD\xBE\xEF",
4081 .Little => "\xEF\xBE\xAD\xDE",
3751 .big => "\xDE\xAD\xBE\xEF",
3752 .little => "\xEF\xBE\xAD\xDE",
40823753 };
40833754
40843755 try testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes));
......@@ -4102,10 +3773,10 @@ test "asBytes" {
41023773 .d = 0xA1,
41033774 };
41043775 switch (native_endian) {
4105 .Little => {
3776 .little => {
41063777 try testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1"));
41073778 },
4108 .Big => {
3779 .big => {
41093780 try testing.expect(eql(u8, asBytes(&inst), "\xA1\xDE\xEF\xBE"));
41103781 },
41113782 }
......@@ -4137,14 +3808,14 @@ pub fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8 {
41373808test "toBytes" {
41383809 var my_bytes = toBytes(@as(u32, 0x12345678));
41393810 switch (native_endian) {
4140 .Big => try testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),
4141 .Little => try testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
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")),
41423813 }
41433814
41443815 my_bytes[0] = '\x99';
41453816 switch (native_endian) {
4146 .Big => try testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),
4147 .Little => try testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
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")),
41483819 }
41493820}
41503821
......@@ -4169,15 +3840,15 @@ pub fn bytesAsValue(comptime T: type, bytes: anytype) BytesAsValueReturnType(T,
41693840test "bytesAsValue" {
41703841 const deadbeef = @as(u32, 0xDEADBEEF);
41713842 const deadbeef_bytes = switch (native_endian) {
4172 .Big => "\xDE\xAD\xBE\xEF",
4173 .Little => "\xEF\xBE\xAD\xDE",
3843 .big => "\xDE\xAD\xBE\xEF",
3844 .little => "\xEF\xBE\xAD\xDE",
41743845 };
41753846
41763847 try testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*);
41773848
41783849 var codeface_bytes: [4]u8 = switch (native_endian) {
4179 .Big => "\xC0\xDE\xFA\xCE",
4180 .Little => "\xCE\xFA\xDE\xC0",
3850 .big => "\xC0\xDE\xFA\xCE",
3851 .little => "\xCE\xFA\xDE\xC0",
41813852 }.*;
41823853 var codeface = bytesAsValue(u32, &codeface_bytes);
41833854 try testing.expect(codeface.* == 0xC0DEFACE);
......@@ -4199,8 +3870,8 @@ test "bytesAsValue" {
41993870 .d = 0xA1,
42003871 };
42013872 const inst_bytes = switch (native_endian) {
4202 .Little => "\xBE\xEF\xDE\xA1",
4203 .Big => "\xA1\xDE\xEF\xBE",
3873 .little => "\xBE\xEF\xDE\xA1",
3874 .big => "\xA1\xDE\xEF\xBE",
42043875 };
42053876 const inst2 = bytesAsValue(S, inst_bytes);
42063877 try testing.expect(meta.eql(inst, inst2.*));
......@@ -4227,8 +3898,8 @@ pub fn bytesToValue(comptime T: type, bytes: anytype) T {
42273898}
42283899test "bytesToValue" {
42293900 const deadbeef_bytes = switch (native_endian) {
4230 .Big => "\xDE\xAD\xBE\xEF",
4231 .Little => "\xEF\xBE\xAD\xDE",
3901 .big => "\xDE\xAD\xBE\xEF",
3902 .little => "\xEF\xBE\xAD\xDE",
42323903 };
42333904
42343905 const deadbeef = bytesToValue(u32, deadbeef_bytes);
......@@ -4357,8 +4028,8 @@ test "sliceAsBytes" {
43574028 const slice = sliceAsBytes(bytes[0..]);
43584029 try testing.expect(slice.len == 4);
43594030 try testing.expect(eql(u8, slice, switch (native_endian) {
4360 .Big => "\xDE\xAD\xBE\xEF",
4361 .Little => "\xAD\xDE\xEF\xBE",
4031 .big => "\xDE\xAD\xBE\xEF",
4032 .little => "\xAD\xDE\xEF\xBE",
43624033 }));
43634034}
43644035
......@@ -4533,7 +4204,7 @@ test "doNotOptimizeAway" {
45334204 doNotOptimizeAway(@as(f64, 0.0));
45344205 doNotOptimizeAway([_]u8{0} ** 4);
45354206 doNotOptimizeAway([_]u8{0} ** 100);
4536 doNotOptimizeAway(@as(std.builtin.Endian, .Little));
4207 doNotOptimizeAway(@as(std.builtin.Endian, .little));
45374208}
45384209
45394210test "alignForward" {
......@@ -4671,7 +4342,6 @@ pub fn alignInSlice(slice: anytype, comptime new_alignment: usize) ?AlignedSlice
46714342}
46724343
46734344test "read/write(Var)PackedInt" {
4674 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
46754345 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
46764346
46774347 switch (builtin.cpu.arch) {
......@@ -4686,7 +4356,7 @@ test "read/write(Var)PackedInt" {
46864356 return error.SkipZigTest;
46874357 }
46884358
4689 const foreign_endian: Endian = if (native_endian == .Big) .Little else .Big;
4359 const foreign_endian: Endian = if (native_endian == .big) .little else .big;
46904360 const expect = std.testing.expect;
46914361 var prng = std.rand.DefaultPrng.init(1234);
46924362 const random = prng.random();
lib/std/net.zig+5-5
......@@ -602,8 +602,8 @@ pub const Ip6Address = extern struct {
602602 }
603603 const big_endian_parts = @as(*align(1) const [8]u16, @ptrCast(&self.sa.addr));
604604 const native_endian_parts = switch (native_endian) {
605 .Big => big_endian_parts.*,
606 .Little => blk: {
605 .big => big_endian_parts.*,
606 .little => blk: {
607607 var buf: [8]u16 = undefined;
608608 for (big_endian_parts, 0..) |part, i| {
609609 buf[i] = mem.bigToNative(u16, part);
......@@ -1052,7 +1052,7 @@ fn linuxLookupName(
10521052 } else {
10531053 sa6.addr[0..12].* = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff".*;
10541054 da6.addr[0..12].* = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff".*;
1055 mem.writeIntNative(u32, da6.addr[12..], addr.addr.in.sa.addr);
1055 mem.writeInt(u32, da6.addr[12..], addr.addr.in.sa.addr, native_endian);
10561056 da4.addr = addr.addr.in.sa.addr;
10571057 da = @ptrCast(&da4);
10581058 dalen = @sizeOf(os.sockaddr.in);
......@@ -1073,7 +1073,7 @@ fn linuxLookupName(
10731073 os.getsockname(fd, sa, &salen) catch break :syscalls;
10741074 if (addr.addr.any.family == os.AF.INET) {
10751075 // TODO sa6.addr[12..16] should return *[4]u8, making this cast unnecessary.
1076 mem.writeIntNative(u32, @as(*[4]u8, @ptrCast(&sa6.addr[12])), sa4.addr);
1076 mem.writeInt(u32, @as(*[4]u8, @ptrCast(&sa6.addr[12])), sa4.addr, native_endian);
10771077 }
10781078 if (dscope == @as(i32, scopeOf(sa6.addr))) key |= DAS_MATCHINGSCOPE;
10791079 if (dlabel == labelOf(sa6.addr)) key |= DAS_MATCHINGLABEL;
......@@ -1569,7 +1569,7 @@ fn resMSendRc(
15691569 );
15701570 for (0..ns.len) |i| {
15711571 if (ns[i].any.family != os.AF.INET) continue;
1572 mem.writeIntNative(u32, ns[i].in6.sa.addr[12..], ns[i].in.sa.addr);
1572 mem.writeInt(u32, ns[i].in6.sa.addr[12..], ns[i].in.sa.addr, native_endian);
15731573 ns[i].in6.sa.addr[0..12].* = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff".*;
15741574 ns[i].any.family = os.AF.INET6;
15751575 ns[i].in6.sa.flowinfo = 0;
lib/std/os/linux.zig+3-3
......@@ -206,11 +206,11 @@ fn splitValueBE64(val: i64) [2]u32 {
206206fn splitValue64(val: i64) [2]u32 {
207207 const u: u64 = @bitCast(val);
208208 switch (native_endian) {
209 .Little => return [2]u32{
209 .little => return [2]u32{
210210 @as(u32, @truncate(u)),
211211 @as(u32, @truncate(u >> 32)),
212212 },
213 .Big => return [2]u32{
213 .big => return [2]u32{
214214 @as(u32, @truncate(u >> 32)),
215215 @as(u32, @truncate(u)),
216216 },
......@@ -6028,7 +6028,7 @@ pub const AUDIT = struct {
60286028
60296029 fn toAudit(arch: std.Target.Cpu.Arch) u32 {
60306030 var res: u32 = @intFromEnum(arch.toElfMachine());
6031 if (arch.endian() == .Little) res |= LE;
6031 if (arch.endian() == .little) res |= LE;
60326032 switch (arch) {
60336033 .aarch64,
60346034 .mips64,
lib/std/os/linux/bpf.zig+4-4
......@@ -696,8 +696,8 @@ pub const Insn = packed struct {
696696 fn endian_swap(endian: std.builtin.Endian, comptime size: Size, dst: Reg) Insn {
697697 return Insn{
698698 .code = switch (endian) {
699 .Big => 0xdc,
700 .Little => 0xd4,
699 .big => 0xdc,
700 .little => 0xd4,
701701 },
702702 .dst = @intFromEnum(dst),
703703 .src = 0,
......@@ -712,11 +712,11 @@ pub const Insn = packed struct {
712712 }
713713
714714 pub fn le(comptime size: Size, dst: Reg) Insn {
715 return endian_swap(.Little, size, dst);
715 return endian_swap(.little, size, dst);
716716 }
717717
718718 pub fn be(comptime size: Size, dst: Reg) Insn {
719 return endian_swap(.Big, size, dst);
719 return endian_swap(.big, size, dst);
720720 }
721721
722722 pub fn call(helper: Helper) Insn {
lib/std/os/linux/seccomp.zig+1-1
......@@ -54,7 +54,7 @@
5454//! manner to the OpenSSH example:
5555//!
5656//! ```zig
57//! const offset = if (native_endian == .Little) struct {
57//! const offset = if (native_endian == .little) struct {
5858//! pub const low = 0;
5959//! pub const high = @sizeOf(u32);
6060//! } else struct {
lib/std/os/test.zig+3-3
......@@ -609,7 +609,7 @@ test "mmap" {
609609
610610 var i: u32 = 0;
611611 while (i < alloc_size / @sizeOf(u32)) : (i += 1) {
612 try stream.writeIntNative(u32, i);
612 try stream.writeInt(u32, i, .little);
613613 }
614614 }
615615
......@@ -633,7 +633,7 @@ test "mmap" {
633633
634634 var i: u32 = 0;
635635 while (i < alloc_size / @sizeOf(u32)) : (i += 1) {
636 try testing.expectEqual(i, try stream.readIntNative(u32));
636 try testing.expectEqual(i, try stream.readInt(u32, .little));
637637 }
638638 }
639639
......@@ -657,7 +657,7 @@ test "mmap" {
657657
658658 var i: u32 = alloc_size / 2 / @sizeOf(u32);
659659 while (i < alloc_size / @sizeOf(u32)) : (i += 1) {
660 try testing.expectEqual(i, try stream.readIntNative(u32));
660 try testing.expectEqual(i, try stream.readInt(u32, .little));
661661 }
662662 }
663663
lib/std/os/windows.zig+2-2
......@@ -3360,13 +3360,13 @@ pub const GUID = extern struct {
33603360 Data4: [8]u8,
33613361
33623362 const hex_offsets = switch (builtin.target.cpu.arch.endian()) {
3363 .Big => [16]u6{
3363 .big => [16]u6{
33643364 0, 2, 4, 6,
33653365 9, 11, 14, 16,
33663366 19, 21, 24, 26,
33673367 28, 30, 32, 34,
33683368 },
3369 .Little => [16]u6{
3369 .little => [16]u6{
33703370 6, 4, 2, 0,
33713371 11, 9, 16, 14,
33723372 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 {
7979 if (endian != native_endian) value = @byteSwap(value);
8080
8181 switch (endian) {
82 .Big => {
82 .big => {
8383 value <<= @as(Shift, @intCast(head_keep_bits));
8484 value >>= @as(Shift, @intCast(head_keep_bits));
8585 value >>= @as(Shift, @intCast(tail_keep_bits));
8686 },
87 .Little => {
87 .little => {
8888 value <<= @as(Shift, @intCast(tail_keep_bits));
8989 value >>= @as(Shift, @intCast(tail_keep_bits));
9090 value >>= @as(Shift, @intCast(head_keep_bits));
......@@ -115,8 +115,8 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type {
115115 const head_keep_bits = bit_index - (start_byte * 8);
116116 const tail_keep_bits = container_bits - (int_bits + head_keep_bits);
117117 const keep_shift = switch (endian) {
118 .Big => @as(Shift, @intCast(tail_keep_bits)),
119 .Little => @as(Shift, @intCast(head_keep_bits)),
118 .big => @as(Shift, @intCast(tail_keep_bits)),
119 .little => @as(Shift, @intCast(head_keep_bits)),
120120 };
121121
122122 //position the bits where they need to be in the container
......@@ -388,10 +388,10 @@ test "PackedIntArray" {
388388
389389test "PackedIntIo" {
390390 const bytes = [_]u8{ 0b01101_000, 0b01011_110, 0b00011_101 };
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));
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));
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));
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));
395395}
396396
397397test "PackedIntArray init" {
......@@ -555,16 +555,16 @@ test "PackedInt(Array/Slice) sliceCast" {
555555 var i = @as(usize, 0);
556556 while (i < packed_slice_cast_2.len) : (i += 1) {
557557 const val = switch (native_endian) {
558 .Big => 0b01,
559 .Little => 0b10,
558 .big => 0b01,
559 .little => 0b10,
560560 };
561561 try testing.expect(packed_slice_cast_2.get(i) == val);
562562 }
563563 i = 0;
564564 while (i < packed_slice_cast_4.len) : (i += 1) {
565565 const val = switch (native_endian) {
566 .Big => 0b0101,
567 .Little => 0b1010,
566 .big => 0b0101,
567 .little => 0b1010,
568568 };
569569 try testing.expect(packed_slice_cast_4.get(i) == val);
570570 }
......@@ -577,8 +577,8 @@ test "PackedInt(Array/Slice) sliceCast" {
577577 i = 0;
578578 while (i < packed_slice_cast_3.len) : (i += 1) {
579579 const val = switch (native_endian) {
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),
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),
582582 };
583583 try testing.expect(packed_slice_cast_3.get(i) == val);
584584 }
......@@ -586,7 +586,7 @@ test "PackedInt(Array/Slice) sliceCast" {
586586
587587test "PackedInt(Array/Slice)Endian" {
588588 {
589 const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8);
589 const PackedArrayBe = PackedIntArrayEndian(u4, .big, 8);
590590 var packed_array_be = PackedArrayBe.init([_]u4{ 0, 1, 2, 3, 4, 5, 6, 7 });
591591 try testing.expect(packed_array_be.bytes[0] == 0b00000001);
592592 try testing.expect(packed_array_be.bytes[1] == 0b00100011);
......@@ -596,14 +596,14 @@ test "PackedInt(Array/Slice)Endian" {
596596 try testing.expect(packed_array_be.get(i) == i);
597597 }
598598
599 var packed_slice_le = packed_array_be.sliceCastEndian(u4, .Little);
599 var packed_slice_le = packed_array_be.sliceCastEndian(u4, .little);
600600 i = 0;
601601 while (i < packed_slice_le.len) : (i += 1) {
602602 const val = if (i % 2 == 0) i + 1 else i - 1;
603603 try testing.expect(packed_slice_le.get(i) == val);
604604 }
605605
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);
607607 i = 0;
608608 while (i < packed_slice_le_shift.len) : (i += 1) {
609609 const val = if (i % 2 == 0) i else i + 2;
......@@ -612,7 +612,7 @@ test "PackedInt(Array/Slice)Endian" {
612612 }
613613
614614 {
615 const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8);
615 const PackedArrayBe = PackedIntArrayEndian(u11, .big, 8);
616616 var packed_array_be = PackedArrayBe.init([_]u11{ 0, 1, 2, 3, 4, 5, 6, 7 });
617617 try testing.expect(packed_array_be.bytes[0] == 0b00000000);
618618 try testing.expect(packed_array_be.bytes[1] == 0b00000000);
......@@ -625,7 +625,7 @@ test "PackedInt(Array/Slice)Endian" {
625625 try testing.expect(packed_array_be.get(i) == i);
626626 }
627627
628 var packed_slice_le = packed_array_be.sliceCastEndian(u11, .Little);
628 var packed_slice_le = packed_array_be.sliceCastEndian(u11, .little);
629629 try testing.expect(packed_slice_le.get(0) == 0b00000000000);
630630 try testing.expect(packed_slice_le.get(1) == 0b00010000000);
631631 try testing.expect(packed_slice_le.get(2) == 0b00000000100);
......@@ -635,7 +635,7 @@ test "PackedInt(Array/Slice)Endian" {
635635 try testing.expect(packed_slice_le.get(6) == 0b10000010000);
636636 try testing.expect(packed_slice_le.get(7) == 0b00000111001);
637637
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);
639639 try testing.expect(packed_slice_le_shift.get(0) == 0b00010000000);
640640 try testing.expect(packed_slice_le_shift.get(1) == 0b00000000100);
641641 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 {
464464};
465465
466466fn readSparseBitVector(stream: anytype, allocator: mem.Allocator) ![]u32 {
467 const num_words = try stream.readIntLittle(u32);
467 const num_words = try stream.readInt(u32, .little);
468468 var list = ArrayList(u32).init(allocator);
469469 errdefer list.deinit();
470470 var word_i: u32 = 0;
471471 while (word_i != num_words) : (word_i += 1) {
472 const word = try stream.readIntLittle(u32);
472 const word = try stream.readInt(u32, .little);
473473 var bit_i: u5 = 0;
474474 while (true) : (bit_i += 1) {
475475 if (word & (@as(u32, 1) << bit_i) != 0) {
......@@ -599,7 +599,7 @@ pub const Pdb = struct {
599599
600600 var sect_cont_offset: usize = 0;
601601 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) {
603603 error.InvalidValue => return error.InvalidDebugInfo,
604604 else => |e| return e,
605605 };
......@@ -625,10 +625,10 @@ pub const Pdb = struct {
625625 const reader = stream.reader();
626626
627627 // Parse the InfoStreamHeader.
628 const version = try reader.readIntLittle(u32);
629 const signature = try reader.readIntLittle(u32);
628 const version = try reader.readInt(u32, .little);
629 const signature = try reader.readInt(u32, .little);
630630 _ = signature;
631 const age = try reader.readIntLittle(u32);
631 const age = try reader.readInt(u32, .little);
632632 const guid = try reader.readBytesNoEof(16);
633633
634634 if (version != 20000404) // VC70, only value observed by LLVM team
......@@ -639,7 +639,7 @@ pub const Pdb = struct {
639639
640640 // Find the string table.
641641 const string_table_index = str_tab_index: {
642 const name_bytes_len = try reader.readIntLittle(u32);
642 const name_bytes_len = try reader.readInt(u32, .little);
643643 const name_bytes = try self.allocator.alloc(u8, name_bytes_len);
644644 defer self.allocator.free(name_bytes);
645645 try reader.readNoEof(name_bytes);
......@@ -667,8 +667,8 @@ pub const Pdb = struct {
667667 defer self.allocator.free(deleted);
668668
669669 for (present) |_| {
670 const name_offset = try reader.readIntLittle(u32);
671 const name_index = try reader.readIntLittle(u32);
670 const name_offset = try reader.readInt(u32, .little);
671 const name_index = try reader.readInt(u32, .little);
672672 if (name_offset > name_bytes.len)
673673 return error.InvalidDebugInfo;
674674 const name = mem.sliceTo(name_bytes[name_offset..], 0);
......@@ -821,7 +821,7 @@ pub const Pdb = struct {
821821 return error.MissingDebugInfo;
822822 const reader = stream.reader();
823823
824 const signature = try reader.readIntLittle(u32);
824 const signature = try reader.readInt(u32, .little);
825825 if (signature != 4)
826826 return error.InvalidDebugInfo;
827827
......@@ -899,7 +899,7 @@ const Msf = struct {
899899 try file.seekTo(superblock.BlockSize * superblock.BlockMapAddr);
900900 var dir_blocks = try allocator.alloc(u32, dir_block_count);
901901 for (dir_blocks) |*b| {
902 b.* = try in.readIntLittle(u32);
902 b.* = try in.readInt(u32, .little);
903903 }
904904 var directory = MsfStream.init(
905905 superblock.BlockSize,
......@@ -908,7 +908,7 @@ const Msf = struct {
908908 );
909909
910910 const begin = directory.pos;
911 const stream_count = try directory.reader().readIntLittle(u32);
911 const stream_count = try directory.reader().readInt(u32, .little);
912912 const stream_sizes = try allocator.alloc(u32, stream_count);
913913 defer allocator.free(stream_sizes);
914914
......@@ -917,7 +917,7 @@ const Msf = struct {
917917 // and must be taken into account when resolving stream indices.
918918 const Nil = 0xFFFFFFFF;
919919 for (stream_sizes) |*s| {
920 const size = try directory.reader().readIntLittle(u32);
920 const size = try directory.reader().readInt(u32, .little);
921921 s.* = if (size == Nil) 0 else blockCountFromSize(size, superblock.BlockSize);
922922 }
923923
......@@ -932,7 +932,7 @@ const Msf = struct {
932932 var blocks = try allocator.alloc(u32, size);
933933 var j: u32 = 0;
934934 while (j < size) : (j += 1) {
935 const block_id = try directory.reader().readIntLittle(u32);
935 const block_id = try directory.reader().readInt(u32, .little);
936936 const n = (block_id % superblock.BlockSize);
937937 // 0 is for SuperBlock, 1 and 2 for FPMs.
938938 if (block_id == 0 or n == 1 or n == 2 or block_id * superblock.BlockSize > file_len)
lib/std/rand.zig+5-4
......@@ -104,15 +104,16 @@ pub const Random = struct {
104104 pub fn int(r: Random, comptime T: type) T {
105105 const bits = @typeInfo(T).Int.bits;
106106 const UnsignedT = std.meta.Int(.unsigned, bits);
107 const ByteAlignedT = std.meta.Int(.unsigned, @divTrunc(bits + 7, 8) * 8);
107 const ceil_bytes = comptime std.math.divCeil(u16, bits, 8) catch unreachable;
108 const ByteAlignedT = std.meta.Int(.unsigned, ceil_bytes * 8);
108109
109 var rand_bytes: [@sizeOf(ByteAlignedT)]u8 = undefined;
110 r.bytes(rand_bytes[0..]);
110 var rand_bytes: [ceil_bytes]u8 = undefined;
111 r.bytes(&rand_bytes);
111112
112113 // use LE instead of native endian for better portability maybe?
113114 // TODO: endian portability is pointless if the underlying prng isn't endian portable.
114115 // TODO: document the endian portability of this library.
115 const byte_aligned_result = mem.readIntSliceLittle(ByteAlignedT, &rand_bytes);
116 const byte_aligned_result = mem.readInt(ByteAlignedT, &rand_bytes, .little);
116117 const unsigned_result: UnsignedT = @truncate(byte_aligned_result);
117118 return @bitCast(unsigned_result);
118119 }
lib/std/rand/Ascon.zig+1-1
......@@ -13,7 +13,7 @@ const mem = std.mem;
1313const Random = std.rand.Random;
1414const Self = @This();
1515
16const Ascon = std.crypto.core.Ascon(.Little);
16const Ascon = std.crypto.core.Ascon(.little);
1717
1818state: Ascon,
1919
lib/std/rand/Isaac64.zig+1-1
......@@ -228,7 +228,7 @@ test "isaac64 fill" {
228228 for (seq) |s| {
229229 var buf0: [8]u8 = undefined;
230230 var buf1: [7]u8 = undefined;
231 std.mem.writeIntLittle(u64, &buf0, s);
231 std.mem.writeInt(u64, &buf0, s, .little);
232232 r.fill(&buf1);
233233 try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
234234 }
lib/std/rand/Pcg.zig+2-2
......@@ -111,8 +111,8 @@ test "pcg fill" {
111111 var i: u32 = 0;
112112 while (i < seq.len) : (i += 2) {
113113 var buf0: [8]u8 = undefined;
114 std.mem.writeIntLittle(u32, buf0[0..4], seq[i]);
115 std.mem.writeIntLittle(u32, buf0[4..8], seq[i + 1]);
114 std.mem.writeInt(u32, buf0[0..4], seq[i], .little);
115 std.mem.writeInt(u32, buf0[4..8], seq[i + 1], .little);
116116
117117 var buf1: [7]u8 = undefined;
118118 r.fill(&buf1);
lib/std/rand/RomuTrio.zig+1-1
......@@ -115,7 +115,7 @@ test "RomuTrio fill" {
115115 for (seq) |s| {
116116 var buf0: [8]u8 = undefined;
117117 var buf1: [7]u8 = undefined;
118 std.mem.writeIntLittle(u64, &buf0, s);
118 std.mem.writeInt(u64, &buf0, s, .little);
119119 r.fill(&buf1);
120120 try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
121121 }
lib/std/rand/Sfc64.zig+1-1
......@@ -125,7 +125,7 @@ test "Sfc64 fill" {
125125 for (seq) |s| {
126126 var buf0: [8]u8 = undefined;
127127 var buf1: [7]u8 = undefined;
128 std.mem.writeIntLittle(u64, &buf0, s);
128 std.mem.writeInt(u64, &buf0, s, .little);
129129 r.fill(&buf1);
130130 try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
131131 }
lib/std/rand/Xoroshiro128.zig+1-1
......@@ -140,7 +140,7 @@ test "xoroshiro fill" {
140140 for (seq) |s| {
141141 var buf0: [8]u8 = undefined;
142142 var buf1: [7]u8 = undefined;
143 std.mem.writeIntLittle(u64, &buf0, s);
143 std.mem.writeInt(u64, &buf0, s, .little);
144144 r.fill(&buf1);
145145 try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
146146 }
lib/std/rand/Xoshiro256.zig+1-1
......@@ -139,7 +139,7 @@ test "xoroshiro fill" {
139139 for (seq) |s| {
140140 var buf0: [8]u8 = undefined;
141141 var buf1: [7]u8 = undefined;
142 std.mem.writeIntLittle(u64, &buf0, s);
142 std.mem.writeInt(u64, &buf0, s, .little);
143143 r.fill(&buf1);
144144 try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..]));
145145 }
lib/std/rand/test.zig+1-1
......@@ -71,7 +71,7 @@ const Dilbert = struct {
7171 for (seq) |s| {
7272 var buf0: [8]u8 = undefined;
7373 var buf1: [8]u8 = undefined;
74 std.mem.writeIntBig(u64, &buf0, s);
74 std.mem.writeInt(u64, &buf0, s, .big);
7575 r.fill(&buf1);
7676 try std.testing.expect(std.mem.eql(u8, buf0[0..], buf1[0..]));
7777 }
lib/std/target.zig+2-2
......@@ -1191,7 +1191,7 @@ pub const Target = struct {
11911191 .loongarch32,
11921192 .loongarch64,
11931193 .arc,
1194 => .Little,
1194 => .little,
11951195
11961196 .armeb,
11971197 .aarch64_be,
......@@ -1207,7 +1207,7 @@ pub const Target = struct {
12071207 .tce,
12081208 .lanai,
12091209 .s390x,
1210 => .Big,
1210 => .big,
12111211 };
12121212 }
12131213
lib/std/tz.zig+6-6
......@@ -59,7 +59,7 @@ pub const Tz = struct {
5959 if (!std.mem.eql(u8, &legacy_header.magic, "TZif")) return error.BadHeader;
6060 if (legacy_header.version != 0 and legacy_header.version != '2' and legacy_header.version != '3') return error.BadVersion;
6161
62 if (builtin.target.cpu.arch.endian() != std.builtin.Endian.Big) {
62 if (builtin.target.cpu.arch.endian() != std.builtin.Endian.big) {
6363 std.mem.byteSwapAllFields(@TypeOf(legacy_header.counts), &legacy_header.counts);
6464 }
6565
......@@ -73,7 +73,7 @@ pub const Tz = struct {
7373 var header = try reader.readStruct(Header);
7474 if (!std.mem.eql(u8, &header.magic, "TZif")) return error.BadHeader;
7575 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) {
7777 std.mem.byteSwapAllFields(@TypeOf(header.counts), &header.counts);
7878 }
7979
......@@ -98,7 +98,7 @@ pub const Tz = struct {
9898 // Parse transition types
9999 var i: usize = 0;
100100 while (i < header.counts.timecnt) : (i += 1) {
101 transitions[i].ts = if (legacy) try reader.readIntBig(i32) else try reader.readIntBig(i64);
101 transitions[i].ts = if (legacy) try reader.readInt(i32, .big) else try reader.readInt(i64, .big);
102102 }
103103
104104 i = 0;
......@@ -111,7 +111,7 @@ pub const Tz = struct {
111111 // Parse time types
112112 i = 0;
113113 while (i < header.counts.typecnt) : (i += 1) {
114 const offset = try reader.readIntBig(i32);
114 const offset = try reader.readInt(i32, .big);
115115 if (offset < -2147483648) return error.Malformed; // rfc8536: utoff [...] MUST NOT be -2**31
116116 const dst = try reader.readByte();
117117 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 {
144144 // Parse leap seconds
145145 i = 0;
146146 while (i < header.counts.leapcnt) : (i += 1) {
147 const occur: i64 = if (legacy) try reader.readIntBig(i32) else try reader.readIntBig(i64);
147 const occur: i64 = if (legacy) try reader.readInt(i32, .big) else try reader.readInt(i64, .big);
148148 if (occur < 0) return error.Malformed; // rfc8536: occur [...] MUST be nonnegative
149149 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
150150 if (occur > std.math.maxInt(i48)) return error.Malformed; // Unreasonably far into the future
151151
152 const corr = try reader.readIntBig(i32);
152 const corr = try reader.readInt(i32, .big);
153153 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)
154154 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)
155155 if (corr > std.math.maxInt(i16)) return error.Malformed; // Unreasonably large correction
lib/std/unicode.zig+25-24
......@@ -1,8 +1,9 @@
11const std = @import("./std.zig");
2const builtin = @import("builtin");
23const assert = std.debug.assert;
34const testing = std.testing;
45const mem = std.mem;
5const builtin = @import("builtin");
6const native_endian = builtin.cpu.arch.endian();
67
78/// Use this to replace an unknown, unrecognized, or unrepresentable character.
89///
......@@ -175,7 +176,7 @@ pub fn utf8CountCodepoints(s: []const u8) !usize {
175176 while (i < s.len) {
176177 // Fast path for ASCII sequences
177178 while (i + N <= s.len) : (i += N) {
178 const v = mem.readIntNative(usize, s[i..][0..N]);
179 const v = mem.readInt(usize, s[i..][0..N], native_endian);
179180 if (v & MASK != 0) break;
180181 len += N;
181182 }
......@@ -451,12 +452,12 @@ pub const Utf16LeIterator = struct {
451452 assert(it.i <= it.bytes.len);
452453 if (it.i == it.bytes.len) return null;
453454 var code_units: [2]u16 = undefined;
454 code_units[0] = mem.readIntLittle(u16, it.bytes[it.i..][0..2]);
455 code_units[0] = mem.readInt(u16, it.bytes[it.i..][0..2], .little);
455456 it.i += 2;
456457 if (utf16IsHighSurrogate(code_units[0])) {
457458 // surrogate pair
458459 if (it.i >= it.bytes.len) return error.DanglingSurrogateHalf;
459 code_units[1] = mem.readIntLittle(u16, it.bytes[it.i..][0..2]);
460 code_units[1] = mem.readInt(u16, it.bytes[it.i..][0..2], .little);
460461 const codepoint = try utf16DecodeSurrogatePair(&code_units);
461462 it.i += 2;
462463 return codepoint;
......@@ -877,16 +878,16 @@ test "utf16leToUtf8" {
877878 const utf16le_as_bytes = mem.sliceAsBytes(utf16le[0..]);
878879
879880 {
880 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 'A');
881 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 'a');
881 mem.writeInt(u16, utf16le_as_bytes[0..2], 'A', .little);
882 mem.writeInt(u16, utf16le_as_bytes[2..4], 'a', .little);
882883 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
883884 defer std.testing.allocator.free(utf8);
884885 try testing.expect(mem.eql(u8, utf8, "Aa"));
885886 }
886887
887888 {
888 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0x80);
889 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xffff);
889 mem.writeInt(u16, utf16le_as_bytes[0..2], 0x80, .little);
890 mem.writeInt(u16, utf16le_as_bytes[2..4], 0xffff, .little);
890891 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
891892 defer std.testing.allocator.free(utf8);
892893 try testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf"));
......@@ -894,8 +895,8 @@ test "utf16leToUtf8" {
894895
895896 {
896897 // the values just outside the surrogate half range
897 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd7ff);
898 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xe000);
898 mem.writeInt(u16, utf16le_as_bytes[0..2], 0xd7ff, .little);
899 mem.writeInt(u16, utf16le_as_bytes[2..4], 0xe000, .little);
899900 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
900901 defer std.testing.allocator.free(utf8);
901902 try testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80"));
......@@ -903,8 +904,8 @@ test "utf16leToUtf8" {
903904
904905 {
905906 // smallest surrogate pair
906 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd800);
907 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
907 mem.writeInt(u16, utf16le_as_bytes[0..2], 0xd800, .little);
908 mem.writeInt(u16, utf16le_as_bytes[2..4], 0xdc00, .little);
908909 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
909910 defer std.testing.allocator.free(utf8);
910911 try testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80"));
......@@ -912,24 +913,24 @@ test "utf16leToUtf8" {
912913
913914 {
914915 // largest surrogate pair
915 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);
916 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdfff);
916 mem.writeInt(u16, utf16le_as_bytes[0..2], 0xdbff, .little);
917 mem.writeInt(u16, utf16le_as_bytes[2..4], 0xdfff, .little);
917918 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
918919 defer std.testing.allocator.free(utf8);
919920 try testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf"));
920921 }
921922
922923 {
923 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);
924 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
924 mem.writeInt(u16, utf16le_as_bytes[0..2], 0xdbff, .little);
925 mem.writeInt(u16, utf16le_as_bytes[2..4], 0xdc00, .little);
925926 const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
926927 defer std.testing.allocator.free(utf8);
927928 try testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80"));
928929 }
929930
930931 {
931 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdcdc);
932 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdcdc);
932 mem.writeInt(u16, utf16le_as_bytes[0..2], 0xdcdc, .little);
933 mem.writeInt(u16, utf16le_as_bytes[2..4], 0xdcdc, .little);
933934 const result = utf16leToUtf8Alloc(std.testing.allocator, &utf16le);
934935 try std.testing.expectError(error.UnexpectedSecondSurrogateHalf, result);
935936 }
......@@ -1140,12 +1141,12 @@ test "fmtUtf16le" {
11401141 try expectFmt("", "{}", .{fmtUtf16le(utf8ToUtf16LeStringLiteral(""))});
11411142 try expectFmt("foo", "{}", .{fmtUtf16le(utf8ToUtf16LeStringLiteral("foo"))});
11421143 try expectFmt("𐐷", "{}", .{fmtUtf16le(utf8ToUtf16LeStringLiteral("𐐷"))});
1143 try expectFmt("퟿", "{}", .{fmtUtf16le(&[_]u16{std.mem.readIntNative(u16, "\xff\xd7")})});
1144 try expectFmt("�", "{}", .{fmtUtf16le(&[_]u16{std.mem.readIntNative(u16, "\x00\xd8")})});
1145 try expectFmt("�", "{}", .{fmtUtf16le(&[_]u16{std.mem.readIntNative(u16, "\xff\xdb")})});
1146 try expectFmt("�", "{}", .{fmtUtf16le(&[_]u16{std.mem.readIntNative(u16, "\x00\xdc")})});
1147 try expectFmt("�", "{}", .{fmtUtf16le(&[_]u16{std.mem.readIntNative(u16, "\xff\xdf")})});
1148 try expectFmt("", "{}", .{fmtUtf16le(&[_]u16{std.mem.readIntNative(u16, "\x00\xe0")})});
1144 try expectFmt("퟿", "{}", .{fmtUtf16le(&[_]u16{std.mem.readInt(u16, "\xff\xd7", native_endian)})});
1145 try expectFmt("�", "{}", .{fmtUtf16le(&[_]u16{std.mem.readInt(u16, "\x00\xd8", native_endian)})});
1146 try expectFmt("�", "{}", .{fmtUtf16le(&[_]u16{std.mem.readInt(u16, "\xff\xdb", native_endian)})});
1147 try expectFmt("�", "{}", .{fmtUtf16le(&[_]u16{std.mem.readInt(u16, "\x00\xdc", native_endian)})});
1148 try expectFmt("�", "{}", .{fmtUtf16le(&[_]u16{std.mem.readInt(u16, "\xff\xdf", native_endian)})});
1149 try expectFmt("", "{}", .{fmtUtf16le(&[_]u16{std.mem.readInt(u16, "\x00\xe0", native_endian)})});
11491150}
11501151
11511152test "utf8ToUtf16LeStringLiteral" {
lib/std/zig/Server.zig+3-3
......@@ -279,12 +279,12 @@ fn bswap_u32_array(slice: []u32) void {
279279
280280/// workaround for https://github.com/ziglang/zig/issues/14904
281281fn bswap_and_workaround_u32(bytes_ptr: *const [4]u8) u32 {
282 return std.mem.readIntLittle(u32, bytes_ptr);
282 return std.mem.readInt(u32, bytes_ptr, .little);
283283}
284284
285285/// workaround for https://github.com/ziglang/zig/issues/14904
286286fn bswap_and_workaround_tag(bytes_ptr: *const [4]u8) InMessage.Tag {
287 const int = std.mem.readIntLittle(u32, bytes_ptr);
287 const int = std.mem.readInt(u32, bytes_ptr, .little);
288288 return @as(InMessage.Tag, @enumFromInt(int));
289289}
290290
......@@ -297,4 +297,4 @@ const std = @import("std");
297297const Allocator = std.mem.Allocator;
298298const assert = std.debug.assert;
299299const native_endian = builtin.target.cpu.arch.endian();
300const need_bswap = native_endian != .Little;
300const need_bswap = native_endian != .little;
lib/std/zig/system/NativeTargetInfo.zig+4-4
......@@ -488,8 +488,8 @@ fn glibcVerFromSoFile(file: fs.File) !std.SemanticVersion {
488488 const hdr64 = @as(*elf.Elf64_Ehdr, @ptrCast(&hdr_buf));
489489 if (!mem.eql(u8, hdr32.e_ident[0..4], elf.MAGIC)) return error.InvalidElfMagic;
490490 const elf_endian: std.builtin.Endian = switch (hdr32.e_ident[elf.EI_DATA]) {
491 elf.ELFDATA2LSB => .Little,
492 elf.ELFDATA2MSB => .Big,
491 elf.ELFDATA2LSB => .little,
492 elf.ELFDATA2MSB => .big,
493493 else => return error.InvalidElfEndian,
494494 };
495495 const need_bswap = elf_endian != native_endian;
......@@ -635,8 +635,8 @@ pub fn abiAndDynamicLinkerFromFile(
635635 const hdr64 = @as(*elf.Elf64_Ehdr, @ptrCast(&hdr_buf));
636636 if (!mem.eql(u8, hdr32.e_ident[0..4], elf.MAGIC)) return error.InvalidElfMagic;
637637 const elf_endian: std.builtin.Endian = switch (hdr32.e_ident[elf.EI_DATA]) {
638 elf.ELFDATA2LSB => .Little,
639 elf.ELFDATA2MSB => .Big,
638 elf.ELFDATA2LSB => .little,
639 elf.ELFDATA2MSB => .big,
640640 else => return error.InvalidElfEndian,
641641 };
642642 const need_bswap = elf_endian != native_endian;
lib/test_runner.zig+3-1
......@@ -13,7 +13,9 @@ var cmdline_buffer: [4096]u8 = undefined;
1313var fba = std.heap.FixedBufferAllocator.init(&cmdline_buffer);
1414
1515pub fn main() void {
16 if (builtin.zig_backend == .stage2_aarch64) {
16 if (builtin.zig_backend == .stage2_aarch64 or
17 builtin.zig_backend == .stage2_wasm)
18 {
1719 return mainSimple() catch @panic("test failure");
1820 }
1921
src/Package/Fetch/git.zig+12-12
......@@ -305,12 +305,12 @@ const Odb = struct {
305305 const n_objects = odb.index_header.fan_out_table[255];
306306 const offset_values_start = IndexHeader.size + n_objects * (oid_length + 4);
307307 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().readIntBig(u32));
308 const l1_offset: packed struct { value: u31, big: bool } = @bitCast(try odb.index_file.reader().readInt(u32, .big));
309309 const pack_offset = pack_offset: {
310310 if (l1_offset.big) {
311311 const l2_offset_values_start = offset_values_start + n_objects * 4;
312312 try odb.index_file.seekTo(l2_offset_values_start + l1_offset.value * 4);
313 break :pack_offset try odb.index_file.reader().readIntBig(u64);
313 break :pack_offset try odb.index_file.reader().readInt(u64, .big);
314314 } else {
315315 break :pack_offset l1_offset.value;
316316 }
......@@ -845,12 +845,12 @@ const PackHeader = struct {
845845 else => |other| return other,
846846 };
847847 if (!mem.eql(u8, &actual_signature, signature)) return error.InvalidHeader;
848 const version = reader.readIntBig(u32) catch |e| switch (e) {
848 const version = reader.readInt(u32, .big) catch |e| switch (e) {
849849 error.EndOfStream => return error.InvalidHeader,
850850 else => |other| return other,
851851 };
852852 if (version != supported_version) return error.UnsupportedVersion;
853 const total_objects = reader.readIntBig(u32) catch |e| switch (e) {
853 const total_objects = reader.readInt(u32, .big) catch |e| switch (e) {
854854 error.EndOfStream => return error.InvalidHeader,
855855 else => |other| return other,
856856 };
......@@ -966,14 +966,14 @@ const IndexHeader = struct {
966966 fn read(reader: anytype) !IndexHeader {
967967 var header_bytes = try reader.readBytesNoEof(size);
968968 if (!mem.eql(u8, header_bytes[0..4], signature)) return error.InvalidHeader;
969 const version = mem.readIntBig(u32, header_bytes[4..8]);
969 const version = mem.readInt(u32, header_bytes[4..8], .big);
970970 if (version != supported_version) return error.UnsupportedVersion;
971971
972972 var fan_out_table: [256]u32 = undefined;
973973 var fan_out_table_stream = std.io.fixedBufferStream(header_bytes[8..]);
974974 const fan_out_table_reader = fan_out_table_stream.reader();
975975 for (&fan_out_table) |*entry| {
976 entry.* = fan_out_table_reader.readIntBig(u32) catch unreachable;
976 entry.* = fan_out_table_reader.readInt(u32, .big) catch unreachable;
977977 }
978978 return .{ .fan_out_table = fan_out_table };
979979 }
......@@ -1041,9 +1041,9 @@ pub fn indexPack(allocator: Allocator, pack: std.fs.File, index_writer: anytype)
10411041 var index_hashed_writer = hashedWriter(index_writer, Sha1.init(.{}));
10421042 const writer = index_hashed_writer.writer();
10431043 try writer.writeAll(IndexHeader.signature);
1044 try writer.writeIntBig(u32, IndexHeader.supported_version);
1044 try writer.writeInt(u32, IndexHeader.supported_version, .big);
10451045 for (fan_out_table) |fan_out_entry| {
1046 try writer.writeIntBig(u32, fan_out_entry);
1046 try writer.writeInt(u32, fan_out_entry, .big);
10471047 }
10481048
10491049 for (oids.items) |oid| {
......@@ -1051,7 +1051,7 @@ pub fn indexPack(allocator: Allocator, pack: std.fs.File, index_writer: anytype)
10511051 }
10521052
10531053 for (oids.items) |oid| {
1054 try writer.writeIntBig(u32, index_entries.get(oid).?.crc32);
1054 try writer.writeInt(u32, index_entries.get(oid).?.crc32, .big);
10551055 }
10561056
10571057 var big_offsets = std.ArrayListUnmanaged(u64){};
......@@ -1059,15 +1059,15 @@ pub fn indexPack(allocator: Allocator, pack: std.fs.File, index_writer: anytype)
10591059 for (oids.items) |oid| {
10601060 const offset = index_entries.get(oid).?.offset;
10611061 if (offset <= std.math.maxInt(u31)) {
1062 try writer.writeIntBig(u32, @intCast(offset));
1062 try writer.writeInt(u32, @intCast(offset), .big);
10631063 } else {
10641064 const index = big_offsets.items.len;
10651065 try big_offsets.append(allocator, offset);
1066 try writer.writeIntBig(u32, @as(u32, @intCast(index)) | (1 << 31));
1066 try writer.writeInt(u32, @as(u32, @intCast(index)) | (1 << 31), .big);
10671067 }
10681068 }
10691069 for (big_offsets.items) |offset| {
1070 try writer.writeIntBig(u64, offset);
1070 try writer.writeInt(u64, offset, .big);
10711071 }
10721072
10731073 try writer.writeAll(&pack_checksum);
src/Sema.zig+24-5
......@@ -26835,7 +26835,7 @@ fn structFieldPtrByIndex(
2683526835 // cause miscompilations; it only means the field pointer uses bit masking when it
2683626836 // might not be strictly necessary.
2683726837 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)
2683926839 {
2684026840 const elem_size_bytes = try sema.typeAbiSize(ptr_ty_data.child.toType());
2684126841 const elem_size_bits = ptr_ty_data.child.toType().bitSize(mod);
......@@ -29684,6 +29684,7 @@ fn storePtrVal(
2968429684 try sema.checkComptimeVarStore(block, src, mut_kit.mut_decl);
2968529685
2968629686 switch (mut_kit.pointee) {
29687 .opv => {},
2968729688 .direct => |val_ptr| {
2968829689 if (mut_kit.mut_decl.runtime_index == .comptime_field_ptr) {
2968929690 val_ptr.* = (try val_ptr.intern(operand_ty, mod)).toValue();
......@@ -29741,6 +29742,7 @@ fn storePtrVal(
2974129742const ComptimePtrMutationKit = struct {
2974229743 mut_decl: InternPool.Key.Ptr.Addr.MutDecl,
2974329744 pointee: union(enum) {
29745 opv,
2974429746 /// The pointer type matches the actual comptime Value so a direct
2974529747 /// modification is possible.
2974629748 direct: *Value,
......@@ -29793,6 +29795,7 @@ fn beginComptimePtrMutation(
2979329795 const eu_ty = mod.intern_pool.typeOf(eu_ptr).toType().childType(mod);
2979429796 var parent = try sema.beginComptimePtrMutation(block, src, eu_ptr.toValue(), eu_ty);
2979529797 switch (parent.pointee) {
29798 .opv => unreachable,
2979629799 .direct => |val_ptr| {
2979729800 const payload_ty = parent.ty.errorUnionPayload(mod);
2979829801 if (val_ptr.ip_index == .none and val_ptr.tag() == .eu_payload) {
......@@ -29835,6 +29838,7 @@ fn beginComptimePtrMutation(
2983529838 const opt_ty = mod.intern_pool.typeOf(opt_ptr).toType().childType(mod);
2983629839 var parent = try sema.beginComptimePtrMutation(block, src, opt_ptr.toValue(), opt_ty);
2983729840 switch (parent.pointee) {
29841 .opv => unreachable,
2983829842 .direct => |val_ptr| {
2983929843 const payload_ty = parent.ty.optionalChild(mod);
2984029844 switch (val_ptr.ip_index) {
......@@ -29888,16 +29892,30 @@ fn beginComptimePtrMutation(
2988829892 var parent = try sema.beginComptimePtrMutation(block, src, elem_ptr.base.toValue(), base_elem_ty);
2988929893
2989029894 switch (parent.pointee) {
29895 .opv => unreachable,
2989129896 .direct => |val_ptr| switch (parent.ty.zigTypeTag(mod)) {
2989229897 .Array, .Vector => {
29898 const elem_ty = parent.ty.childType(mod);
2989329899 const check_len = parent.ty.arrayLenIncludingSentinel(mod);
29900 if ((try sema.typeHasOnePossibleValue(ptr_elem_ty)) != null) {
29901 if (elem_ptr.index > check_len) {
29902 // TODO have the parent include the decl so we can say "declared here"
29903 return sema.fail(block, src, "comptime store of index {d} out of bounds of array length {d}", .{
29904 elem_ptr.index, check_len,
29905 });
29906 }
29907 return .{
29908 .mut_decl = parent.mut_decl,
29909 .pointee = .opv,
29910 .ty = elem_ty,
29911 };
29912 }
2989429913 if (elem_ptr.index >= check_len) {
2989529914 // TODO have the parent include the decl so we can say "declared here"
2989629915 return sema.fail(block, src, "comptime store of index {d} out of bounds of array length {d}", .{
2989729916 elem_ptr.index, check_len,
2989829917 });
2989929918 }
29900 const elem_ty = parent.ty.childType(mod);
2990129919
2990229920 // We might have a pointer to multiple elements of the array (e.g. a pointer
2990329921 // to a sub-array). In this case, we just have to reinterpret the relevant
......@@ -30072,6 +30090,7 @@ fn beginComptimePtrMutation(
3007230090
3007330091 var parent = try sema.beginComptimePtrMutation(block, src, field_ptr.base.toValue(), base_child_ty);
3007430092 switch (parent.pointee) {
30093 .opv => unreachable,
3007530094 .direct => |val_ptr| switch (val_ptr.ip_index) {
3007630095 .empty_struct => {
3007730096 const duped = try sema.arena.create(Value);
......@@ -30717,8 +30736,8 @@ fn bitCastUnionFieldVal(
3071730736 if (field_size > old_size) {
3071830737 const min_size = @max(old_size, 1);
3071930738 switch (endian) {
30720 .Little => @memset(buffer[min_size - 1 ..], 0xaa),
30721 .Big => @memset(buffer[0 .. buffer.len - min_size + 1], 0xaa),
30739 .little => @memset(buffer[min_size - 1 ..], 0xaa),
30740 .big => @memset(buffer[0 .. buffer.len - min_size + 1], 0xaa),
3072230741 }
3072330742 }
3072430743
......@@ -30727,7 +30746,7 @@ fn bitCastUnionFieldVal(
3072730746 error.ReinterpretDeclRef => return null,
3072830747 };
3072930748
30730 break :offset if (endian == .Big) buffer.len - field_size else 0;
30749 break :offset if (endian == .big) buffer.len - field_size else 0;
3073130750 },
3073230751 .Auto => unreachable,
3073330752 };
src/arch/sparc64/CodeGen.zig+2-2
......@@ -1231,8 +1231,8 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
12311231 const abi_size = int_info.bits >> 3;
12321232 const abi_align = operand_ty.abiAlignment(mod);
12331233 const opposite_endian_asi = switch (self.target.cpu.arch.endian()) {
1234 Endian.Big => ASI.asi_primary_little,
1235 Endian.Little => ASI.asi_primary,
1234 Endian.big => ASI.asi_primary_little,
1235 Endian.little => ASI.asi_primary,
12361236 };
12371237
12381238 switch (operand) {
src/arch/sparc64/Emit.zig+1-1
......@@ -677,7 +677,7 @@ fn writeInstruction(emit: *Emit, instruction: Instruction) !void {
677677 // SPARCv9 instructions are always arranged in BE regardless of the
678678 // endianness mode the CPU is running in (Section 3.1 of the ISA specification).
679679 // 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;
681681
682682 std.mem.writeInt(u32, try emit.code.addManyAsArray(4), instruction.toU32(), endian);
683683}
src/arch/wasm/CodeGen.zig+1-1
......@@ -3364,7 +3364,7 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
33643364 const backing_int_ty = struct_type.backingIntType(ip).toType();
33653365 const int_val = try mod.intValue(
33663366 backing_int_ty,
3367 mem.readIntLittle(u64, &buf),
3367 mem.readInt(u64, &buf, .little),
33683368 );
33693369 return func.lowerConstant(int_val, backing_int_ty);
33703370 },
src/arch/wasm/Emit.zig+2-2
......@@ -330,14 +330,14 @@ fn emitImm64(emit: *Emit, inst: Mir.Inst.Index) !void {
330330fn emitFloat32(emit: *Emit, inst: Mir.Inst.Index) !void {
331331 const value: f32 = emit.mir.instructions.items(.data)[inst].float32;
332332 try emit.code.append(std.wasm.opcode(.f32_const));
333 try emit.code.writer().writeIntLittle(u32, @as(u32, @bitCast(value)));
333 try emit.code.writer().writeInt(u32, @bitCast(value), .little);
334334}
335335
336336fn emitFloat64(emit: *Emit, inst: Mir.Inst.Index) !void {
337337 const extra_index = emit.mir.instructions.items(.data)[inst].payload;
338338 const value = emit.mir.extraData(Mir.Float64, extra_index);
339339 try emit.code.append(std.wasm.opcode(.f64_const));
340 try emit.code.writer().writeIntLittle(u64, value.data.toU64());
340 try emit.code.writer().writeInt(u64, value.data.toU64(), .little);
341341}
342342
343343fn 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 {
360360 var creader = std.io.countingReader(stream.reader());
361361 const reader = creader.reader();
362362 const imm = switch (kind) {
363 .imm8s, .rel8 => Immediate.s(try reader.readInt(i8, .Little)),
364 .imm16s, .rel16 => Immediate.s(try reader.readInt(i16, .Little)),
365 .imm32s, .rel32 => Immediate.s(try reader.readInt(i32, .Little)),
366 .imm8 => Immediate.u(try reader.readInt(u8, .Little)),
367 .imm16 => Immediate.u(try reader.readInt(u16, .Little)),
368 .imm32 => Immediate.u(try reader.readInt(u32, .Little)),
369 .imm64 => Immediate.u(try reader.readInt(u64, .Little)),
363 .imm8s, .rel8 => Immediate.s(try reader.readInt(i8, .little)),
364 .imm16s, .rel16 => Immediate.s(try reader.readInt(i16, .little)),
365 .imm32s, .rel32 => Immediate.s(try reader.readInt(i32, .little)),
366 .imm8 => Immediate.u(try reader.readInt(u8, .little)),
367 .imm16 => Immediate.u(try reader.readInt(u16, .little)),
368 .imm32 => Immediate.u(try reader.readInt(u32, .little)),
369 .imm64 => Immediate.u(try reader.readInt(u64, .little)),
370370 else => unreachable,
371371 };
372372 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 {
376376fn parseOffset(dis: *Disassembler) !u64 {
377377 var stream = std.io.fixedBufferStream(dis.code[dis.pos..]);
378378 const reader = stream.reader();
379 const offset = try reader.readInt(u64, .Little);
379 const offset = try reader.readInt(u64, .little);
380380 dis.pos += 8;
381381 return offset;
382382}
......@@ -457,16 +457,16 @@ fn parseDisplacement(dis: *Disassembler, modrm: ModRm, sib: ?Sib) !i32 {
457457 const disp = disp: {
458458 if (sib) |info| {
459459 if (info.base == 0b101 and modrm.mod == 0) {
460 break :disp try reader.readInt(i32, .Little);
460 break :disp try reader.readInt(i32, .little);
461461 }
462462 }
463463 if (modrm.rip()) {
464 break :disp try reader.readInt(i32, .Little);
464 break :disp try reader.readInt(i32, .little);
465465 }
466466 break :disp switch (modrm.mod) {
467467 0b00 => 0,
468 0b01 => try reader.readInt(i8, .Little),
469 0b10 => try reader.readInt(i32, .Little),
468 0b01 => try reader.readInt(i8, .little),
469 0b10 => try reader.readInt(i32, .little),
470470 0b11 => unreachable,
471471 };
472472 };
src/arch/x86_64/Emit.zig+1-1
......@@ -253,7 +253,7 @@ fn fixupRelocs(emit: *Emit) Error!void {
253253 const target = emit.code_offset_mapping.get(reloc.target) orelse
254254 return emit.fail("JMP/CALL relocation target not found!", .{});
255255 const disp = @as(i32, @intCast(@as(i64, @intCast(target)) - @as(i64, @intCast(reloc.source + reloc.length))));
256 mem.writeIntLittle(i32, emit.code.items[reloc.offset..][0..4], disp);
256 mem.writeInt(i32, emit.code.items[reloc.offset..][0..4], disp, .little);
257257 }
258258}
259259
src/arch/x86_64/encoder.zig+4-4
......@@ -998,7 +998,7 @@ fn Encoder(comptime T: type, comptime opts: Options) type {
998998 ///
999999 /// It is sign-extended to 64 bits by the cpu.
10001000 pub fn disp32(self: Self, disp: i32) !void {
1001 try self.writer.writeIntLittle(i32, disp);
1001 try self.writer.writeInt(i32, disp, .little);
10021002 }
10031003
10041004 /// Encode an 8 bit immediate
......@@ -1012,21 +1012,21 @@ fn Encoder(comptime T: type, comptime opts: Options) type {
10121012 ///
10131013 /// It is sign-extended to 64 bits by the cpu.
10141014 pub fn imm16(self: Self, imm: u16) !void {
1015 try self.writer.writeIntLittle(u16, imm);
1015 try self.writer.writeInt(u16, imm, .little);
10161016 }
10171017
10181018 /// Encode an 32 bit immediate
10191019 ///
10201020 /// It is sign-extended to 64 bits by the cpu.
10211021 pub fn imm32(self: Self, imm: u32) !void {
1022 try self.writer.writeIntLittle(u32, imm);
1022 try self.writer.writeInt(u32, imm, .little);
10231023 }
10241024
10251025 /// Encode an 64 bit immediate
10261026 ///
10271027 /// It is sign-extended to 64 bits by the cpu.
10281028 pub fn imm64(self: Self, imm: u64) !void {
1029 try self.writer.writeIntLittle(u64, imm);
1029 try self.writer.writeInt(u64, imm, .little);
10301030 }
10311031 };
10321032}
src/codegen/c.zig+12-9
......@@ -4652,7 +4652,10 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca
46524652 try writer.writeAll(", &");
46534653 try f.writeCValue(writer, operand_lval, .Other);
46544654 try writer.writeAll(", sizeof(");
4655 try f.renderType(writer, dest_ty);
4655 try f.renderType(
4656 writer,
4657 if (dest_ty.abiSize(mod) <= operand_ty.abiSize(mod)) dest_ty else operand_ty,
4658 );
46564659 try writer.writeAll("));\n");
46574660
46584661 // Ensure padding bits have the expected value.
......@@ -4666,8 +4669,8 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca
46664669 try f.writeCValue(writer, local, .Other);
46674670 if (dest_cty.castTag(.array)) |pl| {
46684671 try writer.print("[{d}]", .{switch (target.cpu.arch.endian()) {
4669 .Little => pl.data.len - 1,
4670 .Big => 0,
4672 .little => pl.data.len - 1,
4673 .big => 0,
46714674 }});
46724675 const elem_cty = f.indexToCType(pl.data.elem_type);
46734676 wrap_cty = elem_cty.toSignedness(dest_info.signedness);
......@@ -4697,8 +4700,8 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca
46974700 try f.writeCValue(writer, local, .Other);
46984701 if (dest_cty.castTag(.array)) |pl| {
46994702 try writer.print("[{d}]", .{switch (target.cpu.arch.endian()) {
4700 .Little => pl.data.len - 1,
4701 .Big => 0,
4703 .little => pl.data.len - 1,
4704 .big => 0,
47024705 }});
47034706 }
47044707 if (need_bitcasts) try writer.writeByte(')');
......@@ -7652,13 +7655,13 @@ fn formatIntLiteral(
76527655 else => .{
76537656 .cty = CType.initTag(.void),
76547657 .count = 1,
7655 .endian = .Little,
7658 .endian = .little,
76567659 .homogeneous = true,
76577660 },
76587661 .zig_u128, .zig_i128 => .{
76597662 .cty = CType.initTag(.uint64_t),
76607663 .count = 2,
7661 .endian = .Big,
7664 .endian = .big,
76627665 .homogeneous = false,
76637666 },
76647667 .array => info: {
......@@ -7729,8 +7732,8 @@ fn formatIntLiteral(
77297732 const most_significant_limb_i = wrap.len - limbs_per_c_limb;
77307733 while (limb_offset < wrap.len) : (limb_offset += limbs_per_c_limb) {
77317734 const limb_i = switch (c_limb_info.endian) {
7732 .Little => limb_offset,
7733 .Big => most_significant_limb_i - limb_offset,
7735 .little => limb_offset,
7736 .big => most_significant_limb_i - limb_offset,
77347737 };
77357738 var c_limb_mut = BigInt.Mutable{
77367739 .limbs = wrap.limbs[limb_i..][0..limbs_per_c_limb],
src/codegen/llvm.zig+3-3
......@@ -342,8 +342,8 @@ const DataLayoutBuilder = struct {
342342 writer: anytype,
343343 ) @TypeOf(writer).Error!void {
344344 try writer.writeByte(switch (self.target.cpu.arch.endian()) {
345 .Little => 'e',
346 .Big => 'E',
345 .little => 'e',
346 .big => 'E',
347347 });
348348 switch (self.target.cpu.arch) {
349349 .amdgcn,
......@@ -10453,7 +10453,7 @@ pub const FuncGen = struct {
1045310453 else
1045410454 payload_llvm_ty;
1045510455 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)
1045710457 try fg.wip.bin(.lshr, loaded, try o.builder.intValue(
1045810458 load_llvm_ty,
1045910459 (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
751751
752752 var inc_i: usize = 0;
753753
754 const fn_inclusions_len = mem.readIntLittle(u16, metadata.inclusions[inc_i..][0..2]);
754 const fn_inclusions_len = mem.readInt(u16, metadata.inclusions[inc_i..][0..2], .little);
755755 inc_i += 2;
756756
757757 var sym_i: usize = 0;
......@@ -768,7 +768,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo
768768 versions_len = 0;
769769 break :n name;
770770 };
771 const targets = mem.readIntLittle(u32, metadata.inclusions[inc_i..][0..4]);
771 const targets = mem.readInt(u32, metadata.inclusions[inc_i..][0..4], .little);
772772 inc_i += 4;
773773
774774 const lib_index = metadata.inclusions[inc_i];
......@@ -882,7 +882,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo
882882
883883 try stubs_asm.appendSlice(".data\n");
884884
885 const obj_inclusions_len = mem.readIntLittle(u16, metadata.inclusions[inc_i..][0..2]);
885 const obj_inclusions_len = mem.readInt(u16, metadata.inclusions[inc_i..][0..2], .little);
886886 inc_i += 2;
887887
888888 sym_i = 0;
......@@ -899,10 +899,10 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo
899899 versions_len = 0;
900900 break :n name;
901901 };
902 const targets = mem.readIntLittle(u32, metadata.inclusions[inc_i..][0..4]);
902 const targets = mem.readInt(u32, metadata.inclusions[inc_i..][0..4], .little);
903903 inc_i += 4;
904904
905 const size = mem.readIntLittle(u16, metadata.inclusions[inc_i..][0..2]);
905 const size = mem.readInt(u16, metadata.inclusions[inc_i..][0..2], .little);
906906 inc_i += 2;
907907
908908 const lib_index = metadata.inclusions[inc_i];
src/link/Coff.zig+9-9
......@@ -856,12 +856,12 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void {
856856 switch (self.ptr_width) {
857857 .p32 => {
858858 var buf: [4]u8 = undefined;
859 mem.writeIntLittle(u32, &buf, @as(u32, @intCast(entry_value + self.getImageBase())));
859 mem.writeInt(u32, &buf, @as(u32, @intCast(entry_value + self.getImageBase())), .little);
860860 try self.base.file.?.pwriteAll(&buf, file_offset);
861861 },
862862 .p64 => {
863863 var buf: [8]u8 = undefined;
864 mem.writeIntLittle(u64, &buf, entry_value + self.getImageBase());
864 mem.writeInt(u64, &buf, entry_value + self.getImageBase(), .little);
865865 try self.base.file.?.pwriteAll(&buf, file_offset);
866866 },
867867 }
......@@ -889,14 +889,14 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void {
889889 switch (self.ptr_width) {
890890 .p32 => {
891891 var buf: [4]u8 = undefined;
892 mem.writeIntLittle(u32, &buf, @as(u32, @intCast(entry_value + slide)));
892 mem.writeInt(u32, &buf, @as(u32, @intCast(entry_value + slide)), .little);
893893 writeMem(handle, pvaddr, &buf) catch |err| {
894894 log.warn("writing to protected memory failed with error: {s}", .{@errorName(err)});
895895 };
896896 },
897897 .p64 => {
898898 var buf: [8]u8 = undefined;
899 mem.writeIntLittle(u64, &buf, entry_value + slide);
899 mem.writeInt(u64, &buf, entry_value + slide, .little);
900900 writeMem(handle, pvaddr, &buf) catch |err| {
901901 log.warn("writing to protected memory failed with error: {s}", .{@errorName(err)});
902902 };
......@@ -2076,7 +2076,7 @@ fn writeImportTables(self: *Coff) !void {
20762076 lookup_table_offset += lookup_entry_size;
20772077
20782078 // Names table entry
2079 mem.writeIntLittle(u16, buffer.items[names_table_offset..][0..2], 0); // 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
20802080 names_table_offset += 2;
20812081 @memcpy(buffer.items[names_table_offset..][0..import_name.len], import_name);
20822082 names_table_offset += @as(u32, @intCast(import_name.len));
......@@ -2089,7 +2089,7 @@ fn writeImportTables(self: *Coff) !void {
20892089 }
20902090
20912091 // IAT sentinel
2092 mem.writeIntLittle(u64, buffer.items[iat_offset..][0..lookup_entry_size], 0);
2092 mem.writeInt(u64, buffer.items[iat_offset..][0..lookup_entry_size], 0, .little);
20932093 iat_offset += 8;
20942094
20952095 // Lookup table sentinel
......@@ -2157,7 +2157,7 @@ fn writeStrtab(self: *Coff) !void {
21572157 buffer.appendSliceAssumeCapacity(self.strtab.items());
21582158 // Here, we do a trick in that we do not commit the size of the strtab to strtab buffer, instead
21592159 // we write the length of the strtab to a temporary buffer that goes to file.
2160 mem.writeIntLittle(u32, buffer.items[0..4], @as(u32, @intCast(self.strtab.len())));
2160 mem.writeInt(u32, buffer.items[0..4], @as(u32, @intCast(self.strtab.len())), .little);
21612161
21622162 try self.base.file.?.pwriteAll(buffer.items, self.strtab_offset.?);
21632163}
......@@ -2180,7 +2180,7 @@ fn writeHeader(self: *Coff) !void {
21802180
21812181 try buffer.ensureTotalCapacity(self.getSizeOfHeaders());
21822182 writer.writeAll(msdos_stub) catch unreachable;
2183 mem.writeIntLittle(u32, buffer.items[0x3c..][0..4], msdos_stub.len);
2183 mem.writeInt(u32, buffer.items[0x3c..][0..4], msdos_stub.len, .little);
21842184
21852185 writer.writeAll("PE\x00\x00") catch unreachable;
21862186 var flags = coff.CoffHeaderFlags{
......@@ -2548,7 +2548,7 @@ fn setSymbolName(self: *Coff, symbol: *coff.Symbol, name: []const u8) !void {
25482548 }
25492549 const offset = try self.strtab.insert(self.base.allocator, name);
25502550 @memset(symbol.name[0..4], 0);
2551 mem.writeIntLittle(u32, symbol.name[4..8], offset);
2551 mem.writeInt(u32, symbol.name[4..8], offset, .little);
25522552}
25532553
25542554fn logSymAttributes(sym: *const coff.Symbol, buf: *[4]u8) []const u8 {
src/link/Coff/Relocation.zig+11-10
......@@ -137,7 +137,7 @@ fn resolveAarch64(self: Relocation, ctx: Context) void {
137137 };
138138 inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2));
139139 inst.pc_relative_address.immlo = @as(u2, @truncate(pages));
140 mem.writeIntLittle(u32, buffer[0..4], inst.toU32());
140 mem.writeInt(u32, buffer[0..4], inst.toU32(), .little);
141141 },
142142 .got_pageoff, .import_pageoff, .pageoff => {
143143 assert(!self.pcrel);
......@@ -151,7 +151,7 @@ fn resolveAarch64(self: Relocation, ctx: Context) void {
151151 ), buffer[0..4]),
152152 };
153153 inst.add_subtract_immediate.imm12 = narrowed;
154 mem.writeIntLittle(u32, buffer[0..4], inst.toU32());
154 mem.writeInt(u32, buffer[0..4], inst.toU32(), .little);
155155 } else {
156156 var inst = aarch64.Instruction{
157157 .load_store_register = mem.bytesToValue(meta.TagPayload(
......@@ -173,18 +173,19 @@ fn resolveAarch64(self: Relocation, ctx: Context) void {
173173 }
174174 };
175175 inst.load_store_register.offset = offset;
176 mem.writeIntLittle(u32, buffer[0..4], inst.toU32());
176 mem.writeInt(u32, buffer[0..4], inst.toU32(), .little);
177177 }
178178 },
179179 .direct => {
180180 assert(!self.pcrel);
181181 switch (self.length) {
182 2 => mem.writeIntLittle(
182 2 => mem.writeInt(
183183 u32,
184184 buffer[0..4],
185185 @as(u32, @truncate(ctx.target_vaddr + ctx.image_base)),
186 .little,
186187 ),
187 3 => mem.writeIntLittle(u64, buffer[0..8], ctx.target_vaddr + ctx.image_base),
188 3 => mem.writeInt(u64, buffer[0..8], ctx.target_vaddr + ctx.image_base, .little),
188189 else => unreachable,
189190 }
190191 },
......@@ -207,17 +208,17 @@ fn resolveX86(self: Relocation, ctx: Context) void {
207208 .got, .import => {
208209 assert(self.pcrel);
209210 const disp = @as(i32, @intCast(ctx.target_vaddr)) - @as(i32, @intCast(ctx.source_vaddr)) - 4;
210 mem.writeIntLittle(i32, buffer[0..4], disp);
211 mem.writeInt(i32, buffer[0..4], disp, .little);
211212 },
212213 .direct => {
213214 if (self.pcrel) {
214215 const disp = @as(i32, @intCast(ctx.target_vaddr)) - @as(i32, @intCast(ctx.source_vaddr)) - 4;
215 mem.writeIntLittle(i32, buffer[0..4], disp);
216 mem.writeInt(i32, buffer[0..4], disp, .little);
216217 } else switch (ctx.ptr_width) {
217 .p32 => mem.writeIntLittle(u32, buffer[0..4], @as(u32, @intCast(ctx.target_vaddr + ctx.image_base))),
218 .p32 => mem.writeInt(u32, buffer[0..4], @as(u32, @intCast(ctx.target_vaddr + ctx.image_base)), .little),
218219 .p64 => switch (self.length) {
219 2 => mem.writeIntLittle(u32, buffer[0..4], @as(u32, @truncate(ctx.target_vaddr + ctx.image_base))),
220 3 => mem.writeIntLittle(u64, buffer[0..8], ctx.target_vaddr + ctx.image_base),
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),
221222 else => unreachable,
222223 },
223224 }
src/link/Elf.zig+2-2
......@@ -2719,8 +2719,8 @@ fn writeHeader(self: *Elf) !void {
27192719
27202720 const endian = self.base.options.target.cpu.arch.endian();
27212721 hdr_buf[index] = switch (endian) {
2722 .Little => elf.ELFDATA2LSB,
2723 .Big => elf.ELFDATA2MSB,
2722 .little => elf.ELFDATA2LSB,
2723 .big => elf.ELFDATA2MSB,
27242724 };
27252725 index += 1;
27262726
src/link/Elf/Atom.zig+42-42
......@@ -786,43 +786,43 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void {
786786
787787 elf.R_X86_64_PLT32,
788788 elf.R_X86_64_PC32,
789 => try cwriter.writeIntLittle(i32, @as(i32, @intCast(S + A - P))),
789 => try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .little),
790790
791 elf.R_X86_64_GOTPCREL => try cwriter.writeIntLittle(i32, @as(i32, @intCast(G + GOT + A - P))),
792 elf.R_X86_64_GOTPC32 => try cwriter.writeIntLittle(i32, @as(i32, @intCast(GOT + A - P))),
793 elf.R_X86_64_GOTPC64 => try cwriter.writeIntLittle(i64, GOT + A - P),
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),
793 elf.R_X86_64_GOTPC64 => try cwriter.writeInt(i64, GOT + A - P, .little),
794794
795795 elf.R_X86_64_GOTPCRELX => {
796796 if (!target.flags.import and !target.isIFunc(elf_file) and !target.isAbs(elf_file)) blk: {
797797 x86_64.relaxGotpcrelx(code[r_offset - 2 ..]) catch break :blk;
798 try cwriter.writeIntLittle(i32, @as(i32, @intCast(S + A - P)));
798 try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .little);
799799 continue;
800800 }
801 try cwriter.writeIntLittle(i32, @as(i32, @intCast(G + GOT + A - P)));
801 try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .little);
802802 },
803803
804804 elf.R_X86_64_REX_GOTPCRELX => {
805805 if (!target.flags.import and !target.isIFunc(elf_file) and !target.isAbs(elf_file)) blk: {
806806 x86_64.relaxRexGotpcrelx(code[r_offset - 3 ..]) catch break :blk;
807 try cwriter.writeIntLittle(i32, @as(i32, @intCast(S + A - P)));
807 try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .little);
808808 continue;
809809 }
810 try cwriter.writeIntLittle(i32, @as(i32, @intCast(G + GOT + A - P)));
810 try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .little);
811811 },
812812
813 elf.R_X86_64_32 => try cwriter.writeIntLittle(u32, @as(u32, @truncate(@as(u64, @intCast(S + A))))),
814 elf.R_X86_64_32S => try cwriter.writeIntLittle(i32, @as(i32, @truncate(S + A))),
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),
815815
816 elf.R_X86_64_TPOFF32 => try cwriter.writeIntLittle(i32, @as(i32, @truncate(S + A - TP))),
817 elf.R_X86_64_TPOFF64 => try cwriter.writeIntLittle(i64, S + A - TP),
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),
818818
819 elf.R_X86_64_DTPOFF32 => try cwriter.writeIntLittle(i32, @as(i32, @truncate(S + A - DTP))),
820 elf.R_X86_64_DTPOFF64 => try cwriter.writeIntLittle(i64, S + A - DTP),
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),
821821
822822 elf.R_X86_64_TLSGD => {
823823 if (target.flags.has_tlsgd) {
824824 const S_ = @as(i64, @intCast(target.tlsGdAddress(elf_file)));
825 try cwriter.writeIntLittle(i32, @as(i32, @intCast(S_ + A - P)));
825 try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .little);
826826 } else if (target.flags.has_gottp) {
827827 const S_ = @as(i64, @intCast(target.gotTpAddress(elf_file)));
828828 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 {
843843 if (elf_file.got.tlsld_index) |entry_index| {
844844 const tlsld_entry = elf_file.got.entries.items[entry_index];
845845 const S_ = @as(i64, @intCast(tlsld_entry.address(elf_file)));
846 try cwriter.writeIntLittle(i32, @as(i32, @intCast(S_ + A - P)));
846 try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .little);
847847 } else {
848848 try x86_64.relaxTlsLdToLe(
849849 self,
......@@ -859,10 +859,10 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void {
859859 elf.R_X86_64_GOTPC32_TLSDESC => {
860860 if (target.flags.has_tlsdesc) {
861861 const S_ = @as(i64, @intCast(target.tlsDescAddress(elf_file)));
862 try cwriter.writeIntLittle(i32, @as(i32, @intCast(S_ + A - P)));
862 try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .little);
863863 } else {
864864 try x86_64.relaxGotPcTlsDesc(code[r_offset - 3 ..]);
865 try cwriter.writeIntLittle(i32, @as(i32, @intCast(S - TP)));
865 try cwriter.writeInt(i32, @as(i32, @intCast(S - TP)), .little);
866866 }
867867 },
868868
......@@ -874,18 +874,18 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void {
874874 elf.R_X86_64_GOTTPOFF => {
875875 if (target.flags.has_gottp) {
876876 const S_ = @as(i64, @intCast(target.gotTpAddress(elf_file)));
877 try cwriter.writeIntLittle(i32, @as(i32, @intCast(S_ + A - P)));
877 try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .little);
878878 } else {
879879 x86_64.relaxGotTpOff(code[r_offset - 3 ..]) catch unreachable;
880 try cwriter.writeIntLittle(i32, @as(i32, @intCast(S - TP)));
880 try cwriter.writeInt(i32, @as(i32, @intCast(S - TP)), .little);
881881 }
882882 },
883883
884 elf.R_X86_64_GOT32 => try cwriter.writeIntLittle(i32, @as(i32, @intCast(G + GOT + A))),
884 elf.R_X86_64_GOT32 => try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A)), .little),
885885
886886 // Zig custom relocations
887 Elf.R_X86_64_ZIG_GOT32 => try cwriter.writeIntLittle(u32, @as(u32, @intCast(ZIG_GOT + A))),
888 Elf.R_X86_64_ZIG_GOTPCREL => try cwriter.writeIntLittle(i32, @as(i32, @intCast(ZIG_GOT + A - P))),
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),
889889
890890 else => {},
891891 }
......@@ -920,7 +920,7 @@ fn resolveDynAbsReloc(
920920 .copyrel,
921921 .cplt,
922922 .none,
923 => try writer.writeIntLittle(i32, @as(i32, @truncate(S + A))),
923 => try writer.writeInt(i32, @as(i32, @truncate(S + A)), .little),
924924
925925 .dyn_copyrel => {
926926 if (is_writeable or elf_file.base.options.z_nocopyreloc) {
......@@ -932,7 +932,7 @@ fn resolveDynAbsReloc(
932932 });
933933 try applyDynamicReloc(A, elf_file, writer);
934934 } else {
935 try writer.writeIntLittle(i32, @as(i32, @truncate(S + A)));
935 try writer.writeInt(i32, @as(i32, @truncate(S + A)), .little);
936936 }
937937 },
938938
......@@ -946,7 +946,7 @@ fn resolveDynAbsReloc(
946946 });
947947 try applyDynamicReloc(A, elf_file, writer);
948948 } else {
949 try writer.writeIntLittle(i32, @as(i32, @truncate(S + A)));
949 try writer.writeInt(i32, @as(i32, @truncate(S + A)), .little);
950950 }
951951 },
952952
......@@ -984,7 +984,7 @@ fn resolveDynAbsReloc(
984984fn applyDynamicReloc(value: i64, elf_file: *Elf, writer: anytype) !void {
985985 _ = elf_file;
986986 // if (elf_file.options.apply_dynamic_relocs) {
987 try writer.writeIntLittle(i64, value);
987 try writer.writeInt(i64, value, .little);
988988 // }
989989}
990990
......@@ -1058,22 +1058,22 @@ pub fn resolveRelocsNonAlloc(self: Atom, elf_file: *Elf, code: []u8, undefs: any
10581058
10591059 switch (r_type) {
10601060 elf.R_X86_64_NONE => unreachable,
1061 elf.R_X86_64_8 => try cwriter.writeIntLittle(u8, @as(u8, @bitCast(@as(i8, @intCast(S + A))))),
1062 elf.R_X86_64_16 => try cwriter.writeIntLittle(u16, @as(u16, @bitCast(@as(i16, @intCast(S + A))))),
1063 elf.R_X86_64_32 => try cwriter.writeIntLittle(u32, @as(u32, @bitCast(@as(i32, @intCast(S + A))))),
1064 elf.R_X86_64_32S => try cwriter.writeIntLittle(i32, @as(i32, @intCast(S + A))),
1065 elf.R_X86_64_64 => try cwriter.writeIntLittle(i64, S + A),
1066 elf.R_X86_64_DTPOFF32 => try cwriter.writeIntLittle(i32, @as(i32, @intCast(S + A - DTP))),
1067 elf.R_X86_64_DTPOFF64 => try cwriter.writeIntLittle(i64, S + A - DTP),
1068 elf.R_X86_64_GOTOFF64 => try cwriter.writeIntLittle(i64, S + A - GOT),
1069 elf.R_X86_64_GOTPC64 => try cwriter.writeIntLittle(i64, GOT + A),
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),
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),
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),
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),
1069 elf.R_X86_64_GOTPC64 => try cwriter.writeInt(i64, GOT + A, .little),
10701070 elf.R_X86_64_SIZE32 => {
10711071 const size = @as(i64, @intCast(target.elfSym(elf_file).st_size));
1072 try cwriter.writeIntLittle(u32, @as(u32, @bitCast(@as(i32, @intCast(size + A)))));
1072 try cwriter.writeInt(u32, @as(u32, @bitCast(@as(i32, @intCast(size + A)))), .little);
10731073 },
10741074 elf.R_X86_64_SIZE64 => {
10751075 const size = @as(i64, @intCast(target.elfSym(elf_file).st_size));
1076 try cwriter.writeIntLittle(i64, @as(i64, @intCast(size + A)));
1076 try cwriter.writeInt(i64, @as(i64, @intCast(size + A)), .little);
10771077 },
10781078 else => try self.reportUnhandledRelocError(rel, elf_file),
10791079 }
......@@ -1254,7 +1254,7 @@ const x86_64 = struct {
12541254 0x64, 0x48, 0x8b, 0x04, 0x25, 0, 0, 0, 0, // movq %fs:0,%rax
12551255 0x48, 0x03, 0x05, 0, 0, 0, 0, // add foo@gottpoff(%rip), %rax
12561256 };
1257 std.mem.writeIntLittle(i32, insts[12..][0..4], value - 12);
1257 std.mem.writeInt(i32, insts[12..][0..4], value - 12, .little);
12581258 try stream.seekBy(-4);
12591259 try writer.writeAll(&insts);
12601260 },
......@@ -1292,7 +1292,7 @@ const x86_64 = struct {
12921292 0x64, 0x48, 0x8b, 0, // mov %fs:(%rax), %rax
12931293 0x48, 0x2d, 0, 0, 0, 0, // sub $tls_size, %rax
12941294 };
1295 std.mem.writeIntLittle(i32, insts[8..][0..4], value);
1295 std.mem.writeInt(i32, insts[8..][0..4], value, .little);
12961296 try stream.seekBy(-3);
12971297 try writer.writeAll(&insts);
12981298 },
......@@ -1306,7 +1306,7 @@ const x86_64 = struct {
13061306 0x48, 0x2d, 0, 0, 0, 0, // sub $tls_size, %rax
13071307 0x90, // nop
13081308 };
1309 std.mem.writeIntLittle(i32, insts[8..][0..4], value);
1309 std.mem.writeInt(i32, insts[8..][0..4], value, .little);
13101310 try stream.seekBy(-3);
13111311 try writer.writeAll(&insts);
13121312 },
......@@ -1392,7 +1392,7 @@ const x86_64 = struct {
13921392 0x64, 0x48, 0x8b, 0x04, 0x25, 0, 0, 0, 0, // movq %fs:0,%rax
13931393 0x48, 0x81, 0xc0, 0, 0, 0, 0, // add $tp_offset, %rax
13941394 };
1395 std.mem.writeIntLittle(i32, insts[12..][0..4], value);
1395 std.mem.writeInt(i32, insts[12..][0..4], value, .little);
13961396 try stream.seekBy(-4);
13971397 try writer.writeAll(&insts);
13981398 relocs_log.debug(" relaxing {} and {}", .{
src/link/Elf/eh_frame.zig+15-13
......@@ -33,7 +33,7 @@ pub const Fde = struct {
3333
3434 pub fn ciePointer(fde: Fde, elf_file: *Elf) u32 {
3535 const fde_data = fde.data(elf_file);
36 return std.mem.readIntLittle(u32, fde_data[4..8]);
36 return std.mem.readInt(u32, fde_data[4..8], .little);
3737 }
3838
3939 pub fn calcSize(fde: Fde) usize {
......@@ -217,10 +217,10 @@ pub const Iterator = struct {
217217 var stream = std.io.fixedBufferStream(it.data[it.pos..]);
218218 const reader = stream.reader();
219219
220 var size = try reader.readIntLittle(u32);
220 var size = try reader.readInt(u32, .little);
221221 if (size == 0xFFFFFFFF) @panic("TODO");
222222
223 const id = try reader.readIntLittle(u32);
223 const id = try reader.readInt(u32, .little);
224224 const record = Record{
225225 .tag = if (id == 0) .cie else .fde,
226226 .offset = it.pos,
......@@ -298,10 +298,10 @@ fn resolveReloc(rec: anytype, sym: *const Symbol, rel: elf.Elf64_Rela, elf_file:
298298
299299 var where = contents[offset..];
300300 switch (rel.r_type()) {
301 elf.R_X86_64_32 => std.mem.writeIntLittle(i32, where[0..4], @as(i32, @truncate(S + A))),
302 elf.R_X86_64_64 => std.mem.writeIntLittle(i64, where[0..8], S + A),
303 elf.R_X86_64_PC32 => std.mem.writeIntLittle(i32, where[0..4], @as(i32, @intCast(S - P + A))),
304 elf.R_X86_64_PC64 => std.mem.writeIntLittle(i64, where[0..8], S - P + A),
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),
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),
305305 else => unreachable,
306306 }
307307}
......@@ -338,10 +338,11 @@ pub fn writeEhFrame(elf_file: *Elf, writer: anytype) !void {
338338 const contents = try gpa.dupe(u8, fde.data(elf_file));
339339 defer gpa.free(contents);
340340
341 std.mem.writeIntLittle(
341 std.mem.writeInt(
342342 i32,
343343 contents[4..8],
344 @as(i32, @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,
345346 );
346347
347348 for (fde.relocs(elf_file)) |rel| {
......@@ -353,7 +354,7 @@ pub fn writeEhFrame(elf_file: *Elf, writer: anytype) !void {
353354 }
354355 }
355356
356 try writer.writeIntLittle(u32, 0);
357 try writer.writeInt(u32, 0, .little);
357358}
358359
359360pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void {
......@@ -365,14 +366,15 @@ pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void {
365366 const eh_frame_shdr = elf_file.shdrs.items[elf_file.eh_frame_section_index.?];
366367 const eh_frame_hdr_shdr = elf_file.shdrs.items[elf_file.eh_frame_hdr_section_index.?];
367368 const num_fdes = @as(u32, @intCast(@divExact(eh_frame_hdr_shdr.sh_size - eh_frame_hdr_header_size, 8)));
368 try writer.writeIntLittle(
369 try writer.writeInt(
369370 u32,
370371 @as(u32, @bitCast(@as(
371372 i32,
372373 @truncate(@as(i64, @intCast(eh_frame_shdr.sh_addr)) - @as(i64, @intCast(eh_frame_hdr_shdr.sh_addr)) - 4),
373374 ))),
375 .little,
374376 );
375 try writer.writeIntLittle(u32, num_fdes);
377 try writer.writeInt(u32, num_fdes, .little);
376378
377379 const Entry = struct {
378380 init_addr: u32,
......@@ -401,7 +403,7 @@ pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void {
401403 const S = @as(i64, @intCast(sym.address(.{}, elf_file)));
402404 const A = rel.r_addend;
403405 entries.appendAssumeCapacity(.{
404 .init_addr = @as(u32, @bitCast(@as(i32, @truncate(S + A - @as(i64, @intCast(eh_frame_hdr_shdr.sh_addr)))))),
406 .init_addr = @bitCast(@as(i32, @truncate(S + A - @as(i64, @intCast(eh_frame_hdr_shdr.sh_addr))))),
405407 .fde_addr = @as(
406408 u32,
407409 @bitCast(@as(i32, @truncate(P - @as(i64, @intCast(eh_frame_hdr_shdr.sh_addr))))),
src/link/Elf/synthetic_sections.zig+15-15
......@@ -878,9 +878,9 @@ pub const PltSection = struct {
878878 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp qword ptr [rip] -> .got.plt[2]
879879 };
880880 var disp = @as(i64, @intCast(got_plt_addr + 8)) - @as(i64, @intCast(plt_addr + 8)) - 4;
881 mem.writeIntLittle(i32, preamble[8..][0..4], @as(i32, @intCast(disp)));
881 mem.writeInt(i32, preamble[8..][0..4], @as(i32, @intCast(disp)), .little);
882882 disp = @as(i64, @intCast(got_plt_addr + 16)) - @as(i64, @intCast(plt_addr + 14)) - 4;
883 mem.writeIntLittle(i32, preamble[14..][0..4], @as(i32, @intCast(disp)));
883 mem.writeInt(i32, preamble[14..][0..4], @as(i32, @intCast(disp)), .little);
884884 try writer.writeAll(&preamble);
885885 try writer.writeByteNTimes(0xcc, preamble_size - preamble.len);
886886
......@@ -894,8 +894,8 @@ pub const PltSection = struct {
894894 0x41, 0xbb, 0x00, 0x00, 0x00, 0x00, // mov r11d, N
895895 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp qword ptr [rip] -> .got.plt[N]
896896 };
897 mem.writeIntLittle(i32, entry[6..][0..4], @as(i32, @intCast(i)));
898 mem.writeIntLittle(i32, entry[12..][0..4], @as(i32, @intCast(disp)));
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);
899899 try writer.writeAll(&entry);
900900 }
901901 }
......@@ -971,17 +971,17 @@ pub const GotPltSection = struct {
971971 {
972972 // [0]: _DYNAMIC
973973 const symbol = elf_file.symbol(elf_file.dynamic_index.?);
974 try writer.writeIntLittle(u64, symbol.value);
974 try writer.writeInt(u64, symbol.value, .little);
975975 }
976976 // [1]: 0x0
977977 // [2]: 0x0
978 try writer.writeIntLittle(u64, 0x0);
979 try writer.writeIntLittle(u64, 0x0);
978 try writer.writeInt(u64, 0x0, .little);
979 try writer.writeInt(u64, 0x0, .little);
980980 if (elf_file.plt_section_index) |shndx| {
981981 const plt_addr = elf_file.shdrs.items[shndx].sh_addr;
982982 for (0..elf_file.plt.symbols.items.len) |_| {
983983 // [N]: .plt
984 try writer.writeIntLittle(u64, plt_addr);
984 try writer.writeInt(u64, plt_addr, .little);
985985 }
986986 }
987987 }
......@@ -1023,7 +1023,7 @@ pub const PltGotSection = struct {
10231023 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp qword ptr [rip] -> .got[N]
10241024 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
10251025 };
1026 mem.writeIntLittle(i32, entry[6..][0..4], @as(i32, @intCast(disp)));
1026 mem.writeInt(i32, entry[6..][0..4], @as(i32, @intCast(disp)), .little);
10271027 try writer.writeAll(&entry);
10281028 }
10291029 }
......@@ -1258,8 +1258,8 @@ pub const HashSection = struct {
12581258 }
12591259
12601260 try hs.buffer.ensureTotalCapacityPrecise(gpa, (2 + nsyms * 2) * 4);
1261 hs.buffer.writer(gpa).writeIntLittle(u32, @as(u32, @intCast(nsyms))) catch unreachable;
1262 hs.buffer.writer(gpa).writeIntLittle(u32, @as(u32, @intCast(nsyms))) 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;
12631263 hs.buffer.writer(gpa).writeAll(mem.sliceAsBytes(buckets)) catch unreachable;
12641264 hs.buffer.writer(gpa).writeAll(mem.sliceAsBytes(chains)) catch unreachable;
12651265 }
......@@ -1322,10 +1322,10 @@ pub const GnuHashSection = struct {
13221322 var counting = std.io.countingWriter(writer);
13231323 const cwriter = counting.writer();
13241324
1325 try cwriter.writeIntLittle(u32, hash.num_buckets);
1326 try cwriter.writeIntLittle(u32, export_off);
1327 try cwriter.writeIntLittle(u32, hash.num_bloom);
1328 try cwriter.writeIntLittle(u32, bloom_shift);
1325 try cwriter.writeInt(u32, hash.num_buckets, .little);
1326 try cwriter.writeInt(u32, export_off, .little);
1327 try cwriter.writeInt(u32, hash.num_bloom, .little);
1328 try cwriter.writeInt(u32, bloom_shift, .little);
13291329
13301330 const gpa = elf_file.base.allocator;
13311331 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 {
12221222 log.debug("writing GOT entry {d}: @{x} => {x}", .{ index, vmaddr, entry_value });
12231223
12241224 var buf: [@sizeOf(u64)]u8 = undefined;
1225 mem.writeIntLittle(u64, &buf, entry_value);
1225 mem.writeInt(u64, &buf, entry_value, .little);
12261226 try self.base.file.?.pwriteAll(&buf, file_offset);
12271227
12281228 if (is_hot_update_compatible) {
......@@ -1329,7 +1329,7 @@ fn writeStubTableEntry(self: *MachO, index: usize) !void {
13291329
13301330 {
13311331 var buf: [@sizeOf(u64)]u8 = undefined;
1332 mem.writeIntLittle(u64, &buf, stub_helper_addr);
1332 mem.writeInt(u64, &buf, stub_helper_addr, .little);
13331333 const off = laptr_header.offset + @sizeOf(u64) * index;
13341334 try self.base.file.?.pwriteAll(&buf, off);
13351335 }
......@@ -3773,7 +3773,7 @@ fn collectBindData(self: *MachO, bind: anytype, raw_bindings: anytype) !void {
37733773 const base_offset = sym.n_value - segment.vmaddr;
37743774 const rel_offset = @as(u32, @intCast(rel.r_address - ctx.base_offset));
37753775 const offset = @as(u64, @intCast(base_offset + rel_offset));
3776 const addend = mem.readIntLittle(i64, code[rel_offset..][0..8]);
3776 const addend = mem.readInt(i64, code[rel_offset..][0..8], .little);
37773777
37783778 const dylib_ordinal = @divTrunc(@as(i16, @bitCast(bind_sym.n_desc)), macho.N_SYMBOL_RESOLVER);
37793779 log.debug(" | bind at {x}, import('{s}') in dylib({d})", .{
......@@ -4502,7 +4502,7 @@ pub fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void {
45024502 if (!self.stub_table.lookup.contains(entry)) continue;
45034503 const target_sym = self.getSymbol(entry);
45044504 assert(target_sym.undf());
4505 try writer.writeIntLittle(u32, iundefsym + ctx.imports_table.get(entry).?);
4505 try writer.writeInt(u32, iundefsym + ctx.imports_table.get(entry).?, .little);
45064506 }
45074507 }
45084508
......@@ -4513,9 +4513,9 @@ pub fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void {
45134513 if (!self.got_table.lookup.contains(entry)) continue;
45144514 const target_sym = self.getSymbol(entry);
45154515 if (target_sym.undf()) {
4516 try writer.writeIntLittle(u32, iundefsym + ctx.imports_table.get(entry).?);
4516 try writer.writeInt(u32, iundefsym + ctx.imports_table.get(entry).?, .little);
45174517 } else {
4518 try writer.writeIntLittle(u32, macho.INDIRECT_SYMBOL_LOCAL);
4518 try writer.writeInt(u32, macho.INDIRECT_SYMBOL_LOCAL, .little);
45194519 }
45204520 }
45214521 }
......@@ -4527,7 +4527,7 @@ pub fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void {
45274527 if (!self.stub_table.lookup.contains(entry)) continue;
45284528 const target_sym = self.getSymbol(entry);
45294529 assert(target_sym.undf());
4530 try writer.writeIntLittle(u32, iundefsym + ctx.imports_table.get(entry).?);
4530 try writer.writeInt(u32, iundefsym + ctx.imports_table.get(entry).?, .little);
45314531 }
45324532 }
45334533
src/link/MachO/Archive.zig+4-4
......@@ -123,7 +123,7 @@ fn parseName(allocator: Allocator, name_or_length: ar_hdr.NameOrLength, reader:
123123}
124124
125125fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) !void {
126 const symtab_size = try reader.readIntLittle(u32);
126 const symtab_size = try reader.readInt(u32, .little);
127127 var symtab = try allocator.alloc(u8, symtab_size);
128128 defer allocator.free(symtab);
129129
......@@ -132,7 +132,7 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) !
132132 return error.MalformedArchive;
133133 };
134134
135 const strtab_size = try reader.readIntLittle(u32);
135 const strtab_size = try reader.readInt(u32, .little);
136136 var strtab = try allocator.alloc(u8, strtab_size);
137137 defer allocator.free(strtab);
138138
......@@ -145,11 +145,11 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) !
145145 var symtab_reader = symtab_stream.reader();
146146
147147 while (true) {
148 const n_strx = symtab_reader.readIntLittle(u32) catch |err| switch (err) {
148 const n_strx = symtab_reader.readInt(u32, .little) catch |err| switch (err) {
149149 error.EndOfStream => break,
150150 else => |e| return e,
151151 };
152 const object_offset = try symtab_reader.readIntLittle(u32);
152 const object_offset = try symtab_reader.readInt(u32, .little);
153153
154154 const sym_name = mem.sliceTo(@as([*:0]const u8, @ptrCast(strtab.ptr + n_strx)), 0);
155155 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 {
443443
444444 const address_in_section = if (ctx.rel.r_pcrel == 0) blk: {
445445 break :blk if (ctx.rel.r_length == 3)
446 mem.readIntLittle(u64, ctx.code[rel_offset..][0..8])
446 mem.readInt(u64, ctx.code[rel_offset..][0..8], .little)
447447 else
448 mem.readIntLittle(u32, ctx.code[rel_offset..][0..4]);
448 mem.readInt(u32, ctx.code[rel_offset..][0..4], .little);
449449 } else blk: {
450450 assert(macho_file.base.options.target.cpu.arch == .x86_64);
451451 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 {
455455 .X86_64_RELOC_SIGNED_4 => 4,
456456 else => unreachable,
457457 };
458 const addend = mem.readIntLittle(i32, ctx.code[rel_offset..][0..4]);
458 const addend = mem.readInt(i32, ctx.code[rel_offset..][0..4], .little);
459459 const target_address = @as(i64, @intCast(ctx.base_addr)) + ctx.rel.r_address + 4 + correction + addend;
460460 break :blk @as(u64, @intCast(target_address));
461461 };
......@@ -781,7 +781,7 @@ fn resolveRelocsArm64(
781781 ), code),
782782 };
783783 inst.unconditional_branch_immediate.imm26 = @as(u26, @truncate(@as(u28, @bitCast(displacement >> 2))));
784 mem.writeIntLittle(u32, code, inst.toU32());
784 mem.writeInt(u32, code, inst.toU32(), .little);
785785 },
786786
787787 .ARM64_RELOC_PAGE21,
......@@ -802,7 +802,7 @@ fn resolveRelocsArm64(
802802 };
803803 inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2));
804804 inst.pc_relative_address.immlo = @as(u2, @truncate(pages));
805 mem.writeIntLittle(u32, code, inst.toU32());
805 mem.writeInt(u32, code, inst.toU32(), .little);
806806 addend = null;
807807 },
808808
......@@ -821,7 +821,7 @@ fn resolveRelocsArm64(
821821 ), code),
822822 };
823823 inst.add_subtract_immediate.imm12 = off;
824 mem.writeIntLittle(u32, code, inst.toU32());
824 mem.writeInt(u32, code, inst.toU32(), .little);
825825 } else {
826826 var inst = aarch64.Instruction{
827827 .load_store_register = mem.bytesToValue(meta.TagPayload(
......@@ -839,7 +839,7 @@ fn resolveRelocsArm64(
839839 3 => .load_store_64,
840840 });
841841 inst.load_store_register.offset = off;
842 mem.writeIntLittle(u32, code, inst.toU32());
842 mem.writeInt(u32, code, inst.toU32(), .little);
843843 }
844844 addend = null;
845845 },
......@@ -858,7 +858,7 @@ fn resolveRelocsArm64(
858858 ), code),
859859 };
860860 inst.load_store_register.offset = off;
861 mem.writeIntLittle(u32, code, inst.toU32());
861 mem.writeInt(u32, code, inst.toU32(), .little);
862862 addend = null;
863863 },
864864
......@@ -918,7 +918,7 @@ fn resolveRelocsArm64(
918918 .sf = @as(u1, @truncate(reg_info.size)),
919919 },
920920 };
921 mem.writeIntLittle(u32, code, inst.toU32());
921 mem.writeInt(u32, code, inst.toU32(), .little);
922922 addend = null;
923923 },
924924
......@@ -926,14 +926,14 @@ fn resolveRelocsArm64(
926926 relocs_log.debug(" | target_addr = 0x{x}", .{target_addr});
927927 const result = math.cast(i32, @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr))) orelse
928928 return error.Overflow;
929 mem.writeIntLittle(u32, atom_code[rel_offset..][0..4], @as(u32, @bitCast(result)));
929 mem.writeInt(u32, atom_code[rel_offset..][0..4], @as(u32, @bitCast(result)), .little);
930930 },
931931
932932 .ARM64_RELOC_UNSIGNED => {
933933 var ptr_addend = if (rel.r_length == 3)
934 mem.readIntLittle(i64, atom_code[rel_offset..][0..8])
934 mem.readInt(i64, atom_code[rel_offset..][0..8], .little)
935935 else
936 mem.readIntLittle(i32, atom_code[rel_offset..][0..4]);
936 mem.readInt(i32, atom_code[rel_offset..][0..4], .little);
937937
938938 if (rel.r_extern == 0) {
939939 const base_addr = if (target.sym_index >= object.source_address_lookup.len)
......@@ -954,9 +954,9 @@ fn resolveRelocsArm64(
954954 relocs_log.debug(" | target_addr = 0x{x}", .{result});
955955
956956 if (rel.r_length == 3) {
957 mem.writeIntLittle(u64, atom_code[rel_offset..][0..8], @as(u64, @bitCast(result)));
957 mem.writeInt(u64, atom_code[rel_offset..][0..8], @as(u64, @bitCast(result)), .little);
958958 } else {
959 mem.writeIntLittle(u32, atom_code[rel_offset..][0..4], @as(u32, @truncate(@as(u64, @bitCast(result)))));
959 mem.writeInt(u32, atom_code[rel_offset..][0..4], @as(u32, @truncate(@as(u64, @bitCast(result)))), .little);
960960 }
961961
962962 subtractor = null;
......@@ -1045,25 +1045,25 @@ fn resolveRelocsX86(
10451045
10461046 switch (rel_type) {
10471047 .X86_64_RELOC_BRANCH => {
1048 const addend = mem.readIntLittle(i32, atom_code[rel_offset..][0..4]);
1048 const addend = mem.readInt(i32, atom_code[rel_offset..][0..4], .little);
10491049 const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend));
10501050 relocs_log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});
10511051 const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0);
1052 mem.writeIntLittle(i32, atom_code[rel_offset..][0..4], disp);
1052 mem.writeInt(i32, atom_code[rel_offset..][0..4], disp, .little);
10531053 },
10541054
10551055 .X86_64_RELOC_GOT,
10561056 .X86_64_RELOC_GOT_LOAD,
10571057 => {
1058 const addend = mem.readIntLittle(i32, atom_code[rel_offset..][0..4]);
1058 const addend = mem.readInt(i32, atom_code[rel_offset..][0..4], .little);
10591059 const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend));
10601060 relocs_log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});
10611061 const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0);
1062 mem.writeIntLittle(i32, atom_code[rel_offset..][0..4], disp);
1062 mem.writeInt(i32, atom_code[rel_offset..][0..4], disp, .little);
10631063 },
10641064
10651065 .X86_64_RELOC_TLV => {
1066 const addend = mem.readIntLittle(i32, atom_code[rel_offset..][0..4]);
1066 const addend = mem.readInt(i32, atom_code[rel_offset..][0..4], .little);
10671067 const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend));
10681068 relocs_log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});
10691069 const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0);
......@@ -1073,7 +1073,7 @@ fn resolveRelocsX86(
10731073 atom_code[rel_offset - 2] = 0x8d;
10741074 }
10751075
1076 mem.writeIntLittle(i32, atom_code[rel_offset..][0..4], disp);
1076 mem.writeInt(i32, atom_code[rel_offset..][0..4], disp, .little);
10771077 },
10781078
10791079 .X86_64_RELOC_SIGNED,
......@@ -1088,7 +1088,7 @@ fn resolveRelocsX86(
10881088 .X86_64_RELOC_SIGNED_4 => 4,
10891089 else => unreachable,
10901090 };
1091 var addend = mem.readIntLittle(i32, atom_code[rel_offset..][0..4]) + correction;
1091 var addend = mem.readInt(i32, atom_code[rel_offset..][0..4], .little) + correction;
10921092
10931093 if (rel.r_extern == 0) {
10941094 const base_addr = if (target.sym_index >= object.source_address_lookup.len)
......@@ -1104,14 +1104,14 @@ fn resolveRelocsX86(
11041104 relocs_log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr});
11051105
11061106 const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, correction);
1107 mem.writeIntLittle(i32, atom_code[rel_offset..][0..4], disp);
1107 mem.writeInt(i32, atom_code[rel_offset..][0..4], disp, .little);
11081108 },
11091109
11101110 .X86_64_RELOC_UNSIGNED => {
11111111 var addend = if (rel.r_length == 3)
1112 mem.readIntLittle(i64, atom_code[rel_offset..][0..8])
1112 mem.readInt(i64, atom_code[rel_offset..][0..8], .little)
11131113 else
1114 mem.readIntLittle(i32, atom_code[rel_offset..][0..4]);
1114 mem.readInt(i32, atom_code[rel_offset..][0..4], .little);
11151115
11161116 if (rel.r_extern == 0) {
11171117 const base_addr = if (target.sym_index >= object.source_address_lookup.len)
......@@ -1132,9 +1132,9 @@ fn resolveRelocsX86(
11321132 relocs_log.debug(" | target_addr = 0x{x}", .{result});
11331133
11341134 if (rel.r_length == 3) {
1135 mem.writeIntLittle(u64, atom_code[rel_offset..][0..8], @as(u64, @bitCast(result)));
1135 mem.writeInt(u64, atom_code[rel_offset..][0..8], @as(u64, @bitCast(result)), .little);
11361136 } else {
1137 mem.writeIntLittle(u32, atom_code[rel_offset..][0..4], @as(u32, @truncate(@as(u64, @bitCast(result)))));
1137 mem.writeInt(u32, atom_code[rel_offset..][0..4], @as(u32, @truncate(@as(u64, @bitCast(result)))), .little);
11381138 }
11391139
11401140 subtractor = null;
src/link/MachO/CodeSignature.zig+29-29
......@@ -115,14 +115,14 @@ pub fn writeAdhocSignature(
115115 self.code_directory.inner.length = self.code_directory.size();
116116 header.length += self.code_directory.size();
117117
118 try writer.writeIntBig(u32, header.magic);
119 try writer.writeIntBig(u32, header.length);
120 try writer.writeIntBig(u32, header.count);
118 try writer.writeInt(u32, header.magic, .big);
119 try writer.writeInt(u32, header.length, .big);
120 try writer.writeInt(u32, header.count, .big);
121121
122122 var offset: u32 = @sizeOf(macho.SuperBlob) + @sizeOf(macho.BlobIndex) * @as(u32, @intCast(blobs.items.len));
123123 for (blobs.items) |blob| {
124 try writer.writeIntBig(u32, blob.slotType());
125 try writer.writeIntBig(u32, offset);
124 try writer.writeInt(u32, blob.slotType(), .big);
125 try writer.writeInt(u32, offset, .big);
126126 offset += blob.size();
127127 }
128128
......@@ -272,27 +272,27 @@ const CodeDirectory = struct {
272272 }
273273
274274 fn write(self: CodeDirectory, writer: anytype) !void {
275 try writer.writeIntBig(u32, self.inner.magic);
276 try writer.writeIntBig(u32, self.inner.length);
277 try writer.writeIntBig(u32, self.inner.version);
278 try writer.writeIntBig(u32, self.inner.flags);
279 try writer.writeIntBig(u32, self.inner.hashOffset);
280 try writer.writeIntBig(u32, self.inner.identOffset);
281 try writer.writeIntBig(u32, self.inner.nSpecialSlots);
282 try writer.writeIntBig(u32, self.inner.nCodeSlots);
283 try writer.writeIntBig(u32, self.inner.codeLimit);
275 try writer.writeInt(u32, self.inner.magic, .big);
276 try writer.writeInt(u32, self.inner.length, .big);
277 try writer.writeInt(u32, self.inner.version, .big);
278 try writer.writeInt(u32, self.inner.flags, .big);
279 try writer.writeInt(u32, self.inner.hashOffset, .big);
280 try writer.writeInt(u32, self.inner.identOffset, .big);
281 try writer.writeInt(u32, self.inner.nSpecialSlots, .big);
282 try writer.writeInt(u32, self.inner.nCodeSlots, .big);
283 try writer.writeInt(u32, self.inner.codeLimit, .big);
284284 try writer.writeByte(self.inner.hashSize);
285285 try writer.writeByte(self.inner.hashType);
286286 try writer.writeByte(self.inner.platform);
287287 try writer.writeByte(self.inner.pageSize);
288 try writer.writeIntBig(u32, self.inner.spare2);
289 try writer.writeIntBig(u32, self.inner.scatterOffset);
290 try writer.writeIntBig(u32, self.inner.teamOffset);
291 try writer.writeIntBig(u32, self.inner.spare3);
292 try writer.writeIntBig(u64, self.inner.codeLimit64);
293 try writer.writeIntBig(u64, self.inner.execSegBase);
294 try writer.writeIntBig(u64, self.inner.execSegLimit);
295 try writer.writeIntBig(u64, self.inner.execSegFlags);
288 try writer.writeInt(u32, self.inner.spare2, .big);
289 try writer.writeInt(u32, self.inner.scatterOffset, .big);
290 try writer.writeInt(u32, self.inner.teamOffset, .big);
291 try writer.writeInt(u32, self.inner.spare3, .big);
292 try writer.writeInt(u64, self.inner.codeLimit64, .big);
293 try writer.writeInt(u64, self.inner.execSegBase, .big);
294 try writer.writeInt(u64, self.inner.execSegLimit, .big);
295 try writer.writeInt(u64, self.inner.execSegFlags, .big);
296296
297297 try writer.writeAll(self.ident);
298298 try writer.writeByte(0);
......@@ -325,9 +325,9 @@ const Requirements = struct {
325325 }
326326
327327 fn write(self: Requirements, writer: anytype) !void {
328 try writer.writeIntBig(u32, macho.CSMAGIC_REQUIREMENTS);
329 try writer.writeIntBig(u32, self.size());
330 try writer.writeIntBig(u32, 0);
328 try writer.writeInt(u32, macho.CSMAGIC_REQUIREMENTS, .big);
329 try writer.writeInt(u32, self.size(), .big);
330 try writer.writeInt(u32, 0, .big);
331331 }
332332};
333333
......@@ -348,8 +348,8 @@ const Entitlements = struct {
348348 }
349349
350350 fn write(self: Entitlements, writer: anytype) !void {
351 try writer.writeIntBig(u32, macho.CSMAGIC_EMBEDDED_ENTITLEMENTS);
352 try writer.writeIntBig(u32, self.size());
351 try writer.writeInt(u32, macho.CSMAGIC_EMBEDDED_ENTITLEMENTS, .big);
352 try writer.writeInt(u32, self.size(), .big);
353353 try writer.writeAll(self.inner);
354354 }
355355};
......@@ -371,8 +371,8 @@ const Signature = struct {
371371 }
372372
373373 fn write(self: Signature, writer: anytype) !void {
374 try writer.writeIntBig(u32, macho.CSMAGIC_BLOBWRAPPER);
375 try writer.writeIntBig(u32, self.size());
374 try writer.writeInt(u32, macho.CSMAGIC_BLOBWRAPPER, .big);
375 try writer.writeInt(u32, self.size(), .big);
376376 }
377377};
378378
src/link/MachO/DwarfInfo.zig+17-17
......@@ -121,19 +121,19 @@ pub const CompileUnit = struct {
121121 address_size: u8,
122122
123123 fn read(reader: anytype) !Header {
124 var length: u64 = try reader.readIntLittle(u32);
124 var length: u64 = try reader.readInt(u32, .little);
125125
126126 const is_64bit = length == 0xffffffff;
127127 if (is_64bit) {
128 length = try reader.readIntLittle(u64);
128 length = try reader.readInt(u64, .little);
129129 }
130130
131 const version = try reader.readIntLittle(u16);
131 const version = try reader.readInt(u16, .little);
132132 const debug_abbrev_offset = if (is_64bit)
133 try reader.readIntLittle(u64)
133 try reader.readInt(u64, .little)
134134 else
135 try reader.readIntLittle(u32);
136 const address_size = try reader.readIntLittle(u8);
135 try reader.readInt(u32, .little);
136 const address_size = try reader.readInt(u8, .little);
137137
138138 return Header{
139139 .is_64bit = is_64bit,
......@@ -251,9 +251,9 @@ pub const Attribute = struct {
251251 },
252252 dwarf.FORM.strp => {
253253 const off = if (cuh.is_64bit)
254 mem.readIntLittle(u64, debug_info[0..8])
254 mem.readInt(u64, debug_info[0..8], .little)
255255 else
256 mem.readIntLittle(u32, debug_info[0..4]);
256 mem.readInt(u32, debug_info[0..4], .little);
257257 return ctx.getString(off);
258258 },
259259 else => return null,
......@@ -267,9 +267,9 @@ pub const Attribute = struct {
267267
268268 return switch (self.form) {
269269 dwarf.FORM.data1 => debug_info[0],
270 dwarf.FORM.data2 => mem.readIntLittle(u16, debug_info[0..2]),
271 dwarf.FORM.data4 => mem.readIntLittle(u32, debug_info[0..4]),
272 dwarf.FORM.data8 => mem.readIntLittle(u64, debug_info[0..8]),
270 dwarf.FORM.data2 => mem.readInt(u16, debug_info[0..2], .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),
273273 dwarf.FORM.udata => try leb.readULEB128(u64, reader),
274274 dwarf.FORM.sdata => try leb.readILEB128(i64, reader),
275275 else => null,
......@@ -281,9 +281,9 @@ pub const Attribute = struct {
281281 const debug_info = self.getDebugInfo(ctx);
282282 return switch (cuh.address_size) {
283283 1 => debug_info[0],
284 2 => mem.readIntLittle(u16, debug_info[0..2]),
285 4 => mem.readIntLittle(u32, debug_info[0..4]),
286 8 => mem.readIntLittle(u64, debug_info[0..8]),
284 2 => mem.readInt(u16, debug_info[0..2], .little),
285 4 => mem.readInt(u32, debug_info[0..4], .little),
286 8 => mem.readInt(u64, debug_info[0..8], .little),
287287 else => unreachable,
288288 };
289289 }
......@@ -380,9 +380,9 @@ fn findFormSize(self: DwarfInfo, form: u64, di_off: usize, cuh: CompileUnit.Head
380380 dwarf.FORM.block,
381381 => {
382382 const len: u64 = switch (form) {
383 dwarf.FORM.block1 => try reader.readIntLittle(u8),
384 dwarf.FORM.block2 => try reader.readIntLittle(u16),
385 dwarf.FORM.block4 => try reader.readIntLittle(u32),
383 dwarf.FORM.block1 => try reader.readInt(u8, .little),
384 dwarf.FORM.block2 => try reader.readInt(u16, .little),
385 dwarf.FORM.block4 => try reader.readInt(u32, .little),
386386 dwarf.FORM.block => try leb.readULEB128(u64, reader),
387387 else => unreachable,
388388 };
src/link/MachO/Relocation.zig+9-9
......@@ -128,7 +128,7 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: []
128128 ), buffer[0..4]),
129129 };
130130 inst.unconditional_branch_immediate.imm26 = @as(u26, @truncate(@as(u28, @bitCast(displacement >> 2))));
131 mem.writeIntLittle(u32, buffer[0..4], inst.toU32());
131 mem.writeInt(u32, buffer[0..4], inst.toU32(), .little);
132132 },
133133 .page, .got_page => {
134134 const source_page = @as(i32, @intCast(source_addr >> 12));
......@@ -142,7 +142,7 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: []
142142 };
143143 inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2));
144144 inst.pc_relative_address.immlo = @as(u2, @truncate(pages));
145 mem.writeIntLittle(u32, buffer[0..4], inst.toU32());
145 mem.writeInt(u32, buffer[0..4], inst.toU32(), .little);
146146 },
147147 .pageoff, .got_pageoff => {
148148 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: []
154154 ), buffer[0..4]),
155155 };
156156 inst.add_subtract_immediate.imm12 = narrowed;
157 mem.writeIntLittle(u32, buffer[0..4], inst.toU32());
157 mem.writeInt(u32, buffer[0..4], inst.toU32(), .little);
158158 } else {
159159 var inst = aarch64.Instruction{
160160 .load_store_register = mem.bytesToValue(meta.TagPayload(
......@@ -176,12 +176,12 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: []
176176 }
177177 };
178178 inst.load_store_register.offset = offset;
179 mem.writeIntLittle(u32, buffer[0..4], inst.toU32());
179 mem.writeInt(u32, buffer[0..4], inst.toU32(), .little);
180180 }
181181 },
182182 .tlv_initializer, .unsigned => switch (self.length) {
183 2 => mem.writeIntLittle(u32, buffer[0..4], @as(u32, @truncate(@as(u64, @bitCast(target_addr))))),
184 3 => mem.writeIntLittle(u64, buffer[0..8], @as(u64, @bitCast(target_addr))),
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),
185185 else => unreachable,
186186 },
187187 .got, .signed, .tlv => unreachable, // Invalid target architecture.
......@@ -192,15 +192,15 @@ fn resolveX8664(self: Relocation, source_addr: u64, target_addr: i64, code: []u8
192192 switch (self.type) {
193193 .branch, .got, .tlv, .signed => {
194194 const displacement = @as(i32, @intCast(@as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr)) - 4));
195 mem.writeIntLittle(u32, code[self.offset..][0..4], @as(u32, @bitCast(displacement)));
195 mem.writeInt(u32, code[self.offset..][0..4], @as(u32, @bitCast(displacement)), .little);
196196 },
197197 .tlv_initializer, .unsigned => {
198198 switch (self.length) {
199199 2 => {
200 mem.writeIntLittle(u32, code[self.offset..][0..4], @as(u32, @truncate(@as(u64, @bitCast(target_addr)))));
200 mem.writeInt(u32, code[self.offset..][0..4], @as(u32, @truncate(@as(u64, @bitCast(target_addr)))), .little);
201201 },
202202 3 => {
203 mem.writeIntLittle(u64, code[self.offset..][0..8], @as(u64, @bitCast(target_addr)));
203 mem.writeInt(u64, code[self.offset..][0..8], @as(u64, @bitCast(target_addr)), .little);
204204 },
205205 else => unreachable,
206206 }
src/link/MachO/UnwindInfo.zig+1-1
......@@ -149,7 +149,7 @@ const Page = struct {
149149
150150 for (page.page_encodings[0..page.page_encodings_count]) |record_id| {
151151 const enc = info.records.items[record_id].compactUnwindEncoding;
152 try writer.writeIntLittle(u32, enc);
152 try writer.writeInt(u32, enc, .little);
153153 }
154154
155155 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 {
209209 const writer = buffer.writer();
210210
211211 for (eh_records.values()) |record| {
212 try writer.writeIntLittle(u32, record.size);
212 try writer.writeInt(u32, record.size, .little);
213213 try buffer.appendSlice(record.data);
214214 }
215215
......@@ -259,7 +259,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
259259 base_offset: u64,
260260 }) u64 {
261261 assert(rec.tag == .fde);
262 const addend = mem.readIntLittle(i64, rec.data[4..][0..8]);
262 const addend = mem.readInt(i64, rec.data[4..][0..8], .little);
263263 return @as(u64, @intCast(@as(i64, @intCast(ctx.base_addr + ctx.base_offset + 8)) + addend));
264264 }
265265
......@@ -269,7 +269,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
269269 }) !void {
270270 assert(rec.tag == .fde);
271271 const addend = @as(i64, @intCast(value)) - @as(i64, @intCast(ctx.base_addr + ctx.base_offset + 8));
272 mem.writeIntLittle(i64, rec.data[4..][0..8], addend);
272 mem.writeInt(i64, rec.data[4..][0..8], addend, .little);
273273 }
274274
275275 pub fn getPersonalityPointerReloc(
......@@ -343,13 +343,13 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
343343 const target_addr = macho_file.getGotEntryAddress(target).?;
344344 const result = math.cast(i32, @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr))) orelse
345345 return error.Overflow;
346 mem.writeIntLittle(i32, rec.data[rel_offset..][0..4], result);
346 mem.writeInt(i32, rec.data[rel_offset..][0..4], result, .little);
347347 },
348348 .ARM64_RELOC_UNSIGNED => {
349349 assert(rel.r_extern == 1);
350350 const target_addr = Atom.getRelocTargetAddress(macho_file, target, false);
351351 const result = @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr));
352 mem.writeIntLittle(i64, rec.data[rel_offset..][0..8], @as(i64, @intCast(result)));
352 mem.writeInt(i64, rec.data[rel_offset..][0..8], @as(i64, @intCast(result)), .little);
353353 },
354354 else => unreachable,
355355 }
......@@ -359,10 +359,10 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
359359 switch (rel_type) {
360360 .X86_64_RELOC_GOT => {
361361 const target_addr = macho_file.getGotEntryAddress(target).?;
362 const addend = mem.readIntLittle(i32, rec.data[rel_offset..][0..4]);
362 const addend = mem.readInt(i32, rec.data[rel_offset..][0..4], .little);
363363 const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend));
364364 const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0);
365 mem.writeIntLittle(i32, rec.data[rel_offset..][0..4], disp);
365 mem.writeInt(i32, rec.data[rel_offset..][0..4], disp, .little);
366366 },
367367 else => unreachable,
368368 }
......@@ -375,7 +375,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
375375 pub fn getCiePointerSource(rec: Record, object_id: u32, macho_file: *MachO, offset: u32) u32 {
376376 assert(rec.tag == .fde);
377377 const cpu_arch = macho_file.base.options.target.cpu.arch;
378 const addend = mem.readIntLittle(u32, rec.data[0..4]);
378 const addend = mem.readInt(u32, rec.data[0..4], .little);
379379 switch (cpu_arch) {
380380 .aarch64 => {
381381 const relocs = getRelocs(macho_file, object_id, offset);
......@@ -397,12 +397,12 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
397397
398398 pub fn getCiePointer(rec: Record) u32 {
399399 assert(rec.tag == .fde);
400 return mem.readIntLittle(u32, rec.data[0..4]);
400 return mem.readInt(u32, rec.data[0..4], .little);
401401 }
402402
403403 pub fn setCiePointer(rec: *Record, ptr: u32) void {
404404 assert(rec.tag == .fde);
405 mem.writeIntLittle(u32, rec.data[0..4], ptr);
405 mem.writeInt(u32, rec.data[0..4], ptr, .little);
406406 }
407407
408408 pub fn getAugmentationString(rec: Record) []const u8 {
......@@ -509,14 +509,14 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
509509 if (enc == EH_PE.omit) return null;
510510
511511 var ptr: i64 = switch (enc & 0x0F) {
512 EH_PE.absptr => @as(i64, @bitCast(try reader.readIntLittle(u64))),
513 EH_PE.udata2 => @as(i16, @bitCast(try reader.readIntLittle(u16))),
514 EH_PE.udata4 => @as(i32, @bitCast(try reader.readIntLittle(u32))),
515 EH_PE.udata8 => @as(i64, @bitCast(try reader.readIntLittle(u64))),
512 EH_PE.absptr => @as(i64, @bitCast(try reader.readInt(u64, .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))),
515 EH_PE.udata8 => @as(i64, @bitCast(try reader.readInt(u64, .little))),
516516 EH_PE.uleb128 => @as(i64, @bitCast(try leb.readULEB128(u64, reader))),
517 EH_PE.sdata2 => try reader.readIntLittle(i16),
518 EH_PE.sdata4 => try reader.readIntLittle(i32),
519 EH_PE.sdata8 => try reader.readIntLittle(i64),
517 EH_PE.sdata2 => try reader.readInt(i16, .little),
518 EH_PE.sdata4 => try reader.readInt(i32, .little),
519 EH_PE.sdata8 => try reader.readInt(i64, .little),
520520 EH_PE.sleb128 => try leb.readILEB128(i64, reader),
521521 else => return null,
522522 };
......@@ -552,14 +552,14 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type {
552552 }
553553
554554 switch (enc & 0x0F) {
555 EH_PE.absptr => try writer.writeIntLittle(u64, @as(u64, @bitCast(actual))),
556 EH_PE.udata2 => try writer.writeIntLittle(u16, @as(u16, @bitCast(@as(i16, @intCast(actual))))),
557 EH_PE.udata4 => try writer.writeIntLittle(u32, @as(u32, @bitCast(@as(i32, @intCast(actual))))),
558 EH_PE.udata8 => try writer.writeIntLittle(u64, @as(u64, @bitCast(actual))),
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),
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),
559559 EH_PE.uleb128 => try leb.writeULEB128(writer, @as(u64, @bitCast(actual))),
560 EH_PE.sdata2 => try writer.writeIntLittle(i16, @as(i16, @intCast(actual))),
561 EH_PE.sdata4 => try writer.writeIntLittle(i32, @as(i32, @intCast(actual))),
562 EH_PE.sdata8 => try writer.writeIntLittle(i64, actual),
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),
562 EH_PE.sdata8 => try writer.writeInt(i64, actual, .little),
563563 EH_PE.sleb128 => try leb.writeILEB128(writer, actual),
564564 else => unreachable,
565565 }
......@@ -586,13 +586,13 @@ pub const Iterator = struct {
586586 var stream = std.io.fixedBufferStream(it.data[it.pos..]);
587587 const reader = stream.reader();
588588
589 var size = try reader.readIntLittle(u32);
589 var size = try reader.readInt(u32, .little);
590590 if (size == 0xFFFFFFFF) {
591591 log.debug("MachO doesn't support 64bit DWARF CFI __eh_frame records", .{});
592592 return error.BadDwarfCfi;
593593 }
594594
595 const id = try reader.readIntLittle(u32);
595 const id = try reader.readInt(u32, .little);
596596 const tag: EhFrameRecordTag = if (id == 0) .cie else .fde;
597597 const offset: u32 = 4;
598598 const record = EhFrameRecord(false){
src/link/MachO/stubs.zig+19-19
......@@ -53,7 +53,7 @@ pub fn writeStubHelperPreambleCode(args: struct {
5353 args.dyld_private_addr,
5454 0,
5555 );
56 try writer.writeIntLittle(i32, disp);
56 try writer.writeInt(i32, disp, .little);
5757 }
5858 try writer.writeAll(&.{ 0x41, 0x53, 0xff, 0x25 });
5959 {
......@@ -62,37 +62,37 @@ pub fn writeStubHelperPreambleCode(args: struct {
6262 args.dyld_stub_binder_got_addr,
6363 0,
6464 );
65 try writer.writeIntLittle(i32, disp);
65 try writer.writeInt(i32, disp, .little);
6666 }
6767 },
6868 .aarch64 => {
6969 {
7070 const pages = Relocation.calcNumberOfPages(args.source_addr, args.dyld_private_addr);
71 try writer.writeIntLittle(u32, aarch64.Instruction.adrp(.x17, pages).toU32());
71 try writer.writeInt(u32, aarch64.Instruction.adrp(.x17, pages).toU32(), .little);
7272 }
7373 {
7474 const off = try Relocation.calcPageOffset(args.dyld_private_addr, .arithmetic);
75 try writer.writeIntLittle(u32, aarch64.Instruction.add(.x17, .x17, off, false).toU32());
75 try writer.writeInt(u32, aarch64.Instruction.add(.x17, .x17, off, false).toU32(), .little);
7676 }
77 try writer.writeIntLittle(u32, aarch64.Instruction.stp(
77 try writer.writeInt(u32, aarch64.Instruction.stp(
7878 .x16,
7979 .x17,
8080 aarch64.Register.sp,
8181 aarch64.Instruction.LoadStorePairOffset.pre_index(-16),
82 ).toU32());
82 ).toU32(), .little);
8383 {
8484 const pages = Relocation.calcNumberOfPages(args.source_addr + 12, args.dyld_stub_binder_got_addr);
85 try writer.writeIntLittle(u32, aarch64.Instruction.adrp(.x16, pages).toU32());
85 try writer.writeInt(u32, aarch64.Instruction.adrp(.x16, pages).toU32(), .little);
8686 }
8787 {
8888 const off = try Relocation.calcPageOffset(args.dyld_stub_binder_got_addr, .load_store_64);
89 try writer.writeIntLittle(u32, aarch64.Instruction.ldr(
89 try writer.writeInt(u32, aarch64.Instruction.ldr(
9090 .x16,
9191 .x16,
9292 aarch64.Instruction.LoadStoreOffset.imm(off),
93 ).toU32());
93 ).toU32(), .little);
9494 }
95 try writer.writeIntLittle(u32, aarch64.Instruction.br(.x16).toU32());
95 try writer.writeInt(u32, aarch64.Instruction.br(.x16).toU32(), .little);
9696 },
9797 else => unreachable,
9898 }
......@@ -108,7 +108,7 @@ pub fn writeStubHelperCode(args: struct {
108108 try writer.writeAll(&.{ 0x68, 0x0, 0x0, 0x0, 0x0, 0xe9 });
109109 {
110110 const disp = try Relocation.calcPcRelativeDisplacementX86(args.source_addr + 6, args.target_addr, 0);
111 try writer.writeIntLittle(i32, disp);
111 try writer.writeInt(i32, disp, .little);
112112 }
113113 },
114114 .aarch64 => {
......@@ -117,13 +117,13 @@ pub fn writeStubHelperCode(args: struct {
117117 const div_res = try std.math.divExact(u64, stub_size - @sizeOf(u32), 4);
118118 break :blk std.math.cast(u18, div_res) orelse return error.Overflow;
119119 };
120 try writer.writeIntLittle(u32, aarch64.Instruction.ldrLiteral(
120 try writer.writeInt(u32, aarch64.Instruction.ldrLiteral(
121121 .w16,
122122 literal,
123 ).toU32());
123 ).toU32(), .little);
124124 {
125125 const disp = try Relocation.calcPcRelativeDisplacementArm64(args.source_addr + 4, args.target_addr);
126 try writer.writeIntLittle(u32, aarch64.Instruction.b(disp).toU32());
126 try writer.writeInt(u32, aarch64.Instruction.b(disp).toU32(), .little);
127127 }
128128 try writer.writeAll(&.{ 0x0, 0x0, 0x0, 0x0 });
129129 },
......@@ -141,23 +141,23 @@ pub fn writeStubCode(args: struct {
141141 try writer.writeAll(&.{ 0xff, 0x25 });
142142 {
143143 const disp = try Relocation.calcPcRelativeDisplacementX86(args.source_addr + 2, args.target_addr, 0);
144 try writer.writeIntLittle(i32, disp);
144 try writer.writeInt(i32, disp, .little);
145145 }
146146 },
147147 .aarch64 => {
148148 {
149149 const pages = Relocation.calcNumberOfPages(args.source_addr, args.target_addr);
150 try writer.writeIntLittle(u32, aarch64.Instruction.adrp(.x16, pages).toU32());
150 try writer.writeInt(u32, aarch64.Instruction.adrp(.x16, pages).toU32(), .little);
151151 }
152152 {
153153 const off = try Relocation.calcPageOffset(args.target_addr, .load_store_64);
154 try writer.writeIntLittle(u32, aarch64.Instruction.ldr(
154 try writer.writeInt(u32, aarch64.Instruction.ldr(
155155 .x16,
156156 .x16,
157157 aarch64.Instruction.LoadStoreOffset.imm(off),
158 ).toU32());
158 ).toU32(), .little);
159159 }
160 try writer.writeIntLittle(u32, aarch64.Instruction.br(.x16).toU32());
160 try writer.writeInt(u32, aarch64.Instruction.br(.x16).toU32(), .little);
161161 },
162162 else => unreachable,
163163 }
src/link/MachO/thunks.zig+3-3
......@@ -349,10 +349,10 @@ pub fn writeThunkCode(macho_file: *MachO, thunk: *const Thunk, writer: anytype)
349349 .atom => macho_file.getSymbol(target).n_value,
350350 };
351351 const pages = Relocation.calcNumberOfPages(source_addr, target_addr);
352 try writer.writeIntLittle(u32, aarch64.Instruction.adrp(.x16, pages).toU32());
352 try writer.writeInt(u32, aarch64.Instruction.adrp(.x16, pages).toU32(), .little);
353353 const off = try Relocation.calcPageOffset(target_addr, .arithmetic);
354 try writer.writeIntLittle(u32, aarch64.Instruction.add(.x16, .x16, off, false).toU32());
355 try writer.writeIntLittle(u32, aarch64.Instruction.br(.x16).toU32());
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);
356356 }
357357}
358358
src/link/MachO/zld.zig+2-2
......@@ -796,7 +796,7 @@ fn writePointerEntries(macho_file: *MachO, sect_id: u8, table: anytype) !void {
796796 defer buffer.deinit();
797797 for (table.entries.items) |entry| {
798798 const sym = macho_file.getSymbol(entry);
799 buffer.writer().writeIntLittle(u64, sym.n_value) catch unreachable;
799 buffer.writer().writeInt(u64, sym.n_value, .little) catch unreachable;
800800 }
801801 log.debug("writing __DATA_CONST,__got contents at file offset 0x{x}", .{header.offset});
802802 try macho_file.base.file.?.pwriteAll(buffer.items, header.offset);
......@@ -880,7 +880,7 @@ fn writeLaSymbolPtrs(macho_file: *MachO) !void {
880880 for (0..macho_file.stub_table.count()) |index| {
881881 const target_addr = stub_helper_header.addr + stubs.stubHelperPreambleSize(cpu_arch) +
882882 stubs.stubHelperSize(cpu_arch) * index;
883 buffer.writer().writeIntLittle(u64, target_addr) catch unreachable;
883 buffer.writer().writeInt(u64, target_addr, .little) catch unreachable;
884884 }
885885
886886 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 {
348348 // every 'z' starts with 0
349349 try a.append(0);
350350 // path component value of '/'
351 try a.writer().writeIntBig(u16, 1);
351 try a.writer().writeInt(u16, 1, .big);
352352
353353 // getting the full file path
354354 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
381381 var it = std.mem.tokenizeScalar(u8, path, sep);
382382 while (it.next()) |component| {
383383 if (self.file_segments.get(component)) |num| {
384 try a.writer().writeIntBig(u16, num);
384 try a.writer().writeInt(u16, num, .big);
385385 } else {
386386 self.file_segments_i += 1;
387387 try self.file_segments.put(self.base.allocator, component, self.file_segments_i);
388 try a.writer().writeIntBig(u16, self.file_segments_i);
388 try a.writer().writeInt(u16, self.file_segments_i, .big);
389389 }
390390 }
391391}
......@@ -607,7 +607,7 @@ pub fn changeLine(l: *std.ArrayList(u8), delta_line: i32) !void {
607607 try l.append(toadd);
608608 } else if (delta_line != 0) {
609609 try l.append(0);
610 try l.writer().writeIntBig(i32, delta_line);
610 try l.writer().writeInt(i32, delta_line, .big);
611611 }
612612}
613613
......@@ -922,7 +922,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No
922922 @memcpy(hdr_slice, self.hdr.toU8s()[0..hdr_size]);
923923 // write the fat header for 64 bit entry points
924924 if (self.sixtyfour_bit) {
925 mem.writeIntSliceBig(u64, hdr_buf[32..40], self.entry_val.?);
925 mem.writeInt(u64, hdr_buf[32..40], self.entry_val.?, .big);
926926 }
927927 // perform the relocs
928928 {
......@@ -1311,9 +1311,9 @@ pub fn writeSym(self: *Plan9, w: anytype, sym: aout.Sym) !void {
13111311 // log.debug("write sym{{name: {s}, value: {x}}}", .{ sym.name, sym.value });
13121312 if (sym.type == .bad) return; // we don't want to write free'd symbols
13131313 if (!self.sixtyfour_bit) {
1314 try w.writeIntBig(u32, @as(u32, @intCast(sym.value)));
1314 try w.writeInt(u32, @as(u32, @intCast(sym.value)), .big);
13151315 } else {
1316 try w.writeIntBig(u64, sym.value);
1316 try w.writeInt(u64, sym.value, .big);
13171317 }
13181318 try w.writeByte(@intFromEnum(sym.type));
13191319 try w.writeAll(sym.name);
src/link/Plan9/aout.zig+1-1
......@@ -21,7 +21,7 @@ pub const ExecHdr = extern struct {
2121 var buf: [40]u8 = undefined;
2222 var i: u8 = 0;
2323 inline for (std.meta.fields(@This())) |f| {
24 std.mem.writeIntSliceBig(u32, buf[i..][0..4], @field(self, f.name));
24 std.mem.writeInt(u32, buf[i..][0..4], @field(self, f.name), .big);
2525 i += 4;
2626 }
2727 return buf;
src/link/Wasm.zig+5-5
......@@ -2371,7 +2371,7 @@ fn setupErrorsLen(wasm: *Wasm) !void {
23712371 atom.deinit(wasm);
23722372 break :blk index;
23732373 } else new_atom: {
2374 const atom_index = @as(Atom.Index, @intCast(wasm.managed_atoms.items.len));
2374 const atom_index: Atom.Index = @intCast(wasm.managed_atoms.items.len);
23752375 try wasm.symbol_atom.put(wasm.base.allocator, loc, atom_index);
23762376 try wasm.managed_atoms.append(wasm.base.allocator, undefined);
23772377 break :new_atom atom_index;
......@@ -2380,7 +2380,7 @@ fn setupErrorsLen(wasm: *Wasm) !void {
23802380 atom.* = Atom.empty;
23812381 atom.sym_index = loc.index;
23822382 atom.size = 2;
2383 try atom.code.writer(wasm.base.allocator).writeIntLittle(u16, @as(u16, @intCast(errors_len)));
2383 try atom.code.writer(wasm.base.allocator).writeInt(u16, @intCast(errors_len), .little);
23842384
23852385 try wasm.parseAtom(atom_index, .{ .data = .read_only });
23862386}
......@@ -3151,7 +3151,7 @@ fn populateErrorNameTable(wasm: *Wasm) !void {
31513151 const offset = @as(u32, @intCast(atom.code.items.len));
31523152 // first we create the data for the slice of the name
31533153 try atom.code.appendNTimes(wasm.base.allocator, 0, 4); // ptr to name, will be relocated
3154 try atom.code.writer(wasm.base.allocator).writeIntLittle(u32, len - 1);
3154 try atom.code.writer(wasm.base.allocator).writeInt(u32, len - 1, .little);
31553155 // create relocation to the error name
31563156 try atom.relocs.append(wasm.base.allocator, .{
31573157 .index = names_atom.sym_index,
......@@ -4286,11 +4286,11 @@ fn emitInit(writer: anytype, init_expr: std.wasm.InitExpression) !void {
42864286 },
42874287 .f32_const => |val| {
42884288 try writer.writeByte(std.wasm.opcode(.f32_const));
4289 try writer.writeIntLittle(u32, @as(u32, @bitCast(val)));
4289 try writer.writeInt(u32, @bitCast(val), .little);
42904290 },
42914291 .f64_const => |val| {
42924292 try writer.writeByte(std.wasm.opcode(.f64_const));
4293 try writer.writeIntLittle(u64, @as(u64, @bitCast(val)));
4293 try writer.writeInt(u64, @bitCast(val), .little);
42944294 },
42954295 .global_get => |val| {
42964296 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
141141 const size_trimmed = mem.trim(u8, &archive.header.ar_size, " ");
142142 const sym_tab_size = try std.fmt.parseInt(u32, size_trimmed, 10);
143143
144 const num_symbols = try reader.readIntBig(u32);
144 const num_symbols = try reader.readInt(u32, .big);
145145 const symbol_positions = try allocator.alloc(u32, num_symbols);
146146 defer allocator.free(symbol_positions);
147147 for (symbol_positions) |*index| {
148 index.* = try reader.readIntBig(u32);
148 index.* = try reader.readInt(u32, .big);
149149 }
150150
151151 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 {
114114 .R_WASM_GLOBAL_INDEX_I32,
115115 .R_WASM_MEMORY_ADDR_I32,
116116 .R_WASM_SECTION_OFFSET_I32,
117 => std.mem.writeIntLittle(u32, atom.code.items[reloc.offset..][0..4], @as(u32, @intCast(value))),
117 => std.mem.writeInt(u32, atom.code.items[reloc.offset..][0..4], @as(u32, @intCast(value)), .little),
118118 .R_WASM_TABLE_INDEX_I64,
119119 .R_WASM_MEMORY_ADDR_I64,
120 => std.mem.writeIntLittle(u64, atom.code.items[reloc.offset..][0..8], value),
120 => std.mem.writeInt(u64, atom.code.items[reloc.offset..][0..8], value, .little),
121121 .R_WASM_GLOBAL_INDEX_LEB,
122122 .R_WASM_EVENT_INDEX_LEB,
123123 .R_WASM_FUNCTION_INDEX_LEB,
src/link/Wasm/Object.zig+1-1
......@@ -344,7 +344,7 @@ fn Parser(comptime ReaderType: type) type {
344344 fn parseObject(parser: *ObjectParser, gpa: Allocator, is_object_file: *bool) Error!void {
345345 errdefer parser.object.deinit(gpa);
346346 try parser.verifyMagicBytes();
347 const version = try parser.reader.reader().readIntLittle(u32);
347 const version = try parser.reader.reader().readInt(u32, .little);
348348
349349 parser.object.version = version;
350350 var relocatable_data = std.ArrayList(RelocatableData).init(gpa);
src/resinator/ani.zig+2-2
......@@ -25,14 +25,14 @@ fn getAniheaderFlags(reader: anytype) !u32 {
2525 const riff_header = try reader.readBytesNoEof(4);
2626 if (!std.mem.eql(u8, &riff_header, "RIFF")) return error.InvalidFormat;
2727
28 _ = try reader.readIntLittle(u32); // size of RIFF chunk
28 _ = try reader.readInt(u32, .little); // size of RIFF chunk
2929
3030 const form_type = try reader.readBytesNoEof(4);
3131 if (!std.mem.eql(u8, &form_type, "ACON")) return error.InvalidFormat;
3232
3333 while (true) {
3434 const chunk_id = try reader.readBytesNoEof(4);
35 const chunk_len = try reader.readIntLittle(u32);
35 const chunk_len = try reader.readInt(u32, .little);
3636 if (!std.mem.eql(u8, &chunk_id, "anih")) {
3737 // TODO: Move file cursor instead of skipBytes
3838 try reader.skipBytes(chunk_len, .{});
src/resinator/bmp.zig+8-6
......@@ -20,8 +20,10 @@
2020
2121const std = @import("std");
2222const BitmapHeader = @import("ico.zig").BitmapHeader;
23const builtin = @import("builtin");
24const native_endian = builtin.cpu.arch.endian();
2325
24pub const windows_format_id = std.mem.readIntNative(u16, "BM");
26pub const windows_format_id = std.mem.readInt(u16, "BM", native_endian);
2527pub const file_header_len = 14;
2628
2729pub const ReadError = error{
......@@ -89,19 +91,19 @@ pub fn read(reader: anytype, max_size: u64) ReadError!BitmapInfo {
8991 var bitmap_info: BitmapInfo = undefined;
9092 const file_header = reader.readBytesNoEof(file_header_len) catch return error.UnexpectedEOF;
9193
92 const id = std.mem.readIntNative(u16, file_header[0..2]);
94 const id = std.mem.readInt(u16, file_header[0..2], native_endian);
9395 if (id != windows_format_id) return error.InvalidFileHeader;
9496
95 bitmap_info.pixel_data_offset = std.mem.readIntLittle(u32, file_header[10..14]);
97 bitmap_info.pixel_data_offset = std.mem.readInt(u32, file_header[10..14], .little);
9698 if (bitmap_info.pixel_data_offset > max_size) return error.ImpossiblePixelDataOffset;
9799
98 bitmap_info.dib_header_size = reader.readIntLittle(u32) catch return error.UnexpectedEOF;
100 bitmap_info.dib_header_size = reader.readInt(u32, .little) catch return error.UnexpectedEOF;
99101 if (bitmap_info.pixel_data_offset < file_header_len + bitmap_info.dib_header_size) return error.ImpossiblePixelDataOffset;
100102 const dib_version = BitmapHeader.Version.get(bitmap_info.dib_header_size);
101103 switch (dib_version) {
102104 .@"nt3.1", .@"nt4.0", .@"nt5.0" => {
103105 var dib_header_buf: [@sizeOf(BITMAPINFOHEADER)]u8 align(@alignOf(BITMAPINFOHEADER)) = undefined;
104 std.mem.writeIntLittle(u32, dib_header_buf[0..4], bitmap_info.dib_header_size);
106 std.mem.writeInt(u32, dib_header_buf[0..4], bitmap_info.dib_header_size, .little);
105107 reader.readNoEof(dib_header_buf[4..]) catch return error.UnexpectedEOF;
106108 var dib_header: *BITMAPINFOHEADER = @ptrCast(&dib_header_buf);
107109 structFieldsLittleToNative(BITMAPINFOHEADER, dib_header);
......@@ -116,7 +118,7 @@ pub fn read(reader: anytype, max_size: u64) ReadError!BitmapInfo {
116118 },
117119 .@"win2.0" => {
118120 var dib_header_buf: [@sizeOf(BITMAPCOREHEADER)]u8 align(@alignOf(BITMAPCOREHEADER)) = undefined;
119 std.mem.writeIntLittle(u32, dib_header_buf[0..4], bitmap_info.dib_header_size);
121 std.mem.writeInt(u32, dib_header_buf[0..4], bitmap_info.dib_header_size, .little);
120122 reader.readNoEof(dib_header_buf[4..]) catch return error.UnexpectedEOF;
121123 var dib_header: *BITMAPCOREHEADER = @ptrCast(&dib_header_buf);
122124 structFieldsLittleToNative(BITMAPCOREHEADER, dib_header);
src/resinator/compile.zig+95-94
......@@ -28,6 +28,7 @@ const windows1252 = @import("windows1252.zig");
2828const lang = @import("lang.zig");
2929const code_pages = @import("code_pages.zig");
3030const errors = @import("errors.zig");
31const native_endian = builtin.cpu.arch.endian();
3132
3233pub const CompileOptions = struct {
3334 cwd: std.fs.Dir,
......@@ -584,8 +585,8 @@ pub const Compiler = struct {
584585 // > resource if a RESDIR structure contains information about a cursor.
585586 // where LOCALHEADER is `struct { WORD xHotSpot; WORD yHotSpot; }`
586587 if (icon_dir.image_type == .cursor) {
587 try writer.writeIntLittle(u16, entry.type_specific_data.cursor.hotspot_x);
588 try writer.writeIntLittle(u16, entry.type_specific_data.cursor.hotspot_y);
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);
589590 }
590591
591592 try file.seekTo(entry.data_offset_from_start_of_file);
......@@ -666,7 +667,7 @@ pub const Compiler = struct {
666667 },
667668 .dib => {
668669 var bitmap_header: *ico.BitmapHeader = @ptrCast(@alignCast(&header_bytes));
669 if (builtin.cpu.arch.endian() == .Big) {
670 if (native_endian == .big) {
670671 std.mem.byteSwapAllFields(ico.BitmapHeader, bitmap_header);
671672 }
672673 const bitmap_version = ico.BitmapHeader.Version.get(bitmap_header.bcSize);
......@@ -777,7 +778,7 @@ pub const Compiler = struct {
777778 if (bitmap_info.getActualPaletteByteLen() > bitmap_info.getExpectedPaletteByteLen()) {
778779 const num_ignored_bytes = bitmap_info.getActualPaletteByteLen() - bitmap_info.getExpectedPaletteByteLen();
779780 var number_as_bytes: [8]u8 = undefined;
780 std.mem.writeIntNative(u64, &number_as_bytes, num_ignored_bytes);
781 std.mem.writeInt(u64, &number_as_bytes, num_ignored_bytes, native_endian);
781782 const value_string_index = try self.diagnostics.putString(&number_as_bytes);
782783 try self.addErrorDetails(.{
783784 .err = .bmp_ignored_palette_bytes,
......@@ -792,8 +793,8 @@ pub const Compiler = struct {
792793 const max_missing_bytes = 4096;
793794 if (num_padding_bytes > max_missing_bytes) {
794795 var numbers_as_bytes: [16]u8 = undefined;
795 std.mem.writeIntNative(u64, numbers_as_bytes[0..8], num_padding_bytes);
796 std.mem.writeIntNative(u64, numbers_as_bytes[8..16], max_missing_bytes);
796 std.mem.writeInt(u64, numbers_as_bytes[0..8], num_padding_bytes, native_endian);
797 std.mem.writeInt(u64, numbers_as_bytes[8..16], max_missing_bytes, native_endian);
797798 const values_string_index = try self.diagnostics.putString(&numbers_as_bytes);
798799 try self.addErrorDetails(.{
799800 .err = .bmp_too_many_missing_palette_bytes,
......@@ -809,7 +810,7 @@ pub const Compiler = struct {
809810 }
810811
811812 var number_as_bytes: [8]u8 = undefined;
812 std.mem.writeIntNative(u64, &number_as_bytes, num_padding_bytes);
813 std.mem.writeInt(u64, &number_as_bytes, num_padding_bytes, native_endian);
813814 const value_string_index = try self.diagnostics.putString(&number_as_bytes);
814815 try self.addErrorDetails(.{
815816 .err = .bmp_missing_palette_bytes,
......@@ -820,7 +821,7 @@ pub const Compiler = struct {
820821 const pixel_data_len = bitmap_info.getPixelDataLen(file_size);
821822 if (pixel_data_len > 0) {
822823 const miscompiled_bytes = @min(pixel_data_len, num_padding_bytes);
823 std.mem.writeIntNative(u64, &number_as_bytes, miscompiled_bytes);
824 std.mem.writeInt(u64, &number_as_bytes, miscompiled_bytes, native_endian);
824825 const miscompiled_bytes_string_index = try self.diagnostics.putString(&number_as_bytes);
825826 try self.addErrorDetails(.{
826827 .err = .rc_would_miscompile_bmp_palette_padding,
......@@ -984,8 +985,8 @@ pub const Compiler = struct {
984985 pub fn write(self: Data, writer: anytype) !void {
985986 switch (self) {
986987 .number => |number| switch (number.is_long) {
987 false => try writer.writeIntLittle(WORD, number.asWord()),
988 true => try writer.writeIntLittle(DWORD, number.value),
988 false => try writer.writeInt(WORD, number.asWord(), .little),
989 true => try writer.writeInt(DWORD, number.value, .little),
989990 },
990991 .ascii_string => |ascii_string| {
991992 try writer.writeAll(ascii_string);
......@@ -1315,9 +1316,9 @@ pub const Compiler = struct {
13151316
13161317 try data_writer.writeByte(modifiers.value);
13171318 try data_writer.writeByte(0); // padding
1318 try data_writer.writeIntLittle(u16, key);
1319 try data_writer.writeIntLittle(u16, cmd_id.asWord());
1320 try data_writer.writeIntLittle(u16, 0); // padding
1319 try data_writer.writeInt(u16, key, .little);
1320 try data_writer.writeInt(u16, cmd_id.asWord(), .little);
1321 try data_writer.writeInt(u16, 0, .little); // padding
13211322 }
13221323 }
13231324
......@@ -1700,34 +1701,34 @@ pub const Compiler = struct {
17001701 if (node.help_id == null) break :help_id 0;
17011702 break :help_id evaluateNumberExpression(node.help_id.?, self.source, self.input_code_pages).value;
17021703 };
1703 try data_writer.writeIntLittle(u16, 1); // version number, always 1
1704 try data_writer.writeIntLittle(u16, 0xFFFF); // signature, always 0xFFFF
1705 try data_writer.writeIntLittle(u32, help_id);
1706 try data_writer.writeIntLittle(u32, optional_statement_values.exstyle);
1707 try data_writer.writeIntLittle(u32, optional_statement_values.style);
1704 try data_writer.writeInt(u16, 1, .little); // version number, always 1
1705 try data_writer.writeInt(u16, 0xFFFF, .little); // signature, always 0xFFFF
1706 try data_writer.writeInt(u32, help_id, .little);
1707 try data_writer.writeInt(u32, optional_statement_values.exstyle, .little);
1708 try data_writer.writeInt(u32, optional_statement_values.style, .little);
17081709 } else {
1709 try data_writer.writeIntLittle(u32, optional_statement_values.style);
1710 try data_writer.writeIntLittle(u32, optional_statement_values.exstyle);
1710 try data_writer.writeInt(u32, optional_statement_values.style, .little);
1711 try data_writer.writeInt(u32, optional_statement_values.exstyle, .little);
17111712 }
17121713 // This limit is enforced by the parser, so we know the number of controls
17131714 // is within the range of a u16.
1714 try data_writer.writeIntLittle(u16, @as(u16, @intCast(node.controls.len)));
1715 try data_writer.writeIntLittle(u16, x.asWord());
1716 try data_writer.writeIntLittle(u16, y.asWord());
1717 try data_writer.writeIntLittle(u16, width.asWord());
1718 try data_writer.writeIntLittle(u16, height.asWord());
1715 try data_writer.writeInt(u16, @as(u16, @intCast(node.controls.len)), .little);
1716 try data_writer.writeInt(u16, x.asWord(), .little);
1717 try data_writer.writeInt(u16, y.asWord(), .little);
1718 try data_writer.writeInt(u16, width.asWord(), .little);
1719 try data_writer.writeInt(u16, height.asWord(), .little);
17191720
17201721 // Menu
17211722 if (optional_statement_values.menu) |menu| {
17221723 try menu.write(data_writer);
17231724 } else {
1724 try data_writer.writeIntLittle(u16, 0);
1725 try data_writer.writeInt(u16, 0, .little);
17251726 }
17261727 // Class
17271728 if (optional_statement_values.class) |class| {
17281729 try class.write(data_writer);
17291730 } else {
1730 try data_writer.writeIntLittle(u16, 0);
1731 try data_writer.writeInt(u16, 0, .little);
17311732 }
17321733 // Caption
17331734 if (optional_statement_values.caption) |caption| {
......@@ -1735,7 +1736,7 @@ pub const Compiler = struct {
17351736 defer self.allocator.free(parsed);
17361737 try data_writer.writeAll(std.mem.sliceAsBytes(parsed[0 .. parsed.len + 1]));
17371738 } else {
1738 try data_writer.writeIntLittle(u16, 0);
1739 try data_writer.writeInt(u16, 0, .little);
17391740 }
17401741 // Font
17411742 if (optional_statement_values.font) |font| {
......@@ -1786,18 +1787,18 @@ pub const Compiler = struct {
17861787 switch (resource) {
17871788 .dialog => {
17881789 // Note: Reverse order from DIALOGEX
1789 try data_writer.writeIntLittle(u32, style);
1790 try data_writer.writeIntLittle(u32, exstyle);
1790 try data_writer.writeInt(u32, style, .little);
1791 try data_writer.writeInt(u32, exstyle, .little);
17911792 },
17921793 .dialogex => {
17931794 const help_id: u32 = if (control.help_id) |help_id_expression|
17941795 evaluateNumberExpression(help_id_expression, self.source, self.input_code_pages).value
17951796 else
17961797 0;
1797 try data_writer.writeIntLittle(u32, help_id);
1798 try data_writer.writeInt(u32, help_id, .little);
17981799 // Note: Reverse order from DIALOG
1799 try data_writer.writeIntLittle(u32, exstyle);
1800 try data_writer.writeIntLittle(u32, style);
1800 try data_writer.writeInt(u32, exstyle, .little);
1801 try data_writer.writeInt(u32, style, .little);
18011802 },
18021803 else => unreachable,
18031804 }
......@@ -1807,15 +1808,15 @@ pub const Compiler = struct {
18071808 const control_width = evaluateNumberExpression(control.width, self.source, self.input_code_pages);
18081809 const control_height = evaluateNumberExpression(control.height, self.source, self.input_code_pages);
18091810
1810 try data_writer.writeIntLittle(u16, control_x.asWord());
1811 try data_writer.writeIntLittle(u16, control_y.asWord());
1812 try data_writer.writeIntLittle(u16, control_width.asWord());
1813 try data_writer.writeIntLittle(u16, control_height.asWord());
1811 try data_writer.writeInt(u16, control_x.asWord(), .little);
1812 try data_writer.writeInt(u16, control_y.asWord(), .little);
1813 try data_writer.writeInt(u16, control_width.asWord(), .little);
1814 try data_writer.writeInt(u16, control_height.asWord(), .little);
18141815
18151816 const control_id = evaluateNumberExpression(control.id, self.source, self.input_code_pages);
18161817 switch (resource) {
1817 .dialog => try data_writer.writeIntLittle(u16, control_id.asWord()),
1818 .dialogex => try data_writer.writeIntLittle(u32, control_id.value),
1818 .dialog => try data_writer.writeInt(u16, control_id.asWord(), .little),
1819 .dialogex => try data_writer.writeInt(u32, control_id.value, .little),
18191820 else => unreachable,
18201821 }
18211822
......@@ -1948,7 +1949,7 @@ pub const Compiler = struct {
19481949 }
19491950 // We know the extra_data_buf size fits within a u16.
19501951 const extra_data_size: u16 = @intCast(extra_data_buf.items.len);
1951 try data_writer.writeIntLittle(u16, extra_data_size);
1952 try data_writer.writeInt(u16, extra_data_size, .little);
19521953 try data_writer.writeAll(extra_data_buf.items);
19531954 }
19541955
......@@ -1962,21 +1963,21 @@ pub const Compiler = struct {
19621963
19631964 // I'm assuming this is some sort of version
19641965 // TODO: Try to find something mentioning this
1965 try data_writer.writeIntLittle(u16, 1);
1966 try data_writer.writeIntLittle(u16, button_width.asWord());
1967 try data_writer.writeIntLittle(u16, button_height.asWord());
1968 try data_writer.writeIntLittle(u16, @as(u16, @intCast(node.buttons.len)));
1966 try data_writer.writeInt(u16, 1, .little);
1967 try data_writer.writeInt(u16, button_width.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);
19691970
19701971 for (node.buttons) |button_or_sep| {
19711972 switch (button_or_sep.id) {
19721973 .literal => { // This is always SEPARATOR
19731974 std.debug.assert(button_or_sep.cast(.literal).?.token.id == .literal);
1974 try data_writer.writeIntLittle(u16, 0);
1975 try data_writer.writeInt(u16, 0, .little);
19751976 },
19761977 .simple_statement => {
19771978 const value_node = button_or_sep.cast(.simple_statement).?.value;
19781979 const value = evaluateNumberExpression(value_node, self.source, self.input_code_pages);
1979 try data_writer.writeIntLittle(u16, value.asWord());
1980 try data_writer.writeInt(u16, value.asWord(), .little);
19801981 },
19811982 else => unreachable, // This is a bug in the parser
19821983 }
......@@ -2007,21 +2008,21 @@ pub const Compiler = struct {
20072008 pub fn writeDialogFont(self: *Compiler, resource: Resource, values: FontStatementValues, writer: anytype) !void {
20082009 const node = values.node;
20092010 const point_size = evaluateNumberExpression(node.point_size, self.source, self.input_code_pages);
2010 try writer.writeIntLittle(u16, point_size.asWord());
2011 try writer.writeInt(u16, point_size.asWord(), .little);
20112012
20122013 if (resource == .dialogex) {
2013 try writer.writeIntLittle(u16, values.weight);
2014 try writer.writeInt(u16, values.weight, .little);
20142015 }
20152016
20162017 if (resource == .dialogex) {
2017 try writer.writeIntLittle(u8, @intFromBool(values.italic));
2018 try writer.writeInt(u8, @intFromBool(values.italic), .little);
20182019 }
20192020
20202021 if (node.char_set) |char_set| {
20212022 const value = evaluateNumberExpression(char_set, self.source, self.input_code_pages);
2022 try writer.writeIntLittle(u8, @as(u8, @truncate(value.value)));
2023 try writer.writeInt(u8, @as(u8, @truncate(value.value)), .little);
20232024 } else if (resource == .dialogex) {
2024 try writer.writeIntLittle(u8, 1); // DEFAULT_CHARSET
2025 try writer.writeInt(u8, 1, .little); // DEFAULT_CHARSET
20252026 }
20262027
20272028 const typeface = try self.parseQuotedStringAsWideString(node.typeface);
......@@ -2076,9 +2077,9 @@ pub const Compiler = struct {
20762077 pub fn writeMenuData(self: *Compiler, node: *Node.Menu, data_writer: anytype, resource: Resource) !void {
20772078 // menu header
20782079 const version: u16 = if (resource == .menu) 0 else 1;
2079 try data_writer.writeIntLittle(u16, version);
2080 try data_writer.writeInt(u16, version, .little);
20802081 const header_size: u16 = if (resource == .menu) 0 else 4;
2081 try data_writer.writeIntLittle(u16, header_size); // cbHeaderSize
2082 try data_writer.writeInt(u16, header_size, .little); // cbHeaderSize
20822083 // Note: There can be extra bytes at the end of this header (`rgbExtra`),
20832084 // but they are always zero-length for us, so we don't write anything
20842085 // (the length of the rgbExtra field is inferred from the header_size).
......@@ -2088,9 +2089,9 @@ pub const Compiler = struct {
20882089 if (resource == .menuex) {
20892090 if (node.help_id) |help_id_node| {
20902091 const help_id = evaluateNumberExpression(help_id_node, self.source, self.input_code_pages);
2091 try data_writer.writeIntLittle(u32, help_id.value);
2092 try data_writer.writeInt(u32, help_id.value, .little);
20922093 } else {
2093 try data_writer.writeIntLittle(u32, 0);
2094 try data_writer.writeInt(u32, 0, .little);
20942095 }
20952096 }
20962097
......@@ -2110,9 +2111,9 @@ pub const Compiler = struct {
21102111 // compiler still uses this alternate form, so that's what we use too.
21112112 var flags = res.MenuItemFlags{};
21122113 if (is_last_of_parent) flags.markLast();
2113 try writer.writeIntLittle(u16, flags.value);
2114 try writer.writeIntLittle(u16, 0); // id
2115 try writer.writeIntLittle(u16, 0); // null-terminated UTF-16 text
2114 try writer.writeInt(u16, flags.value, .little);
2115 try writer.writeInt(u16, 0, .little); // id
2116 try writer.writeInt(u16, 0, .little); // null-terminated UTF-16 text
21162117 },
21172118 .menu_item => {
21182119 const menu_item = @fieldParentPtr(Node.MenuItem, "base", node);
......@@ -2123,10 +2124,10 @@ pub const Compiler = struct {
21232124 flags.apply(option);
21242125 }
21252126 if (is_last_of_parent) flags.markLast();
2126 try writer.writeIntLittle(u16, flags.value);
2127 try writer.writeInt(u16, flags.value, .little);
21272128
21282129 var result = evaluateNumberExpression(menu_item.result, self.source, self.input_code_pages);
2129 try writer.writeIntLittle(u16, result.asWord());
2130 try writer.writeInt(u16, result.asWord(), .little);
21302131
21312132 var text = try self.parseQuotedStringAsWideString(menu_item.text);
21322133 defer self.allocator.free(text);
......@@ -2141,7 +2142,7 @@ pub const Compiler = struct {
21412142 flags.apply(option);
21422143 }
21432144 if (is_last_of_parent) flags.markLast();
2144 try writer.writeIntLittle(u16, flags.value);
2145 try writer.writeInt(u16, flags.value, .little);
21452146
21462147 var text = try self.parseQuotedStringAsWideString(popup.text);
21472148 defer self.allocator.free(text);
......@@ -2157,30 +2158,30 @@ pub const Compiler = struct {
21572158
21582159 if (menu_item.type) |flags| {
21592160 const value = evaluateNumberExpression(flags, self.source, self.input_code_pages);
2160 try writer.writeIntLittle(u32, value.value);
2161 try writer.writeInt(u32, value.value, .little);
21612162 } else {
2162 try writer.writeIntLittle(u32, 0);
2163 try writer.writeInt(u32, 0, .little);
21632164 }
21642165
21652166 if (menu_item.state) |state| {
21662167 const value = evaluateNumberExpression(state, self.source, self.input_code_pages);
2167 try writer.writeIntLittle(u32, value.value);
2168 try writer.writeInt(u32, value.value, .little);
21682169 } else {
2169 try writer.writeIntLittle(u32, 0);
2170 try writer.writeInt(u32, 0, .little);
21702171 }
21712172
21722173 if (menu_item.id) |id| {
21732174 const value = evaluateNumberExpression(id, self.source, self.input_code_pages);
2174 try writer.writeIntLittle(u32, value.value);
2175 try writer.writeInt(u32, value.value, .little);
21752176 } else {
2176 try writer.writeIntLittle(u32, 0);
2177 try writer.writeInt(u32, 0, .little);
21772178 }
21782179
21792180 var flags: u16 = 0;
21802181 if (is_last_of_parent) flags |= comptime @as(u16, @intCast(res.MF.END));
21812182 // This constant doesn't seem to have a named #define, it's different than MF_POPUP
21822183 if (node_type == .popup_ex) flags |= 0x01;
2183 try writer.writeIntLittle(u16, flags);
2184 try writer.writeInt(u16, flags, .little);
21842185
21852186 var text = try self.parseQuotedStringAsWideString(menu_item.text);
21862187 defer self.allocator.free(text);
......@@ -2195,9 +2196,9 @@ pub const Compiler = struct {
21952196 if (node_type == .popup_ex) {
21962197 if (menu_item.help_id) |help_id_node| {
21972198 const help_id = evaluateNumberExpression(help_id_node, self.source, self.input_code_pages);
2198 try writer.writeIntLittle(u32, help_id.value);
2199 try writer.writeInt(u32, help_id.value, .little);
21992200 } else {
2200 try writer.writeIntLittle(u32, 0);
2201 try writer.writeInt(u32, 0, .little);
22012202 }
22022203
22032204 for (menu_item.items, 0..) |item, i| {
......@@ -2218,15 +2219,15 @@ pub const Compiler = struct {
22182219 var limited_writer = limitedWriter(data_buffer.writer(), std.math.maxInt(u16));
22192220 const data_writer = limited_writer.writer();
22202221
2221 try data_writer.writeIntLittle(u16, 0); // placeholder size
2222 try data_writer.writeIntLittle(u16, res.FixedFileInfo.byte_len);
2223 try data_writer.writeIntLittle(u16, res.VersionNode.type_binary);
2222 try data_writer.writeInt(u16, 0, .little); // placeholder size
2223 try data_writer.writeInt(u16, res.FixedFileInfo.byte_len, .little);
2224 try data_writer.writeInt(u16, res.VersionNode.type_binary, .little);
22242225 const key_bytes = std.mem.sliceAsBytes(res.FixedFileInfo.key[0 .. res.FixedFileInfo.key.len + 1]);
22252226 try data_writer.writeAll(key_bytes);
22262227 // The number of bytes written up to this point is always the same, since the name
22272228 // of the node is a constant (FixedFileInfo.key). The total number of bytes
22282229 // written so far is 38, so we need 2 padding bytes to get back to DWORD alignment
2229 try data_writer.writeIntLittle(u16, 0);
2230 try data_writer.writeInt(u16, 0, .little);
22302231
22312232 var fixed_file_info = res.FixedFileInfo{};
22322233 for (node.fixed_info) |fixed_info| {
......@@ -2321,7 +2322,7 @@ pub const Compiler = struct {
23212322 // limited the writer to maxInt(u16)
23222323 const data_size: u16 = @intCast(data_buffer.items.len);
23232324 // And now that we know the full size of this node (including its children), set its size
2324 std.mem.writeIntLittle(u16, data_buffer.items[0..2], data_size);
2325 std.mem.writeInt(u16, data_buffer.items[0..2], data_size, .little);
23252326
23262327 var header = try self.resourceHeader(node.id, node.versioninfo, .{
23272328 .data_size = data_size,
......@@ -2344,12 +2345,12 @@ pub const Compiler = struct {
23442345 try writeDataPadding(writer, @as(u16, @intCast(buf.items.len)));
23452346
23462347 const node_and_children_size_offset = buf.items.len;
2347 try writer.writeIntLittle(u16, 0); // placeholder for size
2348 try writer.writeInt(u16, 0, .little); // placeholder for size
23482349 const data_size_offset = buf.items.len;
2349 try writer.writeIntLittle(u16, 0); // placeholder for data size
2350 try writer.writeInt(u16, 0, .little); // placeholder for data size
23502351 const data_type_offset = buf.items.len;
23512352 // Data type is string unless the node contains values that are numbers.
2352 try writer.writeIntLittle(u16, res.VersionNode.type_string);
2353 try writer.writeInt(u16, res.VersionNode.type_string, .little);
23532354
23542355 switch (node.id) {
23552356 inline .block, .block_value => |node_type| {
......@@ -2411,17 +2412,17 @@ pub const Compiler = struct {
24112412 const is_empty = parsed_to_first_null.len == 0;
24122413 const is_only = block_or_value.values.len == 1;
24132414 if ((!is_empty or !is_only) and (is_last or value_value_node.trailing_comma)) {
2414 try writer.writeIntLittle(u16, 0);
2415 try writer.writeInt(u16, 0, .little);
24152416 values_size += if (has_number_value) 2 else 1;
24162417 }
24172418 }
24182419 }
24192420 var data_size_slice = buf.items[data_size_offset..];
2420 std.mem.writeIntLittle(u16, data_size_slice[0..@sizeOf(u16)], @as(u16, @intCast(values_size)));
2421 std.mem.writeInt(u16, data_size_slice[0..@sizeOf(u16)], @as(u16, @intCast(values_size)), .little);
24212422
24222423 if (has_number_value) {
24232424 const data_type_slice = buf.items[data_type_offset..];
2424 std.mem.writeIntLittle(u16, data_type_slice[0..@sizeOf(u16)], res.VersionNode.type_binary);
2425 std.mem.writeInt(u16, data_type_slice[0..@sizeOf(u16)], res.VersionNode.type_binary, .little);
24252426 }
24262427
24272428 if (node_type == .block) {
......@@ -2436,7 +2437,7 @@ pub const Compiler = struct {
24362437
24372438 const node_and_children_size = buf.items.len - node_and_children_size_offset;
24382439 const node_and_children_size_slice = buf.items[node_and_children_size_offset..];
2439 std.mem.writeIntLittle(u16, node_and_children_size_slice[0..@sizeOf(u16)], @as(u16, @intCast(node_and_children_size)));
2440 std.mem.writeInt(u16, node_and_children_size_slice[0..@sizeOf(u16)], @as(u16, @intCast(node_and_children_size)), .little);
24402441 }
24412442
24422443 pub fn writeStringTable(self: *Compiler, node: *Node.StringTable) !void {
......@@ -2644,17 +2645,17 @@ pub const Compiler = struct {
26442645 }
26452646
26462647 fn writeSizeInfo(self: ResourceHeader, writer: anytype, size_info: SizeInfo) !void {
2647 try writer.writeIntLittle(DWORD, self.data_size); // DataSize
2648 try writer.writeIntLittle(DWORD, size_info.bytes); // HeaderSize
2648 try writer.writeInt(DWORD, self.data_size, .little); // DataSize
2649 try writer.writeInt(DWORD, size_info.bytes, .little); // HeaderSize
26492650 try self.type_value.write(writer); // TYPE
26502651 try self.name_value.write(writer); // NAME
26512652 try writer.writeByteNTimes(0, size_info.padding_after_name);
26522653
2653 try writer.writeIntLittle(DWORD, self.data_version); // DataVersion
2654 try writer.writeIntLittle(WORD, self.memory_flags.value); // MemoryFlags
2655 try writer.writeIntLittle(WORD, self.language.asInt()); // LanguageId
2656 try writer.writeIntLittle(DWORD, self.version); // Version
2657 try writer.writeIntLittle(DWORD, self.characteristics); // Characteristics
2654 try writer.writeInt(DWORD, self.data_version, .little); // DataVersion
2655 try writer.writeInt(WORD, self.memory_flags.value, .little); // MemoryFlags
2656 try writer.writeInt(WORD, self.language.asInt(), .little); // LanguageId
2657 try writer.writeInt(DWORD, self.version, .little); // Version
2658 try writer.writeInt(DWORD, self.characteristics, .little); // Characteristics
26582659 }
26592660
26602661 pub fn predefinedResourceType(self: ResourceHeader) ?res.RT {
......@@ -2997,7 +2998,7 @@ pub const FontDir = struct {
29972998 defer header.deinit(compiler.allocator);
29982999
29993000 try header.writeAssertNoOverflow(writer);
3000 try writer.writeIntLittle(u16, num_fonts);
3001 try writer.writeInt(u16, num_fonts, .little);
30013002 for (self.fonts.items) |font| {
30023003 // The format of the FONTDIR is a strange beast.
30033004 // Technically, each FONT is seemingly meant to be written as a
......@@ -3049,7 +3050,7 @@ pub const FontDir = struct {
30493050 // device name/face name in the FONTDIR is reliable.
30503051
30513052 // First, the ID is written, though
3052 try writer.writeIntLittle(u16, font.id);
3053 try writer.writeInt(u16, font.id, .little);
30533054 try writer.writeAll(&font.header_bytes);
30543055 try writer.writeByteNTimes(0, 2);
30553056 }
......@@ -3186,7 +3187,7 @@ pub const StringTable = struct {
31863187 var string_i: u8 = 0;
31873188 while (true) : (i += 1) {
31883189 if (!self.set_indexes.isSet(i)) {
3189 try data_writer.writeIntLittle(u16, 0);
3190 try data_writer.writeInt(u16, 0, .little);
31903191 if (i == 15) break else continue;
31913192 }
31923193
......@@ -3217,10 +3218,10 @@ pub const StringTable = struct {
32173218 // If the option is set, then a NUL terminator is added unconditionally.
32183219 // We already trimmed any trailing NULs, so we know it will be a new addition to the string.
32193220 if (compiler.null_terminate_string_table_strings) string_len_in_utf16_code_units += 1;
3220 try data_writer.writeIntLittle(u16, string_len_in_utf16_code_units);
3221 try data_writer.writeInt(u16, string_len_in_utf16_code_units, .little);
32213222 try data_writer.writeAll(std.mem.sliceAsBytes(trimmed_string));
32223223 if (compiler.null_terminate_string_table_strings) {
3223 try data_writer.writeIntLittle(u16, 0);
3224 try data_writer.writeInt(u16, 0, .little);
32243225 }
32253226
32263227 if (i == 15) break;
src/resinator/errors.zig+7-5
......@@ -9,6 +9,8 @@ const bmp = @import("bmp.zig");
99const parse = @import("parse.zig");
1010const lang = @import("lang.zig");
1111const CodePage = @import("code_pages.zig").CodePage;
12const builtin = @import("builtin");
13const native_endian = builtin.cpu.arch.endian();
1214
1315pub const Diagnostics = struct {
1416 errors: std.ArrayListUnmanaged(ErrorDetails) = .{},
......@@ -649,24 +651,24 @@ pub const ErrorDetails = struct {
649651 },
650652 .bmp_ignored_palette_bytes => {
651653 const bytes = strings[self.extra.number];
652 const ignored_bytes = std.mem.readIntNative(u64, bytes[0..8]);
654 const ignored_bytes = std.mem.readInt(u64, bytes[0..8], native_endian);
653655 try writer.print("bitmap has {d} extra bytes preceding the pixel data which will be ignored", .{ignored_bytes});
654656 },
655657 .bmp_missing_palette_bytes => {
656658 const bytes = strings[self.extra.number];
657 const missing_bytes = std.mem.readIntNative(u64, bytes[0..8]);
659 const missing_bytes = std.mem.readInt(u64, bytes[0..8], native_endian);
658660 try writer.print("bitmap has {d} missing color palette bytes which will be padded with zeroes", .{missing_bytes});
659661 },
660662 .rc_would_miscompile_bmp_palette_padding => {
661663 const bytes = strings[self.extra.number];
662 const miscompiled_bytes = std.mem.readIntNative(u64, bytes[0..8]);
664 const miscompiled_bytes = std.mem.readInt(u64, bytes[0..8], native_endian);
663665 try writer.print("the missing color palette bytes would be miscompiled by the Win32 RC compiler (the added padding bytes would include {d} bytes of the pixel data)", .{miscompiled_bytes});
664666 },
665667 .bmp_too_many_missing_palette_bytes => switch (self.type) {
666668 .err, .warning => {
667669 const bytes = strings[self.extra.number];
668 const missing_bytes = std.mem.readIntNative(u64, bytes[0..8]);
669 const max_missing_bytes = std.mem.readIntNative(u64, bytes[8..16]);
670 const missing_bytes = std.mem.readInt(u64, bytes[0..8], native_endian);
671 const max_missing_bytes = std.mem.readInt(u64, bytes[8..16], native_endian);
670672 try writer.print("bitmap has {} missing color palette bytes which exceeds the maximum of {}", .{ missing_bytes, max_missing_bytes });
671673 },
672674 // TODO: command line option
src/resinator/ico.zig+35-33
......@@ -5,6 +5,8 @@
55//! https://learn.microsoft.com/en-us/windows/win32/menurc/localheader
66
77const std = @import("std");
8const builtin = @import("builtin");
9const native_endian = builtin.cpu.arch.endian();
810
911pub const ReadError = std.mem.Allocator.Error || error{ InvalidHeader, InvalidImageType, ImpossibleDataSize, UnexpectedEOF, ReadError };
1012
......@@ -37,17 +39,17 @@ pub fn read(allocator: std.mem.Allocator, reader: anytype, max_size: u64) ReadEr
3739// to do this. Maybe it makes more sense to handle the translation
3840// at the call site instead of having a helper function here.
3941pub fn readAnyError(allocator: std.mem.Allocator, reader: anytype, max_size: u64) !IconDir {
40 const reserved = try reader.readIntLittle(u16);
42 const reserved = try reader.readInt(u16, .little);
4143 if (reserved != 0) {
4244 return error.InvalidHeader;
4345 }
4446
45 const image_type = reader.readEnum(ImageType, .Little) catch |err| switch (err) {
47 const image_type = reader.readEnum(ImageType, .little) catch |err| switch (err) {
4648 error.InvalidValue => return error.InvalidImageType,
4749 else => |e| return e,
4850 };
4951
50 const num_images = try reader.readIntLittle(u16);
52 const num_images = try reader.readInt(u16, .little);
5153
5254 // To avoid over-allocation in the case of a file that says it has way more
5355 // entries than it actually does, we use an ArrayList with a conservatively
......@@ -66,19 +68,19 @@ pub fn readAnyError(allocator: std.mem.Allocator, reader: anytype, max_size: u64
6668 switch (image_type) {
6769 .icon => {
6870 entry.type_specific_data = .{ .icon = .{
69 .color_planes = try reader.readIntLittle(u16),
70 .bits_per_pixel = try reader.readIntLittle(u16),
71 .color_planes = try reader.readInt(u16, .little),
72 .bits_per_pixel = try reader.readInt(u16, .little),
7173 } };
7274 },
7375 .cursor => {
7476 entry.type_specific_data = .{ .cursor = .{
75 .hotspot_x = try reader.readIntLittle(u16),
76 .hotspot_y = try reader.readIntLittle(u16),
77 .hotspot_x = try reader.readInt(u16, .little),
78 .hotspot_y = try reader.readInt(u16, .little),
7779 } };
7880 },
7981 }
80 entry.data_size_in_bytes = try reader.readIntLittle(u32);
81 entry.data_offset_from_start_of_file = try reader.readIntLittle(u32);
82 entry.data_size_in_bytes = try reader.readInt(u32, .little);
83 entry.data_offset_from_start_of_file = try reader.readInt(u32, .little);
8284 // Validate that the offset/data size is feasible
8385 if (@as(u64, entry.data_offset_from_start_of_file) + entry.data_size_in_bytes > max_size) {
8486 return error.ImpossibleDataSize;
......@@ -133,10 +135,10 @@ pub const IconDir = struct {
133135 }
134136
135137 pub fn writeResData(self: IconDir, writer: anytype, first_image_id: u16) !void {
136 try writer.writeIntLittle(u16, 0);
137 try writer.writeIntLittle(u16, @intFromEnum(self.image_type));
138 try writer.writeInt(u16, 0, .little);
139 try writer.writeInt(u16, @intFromEnum(self.image_type), .little);
138140 // We know that entries.len must fit into a u16
139 try writer.writeIntLittle(u16, @as(u16, @intCast(self.entries.len)));
141 try writer.writeInt(u16, @as(u16, @intCast(self.entries.len)), .little);
140142
141143 var image_id = first_image_id;
142144 for (self.entries) |entry| {
......@@ -173,23 +175,23 @@ pub const Entry = struct {
173175 pub fn writeResData(self: Entry, writer: anytype, id: u16) !void {
174176 switch (self.type_specific_data) {
175177 .icon => |icon_data| {
176 try writer.writeIntLittle(u8, @as(u8, @truncate(self.width)));
177 try writer.writeIntLittle(u8, @as(u8, @truncate(self.height)));
178 try writer.writeIntLittle(u8, self.num_colors);
179 try writer.writeIntLittle(u8, self.reserved);
180 try writer.writeIntLittle(u16, icon_data.color_planes);
181 try writer.writeIntLittle(u16, icon_data.bits_per_pixel);
182 try writer.writeIntLittle(u32, self.data_size_in_bytes);
178 try writer.writeInt(u8, @as(u8, @truncate(self.width)), .little);
179 try writer.writeInt(u8, @as(u8, @truncate(self.height)), .little);
180 try writer.writeInt(u8, self.num_colors, .little);
181 try writer.writeInt(u8, self.reserved, .little);
182 try writer.writeInt(u16, icon_data.color_planes, .little);
183 try writer.writeInt(u16, icon_data.bits_per_pixel, .little);
184 try writer.writeInt(u32, self.data_size_in_bytes, .little);
183185 },
184186 .cursor => |cursor_data| {
185 try writer.writeIntLittle(u16, self.width);
186 try writer.writeIntLittle(u16, self.height);
187 try writer.writeIntLittle(u16, cursor_data.hotspot_x);
188 try writer.writeIntLittle(u16, cursor_data.hotspot_y);
189 try writer.writeIntLittle(u32, self.data_size_in_bytes + 4);
187 try writer.writeInt(u16, self.width, .little);
188 try writer.writeInt(u16, self.height, .little);
189 try writer.writeInt(u16, cursor_data.hotspot_x, .little);
190 try writer.writeInt(u16, cursor_data.hotspot_y, .little);
191 try writer.writeInt(u32, self.data_size_in_bytes + 4, .little);
190192 },
191193 }
192 try writer.writeIntLittle(u16, id);
194 try writer.writeInt(u16, id, .little);
193195 }
194196};
195197
......@@ -235,21 +237,21 @@ pub const ImageFormat = enum {
235237 png,
236238 riff,
237239
238 const riff_header = std.mem.readIntNative(u32, "RIFF");
239 const png_signature = std.mem.readIntNative(u64, "\x89PNG\r\n\x1a\n");
240 const ihdr_code = std.mem.readIntNative(u32, "IHDR");
241 const acon_form_type = std.mem.readIntNative(u32, "ACON");
240 const riff_header = std.mem.readInt(u32, "RIFF", native_endian);
241 const png_signature = std.mem.readInt(u64, "\x89PNG\r\n\x1a\n", native_endian);
242 const ihdr_code = std.mem.readInt(u32, "IHDR", native_endian);
243 const acon_form_type = std.mem.readInt(u32, "ACON", native_endian);
242244
243245 pub fn detect(header_bytes: *const [16]u8) ImageFormat {
244 if (std.mem.readIntNative(u32, header_bytes[0..4]) == riff_header) return .riff;
245 if (std.mem.readIntNative(u64, header_bytes[0..8]) == png_signature) return .png;
246 if (std.mem.readInt(u32, header_bytes[0..4], native_endian) == riff_header) return .riff;
247 if (std.mem.readInt(u64, header_bytes[0..8], native_endian) == png_signature) return .png;
246248 return .dib;
247249 }
248250
249251 pub fn validate(format: ImageFormat, header_bytes: *const [16]u8) bool {
250252 return switch (format) {
251 .png => std.mem.readIntNative(u32, header_bytes[12..16]) == ihdr_code,
252 .riff => std.mem.readIntNative(u32, header_bytes[8..12]) == acon_form_type,
253 .png => std.mem.readInt(u32, header_bytes[12..16], native_endian) == ihdr_code,
254 .riff => std.mem.readInt(u32, header_bytes[8..12], native_endian) == acon_form_type,
253255 .dib => true,
254256 };
255257 }
src/resinator/res.zig+16-16
......@@ -249,14 +249,14 @@ pub const NameOrOrdinal = union(enum) {
249249 try writer.writeAll(std.mem.sliceAsBytes(name[0 .. name.len + 1]));
250250 },
251251 .ordinal => |ordinal| {
252 try writer.writeIntLittle(u16, 0xffff);
253 try writer.writeIntLittle(u16, ordinal);
252 try writer.writeInt(u16, 0xffff, .little);
253 try writer.writeInt(u16, ordinal, .little);
254254 },
255255 }
256256 }
257257
258258 pub fn writeEmpty(writer: anytype) !void {
259 try writer.writeIntLittle(u16, 0);
259 try writer.writeInt(u16, 0, .little);
260260 }
261261
262262 pub fn fromString(allocator: Allocator, bytes: SourceBytes) !NameOrOrdinal {
......@@ -963,19 +963,19 @@ pub const FixedFileInfo = struct {
963963 };
964964
965965 pub fn write(self: FixedFileInfo, writer: anytype) !void {
966 try writer.writeIntLittle(u32, signature);
967 try writer.writeIntLittle(u32, version);
968 try writer.writeIntLittle(u32, self.file_version.mostSignificantCombinedParts());
969 try writer.writeIntLittle(u32, self.file_version.leastSignificantCombinedParts());
970 try writer.writeIntLittle(u32, self.product_version.mostSignificantCombinedParts());
971 try writer.writeIntLittle(u32, self.product_version.leastSignificantCombinedParts());
972 try writer.writeIntLittle(u32, self.file_flags_mask);
973 try writer.writeIntLittle(u32, self.file_flags);
974 try writer.writeIntLittle(u32, self.file_os);
975 try writer.writeIntLittle(u32, self.file_type);
976 try writer.writeIntLittle(u32, self.file_subtype);
977 try writer.writeIntLittle(u32, self.file_date.mostSignificantCombinedParts());
978 try writer.writeIntLittle(u32, self.file_date.leastSignificantCombinedParts());
966 try writer.writeInt(u32, signature, .little);
967 try writer.writeInt(u32, version, .little);
968 try writer.writeInt(u32, self.file_version.mostSignificantCombinedParts(), .little);
969 try writer.writeInt(u32, self.file_version.leastSignificantCombinedParts(), .little);
970 try writer.writeInt(u32, self.product_version.mostSignificantCombinedParts(), .little);
971 try writer.writeInt(u32, self.product_version.leastSignificantCombinedParts(), .little);
972 try writer.writeInt(u32, self.file_flags_mask, .little);
973 try writer.writeInt(u32, self.file_flags, .little);
974 try writer.writeInt(u32, self.file_os, .little);
975 try writer.writeInt(u32, self.file_type, .little);
976 try writer.writeInt(u32, self.file_subtype, .little);
977 try writer.writeInt(u32, self.file_date.mostSignificantCombinedParts(), .little);
978 try writer.writeInt(u32, self.file_date.leastSignificantCombinedParts(), .little);
979979 }
980980};
981981
src/value.zig+6-6
......@@ -778,8 +778,8 @@ pub const Value = struct {
778778 .Void => {},
779779 .Bool => {
780780 const byte_index = switch (endian) {
781 .Little => bit_offset / 8,
782 .Big => buffer.len - bit_offset / 8 - 1,
781 .little => bit_offset / 8,
782 .big => buffer.len - bit_offset / 8 - 1,
783783 };
784784 if (val.toBool()) {
785785 buffer[byte_index] |= (@as(u8, 1) << @as(u3, @intCast(bit_offset % 8)));
......@@ -815,7 +815,7 @@ pub const Value = struct {
815815 var elem_i: usize = 0;
816816 while (elem_i < len) : (elem_i += 1) {
817817 // 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;
819819 const elem_val = try val.elemValue(mod, tgt_elem_i);
820820 try elem_val.writeToPackedMemory(elem_ty, mod, buffer, bit_offset + bits);
821821 bits += elem_bit_size;
......@@ -1064,8 +1064,8 @@ pub const Value = struct {
10641064 .Void => return Value.void,
10651065 .Bool => {
10661066 const byte = switch (endian) {
1067 .Big => buffer[buffer.len - bit_offset / 8 - 1],
1068 .Little => buffer[bit_offset / 8],
1067 .big => buffer[buffer.len - bit_offset / 8 - 1],
1068 .little => buffer[bit_offset / 8],
10691069 };
10701070 if (((byte >> @as(u3, @intCast(bit_offset % 8))) & 1) == 0) {
10711071 return Value.false;
......@@ -1127,7 +1127,7 @@ pub const Value = struct {
11271127 const elem_bit_size = @as(u16, @intCast(elem_ty.bitSize(mod)));
11281128 for (elems, 0..) |_, i| {
11291129 // 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;
11311131 elems[tgt_elem_i] = try (try readFromPackedMemory(elem_ty, mod, buffer, bit_offset + bits, arena)).intern(elem_ty, mod);
11321132 bits += elem_bit_size;
11331133 }
test/behavior/align.zig+2-2
......@@ -616,8 +616,8 @@ test "sub-aligned pointer field access" {
616616 const ptr: *align(1) Header = @ptrCast(buf[1..][0..8]);
617617 const x = ptr.bytes_len;
618618 switch (builtin.cpu.arch.endian()) {
619 .Big => try expect(x == 0x06070809),
620 .Little => try expect(x == 0x09080706),
619 .big => try expect(x == 0x06070809),
620 .little => try expect(x == 0x09080706),
621621 }
622622}
623623
test/behavior/bitcast.zig+5-5
......@@ -107,14 +107,14 @@ fn testBitCastuXToBytes(comptime N: usize) !void {
107107
108108 const byte_count = (N + 7) / 8;
109109 switch (native_endian) {
110 .Little => {
110 .little => {
111111 var byte_i = 0;
112112 while (byte_i < (byte_count - 1)) : (byte_i += 1) {
113113 try expect(bytes[byte_i] == 0xff);
114114 }
115115 try expect(((bytes[byte_i] ^ 0xff) << -%@as(u3, @truncate(N))) == 0);
116116 },
117 .Big => {
117 .big => {
118118 var byte_i = byte_count - 1;
119119 while (byte_i > 0) : (byte_i -= 1) {
120120 try expect(bytes[byte_i] == 0xff);
......@@ -197,11 +197,11 @@ test "@bitCast extern structs at runtime and comptime" {
197197 var full = Full{ .number = 0x1234 };
198198 var two_halves = @as(TwoHalves, @bitCast(full));
199199 switch (native_endian) {
200 .Big => {
200 .big => {
201201 try expect(two_halves.half1 == 0x12);
202202 try expect(two_halves.half2 == 0x34);
203203 },
204 .Little => {
204 .little => {
205205 try expect(two_halves.half1 == 0x34);
206206 try expect(two_halves.half2 == 0x12);
207207 },
......@@ -332,7 +332,7 @@ test "comptime @bitCast packed struct to int and back" {
332332 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
333333 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
334334
335 if (builtin.zig_backend == .stage2_llvm and native_endian == .Big) {
335 if (builtin.zig_backend == .stage2_llvm and native_endian == .big) {
336336 // https://github.com/ziglang/zig/issues/13782
337337 return error.SkipZigTest;
338338 }
test/behavior/bugs/12169.zig+1-1
......@@ -7,7 +7,7 @@ test {
77 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
88 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
99
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) {
1111 // https://github.com/ziglang/zig/issues/13782
1212 return error.SkipZigTest;
1313 }
test/behavior/bugs/1851.zig+1
......@@ -7,6 +7,7 @@ test "allocation and looping over 3-byte integer" {
77 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
88 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
99 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
10 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
1011
1112 if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .macos) {
1213 return error.SkipZigTest; // TODO
test/behavior/cast.zig+1-1
......@@ -1077,7 +1077,7 @@ test "pointer reinterpret const float to int" {
10771077 const float_ptr = &float;
10781078 const int_ptr = @as(*const i32, @ptrCast(float_ptr));
10791079 const int_val = int_ptr.*;
1080 if (native_endian == .Little)
1080 if (native_endian == .little)
10811081 try expect(int_val == 0x33333303)
10821082 else
10831083 try expect(int_val == 0x3fe33333);
test/behavior/cast_int.zig+1-1
......@@ -163,7 +163,7 @@ test "load non byte-sized optional value" {
163163}
164164
165165test "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
167167 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
168168
169169 // note: this bug is triggered by the == operator, expectEqual will hide it
test/behavior/comptime_memory.zig+10-2
......@@ -73,7 +73,7 @@ test "type pun value and struct" {
7373}
7474
7575fn 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);
7777}
7878test "type pun endianness" {
7979 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
......@@ -385,7 +385,7 @@ test "accessing reinterpreted memory of parent object" {
385385 b: [4]u8,
386386 c: f32,
387387 };
388 const expected = if (endian == .Little) 102 else 38;
388 const expected = if (endian == .little) 102 else 38;
389389
390390 comptime {
391391 const x = S{
......@@ -451,3 +451,11 @@ test "type pun null pointer-like optional" {
451451 // note that expectEqual hides the bug
452452 try testing.expect(@as(*const ?*i8, @ptrCast(&p)).* == null);
453453}
454
455test "write empty array to end" {
456 comptime var array: [5]u8 = "hello".*;
457 array[5..5].* = .{};
458 array[5..5].* = [0]u8{};
459 array[5..5].* = [_]u8{};
460 try testing.expectEqualStrings("hello", &array);
461}
test/behavior/packed-struct.zig+12-12
......@@ -165,7 +165,7 @@ test "correct sizeOf and offsets in packed structs" {
165165 try expectEqual(22, @bitOffsetOf(PStruct, "u10_b"));
166166 try expectEqual(4, @sizeOf(PStruct));
167167
168 if (native_endian == .Little) {
168 if (native_endian == .little) {
169169 const s1 = @as(PStruct, @bitCast(@as(u32, 0x12345678)));
170170 try expectEqual(false, s1.bool_a);
171171 try expectEqual(false, s1.bool_b);
......@@ -206,7 +206,7 @@ test "nested packed structs" {
206206 try expectEqual(3, @offsetOf(S3, "y"));
207207 try expectEqual(24, @bitOffsetOf(S3, "y"));
208208
209 if (native_endian == .Little) {
209 if (native_endian == .little) {
210210 const s3 = @as(S3Padded, @bitCast(@as(u64, 0xe952d5c71ff4))).s3;
211211 try expectEqual(@as(u8, 0xf4), s3.x.a);
212212 try expectEqual(@as(u8, 0x1f), s3.x.b);
......@@ -258,7 +258,7 @@ test "nested packed struct unaligned" {
258258 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
259259 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
260260 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
262262
263263 const S1 = packed struct {
264264 a: u4,
......@@ -352,13 +352,13 @@ test "byte-aligned field pointer offsets" {
352352 .d = 4,
353353 };
354354 switch (comptime builtin.cpu.arch.endian()) {
355 .Little => {
355 .little => {
356356 comptime assert(@TypeOf(&a.a) == *align(4) u8);
357357 comptime assert(@TypeOf(&a.b) == *u8);
358358 comptime assert(@TypeOf(&a.c) == *align(2) u8);
359359 comptime assert(@TypeOf(&a.d) == *u8);
360360 },
361 .Big => {
361 .big => {
362362 // TODO re-evaluate packed struct endianness
363363 comptime assert(@TypeOf(&a.a) == *align(4:0:4) u8);
364364 comptime assert(@TypeOf(&a.b) == *align(4:8:4) u8);
......@@ -400,11 +400,11 @@ test "byte-aligned field pointer offsets" {
400400 .b = 2,
401401 };
402402 switch (comptime builtin.cpu.arch.endian()) {
403 .Little => {
403 .little => {
404404 comptime assert(@TypeOf(&b.a) == *align(4) u16);
405405 comptime assert(@TypeOf(&b.b) == *u16);
406406 },
407 .Big => {
407 .big => {
408408 comptime assert(@TypeOf(&b.a) == *align(4:0:4) u16);
409409 comptime assert(@TypeOf(&b.b) == *align(4:16:4) u16);
410410 },
......@@ -433,7 +433,7 @@ test "nested packed struct field pointers" {
433433 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
434434 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // ubsan unaligned pointer access
435435 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
437437
438438 const S2 = packed struct {
439439 base: u8,
......@@ -491,7 +491,7 @@ test "@intFromPtr on a packed struct field" {
491491 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
492492 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
493493 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;
495495
496496 const S = struct {
497497 const P = packed struct {
......@@ -515,7 +515,7 @@ test "@intFromPtr on a packed struct field unaligned and nested" {
515515 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
516516 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
517517 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
519519
520520 const S1 = packed struct {
521521 a: u4,
......@@ -921,11 +921,11 @@ test "overaligned pointer to packed struct" {
921921 var foo: S align(4) = .{ .a = 123, .b = 456 };
922922 const ptr: *align(4) S = &foo;
923923 switch (comptime builtin.cpu.arch.endian()) {
924 .Little => {
924 .little => {
925925 const ptr_to_b: *u32 = &ptr.b;
926926 try expect(ptr_to_b.* == 456);
927927 },
928 .Big => {
928 .big => {
929929 // Byte aligned packed struct field pointers have not been implemented yet.
930930 const ptr_to_a: *align(4:0:8) u32 = &ptr.a;
931931 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" {
2424 try expectEqual(3, @offsetOf(S3, "y"));
2525 try expectEqual(24, @bitOffsetOf(S3, "y"));
2626
27 if (native_endian == .Little) {
27 if (native_endian == .little) {
2828 const s3 = @as(S3Padded, @bitCast(@as(u64, 0xe952d5c71ff4))).s3;
2929 try expectEqual(@as(u8, 0xf4), s3.x.a);
3030 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" {
1313fn testReinterpretBytesAsInteger() !void {
1414 const bytes = "\x12\x34\x56\x78\xab";
1515 const expected = switch (native_endian) {
16 .Little => 0xab785634,
17 .Big => 0x345678ab,
16 .little => 0xab785634,
17 .big => 0x345678ab,
1818 };
1919 try expect(@as(*align(1) const u32, @ptrCast(bytes[1..5])).* == expected);
2020}
......@@ -48,8 +48,8 @@ fn testReinterpretStructWrappedBytesAsInteger() !void {
4848 const S = struct { bytes: [5:0]u8 };
4949 const obj = S{ .bytes = "\x12\x34\x56\x78\xab".* };
5050 const expected = switch (native_endian) {
51 .Little => 0xab785634,
52 .Big => 0x345678ab,
51 .little => 0xab785634,
52 .big => 0x345678ab,
5353 };
5454 try expect(@as(*align(1) const u32, @ptrCast(obj.bytes[1..5])).* == expected);
5555}
......@@ -176,7 +176,7 @@ test "reinterpret struct field at comptime" {
176176 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
177177
178178 const numNative = comptime Bytes.init(0x12345678);
179 if (native_endian != .Little) {
179 if (native_endian != .little) {
180180 try expect(std.mem.eql(u8, &[_]u8{ 0x12, 0x34, 0x56, 0x78 }, &numNative.bytes));
181181 } else {
182182 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" {
201201 const is_bytes = @as([*]const u8, @ptrCast(&is_value))[0..@sizeOf(isize)];
202202 if (@sizeOf(isize) == 8) {
203203 switch (native_endian) {
204 .Little => {
204 .little => {
205205 try expect(is_bytes[0] == 0xff);
206206 try expect(is_bytes[1] == 0xff);
207207 try expect(is_bytes[2] == 0xff);
......@@ -212,7 +212,7 @@ test "ptrcast of const integer has the correct object size" {
212212 try expect(is_bytes[6] == 0xff);
213213 try expect(is_bytes[7] == 0x7f);
214214 },
215 .Big => {
215 .big => {
216216 try expect(is_bytes[0] == 0x7f);
217217 try expect(is_bytes[1] == 0xff);
218218 try expect(is_bytes[2] == 0xff);
test/behavior/struct.zig+2-1
......@@ -1351,6 +1351,7 @@ test "under-aligned struct field" {
13511351 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
13521352 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
13531353 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1354 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
13541355
13551356 const U = extern union {
13561357 fd: i32,
......@@ -1364,7 +1365,7 @@ test "under-aligned struct field" {
13641365 var runtime: usize = 1234;
13651366 const ptr = &S{ .events = 0, .data = .{ .u64 = runtime } };
13661367 const array = @as(*const [12]u8, @ptrCast(ptr));
1367 const result = std.mem.readIntNative(u64, array[4..12]);
1368 const result = std.mem.readInt(u64, array[4..12], native_endian);
13681369 try expect(result == 1234);
13691370}
13701371
test/behavior/union.zig+3-3
......@@ -1686,7 +1686,7 @@ test "memset packed union" {
16861686}
16871687
16881688fn 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);
16901690}
16911691
16921692test "reinterpret extern union" {
......@@ -1723,8 +1723,8 @@ test "reinterpret extern union" {
17231723
17241724 {
17251725 const expected, const mask = switch (endian) {
1726 .Little => .{ 0x2a, 0xff },
1727 .Big => .{ 0x2a000000, 0xff000000 },
1726 .little => .{ 0x2a, 0xff },
1727 .big => .{ 0x2a000000, 0xff000000 },
17281728 };
17291729
17301730 try expectEqual(@as(u8, 0x2a), u.foo);
tools/gen_stubs.zig+4-4
......@@ -234,12 +234,12 @@ pub fn main() !void {
234234
235235 switch (header.is_64) {
236236 true => switch (header.endian) {
237 .Big => try parseElf(parse, true, .Big),
238 .Little => try parseElf(parse, true, .Little),
237 .big => try parseElf(parse, true, .big),
238 .little => try parseElf(parse, true, .little),
239239 },
240240 false => switch (header.endian) {
241 .Big => try parseElf(parse, false, .Big),
242 .Little => try parseElf(parse, false, .Little),
241 .big => try parseElf(parse, false, .big),
242 .little => try parseElf(parse, false, .little),
243243 },
244244 }
245245 }