authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-10-31 04:26:57-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-10-31 21:37:35-04:00
logd890e817610dd75feef55c1f7983190852c622a5
tree679d13309da35aa957a9d20d28671d9b8673b5a1
parent50cdb65784937965b5871037ff40bc34d8eb14af

mem: fix ub in writeInt

Use inline to vastly simplify the exposed API. This allows a comptime-known endian parameter to be propogated, making extra functions for a specific endianness completely unnecessary.

107 files changed, 1120 insertions(+), 1328 deletions(-)

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/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+4-4
......@@ -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+12-15
......@@ -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,
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/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/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+8-8
......@@ -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);
44 mem.writeInt(u32, j[nonce_length..][0..4], 2, .Big);
4545 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,7 +103,7 @@ fn AesGcm(comptime Aes: anytype) type {
103103 return error.AuthenticationFailed;
104104 }
105105
106 mem.writeIntBig(u32, j[nonce_length..][0..4], 2);
106 mem.writeInt(u32, j[nonce_length..][0..4], 2, .Big);
107107 modes.ctr(@TypeOf(aes), aes, m, c, j, std.builtin.Endian.Big);
108108 }
109109 };
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+7-6
......@@ -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
......@@ -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 }
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/isap.zig+11-11
......@@ -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+3-3
......@@ -54,7 +54,7 @@ pub fn Field(comptime params: FieldParams) type {
5454 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 };
6060 if (crypto.utils.timingSafeCompare(u8, &s, &field_order_s, .Little) != .lt) {
......@@ -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);
98 mem.writeInt(IntRepr, &s, x, .Little);
9999 return fromBytes(s, .Little);
100100 }
101101
102102 /// Return the field element as an integer.
103103 pub fn toInt(fe: Fe) IntRepr {
104104 const s = fe.toBytes(.Little);
105 return mem.readIntLittle(IntRepr, &s);
105 return mem.readInt(IntRepr, &s, .Little);
106106 }
107107
108108 /// Return true if the field element is zero.
lib/std/crypto/pcurves/secp256k1.zig+5-5
......@@ -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,10 +72,10 @@ pub const Secp256k1 = struct {
7272
7373 var buf: [32]u8 = undefined;
7474
75 mem.writeIntLittle(u256, &buf, c1);
75 mem.writeInt(u256, &buf, c1, .Little);
7676 const c1x = try scalar.mul(buf, b1_neg_s, .Little);
7777
78 mem.writeIntLittle(u256, &buf, c2);
78 mem.writeInt(u256, &buf, c2, .Little);
7979 const c2x = try scalar.mul(buf, b2_neg_s, .Little);
8080
8181 const r2 = try scalar.add(c1x, c2x, .Little);
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+3-3
......@@ -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)
lib/std/debug.zig+5-5
......@@ -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];
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/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/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/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+11-11
......@@ -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;
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+2-24
......@@ -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
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/mem.zig+233-392
......@@ -1587,68 +1587,40 @@ 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}
1603
1604pub const readIntLittle = switch (native_endian) {
1605 .Little => readIntNative,
1606 .Big => readIntForeign,
1607};
1595test readInt {
1596 try testing.expect(readInt(u0, &[_]u8{}, .Big) == 0x0);
1597 try testing.expect(readInt(u0, &[_]u8{}, .Little) == 0x0);
16081598
1609pub const readIntBig = switch (native_endian) {
1610 .Little => readIntForeign,
1611 .Big => readIntNative,
1612};
1599 try testing.expect(readInt(u8, &[_]u8{0x32}, .Big) == 0x32);
1600 try testing.expect(readInt(u8, &[_]u8{0x12}, .Little) == 0x12);
16131601
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}
1602 try testing.expect(readInt(u16, &[_]u8{ 0x12, 0x34 }, .Big) == 0x1234);
1603 try testing.expect(readInt(u16, &[_]u8{ 0x12, 0x34 }, .Little) == 0x3412);
16241604
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}
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);
16321607
1633pub const readIntSliceLittle = switch (native_endian) {
1634 .Little => readIntSliceNative,
1635 .Big => readIntSliceForeign,
1636};
1608 try testing.expect(readInt(i8, &[_]u8{0xff}, .Big) == -1);
1609 try testing.expect(readInt(i8, &[_]u8{0xfe}, .Little) == -2);
16371610
1638pub const readIntSliceBig = switch (native_endian) {
1639 .Little => readIntSliceForeign,
1640 .Big => readIntSliceNative,
1641};
1611 try testing.expect(readInt(i16, &[_]u8{ 0xff, 0xfd }, .Big) == -3);
1612 try testing.expect(readInt(i16, &[_]u8{ 0xfc, 0xff }, .Little) == -4);
1613}
16421614
1643/// Reads an integer from memory with bit count specified by T.
1615/// Asserts that buffer.len >= @typeInfo(T).Int.bits / 8. Reads the integer starting from index 0
1616/// and ignores extra bytes.
16441617/// 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 }
1618pub inline fn readIntSlice(comptime T: type, buffer: []const u8, endian: Endian) T {
1619 const byte_len = @divExact(@typeInfo(T).Int.bits, 8);
1620 return switch (endian) {
1621 .Little => readInt(T, buffer[0..byte_len], endian),
1622 .Big => readInt(T, buffer[buffer.len - byte_len ..], endian),
1623 };
16521624}
16531625
16541626fn readPackedIntLittle(comptime T: type, bytes: []const u8, bit_offset: usize) T {
......@@ -1668,7 +1640,7 @@ fn readPackedIntLittle(comptime T: type, bytes: []const u8, bit_offset: usize) T
16681640 // Read by loading a LoadInt, and then follow it up with a 1-byte read
16691641 // of the tail if bit_offset pushed us over a byte boundary.
16701642 const read_bytes = bytes[bit_offset / 8 ..];
1671 const val = @as(uN, @truncate(readIntLittle(LoadInt, read_bytes[0..load_size]) >> bit_shift));
1643 const val = @as(uN, @truncate(readInt(LoadInt, read_bytes[0..load_size], .Little) >> bit_shift));
16721644 if (bit_shift > load_tail_bits) {
16731645 const tail_bits = @as(Log2N, @intCast(bit_shift - load_tail_bits));
16741646 const tail_byte = read_bytes[load_size];
......@@ -1696,7 +1668,7 @@ fn readPackedIntBig(comptime T: type, bytes: []const u8, bit_offset: usize) T {
16961668 // of the tail if bit_offset pushed us over a byte boundary.
16971669 const end = bytes.len - (bit_offset / 8);
16981670 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));
1671 const val = @as(uN, @truncate(readInt(LoadInt, bytes[(end - load_size)..end][0..load_size], .Big) >> bit_shift));
17001672 if (bit_shift > load_tail_bits) {
17011673 const tail_bits = @as(Log2N, @intCast(bit_shift - load_tail_bits));
17021674 const tail_byte = if (bit_count < 8) @as(uN, @truncate(read_bytes[0])) else @as(uN, read_bytes[0]);
......@@ -1729,89 +1701,223 @@ pub fn readPackedInt(comptime T: type, bytes: []const u8, bit_offset: usize, end
17291701 }
17301702}
17311703
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
17411704test "comptime read/write int" {
17421705 comptime {
17431706 var bytes: [2]u8 = undefined;
1744 writeIntLittle(u16, &bytes, 0x1234);
1745 const result = readIntBig(u16, &bytes);
1707 writeInt(u16, &bytes, 0x1234, .Little);
1708 const result = readInt(u16, &bytes, .Big);
17461709 try testing.expect(result == 0x3412);
17471710 }
17481711 comptime {
17491712 var bytes: [2]u8 = undefined;
1750 writeIntBig(u16, &bytes, 0x1234);
1751 const result = readIntLittle(u16, &bytes);
1713 writeInt(u16, &bytes, 0x1234, .Big);
1714 const result = readInt(u16, &bytes, .Little);
17521715 try testing.expect(result == 0x3412);
17531716 }
17541717}
17551718
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;
1719/// Writes an integer to memory, storing it in twos-complement.
1720/// This function always succeeds, has defined behavior for all inputs, but
1721/// the integer bit width must be divisible by 8.
1722pub inline fn writeInt(comptime T: type, buffer: *[@divExact(@typeInfo(T).Int.bits, 8)]u8, value: T, endian: Endian) void {
1723 buffer.* = @bitCast(if (endian == native_endian) value else @byteSwap(value));
1724}
17591725
1760 try testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0);
1761 try testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0);
1726test writeInt {
1727 var buf0: [0]u8 = undefined;
1728 var buf1: [1]u8 = undefined;
1729 var buf2: [2]u8 = undefined;
1730 var buf9: [9]u8 = undefined;
17621731
1763 try testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32);
1764 try testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12);
1732 writeInt(u0, &buf0, 0x0, .Big);
1733 try testing.expect(eql(u8, buf0[0..], &[_]u8{}));
1734 writeInt(u0, &buf0, 0x0, .Little);
1735 try testing.expect(eql(u8, buf0[0..], &[_]u8{}));
17651736
1766 try testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234);
1767 try testing.expect(readIntSliceLittle(u16, &[_]u8{ 0x12, 0x34 }) == 0x3412);
1737 writeInt(u8, &buf1, 0x12, .Big);
1738 try testing.expect(eql(u8, buf1[0..], &[_]u8{0x12}));
1739 writeInt(u8, &buf1, 0x34, .Little);
1740 try testing.expect(eql(u8, buf1[0..], &[_]u8{0x34}));
17681741
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);
1742 writeInt(u16, &buf2, 0x1234, .Big);
1743 try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 }));
1744 writeInt(u16, &buf2, 0x5678, .Little);
1745 try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x78, 0x56 }));
17711746
1772 try testing.expect(readIntSliceBig(i8, &[_]u8{0xff}) == -1);
1773 try testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2);
1747 writeInt(u72, &buf9, 0x123456789abcdef024, .Big);
1748 try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
1749 writeInt(u72, &buf9, 0xfedcba9876543210ec, .Little);
1750 try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
1751
1752 writeInt(i8, &buf1, -1, .Big);
1753 try testing.expect(eql(u8, buf1[0..], &[_]u8{0xff}));
1754 writeInt(i8, &buf1, -2, .Little);
1755 try testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe}));
17741756
1775 try testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3);
1776 try testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4);
1757 writeInt(i16, &buf2, -3, .Big);
1758 try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd }));
1759 writeInt(i16, &buf2, -4, .Little);
1760 try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff }));
17771761}
17781762
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;
1763/// Writes a twos-complement integer to memory, with the specified endianness.
1764/// Asserts that buf.len >= @typeInfo(T).Int.bits / 8.
1765/// The bit count of T must be evenly divisible by 8.
1766/// Any extra bytes in buffer not part of the integer are set to zero, with
1767/// respect to endianness. To avoid the branch to check for extra buffer bytes,
1768/// use writeInt instead.
1769pub inline fn writeIntSlice(comptime T: type, buffer: []u8, value: T, endian: Endian) void {
1770 const byte_len = @divExact(@typeInfo(T).Int.bits, 8);
1771 switch (endian) {
1772 .Little => {
1773 writeInt(T, buffer[0..byte_len], value, endian);
1774 @memset(buffer[byte_len..], 0);
1775 },
1776 .Big => {
1777 @memset(buffer[0 .. buffer.len - byte_len], 0);
1778 writeInt(T, buffer[buffer.len - byte_len ..][0..byte_len], value, endian);
1779 },
1780 }
17861781}
17871782
1788/// Writes an integer to memory, storing it in twos-complement.
1789/// This function always succeeds, has defined behavior for all inputs, but
1790/// 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));
1783test writeIntSlice {
1784 try testWriteIntImpl();
1785 try comptime testWriteIntImpl();
17941786}
1787fn testWriteIntImpl() !void {
1788 var bytes: [8]u8 = undefined;
17951789
1796pub const writeIntLittle = switch (native_endian) {
1797 .Little => writeIntNative,
1798 .Big => writeIntForeign,
1799};
1790 writeIntSlice(u0, bytes[0..], 0, .Big);
1791 try testing.expect(eql(u8, &bytes, &[_]u8{
1792 0x00, 0x00, 0x00, 0x00,
1793 0x00, 0x00, 0x00, 0x00,
1794 }));
18001795
1801pub const writeIntBig = switch (native_endian) {
1802 .Little => writeIntForeign,
1803 .Big => writeIntNative,
1804};
1796 writeIntSlice(u0, bytes[0..], 0, .Little);
1797 try testing.expect(eql(u8, &bytes, &[_]u8{
1798 0x00, 0x00, 0x00, 0x00,
1799 0x00, 0x00, 0x00, 0x00,
1800 }));
18051801
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 }
1802 writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, .Big);
1803 try testing.expect(eql(u8, &bytes, &[_]u8{
1804 0x12,
1805 0x34,
1806 0x56,
1807 0x78,
1808 0xCA,
1809 0xFE,
1810 0xBA,
1811 0xBE,
1812 }));
1813
1814 writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, .Little);
1815 try testing.expect(eql(u8, &bytes, &[_]u8{
1816 0x12,
1817 0x34,
1818 0x56,
1819 0x78,
1820 0xCA,
1821 0xFE,
1822 0xBA,
1823 0xBE,
1824 }));
1825
1826 writeIntSlice(u32, bytes[0..], 0x12345678, .Big);
1827 try testing.expect(eql(u8, &bytes, &[_]u8{
1828 0x00,
1829 0x00,
1830 0x00,
1831 0x00,
1832 0x12,
1833 0x34,
1834 0x56,
1835 0x78,
1836 }));
1837
1838 writeIntSlice(u32, bytes[0..], 0x78563412, .Little);
1839 try testing.expect(eql(u8, &bytes, &[_]u8{
1840 0x12,
1841 0x34,
1842 0x56,
1843 0x78,
1844 0x00,
1845 0x00,
1846 0x00,
1847 0x00,
1848 }));
1849
1850 writeIntSlice(u16, bytes[0..], 0x1234, .Big);
1851 try testing.expect(eql(u8, &bytes, &[_]u8{
1852 0x00,
1853 0x00,
1854 0x00,
1855 0x00,
1856 0x00,
1857 0x00,
1858 0x12,
1859 0x34,
1860 }));
1861
1862 writeIntSlice(u16, bytes[0..], 0x1234, .Little);
1863 try testing.expect(eql(u8, &bytes, &[_]u8{
1864 0x34,
1865 0x12,
1866 0x00,
1867 0x00,
1868 0x00,
1869 0x00,
1870 0x00,
1871 0x00,
1872 }));
1873
1874 writeIntSlice(i16, bytes[0..], @as(i16, -21555), .Little);
1875 try testing.expect(eql(u8, &bytes, &[_]u8{
1876 0xCD,
1877 0xAB,
1878 0x00,
1879 0x00,
1880 0x00,
1881 0x00,
1882 0x00,
1883 0x00,
1884 }));
1885
1886 writeIntSlice(i16, bytes[0..], @as(i16, -21555), .Big);
1887 try testing.expect(eql(u8, &bytes, &[_]u8{
1888 0x00,
1889 0x00,
1890 0x00,
1891 0x00,
1892 0x00,
1893 0x00,
1894 0xAB,
1895 0xCD,
1896 }));
1897
1898 writeIntSlice(u8, bytes[0..], 0x12, .Big);
1899 try testing.expect(eql(u8, &bytes, &[_]u8{
1900 0x00, 0x00, 0x00, 0x00,
1901 0x00, 0x00, 0x00, 0x12,
1902 }));
1903
1904 writeIntSlice(u8, bytes[0..], 0x12, .Little);
1905 try testing.expect(eql(u8, &bytes, &[_]u8{
1906 0x12, 0x00, 0x00, 0x00,
1907 0x00, 0x00, 0x00, 0x00,
1908 }));
1909
1910 writeIntSlice(i8, bytes[0..], -1, .Big);
1911 try testing.expect(eql(u8, &bytes, &[_]u8{
1912 0x00, 0x00, 0x00, 0x00,
1913 0x00, 0x00, 0x00, 0xff,
1914 }));
1915
1916 writeIntSlice(i8, bytes[0..], -1, .Little);
1917 try testing.expect(eql(u8, &bytes, &[_]u8{
1918 0xff, 0x00, 0x00, 0x00,
1919 0x00, 0x00, 0x00, 0x00,
1920 }));
18151921}
18161922
18171923fn writePackedIntLittle(comptime T: type, bytes: []u8, bit_offset: usize, value: T) void {
......@@ -1844,7 +1950,7 @@ fn writePackedIntLittle(comptime T: type, bytes: []u8, bit_offset: usize, value:
18441950 write_value |= @as(StoreInt, tail) << (8 * (store_size - 1));
18451951 }
18461952
1847 writeIntLittle(StoreInt, write_bytes[0..store_size], write_value);
1953 writeInt(StoreInt, write_bytes[0..store_size], write_value, .Little);
18481954}
18491955
18501956fn writePackedIntBig(comptime T: type, bytes: []u8, bit_offset: usize, value: T) void {
......@@ -1879,7 +1985,7 @@ fn writePackedIntBig(comptime T: type, bytes: []u8, bit_offset: usize, value: T)
18791985 write_value |= @as(StoreInt, tail) << (8 * (store_size - 1));
18801986 }
18811987
1882 writeIntBig(StoreInt, write_bytes[(byte_count - store_size)..][0..store_size], write_value);
1988 writeInt(StoreInt, write_bytes[(byte_count - store_size)..][0..store_size], write_value, .Big);
18831989}
18841990
18851991pub const writePackedIntNative = switch (native_endian) {
......@@ -1908,91 +2014,6 @@ pub fn writePackedInt(comptime T: type, bytes: []u8, bit_offset: usize, value: T
19082014 }
19092015}
19102016
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;
1956 }
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 };
1994}
1995
19962017/// Stores an integer to packed memory with provided bit_count, bit_offset, and signedness.
19972018/// If negative, the written value is sign-extended.
19982019///
......@@ -2055,45 +2076,6 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value
20552076 write_bytes[@as(usize, @intCast(i))] |= @as(u8, @intCast(@as(uN, @bitCast(remaining)) & tail_mask));
20562077}
20572078
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
20972079/// Swap the byte order of all the members of the fields of a struct
20982080/// (Changing their endianness)
20992081pub fn byteSwapAllFields(comptime S: type, ptr: *S) void {
......@@ -3311,12 +3293,12 @@ fn testReadIntImpl() !void {
33113293 0x56,
33123294 0x78,
33133295 };
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);
3296 try testing.expect(readInt(u32, &bytes, .Big) == 0x12345678);
3297 try testing.expect(readInt(u32, &bytes, .Big) == 0x12345678);
3298 try testing.expect(readInt(i32, &bytes, .Big) == 0x12345678);
3299 try testing.expect(readInt(u32, &bytes, .Little) == 0x78563412);
3300 try testing.expect(readInt(u32, &bytes, .Little) == 0x78563412);
3301 try testing.expect(readInt(i32, &bytes, .Little) == 0x78563412);
33203302 }
33213303 {
33223304 const buf = [_]u8{
......@@ -3325,7 +3307,7 @@ fn testReadIntImpl() !void {
33253307 0x12,
33263308 0x34,
33273309 };
3328 const answer = readInt(u32, &buf, Endian.Big);
3310 const answer = readInt(u32, &buf, .Big);
33293311 try testing.expect(answer == 0x00001234);
33303312 }
33313313 {
......@@ -3335,7 +3317,7 @@ fn testReadIntImpl() !void {
33353317 0x00,
33363318 0x00,
33373319 };
3338 const answer = readInt(u32, &buf, Endian.Little);
3320 const answer = readInt(u32, &buf, .Little);
33393321 try testing.expect(answer == 0x00003412);
33403322 }
33413323 {
......@@ -3343,153 +3325,13 @@ fn testReadIntImpl() !void {
33433325 0xff,
33443326 0xfe,
33453327 };
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);
3328 try testing.expect(readInt(u16, &bytes, .Big) == 0xfffe);
3329 try testing.expect(readInt(i16, &bytes, .Big) == -0x0002);
3330 try testing.expect(readInt(u16, &bytes, .Little) == 0xfeff);
3331 try testing.expect(readInt(i16, &bytes, .Little) == -0x0101);
33503332 }
33513333}
33523334
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
34933335/// Returns the smallest number in a slice. O(n).
34943336/// `slice` must not be empty.
34953337pub fn min(comptime T: type, slice: []const T) T {
......@@ -4671,7 +4513,6 @@ pub fn alignInSlice(slice: anytype, comptime new_alignment: usize) ?AlignedSlice
46714513}
46724514
46734515test "read/write(Var)PackedInt" {
4674 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
46754516 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
46764517
46774518 switch (builtin.cpu.arch) {
lib/std/net.zig+3-3
......@@ -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/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/pdb.zig+13-13
......@@ -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) {
......@@ -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/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/tz.zig+4-4
......@@ -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+2-2
......@@ -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
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/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/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/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/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+34-32
......@@ -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,7 +39,7 @@ 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 }
......@@ -47,7 +49,7 @@ pub fn readAnyError(allocator: std.mem.Allocator, reader: anytype, max_size: u64
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
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/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