| author | |
| committer | |
| log | d890e817610dd75feef55c1f7983190852c622a5 |
| tree | 679d13309da35aa957a9d20d28671d9b8673b5a1 |
| parent | 50cdb65784937965b5871037ff40bc34d8eb14af |
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 { |
| 1624 | 1624 | switch (opcode) { |
| 1625 | 1625 | .i32_const => try writer.print("i32.const {x}\n", .{try std.leb.readILEB128(i32, reader)}), |
| 1626 | 1626 | .i64_const => try writer.print("i64.const {x}\n", .{try std.leb.readILEB128(i64, reader)}), |
| 1627 | .f32_const => try writer.print("f32.const {x}\n", .{@as(f32, @bitCast(try reader.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)))}), | |
| 1629 | 1629 | .global_get => try writer.print("global.get {x}\n", .{try std.leb.readULEB128(u32, reader)}), |
| 1630 | 1630 | else => unreachable, |
| 1631 | 1631 | } |
lib/std/base64.zig+4-4| ... | ... | @@ -104,14 +104,14 @@ pub const Base64Encoder = struct { |
| 104 | 104 | var idx: usize = 0; |
| 105 | 105 | var out_idx: usize = 0; |
| 106 | 106 | 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); | |
| 108 | 108 | inline for (0..16) |i| { |
| 109 | 109 | dest[out_idx + i] = encoder.alphabet_chars[@truncate((bits >> (122 - i * 6)) & 0x3f)]; |
| 110 | 110 | } |
| 111 | 111 | out_idx += 16; |
| 112 | 112 | } |
| 113 | 113 | 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); | |
| 115 | 115 | dest[out_idx] = encoder.alphabet_chars[(bits >> 26) & 0x3f]; |
| 116 | 116 | dest[out_idx + 1] = encoder.alphabet_chars[(bits >> 20) & 0x3f]; |
| 117 | 117 | dest[out_idx + 2] = encoder.alphabet_chars[(bits >> 14) & 0x3f]; |
| ... | ... | @@ -226,7 +226,7 @@ pub const Base64Decoder = struct { |
| 226 | 226 | if ((new_bits & invalid_char_tst) != 0) return error.InvalidCharacter; |
| 227 | 227 | bits |= (new_bits << (24 * i)); |
| 228 | 228 | } |
| 229 | std.mem.writeIntLittle(u128, dest[dest_idx..][0..16], bits); | |
| 229 | std.mem.writeInt(u128, dest[dest_idx..][0..16], bits, .Little); | |
| 230 | 230 | } |
| 231 | 231 | while (fast_src_idx + 4 < source.len and dest_idx + 3 < dest.len) : ({ |
| 232 | 232 | fast_src_idx += 4; |
| ... | ... | @@ -237,7 +237,7 @@ pub const Base64Decoder = struct { |
| 237 | 237 | bits |= decoder.fast_char_to_index[2][source[fast_src_idx + 2]]; |
| 238 | 238 | bits |= decoder.fast_char_to_index[3][source[fast_src_idx + 3]]; |
| 239 | 239 | 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); | |
| 241 | 241 | } |
| 242 | 242 | var remaining = source[fast_src_idx..]; |
| 243 | 243 | 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 { |
| 1376 | 1376 | .capable_io_mode = .blocking, |
| 1377 | 1377 | .intended_io_mode = .blocking, |
| 1378 | 1378 | }; |
| 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; | |
| 1380 | 1380 | } |
| 1381 | 1381 | |
| 1382 | 1382 | fn readIntFd(fd: i32) !ErrInt { |
| ... | ... | @@ -1385,7 +1385,7 @@ fn readIntFd(fd: i32) !ErrInt { |
| 1385 | 1385 | .capable_io_mode = .blocking, |
| 1386 | 1386 | .intended_io_mode = .blocking, |
| 1387 | 1387 | }; |
| 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)); | |
| 1389 | 1389 | } |
| 1390 | 1390 | |
| 1391 | 1391 | /// Caller must free result. |
lib/std/coff.zig+20-20| ... | ... | @@ -663,7 +663,7 @@ pub const Symbol = struct { |
| 663 | 663 | |
| 664 | 664 | pub fn getNameOffset(self: Symbol) ?u32 { |
| 665 | 665 | 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); | |
| 667 | 667 | return offset; |
| 668 | 668 | } |
| 669 | 669 | }; |
| ... | ... | @@ -1075,7 +1075,7 @@ pub const Coff = struct { |
| 1075 | 1075 | var stream = std.io.fixedBufferStream(data); |
| 1076 | 1076 | const reader = stream.reader(); |
| 1077 | 1077 | 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); | |
| 1079 | 1079 | try stream.seekTo(coff_header_offset); |
| 1080 | 1080 | var buf: [4]u8 = undefined; |
| 1081 | 1081 | try reader.readNoEof(&buf); |
| ... | ... | @@ -1142,7 +1142,7 @@ pub const Coff = struct { |
| 1142 | 1142 | if (!mem.eql(u8, &cv_signature, "RSDS")) |
| 1143 | 1143 | return error.InvalidPEMagic; |
| 1144 | 1144 | try reader.readNoEof(self.guid[0..]); |
| 1145 | self.age = try reader.readIntLittle(u32); | |
| 1145 | self.age = try reader.readInt(u32, .Little); | |
| 1146 | 1146 | |
| 1147 | 1147 | // Finally read the null-terminated string. |
| 1148 | 1148 | var byte = try reader.readByte(); |
| ... | ... | @@ -1223,7 +1223,7 @@ pub const Coff = struct { |
| 1223 | 1223 | if (coff_header.pointer_to_symbol_table == 0) return null; |
| 1224 | 1224 | |
| 1225 | 1225 | 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); | |
| 1227 | 1227 | if ((offset + size) > self.data.len) return error.InvalidStrtabSize; |
| 1228 | 1228 | |
| 1229 | 1229 | return Strtab{ .buffer = self.data[offset..][0..size] }; |
| ... | ... | @@ -1324,9 +1324,9 @@ pub const Symtab = struct { |
| 1324 | 1324 | fn asSymbol(raw: []const u8) Symbol { |
| 1325 | 1325 | return .{ |
| 1326 | 1326 | .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))), | |
| 1330 | 1330 | .storage_class = @as(StorageClass, @enumFromInt(raw[16])), |
| 1331 | 1331 | .number_of_aux_symbols = raw[17], |
| 1332 | 1332 | }; |
| ... | ... | @@ -1335,27 +1335,27 @@ pub const Symtab = struct { |
| 1335 | 1335 | fn asDebugInfo(raw: []const u8) DebugInfoDefinition { |
| 1336 | 1336 | return .{ |
| 1337 | 1337 | .unused_1 = raw[0..4].*, |
| 1338 | .linenumber = mem.readIntLittle(u16, raw[4..6]), | |
| 1338 | .linenumber = mem.readInt(u16, raw[4..6], .Little), | |
| 1339 | 1339 | .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), | |
| 1341 | 1341 | .unused_3 = raw[16..18].*, |
| 1342 | 1342 | }; |
| 1343 | 1343 | } |
| 1344 | 1344 | |
| 1345 | 1345 | fn asFuncDef(raw: []const u8) FunctionDefinition { |
| 1346 | 1346 | 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), | |
| 1351 | 1351 | .unused = raw[16..18].*, |
| 1352 | 1352 | }; |
| 1353 | 1353 | } |
| 1354 | 1354 | |
| 1355 | 1355 | fn asWeakExtDef(raw: []const u8) WeakExternalDefinition { |
| 1356 | 1356 | 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))), | |
| 1359 | 1359 | .unused = raw[8..18].*, |
| 1360 | 1360 | }; |
| 1361 | 1361 | } |
| ... | ... | @@ -1368,11 +1368,11 @@ pub const Symtab = struct { |
| 1368 | 1368 | |
| 1369 | 1369 | fn asSectDef(raw: []const u8) SectionDefinition { |
| 1370 | 1370 | 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), | |
| 1376 | 1376 | .selection = @as(ComdatSelection, @enumFromInt(raw[14])), |
| 1377 | 1377 | .unused = raw[15..18].*, |
| 1378 | 1378 | }; |
lib/std/compress/gzip.zig+5-5| ... | ... | @@ -58,7 +58,7 @@ pub fn Decompress(comptime ReaderType: type) type { |
| 58 | 58 | const FLG = header[3]; |
| 59 | 59 | // Modification time, as a Unix timestamp. |
| 60 | 60 | // 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); | |
| 62 | 62 | // Extra flags |
| 63 | 63 | const XFL = header[8]; |
| 64 | 64 | // Operating system where the compression took place |
| ... | ... | @@ -66,7 +66,7 @@ pub fn Decompress(comptime ReaderType: type) type { |
| 66 | 66 | _ = XFL; |
| 67 | 67 | |
| 68 | 68 | const extra = if (FLG & FEXTRA != 0) blk: { |
| 69 | const len = try hashed_reader.readIntLittle(u16); | |
| 69 | const len = try hashed_reader.readInt(u16, .Little); | |
| 70 | 70 | const tmp_buf = try allocator.alloc(u8, len); |
| 71 | 71 | errdefer allocator.free(tmp_buf); |
| 72 | 72 | |
| ... | ... | @@ -88,7 +88,7 @@ pub fn Decompress(comptime ReaderType: type) type { |
| 88 | 88 | errdefer if (comment) |p| allocator.free(p); |
| 89 | 89 | |
| 90 | 90 | if (FLG & FHCRC != 0) { |
| 91 | const hash = try source.readIntLittle(u16); | |
| 91 | const hash = try source.readInt(u16, .Little); | |
| 92 | 92 | if (hash != @as(u16, @truncate(hasher.hasher.final()))) |
| 93 | 93 | return error.WrongChecksum; |
| 94 | 94 | } |
| ... | ... | @@ -133,12 +133,12 @@ pub fn Decompress(comptime ReaderType: type) type { |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | // 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); | |
| 137 | 137 | if (hash != self.hasher.final()) |
| 138 | 138 | return error.WrongChecksum; |
| 139 | 139 | |
| 140 | 140 | // 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); | |
| 142 | 142 | if (self.read_amt & 0xffffffff != input_size) |
| 143 | 143 | return error.CorruptedData; |
| 144 | 144 |
lib/std/compress/lzma/decode.zig+3-3| ... | ... | @@ -58,12 +58,12 @@ pub const Params = struct { |
| 58 | 58 | props /= 5; |
| 59 | 59 | const pb = @as(u3, @intCast(props)); |
| 60 | 60 | |
| 61 | const dict_size_provided = try reader.readIntLittle(u32); | |
| 61 | const dict_size_provided = try reader.readInt(u32, .Little); | |
| 62 | 62 | const dict_size = @max(0x1000, dict_size_provided); |
| 63 | 63 | |
| 64 | 64 | const unpacked_size = switch (options.unpacked_size) { |
| 65 | 65 | .read_from_header => blk: { |
| 66 | const unpacked_size_provided = try reader.readIntLittle(u64); | |
| 66 | const unpacked_size_provided = try reader.readInt(u64, .Little); | |
| 67 | 67 | const marker_mandatory = unpacked_size_provided == 0xFFFF_FFFF_FFFF_FFFF; |
| 68 | 68 | break :blk if (marker_mandatory) |
| 69 | 69 | null |
| ... | ... | @@ -71,7 +71,7 @@ pub const Params = struct { |
| 71 | 71 | unpacked_size_provided; |
| 72 | 72 | }, |
| 73 | 73 | .read_header_but_use_provided => |x| blk: { |
| 74 | _ = try reader.readIntLittle(u64); | |
| 74 | _ = try reader.readInt(u64, .Little); | |
| 75 | 75 | break :blk x; |
| 76 | 76 | }, |
| 77 | 77 | .use_provided => |x| x, |
lib/std/compress/lzma/decode/rangecoder.zig+1-1| ... | ... | @@ -12,7 +12,7 @@ pub const RangeDecoder = struct { |
| 12 | 12 | } |
| 13 | 13 | return RangeDecoder{ |
| 14 | 14 | .range = 0xFFFF_FFFF, |
| 15 | .code = try reader.readIntBig(u32), | |
| 15 | .code = try reader.readInt(u32, .Big), | |
| 16 | 16 | }; |
| 17 | 17 | } |
| 18 | 18 |
lib/std/compress/lzma2/decode.zig+3-3| ... | ... | @@ -97,12 +97,12 @@ pub const Decoder = struct { |
| 97 | 97 | const unpacked_size = blk: { |
| 98 | 98 | var tmp: u64 = status & 0x1F; |
| 99 | 99 | tmp <<= 16; |
| 100 | tmp |= try reader.readIntBig(u16); | |
| 100 | tmp |= try reader.readInt(u16, .Big); | |
| 101 | 101 | break :blk tmp + 1; |
| 102 | 102 | }; |
| 103 | 103 | |
| 104 | 104 | const packed_size = blk: { |
| 105 | const tmp: u17 = try reader.readIntBig(u16); | |
| 105 | const tmp: u17 = try reader.readInt(u16, .Big); | |
| 106 | 106 | break :blk tmp + 1; |
| 107 | 107 | }; |
| 108 | 108 | |
| ... | ... | @@ -155,7 +155,7 @@ pub const Decoder = struct { |
| 155 | 155 | accum: *LzAccumBuffer, |
| 156 | 156 | reset_dict: bool, |
| 157 | 157 | ) !void { |
| 158 | const unpacked_size = @as(u17, try reader.readIntBig(u16)) + 1; | |
| 158 | const unpacked_size = @as(u17, try reader.readInt(u16, .Big)) + 1; | |
| 159 | 159 | |
| 160 | 160 | if (reset_dict) { |
| 161 | 161 | try accum.reset(writer); |
lib/std/compress/xz.zig+4-4| ... | ... | @@ -52,7 +52,7 @@ pub fn Decompress(comptime ReaderType: type) type { |
| 52 | 52 | break :blk hasher.hasher.final(); |
| 53 | 53 | }; |
| 54 | 54 | |
| 55 | const hash_b = try source.readIntLittle(u32); | |
| 55 | const hash_b = try source.readInt(u32, .Little); | |
| 56 | 56 | if (hash_a != hash_b) |
| 57 | 57 | return error.WrongChecksum; |
| 58 | 58 | |
| ... | ... | @@ -105,20 +105,20 @@ pub fn Decompress(comptime ReaderType: type) type { |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | 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); | |
| 109 | 109 | if (hash_a != hash_b) |
| 110 | 110 | return error.WrongChecksum; |
| 111 | 111 | |
| 112 | 112 | break :blk counter.bytes_read; |
| 113 | 113 | }; |
| 114 | 114 | |
| 115 | const hash_a = try self.in_reader.readIntLittle(u32); | |
| 115 | const hash_a = try self.in_reader.readInt(u32, .Little); | |
| 116 | 116 | |
| 117 | 117 | const hash_b = blk: { |
| 118 | 118 | var hasher = std.compress.hashedReader(self.in_reader, Crc32.init()); |
| 119 | 119 | const hashed_reader = hasher.reader(); |
| 120 | 120 | |
| 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; | |
| 122 | 122 | if (backward_size != index_size) |
| 123 | 123 | return error.CorruptInput; |
| 124 | 124 |
lib/std/compress/xz/block.zig+3-3| ... | ... | @@ -148,7 +148,7 @@ pub fn Decoder(comptime ReaderType: type) type { |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | 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); | |
| 152 | 152 | if (hash_a != hash_b) |
| 153 | 153 | return error.WrongChecksum; |
| 154 | 154 | } |
| ... | ... | @@ -182,13 +182,13 @@ pub fn Decoder(comptime ReaderType: type) type { |
| 182 | 182 | .none => {}, |
| 183 | 183 | .crc32 => { |
| 184 | 184 | 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); | |
| 186 | 186 | if (hash_a != hash_b) |
| 187 | 187 | return error.WrongChecksum; |
| 188 | 188 | }, |
| 189 | 189 | .crc64 => { |
| 190 | 190 | 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); | |
| 192 | 192 | if (hash_a != hash_b) |
| 193 | 193 | return error.WrongChecksum; |
| 194 | 194 | }, |
lib/std/compress/zlib.zig+4-4| ... | ... | @@ -36,7 +36,7 @@ pub fn DecompressStream(comptime ReaderType: type) type { |
| 36 | 36 | |
| 37 | 37 | fn init(allocator: mem.Allocator, source: ReaderType) !Self { |
| 38 | 38 | // Zlib header format is specified in RFC1950 |
| 39 | const header_u16 = try source.readIntBig(u16); | |
| 39 | const header_u16 = try source.readInt(u16, .Big); | |
| 40 | 40 | |
| 41 | 41 | // verify the header checksum |
| 42 | 42 | if (header_u16 % 31 != 0) |
| ... | ... | @@ -81,7 +81,7 @@ pub fn DecompressStream(comptime ReaderType: type) type { |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | // 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); | |
| 85 | 85 | if (hash != self.hasher.final()) |
| 86 | 86 | return error.WrongChecksum; |
| 87 | 87 | |
| ... | ... | @@ -132,7 +132,7 @@ pub fn CompressStream(comptime WriterType: type) type { |
| 132 | 132 | }; |
| 133 | 133 | header.checksum = @as(u5, @truncate(31 - @as(u16, @bitCast(header)) % 31)); |
| 134 | 134 | |
| 135 | try dest.writeIntBig(u16, @as(u16, @bitCast(header))); | |
| 135 | try dest.writeInt(u16, @as(u16, @bitCast(header)), .Big); | |
| 136 | 136 | |
| 137 | 137 | const compression_level: deflate.Compression = switch (options.level) { |
| 138 | 138 | .no_compression => .no_compression, |
| ... | ... | @@ -171,7 +171,7 @@ pub fn CompressStream(comptime WriterType: type) type { |
| 171 | 171 | pub fn finish(self: *Self) !void { |
| 172 | 172 | const hash = self.hasher.final(); |
| 173 | 173 | try self.deflator.close(); |
| 174 | try self.in_writer.writeIntBig(u32, hash); | |
| 174 | try self.in_writer.writeInt(u32, hash, .Big); | |
| 175 | 175 | } |
| 176 | 176 | }; |
| 177 | 177 | } |
lib/std/compress/zstandard.zig+1-1| ... | ... | @@ -201,7 +201,7 @@ pub fn DecompressStream( |
| 201 | 201 | if (block_header.last_block) { |
| 202 | 202 | self.state = .LastBlock; |
| 203 | 203 | if (self.frame_context.has_checksum) { |
| 204 | const checksum = source_reader.readIntLittle(u32) catch | |
| 204 | const checksum = source_reader.readInt(u32, .Little) catch | |
| 205 | 205 | return error.MalformedFrame; |
| 206 | 206 | if (comptime options.verify_checksum) { |
| 207 | 207 | 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"); |
| 13 | 13 | |
| 14 | 14 | const decodeFseTable = @import("fse.zig").decodeFseTable; |
| 15 | 15 | |
| 16 | const readInt = std.mem.readIntLittle; | |
| 17 | ||
| 18 | 16 | pub const Error = error{ |
| 19 | 17 | BlockSizeOverMaximum, |
| 20 | 18 | MalformedBlockSize, |
| ... | ... | @@ -1031,9 +1029,9 @@ fn decodeStreams(size_format: u2, stream_data: []const u8) !LiteralsSection.Stre |
| 1031 | 1029 | |
| 1032 | 1030 | if (stream_data.len < 6) return error.MalformedLiteralsSection; |
| 1033 | 1031 | |
| 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); | |
| 1037 | 1035 | |
| 1038 | 1036 | const stream_1_start = 6; |
| 1039 | 1037 | 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"); |
| 15 | 15 | |
| 16 | 16 | const readers = @import("readers.zig"); |
| 17 | 17 | |
| 18 | const readInt = std.mem.readIntLittle; | |
| 19 | const readIntSlice = std.mem.readIntSliceLittle; | |
| 20 | ||
| 21 | 18 | /// Returns `true` is `magic` is a valid magic number for a skippable frame |
| 22 | 19 | pub fn isSkippableMagic(magic: u32) bool { |
| 23 | 20 | return frame.Skippable.magic_number_min <= magic and magic <= frame.Skippable.magic_number_max; |
| ... | ... | @@ -31,7 +28,7 @@ pub fn isSkippableMagic(magic: u32) bool { |
| 31 | 28 | /// skippable frames. |
| 32 | 29 | /// - `error.EndOfStream` if `source` contains fewer than 4 bytes |
| 33 | 30 | pub fn decodeFrameType(source: anytype) error{ BadMagic, EndOfStream }!frame.Kind { |
| 34 | const magic = try source.readIntLittle(u32); | |
| 31 | const magic = try source.readInt(u32, .Little); | |
| 35 | 32 | return frameType(magic); |
| 36 | 33 | } |
| 37 | 34 | |
| ... | ... | @@ -65,14 +62,14 @@ pub const HeaderError = error{ BadMagic, EndOfStream, ReservedBitSet }; |
| 65 | 62 | /// - `error.ReservedBitSet` if the frame is a Zstandard frame and any of the |
| 66 | 63 | /// reserved bits are set |
| 67 | 64 | pub fn decodeFrameHeader(source: anytype) (@TypeOf(source).Error || HeaderError)!FrameHeader { |
| 68 | const magic = try source.readIntLittle(u32); | |
| 65 | const magic = try source.readInt(u32, .Little); | |
| 69 | 66 | const frame_type = try frameType(magic); |
| 70 | 67 | switch (frame_type) { |
| 71 | 68 | .zstandard => return FrameHeader{ .zstandard = try decodeZstandardHeader(source) }, |
| 72 | 69 | .skippable => return FrameHeader{ |
| 73 | 70 | .skippable = .{ |
| 74 | 71 | .magic_number = magic, |
| 75 | .frame_size = try source.readIntLittle(u32), | |
| 72 | .frame_size = try source.readInt(u32, .Little), | |
| 76 | 73 | }, |
| 77 | 74 | }, |
| 78 | 75 | } |
| ... | ... | @@ -193,7 +190,7 @@ pub fn decodeFrame( |
| 193 | 190 | switch (try decodeFrameType(fbs.reader())) { |
| 194 | 191 | .zstandard => return decodeZstandardFrame(dest, src, verify_checksum), |
| 195 | 192 | .skippable => { |
| 196 | const content_size = try fbs.reader().readIntLittle(u32); | |
| 193 | const content_size = try fbs.reader().readInt(u32, .Little); | |
| 197 | 194 | if (content_size > std.math.maxInt(usize) - 8) return error.SkippableSizeTooLarge; |
| 198 | 195 | const read_count = @as(usize, content_size) + 8; |
| 199 | 196 | if (read_count > src.len) return error.SkippableSizeTooLarge; |
| ... | ... | @@ -238,7 +235,7 @@ pub fn decodeFrameArrayList( |
| 238 | 235 | ) (error{ BadMagic, OutOfMemory, SkippableSizeTooLarge } || FrameContext.Error || FrameError)!usize { |
| 239 | 236 | var fbs = std.io.fixedBufferStream(src); |
| 240 | 237 | const reader = fbs.reader(); |
| 241 | const magic = try reader.readIntLittle(u32); | |
| 238 | const magic = try reader.readInt(u32, .Little); | |
| 242 | 239 | switch (try frameType(magic)) { |
| 243 | 240 | .zstandard => return decodeZstandardFrameArrayList( |
| 244 | 241 | allocator, |
| ... | ... | @@ -248,7 +245,7 @@ pub fn decodeFrameArrayList( |
| 248 | 245 | window_size_max, |
| 249 | 246 | ), |
| 250 | 247 | .skippable => { |
| 251 | const content_size = try fbs.reader().readIntLittle(u32); | |
| 248 | const content_size = try fbs.reader().readInt(u32, .Little); | |
| 252 | 249 | if (content_size > std.math.maxInt(usize) - 8) return error.SkippableSizeTooLarge; |
| 253 | 250 | const read_count = @as(usize, content_size) + 8; |
| 254 | 251 | if (read_count > src.len) return error.SkippableSizeTooLarge; |
| ... | ... | @@ -302,7 +299,7 @@ pub fn decodeZstandardFrame( |
| 302 | 299 | WindowSizeUnknown, |
| 303 | 300 | DictionaryIdFlagUnsupported, |
| 304 | 301 | } || 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); | |
| 306 | 303 | var consumed_count: usize = 4; |
| 307 | 304 | |
| 308 | 305 | var frame_context = context: { |
| ... | ... | @@ -354,7 +351,7 @@ pub fn decodeZStandardFrameBlocks( |
| 354 | 351 | if (written_count != content_size) return error.BadContentSize; |
| 355 | 352 | if (frame_context.has_checksum) { |
| 356 | 353 | 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); | |
| 358 | 355 | consumed_count += 4; |
| 359 | 356 | if (frame_context.hasher_opt) |*hasher| { |
| 360 | 357 | if (checksum != computeChecksum(hasher)) return error.ChecksumFailure; |
| ... | ... | @@ -445,7 +442,7 @@ pub fn decodeZstandardFrameArrayList( |
| 445 | 442 | verify_checksum: bool, |
| 446 | 443 | window_size_max: usize, |
| 447 | 444 | ) (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); | |
| 449 | 446 | var consumed_count: usize = 4; |
| 450 | 447 | |
| 451 | 448 | var frame_context = context: { |
| ... | ... | @@ -520,7 +517,7 @@ pub fn decodeZstandardFrameBlocksArrayList( |
| 520 | 517 | |
| 521 | 518 | if (frame_context.has_checksum) { |
| 522 | 519 | 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); | |
| 524 | 521 | consumed_count += 4; |
| 525 | 522 | if (frame_context.hasher_opt) |*hasher| { |
| 526 | 523 | if (checksum != computeChecksum(hasher)) return error.ChecksumFailure; |
| ... | ... | @@ -569,9 +566,9 @@ fn decodeFrameBlocksInner( |
| 569 | 566 | /// Decode the header of a skippable frame. The first four bytes of `src` must |
| 570 | 567 | /// be a valid magic number for a skippable frame. |
| 571 | 568 | pub 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); | |
| 573 | 570 | assert(isSkippableMagic(magic)); |
| 574 | const frame_size = readInt(u32, src[4..8]); | |
| 571 | const frame_size = std.mem.readInt(u32, src[4..8], .Little); | |
| 575 | 572 | return .{ |
| 576 | 573 | .magic_number = magic, |
| 577 | 574 | .frame_size = frame_size, |
lib/std/crypto/25519/field.zig+9-11| ... | ... | @@ -1,8 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | const crypto = std.crypto; |
| 4 | const readIntLittle = std.mem.readIntLittle; | |
| 5 | const writeIntLittle = std.mem.writeIntLittle; | |
| 6 | 4 | |
| 7 | 5 | const NonCanonicalError = crypto.errors.NonCanonicalError; |
| 8 | 6 | const NotSquareError = crypto.errors.NotSquareError; |
| ... | ... | @@ -73,11 +71,11 @@ pub const Fe = struct { |
| 73 | 71 | /// Unpack a field element |
| 74 | 72 | pub fn fromBytes(s: [32]u8) Fe { |
| 75 | 73 | 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; | |
| 81 | 79 | |
| 82 | 80 | return fe; |
| 83 | 81 | } |
| ... | ... | @@ -87,10 +85,10 @@ pub const Fe = struct { |
| 87 | 85 | var reduced = fe; |
| 88 | 86 | reduced.reduce(); |
| 89 | 87 | 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); | |
| 94 | 92 | |
| 95 | 93 | return s; |
| 96 | 94 | } |
lib/std/crypto/25519/scalar.zig+6-6| ... | ... | @@ -15,7 +15,7 @@ pub const zero = [_]u8{0} ** 32; |
| 15 | 15 | |
| 16 | 16 | const field_order_s = s: { |
| 17 | 17 | var s: [32]u8 = undefined; |
| 18 | mem.writeIntLittle(u256, &s, field_order); | |
| 18 | mem.writeInt(u256, &s, field_order, .Little); | |
| 19 | 19 | break :s s; |
| 20 | 20 | }; |
| 21 | 21 | |
| ... | ... | @@ -127,9 +127,9 @@ pub const Scalar = struct { |
| 127 | 127 | var bytes: CompressedScalar = undefined; |
| 128 | 128 | var i: usize = 0; |
| 129 | 129 | 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); | |
| 131 | 131 | } |
| 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); | |
| 133 | 133 | return bytes; |
| 134 | 134 | } |
| 135 | 135 | |
| ... | ... | @@ -580,7 +580,7 @@ const ScalarDouble = struct { |
| 580 | 580 | var limbs: Limbs = undefined; |
| 581 | 581 | var i: usize = 0; |
| 582 | 582 | 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; | |
| 584 | 584 | } |
| 585 | 585 | limbs[i] = @as(u64, bytes[i * 7]); |
| 586 | 586 | return ScalarDouble{ .limbs = limbs }; |
| ... | ... | @@ -590,9 +590,9 @@ const ScalarDouble = struct { |
| 590 | 590 | var limbs: Limbs = undefined; |
| 591 | 591 | var i: usize = 0; |
| 592 | 592 | 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; | |
| 594 | 594 | } |
| 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)); | |
| 596 | 596 | @memset(limbs[5..], 0); |
| 597 | 597 | return ScalarDouble{ .limbs = limbs }; |
| 598 | 598 | } |
lib/std/crypto/Certificate/Bundle/macos.zig+2-2| ... | ... | @@ -32,7 +32,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void { |
| 32 | 32 | |
| 33 | 33 | var table_idx: u32 = 0; |
| 34 | 34 | 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); | |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | const now_sec = std.time.timestamp(); |
| ... | ... | @@ -51,7 +51,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void { |
| 51 | 51 | |
| 52 | 52 | var record_idx: u32 = 0; |
| 53 | 53 | 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); | |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | for (record_list) |record_offset| { |
lib/std/crypto/aegis.zig+4-4| ... | ... | @@ -106,8 +106,8 @@ const State128L = struct { |
| 106 | 106 | fn mac(state: *State128L, comptime tag_bits: u9, adlen: usize, mlen: usize) [tag_bits / 8]u8 { |
| 107 | 107 | const blocks = &state.blocks; |
| 108 | 108 | 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); | |
| 111 | 111 | const tmp = AesBlock.fromBytes(&sizes).xorBlocks(blocks[2]); |
| 112 | 112 | var i: usize = 0; |
| 113 | 113 | while (i < 7) : (i += 1) { |
| ... | ... | @@ -284,8 +284,8 @@ const State256 = struct { |
| 284 | 284 | fn mac(state: *State256, comptime tag_bits: u9, adlen: usize, mlen: usize) [tag_bits / 8]u8 { |
| 285 | 285 | const blocks = &state.blocks; |
| 286 | 286 | 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); | |
| 289 | 289 | const tmp = AesBlock.fromBytes(&sizes).xorBlocks(blocks[3]); |
| 290 | 290 | var i: usize = 0; |
| 291 | 291 | while (i < 7) : (i += 1) { |
lib/std/crypto/aes/soft.zig+18-18| ... | ... | @@ -15,20 +15,20 @@ pub const Block = struct { |
| 15 | 15 | |
| 16 | 16 | /// Convert a byte sequence into an internal representation. |
| 17 | 17 | 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); | |
| 22 | 22 | return Block{ .repr = BlockVec{ s0, s1, s2, s3 } }; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /// Convert the internal representation of a block into a byte sequence. |
| 26 | 26 | pub inline fn toBytes(block: Block) [16]u8 { |
| 27 | 27 | 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); | |
| 32 | 32 | return bytes; |
| 33 | 33 | } |
| 34 | 34 | |
| ... | ... | @@ -123,13 +123,13 @@ pub const Block = struct { |
| 123 | 123 | // Last round uses s-box directly and XORs to produce output. |
| 124 | 124 | var x: [4]u8 = undefined; |
| 125 | 125 | x = sbox_lookup(&sbox_encrypt, @as(u8, @truncate(s0)), @as(u8, @truncate(s1 >> 8)), @as(u8, @truncate(s2 >> 16)), @as(u8, @truncate(s3 >> 24))); |
| 126 | var t0 = mem.readIntLittle(u32, &x); | |
| 126 | var t0 = mem.readInt(u32, &x, .Little); | |
| 127 | 127 | x = sbox_lookup(&sbox_encrypt, @as(u8, @truncate(s1)), @as(u8, @truncate(s2 >> 8)), @as(u8, @truncate(s3 >> 16)), @as(u8, @truncate(s0 >> 24))); |
| 128 | var t1 = mem.readIntLittle(u32, &x); | |
| 128 | var t1 = mem.readInt(u32, &x, .Little); | |
| 129 | 129 | x = sbox_lookup(&sbox_encrypt, @as(u8, @truncate(s2)), @as(u8, @truncate(s3 >> 8)), @as(u8, @truncate(s0 >> 16)), @as(u8, @truncate(s1 >> 24))); |
| 130 | var t2 = mem.readIntLittle(u32, &x); | |
| 130 | var t2 = mem.readInt(u32, &x, .Little); | |
| 131 | 131 | x = sbox_lookup(&sbox_encrypt, @as(u8, @truncate(s3)), @as(u8, @truncate(s0 >> 8)), @as(u8, @truncate(s1 >> 16)), @as(u8, @truncate(s2 >> 24))); |
| 132 | var t3 = mem.readIntLittle(u32, &x); | |
| 132 | var t3 = mem.readInt(u32, &x, .Little); | |
| 133 | 133 | |
| 134 | 134 | t0 ^= round_key.repr[0]; |
| 135 | 135 | t1 ^= round_key.repr[1]; |
| ... | ... | @@ -219,13 +219,13 @@ pub const Block = struct { |
| 219 | 219 | // Last round uses s-box directly and XORs to produce output. |
| 220 | 220 | var x: [4]u8 = undefined; |
| 221 | 221 | x = sbox_lookup(&sbox_decrypt, @as(u8, @truncate(s0)), @as(u8, @truncate(s3 >> 8)), @as(u8, @truncate(s2 >> 16)), @as(u8, @truncate(s1 >> 24))); |
| 222 | var t0 = mem.readIntLittle(u32, &x); | |
| 222 | var t0 = mem.readInt(u32, &x, .Little); | |
| 223 | 223 | x = sbox_lookup(&sbox_decrypt, @as(u8, @truncate(s1)), @as(u8, @truncate(s0 >> 8)), @as(u8, @truncate(s3 >> 16)), @as(u8, @truncate(s2 >> 24))); |
| 224 | var t1 = mem.readIntLittle(u32, &x); | |
| 224 | var t1 = mem.readInt(u32, &x, .Little); | |
| 225 | 225 | x = sbox_lookup(&sbox_decrypt, @as(u8, @truncate(s2)), @as(u8, @truncate(s1 >> 8)), @as(u8, @truncate(s0 >> 16)), @as(u8, @truncate(s3 >> 24))); |
| 226 | var t2 = mem.readIntLittle(u32, &x); | |
| 226 | var t2 = mem.readInt(u32, &x, .Little); | |
| 227 | 227 | x = sbox_lookup(&sbox_decrypt, @as(u8, @truncate(s3)), @as(u8, @truncate(s2 >> 8)), @as(u8, @truncate(s1 >> 16)), @as(u8, @truncate(s0 >> 24))); |
| 228 | var t3 = mem.readIntLittle(u32, &x); | |
| 228 | var t3 = mem.readInt(u32, &x, .Little); | |
| 229 | 229 | |
| 230 | 230 | t0 ^= round_key.repr[0]; |
| 231 | 231 | t1 ^= round_key.repr[1]; |
| ... | ... | @@ -349,14 +349,14 @@ fn KeySchedule(comptime Aes: type) type { |
| 349 | 349 | // Apply sbox_encrypt to each byte in w. |
| 350 | 350 | fn func(w: u32) u32 { |
| 351 | 351 | const x = sbox_lookup(&sbox_key_schedule, @as(u8, @truncate(w)), @as(u8, @truncate(w >> 8)), @as(u8, @truncate(w >> 16)), @as(u8, @truncate(w >> 24))); |
| 352 | return mem.readIntLittle(u32, &x); | |
| 352 | return mem.readInt(u32, &x, .Little); | |
| 353 | 353 | } |
| 354 | 354 | }.func; |
| 355 | 355 | |
| 356 | 356 | var round_keys: [rounds + 1]Block = undefined; |
| 357 | 357 | comptime var i: usize = 0; |
| 358 | 358 | 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); | |
| 360 | 360 | } |
| 361 | 361 | inline while (i < round_keys.len * 4) : (i += 1) { |
| 362 | 362 | 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 { |
| 33 | 33 | var t: [16]u8 = undefined; |
| 34 | 34 | var j: [16]u8 = undefined; |
| 35 | 35 | 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); | |
| 37 | 37 | aes.encrypt(&t, &j); |
| 38 | 38 | |
| 39 | 39 | const block_count = (math.divCeil(usize, ad.len, Ghash.block_length) catch unreachable) + (math.divCeil(usize, c.len, Ghash.block_length) catch unreachable) + 1; |
| ... | ... | @@ -41,14 +41,14 @@ fn AesGcm(comptime Aes: anytype) type { |
| 41 | 41 | mac.update(ad); |
| 42 | 42 | mac.pad(); |
| 43 | 43 | |
| 44 | mem.writeIntBig(u32, j[nonce_length..][0..4], 2); | |
| 44 | mem.writeInt(u32, j[nonce_length..][0..4], 2, .Big); | |
| 45 | 45 | modes.ctr(@TypeOf(aes), aes, c, m, j, std.builtin.Endian.Big); |
| 46 | 46 | mac.update(c[0..m.len][0..]); |
| 47 | 47 | mac.pad(); |
| 48 | 48 | |
| 49 | 49 | 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); | |
| 52 | 52 | mac.update(&final_block); |
| 53 | 53 | mac.final(tag); |
| 54 | 54 | for (t, 0..) |x, i| { |
| ... | ... | @@ -75,7 +75,7 @@ fn AesGcm(comptime Aes: anytype) type { |
| 75 | 75 | var t: [16]u8 = undefined; |
| 76 | 76 | var j: [16]u8 = undefined; |
| 77 | 77 | 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); | |
| 79 | 79 | aes.encrypt(&t, &j); |
| 80 | 80 | |
| 81 | 81 | const block_count = (math.divCeil(usize, ad.len, Ghash.block_length) catch unreachable) + (math.divCeil(usize, c.len, Ghash.block_length) catch unreachable) + 1; |
| ... | ... | @@ -87,8 +87,8 @@ fn AesGcm(comptime Aes: anytype) type { |
| 87 | 87 | mac.pad(); |
| 88 | 88 | |
| 89 | 89 | 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); | |
| 92 | 92 | mac.update(&final_block); |
| 93 | 93 | var computed_tag: [Ghash.mac_length]u8 = undefined; |
| 94 | 94 | mac.final(&computed_tag); |
| ... | ... | @@ -103,7 +103,7 @@ fn AesGcm(comptime Aes: anytype) type { |
| 103 | 103 | return error.AuthenticationFailed; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | mem.writeIntBig(u32, j[nonce_length..][0..4], 2); | |
| 106 | mem.writeInt(u32, j[nonce_length..][0..4], 2, .Big); | |
| 107 | 107 | modes.ctr(@TypeOf(aes), aes, m, c, j, std.builtin.Endian.Big); |
| 108 | 108 | } |
| 109 | 109 | }; |
lib/std/crypto/aes_ocb.zig+4-4| ... | ... | @@ -29,10 +29,10 @@ fn AesOcb(comptime Aes: anytype) type { |
| 29 | 29 | upto: usize, |
| 30 | 30 | |
| 31 | 31 | inline fn double(l: Block) Block { |
| 32 | const l_ = mem.readIntBig(u128, &l); | |
| 32 | const l_ = mem.readInt(u128, &l, .Big); | |
| 33 | 33 | const l_2 = (l_ << 1) ^ (0x87 & -%(l_ >> 127)); |
| 34 | 34 | var l2: Block = undefined; |
| 35 | mem.writeIntBig(u128, &l2, l_2); | |
| 35 | mem.writeInt(u128, &l2, l_2, .Big); | |
| 36 | 36 | return l2; |
| 37 | 37 | } |
| 38 | 38 | |
| ... | ... | @@ -94,10 +94,10 @@ fn AesOcb(comptime Aes: anytype) type { |
| 94 | 94 | nx[15] &= 0xc0; |
| 95 | 95 | var ktop_: Block = undefined; |
| 96 | 96 | aes_enc_ctx.encrypt(&ktop_, &nx); |
| 97 | const ktop = mem.readIntBig(u128, &ktop_); | |
| 97 | const ktop = mem.readInt(u128, &ktop_, .Big); | |
| 98 | 98 | var stretch = (@as(u192, ktop) << 64) | @as(u192, @as(u64, @truncate(ktop >> 64)) ^ @as(u64, @truncate(ktop >> 56))); |
| 99 | 99 | 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); | |
| 101 | 101 | return offset; |
| 102 | 102 | } |
| 103 | 103 |
lib/std/crypto/argon2.zig+17-17| ... | ... | @@ -110,27 +110,27 @@ fn initHash( |
| 110 | 110 | var parameters: [24]u8 = undefined; |
| 111 | 111 | var tmp: [4]u8 = undefined; |
| 112 | 112 | 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); | |
| 119 | 119 | b2.update(&parameters); |
| 120 | mem.writeIntLittle(u32, &tmp, @as(u32, @intCast(password.len))); | |
| 120 | mem.writeInt(u32, &tmp, @as(u32, @intCast(password.len)), .Little); | |
| 121 | 121 | b2.update(&tmp); |
| 122 | 122 | b2.update(password); |
| 123 | mem.writeIntLittle(u32, &tmp, @as(u32, @intCast(salt.len))); | |
| 123 | mem.writeInt(u32, &tmp, @as(u32, @intCast(salt.len)), .Little); | |
| 124 | 124 | b2.update(&tmp); |
| 125 | 125 | b2.update(salt); |
| 126 | 126 | const secret = params.secret orelse ""; |
| 127 | 127 | 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); | |
| 129 | 129 | b2.update(&tmp); |
| 130 | 130 | b2.update(secret); |
| 131 | 131 | const ad = params.ad orelse ""; |
| 132 | 132 | 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); | |
| 134 | 134 | b2.update(&tmp); |
| 135 | 135 | b2.update(ad); |
| 136 | 136 | b2.final(h0[0..Blake2b512.digest_length]); |
| ... | ... | @@ -140,7 +140,7 @@ fn initHash( |
| 140 | 140 | fn blake2bLong(out: []u8, in: []const u8) void { |
| 141 | 141 | const H = Blake2b512; |
| 142 | 142 | 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); | |
| 144 | 144 | |
| 145 | 145 | var out_buf: [H.digest_length]u8 = undefined; |
| 146 | 146 | |
| ... | ... | @@ -183,18 +183,18 @@ fn initBlocks( |
| 183 | 183 | var lane: u24 = 0; |
| 184 | 184 | while (lane < threads) : (lane += 1) { |
| 185 | 185 | 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); | |
| 187 | 187 | |
| 188 | mem.writeIntLittle(u32, h0[Blake2b512.digest_length..][0..4], 0); | |
| 188 | mem.writeInt(u32, h0[Blake2b512.digest_length..][0..4], 0, .Little); | |
| 189 | 189 | blake2bLong(&block0, h0); |
| 190 | 190 | 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); | |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | mem.writeIntLittle(u32, h0[Blake2b512.digest_length..][0..4], 1); | |
| 194 | mem.writeInt(u32, h0[Blake2b512.digest_length..][0..4], 1, .Little); | |
| 195 | 195 | blake2bLong(&block0, h0); |
| 196 | 196 | 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); | |
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | } |
| ... | ... | @@ -433,7 +433,7 @@ fn finalize( |
| 433 | 433 | } |
| 434 | 434 | var block: [1024]u8 = undefined; |
| 435 | 435 | 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); | |
| 437 | 437 | } |
| 438 | 438 | blake2bLong(out, &block); |
| 439 | 439 | } |
lib/std/crypto/ascon.zig+7-6| ... | ... | @@ -8,11 +8,12 @@ |
| 8 | 8 | //! It is not meant to be used directly, but as a building block for symmetric cryptography. |
| 9 | 9 | |
| 10 | 10 | const std = @import("std"); |
| 11 | const builtin = std.builtin; | |
| 11 | const builtin = @import("builtin"); | |
| 12 | 12 | const debug = std.debug; |
| 13 | 13 | const mem = std.mem; |
| 14 | 14 | const testing = std.testing; |
| 15 | 15 | const rotr = std.math.rotr; |
| 16 | const native_endian = builtin.cpu.arch.endian(); | |
| 16 | 17 | |
| 17 | 18 | /// An Ascon state. |
| 18 | 19 | /// |
| ... | ... | @@ -20,7 +21,7 @@ const rotr = std.math.rotr; |
| 20 | 21 | /// |
| 21 | 22 | /// The NIST submission (v1.2) serializes these words as big-endian, |
| 22 | 23 | /// but software implementations are free to use native endianness. |
| 23 | pub fn State(comptime endian: builtin.Endian) type { | |
| 24 | pub fn State(comptime endian: std.builtin.Endian) type { | |
| 24 | 25 | return struct { |
| 25 | 26 | const Self = @This(); |
| 26 | 27 | |
| ... | ... | @@ -133,14 +134,14 @@ pub fn State(comptime endian: builtin.Endian) type { |
| 133 | 134 | |
| 134 | 135 | var i: usize = 0; |
| 135 | 136 | 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); | |
| 138 | 139 | } |
| 139 | 140 | if (i < in.len) { |
| 140 | 141 | var padded = [_]u8{0} ** 8; |
| 141 | 142 | @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); | |
| 144 | 145 | @memcpy(out[i..], padded[0 .. in.len - i]); |
| 145 | 146 | } |
| 146 | 147 | } |
lib/std/crypto/bcrypt.zig+2-2| ... | ... | @@ -451,7 +451,7 @@ pub fn bcrypt( |
| 451 | 451 | |
| 452 | 452 | var ct: [ct_length]u8 = undefined; |
| 453 | 453 | 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); | |
| 455 | 455 | } |
| 456 | 456 | return ct[0..dk_length].*; |
| 457 | 457 | } |
| ... | ... | @@ -547,7 +547,7 @@ const pbkdf_prf = struct { |
| 547 | 547 | // copy out |
| 548 | 548 | var out: [32]u8 = undefined; |
| 549 | 549 | 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); | |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | // zap |
lib/std/crypto/blake2.zig+10-10| ... | ... | @@ -85,12 +85,12 @@ pub fn Blake2s(comptime out_bits: usize) type { |
| 85 | 85 | d.buf_len = 0; |
| 86 | 86 | |
| 87 | 87 | 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); | |
| 90 | 90 | } |
| 91 | 91 | 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); | |
| 94 | 94 | } |
| 95 | 95 | if (key_len > 0) { |
| 96 | 96 | @memset(d.buf[key_len..], 0); |
| ... | ... | @@ -143,7 +143,7 @@ pub fn Blake2s(comptime out_bits: usize) type { |
| 143 | 143 | var v: [16]u32 = undefined; |
| 144 | 144 | |
| 145 | 145 | 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); | |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | var k: usize = 0; |
| ... | ... | @@ -521,12 +521,12 @@ pub fn Blake2b(comptime out_bits: usize) type { |
| 521 | 521 | d.buf_len = 0; |
| 522 | 522 | |
| 523 | 523 | 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); | |
| 526 | 526 | } |
| 527 | 527 | 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); | |
| 530 | 530 | } |
| 531 | 531 | if (key_len > 0) { |
| 532 | 532 | @memset(d.buf[key_len..], 0); |
| ... | ... | @@ -579,7 +579,7 @@ pub fn Blake2b(comptime out_bits: usize) type { |
| 579 | 579 | var v: [16]u64 = undefined; |
| 580 | 580 | |
| 581 | 581 | 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); | |
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | var k: usize = 0; |
lib/std/crypto/blake3.zig+2-2| ... | ... | @@ -212,7 +212,7 @@ fn first8Words(words: [16]u32) [8]u32 { |
| 212 | 212 | fn wordsFromLittleEndianBytes(comptime count: usize, bytes: [count * 4]u8) [count]u32 { |
| 213 | 213 | var words: [count]u32 = undefined; |
| 214 | 214 | for (&words, 0..) |*word, i| { |
| 215 | word.* = mem.readIntSliceLittle(u32, bytes[4 * i ..]); | |
| 215 | word.* = mem.readInt(u32, bytes[4 * i ..][0..4], .Little); | |
| 216 | 216 | } |
| 217 | 217 | return words; |
| 218 | 218 | } |
| ... | ... | @@ -252,7 +252,7 @@ const Output = struct { |
| 252 | 252 | var word_counter: usize = 0; |
| 253 | 253 | while (out_word_it.next()) |out_word| { |
| 254 | 254 | 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); | |
| 256 | 256 | @memcpy(out_word, word_bytes[0..out_word.len]); |
| 257 | 257 | word_counter += 1; |
| 258 | 258 | } |
lib/std/crypto/chacha20.zig+73-73| ... | ... | @@ -87,10 +87,10 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type |
| 87 | 87 | switch (degree) { |
| 88 | 88 | 1 => { |
| 89 | 89 | 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), | |
| 94 | 94 | }; |
| 95 | 95 | return BlockVec{ |
| 96 | 96 | constant_le, |
| ... | ... | @@ -101,14 +101,14 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type |
| 101 | 101 | }, |
| 102 | 102 | 2 => { |
| 103 | 103 | 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), | |
| 112 | 112 | }; |
| 113 | 113 | const n1 = @addWithOverflow(d[0], 1); |
| 114 | 114 | return BlockVec{ |
| ... | ... | @@ -123,22 +123,22 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type |
| 123 | 123 | const n2 = @addWithOverflow(d[0], 2); |
| 124 | 124 | const n3 = @addWithOverflow(d[0], 3); |
| 125 | 125 | 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), | |
| 142 | 142 | }; |
| 143 | 143 | return BlockVec{ |
| 144 | 144 | constant_le, |
| ... | ... | @@ -218,10 +218,10 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type |
| 218 | 218 | inline fn hashToBytes(comptime dm: usize, out: *[64 * dm]u8, x: BlockVec) void { |
| 219 | 219 | for (0..dm) |d| { |
| 220 | 220 | 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); | |
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | } |
| ... | ... | @@ -309,20 +309,20 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type |
| 309 | 309 | fn hchacha20(input: [16]u8, key: [32]u8) [32]u8 { |
| 310 | 310 | var c: [4]u32 = undefined; |
| 311 | 311 | 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); | |
| 313 | 313 | } |
| 314 | 314 | const ctx = initContext(keyToWords(key), c); |
| 315 | 315 | var x: BlockVec = undefined; |
| 316 | 316 | chacha20Core(x[0..], ctx); |
| 317 | 317 | 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); | |
| 326 | 326 | return out; |
| 327 | 327 | } |
| 328 | 328 | }; |
| ... | ... | @@ -336,10 +336,10 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type { |
| 336 | 336 | fn initContext(key: [8]u32, d: [4]u32) BlockVec { |
| 337 | 337 | const c = "expand 32-byte k"; |
| 338 | 338 | 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), | |
| 343 | 343 | }; |
| 344 | 344 | return BlockVec{ |
| 345 | 345 | constant_le[0], constant_le[1], constant_le[2], constant_le[3], |
| ... | ... | @@ -396,10 +396,10 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type { |
| 396 | 396 | |
| 397 | 397 | inline fn hashToBytes(out: *[64]u8, x: BlockVec) void { |
| 398 | 398 | 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); | |
| 403 | 403 | } |
| 404 | 404 | } |
| 405 | 405 | |
| ... | ... | @@ -477,20 +477,20 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type { |
| 477 | 477 | fn hchacha20(input: [16]u8, key: [32]u8) [32]u8 { |
| 478 | 478 | var c: [4]u32 = undefined; |
| 479 | 479 | 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); | |
| 481 | 481 | } |
| 482 | 482 | const ctx = initContext(keyToWords(key), c); |
| 483 | 483 | var x: BlockVec = undefined; |
| 484 | 484 | chacha20Core(x[0..], ctx); |
| 485 | 485 | 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); | |
| 494 | 494 | return out; |
| 495 | 495 | } |
| 496 | 496 | }; |
| ... | ... | @@ -519,7 +519,7 @@ fn ChaChaImpl(comptime rounds_nb: usize) type { |
| 519 | 519 | fn keyToWords(key: [32]u8) [8]u32 { |
| 520 | 520 | var k: [8]u32 = undefined; |
| 521 | 521 | 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); | |
| 523 | 523 | } |
| 524 | 524 | return k; |
| 525 | 525 | } |
| ... | ... | @@ -552,9 +552,9 @@ fn ChaChaIETF(comptime rounds_nb: usize) type { |
| 552 | 552 | |
| 553 | 553 | var d: [4]u32 = undefined; |
| 554 | 554 | 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); | |
| 558 | 558 | ChaChaImpl(rounds_nb).chacha20Xor(out, in, keyToWords(key), d, false); |
| 559 | 559 | } |
| 560 | 560 | |
| ... | ... | @@ -564,9 +564,9 @@ fn ChaChaIETF(comptime rounds_nb: usize) type { |
| 564 | 564 | |
| 565 | 565 | var d: [4]u32 = undefined; |
| 566 | 566 | 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); | |
| 570 | 570 | ChaChaImpl(rounds_nb).chacha20Stream(out, keyToWords(key), d, false); |
| 571 | 571 | } |
| 572 | 572 | }; |
| ... | ... | @@ -592,8 +592,8 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type { |
| 592 | 592 | var c: [4]u32 = undefined; |
| 593 | 593 | c[0] = @as(u32, @truncate(counter)); |
| 594 | 594 | 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); | |
| 597 | 597 | ChaChaImpl(rounds_nb).chacha20Xor(out, in, k, c, true); |
| 598 | 598 | } |
| 599 | 599 | |
| ... | ... | @@ -605,8 +605,8 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type { |
| 605 | 605 | var c: [4]u32 = undefined; |
| 606 | 606 | c[0] = @as(u32, @truncate(counter)); |
| 607 | 607 | 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); | |
| 610 | 610 | ChaChaImpl(rounds_nb).chacha20Stream(out, k, c, true); |
| 611 | 611 | } |
| 612 | 612 | }; |
| ... | ... | @@ -672,8 +672,8 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { |
| 672 | 672 | mac.update(zeros[0..padding]); |
| 673 | 673 | } |
| 674 | 674 | 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); | |
| 677 | 677 | mac.update(lens[0..]); |
| 678 | 678 | mac.final(tag); |
| 679 | 679 | } |
| ... | ... | @@ -708,8 +708,8 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { |
| 708 | 708 | mac.update(zeros[0..padding]); |
| 709 | 709 | } |
| 710 | 710 | 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); | |
| 713 | 713 | mac.update(lens[0..]); |
| 714 | 714 | var computed_tag: [16]u8 = undefined; |
| 715 | 715 | mac.final(computed_tag[0..]); |
lib/std/crypto/cmac.zig+2-2| ... | ... | @@ -76,7 +76,7 @@ pub fn Cmac(comptime BlockCipher: type) type { |
| 76 | 76 | |
| 77 | 77 | fn double(l: Block) Block { |
| 78 | 78 | const Int = std.meta.Int(.unsigned, block_length * 8); |
| 79 | const l_ = mem.readIntBig(Int, &l); | |
| 79 | const l_ = mem.readInt(Int, &l, .Big); | |
| 80 | 80 | const l_2 = switch (block_length) { |
| 81 | 81 | 8 => (l_ << 1) ^ (0x1b & -%(l_ >> 63)), // mod x^64 + x^4 + x^3 + x + 1 |
| 82 | 82 | 16 => (l_ << 1) ^ (0x87 & -%(l_ >> 127)), // mod x^128 + x^7 + x^2 + x + 1 |
| ... | ... | @@ -85,7 +85,7 @@ pub fn Cmac(comptime BlockCipher: type) type { |
| 85 | 85 | else => @compileError("unsupported block length"), |
| 86 | 86 | }; |
| 87 | 87 | var l2: Block = undefined; |
| 88 | mem.writeIntBig(Int, &l2, l_2); | |
| 88 | mem.writeInt(Int, &l2, l_2, .Big); | |
| 89 | 89 | return l2; |
| 90 | 90 | } |
| 91 | 91 | }; |
lib/std/crypto/isap.zig+11-11| ... | ... | @@ -55,9 +55,9 @@ pub const IsapA128A = struct { |
| 55 | 55 | fn trickle(k: [16]u8, iv: [8]u8, y: []const u8, comptime out_len: usize) [out_len]u8 { |
| 56 | 56 | var isap = IsapA128A{ |
| 57 | 57 | .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), | |
| 61 | 61 | 0, |
| 62 | 62 | 0, |
| 63 | 63 | }), |
| ... | ... | @@ -85,9 +85,9 @@ pub const IsapA128A = struct { |
| 85 | 85 | fn mac(c: []const u8, ad: []const u8, npub: [16]u8, key: [16]u8) [16]u8 { |
| 86 | 86 | var isap = IsapA128A{ |
| 87 | 87 | .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), | |
| 91 | 91 | 0, |
| 92 | 92 | 0, |
| 93 | 93 | }), |
| ... | ... | @@ -116,11 +116,11 @@ pub const IsapA128A = struct { |
| 116 | 116 | const nb = trickle(key, iv3, npub[0..], 24); |
| 117 | 117 | var isap = IsapA128A{ |
| 118 | 118 | .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), | |
| 124 | 124 | }), |
| 125 | 125 | }; |
| 126 | 126 | isap.st.permuteR(6); |
lib/std/crypto/keccak_p.zig+13-11| ... | ... | @@ -1,7 +1,9 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | |
| 2 | 3 | const assert = std.debug.assert; |
| 3 | 4 | const math = std.math; |
| 4 | 5 | const mem = std.mem; |
| 6 | const native_endian = builtin.cpu.arch.endian(); | |
| 5 | 7 | |
| 6 | 8 | /// The Keccak-f permutation. |
| 7 | 9 | pub fn KeccakF(comptime f: u11) type { |
| ... | ... | @@ -43,7 +45,7 @@ pub fn KeccakF(comptime f: u11) type { |
| 43 | 45 | pub fn init(bytes: [block_bytes]u8) Self { |
| 44 | 46 | var self: Self = undefined; |
| 45 | 47 | 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); | |
| 47 | 49 | } |
| 48 | 50 | return self; |
| 49 | 51 | } |
| ... | ... | @@ -64,12 +66,12 @@ pub fn KeccakF(comptime f: u11) type { |
| 64 | 66 | pub fn setBytes(self: *Self, bytes: []const u8) void { |
| 65 | 67 | var i: usize = 0; |
| 66 | 68 | 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); | |
| 68 | 70 | } |
| 69 | 71 | if (i < bytes.len) { |
| 70 | 72 | var padded = [_]u8{0} ** @sizeOf(T); |
| 71 | 73 | @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); | |
| 73 | 75 | } |
| 74 | 76 | } |
| 75 | 77 | |
| ... | ... | @@ -83,12 +85,12 @@ pub fn KeccakF(comptime f: u11) type { |
| 83 | 85 | pub fn addBytes(self: *Self, bytes: []const u8) void { |
| 84 | 86 | var i: usize = 0; |
| 85 | 87 | 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); | |
| 87 | 89 | } |
| 88 | 90 | if (i < bytes.len) { |
| 89 | 91 | var padded = [_]u8{0} ** @sizeOf(T); |
| 90 | 92 | @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); | |
| 92 | 94 | } |
| 93 | 95 | } |
| 94 | 96 | |
| ... | ... | @@ -96,11 +98,11 @@ pub fn KeccakF(comptime f: u11) type { |
| 96 | 98 | pub fn extractBytes(self: *Self, out: []u8) void { |
| 97 | 99 | var i: usize = 0; |
| 98 | 100 | 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); | |
| 100 | 102 | } |
| 101 | 103 | if (i < out.len) { |
| 102 | 104 | 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); | |
| 104 | 106 | @memcpy(out[i..], padded[0 .. out.len - i]); |
| 105 | 107 | } |
| 106 | 108 | } |
| ... | ... | @@ -111,14 +113,14 @@ pub fn KeccakF(comptime f: u11) type { |
| 111 | 113 | |
| 112 | 114 | var i: usize = 0; |
| 113 | 115 | 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); | |
| 116 | 118 | } |
| 117 | 119 | if (i < in.len) { |
| 118 | 120 | var padded = [_]u8{0} ** @sizeOf(T); |
| 119 | 121 | @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); | |
| 122 | 124 | @memcpy(out[i..], padded[0 .. in.len - i]); |
| 123 | 125 | } |
| 124 | 126 | } |
lib/std/crypto/md5.zig+2-2| ... | ... | @@ -112,7 +112,7 @@ pub const Md5 = struct { |
| 112 | 112 | d.round(d.buf[0..]); |
| 113 | 113 | |
| 114 | 114 | 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); | |
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | |
| ... | ... | @@ -121,7 +121,7 @@ pub const Md5 = struct { |
| 121 | 121 | |
| 122 | 122 | var i: usize = 0; |
| 123 | 123 | 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); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | var v: [4]u32 = [_]u32{ |
lib/std/crypto/pcurves/common.zig+3-3| ... | ... | @@ -54,7 +54,7 @@ pub fn Field(comptime params: FieldParams) type { |
| 54 | 54 | var s = if (endian == .Little) s_ else orderSwap(s_); |
| 55 | 55 | const field_order_s = comptime fos: { |
| 56 | 56 | 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); | |
| 58 | 58 | break :fos fos; |
| 59 | 59 | }; |
| 60 | 60 | if (crypto.utils.timingSafeCompare(u8, &s, &field_order_s, .Little) != .lt) { |
| ... | ... | @@ -95,14 +95,14 @@ pub fn Field(comptime params: FieldParams) type { |
| 95 | 95 | /// Create a field element from an integer. |
| 96 | 96 | pub fn fromInt(comptime x: IntRepr) NonCanonicalError!Fe { |
| 97 | 97 | var s: [encoded_length]u8 = undefined; |
| 98 | mem.writeIntLittle(IntRepr, &s, x); | |
| 98 | mem.writeInt(IntRepr, &s, x, .Little); | |
| 99 | 99 | return fromBytes(s, .Little); |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /// Return the field element as an integer. |
| 103 | 103 | pub fn toInt(fe: Fe) IntRepr { |
| 104 | 104 | const s = fe.toBytes(.Little); |
| 105 | return mem.readIntLittle(IntRepr, &s); | |
| 105 | return mem.readInt(IntRepr, &s, .Little); | |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /// Return true if the field element is zero. |
lib/std/crypto/pcurves/secp256k1.zig+5-5| ... | ... | @@ -41,7 +41,7 @@ pub const Secp256k1 = struct { |
| 41 | 41 | |
| 42 | 42 | const lambda_s = s: { |
| 43 | 43 | var buf: [32]u8 = undefined; |
| 44 | mem.writeIntLittle(u256, &buf, Endormorphism.lambda); | |
| 44 | mem.writeInt(u256, &buf, Endormorphism.lambda, .Little); | |
| 45 | 45 | break :s buf; |
| 46 | 46 | }; |
| 47 | 47 | |
| ... | ... | @@ -54,12 +54,12 @@ pub const Secp256k1 = struct { |
| 54 | 54 | pub fn splitScalar(s: [32]u8, endian: std.builtin.Endian) NonCanonicalError!SplitScalar { |
| 55 | 55 | const b1_neg_s = comptime s: { |
| 56 | 56 | var buf: [32]u8 = undefined; |
| 57 | mem.writeIntLittle(u256, &buf, 303414439467246543595250775667605759171); | |
| 57 | mem.writeInt(u256, &buf, 303414439467246543595250775667605759171, .Little); | |
| 58 | 58 | break :s buf; |
| 59 | 59 | }; |
| 60 | 60 | const b2_neg_s = comptime s: { |
| 61 | 61 | var buf: [32]u8 = undefined; |
| 62 | mem.writeIntLittle(u256, &buf, scalar.field_order - 64502973549206556628585045361533709077); | |
| 62 | mem.writeInt(u256, &buf, scalar.field_order - 64502973549206556628585045361533709077, .Little); | |
| 63 | 63 | break :s buf; |
| 64 | 64 | }; |
| 65 | 65 | const k = mem.readInt(u256, &s, endian); |
| ... | ... | @@ -72,10 +72,10 @@ pub const Secp256k1 = struct { |
| 72 | 72 | |
| 73 | 73 | var buf: [32]u8 = undefined; |
| 74 | 74 | |
| 75 | mem.writeIntLittle(u256, &buf, c1); | |
| 75 | mem.writeInt(u256, &buf, c1, .Little); | |
| 76 | 76 | const c1x = try scalar.mul(buf, b1_neg_s, .Little); |
| 77 | 77 | |
| 78 | mem.writeIntLittle(u256, &buf, c2); | |
| 78 | mem.writeInt(u256, &buf, c2, .Little); | |
| 79 | 79 | const c2x = try scalar.mul(buf, b2_neg_s, .Little); |
| 80 | 80 | |
| 81 | 81 | const r2 = try scalar.add(c1x, c2x, .Little); |
lib/std/crypto/poly1305.zig+8-8| ... | ... | @@ -22,12 +22,12 @@ pub const Poly1305 = struct { |
| 22 | 22 | pub fn init(key: *const [key_length]u8) Poly1305 { |
| 23 | 23 | return Poly1305{ |
| 24 | 24 | .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, | |
| 27 | 27 | }, |
| 28 | 28 | .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), | |
| 31 | 31 | }, |
| 32 | 32 | }; |
| 33 | 33 | } |
| ... | ... | @@ -56,8 +56,8 @@ pub const Poly1305 = struct { |
| 56 | 56 | var i: usize = 0; |
| 57 | 57 | |
| 58 | 58 | 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); | |
| 61 | 61 | |
| 62 | 62 | // Add the input message to H |
| 63 | 63 | var v = @addWithOverflow(h0, in0); |
| ... | ... | @@ -182,8 +182,8 @@ pub const Poly1305 = struct { |
| 182 | 182 | const c = ((h0 & st.pad[0]) | ((h0 | st.pad[0]) & ~st.h[0])) >> 63; |
| 183 | 183 | st.h[1] = h1 +% st.pad[1] +% c; |
| 184 | 184 | |
| 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); | |
| 187 | 187 | |
| 188 | 188 | utils.secureZero(u8, @as([*]u8, @ptrCast(st))[0..@sizeOf(Poly1305)]); |
| 189 | 189 | } |
lib/std/crypto/salsa20.zig+34-34| ... | ... | @@ -29,10 +29,10 @@ fn SalsaVecImpl(comptime rounds: comptime_int) type { |
| 29 | 29 | fn initContext(key: [8]u32, d: [4]u32) BlockVec { |
| 30 | 30 | const c = "expand 32-byte k"; |
| 31 | 31 | 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), | |
| 36 | 36 | }; |
| 37 | 37 | return BlockVec{ |
| 38 | 38 | Lane{ key[0], key[1], key[2], key[3] }, |
| ... | ... | @@ -112,10 +112,10 @@ fn SalsaVecImpl(comptime rounds: comptime_int) type { |
| 112 | 112 | fn hashToBytes(out: *[64]u8, x: BlockVec) void { |
| 113 | 113 | var i: usize = 0; |
| 114 | 114 | 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); | |
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | |
| ... | ... | @@ -158,20 +158,20 @@ fn SalsaVecImpl(comptime rounds: comptime_int) type { |
| 158 | 158 | fn hsalsa(input: [16]u8, key: [32]u8) [32]u8 { |
| 159 | 159 | var c: [4]u32 = undefined; |
| 160 | 160 | 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); | |
| 162 | 162 | } |
| 163 | 163 | const ctx = initContext(keyToWords(key), c); |
| 164 | 164 | var x: BlockVec = undefined; |
| 165 | 165 | salsaCore(x[0..], ctx, false); |
| 166 | 166 | 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); | |
| 175 | 175 | return out; |
| 176 | 176 | } |
| 177 | 177 | }; |
| ... | ... | @@ -184,10 +184,10 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type { |
| 184 | 184 | fn initContext(key: [8]u32, d: [4]u32) BlockVec { |
| 185 | 185 | const c = "expand 32-byte k"; |
| 186 | 186 | 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), | |
| 191 | 191 | }; |
| 192 | 192 | return BlockVec{ |
| 193 | 193 | constant_le[0], key[0], key[1], key[2], |
| ... | ... | @@ -241,7 +241,7 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type { |
| 241 | 241 | |
| 242 | 242 | fn hashToBytes(out: *[64]u8, x: BlockVec) void { |
| 243 | 243 | 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); | |
| 245 | 245 | } |
| 246 | 246 | } |
| 247 | 247 | |
| ... | ... | @@ -283,20 +283,20 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type { |
| 283 | 283 | fn hsalsa(input: [16]u8, key: [32]u8) [32]u8 { |
| 284 | 284 | var c: [4]u32 = undefined; |
| 285 | 285 | 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); | |
| 287 | 287 | } |
| 288 | 288 | const ctx = initContext(keyToWords(key), c); |
| 289 | 289 | var x: BlockVec = undefined; |
| 290 | 290 | salsaCore(x[0..], ctx, false); |
| 291 | 291 | 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); | |
| 300 | 300 | return out; |
| 301 | 301 | } |
| 302 | 302 | }; |
| ... | ... | @@ -308,7 +308,7 @@ fn keyToWords(key: [32]u8) [8]u32 { |
| 308 | 308 | var k: [8]u32 = undefined; |
| 309 | 309 | var i: usize = 0; |
| 310 | 310 | 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); | |
| 312 | 312 | } |
| 313 | 313 | return k; |
| 314 | 314 | } |
| ... | ... | @@ -335,8 +335,8 @@ pub fn Salsa(comptime rounds: comptime_int) type { |
| 335 | 335 | debug.assert(in.len == out.len); |
| 336 | 336 | |
| 337 | 337 | 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); | |
| 340 | 340 | d[2] = @as(u32, @truncate(counter)); |
| 341 | 341 | d[3] = @as(u32, @truncate(counter >> 32)); |
| 342 | 342 | SalsaImpl(rounds).salsaXor(out, in, keyToWords(key), d); |
lib/std/crypto/scrypt.zig+4-4| ... | ... | @@ -91,7 +91,7 @@ fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) |
| 91 | 91 | var y: []align(16) u32 = @alignCast(xy[32 * r ..]); |
| 92 | 92 | |
| 93 | 93 | for (x, 0..) |*v1, j| { |
| 94 | v1.* = mem.readIntSliceLittle(u32, b[4 * j ..]); | |
| 94 | v1.* = mem.readInt(u32, b[4 * j ..][0..4], .Little); | |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | var tmp: [16]u32 align(16) = undefined; |
| ... | ... | @@ -116,7 +116,7 @@ fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | 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); | |
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | 122 | |
| ... | ... | @@ -361,7 +361,7 @@ const crypt_format = struct { |
| 361 | 361 | std.debug.assert(dst.len == decodedLen(src.len)); |
| 362 | 362 | var i: usize = 0; |
| 363 | 363 | 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); | |
| 365 | 365 | } |
| 366 | 366 | const leftover = src[i * 4 ..]; |
| 367 | 367 | var v: u24 = 0; |
| ... | ... | @@ -377,7 +377,7 @@ const crypt_format = struct { |
| 377 | 377 | std.debug.assert(dst.len == encodedLen(src.len)); |
| 378 | 378 | var i: usize = 0; |
| 379 | 379 | 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)); | |
| 381 | 381 | } |
| 382 | 382 | const leftover = src[i * 3 ..]; |
| 383 | 383 | var v: u24 = 0; |
lib/std/crypto/sha1.zig+2-2| ... | ... | @@ -111,7 +111,7 @@ pub const Sha1 = struct { |
| 111 | 111 | d.round(d.buf[0..]); |
| 112 | 112 | |
| 113 | 113 | 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); | |
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | |
| ... | ... | @@ -151,7 +151,7 @@ pub const Sha1 = struct { |
| 151 | 151 | roundParam(0, 1, 2, 3, 4, 15), |
| 152 | 152 | }; |
| 153 | 153 | 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); | |
| 155 | 155 | |
| 156 | 156 | v[r.e] = v[r.e] +% math.rotl(u32, v[r.a], @as(u32, 5)) +% 0x5A827999 +% s[r.i & 0xf] +% ((v[r.b] & v[r.c]) | (~v[r.b] & v[r.d])); |
| 157 | 157 | v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30)); |
lib/std/crypto/sha2.zig+4-4| ... | ... | @@ -171,7 +171,7 @@ fn Sha2x32(comptime params: Sha2Params32) type { |
| 171 | 171 | const rr = d.s[0 .. params.digest_bits / 32]; |
| 172 | 172 | |
| 173 | 173 | 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); | |
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |
| ... | ... | @@ -195,7 +195,7 @@ fn Sha2x32(comptime params: Sha2Params32) type { |
| 195 | 195 | fn round(d: *Self, b: *const [64]u8) void { |
| 196 | 196 | var s: [64]u32 align(16) = undefined; |
| 197 | 197 | 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); | |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | if (!@inComptime()) { |
| ... | ... | @@ -663,7 +663,7 @@ fn Sha2x64(comptime params: Sha2Params64) type { |
| 663 | 663 | const rr = d.s[0 .. params.digest_bits / 64]; |
| 664 | 664 | |
| 665 | 665 | 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); | |
| 667 | 667 | } |
| 668 | 668 | } |
| 669 | 669 | |
| ... | ... | @@ -678,7 +678,7 @@ fn Sha2x64(comptime params: Sha2Params64) type { |
| 678 | 678 | |
| 679 | 679 | var i: usize = 0; |
| 680 | 680 | 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); | |
| 682 | 682 | } |
| 683 | 683 | while (i < 80) : (i += 1) { |
| 684 | 684 | s[i] = s[i - 16] +% s[i - 7] +% |
lib/std/crypto/siphash.zig+4-4| ... | ... | @@ -56,8 +56,8 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round |
| 56 | 56 | msg_len: u8, |
| 57 | 57 | |
| 58 | 58 | 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); | |
| 61 | 61 | |
| 62 | 62 | var d = Self{ |
| 63 | 63 | .v0 = k0 ^ 0x736f6d6570736575, |
| ... | ... | @@ -124,7 +124,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | fn round(self: *Self, b: [8]u8) void { |
| 127 | const m = mem.readIntLittle(u64, &b); | |
| 127 | const m = mem.readInt(u64, &b, .Little); | |
| 128 | 128 | self.v3 ^= m; |
| 129 | 129 | |
| 130 | 130 | comptime var i: usize = 0; |
| ... | ... | @@ -213,7 +213,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize) |
| 213 | 213 | /// Return an authentication tag for the current state |
| 214 | 214 | /// Assumes `out` is less than or equal to `mac_length`. |
| 215 | 215 | 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); | |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | pub fn finalResult(self: *Self) [mac_length]u8 { |
lib/std/crypto/tls.zig+1-1| ... | ... | @@ -370,7 +370,7 @@ pub fn hkdfExpandLabel( |
| 370 | 370 | const max_context_len = 255; |
| 371 | 371 | const tls13 = "tls13 "; |
| 372 | 372 | 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); | |
| 374 | 374 | buf[2] = @as(u8, @intCast(tls13.len + label.len)); |
| 375 | 375 | buf[3..][0..tls13.len].* = tls13.*; |
| 376 | 376 | 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) |
| 1049 | 1049 | } |
| 1050 | 1050 | const ct: tls.ContentType = @enumFromInt(frag[in]); |
| 1051 | 1051 | 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); | |
| 1053 | 1053 | in += 2; |
| 1054 | 1054 | _ = 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); | |
| 1056 | 1056 | if (record_len > max_ciphertext_len) return error.TlsRecordOverflow; |
| 1057 | 1057 | in += 2; |
| 1058 | 1058 | const end = in + record_len; |
| ... | ... | @@ -1136,7 +1136,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec) |
| 1136 | 1136 | while (true) { |
| 1137 | 1137 | const handshake_type: tls.HandshakeType = @enumFromInt(cleartext[ct_i]); |
| 1138 | 1138 | 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); | |
| 1140 | 1140 | ct_i += 3; |
| 1141 | 1141 | const next_handshake_i = ct_i + handshake_len; |
| 1142 | 1142 | if (next_handshake_i > cleartext.len - 1) |
lib/std/debug.zig+5-5| ... | ... | @@ -1135,8 +1135,8 @@ pub fn readElfDebugInfo( |
| 1135 | 1135 | const gnu_debuglink = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size); |
| 1136 | 1136 | const debug_filename = mem.sliceTo(@as([*:0]const u8, @ptrCast(gnu_debuglink.ptr)), 0); |
| 1137 | 1137 | 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); | |
| 1140 | 1140 | separate_debug_filename = debug_filename; |
| 1141 | 1141 | continue; |
| 1142 | 1142 | } |
| ... | ... | @@ -1868,10 +1868,10 @@ pub const DebugInfo = struct { |
| 1868 | 1868 | elf.PT_NOTE => { |
| 1869 | 1869 | // Look for .note.gnu.build-id |
| 1870 | 1870 | 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); | |
| 1872 | 1872 | 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); | |
| 1875 | 1875 | if (note_type != elf.NT_GNU_BUILD_ID) continue; |
| 1876 | 1876 | if (!mem.eql(u8, "GNU\x00", note_bytes[12..16])) continue; |
| 1877 | 1877 | context.build_id = note_bytes[16..][0..desc_size]; |
lib/std/dwarf.zig+4-3| ... | ... | @@ -7,6 +7,7 @@ const mem = std.mem; |
| 7 | 7 | const math = std.math; |
| 8 | 8 | const leb = @import("leb128.zig"); |
| 9 | 9 | const assert = std.debug.assert; |
| 10 | const native_endian = builtin.cpu.arch.endian(); | |
| 10 | 11 | |
| 11 | 12 | pub const TAG = @import("dwarf/TAG.zig"); |
| 12 | 13 | pub const AT = @import("dwarf/AT.zig"); |
| ... | ... | @@ -1741,7 +1742,7 @@ pub const DwarfInfo = struct { |
| 1741 | 1742 | context.cfa = switch (row.cfa.rule) { |
| 1742 | 1743 | .val_offset => |offset| blk: { |
| 1743 | 1744 | 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); | |
| 1745 | 1746 | break :blk try call_frame.applyOffset(value, offset); |
| 1746 | 1747 | }, |
| 1747 | 1748 | .expression => |expression| blk: { |
| ... | ... | @@ -1814,11 +1815,11 @@ pub const DwarfInfo = struct { |
| 1814 | 1815 | } |
| 1815 | 1816 | |
| 1816 | 1817 | 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( | |
| 1818 | 1819 | context.thread_context, |
| 1819 | 1820 | cie.return_address_register, |
| 1820 | 1821 | context.reg_context, |
| 1821 | ))); | |
| 1822 | ))[0..@sizeOf(usize)], native_endian)); | |
| 1822 | 1823 | } else { |
| 1823 | 1824 | context.pc = 0; |
| 1824 | 1825 | } |
lib/std/dwarf/call_frame.zig+5-4| ... | ... | @@ -7,6 +7,7 @@ const dwarf = std.dwarf; |
| 7 | 7 | const abi = dwarf.abi; |
| 8 | 8 | const expressions = dwarf.expressions; |
| 9 | 9 | const assert = std.debug.assert; |
| 10 | const native_endian = builtin.cpu.arch.endian(); | |
| 10 | 11 | |
| 11 | 12 | const Opcode = enum(u8) { |
| 12 | 13 | advance_loc = 0x1 << 6, |
| ... | ... | @@ -386,12 +387,12 @@ pub const VirtualMachine = struct { |
| 386 | 387 | const addr = try applyOffset(cfa, offset); |
| 387 | 388 | if (expression_context.isValidMemory) |isValidMemory| if (!isValidMemory(addr)) return error.InvalidAddress; |
| 388 | 389 | const ptr: *const usize = @ptrFromInt(addr); |
| 389 | mem.writeIntSliceNative(usize, out, ptr.*); | |
| 390 | mem.writeInt(usize, out[0..@sizeOf(usize)], ptr.*, native_endian); | |
| 390 | 391 | } else return error.InvalidCFA; |
| 391 | 392 | }, |
| 392 | 393 | .val_offset => |offset| { |
| 393 | 394 | 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); | |
| 395 | 396 | } else return error.InvalidCFA; |
| 396 | 397 | }, |
| 397 | 398 | .register => |register| { |
| ... | ... | @@ -409,14 +410,14 @@ pub const VirtualMachine = struct { |
| 409 | 410 | |
| 410 | 411 | if (!context.isValidMemory(addr)) return error.InvalidExpressionAddress; |
| 411 | 412 | const ptr: *usize = @ptrFromInt(addr); |
| 412 | mem.writeIntSliceNative(usize, out, ptr.*); | |
| 413 | mem.writeInt(usize, out[0..@sizeOf(usize)], ptr.*, native_endian); | |
| 413 | 414 | }, |
| 414 | 415 | .val_expression => |expression| { |
| 415 | 416 | context.stack_machine.reset(); |
| 416 | 417 | const value = try context.stack_machine.run(expression, context.allocator, expression_context, context.cfa.?); |
| 417 | 418 | if (value) |v| { |
| 418 | 419 | 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); | |
| 420 | 421 | } else return error.NoExpressionValue; |
| 421 | 422 | }, |
| 422 | 423 | .architectural => return error.UnimplementedRegisterRule, |
lib/std/dwarf/expressions.zig+17-16| ... | ... | @@ -6,6 +6,7 @@ const dwarf = std.dwarf; |
| 6 | 6 | const abi = dwarf.abi; |
| 7 | 7 | const mem = std.mem; |
| 8 | 8 | const assert = std.debug.assert; |
| 9 | const native_endian = builtin.cpu.arch.endian(); | |
| 9 | 10 | |
| 10 | 11 | /// Expressions can be evaluated in different contexts, each requiring its own set of inputs. |
| 11 | 12 | /// 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 { |
| 147 | 148 | .regval_type => |regval_type| regval_type.value, |
| 148 | 149 | .const_type => |const_type| { |
| 149 | 150 | 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), | |
| 154 | 155 | else => return error.InvalidIntegralTypeSize, |
| 155 | 156 | }; |
| 156 | 157 | |
| ... | ... | @@ -352,7 +353,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type { |
| 352 | 353 | const debug_addr_index = operand.?.generic; |
| 353 | 354 | const offset = context.compile_unit.?.addr_base + debug_addr_index; |
| 354 | 355 | 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); | |
| 356 | 357 | try self.stack.append(allocator, .{ .generic = value }); |
| 357 | 358 | }, |
| 358 | 359 | |
| ... | ... | @@ -386,21 +387,21 @@ pub fn StackMachine(comptime options: ExpressionOptions) type { |
| 386 | 387 | if (context.thread_context == null) return error.IncompleteExpressionContext; |
| 387 | 388 | |
| 388 | 389 | 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( | |
| 390 | 391 | context.thread_context.?, |
| 391 | 392 | base_register.base_register, |
| 392 | 393 | context.reg_context, |
| 393 | ))); | |
| 394 | ))[0..@sizeOf(usize)], native_endian)); | |
| 394 | 395 | value += base_register.offset; |
| 395 | 396 | try self.stack.append(allocator, .{ .generic = @intCast(value) }); |
| 396 | 397 | }, |
| 397 | 398 | OP.regval_type => { |
| 398 | 399 | const register_type = operand.?.register_type; |
| 399 | const value = mem.readIntSliceNative(usize, try abi.regBytes( | |
| 400 | const value = mem.readInt(usize, (try abi.regBytes( | |
| 400 | 401 | context.thread_context.?, |
| 401 | 402 | register_type.register, |
| 402 | 403 | context.reg_context, |
| 403 | )); | |
| 404 | ))[0..@sizeOf(usize)], native_endian); | |
| 404 | 405 | try self.stack.append(allocator, .{ |
| 405 | 406 | .regval_type = .{ |
| 406 | 407 | .type_offset = register_type.type_offset, |
| ... | ... | @@ -756,7 +757,7 @@ pub fn StackMachine(comptime options: ExpressionOptions) type { |
| 756 | 757 | |
| 757 | 758 | var block_stream = std.io.fixedBufferStream(block); |
| 758 | 759 | 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); | |
| 760 | 761 | try self.stack.append(allocator, .{ .generic = value }); |
| 761 | 762 | } else { |
| 762 | 763 | var stack_machine: Self = .{}; |
| ... | ... | @@ -1121,9 +1122,9 @@ test "DWARF expressions" { |
| 1121 | 1122 | var mock_debug_addr = std.ArrayList(u8).init(allocator); |
| 1122 | 1123 | defer mock_debug_addr.deinit(); |
| 1123 | 1124 | |
| 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); | |
| 1127 | 1128 | |
| 1128 | 1129 | const context = ExpressionContext{ |
| 1129 | 1130 | .compile_unit = &mock_compile_unit, |
| ... | ... | @@ -1185,7 +1186,7 @@ test "DWARF expressions" { |
| 1185 | 1186 | |
| 1186 | 1187 | // TODO: Test fbreg (once implemented): mock a DIE and point compile_unit.frame_base at it |
| 1187 | 1188 | |
| 1188 | mem.writeIntSliceNative(usize, reg_bytes, 0xee); | |
| 1189 | mem.writeInt(usize, reg_bytes[0..@sizeOf(usize)], 0xee, native_endian); | |
| 1189 | 1190 | (try abi.regValueNative(usize, &thread_context, abi.fpRegNum(reg_context), reg_context)).* = 1; |
| 1190 | 1191 | (try abi.regValueNative(usize, &thread_context, abi.spRegNum(reg_context), reg_context)).* = 2; |
| 1191 | 1192 | (try abi.regValueNative(usize, &thread_context, abi.ipRegNum(), reg_context)).* = 3; |
| ... | ... | @@ -1538,7 +1539,7 @@ test "DWARF expressions" { |
| 1538 | 1539 | |
| 1539 | 1540 | const value: usize = @truncate(0xffeeffee_ffeeffee); |
| 1540 | 1541 | var value_bytes: [options.addr_size]u8 = undefined; |
| 1541 | mem.writeIntSliceNative(usize, &value_bytes, value); | |
| 1542 | mem.writeInt(usize, &value_bytes, value, native_endian); | |
| 1542 | 1543 | |
| 1543 | 1544 | // Convert to generic type |
| 1544 | 1545 | stack_machine.reset(); |
| ... | ... | @@ -1613,7 +1614,7 @@ test "DWARF expressions" { |
| 1613 | 1614 | }; |
| 1614 | 1615 | |
| 1615 | 1616 | 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); | |
| 1617 | 1618 | |
| 1618 | 1619 | var sub_program = std.ArrayList(u8).init(allocator); |
| 1619 | 1620 | 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 { |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | pub 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); | |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | pub fn readU64(self: FloatStream) ?u64 { |
lib/std/fmt/parse_float/decimal.zig+1-1| ... | ... | @@ -260,7 +260,7 @@ pub fn Decimal(comptime T: type) type { |
| 260 | 260 | if (!isEightDigits(v)) { |
| 261 | 261 | break; |
| 262 | 262 | } |
| 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); | |
| 264 | 264 | d.num_digits += 8; |
| 265 | 265 | stream.advance(8); |
| 266 | 266 | } |
lib/std/hash/cityhash.zig+2-2| ... | ... | @@ -6,11 +6,11 @@ inline fn offsetPtr(ptr: [*]const u8, offset: usize) [*]const u8 { |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | fn 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); | |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | fn 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); | |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | pub const CityHash32 = struct { |
lib/std/hash/crc.zig+1-1| ... | ... | @@ -163,7 +163,7 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type { |
| 163 | 163 | const p = input[i..][0..8]; |
| 164 | 164 | |
| 165 | 165 | // 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); | |
| 167 | 167 | |
| 168 | 168 | self.crc = |
| 169 | 169 | lookup_tables[0][p[7]] ^ |
lib/std/hash/verify.zig+1-1| ... | ... | @@ -37,7 +37,7 @@ pub fn smhasher(comptime hash_fn: anytype) u32 { |
| 37 | 37 | for (0..256) |i| { |
| 38 | 38 | buf[i] = @intCast(i); |
| 39 | 39 | 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); | |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | return @truncate(hashMaybeSeed(hash_fn, 0, buf_all[0..])); |
lib/std/hash/wyhash.zig+1-1| ... | ... | @@ -131,7 +131,7 @@ pub const Wyhash = struct { |
| 131 | 131 | inline fn read(comptime bytes: usize, data: []const u8) u64 { |
| 132 | 132 | std.debug.assert(bytes <= 8); |
| 133 | 133 | 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)); | |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | inline fn mum(a: *u64, b: *u64) void { |
lib/std/hash/xxhash.zig+11-11| ... | ... | @@ -53,10 +53,10 @@ pub const XxHash64 = struct { |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | 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)); | |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | fn merge(self: Accumulator) u64 { |
| ... | ... | @@ -139,7 +139,7 @@ pub const XxHash64 = struct { |
| 139 | 139 | |
| 140 | 140 | fn finalize8(v: u64, bytes: *const [8]u8) u64 { |
| 141 | 141 | var acc = v; |
| 142 | const lane = mem.readIntLittle(u64, bytes); | |
| 142 | const lane = mem.readInt(u64, bytes, .Little); | |
| 143 | 143 | acc ^= round(0, lane); |
| 144 | 144 | acc = rotl(u64, acc, 27) *% prime_1; |
| 145 | 145 | acc +%= prime_4; |
| ... | ... | @@ -148,7 +148,7 @@ pub const XxHash64 = struct { |
| 148 | 148 | |
| 149 | 149 | fn finalize4(v: u64, bytes: *const [4]u8) u64 { |
| 150 | 150 | var acc = v; |
| 151 | const lane = @as(u64, mem.readIntLittle(u32, bytes)); | |
| 151 | const lane = @as(u64, mem.readInt(u32, bytes, .Little)); | |
| 152 | 152 | acc ^= lane *% prime_1; |
| 153 | 153 | acc = rotl(u64, acc, 23) *% prime_2; |
| 154 | 154 | acc +%= prime_3; |
| ... | ... | @@ -291,10 +291,10 @@ pub const XxHash32 = struct { |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | 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)); | |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | fn merge(self: Accumulator) u32 { |
| ... | ... | @@ -390,7 +390,7 @@ pub const XxHash32 = struct { |
| 390 | 390 | |
| 391 | 391 | fn finalize4(v: u32, bytes: *const [4]u8) u32 { |
| 392 | 392 | var acc = v; |
| 393 | const lane = mem.readIntLittle(u32, bytes); | |
| 393 | const lane = mem.readInt(u32, bytes, .Little); | |
| 394 | 394 | acc +%= lane *% prime_3; |
| 395 | 395 | acc = rotl(u32, acc, 17) *% prime_4; |
| 396 | 396 | return acc; |
lib/std/io.zig-16| ... | ... | @@ -269,22 +269,6 @@ pub fn GenericReader( |
| 269 | 269 | return @errorCast(self.any().readBoundedBytes(num_bytes)); |
| 270 | 270 | } |
| 271 | 271 | |
| 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 | ||
| 288 | 272 | pub inline fn readInt(self: Self, comptime T: type, endian: std.builtin.Endian) NoEofError!T { |
| 289 | 273 | return @errorCast(self.any().readInt(T, endian)); |
| 290 | 274 | } |
lib/std/io/Reader.zig+2-24| ... | ... | @@ -276,30 +276,8 @@ pub fn readBoundedBytes(self: Self, comptime num_bytes: usize) anyerror!std.Boun |
| 276 | 276 | return result; |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | /// Reads a native-endian integer | |
| 280 | pub 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 | |
| 286 | pub 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 | ||
| 291 | pub 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 | ||
| 296 | pub 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 | ||
| 301 | pub 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))); | |
| 279 | pub 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)); | |
| 303 | 281 | return mem.readInt(T, &bytes, endian); |
| 304 | 282 | } |
| 305 | 283 |
lib/std/io/writer.zig+2-28| ... | ... | @@ -45,34 +45,8 @@ pub fn Writer( |
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | |
| 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; | |
| 76 | 50 | mem.writeInt(std.math.ByteAlignedInt(@TypeOf(value)), &bytes, value, endian); |
| 77 | 51 | return self.writeAll(&bytes); |
| 78 | 52 | } |
lib/std/mem.zig+233-392| ... | ... | @@ -1587,68 +1587,40 @@ pub fn readVarPackedInt( |
| 1587 | 1587 | /// Reads an integer from memory with bit count specified by T. |
| 1588 | 1588 | /// The bit count of T must be evenly divisible by 8. |
| 1589 | 1589 | /// 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. | |
| 1592 | pub fn readIntNative(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8) T { | |
| 1593 | return @as(*align(1) const T, @ptrCast(bytes)).*; | |
| 1590 | pub 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); | |
| 1594 | 1593 | } |
| 1595 | 1594 | |
| 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. | |
| 1600 | pub fn readIntForeign(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8) T { | |
| 1601 | return @byteSwap(readIntNative(T, bytes)); | |
| 1602 | } | |
| 1603 | ||
| 1604 | pub const readIntLittle = switch (native_endian) { | |
| 1605 | .Little => readIntNative, | |
| 1606 | .Big => readIntForeign, | |
| 1607 | }; | |
| 1595 | test readInt { | |
| 1596 | try testing.expect(readInt(u0, &[_]u8{}, .Big) == 0x0); | |
| 1597 | try testing.expect(readInt(u0, &[_]u8{}, .Little) == 0x0); | |
| 1608 | 1598 | |
| 1609 | pub 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); | |
| 1613 | 1601 | |
| 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. | |
| 1619 | pub 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); | |
| 1624 | 1604 | |
| 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. | |
| 1629 | pub 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); | |
| 1632 | 1607 | |
| 1633 | pub 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); | |
| 1637 | 1610 | |
| 1638 | pub 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 | } | |
| 1642 | 1614 | |
| 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. | |
| 1644 | 1617 | /// The bit count of T must be evenly divisible by 8. |
| 1645 | /// This function cannot fail and cannot cause undefined behavior. | |
| 1646 | pub 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 | } | |
| 1618 | pub 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 | }; | |
| 1652 | 1624 | } |
| 1653 | 1625 | |
| 1654 | 1626 | fn 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 |
| 1668 | 1640 | // Read by loading a LoadInt, and then follow it up with a 1-byte read |
| 1669 | 1641 | // of the tail if bit_offset pushed us over a byte boundary. |
| 1670 | 1642 | 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)); | |
| 1672 | 1644 | if (bit_shift > load_tail_bits) { |
| 1673 | 1645 | const tail_bits = @as(Log2N, @intCast(bit_shift - load_tail_bits)); |
| 1674 | 1646 | const tail_byte = read_bytes[load_size]; |
| ... | ... | @@ -1696,7 +1668,7 @@ fn readPackedIntBig(comptime T: type, bytes: []const u8, bit_offset: usize) T { |
| 1696 | 1668 | // of the tail if bit_offset pushed us over a byte boundary. |
| 1697 | 1669 | const end = bytes.len - (bit_offset / 8); |
| 1698 | 1670 | 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)); | |
| 1700 | 1672 | if (bit_shift > load_tail_bits) { |
| 1701 | 1673 | const tail_bits = @as(Log2N, @intCast(bit_shift - load_tail_bits)); |
| 1702 | 1674 | 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 |
| 1729 | 1701 | } |
| 1730 | 1702 | } |
| 1731 | 1703 | |
| 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. | |
| 1735 | pub 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 | ||
| 1741 | 1704 | test "comptime read/write int" { |
| 1742 | 1705 | comptime { |
| 1743 | 1706 | 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); | |
| 1746 | 1709 | try testing.expect(result == 0x3412); |
| 1747 | 1710 | } |
| 1748 | 1711 | comptime { |
| 1749 | 1712 | 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); | |
| 1752 | 1715 | try testing.expect(result == 0x3412); |
| 1753 | 1716 | } |
| 1754 | 1717 | } |
| 1755 | 1718 | |
| 1756 | test "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. | |
| 1722 | pub 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 | } | |
| 1759 | 1725 | |
| 1760 | try testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0); | |
| 1761 | try testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0); | |
| 1726 | test 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; | |
| 1762 | 1731 | |
| 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{})); | |
| 1765 | 1736 | |
| 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})); | |
| 1768 | 1741 | |
| 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 })); | |
| 1771 | 1746 | |
| 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})); | |
| 1774 | 1756 | |
| 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 })); | |
| 1777 | 1761 | } |
| 1778 | 1762 | |
| 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. | |
| 1784 | pub 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. | |
| 1769 | pub 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 | } | |
| 1786 | 1781 | } |
| 1787 | 1782 | |
| 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. | |
| 1792 | pub fn writeIntForeign(comptime T: type, buf: *[@divExact(@typeInfo(T).Int.bits, 8)]u8, value: T) void { | |
| 1793 | writeIntNative(T, buf, @byteSwap(value)); | |
| 1783 | test writeIntSlice { | |
| 1784 | try testWriteIntImpl(); | |
| 1785 | try comptime testWriteIntImpl(); | |
| 1794 | 1786 | } |
| 1787 | fn testWriteIntImpl() !void { | |
| 1788 | var bytes: [8]u8 = undefined; | |
| 1795 | 1789 | |
| 1796 | pub 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 | })); | |
| 1800 | 1795 | |
| 1801 | pub 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 | })); | |
| 1805 | 1801 | |
| 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. | |
| 1809 | pub 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 | })); | |
| 1815 | 1921 | } |
| 1816 | 1922 | |
| 1817 | 1923 | fn 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: |
| 1844 | 1950 | write_value |= @as(StoreInt, tail) << (8 * (store_size - 1)); |
| 1845 | 1951 | } |
| 1846 | 1952 | |
| 1847 | writeIntLittle(StoreInt, write_bytes[0..store_size], write_value); | |
| 1953 | writeInt(StoreInt, write_bytes[0..store_size], write_value, .Little); | |
| 1848 | 1954 | } |
| 1849 | 1955 | |
| 1850 | 1956 | fn 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) |
| 1879 | 1985 | write_value |= @as(StoreInt, tail) << (8 * (store_size - 1)); |
| 1880 | 1986 | } |
| 1881 | 1987 | |
| 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); | |
| 1883 | 1989 | } |
| 1884 | 1990 | |
| 1885 | 1991 | pub const writePackedIntNative = switch (native_endian) { |
| ... | ... | @@ -1908,91 +2014,6 @@ pub fn writePackedInt(comptime T: type, bytes: []u8, bit_offset: usize, value: T |
| 1908 | 2014 | } |
| 1909 | 2015 | } |
| 1910 | 2016 | |
| 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. | |
| 1917 | fn 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 | ||
| 1933 | fn writeIntSliceLittleForeign(comptime T: type, buffer: []u8, value: T) void { | |
| 1934 | return writeIntSliceLittleNative(T, buffer, @byteSwap(value)); | |
| 1935 | } | |
| 1936 | ||
| 1937 | pub 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. | |
| 1947 | fn 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 | ||
| 1963 | fn writeIntSliceBigForeign(comptime T: type, buffer: []u8, value: T) void { | |
| 1964 | return writeIntSliceBigNative(T, buffer, @byteSwap(value)); | |
| 1965 | } | |
| 1966 | ||
| 1967 | pub const writeIntSliceBig = switch (native_endian) { | |
| 1968 | .Little => writeIntSliceBigForeign, | |
| 1969 | .Big => writeIntSliceBigNative, | |
| 1970 | }; | |
| 1971 | ||
| 1972 | pub const writeIntSliceNative = switch (native_endian) { | |
| 1973 | .Little => writeIntSliceLittleNative, | |
| 1974 | .Big => writeIntSliceBigNative, | |
| 1975 | }; | |
| 1976 | ||
| 1977 | pub 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. | |
| 1988 | pub 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 | ||
| 1996 | 2017 | /// Stores an integer to packed memory with provided bit_count, bit_offset, and signedness. |
| 1997 | 2018 | /// If negative, the written value is sign-extended. |
| 1998 | 2019 | /// |
| ... | ... | @@ -2055,45 +2076,6 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value |
| 2055 | 2076 | write_bytes[@as(usize, @intCast(i))] |= @as(u8, @intCast(@as(uN, @bitCast(remaining)) & tail_mask)); |
| 2056 | 2077 | } |
| 2057 | 2078 | |
| 2058 | test "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 | ||
| 2097 | 2079 | /// Swap the byte order of all the members of the fields of a struct |
| 2098 | 2080 | /// (Changing their endianness) |
| 2099 | 2081 | pub fn byteSwapAllFields(comptime S: type, ptr: *S) void { |
| ... | ... | @@ -3311,12 +3293,12 @@ fn testReadIntImpl() !void { |
| 3311 | 3293 | 0x56, |
| 3312 | 3294 | 0x78, |
| 3313 | 3295 | }; |
| 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); | |
| 3320 | 3302 | } |
| 3321 | 3303 | { |
| 3322 | 3304 | const buf = [_]u8{ |
| ... | ... | @@ -3325,7 +3307,7 @@ fn testReadIntImpl() !void { |
| 3325 | 3307 | 0x12, |
| 3326 | 3308 | 0x34, |
| 3327 | 3309 | }; |
| 3328 | const answer = readInt(u32, &buf, Endian.Big); | |
| 3310 | const answer = readInt(u32, &buf, .Big); | |
| 3329 | 3311 | try testing.expect(answer == 0x00001234); |
| 3330 | 3312 | } |
| 3331 | 3313 | { |
| ... | ... | @@ -3335,7 +3317,7 @@ fn testReadIntImpl() !void { |
| 3335 | 3317 | 0x00, |
| 3336 | 3318 | 0x00, |
| 3337 | 3319 | }; |
| 3338 | const answer = readInt(u32, &buf, Endian.Little); | |
| 3320 | const answer = readInt(u32, &buf, .Little); | |
| 3339 | 3321 | try testing.expect(answer == 0x00003412); |
| 3340 | 3322 | } |
| 3341 | 3323 | { |
| ... | ... | @@ -3343,153 +3325,13 @@ fn testReadIntImpl() !void { |
| 3343 | 3325 | 0xff, |
| 3344 | 3326 | 0xfe, |
| 3345 | 3327 | }; |
| 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); | |
| 3350 | 3332 | } |
| 3351 | 3333 | } |
| 3352 | 3334 | |
| 3353 | test writeIntSlice { | |
| 3354 | try testWriteIntImpl(); | |
| 3355 | try comptime testWriteIntImpl(); | |
| 3356 | } | |
| 3357 | fn 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 | ||
| 3493 | 3335 | /// Returns the smallest number in a slice. O(n). |
| 3494 | 3336 | /// `slice` must not be empty. |
| 3495 | 3337 | pub fn min(comptime T: type, slice: []const T) T { |
| ... | ... | @@ -4671,7 +4513,6 @@ pub fn alignInSlice(slice: anytype, comptime new_alignment: usize) ?AlignedSlice |
| 4671 | 4513 | } |
| 4672 | 4514 | |
| 4673 | 4515 | test "read/write(Var)PackedInt" { |
| 4674 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | |
| 4675 | 4516 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 4676 | 4517 | |
| 4677 | 4518 | switch (builtin.cpu.arch) { |
lib/std/net.zig+3-3| ... | ... | @@ -1052,7 +1052,7 @@ fn linuxLookupName( |
| 1052 | 1052 | } else { |
| 1053 | 1053 | sa6.addr[0..12].* = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff".*; |
| 1054 | 1054 | 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); | |
| 1056 | 1056 | da4.addr = addr.addr.in.sa.addr; |
| 1057 | 1057 | da = @ptrCast(&da4); |
| 1058 | 1058 | dalen = @sizeOf(os.sockaddr.in); |
| ... | ... | @@ -1073,7 +1073,7 @@ fn linuxLookupName( |
| 1073 | 1073 | os.getsockname(fd, sa, &salen) catch break :syscalls; |
| 1074 | 1074 | if (addr.addr.any.family == os.AF.INET) { |
| 1075 | 1075 | // 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); | |
| 1077 | 1077 | } |
| 1078 | 1078 | if (dscope == @as(i32, scopeOf(sa6.addr))) key |= DAS_MATCHINGSCOPE; |
| 1079 | 1079 | if (dlabel == labelOf(sa6.addr)) key |= DAS_MATCHINGLABEL; |
| ... | ... | @@ -1569,7 +1569,7 @@ fn resMSendRc( |
| 1569 | 1569 | ); |
| 1570 | 1570 | for (0..ns.len) |i| { |
| 1571 | 1571 | 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); | |
| 1573 | 1573 | ns[i].in6.sa.addr[0..12].* = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff".*; |
| 1574 | 1574 | ns[i].any.family = os.AF.INET6; |
| 1575 | 1575 | ns[i].in6.sa.flowinfo = 0; |
lib/std/os/test.zig+3-3| ... | ... | @@ -609,7 +609,7 @@ test "mmap" { |
| 609 | 609 | |
| 610 | 610 | var i: u32 = 0; |
| 611 | 611 | while (i < alloc_size / @sizeOf(u32)) : (i += 1) { |
| 612 | try stream.writeIntNative(u32, i); | |
| 612 | try stream.writeInt(u32, i, .Little); | |
| 613 | 613 | } |
| 614 | 614 | } |
| 615 | 615 | |
| ... | ... | @@ -633,7 +633,7 @@ test "mmap" { |
| 633 | 633 | |
| 634 | 634 | var i: u32 = 0; |
| 635 | 635 | 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)); | |
| 637 | 637 | } |
| 638 | 638 | } |
| 639 | 639 | |
| ... | ... | @@ -657,7 +657,7 @@ test "mmap" { |
| 657 | 657 | |
| 658 | 658 | var i: u32 = alloc_size / 2 / @sizeOf(u32); |
| 659 | 659 | 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)); | |
| 661 | 661 | } |
| 662 | 662 | } |
| 663 | 663 |
lib/std/pdb.zig+13-13| ... | ... | @@ -464,12 +464,12 @@ pub const PDBStringTableHeader = extern struct { |
| 464 | 464 | }; |
| 465 | 465 | |
| 466 | 466 | fn readSparseBitVector(stream: anytype, allocator: mem.Allocator) ![]u32 { |
| 467 | const num_words = try stream.readIntLittle(u32); | |
| 467 | const num_words = try stream.readInt(u32, .Little); | |
| 468 | 468 | var list = ArrayList(u32).init(allocator); |
| 469 | 469 | errdefer list.deinit(); |
| 470 | 470 | var word_i: u32 = 0; |
| 471 | 471 | while (word_i != num_words) : (word_i += 1) { |
| 472 | const word = try stream.readIntLittle(u32); | |
| 472 | const word = try stream.readInt(u32, .Little); | |
| 473 | 473 | var bit_i: u5 = 0; |
| 474 | 474 | while (true) : (bit_i += 1) { |
| 475 | 475 | if (word & (@as(u32, 1) << bit_i) != 0) { |
| ... | ... | @@ -625,10 +625,10 @@ pub const Pdb = struct { |
| 625 | 625 | const reader = stream.reader(); |
| 626 | 626 | |
| 627 | 627 | // 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); | |
| 630 | 630 | _ = signature; |
| 631 | const age = try reader.readIntLittle(u32); | |
| 631 | const age = try reader.readInt(u32, .Little); | |
| 632 | 632 | const guid = try reader.readBytesNoEof(16); |
| 633 | 633 | |
| 634 | 634 | if (version != 20000404) // VC70, only value observed by LLVM team |
| ... | ... | @@ -639,7 +639,7 @@ pub const Pdb = struct { |
| 639 | 639 | |
| 640 | 640 | // Find the string table. |
| 641 | 641 | 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); | |
| 643 | 643 | const name_bytes = try self.allocator.alloc(u8, name_bytes_len); |
| 644 | 644 | defer self.allocator.free(name_bytes); |
| 645 | 645 | try reader.readNoEof(name_bytes); |
| ... | ... | @@ -667,8 +667,8 @@ pub const Pdb = struct { |
| 667 | 667 | defer self.allocator.free(deleted); |
| 668 | 668 | |
| 669 | 669 | 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); | |
| 672 | 672 | if (name_offset > name_bytes.len) |
| 673 | 673 | return error.InvalidDebugInfo; |
| 674 | 674 | const name = mem.sliceTo(name_bytes[name_offset..], 0); |
| ... | ... | @@ -821,7 +821,7 @@ pub const Pdb = struct { |
| 821 | 821 | return error.MissingDebugInfo; |
| 822 | 822 | const reader = stream.reader(); |
| 823 | 823 | |
| 824 | const signature = try reader.readIntLittle(u32); | |
| 824 | const signature = try reader.readInt(u32, .Little); | |
| 825 | 825 | if (signature != 4) |
| 826 | 826 | return error.InvalidDebugInfo; |
| 827 | 827 | |
| ... | ... | @@ -899,7 +899,7 @@ const Msf = struct { |
| 899 | 899 | try file.seekTo(superblock.BlockSize * superblock.BlockMapAddr); |
| 900 | 900 | var dir_blocks = try allocator.alloc(u32, dir_block_count); |
| 901 | 901 | for (dir_blocks) |*b| { |
| 902 | b.* = try in.readIntLittle(u32); | |
| 902 | b.* = try in.readInt(u32, .Little); | |
| 903 | 903 | } |
| 904 | 904 | var directory = MsfStream.init( |
| 905 | 905 | superblock.BlockSize, |
| ... | ... | @@ -908,7 +908,7 @@ const Msf = struct { |
| 908 | 908 | ); |
| 909 | 909 | |
| 910 | 910 | const begin = directory.pos; |
| 911 | const stream_count = try directory.reader().readIntLittle(u32); | |
| 911 | const stream_count = try directory.reader().readInt(u32, .Little); | |
| 912 | 912 | const stream_sizes = try allocator.alloc(u32, stream_count); |
| 913 | 913 | defer allocator.free(stream_sizes); |
| 914 | 914 | |
| ... | ... | @@ -917,7 +917,7 @@ const Msf = struct { |
| 917 | 917 | // and must be taken into account when resolving stream indices. |
| 918 | 918 | const Nil = 0xFFFFFFFF; |
| 919 | 919 | for (stream_sizes) |*s| { |
| 920 | const size = try directory.reader().readIntLittle(u32); | |
| 920 | const size = try directory.reader().readInt(u32, .Little); | |
| 921 | 921 | s.* = if (size == Nil) 0 else blockCountFromSize(size, superblock.BlockSize); |
| 922 | 922 | } |
| 923 | 923 | |
| ... | ... | @@ -932,7 +932,7 @@ const Msf = struct { |
| 932 | 932 | var blocks = try allocator.alloc(u32, size); |
| 933 | 933 | var j: u32 = 0; |
| 934 | 934 | while (j < size) : (j += 1) { |
| 935 | const block_id = try directory.reader().readIntLittle(u32); | |
| 935 | const block_id = try directory.reader().readInt(u32, .Little); | |
| 936 | 936 | const n = (block_id % superblock.BlockSize); |
| 937 | 937 | // 0 is for SuperBlock, 1 and 2 for FPMs. |
| 938 | 938 | 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 { |
| 104 | 104 | pub fn int(r: Random, comptime T: type) T { |
| 105 | 105 | const bits = @typeInfo(T).Int.bits; |
| 106 | 106 | 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); | |
| 108 | 109 | |
| 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); | |
| 111 | 112 | |
| 112 | 113 | // use LE instead of native endian for better portability maybe? |
| 113 | 114 | // TODO: endian portability is pointless if the underlying prng isn't endian portable. |
| 114 | 115 | // 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); | |
| 116 | 117 | const unsigned_result: UnsignedT = @truncate(byte_aligned_result); |
| 117 | 118 | return @bitCast(unsigned_result); |
| 118 | 119 | } |
lib/std/rand/Isaac64.zig+1-1| ... | ... | @@ -228,7 +228,7 @@ test "isaac64 fill" { |
| 228 | 228 | for (seq) |s| { |
| 229 | 229 | var buf0: [8]u8 = undefined; |
| 230 | 230 | var buf1: [7]u8 = undefined; |
| 231 | std.mem.writeIntLittle(u64, &buf0, s); | |
| 231 | std.mem.writeInt(u64, &buf0, s, .Little); | |
| 232 | 232 | r.fill(&buf1); |
| 233 | 233 | try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); |
| 234 | 234 | } |
lib/std/rand/Pcg.zig+2-2| ... | ... | @@ -111,8 +111,8 @@ test "pcg fill" { |
| 111 | 111 | var i: u32 = 0; |
| 112 | 112 | while (i < seq.len) : (i += 2) { |
| 113 | 113 | 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); | |
| 116 | 116 | |
| 117 | 117 | var buf1: [7]u8 = undefined; |
| 118 | 118 | r.fill(&buf1); |
lib/std/rand/RomuTrio.zig+1-1| ... | ... | @@ -115,7 +115,7 @@ test "RomuTrio fill" { |
| 115 | 115 | for (seq) |s| { |
| 116 | 116 | var buf0: [8]u8 = undefined; |
| 117 | 117 | var buf1: [7]u8 = undefined; |
| 118 | std.mem.writeIntLittle(u64, &buf0, s); | |
| 118 | std.mem.writeInt(u64, &buf0, s, .Little); | |
| 119 | 119 | r.fill(&buf1); |
| 120 | 120 | try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); |
| 121 | 121 | } |
lib/std/rand/Sfc64.zig+1-1| ... | ... | @@ -125,7 +125,7 @@ test "Sfc64 fill" { |
| 125 | 125 | for (seq) |s| { |
| 126 | 126 | var buf0: [8]u8 = undefined; |
| 127 | 127 | var buf1: [7]u8 = undefined; |
| 128 | std.mem.writeIntLittle(u64, &buf0, s); | |
| 128 | std.mem.writeInt(u64, &buf0, s, .Little); | |
| 129 | 129 | r.fill(&buf1); |
| 130 | 130 | try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); |
| 131 | 131 | } |
lib/std/rand/Xoroshiro128.zig+1-1| ... | ... | @@ -140,7 +140,7 @@ test "xoroshiro fill" { |
| 140 | 140 | for (seq) |s| { |
| 141 | 141 | var buf0: [8]u8 = undefined; |
| 142 | 142 | var buf1: [7]u8 = undefined; |
| 143 | std.mem.writeIntLittle(u64, &buf0, s); | |
| 143 | std.mem.writeInt(u64, &buf0, s, .Little); | |
| 144 | 144 | r.fill(&buf1); |
| 145 | 145 | try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); |
| 146 | 146 | } |
lib/std/rand/Xoshiro256.zig+1-1| ... | ... | @@ -139,7 +139,7 @@ test "xoroshiro fill" { |
| 139 | 139 | for (seq) |s| { |
| 140 | 140 | var buf0: [8]u8 = undefined; |
| 141 | 141 | var buf1: [7]u8 = undefined; |
| 142 | std.mem.writeIntLittle(u64, &buf0, s); | |
| 142 | std.mem.writeInt(u64, &buf0, s, .Little); | |
| 143 | 143 | r.fill(&buf1); |
| 144 | 144 | try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); |
| 145 | 145 | } |
lib/std/rand/test.zig+1-1| ... | ... | @@ -71,7 +71,7 @@ const Dilbert = struct { |
| 71 | 71 | for (seq) |s| { |
| 72 | 72 | var buf0: [8]u8 = undefined; |
| 73 | 73 | var buf1: [8]u8 = undefined; |
| 74 | std.mem.writeIntBig(u64, &buf0, s); | |
| 74 | std.mem.writeInt(u64, &buf0, s, .Big); | |
| 75 | 75 | r.fill(&buf1); |
| 76 | 76 | try std.testing.expect(std.mem.eql(u8, buf0[0..], buf1[0..])); |
| 77 | 77 | } |
lib/std/tz.zig+4-4| ... | ... | @@ -98,7 +98,7 @@ pub const Tz = struct { |
| 98 | 98 | // Parse transition types |
| 99 | 99 | var i: usize = 0; |
| 100 | 100 | 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); | |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | i = 0; |
| ... | ... | @@ -111,7 +111,7 @@ pub const Tz = struct { |
| 111 | 111 | // Parse time types |
| 112 | 112 | i = 0; |
| 113 | 113 | while (i < header.counts.typecnt) : (i += 1) { |
| 114 | const offset = try reader.readIntBig(i32); | |
| 114 | const offset = try reader.readInt(i32, .Big); | |
| 115 | 115 | if (offset < -2147483648) return error.Malformed; // rfc8536: utoff [...] MUST NOT be -2**31 |
| 116 | 116 | const dst = try reader.readByte(); |
| 117 | 117 | if (dst != 0 and dst != 1) return error.Malformed; // rfc8536: (is)dst [...] The value MUST be 0 or 1. |
| ... | ... | @@ -144,12 +144,12 @@ pub const Tz = struct { |
| 144 | 144 | // Parse leap seconds |
| 145 | 145 | i = 0; |
| 146 | 146 | 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); | |
| 148 | 148 | if (occur < 0) return error.Malformed; // rfc8536: occur [...] MUST be nonnegative |
| 149 | 149 | if (i > 0 and leapseconds[i - 1].occurrence + 2419199 > occur) return error.Malformed; // rfc8536: occur [...] each later value MUST be at least 2419199 greater than the previous value |
| 150 | 150 | if (occur > std.math.maxInt(i48)) return error.Malformed; // Unreasonably far into the future |
| 151 | 151 | |
| 152 | const corr = try reader.readIntBig(i32); | |
| 152 | const corr = try reader.readInt(i32, .Big); | |
| 153 | 153 | if (i == 0 and corr != -1 and corr != 1) return error.Malformed; // rfc8536: The correction value in the first leap-second record, if present, MUST be either one (1) or minus one (-1) |
| 154 | 154 | if (i > 0 and leapseconds[i - 1].correction != corr + 1 and leapseconds[i - 1].correction != corr - 1) return error.Malformed; // rfc8536: The correction values in adjacent leap-second records MUST differ by exactly one (1) |
| 155 | 155 | if (corr > std.math.maxInt(i16)) return error.Malformed; // Unreasonably large correction |
lib/std/unicode.zig+25-24| ... | ... | @@ -1,8 +1,9 @@ |
| 1 | 1 | const std = @import("./std.zig"); |
| 2 | const builtin = @import("builtin"); | |
| 2 | 3 | const assert = std.debug.assert; |
| 3 | 4 | const testing = std.testing; |
| 4 | 5 | const mem = std.mem; |
| 5 | const builtin = @import("builtin"); | |
| 6 | const native_endian = builtin.cpu.arch.endian(); | |
| 6 | 7 | |
| 7 | 8 | /// Use this to replace an unknown, unrecognized, or unrepresentable character. |
| 8 | 9 | /// |
| ... | ... | @@ -175,7 +176,7 @@ pub fn utf8CountCodepoints(s: []const u8) !usize { |
| 175 | 176 | while (i < s.len) { |
| 176 | 177 | // Fast path for ASCII sequences |
| 177 | 178 | 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); | |
| 179 | 180 | if (v & MASK != 0) break; |
| 180 | 181 | len += N; |
| 181 | 182 | } |
| ... | ... | @@ -451,12 +452,12 @@ pub const Utf16LeIterator = struct { |
| 451 | 452 | assert(it.i <= it.bytes.len); |
| 452 | 453 | if (it.i == it.bytes.len) return null; |
| 453 | 454 | 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); | |
| 455 | 456 | it.i += 2; |
| 456 | 457 | if (utf16IsHighSurrogate(code_units[0])) { |
| 457 | 458 | // surrogate pair |
| 458 | 459 | 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); | |
| 460 | 461 | const codepoint = try utf16DecodeSurrogatePair(&code_units); |
| 461 | 462 | it.i += 2; |
| 462 | 463 | return codepoint; |
| ... | ... | @@ -877,16 +878,16 @@ test "utf16leToUtf8" { |
| 877 | 878 | const utf16le_as_bytes = mem.sliceAsBytes(utf16le[0..]); |
| 878 | 879 | |
| 879 | 880 | { |
| 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); | |
| 882 | 883 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); |
| 883 | 884 | defer std.testing.allocator.free(utf8); |
| 884 | 885 | try testing.expect(mem.eql(u8, utf8, "Aa")); |
| 885 | 886 | } |
| 886 | 887 | |
| 887 | 888 | { |
| 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); | |
| 890 | 891 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); |
| 891 | 892 | defer std.testing.allocator.free(utf8); |
| 892 | 893 | try testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf")); |
| ... | ... | @@ -894,8 +895,8 @@ test "utf16leToUtf8" { |
| 894 | 895 | |
| 895 | 896 | { |
| 896 | 897 | // 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); | |
| 899 | 900 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); |
| 900 | 901 | defer std.testing.allocator.free(utf8); |
| 901 | 902 | try testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80")); |
| ... | ... | @@ -903,8 +904,8 @@ test "utf16leToUtf8" { |
| 903 | 904 | |
| 904 | 905 | { |
| 905 | 906 | // 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); | |
| 908 | 909 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); |
| 909 | 910 | defer std.testing.allocator.free(utf8); |
| 910 | 911 | try testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80")); |
| ... | ... | @@ -912,24 +913,24 @@ test "utf16leToUtf8" { |
| 912 | 913 | |
| 913 | 914 | { |
| 914 | 915 | // 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); | |
| 917 | 918 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); |
| 918 | 919 | defer std.testing.allocator.free(utf8); |
| 919 | 920 | try testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf")); |
| 920 | 921 | } |
| 921 | 922 | |
| 922 | 923 | { |
| 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); | |
| 925 | 926 | const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); |
| 926 | 927 | defer std.testing.allocator.free(utf8); |
| 927 | 928 | try testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80")); |
| 928 | 929 | } |
| 929 | 930 | |
| 930 | 931 | { |
| 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); | |
| 933 | 934 | const result = utf16leToUtf8Alloc(std.testing.allocator, &utf16le); |
| 934 | 935 | try std.testing.expectError(error.UnexpectedSecondSurrogateHalf, result); |
| 935 | 936 | } |
| ... | ... | @@ -1140,12 +1141,12 @@ test "fmtUtf16le" { |
| 1140 | 1141 | try expectFmt("", "{}", .{fmtUtf16le(utf8ToUtf16LeStringLiteral(""))}); |
| 1141 | 1142 | try expectFmt("foo", "{}", .{fmtUtf16le(utf8ToUtf16LeStringLiteral("foo"))}); |
| 1142 | 1143 | 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)})}); | |
| 1149 | 1150 | } |
| 1150 | 1151 | |
| 1151 | 1152 | test "utf8ToUtf16LeStringLiteral" { |
lib/std/zig/Server.zig+2-2| ... | ... | @@ -279,12 +279,12 @@ fn bswap_u32_array(slice: []u32) void { |
| 279 | 279 | |
| 280 | 280 | /// workaround for https://github.com/ziglang/zig/issues/14904 |
| 281 | 281 | fn 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); | |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | /// workaround for https://github.com/ziglang/zig/issues/14904 |
| 286 | 286 | fn 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); | |
| 288 | 288 | return @as(InMessage.Tag, @enumFromInt(int)); |
| 289 | 289 | } |
| 290 | 290 |
lib/test_runner.zig+3-1| ... | ... | @@ -13,7 +13,9 @@ var cmdline_buffer: [4096]u8 = undefined; |
| 13 | 13 | var fba = std.heap.FixedBufferAllocator.init(&cmdline_buffer); |
| 14 | 14 | |
| 15 | 15 | pub 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 | { | |
| 17 | 19 | return mainSimple() catch @panic("test failure"); |
| 18 | 20 | } |
| 19 | 21 |
src/Package/Fetch/git.zig+12-12| ... | ... | @@ -305,12 +305,12 @@ const Odb = struct { |
| 305 | 305 | const n_objects = odb.index_header.fan_out_table[255]; |
| 306 | 306 | const offset_values_start = IndexHeader.size + n_objects * (oid_length + 4); |
| 307 | 307 | try odb.index_file.seekTo(offset_values_start + found_index * 4); |
| 308 | const l1_offset: packed struct { value: u31, big: bool } = @bitCast(try odb.index_file.reader().readIntBig(u32)); | |
| 308 | const l1_offset: packed struct { value: u31, big: bool } = @bitCast(try odb.index_file.reader().readInt(u32, .Big)); | |
| 309 | 309 | const pack_offset = pack_offset: { |
| 310 | 310 | if (l1_offset.big) { |
| 311 | 311 | const l2_offset_values_start = offset_values_start + n_objects * 4; |
| 312 | 312 | 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); | |
| 314 | 314 | } else { |
| 315 | 315 | break :pack_offset l1_offset.value; |
| 316 | 316 | } |
| ... | ... | @@ -845,12 +845,12 @@ const PackHeader = struct { |
| 845 | 845 | else => |other| return other, |
| 846 | 846 | }; |
| 847 | 847 | 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) { | |
| 849 | 849 | error.EndOfStream => return error.InvalidHeader, |
| 850 | 850 | else => |other| return other, |
| 851 | 851 | }; |
| 852 | 852 | 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) { | |
| 854 | 854 | error.EndOfStream => return error.InvalidHeader, |
| 855 | 855 | else => |other| return other, |
| 856 | 856 | }; |
| ... | ... | @@ -966,14 +966,14 @@ const IndexHeader = struct { |
| 966 | 966 | fn read(reader: anytype) !IndexHeader { |
| 967 | 967 | var header_bytes = try reader.readBytesNoEof(size); |
| 968 | 968 | 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); | |
| 970 | 970 | if (version != supported_version) return error.UnsupportedVersion; |
| 971 | 971 | |
| 972 | 972 | var fan_out_table: [256]u32 = undefined; |
| 973 | 973 | var fan_out_table_stream = std.io.fixedBufferStream(header_bytes[8..]); |
| 974 | 974 | const fan_out_table_reader = fan_out_table_stream.reader(); |
| 975 | 975 | 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; | |
| 977 | 977 | } |
| 978 | 978 | return .{ .fan_out_table = fan_out_table }; |
| 979 | 979 | } |
| ... | ... | @@ -1041,9 +1041,9 @@ pub fn indexPack(allocator: Allocator, pack: std.fs.File, index_writer: anytype) |
| 1041 | 1041 | var index_hashed_writer = hashedWriter(index_writer, Sha1.init(.{})); |
| 1042 | 1042 | const writer = index_hashed_writer.writer(); |
| 1043 | 1043 | try writer.writeAll(IndexHeader.signature); |
| 1044 | try writer.writeIntBig(u32, IndexHeader.supported_version); | |
| 1044 | try writer.writeInt(u32, IndexHeader.supported_version, .Big); | |
| 1045 | 1045 | for (fan_out_table) |fan_out_entry| { |
| 1046 | try writer.writeIntBig(u32, fan_out_entry); | |
| 1046 | try writer.writeInt(u32, fan_out_entry, .Big); | |
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | 1049 | for (oids.items) |oid| { |
| ... | ... | @@ -1051,7 +1051,7 @@ pub fn indexPack(allocator: Allocator, pack: std.fs.File, index_writer: anytype) |
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | 1053 | 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); | |
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | 1057 | var big_offsets = std.ArrayListUnmanaged(u64){}; |
| ... | ... | @@ -1059,15 +1059,15 @@ pub fn indexPack(allocator: Allocator, pack: std.fs.File, index_writer: anytype) |
| 1059 | 1059 | for (oids.items) |oid| { |
| 1060 | 1060 | const offset = index_entries.get(oid).?.offset; |
| 1061 | 1061 | if (offset <= std.math.maxInt(u31)) { |
| 1062 | try writer.writeIntBig(u32, @intCast(offset)); | |
| 1062 | try writer.writeInt(u32, @intCast(offset), .Big); | |
| 1063 | 1063 | } else { |
| 1064 | 1064 | const index = big_offsets.items.len; |
| 1065 | 1065 | 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); | |
| 1067 | 1067 | } |
| 1068 | 1068 | } |
| 1069 | 1069 | for (big_offsets.items) |offset| { |
| 1070 | try writer.writeIntBig(u64, offset); | |
| 1070 | try writer.writeInt(u64, offset, .Big); | |
| 1071 | 1071 | } |
| 1072 | 1072 | |
| 1073 | 1073 | 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 { |
| 3364 | 3364 | const backing_int_ty = struct_type.backingIntType(ip).toType(); |
| 3365 | 3365 | const int_val = try mod.intValue( |
| 3366 | 3366 | backing_int_ty, |
| 3367 | mem.readIntLittle(u64, &buf), | |
| 3367 | mem.readInt(u64, &buf, .Little), | |
| 3368 | 3368 | ); |
| 3369 | 3369 | return func.lowerConstant(int_val, backing_int_ty); |
| 3370 | 3370 | }, |
src/arch/wasm/Emit.zig+2-2| ... | ... | @@ -330,14 +330,14 @@ fn emitImm64(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 330 | 330 | fn emitFloat32(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 331 | 331 | const value: f32 = emit.mir.instructions.items(.data)[inst].float32; |
| 332 | 332 | 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); | |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | fn emitFloat64(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 337 | 337 | const extra_index = emit.mir.instructions.items(.data)[inst].payload; |
| 338 | 338 | const value = emit.mir.extraData(Mir.Float64, extra_index); |
| 339 | 339 | 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); | |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | fn 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 { |
| 253 | 253 | const target = emit.code_offset_mapping.get(reloc.target) orelse |
| 254 | 254 | return emit.fail("JMP/CALL relocation target not found!", .{}); |
| 255 | 255 | 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); | |
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 |
src/arch/x86_64/encoder.zig+4-4| ... | ... | @@ -998,7 +998,7 @@ fn Encoder(comptime T: type, comptime opts: Options) type { |
| 998 | 998 | /// |
| 999 | 999 | /// It is sign-extended to 64 bits by the cpu. |
| 1000 | 1000 | pub fn disp32(self: Self, disp: i32) !void { |
| 1001 | try self.writer.writeIntLittle(i32, disp); | |
| 1001 | try self.writer.writeInt(i32, disp, .Little); | |
| 1002 | 1002 | } |
| 1003 | 1003 | |
| 1004 | 1004 | /// Encode an 8 bit immediate |
| ... | ... | @@ -1012,21 +1012,21 @@ fn Encoder(comptime T: type, comptime opts: Options) type { |
| 1012 | 1012 | /// |
| 1013 | 1013 | /// It is sign-extended to 64 bits by the cpu. |
| 1014 | 1014 | pub fn imm16(self: Self, imm: u16) !void { |
| 1015 | try self.writer.writeIntLittle(u16, imm); | |
| 1015 | try self.writer.writeInt(u16, imm, .Little); | |
| 1016 | 1016 | } |
| 1017 | 1017 | |
| 1018 | 1018 | /// Encode an 32 bit immediate |
| 1019 | 1019 | /// |
| 1020 | 1020 | /// It is sign-extended to 64 bits by the cpu. |
| 1021 | 1021 | pub fn imm32(self: Self, imm: u32) !void { |
| 1022 | try self.writer.writeIntLittle(u32, imm); | |
| 1022 | try self.writer.writeInt(u32, imm, .Little); | |
| 1023 | 1023 | } |
| 1024 | 1024 | |
| 1025 | 1025 | /// Encode an 64 bit immediate |
| 1026 | 1026 | /// |
| 1027 | 1027 | /// It is sign-extended to 64 bits by the cpu. |
| 1028 | 1028 | pub fn imm64(self: Self, imm: u64) !void { |
| 1029 | try self.writer.writeIntLittle(u64, imm); | |
| 1029 | try self.writer.writeInt(u64, imm, .Little); | |
| 1030 | 1030 | } |
| 1031 | 1031 | }; |
| 1032 | 1032 | } |
src/glibc.zig+5-5| ... | ... | @@ -751,7 +751,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo |
| 751 | 751 | |
| 752 | 752 | var inc_i: usize = 0; |
| 753 | 753 | |
| 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); | |
| 755 | 755 | inc_i += 2; |
| 756 | 756 | |
| 757 | 757 | var sym_i: usize = 0; |
| ... | ... | @@ -768,7 +768,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo |
| 768 | 768 | versions_len = 0; |
| 769 | 769 | break :n name; |
| 770 | 770 | }; |
| 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); | |
| 772 | 772 | inc_i += 4; |
| 773 | 773 | |
| 774 | 774 | const lib_index = metadata.inclusions[inc_i]; |
| ... | ... | @@ -882,7 +882,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo |
| 882 | 882 | |
| 883 | 883 | try stubs_asm.appendSlice(".data\n"); |
| 884 | 884 | |
| 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); | |
| 886 | 886 | inc_i += 2; |
| 887 | 887 | |
| 888 | 888 | sym_i = 0; |
| ... | ... | @@ -899,10 +899,10 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo |
| 899 | 899 | versions_len = 0; |
| 900 | 900 | break :n name; |
| 901 | 901 | }; |
| 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); | |
| 903 | 903 | inc_i += 4; |
| 904 | 904 | |
| 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); | |
| 906 | 906 | inc_i += 2; |
| 907 | 907 | |
| 908 | 908 | const lib_index = metadata.inclusions[inc_i]; |
src/link/Coff.zig+9-9| ... | ... | @@ -856,12 +856,12 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void { |
| 856 | 856 | switch (self.ptr_width) { |
| 857 | 857 | .p32 => { |
| 858 | 858 | 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); | |
| 860 | 860 | try self.base.file.?.pwriteAll(&buf, file_offset); |
| 861 | 861 | }, |
| 862 | 862 | .p64 => { |
| 863 | 863 | var buf: [8]u8 = undefined; |
| 864 | mem.writeIntLittle(u64, &buf, entry_value + self.getImageBase()); | |
| 864 | mem.writeInt(u64, &buf, entry_value + self.getImageBase(), .Little); | |
| 865 | 865 | try self.base.file.?.pwriteAll(&buf, file_offset); |
| 866 | 866 | }, |
| 867 | 867 | } |
| ... | ... | @@ -889,14 +889,14 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void { |
| 889 | 889 | switch (self.ptr_width) { |
| 890 | 890 | .p32 => { |
| 891 | 891 | 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); | |
| 893 | 893 | writeMem(handle, pvaddr, &buf) catch |err| { |
| 894 | 894 | log.warn("writing to protected memory failed with error: {s}", .{@errorName(err)}); |
| 895 | 895 | }; |
| 896 | 896 | }, |
| 897 | 897 | .p64 => { |
| 898 | 898 | var buf: [8]u8 = undefined; |
| 899 | mem.writeIntLittle(u64, &buf, entry_value + slide); | |
| 899 | mem.writeInt(u64, &buf, entry_value + slide, .Little); | |
| 900 | 900 | writeMem(handle, pvaddr, &buf) catch |err| { |
| 901 | 901 | log.warn("writing to protected memory failed with error: {s}", .{@errorName(err)}); |
| 902 | 902 | }; |
| ... | ... | @@ -2076,7 +2076,7 @@ fn writeImportTables(self: *Coff) !void { |
| 2076 | 2076 | lookup_table_offset += lookup_entry_size; |
| 2077 | 2077 | |
| 2078 | 2078 | // 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 | |
| 2080 | 2080 | names_table_offset += 2; |
| 2081 | 2081 | @memcpy(buffer.items[names_table_offset..][0..import_name.len], import_name); |
| 2082 | 2082 | names_table_offset += @as(u32, @intCast(import_name.len)); |
| ... | ... | @@ -2089,7 +2089,7 @@ fn writeImportTables(self: *Coff) !void { |
| 2089 | 2089 | } |
| 2090 | 2090 | |
| 2091 | 2091 | // 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); | |
| 2093 | 2093 | iat_offset += 8; |
| 2094 | 2094 | |
| 2095 | 2095 | // Lookup table sentinel |
| ... | ... | @@ -2157,7 +2157,7 @@ fn writeStrtab(self: *Coff) !void { |
| 2157 | 2157 | buffer.appendSliceAssumeCapacity(self.strtab.items()); |
| 2158 | 2158 | // Here, we do a trick in that we do not commit the size of the strtab to strtab buffer, instead |
| 2159 | 2159 | // 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); | |
| 2161 | 2161 | |
| 2162 | 2162 | try self.base.file.?.pwriteAll(buffer.items, self.strtab_offset.?); |
| 2163 | 2163 | } |
| ... | ... | @@ -2180,7 +2180,7 @@ fn writeHeader(self: *Coff) !void { |
| 2180 | 2180 | |
| 2181 | 2181 | try buffer.ensureTotalCapacity(self.getSizeOfHeaders()); |
| 2182 | 2182 | 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); | |
| 2184 | 2184 | |
| 2185 | 2185 | writer.writeAll("PE\x00\x00") catch unreachable; |
| 2186 | 2186 | var flags = coff.CoffHeaderFlags{ |
| ... | ... | @@ -2548,7 +2548,7 @@ fn setSymbolName(self: *Coff, symbol: *coff.Symbol, name: []const u8) !void { |
| 2548 | 2548 | } |
| 2549 | 2549 | const offset = try self.strtab.insert(self.base.allocator, name); |
| 2550 | 2550 | @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); | |
| 2552 | 2552 | } |
| 2553 | 2553 | |
| 2554 | 2554 | fn 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 { |
| 137 | 137 | }; |
| 138 | 138 | inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2)); |
| 139 | 139 | 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); | |
| 141 | 141 | }, |
| 142 | 142 | .got_pageoff, .import_pageoff, .pageoff => { |
| 143 | 143 | assert(!self.pcrel); |
| ... | ... | @@ -151,7 +151,7 @@ fn resolveAarch64(self: Relocation, ctx: Context) void { |
| 151 | 151 | ), buffer[0..4]), |
| 152 | 152 | }; |
| 153 | 153 | 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); | |
| 155 | 155 | } else { |
| 156 | 156 | var inst = aarch64.Instruction{ |
| 157 | 157 | .load_store_register = mem.bytesToValue(meta.TagPayload( |
| ... | ... | @@ -173,18 +173,19 @@ fn resolveAarch64(self: Relocation, ctx: Context) void { |
| 173 | 173 | } |
| 174 | 174 | }; |
| 175 | 175 | 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); | |
| 177 | 177 | } |
| 178 | 178 | }, |
| 179 | 179 | .direct => { |
| 180 | 180 | assert(!self.pcrel); |
| 181 | 181 | switch (self.length) { |
| 182 | 2 => mem.writeIntLittle( | |
| 182 | 2 => mem.writeInt( | |
| 183 | 183 | u32, |
| 184 | 184 | buffer[0..4], |
| 185 | 185 | @as(u32, @truncate(ctx.target_vaddr + ctx.image_base)), |
| 186 | .Little, | |
| 186 | 187 | ), |
| 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), | |
| 188 | 189 | else => unreachable, |
| 189 | 190 | } |
| 190 | 191 | }, |
| ... | ... | @@ -207,17 +208,17 @@ fn resolveX86(self: Relocation, ctx: Context) void { |
| 207 | 208 | .got, .import => { |
| 208 | 209 | assert(self.pcrel); |
| 209 | 210 | 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); | |
| 211 | 212 | }, |
| 212 | 213 | .direct => { |
| 213 | 214 | if (self.pcrel) { |
| 214 | 215 | 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); | |
| 216 | 217 | } 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), | |
| 218 | 219 | .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), | |
| 221 | 222 | else => unreachable, |
| 222 | 223 | }, |
| 223 | 224 | } |
src/link/Elf/Atom.zig+42-42| ... | ... | @@ -786,43 +786,43 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void { |
| 786 | 786 | |
| 787 | 787 | elf.R_X86_64_PLT32, |
| 788 | 788 | 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), | |
| 790 | 790 | |
| 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), | |
| 794 | 794 | |
| 795 | 795 | elf.R_X86_64_GOTPCRELX => { |
| 796 | 796 | if (!target.flags.import and !target.isIFunc(elf_file) and !target.isAbs(elf_file)) blk: { |
| 797 | 797 | 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); | |
| 799 | 799 | continue; |
| 800 | 800 | } |
| 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); | |
| 802 | 802 | }, |
| 803 | 803 | |
| 804 | 804 | elf.R_X86_64_REX_GOTPCRELX => { |
| 805 | 805 | if (!target.flags.import and !target.isIFunc(elf_file) and !target.isAbs(elf_file)) blk: { |
| 806 | 806 | 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); | |
| 808 | 808 | continue; |
| 809 | 809 | } |
| 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); | |
| 811 | 811 | }, |
| 812 | 812 | |
| 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), | |
| 815 | 815 | |
| 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), | |
| 818 | 818 | |
| 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), | |
| 821 | 821 | |
| 822 | 822 | elf.R_X86_64_TLSGD => { |
| 823 | 823 | if (target.flags.has_tlsgd) { |
| 824 | 824 | 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); | |
| 826 | 826 | } else if (target.flags.has_gottp) { |
| 827 | 827 | const S_ = @as(i64, @intCast(target.gotTpAddress(elf_file))); |
| 828 | 828 | try x86_64.relaxTlsGdToIe(self, rels[i .. i + 2], @intCast(S_ - P), elf_file, &stream); |
| ... | ... | @@ -843,7 +843,7 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void { |
| 843 | 843 | if (elf_file.got.tlsld_index) |entry_index| { |
| 844 | 844 | const tlsld_entry = elf_file.got.entries.items[entry_index]; |
| 845 | 845 | 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); | |
| 847 | 847 | } else { |
| 848 | 848 | try x86_64.relaxTlsLdToLe( |
| 849 | 849 | self, |
| ... | ... | @@ -859,10 +859,10 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void { |
| 859 | 859 | elf.R_X86_64_GOTPC32_TLSDESC => { |
| 860 | 860 | if (target.flags.has_tlsdesc) { |
| 861 | 861 | 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); | |
| 863 | 863 | } else { |
| 864 | 864 | 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); | |
| 866 | 866 | } |
| 867 | 867 | }, |
| 868 | 868 | |
| ... | ... | @@ -874,18 +874,18 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void { |
| 874 | 874 | elf.R_X86_64_GOTTPOFF => { |
| 875 | 875 | if (target.flags.has_gottp) { |
| 876 | 876 | 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); | |
| 878 | 878 | } else { |
| 879 | 879 | 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); | |
| 881 | 881 | } |
| 882 | 882 | }, |
| 883 | 883 | |
| 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), | |
| 885 | 885 | |
| 886 | 886 | // 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), | |
| 889 | 889 | |
| 890 | 890 | else => {}, |
| 891 | 891 | } |
| ... | ... | @@ -920,7 +920,7 @@ fn resolveDynAbsReloc( |
| 920 | 920 | .copyrel, |
| 921 | 921 | .cplt, |
| 922 | 922 | .none, |
| 923 | => try writer.writeIntLittle(i32, @as(i32, @truncate(S + A))), | |
| 923 | => try writer.writeInt(i32, @as(i32, @truncate(S + A)), .Little), | |
| 924 | 924 | |
| 925 | 925 | .dyn_copyrel => { |
| 926 | 926 | if (is_writeable or elf_file.base.options.z_nocopyreloc) { |
| ... | ... | @@ -932,7 +932,7 @@ fn resolveDynAbsReloc( |
| 932 | 932 | }); |
| 933 | 933 | try applyDynamicReloc(A, elf_file, writer); |
| 934 | 934 | } else { |
| 935 | try writer.writeIntLittle(i32, @as(i32, @truncate(S + A))); | |
| 935 | try writer.writeInt(i32, @as(i32, @truncate(S + A)), .Little); | |
| 936 | 936 | } |
| 937 | 937 | }, |
| 938 | 938 | |
| ... | ... | @@ -946,7 +946,7 @@ fn resolveDynAbsReloc( |
| 946 | 946 | }); |
| 947 | 947 | try applyDynamicReloc(A, elf_file, writer); |
| 948 | 948 | } else { |
| 949 | try writer.writeIntLittle(i32, @as(i32, @truncate(S + A))); | |
| 949 | try writer.writeInt(i32, @as(i32, @truncate(S + A)), .Little); | |
| 950 | 950 | } |
| 951 | 951 | }, |
| 952 | 952 | |
| ... | ... | @@ -984,7 +984,7 @@ fn resolveDynAbsReloc( |
| 984 | 984 | fn applyDynamicReloc(value: i64, elf_file: *Elf, writer: anytype) !void { |
| 985 | 985 | _ = elf_file; |
| 986 | 986 | // if (elf_file.options.apply_dynamic_relocs) { |
| 987 | try writer.writeIntLittle(i64, value); | |
| 987 | try writer.writeInt(i64, value, .Little); | |
| 988 | 988 | // } |
| 989 | 989 | } |
| 990 | 990 | |
| ... | ... | @@ -1058,22 +1058,22 @@ pub fn resolveRelocsNonAlloc(self: Atom, elf_file: *Elf, code: []u8, undefs: any |
| 1058 | 1058 | |
| 1059 | 1059 | switch (r_type) { |
| 1060 | 1060 | 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), | |
| 1070 | 1070 | elf.R_X86_64_SIZE32 => { |
| 1071 | 1071 | 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); | |
| 1073 | 1073 | }, |
| 1074 | 1074 | elf.R_X86_64_SIZE64 => { |
| 1075 | 1075 | 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); | |
| 1077 | 1077 | }, |
| 1078 | 1078 | else => try self.reportUnhandledRelocError(rel, elf_file), |
| 1079 | 1079 | } |
| ... | ... | @@ -1254,7 +1254,7 @@ const x86_64 = struct { |
| 1254 | 1254 | 0x64, 0x48, 0x8b, 0x04, 0x25, 0, 0, 0, 0, // movq %fs:0,%rax |
| 1255 | 1255 | 0x48, 0x03, 0x05, 0, 0, 0, 0, // add foo@gottpoff(%rip), %rax |
| 1256 | 1256 | }; |
| 1257 | std.mem.writeIntLittle(i32, insts[12..][0..4], value - 12); | |
| 1257 | std.mem.writeInt(i32, insts[12..][0..4], value - 12, .Little); | |
| 1258 | 1258 | try stream.seekBy(-4); |
| 1259 | 1259 | try writer.writeAll(&insts); |
| 1260 | 1260 | }, |
| ... | ... | @@ -1292,7 +1292,7 @@ const x86_64 = struct { |
| 1292 | 1292 | 0x64, 0x48, 0x8b, 0, // mov %fs:(%rax), %rax |
| 1293 | 1293 | 0x48, 0x2d, 0, 0, 0, 0, // sub $tls_size, %rax |
| 1294 | 1294 | }; |
| 1295 | std.mem.writeIntLittle(i32, insts[8..][0..4], value); | |
| 1295 | std.mem.writeInt(i32, insts[8..][0..4], value, .Little); | |
| 1296 | 1296 | try stream.seekBy(-3); |
| 1297 | 1297 | try writer.writeAll(&insts); |
| 1298 | 1298 | }, |
| ... | ... | @@ -1306,7 +1306,7 @@ const x86_64 = struct { |
| 1306 | 1306 | 0x48, 0x2d, 0, 0, 0, 0, // sub $tls_size, %rax |
| 1307 | 1307 | 0x90, // nop |
| 1308 | 1308 | }; |
| 1309 | std.mem.writeIntLittle(i32, insts[8..][0..4], value); | |
| 1309 | std.mem.writeInt(i32, insts[8..][0..4], value, .Little); | |
| 1310 | 1310 | try stream.seekBy(-3); |
| 1311 | 1311 | try writer.writeAll(&insts); |
| 1312 | 1312 | }, |
| ... | ... | @@ -1392,7 +1392,7 @@ const x86_64 = struct { |
| 1392 | 1392 | 0x64, 0x48, 0x8b, 0x04, 0x25, 0, 0, 0, 0, // movq %fs:0,%rax |
| 1393 | 1393 | 0x48, 0x81, 0xc0, 0, 0, 0, 0, // add $tp_offset, %rax |
| 1394 | 1394 | }; |
| 1395 | std.mem.writeIntLittle(i32, insts[12..][0..4], value); | |
| 1395 | std.mem.writeInt(i32, insts[12..][0..4], value, .Little); | |
| 1396 | 1396 | try stream.seekBy(-4); |
| 1397 | 1397 | try writer.writeAll(&insts); |
| 1398 | 1398 | relocs_log.debug(" relaxing {} and {}", .{ |
src/link/Elf/eh_frame.zig+15-13| ... | ... | @@ -33,7 +33,7 @@ pub const Fde = struct { |
| 33 | 33 | |
| 34 | 34 | pub fn ciePointer(fde: Fde, elf_file: *Elf) u32 { |
| 35 | 35 | 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); | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | pub fn calcSize(fde: Fde) usize { |
| ... | ... | @@ -217,10 +217,10 @@ pub const Iterator = struct { |
| 217 | 217 | var stream = std.io.fixedBufferStream(it.data[it.pos..]); |
| 218 | 218 | const reader = stream.reader(); |
| 219 | 219 | |
| 220 | var size = try reader.readIntLittle(u32); | |
| 220 | var size = try reader.readInt(u32, .Little); | |
| 221 | 221 | if (size == 0xFFFFFFFF) @panic("TODO"); |
| 222 | 222 | |
| 223 | const id = try reader.readIntLittle(u32); | |
| 223 | const id = try reader.readInt(u32, .Little); | |
| 224 | 224 | const record = Record{ |
| 225 | 225 | .tag = if (id == 0) .cie else .fde, |
| 226 | 226 | .offset = it.pos, |
| ... | ... | @@ -298,10 +298,10 @@ fn resolveReloc(rec: anytype, sym: *const Symbol, rel: elf.Elf64_Rela, elf_file: |
| 298 | 298 | |
| 299 | 299 | var where = contents[offset..]; |
| 300 | 300 | 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), | |
| 305 | 305 | else => unreachable, |
| 306 | 306 | } |
| 307 | 307 | } |
| ... | ... | @@ -338,10 +338,11 @@ pub fn writeEhFrame(elf_file: *Elf, writer: anytype) !void { |
| 338 | 338 | const contents = try gpa.dupe(u8, fde.data(elf_file)); |
| 339 | 339 | defer gpa.free(contents); |
| 340 | 340 | |
| 341 | std.mem.writeIntLittle( | |
| 341 | std.mem.writeInt( | |
| 342 | 342 | i32, |
| 343 | 343 | 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, | |
| 345 | 346 | ); |
| 346 | 347 | |
| 347 | 348 | for (fde.relocs(elf_file)) |rel| { |
| ... | ... | @@ -353,7 +354,7 @@ pub fn writeEhFrame(elf_file: *Elf, writer: anytype) !void { |
| 353 | 354 | } |
| 354 | 355 | } |
| 355 | 356 | |
| 356 | try writer.writeIntLittle(u32, 0); | |
| 357 | try writer.writeInt(u32, 0, .Little); | |
| 357 | 358 | } |
| 358 | 359 | |
| 359 | 360 | pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void { |
| ... | ... | @@ -365,14 +366,15 @@ pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void { |
| 365 | 366 | const eh_frame_shdr = elf_file.shdrs.items[elf_file.eh_frame_section_index.?]; |
| 366 | 367 | const eh_frame_hdr_shdr = elf_file.shdrs.items[elf_file.eh_frame_hdr_section_index.?]; |
| 367 | 368 | 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( | |
| 369 | 370 | u32, |
| 370 | 371 | @as(u32, @bitCast(@as( |
| 371 | 372 | i32, |
| 372 | 373 | @truncate(@as(i64, @intCast(eh_frame_shdr.sh_addr)) - @as(i64, @intCast(eh_frame_hdr_shdr.sh_addr)) - 4), |
| 373 | 374 | ))), |
| 375 | .Little, | |
| 374 | 376 | ); |
| 375 | try writer.writeIntLittle(u32, num_fdes); | |
| 377 | try writer.writeInt(u32, num_fdes, .Little); | |
| 376 | 378 | |
| 377 | 379 | const Entry = struct { |
| 378 | 380 | init_addr: u32, |
| ... | ... | @@ -401,7 +403,7 @@ pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void { |
| 401 | 403 | const S = @as(i64, @intCast(sym.address(.{}, elf_file))); |
| 402 | 404 | const A = rel.r_addend; |
| 403 | 405 | 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))))), | |
| 405 | 407 | .fde_addr = @as( |
| 406 | 408 | u32, |
| 407 | 409 | @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 { |
| 878 | 878 | 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp qword ptr [rip] -> .got.plt[2] |
| 879 | 879 | }; |
| 880 | 880 | 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); | |
| 882 | 882 | 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); | |
| 884 | 884 | try writer.writeAll(&preamble); |
| 885 | 885 | try writer.writeByteNTimes(0xcc, preamble_size - preamble.len); |
| 886 | 886 | |
| ... | ... | @@ -894,8 +894,8 @@ pub const PltSection = struct { |
| 894 | 894 | 0x41, 0xbb, 0x00, 0x00, 0x00, 0x00, // mov r11d, N |
| 895 | 895 | 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp qword ptr [rip] -> .got.plt[N] |
| 896 | 896 | }; |
| 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); | |
| 899 | 899 | try writer.writeAll(&entry); |
| 900 | 900 | } |
| 901 | 901 | } |
| ... | ... | @@ -971,17 +971,17 @@ pub const GotPltSection = struct { |
| 971 | 971 | { |
| 972 | 972 | // [0]: _DYNAMIC |
| 973 | 973 | const symbol = elf_file.symbol(elf_file.dynamic_index.?); |
| 974 | try writer.writeIntLittle(u64, symbol.value); | |
| 974 | try writer.writeInt(u64, symbol.value, .Little); | |
| 975 | 975 | } |
| 976 | 976 | // [1]: 0x0 |
| 977 | 977 | // [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); | |
| 980 | 980 | if (elf_file.plt_section_index) |shndx| { |
| 981 | 981 | const plt_addr = elf_file.shdrs.items[shndx].sh_addr; |
| 982 | 982 | for (0..elf_file.plt.symbols.items.len) |_| { |
| 983 | 983 | // [N]: .plt |
| 984 | try writer.writeIntLittle(u64, plt_addr); | |
| 984 | try writer.writeInt(u64, plt_addr, .Little); | |
| 985 | 985 | } |
| 986 | 986 | } |
| 987 | 987 | } |
| ... | ... | @@ -1023,7 +1023,7 @@ pub const PltGotSection = struct { |
| 1023 | 1023 | 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp qword ptr [rip] -> .got[N] |
| 1024 | 1024 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, |
| 1025 | 1025 | }; |
| 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); | |
| 1027 | 1027 | try writer.writeAll(&entry); |
| 1028 | 1028 | } |
| 1029 | 1029 | } |
| ... | ... | @@ -1258,8 +1258,8 @@ pub const HashSection = struct { |
| 1258 | 1258 | } |
| 1259 | 1259 | |
| 1260 | 1260 | 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; | |
| 1263 | 1263 | hs.buffer.writer(gpa).writeAll(mem.sliceAsBytes(buckets)) catch unreachable; |
| 1264 | 1264 | hs.buffer.writer(gpa).writeAll(mem.sliceAsBytes(chains)) catch unreachable; |
| 1265 | 1265 | } |
| ... | ... | @@ -1322,10 +1322,10 @@ pub const GnuHashSection = struct { |
| 1322 | 1322 | var counting = std.io.countingWriter(writer); |
| 1323 | 1323 | const cwriter = counting.writer(); |
| 1324 | 1324 | |
| 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); | |
| 1329 | 1329 | |
| 1330 | 1330 | const gpa = elf_file.base.allocator; |
| 1331 | 1331 | const hashes = try gpa.alloc(u32, exports.len); |
src/link/MachO.zig+7-7| ... | ... | @@ -1222,7 +1222,7 @@ fn writeOffsetTableEntry(self: *MachO, index: usize) !void { |
| 1222 | 1222 | log.debug("writing GOT entry {d}: @{x} => {x}", .{ index, vmaddr, entry_value }); |
| 1223 | 1223 | |
| 1224 | 1224 | var buf: [@sizeOf(u64)]u8 = undefined; |
| 1225 | mem.writeIntLittle(u64, &buf, entry_value); | |
| 1225 | mem.writeInt(u64, &buf, entry_value, .Little); | |
| 1226 | 1226 | try self.base.file.?.pwriteAll(&buf, file_offset); |
| 1227 | 1227 | |
| 1228 | 1228 | if (is_hot_update_compatible) { |
| ... | ... | @@ -1329,7 +1329,7 @@ fn writeStubTableEntry(self: *MachO, index: usize) !void { |
| 1329 | 1329 | |
| 1330 | 1330 | { |
| 1331 | 1331 | var buf: [@sizeOf(u64)]u8 = undefined; |
| 1332 | mem.writeIntLittle(u64, &buf, stub_helper_addr); | |
| 1332 | mem.writeInt(u64, &buf, stub_helper_addr, .Little); | |
| 1333 | 1333 | const off = laptr_header.offset + @sizeOf(u64) * index; |
| 1334 | 1334 | try self.base.file.?.pwriteAll(&buf, off); |
| 1335 | 1335 | } |
| ... | ... | @@ -3773,7 +3773,7 @@ fn collectBindData(self: *MachO, bind: anytype, raw_bindings: anytype) !void { |
| 3773 | 3773 | const base_offset = sym.n_value - segment.vmaddr; |
| 3774 | 3774 | const rel_offset = @as(u32, @intCast(rel.r_address - ctx.base_offset)); |
| 3775 | 3775 | 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); | |
| 3777 | 3777 | |
| 3778 | 3778 | const dylib_ordinal = @divTrunc(@as(i16, @bitCast(bind_sym.n_desc)), macho.N_SYMBOL_RESOLVER); |
| 3779 | 3779 | log.debug(" | bind at {x}, import('{s}') in dylib({d})", .{ |
| ... | ... | @@ -4502,7 +4502,7 @@ pub fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void { |
| 4502 | 4502 | if (!self.stub_table.lookup.contains(entry)) continue; |
| 4503 | 4503 | const target_sym = self.getSymbol(entry); |
| 4504 | 4504 | 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); | |
| 4506 | 4506 | } |
| 4507 | 4507 | } |
| 4508 | 4508 | |
| ... | ... | @@ -4513,9 +4513,9 @@ pub fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void { |
| 4513 | 4513 | if (!self.got_table.lookup.contains(entry)) continue; |
| 4514 | 4514 | const target_sym = self.getSymbol(entry); |
| 4515 | 4515 | 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); | |
| 4517 | 4517 | } else { |
| 4518 | try writer.writeIntLittle(u32, macho.INDIRECT_SYMBOL_LOCAL); | |
| 4518 | try writer.writeInt(u32, macho.INDIRECT_SYMBOL_LOCAL, .Little); | |
| 4519 | 4519 | } |
| 4520 | 4520 | } |
| 4521 | 4521 | } |
| ... | ... | @@ -4527,7 +4527,7 @@ pub fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void { |
| 4527 | 4527 | if (!self.stub_table.lookup.contains(entry)) continue; |
| 4528 | 4528 | const target_sym = self.getSymbol(entry); |
| 4529 | 4529 | 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); | |
| 4531 | 4531 | } |
| 4532 | 4532 | } |
| 4533 | 4533 |
src/link/MachO/Archive.zig+4-4| ... | ... | @@ -123,7 +123,7 @@ fn parseName(allocator: Allocator, name_or_length: ar_hdr.NameOrLength, reader: |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | fn 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); | |
| 127 | 127 | var symtab = try allocator.alloc(u8, symtab_size); |
| 128 | 128 | defer allocator.free(symtab); |
| 129 | 129 | |
| ... | ... | @@ -132,7 +132,7 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) ! |
| 132 | 132 | return error.MalformedArchive; |
| 133 | 133 | }; |
| 134 | 134 | |
| 135 | const strtab_size = try reader.readIntLittle(u32); | |
| 135 | const strtab_size = try reader.readInt(u32, .Little); | |
| 136 | 136 | var strtab = try allocator.alloc(u8, strtab_size); |
| 137 | 137 | defer allocator.free(strtab); |
| 138 | 138 | |
| ... | ... | @@ -145,11 +145,11 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) ! |
| 145 | 145 | var symtab_reader = symtab_stream.reader(); |
| 146 | 146 | |
| 147 | 147 | 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) { | |
| 149 | 149 | error.EndOfStream => break, |
| 150 | 150 | else => |e| return e, |
| 151 | 151 | }; |
| 152 | const object_offset = try symtab_reader.readIntLittle(u32); | |
| 152 | const object_offset = try symtab_reader.readInt(u32, .Little); | |
| 153 | 153 | |
| 154 | 154 | const sym_name = mem.sliceTo(@as([*:0]const u8, @ptrCast(strtab.ptr + n_strx)), 0); |
| 155 | 155 | const owned_name = try allocator.dupe(u8, sym_name); |
src/link/MachO/Atom.zig+26-26| ... | ... | @@ -443,9 +443,9 @@ pub fn parseRelocTarget(macho_file: *MachO, ctx: struct { |
| 443 | 443 | |
| 444 | 444 | const address_in_section = if (ctx.rel.r_pcrel == 0) blk: { |
| 445 | 445 | 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) | |
| 447 | 447 | else |
| 448 | mem.readIntLittle(u32, ctx.code[rel_offset..][0..4]); | |
| 448 | mem.readInt(u32, ctx.code[rel_offset..][0..4], .Little); | |
| 449 | 449 | } else blk: { |
| 450 | 450 | assert(macho_file.base.options.target.cpu.arch == .x86_64); |
| 451 | 451 | const correction: u3 = switch (@as(macho.reloc_type_x86_64, @enumFromInt(ctx.rel.r_type))) { |
| ... | ... | @@ -455,7 +455,7 @@ pub fn parseRelocTarget(macho_file: *MachO, ctx: struct { |
| 455 | 455 | .X86_64_RELOC_SIGNED_4 => 4, |
| 456 | 456 | else => unreachable, |
| 457 | 457 | }; |
| 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); | |
| 459 | 459 | const target_address = @as(i64, @intCast(ctx.base_addr)) + ctx.rel.r_address + 4 + correction + addend; |
| 460 | 460 | break :blk @as(u64, @intCast(target_address)); |
| 461 | 461 | }; |
| ... | ... | @@ -781,7 +781,7 @@ fn resolveRelocsArm64( |
| 781 | 781 | ), code), |
| 782 | 782 | }; |
| 783 | 783 | 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); | |
| 785 | 785 | }, |
| 786 | 786 | |
| 787 | 787 | .ARM64_RELOC_PAGE21, |
| ... | ... | @@ -802,7 +802,7 @@ fn resolveRelocsArm64( |
| 802 | 802 | }; |
| 803 | 803 | inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2)); |
| 804 | 804 | inst.pc_relative_address.immlo = @as(u2, @truncate(pages)); |
| 805 | mem.writeIntLittle(u32, code, inst.toU32()); | |
| 805 | mem.writeInt(u32, code, inst.toU32(), .Little); | |
| 806 | 806 | addend = null; |
| 807 | 807 | }, |
| 808 | 808 | |
| ... | ... | @@ -821,7 +821,7 @@ fn resolveRelocsArm64( |
| 821 | 821 | ), code), |
| 822 | 822 | }; |
| 823 | 823 | inst.add_subtract_immediate.imm12 = off; |
| 824 | mem.writeIntLittle(u32, code, inst.toU32()); | |
| 824 | mem.writeInt(u32, code, inst.toU32(), .Little); | |
| 825 | 825 | } else { |
| 826 | 826 | var inst = aarch64.Instruction{ |
| 827 | 827 | .load_store_register = mem.bytesToValue(meta.TagPayload( |
| ... | ... | @@ -839,7 +839,7 @@ fn resolveRelocsArm64( |
| 839 | 839 | 3 => .load_store_64, |
| 840 | 840 | }); |
| 841 | 841 | inst.load_store_register.offset = off; |
| 842 | mem.writeIntLittle(u32, code, inst.toU32()); | |
| 842 | mem.writeInt(u32, code, inst.toU32(), .Little); | |
| 843 | 843 | } |
| 844 | 844 | addend = null; |
| 845 | 845 | }, |
| ... | ... | @@ -858,7 +858,7 @@ fn resolveRelocsArm64( |
| 858 | 858 | ), code), |
| 859 | 859 | }; |
| 860 | 860 | inst.load_store_register.offset = off; |
| 861 | mem.writeIntLittle(u32, code, inst.toU32()); | |
| 861 | mem.writeInt(u32, code, inst.toU32(), .Little); | |
| 862 | 862 | addend = null; |
| 863 | 863 | }, |
| 864 | 864 | |
| ... | ... | @@ -918,7 +918,7 @@ fn resolveRelocsArm64( |
| 918 | 918 | .sf = @as(u1, @truncate(reg_info.size)), |
| 919 | 919 | }, |
| 920 | 920 | }; |
| 921 | mem.writeIntLittle(u32, code, inst.toU32()); | |
| 921 | mem.writeInt(u32, code, inst.toU32(), .Little); | |
| 922 | 922 | addend = null; |
| 923 | 923 | }, |
| 924 | 924 | |
| ... | ... | @@ -926,14 +926,14 @@ fn resolveRelocsArm64( |
| 926 | 926 | relocs_log.debug(" | target_addr = 0x{x}", .{target_addr}); |
| 927 | 927 | const result = math.cast(i32, @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr))) orelse |
| 928 | 928 | 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); | |
| 930 | 930 | }, |
| 931 | 931 | |
| 932 | 932 | .ARM64_RELOC_UNSIGNED => { |
| 933 | 933 | 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) | |
| 935 | 935 | else |
| 936 | mem.readIntLittle(i32, atom_code[rel_offset..][0..4]); | |
| 936 | mem.readInt(i32, atom_code[rel_offset..][0..4], .Little); | |
| 937 | 937 | |
| 938 | 938 | if (rel.r_extern == 0) { |
| 939 | 939 | const base_addr = if (target.sym_index >= object.source_address_lookup.len) |
| ... | ... | @@ -954,9 +954,9 @@ fn resolveRelocsArm64( |
| 954 | 954 | relocs_log.debug(" | target_addr = 0x{x}", .{result}); |
| 955 | 955 | |
| 956 | 956 | 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); | |
| 958 | 958 | } 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); | |
| 960 | 960 | } |
| 961 | 961 | |
| 962 | 962 | subtractor = null; |
| ... | ... | @@ -1045,25 +1045,25 @@ fn resolveRelocsX86( |
| 1045 | 1045 | |
| 1046 | 1046 | switch (rel_type) { |
| 1047 | 1047 | .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); | |
| 1049 | 1049 | const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend)); |
| 1050 | 1050 | relocs_log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr}); |
| 1051 | 1051 | 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); | |
| 1053 | 1053 | }, |
| 1054 | 1054 | |
| 1055 | 1055 | .X86_64_RELOC_GOT, |
| 1056 | 1056 | .X86_64_RELOC_GOT_LOAD, |
| 1057 | 1057 | => { |
| 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); | |
| 1059 | 1059 | const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend)); |
| 1060 | 1060 | relocs_log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr}); |
| 1061 | 1061 | 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); | |
| 1063 | 1063 | }, |
| 1064 | 1064 | |
| 1065 | 1065 | .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); | |
| 1067 | 1067 | const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend)); |
| 1068 | 1068 | relocs_log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr}); |
| 1069 | 1069 | const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0); |
| ... | ... | @@ -1073,7 +1073,7 @@ fn resolveRelocsX86( |
| 1073 | 1073 | atom_code[rel_offset - 2] = 0x8d; |
| 1074 | 1074 | } |
| 1075 | 1075 | |
| 1076 | mem.writeIntLittle(i32, atom_code[rel_offset..][0..4], disp); | |
| 1076 | mem.writeInt(i32, atom_code[rel_offset..][0..4], disp, .Little); | |
| 1077 | 1077 | }, |
| 1078 | 1078 | |
| 1079 | 1079 | .X86_64_RELOC_SIGNED, |
| ... | ... | @@ -1088,7 +1088,7 @@ fn resolveRelocsX86( |
| 1088 | 1088 | .X86_64_RELOC_SIGNED_4 => 4, |
| 1089 | 1089 | else => unreachable, |
| 1090 | 1090 | }; |
| 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; | |
| 1092 | 1092 | |
| 1093 | 1093 | if (rel.r_extern == 0) { |
| 1094 | 1094 | const base_addr = if (target.sym_index >= object.source_address_lookup.len) |
| ... | ... | @@ -1104,14 +1104,14 @@ fn resolveRelocsX86( |
| 1104 | 1104 | relocs_log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr}); |
| 1105 | 1105 | |
| 1106 | 1106 | 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); | |
| 1108 | 1108 | }, |
| 1109 | 1109 | |
| 1110 | 1110 | .X86_64_RELOC_UNSIGNED => { |
| 1111 | 1111 | 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) | |
| 1113 | 1113 | else |
| 1114 | mem.readIntLittle(i32, atom_code[rel_offset..][0..4]); | |
| 1114 | mem.readInt(i32, atom_code[rel_offset..][0..4], .Little); | |
| 1115 | 1115 | |
| 1116 | 1116 | if (rel.r_extern == 0) { |
| 1117 | 1117 | const base_addr = if (target.sym_index >= object.source_address_lookup.len) |
| ... | ... | @@ -1132,9 +1132,9 @@ fn resolveRelocsX86( |
| 1132 | 1132 | relocs_log.debug(" | target_addr = 0x{x}", .{result}); |
| 1133 | 1133 | |
| 1134 | 1134 | 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); | |
| 1136 | 1136 | } 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); | |
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | 1140 | subtractor = null; |
src/link/MachO/CodeSignature.zig+29-29| ... | ... | @@ -115,14 +115,14 @@ pub fn writeAdhocSignature( |
| 115 | 115 | self.code_directory.inner.length = self.code_directory.size(); |
| 116 | 116 | header.length += self.code_directory.size(); |
| 117 | 117 | |
| 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); | |
| 121 | 121 | |
| 122 | 122 | var offset: u32 = @sizeOf(macho.SuperBlob) + @sizeOf(macho.BlobIndex) * @as(u32, @intCast(blobs.items.len)); |
| 123 | 123 | 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); | |
| 126 | 126 | offset += blob.size(); |
| 127 | 127 | } |
| 128 | 128 | |
| ... | ... | @@ -272,27 +272,27 @@ const CodeDirectory = struct { |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | 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); | |
| 284 | 284 | try writer.writeByte(self.inner.hashSize); |
| 285 | 285 | try writer.writeByte(self.inner.hashType); |
| 286 | 286 | try writer.writeByte(self.inner.platform); |
| 287 | 287 | 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); | |
| 296 | 296 | |
| 297 | 297 | try writer.writeAll(self.ident); |
| 298 | 298 | try writer.writeByte(0); |
| ... | ... | @@ -325,9 +325,9 @@ const Requirements = struct { |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | 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); | |
| 331 | 331 | } |
| 332 | 332 | }; |
| 333 | 333 | |
| ... | ... | @@ -348,8 +348,8 @@ const Entitlements = struct { |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | 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); | |
| 353 | 353 | try writer.writeAll(self.inner); |
| 354 | 354 | } |
| 355 | 355 | }; |
| ... | ... | @@ -371,8 +371,8 @@ const Signature = struct { |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | 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); | |
| 376 | 376 | } |
| 377 | 377 | }; |
| 378 | 378 |
src/link/MachO/DwarfInfo.zig+17-17| ... | ... | @@ -121,19 +121,19 @@ pub const CompileUnit = struct { |
| 121 | 121 | address_size: u8, |
| 122 | 122 | |
| 123 | 123 | fn read(reader: anytype) !Header { |
| 124 | var length: u64 = try reader.readIntLittle(u32); | |
| 124 | var length: u64 = try reader.readInt(u32, .Little); | |
| 125 | 125 | |
| 126 | 126 | const is_64bit = length == 0xffffffff; |
| 127 | 127 | if (is_64bit) { |
| 128 | length = try reader.readIntLittle(u64); | |
| 128 | length = try reader.readInt(u64, .Little); | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | const version = try reader.readIntLittle(u16); | |
| 131 | const version = try reader.readInt(u16, .Little); | |
| 132 | 132 | const debug_abbrev_offset = if (is_64bit) |
| 133 | try reader.readIntLittle(u64) | |
| 133 | try reader.readInt(u64, .Little) | |
| 134 | 134 | 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); | |
| 137 | 137 | |
| 138 | 138 | return Header{ |
| 139 | 139 | .is_64bit = is_64bit, |
| ... | ... | @@ -251,9 +251,9 @@ pub const Attribute = struct { |
| 251 | 251 | }, |
| 252 | 252 | dwarf.FORM.strp => { |
| 253 | 253 | const off = if (cuh.is_64bit) |
| 254 | mem.readIntLittle(u64, debug_info[0..8]) | |
| 254 | mem.readInt(u64, debug_info[0..8], .Little) | |
| 255 | 255 | else |
| 256 | mem.readIntLittle(u32, debug_info[0..4]); | |
| 256 | mem.readInt(u32, debug_info[0..4], .Little); | |
| 257 | 257 | return ctx.getString(off); |
| 258 | 258 | }, |
| 259 | 259 | else => return null, |
| ... | ... | @@ -267,9 +267,9 @@ pub const Attribute = struct { |
| 267 | 267 | |
| 268 | 268 | return switch (self.form) { |
| 269 | 269 | 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), | |
| 273 | 273 | dwarf.FORM.udata => try leb.readULEB128(u64, reader), |
| 274 | 274 | dwarf.FORM.sdata => try leb.readILEB128(i64, reader), |
| 275 | 275 | else => null, |
| ... | ... | @@ -281,9 +281,9 @@ pub const Attribute = struct { |
| 281 | 281 | const debug_info = self.getDebugInfo(ctx); |
| 282 | 282 | return switch (cuh.address_size) { |
| 283 | 283 | 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), | |
| 287 | 287 | else => unreachable, |
| 288 | 288 | }; |
| 289 | 289 | } |
| ... | ... | @@ -380,9 +380,9 @@ fn findFormSize(self: DwarfInfo, form: u64, di_off: usize, cuh: CompileUnit.Head |
| 380 | 380 | dwarf.FORM.block, |
| 381 | 381 | => { |
| 382 | 382 | 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), | |
| 386 | 386 | dwarf.FORM.block => try leb.readULEB128(u64, reader), |
| 387 | 387 | else => unreachable, |
| 388 | 388 | }; |
src/link/MachO/Relocation.zig+9-9| ... | ... | @@ -128,7 +128,7 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: [] |
| 128 | 128 | ), buffer[0..4]), |
| 129 | 129 | }; |
| 130 | 130 | 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); | |
| 132 | 132 | }, |
| 133 | 133 | .page, .got_page => { |
| 134 | 134 | const source_page = @as(i32, @intCast(source_addr >> 12)); |
| ... | ... | @@ -142,7 +142,7 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: [] |
| 142 | 142 | }; |
| 143 | 143 | inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2)); |
| 144 | 144 | 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); | |
| 146 | 146 | }, |
| 147 | 147 | .pageoff, .got_pageoff => { |
| 148 | 148 | const narrowed = @as(u12, @truncate(@as(u64, @intCast(target_addr)))); |
| ... | ... | @@ -154,7 +154,7 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: [] |
| 154 | 154 | ), buffer[0..4]), |
| 155 | 155 | }; |
| 156 | 156 | 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); | |
| 158 | 158 | } else { |
| 159 | 159 | var inst = aarch64.Instruction{ |
| 160 | 160 | .load_store_register = mem.bytesToValue(meta.TagPayload( |
| ... | ... | @@ -176,12 +176,12 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: [] |
| 176 | 176 | } |
| 177 | 177 | }; |
| 178 | 178 | 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); | |
| 180 | 180 | } |
| 181 | 181 | }, |
| 182 | 182 | .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), | |
| 185 | 185 | else => unreachable, |
| 186 | 186 | }, |
| 187 | 187 | .got, .signed, .tlv => unreachable, // Invalid target architecture. |
| ... | ... | @@ -192,15 +192,15 @@ fn resolveX8664(self: Relocation, source_addr: u64, target_addr: i64, code: []u8 |
| 192 | 192 | switch (self.type) { |
| 193 | 193 | .branch, .got, .tlv, .signed => { |
| 194 | 194 | 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); | |
| 196 | 196 | }, |
| 197 | 197 | .tlv_initializer, .unsigned => { |
| 198 | 198 | switch (self.length) { |
| 199 | 199 | 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); | |
| 201 | 201 | }, |
| 202 | 202 | 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); | |
| 204 | 204 | }, |
| 205 | 205 | else => unreachable, |
| 206 | 206 | } |
src/link/MachO/UnwindInfo.zig+1-1| ... | ... | @@ -149,7 +149,7 @@ const Page = struct { |
| 149 | 149 | |
| 150 | 150 | for (page.page_encodings[0..page.page_encodings_count]) |record_id| { |
| 151 | 151 | const enc = info.records.items[record_id].compactUnwindEncoding; |
| 152 | try writer.writeIntLittle(u32, enc); | |
| 152 | try writer.writeInt(u32, enc, .Little); | |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | assert(page.count > 0); |
src/link/MachO/eh_frame.zig+26-26| ... | ... | @@ -209,7 +209,7 @@ pub fn write(macho_file: *MachO, unwind_info: *UnwindInfo) !void { |
| 209 | 209 | const writer = buffer.writer(); |
| 210 | 210 | |
| 211 | 211 | for (eh_records.values()) |record| { |
| 212 | try writer.writeIntLittle(u32, record.size); | |
| 212 | try writer.writeInt(u32, record.size, .Little); | |
| 213 | 213 | try buffer.appendSlice(record.data); |
| 214 | 214 | } |
| 215 | 215 | |
| ... | ... | @@ -259,7 +259,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { |
| 259 | 259 | base_offset: u64, |
| 260 | 260 | }) u64 { |
| 261 | 261 | 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); | |
| 263 | 263 | return @as(u64, @intCast(@as(i64, @intCast(ctx.base_addr + ctx.base_offset + 8)) + addend)); |
| 264 | 264 | } |
| 265 | 265 | |
| ... | ... | @@ -269,7 +269,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { |
| 269 | 269 | }) !void { |
| 270 | 270 | assert(rec.tag == .fde); |
| 271 | 271 | 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); | |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | pub fn getPersonalityPointerReloc( |
| ... | ... | @@ -343,13 +343,13 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { |
| 343 | 343 | const target_addr = macho_file.getGotEntryAddress(target).?; |
| 344 | 344 | const result = math.cast(i32, @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr))) orelse |
| 345 | 345 | 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); | |
| 347 | 347 | }, |
| 348 | 348 | .ARM64_RELOC_UNSIGNED => { |
| 349 | 349 | assert(rel.r_extern == 1); |
| 350 | 350 | const target_addr = Atom.getRelocTargetAddress(macho_file, target, false); |
| 351 | 351 | 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); | |
| 353 | 353 | }, |
| 354 | 354 | else => unreachable, |
| 355 | 355 | } |
| ... | ... | @@ -359,10 +359,10 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { |
| 359 | 359 | switch (rel_type) { |
| 360 | 360 | .X86_64_RELOC_GOT => { |
| 361 | 361 | 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); | |
| 363 | 363 | const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend)); |
| 364 | 364 | 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); | |
| 366 | 366 | }, |
| 367 | 367 | else => unreachable, |
| 368 | 368 | } |
| ... | ... | @@ -375,7 +375,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { |
| 375 | 375 | pub fn getCiePointerSource(rec: Record, object_id: u32, macho_file: *MachO, offset: u32) u32 { |
| 376 | 376 | assert(rec.tag == .fde); |
| 377 | 377 | 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); | |
| 379 | 379 | switch (cpu_arch) { |
| 380 | 380 | .aarch64 => { |
| 381 | 381 | const relocs = getRelocs(macho_file, object_id, offset); |
| ... | ... | @@ -397,12 +397,12 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { |
| 397 | 397 | |
| 398 | 398 | pub fn getCiePointer(rec: Record) u32 { |
| 399 | 399 | assert(rec.tag == .fde); |
| 400 | return mem.readIntLittle(u32, rec.data[0..4]); | |
| 400 | return mem.readInt(u32, rec.data[0..4], .Little); | |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | pub fn setCiePointer(rec: *Record, ptr: u32) void { |
| 404 | 404 | assert(rec.tag == .fde); |
| 405 | mem.writeIntLittle(u32, rec.data[0..4], ptr); | |
| 405 | mem.writeInt(u32, rec.data[0..4], ptr, .Little); | |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | pub fn getAugmentationString(rec: Record) []const u8 { |
| ... | ... | @@ -509,14 +509,14 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { |
| 509 | 509 | if (enc == EH_PE.omit) return null; |
| 510 | 510 | |
| 511 | 511 | 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))), | |
| 516 | 516 | 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), | |
| 520 | 520 | EH_PE.sleb128 => try leb.readILEB128(i64, reader), |
| 521 | 521 | else => return null, |
| 522 | 522 | }; |
| ... | ... | @@ -552,14 +552,14 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | 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), | |
| 559 | 559 | 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), | |
| 563 | 563 | EH_PE.sleb128 => try leb.writeILEB128(writer, actual), |
| 564 | 564 | else => unreachable, |
| 565 | 565 | } |
| ... | ... | @@ -586,13 +586,13 @@ pub const Iterator = struct { |
| 586 | 586 | var stream = std.io.fixedBufferStream(it.data[it.pos..]); |
| 587 | 587 | const reader = stream.reader(); |
| 588 | 588 | |
| 589 | var size = try reader.readIntLittle(u32); | |
| 589 | var size = try reader.readInt(u32, .Little); | |
| 590 | 590 | if (size == 0xFFFFFFFF) { |
| 591 | 591 | log.debug("MachO doesn't support 64bit DWARF CFI __eh_frame records", .{}); |
| 592 | 592 | return error.BadDwarfCfi; |
| 593 | 593 | } |
| 594 | 594 | |
| 595 | const id = try reader.readIntLittle(u32); | |
| 595 | const id = try reader.readInt(u32, .Little); | |
| 596 | 596 | const tag: EhFrameRecordTag = if (id == 0) .cie else .fde; |
| 597 | 597 | const offset: u32 = 4; |
| 598 | 598 | const record = EhFrameRecord(false){ |
src/link/MachO/stubs.zig+19-19| ... | ... | @@ -53,7 +53,7 @@ pub fn writeStubHelperPreambleCode(args: struct { |
| 53 | 53 | args.dyld_private_addr, |
| 54 | 54 | 0, |
| 55 | 55 | ); |
| 56 | try writer.writeIntLittle(i32, disp); | |
| 56 | try writer.writeInt(i32, disp, .Little); | |
| 57 | 57 | } |
| 58 | 58 | try writer.writeAll(&.{ 0x41, 0x53, 0xff, 0x25 }); |
| 59 | 59 | { |
| ... | ... | @@ -62,37 +62,37 @@ pub fn writeStubHelperPreambleCode(args: struct { |
| 62 | 62 | args.dyld_stub_binder_got_addr, |
| 63 | 63 | 0, |
| 64 | 64 | ); |
| 65 | try writer.writeIntLittle(i32, disp); | |
| 65 | try writer.writeInt(i32, disp, .Little); | |
| 66 | 66 | } |
| 67 | 67 | }, |
| 68 | 68 | .aarch64 => { |
| 69 | 69 | { |
| 70 | 70 | 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); | |
| 72 | 72 | } |
| 73 | 73 | { |
| 74 | 74 | 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); | |
| 76 | 76 | } |
| 77 | try writer.writeIntLittle(u32, aarch64.Instruction.stp( | |
| 77 | try writer.writeInt(u32, aarch64.Instruction.stp( | |
| 78 | 78 | .x16, |
| 79 | 79 | .x17, |
| 80 | 80 | aarch64.Register.sp, |
| 81 | 81 | aarch64.Instruction.LoadStorePairOffset.pre_index(-16), |
| 82 | ).toU32()); | |
| 82 | ).toU32(), .Little); | |
| 83 | 83 | { |
| 84 | 84 | 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); | |
| 86 | 86 | } |
| 87 | 87 | { |
| 88 | 88 | 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( | |
| 90 | 90 | .x16, |
| 91 | 91 | .x16, |
| 92 | 92 | aarch64.Instruction.LoadStoreOffset.imm(off), |
| 93 | ).toU32()); | |
| 93 | ).toU32(), .Little); | |
| 94 | 94 | } |
| 95 | try writer.writeIntLittle(u32, aarch64.Instruction.br(.x16).toU32()); | |
| 95 | try writer.writeInt(u32, aarch64.Instruction.br(.x16).toU32(), .Little); | |
| 96 | 96 | }, |
| 97 | 97 | else => unreachable, |
| 98 | 98 | } |
| ... | ... | @@ -108,7 +108,7 @@ pub fn writeStubHelperCode(args: struct { |
| 108 | 108 | try writer.writeAll(&.{ 0x68, 0x0, 0x0, 0x0, 0x0, 0xe9 }); |
| 109 | 109 | { |
| 110 | 110 | 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); | |
| 112 | 112 | } |
| 113 | 113 | }, |
| 114 | 114 | .aarch64 => { |
| ... | ... | @@ -117,13 +117,13 @@ pub fn writeStubHelperCode(args: struct { |
| 117 | 117 | const div_res = try std.math.divExact(u64, stub_size - @sizeOf(u32), 4); |
| 118 | 118 | break :blk std.math.cast(u18, div_res) orelse return error.Overflow; |
| 119 | 119 | }; |
| 120 | try writer.writeIntLittle(u32, aarch64.Instruction.ldrLiteral( | |
| 120 | try writer.writeInt(u32, aarch64.Instruction.ldrLiteral( | |
| 121 | 121 | .w16, |
| 122 | 122 | literal, |
| 123 | ).toU32()); | |
| 123 | ).toU32(), .Little); | |
| 124 | 124 | { |
| 125 | 125 | 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); | |
| 127 | 127 | } |
| 128 | 128 | try writer.writeAll(&.{ 0x0, 0x0, 0x0, 0x0 }); |
| 129 | 129 | }, |
| ... | ... | @@ -141,23 +141,23 @@ pub fn writeStubCode(args: struct { |
| 141 | 141 | try writer.writeAll(&.{ 0xff, 0x25 }); |
| 142 | 142 | { |
| 143 | 143 | 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); | |
| 145 | 145 | } |
| 146 | 146 | }, |
| 147 | 147 | .aarch64 => { |
| 148 | 148 | { |
| 149 | 149 | 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); | |
| 151 | 151 | } |
| 152 | 152 | { |
| 153 | 153 | 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( | |
| 155 | 155 | .x16, |
| 156 | 156 | .x16, |
| 157 | 157 | aarch64.Instruction.LoadStoreOffset.imm(off), |
| 158 | ).toU32()); | |
| 158 | ).toU32(), .Little); | |
| 159 | 159 | } |
| 160 | try writer.writeIntLittle(u32, aarch64.Instruction.br(.x16).toU32()); | |
| 160 | try writer.writeInt(u32, aarch64.Instruction.br(.x16).toU32(), .Little); | |
| 161 | 161 | }, |
| 162 | 162 | else => unreachable, |
| 163 | 163 | } |
src/link/MachO/thunks.zig+3-3| ... | ... | @@ -349,10 +349,10 @@ pub fn writeThunkCode(macho_file: *MachO, thunk: *const Thunk, writer: anytype) |
| 349 | 349 | .atom => macho_file.getSymbol(target).n_value, |
| 350 | 350 | }; |
| 351 | 351 | 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); | |
| 353 | 353 | 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); | |
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | 358 |
src/link/MachO/zld.zig+2-2| ... | ... | @@ -796,7 +796,7 @@ fn writePointerEntries(macho_file: *MachO, sect_id: u8, table: anytype) !void { |
| 796 | 796 | defer buffer.deinit(); |
| 797 | 797 | for (table.entries.items) |entry| { |
| 798 | 798 | 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; | |
| 800 | 800 | } |
| 801 | 801 | log.debug("writing __DATA_CONST,__got contents at file offset 0x{x}", .{header.offset}); |
| 802 | 802 | try macho_file.base.file.?.pwriteAll(buffer.items, header.offset); |
| ... | ... | @@ -880,7 +880,7 @@ fn writeLaSymbolPtrs(macho_file: *MachO) !void { |
| 880 | 880 | for (0..macho_file.stub_table.count()) |index| { |
| 881 | 881 | const target_addr = stub_helper_header.addr + stubs.stubHelperPreambleSize(cpu_arch) + |
| 882 | 882 | stubs.stubHelperSize(cpu_arch) * index; |
| 883 | buffer.writer().writeIntLittle(u64, target_addr) catch unreachable; | |
| 883 | buffer.writer().writeInt(u64, target_addr, .Little) catch unreachable; | |
| 884 | 884 | } |
| 885 | 885 | |
| 886 | 886 | log.debug("writing __DATA,__la_symbol_ptr contents at file offset 0x{x}", .{ |
src/link/Plan9.zig+7-7| ... | ... | @@ -348,7 +348,7 @@ fn putFn(self: *Plan9, decl_index: Module.Decl.Index, out: FnDeclOutput) !void { |
| 348 | 348 | // every 'z' starts with 0 |
| 349 | 349 | try a.append(0); |
| 350 | 350 | // path component value of '/' |
| 351 | try a.writer().writeIntBig(u16, 1); | |
| 351 | try a.writer().writeInt(u16, 1, .Big); | |
| 352 | 352 | |
| 353 | 353 | // getting the full file path |
| 354 | 354 | var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; |
| ... | ... | @@ -381,11 +381,11 @@ fn addPathComponents(self: *Plan9, path: []const u8, a: *std.ArrayList(u8)) !voi |
| 381 | 381 | var it = std.mem.tokenizeScalar(u8, path, sep); |
| 382 | 382 | while (it.next()) |component| { |
| 383 | 383 | if (self.file_segments.get(component)) |num| { |
| 384 | try a.writer().writeIntBig(u16, num); | |
| 384 | try a.writer().writeInt(u16, num, .Big); | |
| 385 | 385 | } else { |
| 386 | 386 | self.file_segments_i += 1; |
| 387 | 387 | 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); | |
| 389 | 389 | } |
| 390 | 390 | } |
| 391 | 391 | } |
| ... | ... | @@ -607,7 +607,7 @@ pub fn changeLine(l: *std.ArrayList(u8), delta_line: i32) !void { |
| 607 | 607 | try l.append(toadd); |
| 608 | 608 | } else if (delta_line != 0) { |
| 609 | 609 | try l.append(0); |
| 610 | try l.writer().writeIntBig(i32, delta_line); | |
| 610 | try l.writer().writeInt(i32, delta_line, .Big); | |
| 611 | 611 | } |
| 612 | 612 | } |
| 613 | 613 | |
| ... | ... | @@ -922,7 +922,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No |
| 922 | 922 | @memcpy(hdr_slice, self.hdr.toU8s()[0..hdr_size]); |
| 923 | 923 | // write the fat header for 64 bit entry points |
| 924 | 924 | 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); | |
| 926 | 926 | } |
| 927 | 927 | // perform the relocs |
| 928 | 928 | { |
| ... | ... | @@ -1311,9 +1311,9 @@ pub fn writeSym(self: *Plan9, w: anytype, sym: aout.Sym) !void { |
| 1311 | 1311 | // log.debug("write sym{{name: {s}, value: {x}}}", .{ sym.name, sym.value }); |
| 1312 | 1312 | if (sym.type == .bad) return; // we don't want to write free'd symbols |
| 1313 | 1313 | 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); | |
| 1315 | 1315 | } else { |
| 1316 | try w.writeIntBig(u64, sym.value); | |
| 1316 | try w.writeInt(u64, sym.value, .Big); | |
| 1317 | 1317 | } |
| 1318 | 1318 | try w.writeByte(@intFromEnum(sym.type)); |
| 1319 | 1319 | try w.writeAll(sym.name); |
src/link/Plan9/aout.zig+1-1| ... | ... | @@ -21,7 +21,7 @@ pub const ExecHdr = extern struct { |
| 21 | 21 | var buf: [40]u8 = undefined; |
| 22 | 22 | var i: u8 = 0; |
| 23 | 23 | 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); | |
| 25 | 25 | i += 4; |
| 26 | 26 | } |
| 27 | 27 | return buf; |
src/link/Wasm.zig+5-5| ... | ... | @@ -2371,7 +2371,7 @@ fn setupErrorsLen(wasm: *Wasm) !void { |
| 2371 | 2371 | atom.deinit(wasm); |
| 2372 | 2372 | break :blk index; |
| 2373 | 2373 | } 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); | |
| 2375 | 2375 | try wasm.symbol_atom.put(wasm.base.allocator, loc, atom_index); |
| 2376 | 2376 | try wasm.managed_atoms.append(wasm.base.allocator, undefined); |
| 2377 | 2377 | break :new_atom atom_index; |
| ... | ... | @@ -2380,7 +2380,7 @@ fn setupErrorsLen(wasm: *Wasm) !void { |
| 2380 | 2380 | atom.* = Atom.empty; |
| 2381 | 2381 | atom.sym_index = loc.index; |
| 2382 | 2382 | 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); | |
| 2384 | 2384 | |
| 2385 | 2385 | try wasm.parseAtom(atom_index, .{ .data = .read_only }); |
| 2386 | 2386 | } |
| ... | ... | @@ -3151,7 +3151,7 @@ fn populateErrorNameTable(wasm: *Wasm) !void { |
| 3151 | 3151 | const offset = @as(u32, @intCast(atom.code.items.len)); |
| 3152 | 3152 | // first we create the data for the slice of the name |
| 3153 | 3153 | 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); | |
| 3155 | 3155 | // create relocation to the error name |
| 3156 | 3156 | try atom.relocs.append(wasm.base.allocator, .{ |
| 3157 | 3157 | .index = names_atom.sym_index, |
| ... | ... | @@ -4286,11 +4286,11 @@ fn emitInit(writer: anytype, init_expr: std.wasm.InitExpression) !void { |
| 4286 | 4286 | }, |
| 4287 | 4287 | .f32_const => |val| { |
| 4288 | 4288 | 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); | |
| 4290 | 4290 | }, |
| 4291 | 4291 | .f64_const => |val| { |
| 4292 | 4292 | 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); | |
| 4294 | 4294 | }, |
| 4295 | 4295 | .global_get => |val| { |
| 4296 | 4296 | try writer.writeByte(std.wasm.opcode(.global_get)); |
src/link/Wasm/Archive.zig+2-2| ... | ... | @@ -141,11 +141,11 @@ fn parseTableOfContents(archive: *Archive, allocator: Allocator, reader: anytype |
| 141 | 141 | const size_trimmed = mem.trim(u8, &archive.header.ar_size, " "); |
| 142 | 142 | const sym_tab_size = try std.fmt.parseInt(u32, size_trimmed, 10); |
| 143 | 143 | |
| 144 | const num_symbols = try reader.readIntBig(u32); | |
| 144 | const num_symbols = try reader.readInt(u32, .Big); | |
| 145 | 145 | const symbol_positions = try allocator.alloc(u32, num_symbols); |
| 146 | 146 | defer allocator.free(symbol_positions); |
| 147 | 147 | for (symbol_positions) |*index| { |
| 148 | index.* = try reader.readIntBig(u32); | |
| 148 | index.* = try reader.readInt(u32, .Big); | |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | const sym_tab = try allocator.alloc(u8, sym_tab_size - 4 - (4 * num_symbols)); |
src/link/Wasm/Atom.zig+2-2| ... | ... | @@ -114,10 +114,10 @@ pub fn resolveRelocs(atom: *Atom, wasm_bin: *const Wasm) void { |
| 114 | 114 | .R_WASM_GLOBAL_INDEX_I32, |
| 115 | 115 | .R_WASM_MEMORY_ADDR_I32, |
| 116 | 116 | .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), | |
| 118 | 118 | .R_WASM_TABLE_INDEX_I64, |
| 119 | 119 | .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), | |
| 121 | 121 | .R_WASM_GLOBAL_INDEX_LEB, |
| 122 | 122 | .R_WASM_EVENT_INDEX_LEB, |
| 123 | 123 | .R_WASM_FUNCTION_INDEX_LEB, |
src/link/Wasm/Object.zig+1-1| ... | ... | @@ -344,7 +344,7 @@ fn Parser(comptime ReaderType: type) type { |
| 344 | 344 | fn parseObject(parser: *ObjectParser, gpa: Allocator, is_object_file: *bool) Error!void { |
| 345 | 345 | errdefer parser.object.deinit(gpa); |
| 346 | 346 | try parser.verifyMagicBytes(); |
| 347 | const version = try parser.reader.reader().readIntLittle(u32); | |
| 347 | const version = try parser.reader.reader().readInt(u32, .Little); | |
| 348 | 348 | |
| 349 | 349 | parser.object.version = version; |
| 350 | 350 | var relocatable_data = std.ArrayList(RelocatableData).init(gpa); |
src/resinator/ani.zig+2-2| ... | ... | @@ -25,14 +25,14 @@ fn getAniheaderFlags(reader: anytype) !u32 { |
| 25 | 25 | const riff_header = try reader.readBytesNoEof(4); |
| 26 | 26 | if (!std.mem.eql(u8, &riff_header, "RIFF")) return error.InvalidFormat; |
| 27 | 27 | |
| 28 | _ = try reader.readIntLittle(u32); // size of RIFF chunk | |
| 28 | _ = try reader.readInt(u32, .Little); // size of RIFF chunk | |
| 29 | 29 | |
| 30 | 30 | const form_type = try reader.readBytesNoEof(4); |
| 31 | 31 | if (!std.mem.eql(u8, &form_type, "ACON")) return error.InvalidFormat; |
| 32 | 32 | |
| 33 | 33 | while (true) { |
| 34 | 34 | const chunk_id = try reader.readBytesNoEof(4); |
| 35 | const chunk_len = try reader.readIntLittle(u32); | |
| 35 | const chunk_len = try reader.readInt(u32, .Little); | |
| 36 | 36 | if (!std.mem.eql(u8, &chunk_id, "anih")) { |
| 37 | 37 | // TODO: Move file cursor instead of skipBytes |
| 38 | 38 | try reader.skipBytes(chunk_len, .{}); |
src/resinator/bmp.zig+8-6| ... | ... | @@ -20,8 +20,10 @@ |
| 20 | 20 | |
| 21 | 21 | const std = @import("std"); |
| 22 | 22 | const BitmapHeader = @import("ico.zig").BitmapHeader; |
| 23 | const builtin = @import("builtin"); | |
| 24 | const native_endian = builtin.cpu.arch.endian(); | |
| 23 | 25 | |
| 24 | pub const windows_format_id = std.mem.readIntNative(u16, "BM"); | |
| 26 | pub const windows_format_id = std.mem.readInt(u16, "BM", native_endian); | |
| 25 | 27 | pub const file_header_len = 14; |
| 26 | 28 | |
| 27 | 29 | pub const ReadError = error{ |
| ... | ... | @@ -89,19 +91,19 @@ pub fn read(reader: anytype, max_size: u64) ReadError!BitmapInfo { |
| 89 | 91 | var bitmap_info: BitmapInfo = undefined; |
| 90 | 92 | const file_header = reader.readBytesNoEof(file_header_len) catch return error.UnexpectedEOF; |
| 91 | 93 | |
| 92 | const id = std.mem.readIntNative(u16, file_header[0..2]); | |
| 94 | const id = std.mem.readInt(u16, file_header[0..2], native_endian); | |
| 93 | 95 | if (id != windows_format_id) return error.InvalidFileHeader; |
| 94 | 96 | |
| 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); | |
| 96 | 98 | if (bitmap_info.pixel_data_offset > max_size) return error.ImpossiblePixelDataOffset; |
| 97 | 99 | |
| 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; | |
| 99 | 101 | if (bitmap_info.pixel_data_offset < file_header_len + bitmap_info.dib_header_size) return error.ImpossiblePixelDataOffset; |
| 100 | 102 | const dib_version = BitmapHeader.Version.get(bitmap_info.dib_header_size); |
| 101 | 103 | switch (dib_version) { |
| 102 | 104 | .@"nt3.1", .@"nt4.0", .@"nt5.0" => { |
| 103 | 105 | 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); | |
| 105 | 107 | reader.readNoEof(dib_header_buf[4..]) catch return error.UnexpectedEOF; |
| 106 | 108 | var dib_header: *BITMAPINFOHEADER = @ptrCast(&dib_header_buf); |
| 107 | 109 | structFieldsLittleToNative(BITMAPINFOHEADER, dib_header); |
| ... | ... | @@ -116,7 +118,7 @@ pub fn read(reader: anytype, max_size: u64) ReadError!BitmapInfo { |
| 116 | 118 | }, |
| 117 | 119 | .@"win2.0" => { |
| 118 | 120 | 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); | |
| 120 | 122 | reader.readNoEof(dib_header_buf[4..]) catch return error.UnexpectedEOF; |
| 121 | 123 | var dib_header: *BITMAPCOREHEADER = @ptrCast(&dib_header_buf); |
| 122 | 124 | structFieldsLittleToNative(BITMAPCOREHEADER, dib_header); |
src/resinator/compile.zig+95-94| ... | ... | @@ -28,6 +28,7 @@ const windows1252 = @import("windows1252.zig"); |
| 28 | 28 | const lang = @import("lang.zig"); |
| 29 | 29 | const code_pages = @import("code_pages.zig"); |
| 30 | 30 | const errors = @import("errors.zig"); |
| 31 | const native_endian = builtin.cpu.arch.endian(); | |
| 31 | 32 | |
| 32 | 33 | pub const CompileOptions = struct { |
| 33 | 34 | cwd: std.fs.Dir, |
| ... | ... | @@ -584,8 +585,8 @@ pub const Compiler = struct { |
| 584 | 585 | // > resource if a RESDIR structure contains information about a cursor. |
| 585 | 586 | // where LOCALHEADER is `struct { WORD xHotSpot; WORD yHotSpot; }` |
| 586 | 587 | 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); | |
| 589 | 590 | } |
| 590 | 591 | |
| 591 | 592 | try file.seekTo(entry.data_offset_from_start_of_file); |
| ... | ... | @@ -666,7 +667,7 @@ pub const Compiler = struct { |
| 666 | 667 | }, |
| 667 | 668 | .dib => { |
| 668 | 669 | var bitmap_header: *ico.BitmapHeader = @ptrCast(@alignCast(&header_bytes)); |
| 669 | if (builtin.cpu.arch.endian() == .Big) { | |
| 670 | if (native_endian == .Big) { | |
| 670 | 671 | std.mem.byteSwapAllFields(ico.BitmapHeader, bitmap_header); |
| 671 | 672 | } |
| 672 | 673 | const bitmap_version = ico.BitmapHeader.Version.get(bitmap_header.bcSize); |
| ... | ... | @@ -777,7 +778,7 @@ pub const Compiler = struct { |
| 777 | 778 | if (bitmap_info.getActualPaletteByteLen() > bitmap_info.getExpectedPaletteByteLen()) { |
| 778 | 779 | const num_ignored_bytes = bitmap_info.getActualPaletteByteLen() - bitmap_info.getExpectedPaletteByteLen(); |
| 779 | 780 | 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); | |
| 781 | 782 | const value_string_index = try self.diagnostics.putString(&number_as_bytes); |
| 782 | 783 | try self.addErrorDetails(.{ |
| 783 | 784 | .err = .bmp_ignored_palette_bytes, |
| ... | ... | @@ -792,8 +793,8 @@ pub const Compiler = struct { |
| 792 | 793 | const max_missing_bytes = 4096; |
| 793 | 794 | if (num_padding_bytes > max_missing_bytes) { |
| 794 | 795 | 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); | |
| 797 | 798 | const values_string_index = try self.diagnostics.putString(&numbers_as_bytes); |
| 798 | 799 | try self.addErrorDetails(.{ |
| 799 | 800 | .err = .bmp_too_many_missing_palette_bytes, |
| ... | ... | @@ -809,7 +810,7 @@ pub const Compiler = struct { |
| 809 | 810 | } |
| 810 | 811 | |
| 811 | 812 | 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); | |
| 813 | 814 | const value_string_index = try self.diagnostics.putString(&number_as_bytes); |
| 814 | 815 | try self.addErrorDetails(.{ |
| 815 | 816 | .err = .bmp_missing_palette_bytes, |
| ... | ... | @@ -820,7 +821,7 @@ pub const Compiler = struct { |
| 820 | 821 | const pixel_data_len = bitmap_info.getPixelDataLen(file_size); |
| 821 | 822 | if (pixel_data_len > 0) { |
| 822 | 823 | 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); | |
| 824 | 825 | const miscompiled_bytes_string_index = try self.diagnostics.putString(&number_as_bytes); |
| 825 | 826 | try self.addErrorDetails(.{ |
| 826 | 827 | .err = .rc_would_miscompile_bmp_palette_padding, |
| ... | ... | @@ -984,8 +985,8 @@ pub const Compiler = struct { |
| 984 | 985 | pub fn write(self: Data, writer: anytype) !void { |
| 985 | 986 | switch (self) { |
| 986 | 987 | .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), | |
| 989 | 990 | }, |
| 990 | 991 | .ascii_string => |ascii_string| { |
| 991 | 992 | try writer.writeAll(ascii_string); |
| ... | ... | @@ -1315,9 +1316,9 @@ pub const Compiler = struct { |
| 1315 | 1316 | |
| 1316 | 1317 | try data_writer.writeByte(modifiers.value); |
| 1317 | 1318 | 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 | |
| 1321 | 1322 | } |
| 1322 | 1323 | } |
| 1323 | 1324 | |
| ... | ... | @@ -1700,34 +1701,34 @@ pub const Compiler = struct { |
| 1700 | 1701 | if (node.help_id == null) break :help_id 0; |
| 1701 | 1702 | break :help_id evaluateNumberExpression(node.help_id.?, self.source, self.input_code_pages).value; |
| 1702 | 1703 | }; |
| 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); | |
| 1708 | 1709 | } 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); | |
| 1711 | 1712 | } |
| 1712 | 1713 | // This limit is enforced by the parser, so we know the number of controls |
| 1713 | 1714 | // 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); | |
| 1719 | 1720 | |
| 1720 | 1721 | // Menu |
| 1721 | 1722 | if (optional_statement_values.menu) |menu| { |
| 1722 | 1723 | try menu.write(data_writer); |
| 1723 | 1724 | } else { |
| 1724 | try data_writer.writeIntLittle(u16, 0); | |
| 1725 | try data_writer.writeInt(u16, 0, .Little); | |
| 1725 | 1726 | } |
| 1726 | 1727 | // Class |
| 1727 | 1728 | if (optional_statement_values.class) |class| { |
| 1728 | 1729 | try class.write(data_writer); |
| 1729 | 1730 | } else { |
| 1730 | try data_writer.writeIntLittle(u16, 0); | |
| 1731 | try data_writer.writeInt(u16, 0, .Little); | |
| 1731 | 1732 | } |
| 1732 | 1733 | // Caption |
| 1733 | 1734 | if (optional_statement_values.caption) |caption| { |
| ... | ... | @@ -1735,7 +1736,7 @@ pub const Compiler = struct { |
| 1735 | 1736 | defer self.allocator.free(parsed); |
| 1736 | 1737 | try data_writer.writeAll(std.mem.sliceAsBytes(parsed[0 .. parsed.len + 1])); |
| 1737 | 1738 | } else { |
| 1738 | try data_writer.writeIntLittle(u16, 0); | |
| 1739 | try data_writer.writeInt(u16, 0, .Little); | |
| 1739 | 1740 | } |
| 1740 | 1741 | // Font |
| 1741 | 1742 | if (optional_statement_values.font) |font| { |
| ... | ... | @@ -1786,18 +1787,18 @@ pub const Compiler = struct { |
| 1786 | 1787 | switch (resource) { |
| 1787 | 1788 | .dialog => { |
| 1788 | 1789 | // 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); | |
| 1791 | 1792 | }, |
| 1792 | 1793 | .dialogex => { |
| 1793 | 1794 | const help_id: u32 = if (control.help_id) |help_id_expression| |
| 1794 | 1795 | evaluateNumberExpression(help_id_expression, self.source, self.input_code_pages).value |
| 1795 | 1796 | else |
| 1796 | 1797 | 0; |
| 1797 | try data_writer.writeIntLittle(u32, help_id); | |
| 1798 | try data_writer.writeInt(u32, help_id, .Little); | |
| 1798 | 1799 | // 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); | |
| 1801 | 1802 | }, |
| 1802 | 1803 | else => unreachable, |
| 1803 | 1804 | } |
| ... | ... | @@ -1807,15 +1808,15 @@ pub const Compiler = struct { |
| 1807 | 1808 | const control_width = evaluateNumberExpression(control.width, self.source, self.input_code_pages); |
| 1808 | 1809 | const control_height = evaluateNumberExpression(control.height, self.source, self.input_code_pages); |
| 1809 | 1810 | |
| 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); | |
| 1814 | 1815 | |
| 1815 | 1816 | const control_id = evaluateNumberExpression(control.id, self.source, self.input_code_pages); |
| 1816 | 1817 | 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), | |
| 1819 | 1820 | else => unreachable, |
| 1820 | 1821 | } |
| 1821 | 1822 | |
| ... | ... | @@ -1948,7 +1949,7 @@ pub const Compiler = struct { |
| 1948 | 1949 | } |
| 1949 | 1950 | // We know the extra_data_buf size fits within a u16. |
| 1950 | 1951 | 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); | |
| 1952 | 1953 | try data_writer.writeAll(extra_data_buf.items); |
| 1953 | 1954 | } |
| 1954 | 1955 | |
| ... | ... | @@ -1962,21 +1963,21 @@ pub const Compiler = struct { |
| 1962 | 1963 | |
| 1963 | 1964 | // I'm assuming this is some sort of version |
| 1964 | 1965 | // 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); | |
| 1969 | 1970 | |
| 1970 | 1971 | for (node.buttons) |button_or_sep| { |
| 1971 | 1972 | switch (button_or_sep.id) { |
| 1972 | 1973 | .literal => { // This is always SEPARATOR |
| 1973 | 1974 | 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); | |
| 1975 | 1976 | }, |
| 1976 | 1977 | .simple_statement => { |
| 1977 | 1978 | const value_node = button_or_sep.cast(.simple_statement).?.value; |
| 1978 | 1979 | 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); | |
| 1980 | 1981 | }, |
| 1981 | 1982 | else => unreachable, // This is a bug in the parser |
| 1982 | 1983 | } |
| ... | ... | @@ -2007,21 +2008,21 @@ pub const Compiler = struct { |
| 2007 | 2008 | pub fn writeDialogFont(self: *Compiler, resource: Resource, values: FontStatementValues, writer: anytype) !void { |
| 2008 | 2009 | const node = values.node; |
| 2009 | 2010 | 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); | |
| 2011 | 2012 | |
| 2012 | 2013 | if (resource == .dialogex) { |
| 2013 | try writer.writeIntLittle(u16, values.weight); | |
| 2014 | try writer.writeInt(u16, values.weight, .Little); | |
| 2014 | 2015 | } |
| 2015 | 2016 | |
| 2016 | 2017 | if (resource == .dialogex) { |
| 2017 | try writer.writeIntLittle(u8, @intFromBool(values.italic)); | |
| 2018 | try writer.writeInt(u8, @intFromBool(values.italic), .Little); | |
| 2018 | 2019 | } |
| 2019 | 2020 | |
| 2020 | 2021 | if (node.char_set) |char_set| { |
| 2021 | 2022 | 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); | |
| 2023 | 2024 | } else if (resource == .dialogex) { |
| 2024 | try writer.writeIntLittle(u8, 1); // DEFAULT_CHARSET | |
| 2025 | try writer.writeInt(u8, 1, .Little); // DEFAULT_CHARSET | |
| 2025 | 2026 | } |
| 2026 | 2027 | |
| 2027 | 2028 | const typeface = try self.parseQuotedStringAsWideString(node.typeface); |
| ... | ... | @@ -2076,9 +2077,9 @@ pub const Compiler = struct { |
| 2076 | 2077 | pub fn writeMenuData(self: *Compiler, node: *Node.Menu, data_writer: anytype, resource: Resource) !void { |
| 2077 | 2078 | // menu header |
| 2078 | 2079 | const version: u16 = if (resource == .menu) 0 else 1; |
| 2079 | try data_writer.writeIntLittle(u16, version); | |
| 2080 | try data_writer.writeInt(u16, version, .Little); | |
| 2080 | 2081 | 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 | |
| 2082 | 2083 | // Note: There can be extra bytes at the end of this header (`rgbExtra`), |
| 2083 | 2084 | // but they are always zero-length for us, so we don't write anything |
| 2084 | 2085 | // (the length of the rgbExtra field is inferred from the header_size). |
| ... | ... | @@ -2088,9 +2089,9 @@ pub const Compiler = struct { |
| 2088 | 2089 | if (resource == .menuex) { |
| 2089 | 2090 | if (node.help_id) |help_id_node| { |
| 2090 | 2091 | 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); | |
| 2092 | 2093 | } else { |
| 2093 | try data_writer.writeIntLittle(u32, 0); | |
| 2094 | try data_writer.writeInt(u32, 0, .Little); | |
| 2094 | 2095 | } |
| 2095 | 2096 | } |
| 2096 | 2097 | |
| ... | ... | @@ -2110,9 +2111,9 @@ pub const Compiler = struct { |
| 2110 | 2111 | // compiler still uses this alternate form, so that's what we use too. |
| 2111 | 2112 | var flags = res.MenuItemFlags{}; |
| 2112 | 2113 | 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 | |
| 2116 | 2117 | }, |
| 2117 | 2118 | .menu_item => { |
| 2118 | 2119 | const menu_item = @fieldParentPtr(Node.MenuItem, "base", node); |
| ... | ... | @@ -2123,10 +2124,10 @@ pub const Compiler = struct { |
| 2123 | 2124 | flags.apply(option); |
| 2124 | 2125 | } |
| 2125 | 2126 | if (is_last_of_parent) flags.markLast(); |
| 2126 | try writer.writeIntLittle(u16, flags.value); | |
| 2127 | try writer.writeInt(u16, flags.value, .Little); | |
| 2127 | 2128 | |
| 2128 | 2129 | 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); | |
| 2130 | 2131 | |
| 2131 | 2132 | var text = try self.parseQuotedStringAsWideString(menu_item.text); |
| 2132 | 2133 | defer self.allocator.free(text); |
| ... | ... | @@ -2141,7 +2142,7 @@ pub const Compiler = struct { |
| 2141 | 2142 | flags.apply(option); |
| 2142 | 2143 | } |
| 2143 | 2144 | if (is_last_of_parent) flags.markLast(); |
| 2144 | try writer.writeIntLittle(u16, flags.value); | |
| 2145 | try writer.writeInt(u16, flags.value, .Little); | |
| 2145 | 2146 | |
| 2146 | 2147 | var text = try self.parseQuotedStringAsWideString(popup.text); |
| 2147 | 2148 | defer self.allocator.free(text); |
| ... | ... | @@ -2157,30 +2158,30 @@ pub const Compiler = struct { |
| 2157 | 2158 | |
| 2158 | 2159 | if (menu_item.type) |flags| { |
| 2159 | 2160 | 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); | |
| 2161 | 2162 | } else { |
| 2162 | try writer.writeIntLittle(u32, 0); | |
| 2163 | try writer.writeInt(u32, 0, .Little); | |
| 2163 | 2164 | } |
| 2164 | 2165 | |
| 2165 | 2166 | if (menu_item.state) |state| { |
| 2166 | 2167 | 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); | |
| 2168 | 2169 | } else { |
| 2169 | try writer.writeIntLittle(u32, 0); | |
| 2170 | try writer.writeInt(u32, 0, .Little); | |
| 2170 | 2171 | } |
| 2171 | 2172 | |
| 2172 | 2173 | if (menu_item.id) |id| { |
| 2173 | 2174 | 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); | |
| 2175 | 2176 | } else { |
| 2176 | try writer.writeIntLittle(u32, 0); | |
| 2177 | try writer.writeInt(u32, 0, .Little); | |
| 2177 | 2178 | } |
| 2178 | 2179 | |
| 2179 | 2180 | var flags: u16 = 0; |
| 2180 | 2181 | if (is_last_of_parent) flags |= comptime @as(u16, @intCast(res.MF.END)); |
| 2181 | 2182 | // This constant doesn't seem to have a named #define, it's different than MF_POPUP |
| 2182 | 2183 | if (node_type == .popup_ex) flags |= 0x01; |
| 2183 | try writer.writeIntLittle(u16, flags); | |
| 2184 | try writer.writeInt(u16, flags, .Little); | |
| 2184 | 2185 | |
| 2185 | 2186 | var text = try self.parseQuotedStringAsWideString(menu_item.text); |
| 2186 | 2187 | defer self.allocator.free(text); |
| ... | ... | @@ -2195,9 +2196,9 @@ pub const Compiler = struct { |
| 2195 | 2196 | if (node_type == .popup_ex) { |
| 2196 | 2197 | if (menu_item.help_id) |help_id_node| { |
| 2197 | 2198 | 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); | |
| 2199 | 2200 | } else { |
| 2200 | try writer.writeIntLittle(u32, 0); | |
| 2201 | try writer.writeInt(u32, 0, .Little); | |
| 2201 | 2202 | } |
| 2202 | 2203 | |
| 2203 | 2204 | for (menu_item.items, 0..) |item, i| { |
| ... | ... | @@ -2218,15 +2219,15 @@ pub const Compiler = struct { |
| 2218 | 2219 | var limited_writer = limitedWriter(data_buffer.writer(), std.math.maxInt(u16)); |
| 2219 | 2220 | const data_writer = limited_writer.writer(); |
| 2220 | 2221 | |
| 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); | |
| 2224 | 2225 | const key_bytes = std.mem.sliceAsBytes(res.FixedFileInfo.key[0 .. res.FixedFileInfo.key.len + 1]); |
| 2225 | 2226 | try data_writer.writeAll(key_bytes); |
| 2226 | 2227 | // The number of bytes written up to this point is always the same, since the name |
| 2227 | 2228 | // of the node is a constant (FixedFileInfo.key). The total number of bytes |
| 2228 | 2229 | // 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); | |
| 2230 | 2231 | |
| 2231 | 2232 | var fixed_file_info = res.FixedFileInfo{}; |
| 2232 | 2233 | for (node.fixed_info) |fixed_info| { |
| ... | ... | @@ -2321,7 +2322,7 @@ pub const Compiler = struct { |
| 2321 | 2322 | // limited the writer to maxInt(u16) |
| 2322 | 2323 | const data_size: u16 = @intCast(data_buffer.items.len); |
| 2323 | 2324 | // 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); | |
| 2325 | 2326 | |
| 2326 | 2327 | var header = try self.resourceHeader(node.id, node.versioninfo, .{ |
| 2327 | 2328 | .data_size = data_size, |
| ... | ... | @@ -2344,12 +2345,12 @@ pub const Compiler = struct { |
| 2344 | 2345 | try writeDataPadding(writer, @as(u16, @intCast(buf.items.len))); |
| 2345 | 2346 | |
| 2346 | 2347 | 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 | |
| 2348 | 2349 | 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 | |
| 2350 | 2351 | const data_type_offset = buf.items.len; |
| 2351 | 2352 | // 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); | |
| 2353 | 2354 | |
| 2354 | 2355 | switch (node.id) { |
| 2355 | 2356 | inline .block, .block_value => |node_type| { |
| ... | ... | @@ -2411,17 +2412,17 @@ pub const Compiler = struct { |
| 2411 | 2412 | const is_empty = parsed_to_first_null.len == 0; |
| 2412 | 2413 | const is_only = block_or_value.values.len == 1; |
| 2413 | 2414 | 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); | |
| 2415 | 2416 | values_size += if (has_number_value) 2 else 1; |
| 2416 | 2417 | } |
| 2417 | 2418 | } |
| 2418 | 2419 | } |
| 2419 | 2420 | 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); | |
| 2421 | 2422 | |
| 2422 | 2423 | if (has_number_value) { |
| 2423 | 2424 | 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); | |
| 2425 | 2426 | } |
| 2426 | 2427 | |
| 2427 | 2428 | if (node_type == .block) { |
| ... | ... | @@ -2436,7 +2437,7 @@ pub const Compiler = struct { |
| 2436 | 2437 | |
| 2437 | 2438 | const node_and_children_size = buf.items.len - node_and_children_size_offset; |
| 2438 | 2439 | 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); | |
| 2440 | 2441 | } |
| 2441 | 2442 | |
| 2442 | 2443 | pub fn writeStringTable(self: *Compiler, node: *Node.StringTable) !void { |
| ... | ... | @@ -2644,17 +2645,17 @@ pub const Compiler = struct { |
| 2644 | 2645 | } |
| 2645 | 2646 | |
| 2646 | 2647 | 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 | |
| 2649 | 2650 | try self.type_value.write(writer); // TYPE |
| 2650 | 2651 | try self.name_value.write(writer); // NAME |
| 2651 | 2652 | try writer.writeByteNTimes(0, size_info.padding_after_name); |
| 2652 | 2653 | |
| 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 | |
| 2658 | 2659 | } |
| 2659 | 2660 | |
| 2660 | 2661 | pub fn predefinedResourceType(self: ResourceHeader) ?res.RT { |
| ... | ... | @@ -2997,7 +2998,7 @@ pub const FontDir = struct { |
| 2997 | 2998 | defer header.deinit(compiler.allocator); |
| 2998 | 2999 | |
| 2999 | 3000 | try header.writeAssertNoOverflow(writer); |
| 3000 | try writer.writeIntLittle(u16, num_fonts); | |
| 3001 | try writer.writeInt(u16, num_fonts, .Little); | |
| 3001 | 3002 | for (self.fonts.items) |font| { |
| 3002 | 3003 | // The format of the FONTDIR is a strange beast. |
| 3003 | 3004 | // Technically, each FONT is seemingly meant to be written as a |
| ... | ... | @@ -3049,7 +3050,7 @@ pub const FontDir = struct { |
| 3049 | 3050 | // device name/face name in the FONTDIR is reliable. |
| 3050 | 3051 | |
| 3051 | 3052 | // First, the ID is written, though |
| 3052 | try writer.writeIntLittle(u16, font.id); | |
| 3053 | try writer.writeInt(u16, font.id, .Little); | |
| 3053 | 3054 | try writer.writeAll(&font.header_bytes); |
| 3054 | 3055 | try writer.writeByteNTimes(0, 2); |
| 3055 | 3056 | } |
| ... | ... | @@ -3186,7 +3187,7 @@ pub const StringTable = struct { |
| 3186 | 3187 | var string_i: u8 = 0; |
| 3187 | 3188 | while (true) : (i += 1) { |
| 3188 | 3189 | if (!self.set_indexes.isSet(i)) { |
| 3189 | try data_writer.writeIntLittle(u16, 0); | |
| 3190 | try data_writer.writeInt(u16, 0, .Little); | |
| 3190 | 3191 | if (i == 15) break else continue; |
| 3191 | 3192 | } |
| 3192 | 3193 | |
| ... | ... | @@ -3217,10 +3218,10 @@ pub const StringTable = struct { |
| 3217 | 3218 | // If the option is set, then a NUL terminator is added unconditionally. |
| 3218 | 3219 | // We already trimmed any trailing NULs, so we know it will be a new addition to the string. |
| 3219 | 3220 | 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); | |
| 3221 | 3222 | try data_writer.writeAll(std.mem.sliceAsBytes(trimmed_string)); |
| 3222 | 3223 | if (compiler.null_terminate_string_table_strings) { |
| 3223 | try data_writer.writeIntLittle(u16, 0); | |
| 3224 | try data_writer.writeInt(u16, 0, .Little); | |
| 3224 | 3225 | } |
| 3225 | 3226 | |
| 3226 | 3227 | if (i == 15) break; |
src/resinator/errors.zig+7-5| ... | ... | @@ -9,6 +9,8 @@ const bmp = @import("bmp.zig"); |
| 9 | 9 | const parse = @import("parse.zig"); |
| 10 | 10 | const lang = @import("lang.zig"); |
| 11 | 11 | const CodePage = @import("code_pages.zig").CodePage; |
| 12 | const builtin = @import("builtin"); | |
| 13 | const native_endian = builtin.cpu.arch.endian(); | |
| 12 | 14 | |
| 13 | 15 | pub const Diagnostics = struct { |
| 14 | 16 | errors: std.ArrayListUnmanaged(ErrorDetails) = .{}, |
| ... | ... | @@ -649,24 +651,24 @@ pub const ErrorDetails = struct { |
| 649 | 651 | }, |
| 650 | 652 | .bmp_ignored_palette_bytes => { |
| 651 | 653 | 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); | |
| 653 | 655 | try writer.print("bitmap has {d} extra bytes preceding the pixel data which will be ignored", .{ignored_bytes}); |
| 654 | 656 | }, |
| 655 | 657 | .bmp_missing_palette_bytes => { |
| 656 | 658 | 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); | |
| 658 | 660 | try writer.print("bitmap has {d} missing color palette bytes which will be padded with zeroes", .{missing_bytes}); |
| 659 | 661 | }, |
| 660 | 662 | .rc_would_miscompile_bmp_palette_padding => { |
| 661 | 663 | 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); | |
| 663 | 665 | 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}); |
| 664 | 666 | }, |
| 665 | 667 | .bmp_too_many_missing_palette_bytes => switch (self.type) { |
| 666 | 668 | .err, .warning => { |
| 667 | 669 | 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); | |
| 670 | 672 | try writer.print("bitmap has {} missing color palette bytes which exceeds the maximum of {}", .{ missing_bytes, max_missing_bytes }); |
| 671 | 673 | }, |
| 672 | 674 | // TODO: command line option |
src/resinator/ico.zig+34-32| ... | ... | @@ -5,6 +5,8 @@ |
| 5 | 5 | //! https://learn.microsoft.com/en-us/windows/win32/menurc/localheader |
| 6 | 6 | |
| 7 | 7 | const std = @import("std"); |
| 8 | const builtin = @import("builtin"); | |
| 9 | const native_endian = builtin.cpu.arch.endian(); | |
| 8 | 10 | |
| 9 | 11 | pub const ReadError = std.mem.Allocator.Error || error{ InvalidHeader, InvalidImageType, ImpossibleDataSize, UnexpectedEOF, ReadError }; |
| 10 | 12 | |
| ... | ... | @@ -37,7 +39,7 @@ pub fn read(allocator: std.mem.Allocator, reader: anytype, max_size: u64) ReadEr |
| 37 | 39 | // to do this. Maybe it makes more sense to handle the translation |
| 38 | 40 | // at the call site instead of having a helper function here. |
| 39 | 41 | pub 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); | |
| 41 | 43 | if (reserved != 0) { |
| 42 | 44 | return error.InvalidHeader; |
| 43 | 45 | } |
| ... | ... | @@ -47,7 +49,7 @@ pub fn readAnyError(allocator: std.mem.Allocator, reader: anytype, max_size: u64 |
| 47 | 49 | else => |e| return e, |
| 48 | 50 | }; |
| 49 | 51 | |
| 50 | const num_images = try reader.readIntLittle(u16); | |
| 52 | const num_images = try reader.readInt(u16, .Little); | |
| 51 | 53 | |
| 52 | 54 | // To avoid over-allocation in the case of a file that says it has way more |
| 53 | 55 | // 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 |
| 66 | 68 | switch (image_type) { |
| 67 | 69 | .icon => { |
| 68 | 70 | 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), | |
| 71 | 73 | } }; |
| 72 | 74 | }, |
| 73 | 75 | .cursor => { |
| 74 | 76 | 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), | |
| 77 | 79 | } }; |
| 78 | 80 | }, |
| 79 | 81 | } |
| 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); | |
| 82 | 84 | // Validate that the offset/data size is feasible |
| 83 | 85 | if (@as(u64, entry.data_offset_from_start_of_file) + entry.data_size_in_bytes > max_size) { |
| 84 | 86 | return error.ImpossibleDataSize; |
| ... | ... | @@ -133,10 +135,10 @@ pub const IconDir = struct { |
| 133 | 135 | } |
| 134 | 136 | |
| 135 | 137 | 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); | |
| 138 | 140 | // 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); | |
| 140 | 142 | |
| 141 | 143 | var image_id = first_image_id; |
| 142 | 144 | for (self.entries) |entry| { |
| ... | ... | @@ -173,23 +175,23 @@ pub const Entry = struct { |
| 173 | 175 | pub fn writeResData(self: Entry, writer: anytype, id: u16) !void { |
| 174 | 176 | switch (self.type_specific_data) { |
| 175 | 177 | .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); | |
| 183 | 185 | }, |
| 184 | 186 | .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); | |
| 190 | 192 | }, |
| 191 | 193 | } |
| 192 | try writer.writeIntLittle(u16, id); | |
| 194 | try writer.writeInt(u16, id, .Little); | |
| 193 | 195 | } |
| 194 | 196 | }; |
| 195 | 197 | |
| ... | ... | @@ -235,21 +237,21 @@ pub const ImageFormat = enum { |
| 235 | 237 | png, |
| 236 | 238 | riff, |
| 237 | 239 | |
| 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); | |
| 242 | 244 | |
| 243 | 245 | 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; | |
| 246 | 248 | return .dib; |
| 247 | 249 | } |
| 248 | 250 | |
| 249 | 251 | pub fn validate(format: ImageFormat, header_bytes: *const [16]u8) bool { |
| 250 | 252 | 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, | |
| 253 | 255 | .dib => true, |
| 254 | 256 | }; |
| 255 | 257 | } |
src/resinator/res.zig+16-16| ... | ... | @@ -249,14 +249,14 @@ pub const NameOrOrdinal = union(enum) { |
| 249 | 249 | try writer.writeAll(std.mem.sliceAsBytes(name[0 .. name.len + 1])); |
| 250 | 250 | }, |
| 251 | 251 | .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); | |
| 254 | 254 | }, |
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | pub fn writeEmpty(writer: anytype) !void { |
| 259 | try writer.writeIntLittle(u16, 0); | |
| 259 | try writer.writeInt(u16, 0, .Little); | |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | pub fn fromString(allocator: Allocator, bytes: SourceBytes) !NameOrOrdinal { |
| ... | ... | @@ -963,19 +963,19 @@ pub const FixedFileInfo = struct { |
| 963 | 963 | }; |
| 964 | 964 | |
| 965 | 965 | 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); | |
| 979 | 979 | } |
| 980 | 980 | }; |
| 981 | 981 |
test/behavior/bugs/1851.zig+1| ... | ... | @@ -7,6 +7,7 @@ test "allocation and looping over 3-byte integer" { |
| 7 | 7 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 8 | 8 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 9 | 9 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 10 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; | |
| 10 | 11 | |
| 11 | 12 | if (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .macos) { |
| 12 | 13 | return error.SkipZigTest; // TODO |
test/behavior/struct.zig+2-1| ... | ... | @@ -1351,6 +1351,7 @@ test "under-aligned struct field" { |
| 1351 | 1351 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 1352 | 1352 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1353 | 1353 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
| 1354 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; | |
| 1354 | 1355 | |
| 1355 | 1356 | const U = extern union { |
| 1356 | 1357 | fd: i32, |
| ... | ... | @@ -1364,7 +1365,7 @@ test "under-aligned struct field" { |
| 1364 | 1365 | var runtime: usize = 1234; |
| 1365 | 1366 | const ptr = &S{ .events = 0, .data = .{ .u64 = runtime } }; |
| 1366 | 1367 | 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); | |
| 1368 | 1369 | try expect(result == 1234); |
| 1369 | 1370 | } |
| 1370 | 1371 |