diff --git a/deps/aro/Compilation.zig b/deps/aro/Compilation.zig index 66a47d6f4f..6f4b668407 100644 --- a/deps/aro/Compilation.zig +++ b/deps/aro/Compilation.zig @@ -402,7 +402,7 @@ pub fn generateBuiltinMacros(comp: *Compilation) !Source { \\#define __ORDER_PDP_ENDIAN__ 3412 \\ ); - if (comp.target.cpu.arch.endian() == .Little) try w.writeAll( + if (comp.target.cpu.arch.endian() == .little) try w.writeAll( \\#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ \\#define __LITTLE_ENDIAN__ 1 \\ diff --git a/deps/aro/target.zig b/deps/aro/target.zig index 14c698657d..fcdac57f6e 100644 --- a/deps/aro/target.zig +++ b/deps/aro/target.zig @@ -398,8 +398,8 @@ pub fn ldEmulationOption(target: std.Target, arm_endianness: ?std.builtin.Endian .thumb, .thumbeb, => switch (arm_endianness orelse target.cpu.arch.endian()) { - .Little => "armelf_linux_eabi", - .Big => "armelfb_linux_eabi", + .little => "armelf_linux_eabi", + .big => "armelfb_linux_eabi", }, .aarch64 => "aarch64linux", .aarch64_be => "aarch64linuxb", diff --git a/doc/langref.html.in b/doc/langref.html.in index 9d6c02df44..b3ae609a75 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -3376,11 +3376,11 @@ fn doTheTest() !void { var ordered: [2]u8 = @bitCast(full); switch (native_endian) { - .Big => { + .big => { try expect(ordered[0] == 0x12); try expect(ordered[1] == 0x34); }, - .Little => { + .little => { try expect(ordered[0] == 0x34); try expect(ordered[1] == 0x12); }, diff --git a/lib/compiler_rt/common.zig b/lib/compiler_rt/common.zig index eccd27e790..8dd8e71dcd 100644 --- a/lib/compiler_rt/common.zig +++ b/lib/compiler_rt/common.zig @@ -249,7 +249,7 @@ pub fn HalveInt(comptime T: type, comptime signed_half: bool) type { pub const HalfT = if (signed_half) HalfTS else HalfTU; all: T, - s: if (native_endian == .Little) + s: if (native_endian == .little) extern struct { low: HalfT, high: HalfT } else extern struct { high: HalfT, low: HalfT }, diff --git a/lib/compiler_rt/fmod.zig b/lib/compiler_rt/fmod.zig index 1eb7707c60..7c40298f32 100644 --- a/lib/compiler_rt/fmod.zig +++ b/lib/compiler_rt/fmod.zig @@ -142,16 +142,16 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 { const bPtr_u16: [*]u16 = @ptrCast(&bmod); const exp_and_sign_index = comptime switch (builtin.target.cpu.arch.endian()) { - .Little => 7, - .Big => 0, + .little => 7, + .big => 0, }; const low_index = comptime switch (builtin.target.cpu.arch.endian()) { - .Little => 0, - .Big => 1, + .little => 0, + .big => 1, }; const high_index = comptime switch (builtin.target.cpu.arch.endian()) { - .Little => 1, - .Big => 0, + .little => 1, + .big => 0, }; const signA = aPtr_u16[exp_and_sign_index] & 0x8000; diff --git a/lib/compiler_rt/udivmod.zig b/lib/compiler_rt/udivmod.zig index c9dd132b1b..1075cb0f31 100644 --- a/lib/compiler_rt/udivmod.zig +++ b/lib/compiler_rt/udivmod.zig @@ -5,8 +5,8 @@ const Log2Int = std.math.Log2Int; const HalveInt = @import("common.zig").HalveInt; const lo = switch (builtin.cpu.arch.endian()) { - .Big => 1, - .Little => 0, + .big => 1, + .little => 0, }; const hi = 1 - lo; diff --git a/lib/compiler_rt/udivmodei4.zig b/lib/compiler_rt/udivmodei4.zig index ff37a0cd27..064a3b842e 100644 --- a/lib/compiler_rt/udivmodei4.zig +++ b/lib/compiler_rt/udivmodei4.zig @@ -15,12 +15,12 @@ const endian = builtin.cpu.arch.endian(); /// Get the value of a limb. inline fn limb(x: []const u32, i: usize) u32 { - return if (endian == .Little) x[i] else x[x.len - 1 - i]; + return if (endian == .little) x[i] else x[x.len - 1 - i]; } /// Change the value of a limb. inline fn limb_set(x: []u32, i: usize, v: u32) void { - if (endian == .Little) { + if (endian == .little) { x[i] = v; } else { x[x.len - 1 - i] = v; diff --git a/lib/std/Build/Step/CheckObject.zig b/lib/std/Build/Step/CheckObject.zig index 45a5ea541f..66bf5cadf3 100644 --- a/lib/std/Build/Step/CheckObject.zig +++ b/lib/std/Build/Step/CheckObject.zig @@ -1624,8 +1624,8 @@ const WasmDumper = struct { switch (opcode) { .i32_const => try writer.print("i32.const {x}\n", .{try std.leb.readILEB128(i32, reader)}), .i64_const => try writer.print("i64.const {x}\n", .{try std.leb.readILEB128(i64, reader)}), - .f32_const => try writer.print("f32.const {x}\n", .{@as(f32, @bitCast(try reader.readInt(u32, .Little)))}), - .f64_const => try writer.print("f64.const {x}\n", .{@as(f64, @bitCast(try reader.readInt(u64, .Little)))}), + .f32_const => try writer.print("f32.const {x}\n", .{@as(f32, @bitCast(try reader.readInt(u32, .little)))}), + .f64_const => try writer.print("f64.const {x}\n", .{@as(f64, @bitCast(try reader.readInt(u64, .little)))}), .global_get => try writer.print("global.get {x}\n", .{try std.leb.readULEB128(u32, reader)}), else => unreachable, } diff --git a/lib/std/base64.zig b/lib/std/base64.zig index f0ad1d97bc..bca829de38 100644 --- a/lib/std/base64.zig +++ b/lib/std/base64.zig @@ -104,14 +104,14 @@ pub const Base64Encoder = struct { var idx: usize = 0; var out_idx: usize = 0; while (idx + 15 < source.len) : (idx += 12) { - const bits = std.mem.readInt(u128, source[idx..][0..16], .Big); + const bits = std.mem.readInt(u128, source[idx..][0..16], .big); inline for (0..16) |i| { dest[out_idx + i] = encoder.alphabet_chars[@truncate((bits >> (122 - i * 6)) & 0x3f)]; } out_idx += 16; } while (idx + 3 < source.len) : (idx += 3) { - const bits = std.mem.readInt(u32, source[idx..][0..4], .Big); + const bits = std.mem.readInt(u32, source[idx..][0..4], .big); dest[out_idx] = encoder.alphabet_chars[(bits >> 26) & 0x3f]; dest[out_idx + 1] = encoder.alphabet_chars[(bits >> 20) & 0x3f]; dest[out_idx + 2] = encoder.alphabet_chars[(bits >> 14) & 0x3f]; @@ -226,7 +226,7 @@ pub const Base64Decoder = struct { if ((new_bits & invalid_char_tst) != 0) return error.InvalidCharacter; bits |= (new_bits << (24 * i)); } - std.mem.writeInt(u128, dest[dest_idx..][0..16], bits, .Little); + std.mem.writeInt(u128, dest[dest_idx..][0..16], bits, .little); } while (fast_src_idx + 4 < source.len and dest_idx + 3 < dest.len) : ({ fast_src_idx += 4; @@ -237,7 +237,7 @@ pub const Base64Decoder = struct { bits |= decoder.fast_char_to_index[2][source[fast_src_idx + 2]]; bits |= decoder.fast_char_to_index[3][source[fast_src_idx + 3]]; if ((bits & invalid_char_tst) != 0) return error.InvalidCharacter; - std.mem.writeInt(u32, dest[dest_idx..][0..4], bits, .Little); + std.mem.writeInt(u32, dest[dest_idx..][0..4], bits, .little); } var remaining = source[fast_src_idx..]; for (remaining, fast_src_idx..) |c, src_idx| { diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index c83bfb4276..4042bc2743 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -450,8 +450,8 @@ pub const FloatMode = enum { /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. pub const Endian = enum { - Big, - Little, + big, + little, }; /// This data structure is used by the Zig language code generation and diff --git a/lib/std/child_process.zig b/lib/std/child_process.zig index ca1191398a..b3edbcd76a 100644 --- a/lib/std/child_process.zig +++ b/lib/std/child_process.zig @@ -1376,7 +1376,7 @@ fn writeIntFd(fd: i32, value: ErrInt) !void { .capable_io_mode = .blocking, .intended_io_mode = .blocking, }; - file.writer().writeInt(u64, @intCast(value), .Little) catch return error.SystemResources; + file.writer().writeInt(u64, @intCast(value), .little) catch return error.SystemResources; } fn readIntFd(fd: i32) !ErrInt { @@ -1385,7 +1385,7 @@ fn readIntFd(fd: i32) !ErrInt { .capable_io_mode = .blocking, .intended_io_mode = .blocking, }; - return @as(ErrInt, @intCast(file.reader().readInt(u64, .Little) catch return error.SystemResources)); + return @as(ErrInt, @intCast(file.reader().readInt(u64, .little) catch return error.SystemResources)); } /// Caller must free result. diff --git a/lib/std/coff.zig b/lib/std/coff.zig index 0a2f9c5210..b2bf09ef2a 100644 --- a/lib/std/coff.zig +++ b/lib/std/coff.zig @@ -663,7 +663,7 @@ pub const Symbol = struct { pub fn getNameOffset(self: Symbol) ?u32 { if (!std.mem.eql(u8, self.name[0..4], "\x00\x00\x00\x00")) return null; - const offset = std.mem.readInt(u32, self.name[4..8], .Little); + const offset = std.mem.readInt(u32, self.name[4..8], .little); return offset; } }; @@ -1075,7 +1075,7 @@ pub const Coff = struct { var stream = std.io.fixedBufferStream(data); const reader = stream.reader(); try stream.seekTo(pe_pointer_offset); - var coff_header_offset = try reader.readInt(u32, .Little); + var coff_header_offset = try reader.readInt(u32, .little); try stream.seekTo(coff_header_offset); var buf: [4]u8 = undefined; try reader.readNoEof(&buf); @@ -1142,7 +1142,7 @@ pub const Coff = struct { if (!mem.eql(u8, &cv_signature, "RSDS")) return error.InvalidPEMagic; try reader.readNoEof(self.guid[0..]); - self.age = try reader.readInt(u32, .Little); + self.age = try reader.readInt(u32, .little); // Finally read the null-terminated string. var byte = try reader.readByte(); @@ -1223,7 +1223,7 @@ pub const Coff = struct { if (coff_header.pointer_to_symbol_table == 0) return null; const offset = coff_header.pointer_to_symbol_table + Symbol.sizeOf() * coff_header.number_of_symbols; - const size = mem.readInt(u32, self.data[offset..][0..4], .Little); + const size = mem.readInt(u32, self.data[offset..][0..4], .little); if ((offset + size) > self.data.len) return error.InvalidStrtabSize; return Strtab{ .buffer = self.data[offset..][0..size] }; @@ -1324,9 +1324,9 @@ pub const Symtab = struct { fn asSymbol(raw: []const u8) Symbol { return .{ .name = raw[0..8].*, - .value = mem.readInt(u32, raw[8..12], .Little), - .section_number = @as(SectionNumber, @enumFromInt(mem.readInt(u16, raw[12..14], .Little))), - .type = @as(SymType, @bitCast(mem.readInt(u16, raw[14..16], .Little))), + .value = mem.readInt(u32, raw[8..12], .little), + .section_number = @as(SectionNumber, @enumFromInt(mem.readInt(u16, raw[12..14], .little))), + .type = @as(SymType, @bitCast(mem.readInt(u16, raw[14..16], .little))), .storage_class = @as(StorageClass, @enumFromInt(raw[16])), .number_of_aux_symbols = raw[17], }; @@ -1335,27 +1335,27 @@ pub const Symtab = struct { fn asDebugInfo(raw: []const u8) DebugInfoDefinition { return .{ .unused_1 = raw[0..4].*, - .linenumber = mem.readInt(u16, raw[4..6], .Little), + .linenumber = mem.readInt(u16, raw[4..6], .little), .unused_2 = raw[6..12].*, - .pointer_to_next_function = mem.readInt(u32, raw[12..16], .Little), + .pointer_to_next_function = mem.readInt(u32, raw[12..16], .little), .unused_3 = raw[16..18].*, }; } fn asFuncDef(raw: []const u8) FunctionDefinition { return .{ - .tag_index = mem.readInt(u32, raw[0..4], .Little), - .total_size = mem.readInt(u32, raw[4..8], .Little), - .pointer_to_linenumber = mem.readInt(u32, raw[8..12], .Little), - .pointer_to_next_function = mem.readInt(u32, raw[12..16], .Little), + .tag_index = mem.readInt(u32, raw[0..4], .little), + .total_size = mem.readInt(u32, raw[4..8], .little), + .pointer_to_linenumber = mem.readInt(u32, raw[8..12], .little), + .pointer_to_next_function = mem.readInt(u32, raw[12..16], .little), .unused = raw[16..18].*, }; } fn asWeakExtDef(raw: []const u8) WeakExternalDefinition { return .{ - .tag_index = mem.readInt(u32, raw[0..4], .Little), - .flag = @as(WeakExternalFlag, @enumFromInt(mem.readInt(u32, raw[4..8], .Little))), + .tag_index = mem.readInt(u32, raw[0..4], .little), + .flag = @as(WeakExternalFlag, @enumFromInt(mem.readInt(u32, raw[4..8], .little))), .unused = raw[8..18].*, }; } @@ -1368,11 +1368,11 @@ pub const Symtab = struct { fn asSectDef(raw: []const u8) SectionDefinition { return .{ - .length = mem.readInt(u32, raw[0..4], .Little), - .number_of_relocations = mem.readInt(u16, raw[4..6], .Little), - .number_of_linenumbers = mem.readInt(u16, raw[6..8], .Little), - .checksum = mem.readInt(u32, raw[8..12], .Little), - .number = mem.readInt(u16, raw[12..14], .Little), + .length = mem.readInt(u32, raw[0..4], .little), + .number_of_relocations = mem.readInt(u16, raw[4..6], .little), + .number_of_linenumbers = mem.readInt(u16, raw[6..8], .little), + .checksum = mem.readInt(u32, raw[8..12], .little), + .number = mem.readInt(u16, raw[12..14], .little), .selection = @as(ComdatSelection, @enumFromInt(raw[14])), .unused = raw[15..18].*, }; diff --git a/lib/std/compress/gzip.zig b/lib/std/compress/gzip.zig index 0b87411798..bb94687114 100644 --- a/lib/std/compress/gzip.zig +++ b/lib/std/compress/gzip.zig @@ -58,7 +58,7 @@ pub fn Decompress(comptime ReaderType: type) type { const FLG = header[3]; // Modification time, as a Unix timestamp. // If zero there's no timestamp available. - const MTIME = mem.readInt(u32, header[4..8], .Little); + const MTIME = mem.readInt(u32, header[4..8], .little); // Extra flags const XFL = header[8]; // Operating system where the compression took place @@ -66,7 +66,7 @@ pub fn Decompress(comptime ReaderType: type) type { _ = XFL; const extra = if (FLG & FEXTRA != 0) blk: { - const len = try hashed_reader.readInt(u16, .Little); + const len = try hashed_reader.readInt(u16, .little); const tmp_buf = try allocator.alloc(u8, len); errdefer allocator.free(tmp_buf); @@ -88,7 +88,7 @@ pub fn Decompress(comptime ReaderType: type) type { errdefer if (comment) |p| allocator.free(p); if (FLG & FHCRC != 0) { - const hash = try source.readInt(u16, .Little); + const hash = try source.readInt(u16, .little); if (hash != @as(u16, @truncate(hasher.hasher.final()))) return error.WrongChecksum; } @@ -133,12 +133,12 @@ pub fn Decompress(comptime ReaderType: type) type { } // We've reached the end of stream, check if the checksum matches - const hash = try self.in_reader.readInt(u32, .Little); + const hash = try self.in_reader.readInt(u32, .little); if (hash != self.hasher.final()) return error.WrongChecksum; // The ISIZE field is the size of the uncompressed input modulo 2^32 - const input_size = try self.in_reader.readInt(u32, .Little); + const input_size = try self.in_reader.readInt(u32, .little); if (self.read_amt & 0xffffffff != input_size) return error.CorruptedData; diff --git a/lib/std/compress/lzma/decode.zig b/lib/std/compress/lzma/decode.zig index e8062cc6d2..ec0619ba57 100644 --- a/lib/std/compress/lzma/decode.zig +++ b/lib/std/compress/lzma/decode.zig @@ -58,12 +58,12 @@ pub const Params = struct { props /= 5; const pb = @as(u3, @intCast(props)); - const dict_size_provided = try reader.readInt(u32, .Little); + const dict_size_provided = try reader.readInt(u32, .little); const dict_size = @max(0x1000, dict_size_provided); const unpacked_size = switch (options.unpacked_size) { .read_from_header => blk: { - const unpacked_size_provided = try reader.readInt(u64, .Little); + const unpacked_size_provided = try reader.readInt(u64, .little); const marker_mandatory = unpacked_size_provided == 0xFFFF_FFFF_FFFF_FFFF; break :blk if (marker_mandatory) null @@ -71,7 +71,7 @@ pub const Params = struct { unpacked_size_provided; }, .read_header_but_use_provided => |x| blk: { - _ = try reader.readInt(u64, .Little); + _ = try reader.readInt(u64, .little); break :blk x; }, .use_provided => |x| x, diff --git a/lib/std/compress/lzma/decode/rangecoder.zig b/lib/std/compress/lzma/decode/rangecoder.zig index b102639be0..515420a7d4 100644 --- a/lib/std/compress/lzma/decode/rangecoder.zig +++ b/lib/std/compress/lzma/decode/rangecoder.zig @@ -12,7 +12,7 @@ pub const RangeDecoder = struct { } return RangeDecoder{ .range = 0xFFFF_FFFF, - .code = try reader.readInt(u32, .Big), + .code = try reader.readInt(u32, .big), }; } diff --git a/lib/std/compress/lzma2/decode.zig b/lib/std/compress/lzma2/decode.zig index ba67782d86..938c2d437b 100644 --- a/lib/std/compress/lzma2/decode.zig +++ b/lib/std/compress/lzma2/decode.zig @@ -97,12 +97,12 @@ pub const Decoder = struct { const unpacked_size = blk: { var tmp: u64 = status & 0x1F; tmp <<= 16; - tmp |= try reader.readInt(u16, .Big); + tmp |= try reader.readInt(u16, .big); break :blk tmp + 1; }; const packed_size = blk: { - const tmp: u17 = try reader.readInt(u16, .Big); + const tmp: u17 = try reader.readInt(u16, .big); break :blk tmp + 1; }; @@ -155,7 +155,7 @@ pub const Decoder = struct { accum: *LzAccumBuffer, reset_dict: bool, ) !void { - const unpacked_size = @as(u17, try reader.readInt(u16, .Big)) + 1; + const unpacked_size = @as(u17, try reader.readInt(u16, .big)) + 1; if (reset_dict) { try accum.reset(writer); diff --git a/lib/std/compress/xz.zig b/lib/std/compress/xz.zig index 4515ed89dc..e844c234ff 100644 --- a/lib/std/compress/xz.zig +++ b/lib/std/compress/xz.zig @@ -12,7 +12,7 @@ pub const Check = enum(u4) { }; fn readStreamFlags(reader: anytype, check: *Check) !void { - var bit_reader = std.io.bitReader(.Little, reader); + var bit_reader = std.io.bitReader(.little, reader); const reserved1 = try bit_reader.readBitsNoEof(u8, 8); if (reserved1 != 0) @@ -52,7 +52,7 @@ pub fn Decompress(comptime ReaderType: type) type { break :blk hasher.hasher.final(); }; - const hash_b = try source.readInt(u32, .Little); + const hash_b = try source.readInt(u32, .little); if (hash_a != hash_b) return error.WrongChecksum; @@ -105,20 +105,20 @@ pub fn Decompress(comptime ReaderType: type) type { } const hash_a = hasher.hasher.final(); - const hash_b = try counting_reader.readInt(u32, .Little); + const hash_b = try counting_reader.readInt(u32, .little); if (hash_a != hash_b) return error.WrongChecksum; break :blk counter.bytes_read; }; - const hash_a = try self.in_reader.readInt(u32, .Little); + const hash_a = try self.in_reader.readInt(u32, .little); const hash_b = blk: { var hasher = std.compress.hashedReader(self.in_reader, Crc32.init()); const hashed_reader = hasher.reader(); - const backward_size = (@as(u64, try hashed_reader.readInt(u32, .Little)) + 1) * 4; + const backward_size = (@as(u64, try hashed_reader.readInt(u32, .little)) + 1) * 4; if (backward_size != index_size) return error.CorruptInput; diff --git a/lib/std/compress/xz/block.zig b/lib/std/compress/xz/block.zig index 640375988f..cd2c465dc5 100644 --- a/lib/std/compress/xz/block.zig +++ b/lib/std/compress/xz/block.zig @@ -148,7 +148,7 @@ pub fn Decoder(comptime ReaderType: type) type { } const hash_a = header_hasher.hasher.final(); - const hash_b = try header_reader.readInt(u32, .Little); + const hash_b = try header_reader.readInt(u32, .little); if (hash_a != hash_b) return error.WrongChecksum; } @@ -182,13 +182,13 @@ pub fn Decoder(comptime ReaderType: type) type { .none => {}, .crc32 => { const hash_a = Crc32.hash(unpacked_bytes); - const hash_b = try self.inner_reader.readInt(u32, .Little); + const hash_b = try self.inner_reader.readInt(u32, .little); if (hash_a != hash_b) return error.WrongChecksum; }, .crc64 => { const hash_a = Crc64.hash(unpacked_bytes); - const hash_b = try self.inner_reader.readInt(u64, .Little); + const hash_b = try self.inner_reader.readInt(u64, .little); if (hash_a != hash_b) return error.WrongChecksum; }, diff --git a/lib/std/compress/zlib.zig b/lib/std/compress/zlib.zig index a39c8bc3c3..6708875930 100644 --- a/lib/std/compress/zlib.zig +++ b/lib/std/compress/zlib.zig @@ -36,7 +36,7 @@ pub fn DecompressStream(comptime ReaderType: type) type { fn init(allocator: mem.Allocator, source: ReaderType) !Self { // Zlib header format is specified in RFC1950 - const header_u16 = try source.readInt(u16, .Big); + const header_u16 = try source.readInt(u16, .big); // verify the header checksum if (header_u16 % 31 != 0) @@ -81,7 +81,7 @@ pub fn DecompressStream(comptime ReaderType: type) type { } // We've reached the end of stream, check if the checksum matches - const hash = try self.in_reader.readInt(u32, .Big); + const hash = try self.in_reader.readInt(u32, .big); if (hash != self.hasher.final()) return error.WrongChecksum; @@ -132,7 +132,7 @@ pub fn CompressStream(comptime WriterType: type) type { }; header.checksum = @as(u5, @truncate(31 - @as(u16, @bitCast(header)) % 31)); - try dest.writeInt(u16, @as(u16, @bitCast(header)), .Big); + try dest.writeInt(u16, @as(u16, @bitCast(header)), .big); const compression_level: deflate.Compression = switch (options.level) { .no_compression => .no_compression, @@ -171,7 +171,7 @@ pub fn CompressStream(comptime WriterType: type) type { pub fn finish(self: *Self) !void { const hash = self.hasher.final(); try self.deflator.close(); - try self.in_writer.writeInt(u32, hash, .Big); + try self.in_writer.writeInt(u32, hash, .big); } }; } diff --git a/lib/std/compress/zstandard.zig b/lib/std/compress/zstandard.zig index 7376373adc..10eb878a1c 100644 --- a/lib/std/compress/zstandard.zig +++ b/lib/std/compress/zstandard.zig @@ -201,7 +201,7 @@ pub fn DecompressStream( if (block_header.last_block) { self.state = .LastBlock; if (self.frame_context.has_checksum) { - const checksum = source_reader.readInt(u32, .Little) catch + const checksum = source_reader.readInt(u32, .little) catch return error.MalformedFrame; if (comptime options.verify_checksum) { if (self.frame_context.hasher_opt) |*hasher| { diff --git a/lib/std/compress/zstandard/decode/block.zig b/lib/std/compress/zstandard/decode/block.zig index 184f453de4..36837a6b53 100644 --- a/lib/std/compress/zstandard/decode/block.zig +++ b/lib/std/compress/zstandard/decode/block.zig @@ -1029,9 +1029,9 @@ fn decodeStreams(size_format: u2, stream_data: []const u8) !LiteralsSection.Stre if (stream_data.len < 6) return error.MalformedLiteralsSection; - const stream_1_length: usize = std.mem.readInt(u16, stream_data[0..2], .Little); - const stream_2_length: usize = std.mem.readInt(u16, stream_data[2..4], .Little); - const stream_3_length: usize = std.mem.readInt(u16, stream_data[4..6], .Little); + const stream_1_length: usize = std.mem.readInt(u16, stream_data[0..2], .little); + const stream_2_length: usize = std.mem.readInt(u16, stream_data[2..4], .little); + const stream_3_length: usize = std.mem.readInt(u16, stream_data[4..6], .little); const stream_1_start = 6; const stream_2_start = stream_1_start + stream_1_length; diff --git a/lib/std/compress/zstandard/decompress.zig b/lib/std/compress/zstandard/decompress.zig index 65e0593ea7..c33d87379a 100644 --- a/lib/std/compress/zstandard/decompress.zig +++ b/lib/std/compress/zstandard/decompress.zig @@ -28,7 +28,7 @@ pub fn isSkippableMagic(magic: u32) bool { /// skippable frames. /// - `error.EndOfStream` if `source` contains fewer than 4 bytes pub fn decodeFrameType(source: anytype) error{ BadMagic, EndOfStream }!frame.Kind { - const magic = try source.readInt(u32, .Little); + const magic = try source.readInt(u32, .little); return frameType(magic); } @@ -62,14 +62,14 @@ pub const HeaderError = error{ BadMagic, EndOfStream, ReservedBitSet }; /// - `error.ReservedBitSet` if the frame is a Zstandard frame and any of the /// reserved bits are set pub fn decodeFrameHeader(source: anytype) (@TypeOf(source).Error || HeaderError)!FrameHeader { - const magic = try source.readInt(u32, .Little); + const magic = try source.readInt(u32, .little); const frame_type = try frameType(magic); switch (frame_type) { .zstandard => return FrameHeader{ .zstandard = try decodeZstandardHeader(source) }, .skippable => return FrameHeader{ .skippable = .{ .magic_number = magic, - .frame_size = try source.readInt(u32, .Little), + .frame_size = try source.readInt(u32, .little), }, }, } @@ -190,7 +190,7 @@ pub fn decodeFrame( switch (try decodeFrameType(fbs.reader())) { .zstandard => return decodeZstandardFrame(dest, src, verify_checksum), .skippable => { - const content_size = try fbs.reader().readInt(u32, .Little); + const content_size = try fbs.reader().readInt(u32, .little); if (content_size > std.math.maxInt(usize) - 8) return error.SkippableSizeTooLarge; const read_count = @as(usize, content_size) + 8; if (read_count > src.len) return error.SkippableSizeTooLarge; @@ -235,7 +235,7 @@ pub fn decodeFrameArrayList( ) (error{ BadMagic, OutOfMemory, SkippableSizeTooLarge } || FrameContext.Error || FrameError)!usize { var fbs = std.io.fixedBufferStream(src); const reader = fbs.reader(); - const magic = try reader.readInt(u32, .Little); + const magic = try reader.readInt(u32, .little); switch (try frameType(magic)) { .zstandard => return decodeZstandardFrameArrayList( allocator, @@ -245,7 +245,7 @@ pub fn decodeFrameArrayList( window_size_max, ), .skippable => { - const content_size = try fbs.reader().readInt(u32, .Little); + const content_size = try fbs.reader().readInt(u32, .little); if (content_size > std.math.maxInt(usize) - 8) return error.SkippableSizeTooLarge; const read_count = @as(usize, content_size) + 8; if (read_count > src.len) return error.SkippableSizeTooLarge; @@ -299,7 +299,7 @@ pub fn decodeZstandardFrame( WindowSizeUnknown, DictionaryIdFlagUnsupported, } || FrameError)!ReadWriteCount { - assert(std.mem.readInt(u32, src[0..4], .Little) == frame.Zstandard.magic_number); + assert(std.mem.readInt(u32, src[0..4], .little) == frame.Zstandard.magic_number); var consumed_count: usize = 4; var frame_context = context: { @@ -351,7 +351,7 @@ pub fn decodeZStandardFrameBlocks( if (written_count != content_size) return error.BadContentSize; if (frame_context.has_checksum) { if (src.len < consumed_count + 4) return error.EndOfStream; - const checksum = std.mem.readInt(u32, src[consumed_count..][0..4], .Little); + const checksum = std.mem.readInt(u32, src[consumed_count..][0..4], .little); consumed_count += 4; if (frame_context.hasher_opt) |*hasher| { if (checksum != computeChecksum(hasher)) return error.ChecksumFailure; @@ -442,7 +442,7 @@ pub fn decodeZstandardFrameArrayList( verify_checksum: bool, window_size_max: usize, ) (error{OutOfMemory} || FrameContext.Error || FrameError)!usize { - assert(std.mem.readInt(u32, src[0..4], .Little) == frame.Zstandard.magic_number); + assert(std.mem.readInt(u32, src[0..4], .little) == frame.Zstandard.magic_number); var consumed_count: usize = 4; var frame_context = context: { @@ -517,7 +517,7 @@ pub fn decodeZstandardFrameBlocksArrayList( if (frame_context.has_checksum) { if (src.len < consumed_count + 4) return error.EndOfStream; - const checksum = std.mem.readInt(u32, src[consumed_count..][0..4], .Little); + const checksum = std.mem.readInt(u32, src[consumed_count..][0..4], .little); consumed_count += 4; if (frame_context.hasher_opt) |*hasher| { if (checksum != computeChecksum(hasher)) return error.ChecksumFailure; @@ -566,9 +566,9 @@ fn decodeFrameBlocksInner( /// Decode the header of a skippable frame. The first four bytes of `src` must /// be a valid magic number for a skippable frame. pub fn decodeSkippableHeader(src: *const [8]u8) SkippableHeader { - const magic = std.mem.readInt(u32, src[0..4], .Little); + const magic = std.mem.readInt(u32, src[0..4], .little); assert(isSkippableMagic(magic)); - const frame_size = std.mem.readInt(u32, src[4..8], .Little); + const frame_size = std.mem.readInt(u32, src[4..8], .little); return .{ .magic_number = magic, .frame_size = frame_size, @@ -609,13 +609,13 @@ pub fn decodeZstandardHeader( if (descriptor.dictionary_id_flag > 0) { // if flag is 3 then field_size = 4, else field_size = flag const field_size = (@as(u4, 1) << descriptor.dictionary_id_flag) >> 1; - dictionary_id = try source.readVarInt(u32, .Little, field_size); + dictionary_id = try source.readVarInt(u32, .little, field_size); } var content_size: ?u64 = null; if (descriptor.single_segment_flag or descriptor.content_size_flag > 0) { const field_size = @as(u4, 1) << descriptor.content_size_flag; - content_size = try source.readVarInt(u64, .Little, field_size); + content_size = try source.readVarInt(u64, .little, field_size); if (field_size == 2) content_size.? += 256; } diff --git a/lib/std/compress/zstandard/readers.zig b/lib/std/compress/zstandard/readers.zig index e2f62ddc51..f95573f77b 100644 --- a/lib/std/compress/zstandard/readers.zig +++ b/lib/std/compress/zstandard/readers.zig @@ -31,11 +31,11 @@ pub const ReversedByteReader = struct { /// FSE compressed data. pub const ReverseBitReader = struct { byte_reader: ReversedByteReader, - bit_reader: std.io.BitReader(.Big, ReversedByteReader.Reader), + bit_reader: std.io.BitReader(.big, ReversedByteReader.Reader), pub fn init(self: *ReverseBitReader, bytes: []const u8) error{BitStreamHasNoStartBit}!void { self.byte_reader = ReversedByteReader.init(bytes); - self.bit_reader = std.io.bitReader(.Big, self.byte_reader.reader()); + self.bit_reader = std.io.bitReader(.big, self.byte_reader.reader()); if (bytes.len == 0) return; var i: usize = 0; while (i < 8 and 0 == self.readBitsNoEof(u1, 1) catch unreachable) : (i += 1) {} @@ -61,7 +61,7 @@ pub const ReverseBitReader = struct { pub fn BitReader(comptime Reader: type) type { return struct { - underlying: std.io.BitReader(.Little, Reader), + underlying: std.io.BitReader(.little, Reader), pub fn readBitsNoEof(self: *@This(), comptime U: type, num_bits: usize) !U { return self.underlying.readBitsNoEof(U, num_bits); @@ -78,5 +78,5 @@ pub fn BitReader(comptime Reader: type) type { } pub fn bitReader(reader: anytype) BitReader(@TypeOf(reader)) { - return .{ .underlying = std.io.bitReader(.Little, reader) }; + return .{ .underlying = std.io.bitReader(.little, reader) }; } diff --git a/lib/std/crypto/25519/field.zig b/lib/std/crypto/25519/field.zig index 389a8084cd..401616f1b8 100644 --- a/lib/std/crypto/25519/field.zig +++ b/lib/std/crypto/25519/field.zig @@ -71,11 +71,11 @@ pub const Fe = struct { /// Unpack a field element pub fn fromBytes(s: [32]u8) Fe { var fe: Fe = undefined; - fe.limbs[0] = std.mem.readInt(u64, s[0..8], .Little) & MASK51; - fe.limbs[1] = (std.mem.readInt(u64, s[6..14], .Little) >> 3) & MASK51; - fe.limbs[2] = (std.mem.readInt(u64, s[12..20], .Little) >> 6) & MASK51; - fe.limbs[3] = (std.mem.readInt(u64, s[19..27], .Little) >> 1) & MASK51; - fe.limbs[4] = (std.mem.readInt(u64, s[24..32], .Little) >> 12) & MASK51; + fe.limbs[0] = std.mem.readInt(u64, s[0..8], .little) & MASK51; + fe.limbs[1] = (std.mem.readInt(u64, s[6..14], .little) >> 3) & MASK51; + fe.limbs[2] = (std.mem.readInt(u64, s[12..20], .little) >> 6) & MASK51; + fe.limbs[3] = (std.mem.readInt(u64, s[19..27], .little) >> 1) & MASK51; + fe.limbs[4] = (std.mem.readInt(u64, s[24..32], .little) >> 12) & MASK51; return fe; } @@ -85,10 +85,10 @@ pub const Fe = struct { var reduced = fe; reduced.reduce(); var s: [32]u8 = undefined; - std.mem.writeInt(u64, s[0..8], reduced.limbs[0] | (reduced.limbs[1] << 51), .Little); - std.mem.writeInt(u64, s[8..16], (reduced.limbs[1] >> 13) | (reduced.limbs[2] << 38), .Little); - std.mem.writeInt(u64, s[16..24], (reduced.limbs[2] >> 26) | (reduced.limbs[3] << 25), .Little); - std.mem.writeInt(u64, s[24..32], (reduced.limbs[3] >> 39) | (reduced.limbs[4] << 12), .Little); + std.mem.writeInt(u64, s[0..8], reduced.limbs[0] | (reduced.limbs[1] << 51), .little); + std.mem.writeInt(u64, s[8..16], (reduced.limbs[1] >> 13) | (reduced.limbs[2] << 38), .little); + std.mem.writeInt(u64, s[16..24], (reduced.limbs[2] >> 26) | (reduced.limbs[3] << 25), .little); + std.mem.writeInt(u64, s[24..32], (reduced.limbs[3] >> 39) | (reduced.limbs[4] << 12), .little); return s; } diff --git a/lib/std/crypto/25519/scalar.zig b/lib/std/crypto/25519/scalar.zig index cf18c7cedd..e7e74bf618 100644 --- a/lib/std/crypto/25519/scalar.zig +++ b/lib/std/crypto/25519/scalar.zig @@ -15,7 +15,7 @@ pub const zero = [_]u8{0} ** 32; const field_order_s = s: { var s: [32]u8 = undefined; - mem.writeInt(u256, &s, field_order, .Little); + mem.writeInt(u256, &s, field_order, .little); break :s s; }; @@ -127,9 +127,9 @@ pub const Scalar = struct { var bytes: CompressedScalar = undefined; var i: usize = 0; while (i < 4) : (i += 1) { - mem.writeInt(u64, bytes[i * 7 ..][0..8], expanded.limbs[i], .Little); + mem.writeInt(u64, bytes[i * 7 ..][0..8], expanded.limbs[i], .little); } - mem.writeInt(u32, bytes[i * 7 ..][0..4], @intCast(expanded.limbs[i]), .Little); + mem.writeInt(u32, bytes[i * 7 ..][0..4], @intCast(expanded.limbs[i]), .little); return bytes; } @@ -580,7 +580,7 @@ const ScalarDouble = struct { var limbs: Limbs = undefined; var i: usize = 0; while (i < 9) : (i += 1) { - limbs[i] = mem.readInt(u64, bytes[i * 7 ..][0..8], .Little) & 0xffffffffffffff; + limbs[i] = mem.readInt(u64, bytes[i * 7 ..][0..8], .little) & 0xffffffffffffff; } limbs[i] = @as(u64, bytes[i * 7]); return ScalarDouble{ .limbs = limbs }; @@ -590,9 +590,9 @@ const ScalarDouble = struct { var limbs: Limbs = undefined; var i: usize = 0; while (i < 4) : (i += 1) { - limbs[i] = mem.readInt(u64, bytes[i * 7 ..][0..8], .Little) & 0xffffffffffffff; + limbs[i] = mem.readInt(u64, bytes[i * 7 ..][0..8], .little) & 0xffffffffffffff; } - limbs[i] = @as(u64, mem.readInt(u32, bytes[i * 7 ..][0..4], .Little)); + limbs[i] = @as(u64, mem.readInt(u32, bytes[i * 7 ..][0..4], .little)); @memset(limbs[5..], 0); return ScalarDouble{ .limbs = limbs }; } diff --git a/lib/std/crypto/Certificate.zig b/lib/std/crypto/Certificate.zig index 1b1d4812d3..b7d24de0d6 100644 --- a/lib/std/crypto/Certificate.zig +++ b/lib/std/crypto/Certificate.zig @@ -1075,7 +1075,7 @@ pub const rsa = struct { // Reject modulus below 512 bits. // 512-bit RSA was factored in 1999, so this limit barely means anything, // but establish some limit now to ratchet in what we can. - const _n = Modulus.fromBytes(modulus_bytes, .Big) catch return error.CertificatePublicKeyInvalid; + const _n = Modulus.fromBytes(modulus_bytes, .big) catch return error.CertificatePublicKeyInvalid; if (_n.bits() < 512) return error.CertificatePublicKeyInvalid; // Exponent must be odd and greater than 2. @@ -1085,7 +1085,7 @@ pub const rsa = struct { // Windows commonly does. // [1] https://learn.microsoft.com/en-us/windows/win32/api/wincrypt/ns-wincrypt-rsapubkey if (pub_bytes.len > 4) return error.CertificatePublicKeyInvalid; - const _e = Fe.fromBytes(_n, pub_bytes, .Big) catch return error.CertificatePublicKeyInvalid; + const _e = Fe.fromBytes(_n, pub_bytes, .big) catch return error.CertificatePublicKeyInvalid; if (!_e.isOdd()) return error.CertificatePublicKeyInvalid; const e_v = _e.toPrimitive(u32) catch return error.CertificatePublicKeyInvalid; if (e_v < 2) return error.CertificatePublicKeyInvalid; @@ -1116,10 +1116,10 @@ pub const rsa = struct { }; fn encrypt(comptime modulus_len: usize, msg: [modulus_len]u8, public_key: PublicKey) ![modulus_len]u8 { - const m = Fe.fromBytes(public_key.n, &msg, .Big) catch return error.MessageTooLong; + const m = Fe.fromBytes(public_key.n, &msg, .big) catch return error.MessageTooLong; const e = public_key.n.powPublic(m, public_key.e) catch unreachable; var res: [modulus_len]u8 = undefined; - e.toBytes(&res, .Big) catch unreachable; + e.toBytes(&res, .big) catch unreachable; return res; } }; diff --git a/lib/std/crypto/Certificate/Bundle/macos.zig b/lib/std/crypto/Certificate/Bundle/macos.zig index 3814fd421f..860c1599e4 100644 --- a/lib/std/crypto/Certificate/Bundle/macos.zig +++ b/lib/std/crypto/Certificate/Bundle/macos.zig @@ -32,7 +32,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void { var table_idx: u32 = 0; while (table_idx < table_list.len) : (table_idx += 1) { - table_list[table_idx] = try reader.readInt(u32, .Big); + table_list[table_idx] = try reader.readInt(u32, .big); } const now_sec = std.time.timestamp(); @@ -51,7 +51,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void { var record_idx: u32 = 0; while (record_idx < record_list.len) : (record_idx += 1) { - record_list[record_idx] = try reader.readInt(u32, .Big); + record_list[record_idx] = try reader.readInt(u32, .big); } for (record_list) |record_offset| { diff --git a/lib/std/crypto/aegis.zig b/lib/std/crypto/aegis.zig index f6b6864936..9aff9f0776 100644 --- a/lib/std/crypto/aegis.zig +++ b/lib/std/crypto/aegis.zig @@ -106,8 +106,8 @@ const State128L = struct { fn mac(state: *State128L, comptime tag_bits: u9, adlen: usize, mlen: usize) [tag_bits / 8]u8 { const blocks = &state.blocks; var sizes: [16]u8 = undefined; - mem.writeInt(u64, sizes[0..8], adlen * 8, .Little); - mem.writeInt(u64, sizes[8..16], mlen * 8, .Little); + mem.writeInt(u64, sizes[0..8], adlen * 8, .little); + mem.writeInt(u64, sizes[8..16], mlen * 8, .little); const tmp = AesBlock.fromBytes(&sizes).xorBlocks(blocks[2]); var i: usize = 0; while (i < 7) : (i += 1) { @@ -284,8 +284,8 @@ const State256 = struct { fn mac(state: *State256, comptime tag_bits: u9, adlen: usize, mlen: usize) [tag_bits / 8]u8 { const blocks = &state.blocks; var sizes: [16]u8 = undefined; - mem.writeInt(u64, sizes[0..8], adlen * 8, .Little); - mem.writeInt(u64, sizes[8..16], mlen * 8, .Little); + mem.writeInt(u64, sizes[0..8], adlen * 8, .little); + mem.writeInt(u64, sizes[8..16], mlen * 8, .little); const tmp = AesBlock.fromBytes(&sizes).xorBlocks(blocks[3]); var i: usize = 0; while (i < 7) : (i += 1) { diff --git a/lib/std/crypto/aes.zig b/lib/std/crypto/aes.zig index fb3246b0a0..c4f709d631 100644 --- a/lib/std/crypto/aes.zig +++ b/lib/std/crypto/aes.zig @@ -50,7 +50,7 @@ test "ctr" { var out: [exp_out.len]u8 = undefined; var ctx = Aes128.initEnc(key); - ctr(AesEncryptCtx(Aes128), ctx, out[0..], in[0..], iv, std.builtin.Endian.Big); + ctr(AesEncryptCtx(Aes128), ctx, out[0..], in[0..], iv, std.builtin.Endian.big); try testing.expectEqualSlices(u8, exp_out[0..], out[0..]); } diff --git a/lib/std/crypto/aes/soft.zig b/lib/std/crypto/aes/soft.zig index e1fa201c9c..9e7af0606d 100644 --- a/lib/std/crypto/aes/soft.zig +++ b/lib/std/crypto/aes/soft.zig @@ -15,20 +15,20 @@ pub const Block = struct { /// Convert a byte sequence into an internal representation. pub inline fn fromBytes(bytes: *const [16]u8) Block { - const s0 = mem.readInt(u32, bytes[0..4], .Little); - const s1 = mem.readInt(u32, bytes[4..8], .Little); - const s2 = mem.readInt(u32, bytes[8..12], .Little); - const s3 = mem.readInt(u32, bytes[12..16], .Little); + const s0 = mem.readInt(u32, bytes[0..4], .little); + const s1 = mem.readInt(u32, bytes[4..8], .little); + const s2 = mem.readInt(u32, bytes[8..12], .little); + const s3 = mem.readInt(u32, bytes[12..16], .little); return Block{ .repr = BlockVec{ s0, s1, s2, s3 } }; } /// Convert the internal representation of a block into a byte sequence. pub inline fn toBytes(block: Block) [16]u8 { var bytes: [16]u8 = undefined; - mem.writeInt(u32, bytes[0..4], block.repr[0], .Little); - mem.writeInt(u32, bytes[4..8], block.repr[1], .Little); - mem.writeInt(u32, bytes[8..12], block.repr[2], .Little); - mem.writeInt(u32, bytes[12..16], block.repr[3], .Little); + mem.writeInt(u32, bytes[0..4], block.repr[0], .little); + mem.writeInt(u32, bytes[4..8], block.repr[1], .little); + mem.writeInt(u32, bytes[8..12], block.repr[2], .little); + mem.writeInt(u32, bytes[12..16], block.repr[3], .little); return bytes; } @@ -123,13 +123,13 @@ pub const Block = struct { // Last round uses s-box directly and XORs to produce output. var x: [4]u8 = undefined; x = sbox_lookup(&sbox_encrypt, @as(u8, @truncate(s0)), @as(u8, @truncate(s1 >> 8)), @as(u8, @truncate(s2 >> 16)), @as(u8, @truncate(s3 >> 24))); - var t0 = mem.readInt(u32, &x, .Little); + var t0 = mem.readInt(u32, &x, .little); x = sbox_lookup(&sbox_encrypt, @as(u8, @truncate(s1)), @as(u8, @truncate(s2 >> 8)), @as(u8, @truncate(s3 >> 16)), @as(u8, @truncate(s0 >> 24))); - var t1 = mem.readInt(u32, &x, .Little); + var t1 = mem.readInt(u32, &x, .little); x = sbox_lookup(&sbox_encrypt, @as(u8, @truncate(s2)), @as(u8, @truncate(s3 >> 8)), @as(u8, @truncate(s0 >> 16)), @as(u8, @truncate(s1 >> 24))); - var t2 = mem.readInt(u32, &x, .Little); + var t2 = mem.readInt(u32, &x, .little); x = sbox_lookup(&sbox_encrypt, @as(u8, @truncate(s3)), @as(u8, @truncate(s0 >> 8)), @as(u8, @truncate(s1 >> 16)), @as(u8, @truncate(s2 >> 24))); - var t3 = mem.readInt(u32, &x, .Little); + var t3 = mem.readInt(u32, &x, .little); t0 ^= round_key.repr[0]; t1 ^= round_key.repr[1]; @@ -219,13 +219,13 @@ pub const Block = struct { // Last round uses s-box directly and XORs to produce output. var x: [4]u8 = undefined; x = sbox_lookup(&sbox_decrypt, @as(u8, @truncate(s0)), @as(u8, @truncate(s3 >> 8)), @as(u8, @truncate(s2 >> 16)), @as(u8, @truncate(s1 >> 24))); - var t0 = mem.readInt(u32, &x, .Little); + var t0 = mem.readInt(u32, &x, .little); x = sbox_lookup(&sbox_decrypt, @as(u8, @truncate(s1)), @as(u8, @truncate(s0 >> 8)), @as(u8, @truncate(s3 >> 16)), @as(u8, @truncate(s2 >> 24))); - var t1 = mem.readInt(u32, &x, .Little); + var t1 = mem.readInt(u32, &x, .little); x = sbox_lookup(&sbox_decrypt, @as(u8, @truncate(s2)), @as(u8, @truncate(s1 >> 8)), @as(u8, @truncate(s0 >> 16)), @as(u8, @truncate(s3 >> 24))); - var t2 = mem.readInt(u32, &x, .Little); + var t2 = mem.readInt(u32, &x, .little); x = sbox_lookup(&sbox_decrypt, @as(u8, @truncate(s3)), @as(u8, @truncate(s2 >> 8)), @as(u8, @truncate(s1 >> 16)), @as(u8, @truncate(s0 >> 24))); - var t3 = mem.readInt(u32, &x, .Little); + var t3 = mem.readInt(u32, &x, .little); t0 ^= round_key.repr[0]; t1 ^= round_key.repr[1]; @@ -349,14 +349,14 @@ fn KeySchedule(comptime Aes: type) type { // Apply sbox_encrypt to each byte in w. fn func(w: u32) u32 { 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))); - return mem.readInt(u32, &x, .Little); + return mem.readInt(u32, &x, .little); } }.func; var round_keys: [rounds + 1]Block = undefined; comptime var i: usize = 0; inline while (i < words_in_key) : (i += 1) { - round_keys[i / 4].repr[i % 4] = mem.readInt(u32, key[4 * i ..][0..4], .Big); + round_keys[i / 4].repr[i % 4] = mem.readInt(u32, key[4 * i ..][0..4], .big); } inline while (i < round_keys.len * 4) : (i += 1) { var t = round_keys[(i - 1) / 4].repr[(i - 1) % 4]; diff --git a/lib/std/crypto/aes_gcm.zig b/lib/std/crypto/aes_gcm.zig index 5545d1c0e8..e276c9dfd8 100644 --- a/lib/std/crypto/aes_gcm.zig +++ b/lib/std/crypto/aes_gcm.zig @@ -33,7 +33,7 @@ fn AesGcm(comptime Aes: anytype) type { var t: [16]u8 = undefined; var j: [16]u8 = undefined; j[0..nonce_length].* = npub; - mem.writeInt(u32, j[nonce_length..][0..4], 1, .Big); + mem.writeInt(u32, j[nonce_length..][0..4], 1, .big); aes.encrypt(&t, &j); 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 { mac.update(ad); mac.pad(); - mem.writeInt(u32, j[nonce_length..][0..4], 2, .Big); - modes.ctr(@TypeOf(aes), aes, c, m, j, std.builtin.Endian.Big); + mem.writeInt(u32, j[nonce_length..][0..4], 2, .big); + modes.ctr(@TypeOf(aes), aes, c, m, j, std.builtin.Endian.big); mac.update(c[0..m.len][0..]); mac.pad(); var final_block = h; - mem.writeInt(u64, final_block[0..8], ad.len * 8, .Big); - mem.writeInt(u64, final_block[8..16], m.len * 8, .Big); + mem.writeInt(u64, final_block[0..8], ad.len * 8, .big); + mem.writeInt(u64, final_block[8..16], m.len * 8, .big); mac.update(&final_block); mac.final(tag); for (t, 0..) |x, i| { @@ -75,7 +75,7 @@ fn AesGcm(comptime Aes: anytype) type { var t: [16]u8 = undefined; var j: [16]u8 = undefined; j[0..nonce_length].* = npub; - mem.writeInt(u32, j[nonce_length..][0..4], 1, .Big); + mem.writeInt(u32, j[nonce_length..][0..4], 1, .big); aes.encrypt(&t, &j); 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 { mac.pad(); var final_block = h; - mem.writeInt(u64, final_block[0..8], ad.len * 8, .Big); - mem.writeInt(u64, final_block[8..16], m.len * 8, .Big); + mem.writeInt(u64, final_block[0..8], ad.len * 8, .big); + mem.writeInt(u64, final_block[8..16], m.len * 8, .big); mac.update(&final_block); var computed_tag: [Ghash.mac_length]u8 = undefined; mac.final(&computed_tag); @@ -103,8 +103,8 @@ fn AesGcm(comptime Aes: anytype) type { return error.AuthenticationFailed; } - mem.writeInt(u32, j[nonce_length..][0..4], 2, .Big); - modes.ctr(@TypeOf(aes), aes, m, c, j, std.builtin.Endian.Big); + mem.writeInt(u32, j[nonce_length..][0..4], 2, .big); + modes.ctr(@TypeOf(aes), aes, m, c, j, std.builtin.Endian.big); } }; } diff --git a/lib/std/crypto/aes_ocb.zig b/lib/std/crypto/aes_ocb.zig index 65162c01ee..05353a3c82 100644 --- a/lib/std/crypto/aes_ocb.zig +++ b/lib/std/crypto/aes_ocb.zig @@ -29,10 +29,10 @@ fn AesOcb(comptime Aes: anytype) type { upto: usize, inline fn double(l: Block) Block { - const l_ = mem.readInt(u128, &l, .Big); + const l_ = mem.readInt(u128, &l, .big); const l_2 = (l_ << 1) ^ (0x87 & -%(l_ >> 127)); var l2: Block = undefined; - mem.writeInt(u128, &l2, l_2, .Big); + mem.writeInt(u128, &l2, l_2, .big); return l2; } @@ -94,10 +94,10 @@ fn AesOcb(comptime Aes: anytype) type { nx[15] &= 0xc0; var ktop_: Block = undefined; aes_enc_ctx.encrypt(&ktop_, &nx); - const ktop = mem.readInt(u128, &ktop_, .Big); + const ktop = mem.readInt(u128, &ktop_, .big); var stretch = (@as(u192, ktop) << 64) | @as(u192, @as(u64, @truncate(ktop >> 64)) ^ @as(u64, @truncate(ktop >> 56))); var offset: Block = undefined; - mem.writeInt(u128, &offset, @as(u128, @truncate(stretch >> (64 - @as(u7, bottom)))), .Big); + mem.writeInt(u128, &offset, @as(u128, @truncate(stretch >> (64 - @as(u7, bottom)))), .big); return offset; } diff --git a/lib/std/crypto/argon2.zig b/lib/std/crypto/argon2.zig index 09835011c7..500bebd09c 100644 --- a/lib/std/crypto/argon2.zig +++ b/lib/std/crypto/argon2.zig @@ -110,27 +110,27 @@ fn initHash( var parameters: [24]u8 = undefined; var tmp: [4]u8 = undefined; var b2 = Blake2b512.init(.{}); - mem.writeInt(u32, parameters[0..4], params.p, .Little); - mem.writeInt(u32, parameters[4..8], @as(u32, @intCast(dk_len)), .Little); - mem.writeInt(u32, parameters[8..12], params.m, .Little); - mem.writeInt(u32, parameters[12..16], params.t, .Little); - mem.writeInt(u32, parameters[16..20], version, .Little); - mem.writeInt(u32, parameters[20..24], @intFromEnum(mode), .Little); + mem.writeInt(u32, parameters[0..4], params.p, .little); + mem.writeInt(u32, parameters[4..8], @as(u32, @intCast(dk_len)), .little); + mem.writeInt(u32, parameters[8..12], params.m, .little); + mem.writeInt(u32, parameters[12..16], params.t, .little); + mem.writeInt(u32, parameters[16..20], version, .little); + mem.writeInt(u32, parameters[20..24], @intFromEnum(mode), .little); b2.update(¶meters); - mem.writeInt(u32, &tmp, @as(u32, @intCast(password.len)), .Little); + mem.writeInt(u32, &tmp, @as(u32, @intCast(password.len)), .little); b2.update(&tmp); b2.update(password); - mem.writeInt(u32, &tmp, @as(u32, @intCast(salt.len)), .Little); + mem.writeInt(u32, &tmp, @as(u32, @intCast(salt.len)), .little); b2.update(&tmp); b2.update(salt); const secret = params.secret orelse ""; std.debug.assert(secret.len <= max_int); - mem.writeInt(u32, &tmp, @as(u32, @intCast(secret.len)), .Little); + mem.writeInt(u32, &tmp, @as(u32, @intCast(secret.len)), .little); b2.update(&tmp); b2.update(secret); const ad = params.ad orelse ""; std.debug.assert(ad.len <= max_int); - mem.writeInt(u32, &tmp, @as(u32, @intCast(ad.len)), .Little); + mem.writeInt(u32, &tmp, @as(u32, @intCast(ad.len)), .little); b2.update(&tmp); b2.update(ad); b2.final(h0[0..Blake2b512.digest_length]); @@ -140,7 +140,7 @@ fn initHash( fn blake2bLong(out: []u8, in: []const u8) void { const H = Blake2b512; var outlen_bytes: [4]u8 = undefined; - mem.writeInt(u32, &outlen_bytes, @as(u32, @intCast(out.len)), .Little); + mem.writeInt(u32, &outlen_bytes, @as(u32, @intCast(out.len)), .little); var out_buf: [H.digest_length]u8 = undefined; @@ -183,18 +183,18 @@ fn initBlocks( var lane: u24 = 0; while (lane < threads) : (lane += 1) { const j = lane * (memory / threads); - mem.writeInt(u32, h0[Blake2b512.digest_length + 4 ..][0..4], lane, .Little); + mem.writeInt(u32, h0[Blake2b512.digest_length + 4 ..][0..4], lane, .little); - mem.writeInt(u32, h0[Blake2b512.digest_length..][0..4], 0, .Little); + mem.writeInt(u32, h0[Blake2b512.digest_length..][0..4], 0, .little); blake2bLong(&block0, h0); for (&blocks.items[j + 0], 0..) |*v, i| { - v.* = mem.readInt(u64, block0[i * 8 ..][0..8], .Little); + v.* = mem.readInt(u64, block0[i * 8 ..][0..8], .little); } - mem.writeInt(u32, h0[Blake2b512.digest_length..][0..4], 1, .Little); + mem.writeInt(u32, h0[Blake2b512.digest_length..][0..4], 1, .little); blake2bLong(&block0, h0); for (&blocks.items[j + 1], 0..) |*v, i| { - v.* = mem.readInt(u64, block0[i * 8 ..][0..8], .Little); + v.* = mem.readInt(u64, block0[i * 8 ..][0..8], .little); } } } @@ -433,7 +433,7 @@ fn finalize( } var block: [1024]u8 = undefined; for (blocks.items[memory - 1], 0..) |v, i| { - mem.writeInt(u64, block[i * 8 ..][0..8], v, .Little); + mem.writeInt(u64, block[i * 8 ..][0..8], v, .little); } blake2bLong(out, &block); } diff --git a/lib/std/crypto/ascon.zig b/lib/std/crypto/ascon.zig index 673359ad80..521f9c922e 100644 --- a/lib/std/crypto/ascon.zig +++ b/lib/std/crypto/ascon.zig @@ -96,8 +96,8 @@ pub fn State(comptime endian: std.builtin.Endian) type { /// XOR a byte into the state at a given offset. pub fn addByte(self: *Self, byte: u8, offset: usize) void { const z = switch (endian) { - .Big => 64 - 8 - 8 * @as(u6, @truncate(offset % 8)), - .Little => 8 * @as(u6, @truncate(offset % 8)), + .big => 64 - 8 - 8 * @as(u6, @truncate(offset % 8)), + .little => 8 * @as(u6, @truncate(offset % 8)), }; self.st[offset / 8] ^= @as(u64, byte) << z; } @@ -215,7 +215,7 @@ pub fn State(comptime endian: std.builtin.Endian) type { } test "ascon" { - const Ascon = State(.Big); + const Ascon = State(.big); const bytes = [_]u8{0x01} ** Ascon.block_bytes; var st = Ascon.init(bytes); var out: [Ascon.block_bytes]u8 = undefined; diff --git a/lib/std/crypto/bcrypt.zig b/lib/std/crypto/bcrypt.zig index 8da09ff5c9..9fc2ecb63b 100644 --- a/lib/std/crypto/bcrypt.zig +++ b/lib/std/crypto/bcrypt.zig @@ -451,7 +451,7 @@ pub fn bcrypt( var ct: [ct_length]u8 = undefined; for (cdata, 0..) |c, i| { - mem.writeInt(u32, ct[i * 4 ..][0..4], c, .Big); + mem.writeInt(u32, ct[i * 4 ..][0..4], c, .big); } return ct[0..dk_length].*; } @@ -547,7 +547,7 @@ const pbkdf_prf = struct { // copy out var out: [32]u8 = undefined; for (cdata, 0..) |v, i| { - std.mem.writeInt(u32, out[4 * i ..][0..4], v, .Little); + std.mem.writeInt(u32, out[4 * i ..][0..4], v, .little); } // zap diff --git a/lib/std/crypto/blake2.zig b/lib/std/crypto/blake2.zig index b17fdbc36e..255011de87 100644 --- a/lib/std/crypto/blake2.zig +++ b/lib/std/crypto/blake2.zig @@ -85,12 +85,12 @@ pub fn Blake2s(comptime out_bits: usize) type { d.buf_len = 0; if (options.salt) |salt| { - d.h[4] ^= mem.readInt(u32, salt[0..4], .Little); - d.h[5] ^= mem.readInt(u32, salt[4..8], .Little); + d.h[4] ^= mem.readInt(u32, salt[0..4], .little); + d.h[5] ^= mem.readInt(u32, salt[4..8], .little); } if (options.context) |context| { - d.h[6] ^= mem.readInt(u32, context[0..4], .Little); - d.h[7] ^= mem.readInt(u32, context[4..8], .Little); + d.h[6] ^= mem.readInt(u32, context[0..4], .little); + d.h[7] ^= mem.readInt(u32, context[4..8], .little); } if (key_len > 0) { @memset(d.buf[key_len..], 0); @@ -143,7 +143,7 @@ pub fn Blake2s(comptime out_bits: usize) type { var v: [16]u32 = undefined; for (&m, 0..) |*r, i| { - r.* = mem.readInt(u32, b[4 * i ..][0..4], .Little); + r.* = mem.readInt(u32, b[4 * i ..][0..4], .little); } var k: usize = 0; @@ -521,12 +521,12 @@ pub fn Blake2b(comptime out_bits: usize) type { d.buf_len = 0; if (options.salt) |salt| { - d.h[4] ^= mem.readInt(u64, salt[0..8], .Little); - d.h[5] ^= mem.readInt(u64, salt[8..16], .Little); + d.h[4] ^= mem.readInt(u64, salt[0..8], .little); + d.h[5] ^= mem.readInt(u64, salt[8..16], .little); } if (options.context) |context| { - d.h[6] ^= mem.readInt(u64, context[0..8], .Little); - d.h[7] ^= mem.readInt(u64, context[8..16], .Little); + d.h[6] ^= mem.readInt(u64, context[0..8], .little); + d.h[7] ^= mem.readInt(u64, context[8..16], .little); } if (key_len > 0) { @memset(d.buf[key_len..], 0); @@ -579,7 +579,7 @@ pub fn Blake2b(comptime out_bits: usize) type { var v: [16]u64 = undefined; for (&m, 0..) |*r, i| { - r.* = mem.readInt(u64, b[8 * i ..][0..8], .Little); + r.* = mem.readInt(u64, b[8 * i ..][0..8], .little); } var k: usize = 0; diff --git a/lib/std/crypto/blake3.zig b/lib/std/crypto/blake3.zig index d33ab6aac1..04becf6789 100644 --- a/lib/std/crypto/blake3.zig +++ b/lib/std/crypto/blake3.zig @@ -212,7 +212,7 @@ fn first8Words(words: [16]u32) [8]u32 { fn wordsFromLittleEndianBytes(comptime count: usize, bytes: [count * 4]u8) [count]u32 { var words: [count]u32 = undefined; for (&words, 0..) |*word, i| { - word.* = mem.readInt(u32, bytes[4 * i ..][0..4], .Little); + word.* = mem.readInt(u32, bytes[4 * i ..][0..4], .little); } return words; } @@ -252,7 +252,7 @@ const Output = struct { var word_counter: usize = 0; while (out_word_it.next()) |out_word| { var word_bytes: [4]u8 = undefined; - mem.writeInt(u32, &word_bytes, words[word_counter], .Little); + mem.writeInt(u32, &word_bytes, words[word_counter], .little); @memcpy(out_word, word_bytes[0..out_word.len]); word_counter += 1; } diff --git a/lib/std/crypto/chacha20.zig b/lib/std/crypto/chacha20.zig index 941bfefe48..7e0c891747 100644 --- a/lib/std/crypto/chacha20.zig +++ b/lib/std/crypto/chacha20.zig @@ -87,10 +87,10 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type switch (degree) { 1 => { const constant_le = Lane{ - mem.readInt(u32, c[0..4], .Little), - mem.readInt(u32, c[4..8], .Little), - mem.readInt(u32, c[8..12], .Little), - mem.readInt(u32, c[12..16], .Little), + mem.readInt(u32, c[0..4], .little), + mem.readInt(u32, c[4..8], .little), + mem.readInt(u32, c[8..12], .little), + mem.readInt(u32, c[12..16], .little), }; return BlockVec{ constant_le, @@ -101,14 +101,14 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type }, 2 => { const constant_le = Lane{ - mem.readInt(u32, c[0..4], .Little), - mem.readInt(u32, c[4..8], .Little), - mem.readInt(u32, c[8..12], .Little), - mem.readInt(u32, c[12..16], .Little), - mem.readInt(u32, c[0..4], .Little), - mem.readInt(u32, c[4..8], .Little), - mem.readInt(u32, c[8..12], .Little), - mem.readInt(u32, c[12..16], .Little), + mem.readInt(u32, c[0..4], .little), + mem.readInt(u32, c[4..8], .little), + mem.readInt(u32, c[8..12], .little), + mem.readInt(u32, c[12..16], .little), + mem.readInt(u32, c[0..4], .little), + mem.readInt(u32, c[4..8], .little), + mem.readInt(u32, c[8..12], .little), + mem.readInt(u32, c[12..16], .little), }; const n1 = @addWithOverflow(d[0], 1); return BlockVec{ @@ -123,22 +123,22 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type const n2 = @addWithOverflow(d[0], 2); const n3 = @addWithOverflow(d[0], 3); const constant_le = Lane{ - mem.readInt(u32, c[0..4], .Little), - mem.readInt(u32, c[4..8], .Little), - mem.readInt(u32, c[8..12], .Little), - mem.readInt(u32, c[12..16], .Little), - mem.readInt(u32, c[0..4], .Little), - mem.readInt(u32, c[4..8], .Little), - mem.readInt(u32, c[8..12], .Little), - mem.readInt(u32, c[12..16], .Little), - mem.readInt(u32, c[0..4], .Little), - mem.readInt(u32, c[4..8], .Little), - mem.readInt(u32, c[8..12], .Little), - mem.readInt(u32, c[12..16], .Little), - mem.readInt(u32, c[0..4], .Little), - mem.readInt(u32, c[4..8], .Little), - mem.readInt(u32, c[8..12], .Little), - mem.readInt(u32, c[12..16], .Little), + mem.readInt(u32, c[0..4], .little), + mem.readInt(u32, c[4..8], .little), + mem.readInt(u32, c[8..12], .little), + mem.readInt(u32, c[12..16], .little), + mem.readInt(u32, c[0..4], .little), + mem.readInt(u32, c[4..8], .little), + mem.readInt(u32, c[8..12], .little), + mem.readInt(u32, c[12..16], .little), + mem.readInt(u32, c[0..4], .little), + mem.readInt(u32, c[4..8], .little), + mem.readInt(u32, c[8..12], .little), + mem.readInt(u32, c[12..16], .little), + mem.readInt(u32, c[0..4], .little), + mem.readInt(u32, c[4..8], .little), + mem.readInt(u32, c[8..12], .little), + mem.readInt(u32, c[12..16], .little), }; return BlockVec{ constant_le, @@ -218,10 +218,10 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type inline fn hashToBytes(comptime dm: usize, out: *[64 * dm]u8, x: BlockVec) void { for (0..dm) |d| { for (0..4) |i| { - mem.writeInt(u32, out[64 * d + 16 * i + 0 ..][0..4], x[i][0 + 4 * d], .Little); - mem.writeInt(u32, out[64 * d + 16 * i + 4 ..][0..4], x[i][1 + 4 * d], .Little); - mem.writeInt(u32, out[64 * d + 16 * i + 8 ..][0..4], x[i][2 + 4 * d], .Little); - mem.writeInt(u32, out[64 * d + 16 * i + 12 ..][0..4], x[i][3 + 4 * d], .Little); + mem.writeInt(u32, out[64 * d + 16 * i + 0 ..][0..4], x[i][0 + 4 * d], .little); + mem.writeInt(u32, out[64 * d + 16 * i + 4 ..][0..4], x[i][1 + 4 * d], .little); + mem.writeInt(u32, out[64 * d + 16 * i + 8 ..][0..4], x[i][2 + 4 * d], .little); + mem.writeInt(u32, out[64 * d + 16 * i + 12 ..][0..4], x[i][3 + 4 * d], .little); } } } @@ -309,20 +309,20 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type fn hchacha20(input: [16]u8, key: [32]u8) [32]u8 { var c: [4]u32 = undefined; for (c, 0..) |_, i| { - c[i] = mem.readInt(u32, input[4 * i ..][0..4], .Little); + c[i] = mem.readInt(u32, input[4 * i ..][0..4], .little); } const ctx = initContext(keyToWords(key), c); var x: BlockVec = undefined; chacha20Core(x[0..], ctx); var out: [32]u8 = undefined; - mem.writeInt(u32, out[0..4], x[0][0], .Little); - mem.writeInt(u32, out[4..8], x[0][1], .Little); - mem.writeInt(u32, out[8..12], x[0][2], .Little); - mem.writeInt(u32, out[12..16], x[0][3], .Little); - mem.writeInt(u32, out[16..20], x[3][0], .Little); - mem.writeInt(u32, out[20..24], x[3][1], .Little); - mem.writeInt(u32, out[24..28], x[3][2], .Little); - mem.writeInt(u32, out[28..32], x[3][3], .Little); + mem.writeInt(u32, out[0..4], x[0][0], .little); + mem.writeInt(u32, out[4..8], x[0][1], .little); + mem.writeInt(u32, out[8..12], x[0][2], .little); + mem.writeInt(u32, out[12..16], x[0][3], .little); + mem.writeInt(u32, out[16..20], x[3][0], .little); + mem.writeInt(u32, out[20..24], x[3][1], .little); + mem.writeInt(u32, out[24..28], x[3][2], .little); + mem.writeInt(u32, out[28..32], x[3][3], .little); return out; } }; @@ -336,10 +336,10 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type { fn initContext(key: [8]u32, d: [4]u32) BlockVec { const c = "expand 32-byte k"; const constant_le = comptime [4]u32{ - mem.readInt(u32, c[0..4], .Little), - mem.readInt(u32, c[4..8], .Little), - mem.readInt(u32, c[8..12], .Little), - mem.readInt(u32, c[12..16], .Little), + mem.readInt(u32, c[0..4], .little), + mem.readInt(u32, c[4..8], .little), + mem.readInt(u32, c[8..12], .little), + mem.readInt(u32, c[12..16], .little), }; return BlockVec{ constant_le[0], constant_le[1], constant_le[2], constant_le[3], @@ -396,10 +396,10 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type { inline fn hashToBytes(out: *[64]u8, x: BlockVec) void { for (0..4) |i| { - mem.writeInt(u32, out[16 * i + 0 ..][0..4], x[i * 4 + 0], .Little); - mem.writeInt(u32, out[16 * i + 4 ..][0..4], x[i * 4 + 1], .Little); - mem.writeInt(u32, out[16 * i + 8 ..][0..4], x[i * 4 + 2], .Little); - mem.writeInt(u32, out[16 * i + 12 ..][0..4], x[i * 4 + 3], .Little); + mem.writeInt(u32, out[16 * i + 0 ..][0..4], x[i * 4 + 0], .little); + mem.writeInt(u32, out[16 * i + 4 ..][0..4], x[i * 4 + 1], .little); + mem.writeInt(u32, out[16 * i + 8 ..][0..4], x[i * 4 + 2], .little); + mem.writeInt(u32, out[16 * i + 12 ..][0..4], x[i * 4 + 3], .little); } } @@ -477,20 +477,20 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type { fn hchacha20(input: [16]u8, key: [32]u8) [32]u8 { var c: [4]u32 = undefined; for (c, 0..) |_, i| { - c[i] = mem.readInt(u32, input[4 * i ..][0..4], .Little); + c[i] = mem.readInt(u32, input[4 * i ..][0..4], .little); } const ctx = initContext(keyToWords(key), c); var x: BlockVec = undefined; chacha20Core(x[0..], ctx); var out: [32]u8 = undefined; - mem.writeInt(u32, out[0..4], x[0], .Little); - mem.writeInt(u32, out[4..8], x[1], .Little); - mem.writeInt(u32, out[8..12], x[2], .Little); - mem.writeInt(u32, out[12..16], x[3], .Little); - mem.writeInt(u32, out[16..20], x[12], .Little); - mem.writeInt(u32, out[20..24], x[13], .Little); - mem.writeInt(u32, out[24..28], x[14], .Little); - mem.writeInt(u32, out[28..32], x[15], .Little); + mem.writeInt(u32, out[0..4], x[0], .little); + mem.writeInt(u32, out[4..8], x[1], .little); + mem.writeInt(u32, out[8..12], x[2], .little); + mem.writeInt(u32, out[12..16], x[3], .little); + mem.writeInt(u32, out[16..20], x[12], .little); + mem.writeInt(u32, out[20..24], x[13], .little); + mem.writeInt(u32, out[24..28], x[14], .little); + mem.writeInt(u32, out[28..32], x[15], .little); return out; } }; @@ -519,7 +519,7 @@ fn ChaChaImpl(comptime rounds_nb: usize) type { fn keyToWords(key: [32]u8) [8]u32 { var k: [8]u32 = undefined; for (0..8) |i| { - k[i] = mem.readInt(u32, key[i * 4 ..][0..4], .Little); + k[i] = mem.readInt(u32, key[i * 4 ..][0..4], .little); } return k; } @@ -552,9 +552,9 @@ fn ChaChaIETF(comptime rounds_nb: usize) type { var d: [4]u32 = undefined; d[0] = counter; - d[1] = mem.readInt(u32, nonce[0..4], .Little); - d[2] = mem.readInt(u32, nonce[4..8], .Little); - d[3] = mem.readInt(u32, nonce[8..12], .Little); + d[1] = mem.readInt(u32, nonce[0..4], .little); + d[2] = mem.readInt(u32, nonce[4..8], .little); + d[3] = mem.readInt(u32, nonce[8..12], .little); ChaChaImpl(rounds_nb).chacha20Xor(out, in, keyToWords(key), d, false); } @@ -564,9 +564,9 @@ fn ChaChaIETF(comptime rounds_nb: usize) type { var d: [4]u32 = undefined; d[0] = counter; - d[1] = mem.readInt(u32, nonce[0..4], .Little); - d[2] = mem.readInt(u32, nonce[4..8], .Little); - d[3] = mem.readInt(u32, nonce[8..12], .Little); + d[1] = mem.readInt(u32, nonce[0..4], .little); + d[2] = mem.readInt(u32, nonce[4..8], .little); + d[3] = mem.readInt(u32, nonce[8..12], .little); ChaChaImpl(rounds_nb).chacha20Stream(out, keyToWords(key), d, false); } }; @@ -592,8 +592,8 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type { var c: [4]u32 = undefined; c[0] = @as(u32, @truncate(counter)); c[1] = @as(u32, @truncate(counter >> 32)); - c[2] = mem.readInt(u32, nonce[0..4], .Little); - c[3] = mem.readInt(u32, nonce[4..8], .Little); + c[2] = mem.readInt(u32, nonce[0..4], .little); + c[3] = mem.readInt(u32, nonce[4..8], .little); ChaChaImpl(rounds_nb).chacha20Xor(out, in, k, c, true); } @@ -605,8 +605,8 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type { var c: [4]u32 = undefined; c[0] = @as(u32, @truncate(counter)); c[1] = @as(u32, @truncate(counter >> 32)); - c[2] = mem.readInt(u32, nonce[0..4], .Little); - c[3] = mem.readInt(u32, nonce[4..8], .Little); + c[2] = mem.readInt(u32, nonce[0..4], .little); + c[3] = mem.readInt(u32, nonce[4..8], .little); ChaChaImpl(rounds_nb).chacha20Stream(out, k, c, true); } }; @@ -672,8 +672,8 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { mac.update(zeros[0..padding]); } var lens: [16]u8 = undefined; - mem.writeInt(u64, lens[0..8], ad.len, .Little); - mem.writeInt(u64, lens[8..16], m.len, .Little); + mem.writeInt(u64, lens[0..8], ad.len, .little); + mem.writeInt(u64, lens[8..16], m.len, .little); mac.update(lens[0..]); mac.final(tag); } @@ -708,8 +708,8 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { mac.update(zeros[0..padding]); } var lens: [16]u8 = undefined; - mem.writeInt(u64, lens[0..8], ad.len, .Little); - mem.writeInt(u64, lens[8..16], c.len, .Little); + mem.writeInt(u64, lens[0..8], ad.len, .little); + mem.writeInt(u64, lens[8..16], c.len, .little); mac.update(lens[0..]); var computed_tag: [16]u8 = undefined; mac.final(computed_tag[0..]); diff --git a/lib/std/crypto/cmac.zig b/lib/std/crypto/cmac.zig index e28853de51..32ba7f4b99 100644 --- a/lib/std/crypto/cmac.zig +++ b/lib/std/crypto/cmac.zig @@ -76,7 +76,7 @@ pub fn Cmac(comptime BlockCipher: type) type { fn double(l: Block) Block { const Int = std.meta.Int(.unsigned, block_length * 8); - const l_ = mem.readInt(Int, &l, .Big); + const l_ = mem.readInt(Int, &l, .big); const l_2 = switch (block_length) { 8 => (l_ << 1) ^ (0x1b & -%(l_ >> 63)), // mod x^64 + x^4 + x^3 + x + 1 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 { else => @compileError("unsupported block length"), }; var l2: Block = undefined; - mem.writeInt(Int, &l2, l_2, .Big); + mem.writeInt(Int, &l2, l_2, .big); return l2; } }; diff --git a/lib/std/crypto/ecdsa.zig b/lib/std/crypto/ecdsa.zig index 8da7100f8f..e705fcf79b 100644 --- a/lib/std/crypto/ecdsa.zig +++ b/lib/std/crypto/ecdsa.zig @@ -209,17 +209,17 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { const k = deterministicScalar(h_slice.*, self.secret_key.bytes, self.noise); - const p = try Curve.basePoint.mul(k.toBytes(.Big), .Big); - const xs = p.affineCoordinates().x.toBytes(.Big); + const p = try Curve.basePoint.mul(k.toBytes(.big), .big); + const xs = p.affineCoordinates().x.toBytes(.big); const r = reduceToScalar(Curve.Fe.encoded_length, xs); if (r.isZero()) return error.IdentityElement; const k_inv = k.invert(); - const zrs = z.add(r.mul(try Curve.scalar.Scalar.fromBytes(self.secret_key.bytes, .Big))); + const zrs = z.add(r.mul(try Curve.scalar.Scalar.fromBytes(self.secret_key.bytes, .big))); const s = k_inv.mul(zrs); if (s.isZero()) return error.IdentityElement; - return Signature{ .r = r.toBytes(.Big), .s = s.toBytes(.Big) }; + return Signature{ .r = r.toBytes(.big), .s = s.toBytes(.big) }; } }; @@ -232,8 +232,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { public_key: PublicKey, fn init(sig: Signature, public_key: PublicKey) (IdentityElementError || NonCanonicalError)!Verifier { - const r = try Curve.scalar.Scalar.fromBytes(sig.r, .Big); - const s = try Curve.scalar.Scalar.fromBytes(sig.s, .Big); + const r = try Curve.scalar.Scalar.fromBytes(sig.r, .big); + const s = try Curve.scalar.Scalar.fromBytes(sig.s, .big); if (r.isZero() or s.isZero()) return error.IdentityElement; return Verifier{ @@ -262,11 +262,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { } const s_inv = self.s.invert(); - const v1 = z.mul(s_inv).toBytes(.Little); - const v2 = self.r.mul(s_inv).toBytes(.Little); - const v1g = try Curve.basePoint.mulPublic(v1, .Little); - const v2pk = try self.public_key.p.mulPublic(v2, .Little); - const vxs = v1g.add(v2pk).affineCoordinates().x.toBytes(.Big); + const v1 = z.mul(s_inv).toBytes(.little); + const v2 = self.r.mul(s_inv).toBytes(.little); + const v1g = try Curve.basePoint.mulPublic(v1, .little); + const v2pk = try self.public_key.p.mulPublic(v2, .little); + const vxs = v1g.add(v2pk).affineCoordinates().x.toBytes(.big); const vr = reduceToScalar(Curve.Fe.encoded_length, vxs); if (!self.r.equivalent(vr)) { return error.SignatureVerificationFailed; @@ -295,13 +295,13 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { } const h = [_]u8{0x00} ** Hash.digest_length; const k0 = [_]u8{0x01} ** SecretKey.encoded_length; - const secret_key = deterministicScalar(h, k0, seed_).toBytes(.Big); + const secret_key = deterministicScalar(h, k0, seed_).toBytes(.big); return fromSecretKey(SecretKey{ .bytes = secret_key }); } /// Return the public key corresponding to the secret key. pub fn fromSecretKey(secret_key: SecretKey) IdentityElementError!KeyPair { - const public_key = try Curve.basePoint.mul(secret_key.bytes, .Big); + const public_key = try Curve.basePoint.mul(secret_key.bytes, .big); return KeyPair{ .secret_key = secret_key, .public_key = PublicKey{ .p = public_key } }; } @@ -326,11 +326,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { if (unreduced_len >= 48) { var xs = [_]u8{0} ** 64; @memcpy(xs[xs.len - s.len ..], s[0..]); - return Curve.scalar.Scalar.fromBytes64(xs, .Big); + return Curve.scalar.Scalar.fromBytes64(xs, .big); } var xs = [_]u8{0} ** 48; @memcpy(xs[xs.len - s.len ..], s[0..]); - return Curve.scalar.Scalar.fromBytes48(xs, .Big); + return Curve.scalar.Scalar.fromBytes48(xs, .big); } // Create a deterministic scalar according to a secret key and optional noise. @@ -362,7 +362,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { Hmac.create(m_v, m_v, &k); @memcpy(t[t_off..t_end], m_v[0 .. t_end - t_off]); } - if (Curve.scalar.Scalar.fromBytes(t, .Big)) |s| return s else |_| {} + if (Curve.scalar.Scalar.fromBytes(t, .big)) |s| return s else |_| {} m_i.* = 0x00; Hmac.create(&k, m[0 .. m_v.len + 1], &k); Hmac.create(m_v, m_v, &k); diff --git a/lib/std/crypto/ff.zig b/lib/std/crypto/ff.zig index e00a3741da..932575e936 100644 --- a/lib/std/crypto/ff.zig +++ b/lib/std/crypto/ff.zig @@ -137,8 +137,8 @@ pub fn Uint(comptime max_bits: comptime_int) type { @memset(bytes, 0); var shift: usize = 0; var out_i: usize = switch (endian) { - .Big => bytes.len - 1, - .Little => 0, + .big => bytes.len - 1, + .little => 0, }; for (0..self.limbs.len) |i| { var remaining_bits = t_bits; @@ -150,7 +150,7 @@ pub fn Uint(comptime max_bits: comptime_int) type { remaining_bits -= consumed; shift = 0; switch (endian) { - .Big => { + .big => { if (out_i == 0) { if (i != self.limbs.len - 1 or limb != 0) { return error.Overflow; @@ -159,7 +159,7 @@ pub fn Uint(comptime max_bits: comptime_int) type { } out_i -= 1; }, - .Little => { + .little => { out_i += 1; if (out_i == bytes.len) { if (i != self.limbs.len - 1 or limb != 0) { @@ -182,8 +182,8 @@ pub fn Uint(comptime max_bits: comptime_int) type { var out = Self.zero; var out_i: usize = 0; var i: usize = switch (endian) { - .Big => bytes.len - 1, - .Little => 0, + .big => bytes.len - 1, + .little => 0, }; while (true) { const bi = bytes[i]; @@ -203,11 +203,11 @@ pub fn Uint(comptime max_bits: comptime_int) type { out.limbs.set(out_i, overflow); } switch (endian) { - .Big => { + .big => { if (i == 0) break; i -= 1; }, - .Little => { + .little => { i += 1; if (i == bytes.len) break; }, @@ -227,7 +227,7 @@ pub fn Uint(comptime max_bits: comptime_int) type { Limb, x.limbs.constSlice(), y.limbs.constSlice(), - .Little, + .little, ); } @@ -667,15 +667,15 @@ pub fn Modulus(comptime max_bits: comptime_int) type { var out = self.one(); self.toMontgomery(&out) catch unreachable; - if (public and e.len < 3 or (e.len == 3 and e[if (endian == .Big) 0 else 2] <= 0b1111)) { + if (public and e.len < 3 or (e.len == 3 and e[if (endian == .big) 0 else 2] <= 0b1111)) { // Do not use a precomputation table for short, public exponents var x_m = x; if (x.montgomery == false) { self.toMontgomery(&x_m) catch unreachable; } var s = switch (endian) { - .Big => 0, - .Little => e.len - 1, + .big => 0, + .little => e.len - 1, }; while (true) { const b = e[s]; @@ -690,11 +690,11 @@ pub fn Modulus(comptime max_bits: comptime_int) type { if (j == 0) break; } switch (endian) { - .Big => { + .big => { s += 1; if (s == e.len) break; }, - .Little => { + .little => { if (s == 0) break; s -= 1; }, @@ -711,8 +711,8 @@ pub fn Modulus(comptime max_bits: comptime_int) type { } var t0 = self.zero; var s = switch (endian) { - .Big => 0, - .Little => e.len - 1, + .big => 0, + .little => e.len - 1, }; while (true) { const b = e[s]; @@ -737,11 +737,11 @@ pub fn Modulus(comptime max_bits: comptime_int) type { } } switch (endian) { - .Big => { + .big => { s += 1; if (s == e.len) break; }, - .Little => { + .little => { if (s == 0) break; s -= 1; }, @@ -791,10 +791,10 @@ pub fn Modulus(comptime max_bits: comptime_int) type { var e_normalized = Fe{ .v = e.v.normalize() }; var buf_: [Fe.encoded_bytes]u8 = undefined; var buf = buf_[0 .. math.divCeil(usize, e_normalized.v.limbs_count() * t_bits, 8) catch unreachable]; - e_normalized.toBytes(buf, .Little) catch unreachable; + e_normalized.toBytes(buf, .little) catch unreachable; const leading = @clz(e_normalized.v.limbs.get(e_normalized.v.limbs_count() - carry_bits)); buf = buf[0 .. buf.len - leading / 8]; - return self.powWithEncodedPublicExponent(x, buf, .Little); + return self.powWithEncodedPublicExponent(x, buf, .little); } /// Returns x^e (mod m), with the exponent provided as a byte string. diff --git a/lib/std/crypto/ghash_polyval.zig b/lib/std/crypto/ghash_polyval.zig index 47e2a65a94..6949553ad5 100644 --- a/lib/std/crypto/ghash_polyval.zig +++ b/lib/std/crypto/ghash_polyval.zig @@ -13,7 +13,7 @@ const Precomp = u128; /// It is not a general purpose hash function - The key must be secret, unpredictable and never reused. /// /// GHASH is typically used to compute the authentication tag in the AES-GCM construction. -pub const Ghash = Hash(.Big, true); +pub const Ghash = Hash(.big, true); /// POLYVAL is a universal hash function that uses multiplication by a fixed /// parameter within a Galois field. @@ -21,7 +21,7 @@ pub const Ghash = Hash(.Big, true); /// It is not a general purpose hash function - The key must be secret, unpredictable and never reused. /// /// POLYVAL is typically used to compute the authentication tag in the AES-GCM-SIV construction. -pub const Polyval = Hash(.Little, false); +pub const Polyval = Hash(.little, false); fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { return struct { diff --git a/lib/std/crypto/isap.zig b/lib/std/crypto/isap.zig index 3555ae2467..2db733a8ac 100644 --- a/lib/std/crypto/isap.zig +++ b/lib/std/crypto/isap.zig @@ -4,7 +4,7 @@ const debug = std.debug; const mem = std.mem; const math = std.math; const testing = std.testing; -const Ascon = crypto.core.Ascon(.Big); +const Ascon = crypto.core.Ascon(.big); const AuthenticationError = crypto.errors.AuthenticationError; /// ISAPv2 is an authenticated encryption system hardened against side channels and fault attacks. @@ -55,9 +55,9 @@ pub const IsapA128A = struct { fn trickle(k: [16]u8, iv: [8]u8, y: []const u8, comptime out_len: usize) [out_len]u8 { var isap = IsapA128A{ .st = Ascon.initFromWords(.{ - mem.readInt(u64, k[0..8], .Big), - mem.readInt(u64, k[8..16], .Big), - mem.readInt(u64, iv[0..8], .Big), + mem.readInt(u64, k[0..8], .big), + mem.readInt(u64, k[8..16], .big), + mem.readInt(u64, iv[0..8], .big), 0, 0, }), @@ -85,9 +85,9 @@ pub const IsapA128A = struct { fn mac(c: []const u8, ad: []const u8, npub: [16]u8, key: [16]u8) [16]u8 { var isap = IsapA128A{ .st = Ascon.initFromWords(.{ - mem.readInt(u64, npub[0..8], .Big), - mem.readInt(u64, npub[8..16], .Big), - mem.readInt(u64, iv1[0..], .Big), + mem.readInt(u64, npub[0..8], .big), + mem.readInt(u64, npub[8..16], .big), + mem.readInt(u64, iv1[0..], .big), 0, 0, }), @@ -116,11 +116,11 @@ pub const IsapA128A = struct { const nb = trickle(key, iv3, npub[0..], 24); var isap = IsapA128A{ .st = Ascon.initFromWords(.{ - mem.readInt(u64, nb[0..8], .Big), - mem.readInt(u64, nb[8..16], .Big), - mem.readInt(u64, nb[16..24], .Big), - mem.readInt(u64, npub[0..8], .Big), - mem.readInt(u64, npub[8..16], .Big), + mem.readInt(u64, nb[0..8], .big), + mem.readInt(u64, nb[8..16], .big), + mem.readInt(u64, nb[16..24], .big), + mem.readInt(u64, npub[0..8], .big), + mem.readInt(u64, npub[8..16], .big), }), }; isap.st.permuteR(6); diff --git a/lib/std/crypto/keccak_p.zig b/lib/std/crypto/keccak_p.zig index 46d4f85ef9..d04373269e 100644 --- a/lib/std/crypto/keccak_p.zig +++ b/lib/std/crypto/keccak_p.zig @@ -45,7 +45,7 @@ pub fn KeccakF(comptime f: u11) type { pub fn init(bytes: [block_bytes]u8) Self { var self: Self = undefined; inline for (&self.st, 0..) |*r, i| { - r.* = mem.readInt(T, bytes[@sizeOf(T) * i ..][0..@sizeOf(T)], .Little); + r.* = mem.readInt(T, bytes[@sizeOf(T) * i ..][0..@sizeOf(T)], .little); } return self; } @@ -66,12 +66,12 @@ pub fn KeccakF(comptime f: u11) type { pub fn setBytes(self: *Self, bytes: []const u8) void { var i: usize = 0; while (i + @sizeOf(T) <= bytes.len) : (i += @sizeOf(T)) { - self.st[i / @sizeOf(T)] = mem.readInt(T, bytes[i..][0..@sizeOf(T)], .Little); + self.st[i / @sizeOf(T)] = mem.readInt(T, bytes[i..][0..@sizeOf(T)], .little); } if (i < bytes.len) { var padded = [_]u8{0} ** @sizeOf(T); @memcpy(padded[0 .. bytes.len - i], bytes[i..]); - self.st[i / @sizeOf(T)] = mem.readInt(T, padded[0..], .Little); + self.st[i / @sizeOf(T)] = mem.readInt(T, padded[0..], .little); } } @@ -85,12 +85,12 @@ pub fn KeccakF(comptime f: u11) type { pub fn addBytes(self: *Self, bytes: []const u8) void { var i: usize = 0; while (i + @sizeOf(T) <= bytes.len) : (i += @sizeOf(T)) { - self.st[i / @sizeOf(T)] ^= mem.readInt(T, bytes[i..][0..@sizeOf(T)], .Little); + self.st[i / @sizeOf(T)] ^= mem.readInt(T, bytes[i..][0..@sizeOf(T)], .little); } if (i < bytes.len) { var padded = [_]u8{0} ** @sizeOf(T); @memcpy(padded[0 .. bytes.len - i], bytes[i..]); - self.st[i / @sizeOf(T)] ^= mem.readInt(T, padded[0..], .Little); + self.st[i / @sizeOf(T)] ^= mem.readInt(T, padded[0..], .little); } } @@ -98,11 +98,11 @@ pub fn KeccakF(comptime f: u11) type { pub fn extractBytes(self: *Self, out: []u8) void { var i: usize = 0; while (i + @sizeOf(T) <= out.len) : (i += @sizeOf(T)) { - mem.writeInt(T, out[i..][0..@sizeOf(T)], self.st[i / @sizeOf(T)], .Little); + mem.writeInt(T, out[i..][0..@sizeOf(T)], self.st[i / @sizeOf(T)], .little); } if (i < out.len) { var padded = [_]u8{0} ** @sizeOf(T); - mem.writeInt(T, padded[0..], self.st[i / @sizeOf(T)], .Little); + mem.writeInt(T, padded[0..], self.st[i / @sizeOf(T)], .little); @memcpy(out[i..], padded[0 .. out.len - i]); } } diff --git a/lib/std/crypto/md5.zig b/lib/std/crypto/md5.zig index 3c6d04ceaf..2fcdbbcc8c 100644 --- a/lib/std/crypto/md5.zig +++ b/lib/std/crypto/md5.zig @@ -112,7 +112,7 @@ pub const Md5 = struct { d.round(d.buf[0..]); for (d.s, 0..) |s, j| { - mem.writeInt(u32, out[4 * j ..][0..4], s, .Little); + mem.writeInt(u32, out[4 * j ..][0..4], s, .little); } } @@ -121,7 +121,7 @@ pub const Md5 = struct { var i: usize = 0; while (i < 16) : (i += 1) { - s[i] = mem.readInt(u32, b[i * 4 ..][0..4], .Little); + s[i] = mem.readInt(u32, b[i * 4 ..][0..4], .little); } var v: [4]u32 = [_]u32{ diff --git a/lib/std/crypto/pcurves/common.zig b/lib/std/crypto/pcurves/common.zig index 6c775e3c1c..4a6815ae05 100644 --- a/lib/std/crypto/pcurves/common.zig +++ b/lib/std/crypto/pcurves/common.zig @@ -51,13 +51,13 @@ pub fn Field(comptime params: FieldParams) type { /// Reject non-canonical encodings of an element. pub fn rejectNonCanonical(s_: [encoded_length]u8, endian: std.builtin.Endian) NonCanonicalError!void { - var s = if (endian == .Little) s_ else orderSwap(s_); + var s = if (endian == .little) s_ else orderSwap(s_); const field_order_s = comptime fos: { var fos: [encoded_length]u8 = undefined; - mem.writeInt(std.meta.Int(.unsigned, encoded_length * 8), &fos, field_order, .Little); + mem.writeInt(std.meta.Int(.unsigned, encoded_length * 8), &fos, field_order, .little); break :fos fos; }; - if (crypto.utils.timingSafeCompare(u8, &s, &field_order_s, .Little) != .lt) { + if (crypto.utils.timingSafeCompare(u8, &s, &field_order_s, .little) != .lt) { return error.NonCanonical; } } @@ -71,8 +71,8 @@ pub fn Field(comptime params: FieldParams) type { /// Unpack a field element. pub fn fromBytes(s_: [encoded_length]u8, endian: std.builtin.Endian) NonCanonicalError!Fe { - var s = if (endian == .Little) s_ else orderSwap(s_); - try rejectNonCanonical(s, .Little); + var s = if (endian == .little) s_ else orderSwap(s_); + try rejectNonCanonical(s, .little); var limbs_z: NonMontgomeryDomainFieldElement = undefined; fiat.fromBytes(&limbs_z, s); var limbs: MontgomeryDomainFieldElement = undefined; @@ -86,7 +86,7 @@ pub fn Field(comptime params: FieldParams) type { fiat.fromMontgomery(&limbs_z, fe.limbs); var s: [encoded_length]u8 = undefined; fiat.toBytes(&s, limbs_z); - return if (endian == .Little) s else orderSwap(s); + return if (endian == .little) s else orderSwap(s); } /// Element as an integer. @@ -95,14 +95,14 @@ pub fn Field(comptime params: FieldParams) type { /// Create a field element from an integer. pub fn fromInt(comptime x: IntRepr) NonCanonicalError!Fe { var s: [encoded_length]u8 = undefined; - mem.writeInt(IntRepr, &s, x, .Little); - return fromBytes(s, .Little); + mem.writeInt(IntRepr, &s, x, .little); + return fromBytes(s, .little); } /// Return the field element as an integer. pub fn toInt(fe: Fe) IntRepr { - const s = fe.toBytes(.Little); - return mem.readInt(IntRepr, &s, .Little); + const s = fe.toBytes(.little); + return mem.readInt(IntRepr, &s, .little); } /// Return true if the field element is zero. @@ -119,7 +119,7 @@ pub fn Field(comptime params: FieldParams) type { /// Return true if the element is odd. pub fn isOdd(fe: Fe) bool { - const s = fe.toBytes(.Little); + const s = fe.toBytes(.little); return @as(u1, @truncate(s[0])) != 0; } diff --git a/lib/std/crypto/pcurves/p256.zig b/lib/std/crypto/pcurves/p256.zig index 87c963f834..37f16715f4 100644 --- a/lib/std/crypto/pcurves/p256.zig +++ b/lib/std/crypto/pcurves/p256.zig @@ -87,15 +87,15 @@ pub const P256 = struct { }, 2, 3 => { if (encoded.len != 32) return error.InvalidEncoding; - const x = try Fe.fromBytes(encoded[0..32].*, .Big); + const x = try Fe.fromBytes(encoded[0..32].*, .big); const y_is_odd = (encoding_type == 3); const y = try recoverY(x, y_is_odd); return P256{ .x = x, .y = y }; }, 4 => { if (encoded.len != 64) return error.InvalidEncoding; - const x = try Fe.fromBytes(encoded[0..32].*, .Big); - const y = try Fe.fromBytes(encoded[32..64].*, .Big); + const x = try Fe.fromBytes(encoded[0..32].*, .big); + const y = try Fe.fromBytes(encoded[32..64].*, .big); return P256.fromAffineCoordinates(.{ .x = x, .y = y }); }, else => return error.InvalidEncoding, @@ -107,7 +107,7 @@ pub const P256 = struct { var out: [33]u8 = undefined; const xy = p.affineCoordinates(); out[0] = if (xy.y.isOdd()) 3 else 2; - out[1..].* = xy.x.toBytes(.Big); + out[1..].* = xy.x.toBytes(.big); return out; } @@ -116,15 +116,15 @@ pub const P256 = struct { var out: [65]u8 = undefined; out[0] = 4; const xy = p.affineCoordinates(); - out[1..33].* = xy.x.toBytes(.Big); - out[33..65].* = xy.y.toBytes(.Big); + out[1..33].* = xy.x.toBytes(.big); + out[33..65].* = xy.y.toBytes(.big); return out; } /// Return a random point. pub fn random() P256 { - const n = scalar.random(.Little); - return basePoint.mul(n, .Little) catch unreachable; + const n = scalar.random(.little); + return basePoint.mul(n, .little) catch unreachable; } /// Flip the sign of the X coordinate. @@ -400,7 +400,7 @@ pub const P256 = struct { /// Multiply an elliptic curve point by a scalar. /// Return error.IdentityElement if the result is the identity element. pub fn mul(p: P256, s_: [32]u8, endian: std.builtin.Endian) IdentityElementError!P256 { - const s = if (endian == .Little) s_ else Fe.orderSwap(s_); + const s = if (endian == .little) s_ else Fe.orderSwap(s_); if (p.is_base) { return pcMul16(&basePointPc, s, false); } @@ -412,7 +412,7 @@ pub const P256 = struct { /// Multiply an elliptic curve point by a *PUBLIC* scalar *IN VARIABLE TIME* /// This can be used for signature verification. pub fn mulPublic(p: P256, s_: [32]u8, endian: std.builtin.Endian) IdentityElementError!P256 { - const s = if (endian == .Little) s_ else Fe.orderSwap(s_); + const s = if (endian == .little) s_ else Fe.orderSwap(s_); if (p.is_base) { return pcMul16(&basePointPc, s, true); } @@ -424,8 +424,8 @@ pub const P256 = struct { /// Double-base multiplication of public parameters - Compute (p1*s1)+(p2*s2) *IN VARIABLE TIME* /// This can be used for signature verification. pub fn mulDoubleBasePublic(p1: P256, s1_: [32]u8, p2: P256, s2_: [32]u8, endian: std.builtin.Endian) IdentityElementError!P256 { - const s1 = if (endian == .Little) s1_ else Fe.orderSwap(s1_); - const s2 = if (endian == .Little) s2_ else Fe.orderSwap(s2_); + const s1 = if (endian == .little) s1_ else Fe.orderSwap(s1_); + const s2 = if (endian == .little) s2_ else Fe.orderSwap(s2_); try p1.rejectIdentity(); var pc1_array: [9]P256 = undefined; const pc1 = if (p1.is_base) basePointPc[0..9] else pc: { diff --git a/lib/std/crypto/pcurves/p256/scalar.zig b/lib/std/crypto/pcurves/p256/scalar.zig index 9506a5e57a..d7d8ed5256 100644 --- a/lib/std/crypto/pcurves/p256/scalar.zig +++ b/lib/std/crypto/pcurves/p256/scalar.zig @@ -174,7 +174,7 @@ pub const Scalar = struct { var s: [48]u8 = undefined; while (true) { crypto.random.bytes(&s); - const n = Scalar.fromBytes48(s, .Little); + const n = Scalar.fromBytes48(s, .little); if (!n.isZero()) { return n; } @@ -191,7 +191,7 @@ const ScalarDouble = struct { debug.assert(bits > 0 and bits <= 512 and bits >= Fe.saturated_bits and bits <= Fe.saturated_bits * 3); var s = s_; - if (endian == .Big) { + if (endian == .big) { for (s_, 0..) |x, i| s[s.len - 1 - i] = x; } var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero }; @@ -199,19 +199,19 @@ const ScalarDouble = struct { var b = [_]u8{0} ** encoded_length; const len = @min(s.len, 24); b[0..len].* = s[0..len].*; - t.x1 = Fe.fromBytes(b, .Little) catch unreachable; + t.x1 = Fe.fromBytes(b, .little) catch unreachable; } if (s_.len >= 24) { var b = [_]u8{0} ** encoded_length; const len = @min(s.len - 24, 24); b[0..len].* = s[24..][0..len].*; - t.x2 = Fe.fromBytes(b, .Little) catch unreachable; + t.x2 = Fe.fromBytes(b, .little) catch unreachable; } if (s_.len >= 48) { var b = [_]u8{0} ** encoded_length; const len = s.len - 48; b[0..len].* = s[48..][0..len].*; - t.x3 = Fe.fromBytes(b, .Little) catch unreachable; + t.x3 = Fe.fromBytes(b, .little) catch unreachable; } return t; } diff --git a/lib/std/crypto/pcurves/p384.zig b/lib/std/crypto/pcurves/p384.zig index 9fb84625fb..6585a0adfd 100644 --- a/lib/std/crypto/pcurves/p384.zig +++ b/lib/std/crypto/pcurves/p384.zig @@ -87,15 +87,15 @@ pub const P384 = struct { }, 2, 3 => { if (encoded.len != 48) return error.InvalidEncoding; - const x = try Fe.fromBytes(encoded[0..48].*, .Big); + const x = try Fe.fromBytes(encoded[0..48].*, .big); const y_is_odd = (encoding_type == 3); const y = try recoverY(x, y_is_odd); return P384{ .x = x, .y = y }; }, 4 => { if (encoded.len != 96) return error.InvalidEncoding; - const x = try Fe.fromBytes(encoded[0..48].*, .Big); - const y = try Fe.fromBytes(encoded[48..96].*, .Big); + const x = try Fe.fromBytes(encoded[0..48].*, .big); + const y = try Fe.fromBytes(encoded[48..96].*, .big); return P384.fromAffineCoordinates(.{ .x = x, .y = y }); }, else => return error.InvalidEncoding, @@ -107,7 +107,7 @@ pub const P384 = struct { var out: [49]u8 = undefined; const xy = p.affineCoordinates(); out[0] = if (xy.y.isOdd()) 3 else 2; - out[1..].* = xy.x.toBytes(.Big); + out[1..].* = xy.x.toBytes(.big); return out; } @@ -116,15 +116,15 @@ pub const P384 = struct { var out: [97]u8 = undefined; out[0] = 4; const xy = p.affineCoordinates(); - out[1..49].* = xy.x.toBytes(.Big); - out[49..97].* = xy.y.toBytes(.Big); + out[1..49].* = xy.x.toBytes(.big); + out[49..97].* = xy.y.toBytes(.big); return out; } /// Return a random point. pub fn random() P384 { - const n = scalar.random(.Little); - return basePoint.mul(n, .Little) catch unreachable; + const n = scalar.random(.little); + return basePoint.mul(n, .little) catch unreachable; } /// Flip the sign of the X coordinate. @@ -400,7 +400,7 @@ pub const P384 = struct { /// Multiply an elliptic curve point by a scalar. /// Return error.IdentityElement if the result is the identity element. pub fn mul(p: P384, s_: [48]u8, endian: std.builtin.Endian) IdentityElementError!P384 { - const s = if (endian == .Little) s_ else Fe.orderSwap(s_); + const s = if (endian == .little) s_ else Fe.orderSwap(s_); if (p.is_base) { return pcMul16(&basePointPc, s, false); } @@ -412,7 +412,7 @@ pub const P384 = struct { /// Multiply an elliptic curve point by a *PUBLIC* scalar *IN VARIABLE TIME* /// This can be used for signature verification. pub fn mulPublic(p: P384, s_: [48]u8, endian: std.builtin.Endian) IdentityElementError!P384 { - const s = if (endian == .Little) s_ else Fe.orderSwap(s_); + const s = if (endian == .little) s_ else Fe.orderSwap(s_); if (p.is_base) { return pcMul16(&basePointPc, s, true); } @@ -424,8 +424,8 @@ pub const P384 = struct { /// Double-base multiplication of public parameters - Compute (p1*s1)+(p2*s2) *IN VARIABLE TIME* /// This can be used for signature verification. pub fn mulDoubleBasePublic(p1: P384, s1_: [48]u8, p2: P384, s2_: [48]u8, endian: std.builtin.Endian) IdentityElementError!P384 { - const s1 = if (endian == .Little) s1_ else Fe.orderSwap(s1_); - const s2 = if (endian == .Little) s2_ else Fe.orderSwap(s2_); + const s1 = if (endian == .little) s1_ else Fe.orderSwap(s1_); + const s2 = if (endian == .little) s2_ else Fe.orderSwap(s2_); try p1.rejectIdentity(); var pc1_array: [9]P384 = undefined; const pc1 = if (p1.is_base) basePointPc[0..9] else pc: { diff --git a/lib/std/crypto/pcurves/p384/scalar.zig b/lib/std/crypto/pcurves/p384/scalar.zig index 499305bfec..d29d5ba655 100644 --- a/lib/std/crypto/pcurves/p384/scalar.zig +++ b/lib/std/crypto/pcurves/p384/scalar.zig @@ -163,7 +163,7 @@ pub const Scalar = struct { var s: [64]u8 = undefined; while (true) { crypto.random.bytes(&s); - const n = Scalar.fromBytes64(s, .Little); + const n = Scalar.fromBytes64(s, .little); if (!n.isZero()) { return n; } @@ -179,7 +179,7 @@ const ScalarDouble = struct { debug.assert(bits > 0 and bits <= 512 and bits >= Fe.saturated_bits and bits <= Fe.saturated_bits * 2); var s = s_; - if (endian == .Big) { + if (endian == .big) { for (s_, 0..) |x, i| s[s.len - 1 - i] = x; } var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero }; @@ -187,13 +187,13 @@ const ScalarDouble = struct { var b = [_]u8{0} ** encoded_length; const len = @min(s.len, 32); b[0..len].* = s[0..len].*; - t.x1 = Fe.fromBytes(b, .Little) catch unreachable; + t.x1 = Fe.fromBytes(b, .little) catch unreachable; } if (s_.len >= 32) { var b = [_]u8{0} ** encoded_length; const len = @min(s.len - 32, 32); b[0..len].* = s[32..][0..len].*; - t.x2 = Fe.fromBytes(b, .Little) catch unreachable; + t.x2 = Fe.fromBytes(b, .little) catch unreachable; } return t; } diff --git a/lib/std/crypto/pcurves/secp256k1.zig b/lib/std/crypto/pcurves/secp256k1.zig index 926f3114aa..a623e25de4 100644 --- a/lib/std/crypto/pcurves/secp256k1.zig +++ b/lib/std/crypto/pcurves/secp256k1.zig @@ -41,7 +41,7 @@ pub const Secp256k1 = struct { const lambda_s = s: { var buf: [32]u8 = undefined; - mem.writeInt(u256, &buf, Endormorphism.lambda, .Little); + mem.writeInt(u256, &buf, Endormorphism.lambda, .little); break :s buf; }; @@ -54,12 +54,12 @@ pub const Secp256k1 = struct { pub fn splitScalar(s: [32]u8, endian: std.builtin.Endian) NonCanonicalError!SplitScalar { const b1_neg_s = comptime s: { var buf: [32]u8 = undefined; - mem.writeInt(u256, &buf, 303414439467246543595250775667605759171, .Little); + mem.writeInt(u256, &buf, 303414439467246543595250775667605759171, .little); break :s buf; }; const b2_neg_s = comptime s: { var buf: [32]u8 = undefined; - mem.writeInt(u256, &buf, scalar.field_order - 64502973549206556628585045361533709077, .Little); + mem.writeInt(u256, &buf, scalar.field_order - 64502973549206556628585045361533709077, .little); break :s buf; }; const k = mem.readInt(u256, &s, endian); @@ -72,16 +72,16 @@ pub const Secp256k1 = struct { var buf: [32]u8 = undefined; - mem.writeInt(u256, &buf, c1, .Little); - const c1x = try scalar.mul(buf, b1_neg_s, .Little); + mem.writeInt(u256, &buf, c1, .little); + const c1x = try scalar.mul(buf, b1_neg_s, .little); - mem.writeInt(u256, &buf, c2, .Little); - const c2x = try scalar.mul(buf, b2_neg_s, .Little); + mem.writeInt(u256, &buf, c2, .little); + const c2x = try scalar.mul(buf, b2_neg_s, .little); - const r2 = try scalar.add(c1x, c2x, .Little); + const r2 = try scalar.add(c1x, c2x, .little); - var r1 = try scalar.mul(r2, lambda_s, .Little); - r1 = try scalar.sub(s, r1, .Little); + var r1 = try scalar.mul(r2, lambda_s, .little); + r1 = try scalar.sub(s, r1, .little); return SplitScalar{ .r1 = r1, .r2 = r2 }; } @@ -140,15 +140,15 @@ pub const Secp256k1 = struct { }, 2, 3 => { if (encoded.len != 32) return error.InvalidEncoding; - const x = try Fe.fromBytes(encoded[0..32].*, .Big); + const x = try Fe.fromBytes(encoded[0..32].*, .big); const y_is_odd = (encoding_type == 3); const y = try recoverY(x, y_is_odd); return Secp256k1{ .x = x, .y = y }; }, 4 => { if (encoded.len != 64) return error.InvalidEncoding; - const x = try Fe.fromBytes(encoded[0..32].*, .Big); - const y = try Fe.fromBytes(encoded[32..64].*, .Big); + const x = try Fe.fromBytes(encoded[0..32].*, .big); + const y = try Fe.fromBytes(encoded[32..64].*, .big); return Secp256k1.fromAffineCoordinates(.{ .x = x, .y = y }); }, else => return error.InvalidEncoding, @@ -160,7 +160,7 @@ pub const Secp256k1 = struct { var out: [33]u8 = undefined; const xy = p.affineCoordinates(); out[0] = if (xy.y.isOdd()) 3 else 2; - out[1..].* = xy.x.toBytes(.Big); + out[1..].* = xy.x.toBytes(.big); return out; } @@ -169,15 +169,15 @@ pub const Secp256k1 = struct { var out: [65]u8 = undefined; out[0] = 4; const xy = p.affineCoordinates(); - out[1..33].* = xy.x.toBytes(.Big); - out[33..65].* = xy.y.toBytes(.Big); + out[1..33].* = xy.x.toBytes(.big); + out[33..65].* = xy.y.toBytes(.big); return out; } /// Return a random point. pub fn random() Secp256k1 { - const n = scalar.random(.Little); - return basePoint.mul(n, .Little) catch unreachable; + const n = scalar.random(.little); + return basePoint.mul(n, .little) catch unreachable; } /// Flip the sign of the X coordinate. @@ -428,7 +428,7 @@ pub const Secp256k1 = struct { /// Multiply an elliptic curve point by a scalar. /// Return error.IdentityElement if the result is the identity element. pub fn mul(p: Secp256k1, s_: [32]u8, endian: std.builtin.Endian) IdentityElementError!Secp256k1 { - const s = if (endian == .Little) s_ else Fe.orderSwap(s_); + const s = if (endian == .little) s_ else Fe.orderSwap(s_); if (p.is_base) { return pcMul16(&basePointPc, s, false); } @@ -440,24 +440,24 @@ pub const Secp256k1 = struct { /// Multiply an elliptic curve point by a *PUBLIC* scalar *IN VARIABLE TIME* /// This can be used for signature verification. pub fn mulPublic(p: Secp256k1, s_: [32]u8, endian: std.builtin.Endian) (IdentityElementError || NonCanonicalError)!Secp256k1 { - const s = if (endian == .Little) s_ else Fe.orderSwap(s_); - const zero = comptime scalar.Scalar.zero.toBytes(.Little); + const s = if (endian == .little) s_ else Fe.orderSwap(s_); + const zero = comptime scalar.Scalar.zero.toBytes(.little); if (mem.eql(u8, &zero, &s)) { return error.IdentityElement; } const pc = precompute(p, 8); var lambda_p = try pcMul(&pc, Endormorphism.lambda_s, true); - var split_scalar = try Endormorphism.splitScalar(s, .Little); + var split_scalar = try Endormorphism.splitScalar(s, .little); var px = p; // If a key is negative, flip the sign to keep it half-sized, // and flip the sign of the Y point coordinate to compensate. if (split_scalar.r1[split_scalar.r1.len / 2] != 0) { - split_scalar.r1 = scalar.neg(split_scalar.r1, .Little) catch zero; + split_scalar.r1 = scalar.neg(split_scalar.r1, .little) catch zero; px = px.neg(); } if (split_scalar.r2[split_scalar.r2.len / 2] != 0) { - split_scalar.r2 = scalar.neg(split_scalar.r2, .Little) catch zero; + split_scalar.r2 = scalar.neg(split_scalar.r2, .little) catch zero; lambda_p = lambda_p.neg(); } return mulDoubleBasePublicEndo(px, split_scalar.r1, lambda_p, split_scalar.r2); @@ -502,8 +502,8 @@ pub const Secp256k1 = struct { /// Double-base multiplication of public parameters - Compute (p1*s1)+(p2*s2) *IN VARIABLE TIME* /// This can be used for signature verification. pub fn mulDoubleBasePublic(p1: Secp256k1, s1_: [32]u8, p2: Secp256k1, s2_: [32]u8, endian: std.builtin.Endian) IdentityElementError!Secp256k1 { - const s1 = if (endian == .Little) s1_ else Fe.orderSwap(s1_); - const s2 = if (endian == .Little) s2_ else Fe.orderSwap(s2_); + const s1 = if (endian == .little) s1_ else Fe.orderSwap(s1_); + const s2 = if (endian == .little) s2_ else Fe.orderSwap(s2_); try p1.rejectIdentity(); var pc1_array: [9]Secp256k1 = undefined; const pc1 = if (p1.is_base) basePointPc[0..9] else pc: { diff --git a/lib/std/crypto/pcurves/secp256k1/scalar.zig b/lib/std/crypto/pcurves/secp256k1/scalar.zig index 2a40c9bf96..dfb9a7f5e6 100644 --- a/lib/std/crypto/pcurves/secp256k1/scalar.zig +++ b/lib/std/crypto/pcurves/secp256k1/scalar.zig @@ -174,7 +174,7 @@ pub const Scalar = struct { var s: [48]u8 = undefined; while (true) { crypto.random.bytes(&s); - const n = Scalar.fromBytes48(s, .Little); + const n = Scalar.fromBytes48(s, .little); if (!n.isZero()) { return n; } @@ -191,7 +191,7 @@ const ScalarDouble = struct { debug.assert(bits > 0 and bits <= 512 and bits >= Fe.saturated_bits and bits <= Fe.saturated_bits * 3); var s = s_; - if (endian == .Big) { + if (endian == .big) { for (s_, 0..) |x, i| s[s.len - 1 - i] = x; } var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero }; @@ -199,19 +199,19 @@ const ScalarDouble = struct { var b = [_]u8{0} ** encoded_length; const len = @min(s.len, 24); b[0..len].* = s[0..len].*; - t.x1 = Fe.fromBytes(b, .Little) catch unreachable; + t.x1 = Fe.fromBytes(b, .little) catch unreachable; } if (s_.len >= 24) { var b = [_]u8{0} ** encoded_length; const len = @min(s.len - 24, 24); b[0..len].* = s[24..][0..len].*; - t.x2 = Fe.fromBytes(b, .Little) catch unreachable; + t.x2 = Fe.fromBytes(b, .little) catch unreachable; } if (s_.len >= 48) { var b = [_]u8{0} ** encoded_length; const len = s.len - 48; b[0..len].* = s[48..][0..len].*; - t.x3 = Fe.fromBytes(b, .Little) catch unreachable; + t.x3 = Fe.fromBytes(b, .little) catch unreachable; } return t; } diff --git a/lib/std/crypto/pcurves/tests/p256.zig b/lib/std/crypto/pcurves/tests/p256.zig index 716f730dc7..7da68044f8 100644 --- a/lib/std/crypto/pcurves/tests/p256.zig +++ b/lib/std/crypto/pcurves/tests/p256.zig @@ -5,12 +5,12 @@ const testing = std.testing; const P256 = @import("../p256.zig").P256; test "p256 ECDH key exchange" { - const dha = P256.scalar.random(.Little); - const dhb = P256.scalar.random(.Little); - const dhA = try P256.basePoint.mul(dha, .Little); - const dhB = try P256.basePoint.mul(dhb, .Little); - const shareda = try dhA.mul(dhb, .Little); - const sharedb = try dhB.mul(dha, .Little); + const dha = P256.scalar.random(.little); + const dhb = P256.scalar.random(.little); + const dhA = try P256.basePoint.mul(dha, .little); + const dhB = try P256.basePoint.mul(dhb, .little); + const shareda = try dhA.mul(dhb, .little); + const sharedb = try dhB.mul(dha, .little); try testing.expect(shareda.equivalent(sharedb)); } @@ -21,7 +21,7 @@ test "p256 point from affine coordinates" { _ = try fmt.hexToBytes(&xs, xh); var ys: [32]u8 = undefined; _ = try fmt.hexToBytes(&ys, yh); - var p = try P256.fromSerializedAffineCoordinates(xs, ys, .Big); + var p = try P256.fromSerializedAffineCoordinates(xs, ys, .big); try testing.expect(p.equivalent(P256.basePoint)); } @@ -44,7 +44,7 @@ test "p256 test vectors" { p = p.add(P256.basePoint); var xs: [32]u8 = undefined; _ = try fmt.hexToBytes(&xs, xh); - try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs); + try testing.expectEqualSlices(u8, &x.toBytes(.big), &xs); } } @@ -61,7 +61,7 @@ test "p256 test vectors - doubling" { p = p.dbl(); var xs: [32]u8 = undefined; _ = try fmt.hexToBytes(&xs, xh); - try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs); + try testing.expectEqualSlices(u8, &x.toBytes(.big), &xs); } } @@ -80,20 +80,20 @@ test "p256 uncompressed sec1 encoding/decoding" { } test "p256 public key is the neutral element" { - const n = P256.scalar.Scalar.zero.toBytes(.Little); + const n = P256.scalar.Scalar.zero.toBytes(.little); const p = P256.random(); - try testing.expectError(error.IdentityElement, p.mul(n, .Little)); + try testing.expectError(error.IdentityElement, p.mul(n, .little)); } test "p256 public key is the neutral element (public verification)" { - const n = P256.scalar.Scalar.zero.toBytes(.Little); + const n = P256.scalar.Scalar.zero.toBytes(.little); const p = P256.random(); - try testing.expectError(error.IdentityElement, p.mulPublic(n, .Little)); + try testing.expectError(error.IdentityElement, p.mulPublic(n, .little)); } test "p256 field element non-canonical encoding" { const s = [_]u8{0xff} ** 32; - try testing.expectError(error.NonCanonical, P256.Fe.fromBytes(s, .Little)); + try testing.expectError(error.NonCanonical, P256.Fe.fromBytes(s, .little)); } test "p256 neutral element decoding" { @@ -107,8 +107,8 @@ test "p256 double base multiplication" { const p2 = P256.basePoint.dbl(); const s1 = [_]u8{0x01} ** 32; const s2 = [_]u8{0x02} ** 32; - const pr1 = try P256.mulDoubleBasePublic(p1, s1, p2, s2, .Little); - const pr2 = (try p1.mul(s1, .Little)).add(try p2.mul(s2, .Little)); + const pr1 = try P256.mulDoubleBasePublic(p1, s1, p2, s2, .little); + const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); try testing.expect(pr1.equivalent(pr2)); } @@ -117,8 +117,8 @@ test "p256 double base multiplication with large scalars" { const p2 = P256.basePoint.dbl(); const s1 = [_]u8{0xee} ** 32; const s2 = [_]u8{0xdd} ** 32; - const pr1 = try P256.mulDoubleBasePublic(p1, s1, p2, s2, .Little); - const pr2 = (try p1.mul(s1, .Little)).add(try p2.mul(s2, .Little)); + const pr1 = try P256.mulDoubleBasePublic(p1, s1, p2, s2, .little); + const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); try testing.expect(pr1.equivalent(pr2)); } @@ -130,9 +130,9 @@ test "p256 scalar inverse" { const scalar = try P256.scalar.Scalar.fromBytes(.{ 0x94, 0xa1, 0xbb, 0xb1, 0x4b, 0x90, 0x6a, 0x61, 0xa2, 0x80, 0xf2, 0x45, 0xf9, 0xe9, 0x3c, 0x7f, 0x3b, 0x4a, 0x62, 0x47, 0x82, 0x4f, 0x5d, 0x33, 0xb9, 0x67, 0x07, 0x87, 0x64, 0x2a, 0x68, 0xde, - }, .Big); + }, .big); const inverse = scalar.invert(); - try std.testing.expectEqualSlices(u8, &out, &inverse.toBytes(.Big)); + try std.testing.expectEqualSlices(u8, &out, &inverse.toBytes(.big)); } test "p256 scalar parity" { diff --git a/lib/std/crypto/pcurves/tests/p384.zig b/lib/std/crypto/pcurves/tests/p384.zig index 1763cfcfa5..e51a683136 100644 --- a/lib/std/crypto/pcurves/tests/p384.zig +++ b/lib/std/crypto/pcurves/tests/p384.zig @@ -5,12 +5,12 @@ const testing = std.testing; const P384 = @import("../p384.zig").P384; test "p384 ECDH key exchange" { - const dha = P384.scalar.random(.Little); - const dhb = P384.scalar.random(.Little); - const dhA = try P384.basePoint.mul(dha, .Little); - const dhB = try P384.basePoint.mul(dhb, .Little); - const shareda = try dhA.mul(dhb, .Little); - const sharedb = try dhB.mul(dha, .Little); + const dha = P384.scalar.random(.little); + const dhb = P384.scalar.random(.little); + const dhA = try P384.basePoint.mul(dha, .little); + const dhB = try P384.basePoint.mul(dhb, .little); + const shareda = try dhA.mul(dhb, .little); + const sharedb = try dhB.mul(dha, .little); try testing.expect(shareda.equivalent(sharedb)); } @@ -21,7 +21,7 @@ test "p384 point from affine coordinates" { _ = try fmt.hexToBytes(&xs, xh); var ys: [48]u8 = undefined; _ = try fmt.hexToBytes(&ys, yh); - var p = try P384.fromSerializedAffineCoordinates(xs, ys, .Big); + var p = try P384.fromSerializedAffineCoordinates(xs, ys, .big); try testing.expect(p.equivalent(P384.basePoint)); } @@ -45,7 +45,7 @@ test "p384 test vectors" { p = p.add(P384.basePoint); var xs: [48]u8 = undefined; _ = try fmt.hexToBytes(&xs, xh); - try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs); + try testing.expectEqualSlices(u8, &x.toBytes(.big), &xs); } } @@ -62,7 +62,7 @@ test "p384 test vectors - doubling" { p = p.dbl(); var xs: [48]u8 = undefined; _ = try fmt.hexToBytes(&xs, xh); - try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs); + try testing.expectEqualSlices(u8, &x.toBytes(.big), &xs); } } @@ -83,20 +83,20 @@ test "p384 uncompressed sec1 encoding/decoding" { } test "p384 public key is the neutral element" { - const n = P384.scalar.Scalar.zero.toBytes(.Little); + const n = P384.scalar.Scalar.zero.toBytes(.little); const p = P384.random(); - try testing.expectError(error.IdentityElement, p.mul(n, .Little)); + try testing.expectError(error.IdentityElement, p.mul(n, .little)); } test "p384 public key is the neutral element (public verification)" { - const n = P384.scalar.Scalar.zero.toBytes(.Little); + const n = P384.scalar.Scalar.zero.toBytes(.little); const p = P384.random(); - try testing.expectError(error.IdentityElement, p.mulPublic(n, .Little)); + try testing.expectError(error.IdentityElement, p.mulPublic(n, .little)); } test "p384 field element non-canonical encoding" { const s = [_]u8{0xff} ** 48; - try testing.expectError(error.NonCanonical, P384.Fe.fromBytes(s, .Little)); + try testing.expectError(error.NonCanonical, P384.Fe.fromBytes(s, .little)); } test "p384 neutral element decoding" { @@ -110,8 +110,8 @@ test "p384 double base multiplication" { const p2 = P384.basePoint.dbl(); const s1 = [_]u8{0x01} ** 48; const s2 = [_]u8{0x02} ** 48; - const pr1 = try P384.mulDoubleBasePublic(p1, s1, p2, s2, .Little); - const pr2 = (try p1.mul(s1, .Little)).add(try p2.mul(s2, .Little)); + const pr1 = try P384.mulDoubleBasePublic(p1, s1, p2, s2, .little); + const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); try testing.expect(pr1.equivalent(pr2)); } @@ -120,8 +120,8 @@ test "p384 double base multiplication with large scalars" { const p2 = P384.basePoint.dbl(); const s1 = [_]u8{0xee} ** 48; const s2 = [_]u8{0xdd} ** 48; - const pr1 = try P384.mulDoubleBasePublic(p1, s1, p2, s2, .Little); - const pr2 = (try p1.mul(s1, .Little)).add(try p2.mul(s2, .Little)); + const pr1 = try P384.mulDoubleBasePublic(p1, s1, p2, s2, .little); + const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); try testing.expect(pr1.equivalent(pr2)); } @@ -134,10 +134,10 @@ test "p384 scalar inverse" { 0x94, 0xa1, 0xbb, 0xb1, 0x4b, 0x90, 0x6a, 0x61, 0xa2, 0x80, 0xf2, 0x45, 0xf9, 0xe9, 0x3c, 0x7f, 0x3b, 0x4a, 0x62, 0x47, 0x82, 0x4f, 0x5d, 0x33, 0xb9, 0x67, 0x07, 0x87, 0x64, 0x2a, 0x68, 0xde, 0x38, 0x36, 0xe8, 0x0f, 0xa2, 0x84, 0x6b, 0x4e, 0xf3, 0x9a, 0x02, 0x31, 0x24, 0x41, 0x22, 0xca, - }, .Big); + }, .big); const inverse = scalar.invert(); const inverse2 = inverse.invert(); - try testing.expectEqualSlices(u8, &out, &inverse.toBytes(.Big)); + try testing.expectEqualSlices(u8, &out, &inverse.toBytes(.big)); try testing.expect(inverse2.equivalent(scalar)); const sq = scalar.sq(); diff --git a/lib/std/crypto/pcurves/tests/secp256k1.zig b/lib/std/crypto/pcurves/tests/secp256k1.zig index b651f01e04..0fb2a13cf8 100644 --- a/lib/std/crypto/pcurves/tests/secp256k1.zig +++ b/lib/std/crypto/pcurves/tests/secp256k1.zig @@ -5,22 +5,22 @@ const testing = std.testing; const Secp256k1 = @import("../secp256k1.zig").Secp256k1; test "secp256k1 ECDH key exchange" { - const dha = Secp256k1.scalar.random(.Little); - const dhb = Secp256k1.scalar.random(.Little); - const dhA = try Secp256k1.basePoint.mul(dha, .Little); - const dhB = try Secp256k1.basePoint.mul(dhb, .Little); - const shareda = try dhA.mul(dhb, .Little); - const sharedb = try dhB.mul(dha, .Little); + const dha = Secp256k1.scalar.random(.little); + const dhb = Secp256k1.scalar.random(.little); + const dhA = try Secp256k1.basePoint.mul(dha, .little); + const dhB = try Secp256k1.basePoint.mul(dhb, .little); + const shareda = try dhA.mul(dhb, .little); + const sharedb = try dhB.mul(dha, .little); try testing.expect(shareda.equivalent(sharedb)); } test "secp256k1 ECDH key exchange including public multiplication" { - const dha = Secp256k1.scalar.random(.Little); - const dhb = Secp256k1.scalar.random(.Little); - const dhA = try Secp256k1.basePoint.mul(dha, .Little); - const dhB = try Secp256k1.basePoint.mulPublic(dhb, .Little); - const shareda = try dhA.mul(dhb, .Little); - const sharedb = try dhB.mulPublic(dha, .Little); + const dha = Secp256k1.scalar.random(.little); + const dhb = Secp256k1.scalar.random(.little); + const dhA = try Secp256k1.basePoint.mul(dha, .little); + const dhB = try Secp256k1.basePoint.mulPublic(dhb, .little); + const shareda = try dhA.mul(dhb, .little); + const sharedb = try dhB.mulPublic(dha, .little); try testing.expect(shareda.equivalent(sharedb)); } @@ -31,7 +31,7 @@ test "secp256k1 point from affine coordinates" { _ = try fmt.hexToBytes(&xs, xh); var ys: [32]u8 = undefined; _ = try fmt.hexToBytes(&ys, yh); - var p = try Secp256k1.fromSerializedAffineCoordinates(xs, ys, .Big); + var p = try Secp256k1.fromSerializedAffineCoordinates(xs, ys, .big); try testing.expect(p.equivalent(Secp256k1.basePoint)); } @@ -54,7 +54,7 @@ test "secp256k1 test vectors" { p = p.add(Secp256k1.basePoint); var xs: [32]u8 = undefined; _ = try fmt.hexToBytes(&xs, xh); - try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs); + try testing.expectEqualSlices(u8, &x.toBytes(.big), &xs); } } @@ -72,7 +72,7 @@ test "secp256k1 test vectors - doubling" { p = p.dbl(); var xs: [32]u8 = undefined; _ = try fmt.hexToBytes(&xs, xh); - try testing.expectEqualSlices(u8, &x.toBytes(.Big), &xs); + try testing.expectEqualSlices(u8, &x.toBytes(.big), &xs); } } @@ -91,20 +91,20 @@ test "secp256k1 uncompressed sec1 encoding/decoding" { } test "secp256k1 public key is the neutral element" { - const n = Secp256k1.scalar.Scalar.zero.toBytes(.Little); + const n = Secp256k1.scalar.Scalar.zero.toBytes(.little); const p = Secp256k1.random(); - try testing.expectError(error.IdentityElement, p.mul(n, .Little)); + try testing.expectError(error.IdentityElement, p.mul(n, .little)); } test "secp256k1 public key is the neutral element (public verification)" { - const n = Secp256k1.scalar.Scalar.zero.toBytes(.Little); + const n = Secp256k1.scalar.Scalar.zero.toBytes(.little); const p = Secp256k1.random(); - try testing.expectError(error.IdentityElement, p.mulPublic(n, .Little)); + try testing.expectError(error.IdentityElement, p.mulPublic(n, .little)); } test "secp256k1 field element non-canonical encoding" { const s = [_]u8{0xff} ** 32; - try testing.expectError(error.NonCanonical, Secp256k1.Fe.fromBytes(s, .Little)); + try testing.expectError(error.NonCanonical, Secp256k1.Fe.fromBytes(s, .little)); } test "secp256k1 neutral element decoding" { @@ -118,8 +118,8 @@ test "secp256k1 double base multiplication" { const p2 = Secp256k1.basePoint.dbl(); const s1 = [_]u8{0x01} ** 32; const s2 = [_]u8{0x02} ** 32; - const pr1 = try Secp256k1.mulDoubleBasePublic(p1, s1, p2, s2, .Little); - const pr2 = (try p1.mul(s1, .Little)).add(try p2.mul(s2, .Little)); + const pr1 = try Secp256k1.mulDoubleBasePublic(p1, s1, p2, s2, .little); + const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); try testing.expect(pr1.equivalent(pr2)); } @@ -131,9 +131,9 @@ test "secp256k1 scalar inverse" { const scalar = try Secp256k1.scalar.Scalar.fromBytes(.{ 0x94, 0xa1, 0xbb, 0xb1, 0x4b, 0x90, 0x6a, 0x61, 0xa2, 0x80, 0xf2, 0x45, 0xf9, 0xe9, 0x3c, 0x7f, 0x3b, 0x4a, 0x62, 0x47, 0x82, 0x4f, 0x5d, 0x33, 0xb9, 0x67, 0x07, 0x87, 0x64, 0x2a, 0x68, 0xde, - }, .Big); + }, .big); const inverse = scalar.invert(); - try std.testing.expectEqualSlices(u8, &out, &inverse.toBytes(.Big)); + try std.testing.expectEqualSlices(u8, &out, &inverse.toBytes(.big)); } test "secp256k1 scalar parity" { diff --git a/lib/std/crypto/poly1305.zig b/lib/std/crypto/poly1305.zig index f8764e1f22..67e1b630c1 100644 --- a/lib/std/crypto/poly1305.zig +++ b/lib/std/crypto/poly1305.zig @@ -22,12 +22,12 @@ pub const Poly1305 = struct { pub fn init(key: *const [key_length]u8) Poly1305 { return Poly1305{ .r = [_]u64{ - mem.readInt(u64, key[0..8], .Little) & 0x0ffffffc0fffffff, - mem.readInt(u64, key[8..16], .Little) & 0x0ffffffc0ffffffc, + mem.readInt(u64, key[0..8], .little) & 0x0ffffffc0fffffff, + mem.readInt(u64, key[8..16], .little) & 0x0ffffffc0ffffffc, }, .pad = [_]u64{ - mem.readInt(u64, key[16..24], .Little), - mem.readInt(u64, key[24..32], .Little), + mem.readInt(u64, key[16..24], .little), + mem.readInt(u64, key[24..32], .little), }, }; } @@ -56,8 +56,8 @@ pub const Poly1305 = struct { var i: usize = 0; while (i + block_length <= m.len) : (i += block_length) { - const in0 = mem.readInt(u64, m[i..][0..8], .Little); - const in1 = mem.readInt(u64, m[i + 8 ..][0..8], .Little); + const in0 = mem.readInt(u64, m[i..][0..8], .little); + const in1 = mem.readInt(u64, m[i + 8 ..][0..8], .little); // Add the input message to H var v = @addWithOverflow(h0, in0); @@ -182,8 +182,8 @@ pub const Poly1305 = struct { const c = ((h0 & st.pad[0]) | ((h0 | st.pad[0]) & ~st.h[0])) >> 63; st.h[1] = h1 +% st.pad[1] +% c; - mem.writeInt(u64, out[0..8], st.h[0], .Little); - mem.writeInt(u64, out[8..16], st.h[1], .Little); + mem.writeInt(u64, out[0..8], st.h[0], .little); + mem.writeInt(u64, out[8..16], st.h[1], .little); utils.secureZero(u8, @as([*]u8, @ptrCast(st))[0..@sizeOf(Poly1305)]); } diff --git a/lib/std/crypto/salsa20.zig b/lib/std/crypto/salsa20.zig index 6e170eb037..b83db0a317 100644 --- a/lib/std/crypto/salsa20.zig +++ b/lib/std/crypto/salsa20.zig @@ -29,10 +29,10 @@ fn SalsaVecImpl(comptime rounds: comptime_int) type { fn initContext(key: [8]u32, d: [4]u32) BlockVec { const c = "expand 32-byte k"; const constant_le = comptime [4]u32{ - mem.readInt(u32, c[0..4], .Little), - mem.readInt(u32, c[4..8], .Little), - mem.readInt(u32, c[8..12], .Little), - mem.readInt(u32, c[12..16], .Little), + mem.readInt(u32, c[0..4], .little), + mem.readInt(u32, c[4..8], .little), + mem.readInt(u32, c[8..12], .little), + mem.readInt(u32, c[12..16], .little), }; return BlockVec{ Lane{ key[0], key[1], key[2], key[3] }, @@ -112,10 +112,10 @@ fn SalsaVecImpl(comptime rounds: comptime_int) type { fn hashToBytes(out: *[64]u8, x: BlockVec) void { var i: usize = 0; while (i < 4) : (i += 1) { - mem.writeInt(u32, out[16 * i + 0 ..][0..4], x[i][0], .Little); - mem.writeInt(u32, out[16 * i + 4 ..][0..4], x[i][1], .Little); - mem.writeInt(u32, out[16 * i + 8 ..][0..4], x[i][2], .Little); - mem.writeInt(u32, out[16 * i + 12 ..][0..4], x[i][3], .Little); + mem.writeInt(u32, out[16 * i + 0 ..][0..4], x[i][0], .little); + mem.writeInt(u32, out[16 * i + 4 ..][0..4], x[i][1], .little); + mem.writeInt(u32, out[16 * i + 8 ..][0..4], x[i][2], .little); + mem.writeInt(u32, out[16 * i + 12 ..][0..4], x[i][3], .little); } } @@ -158,20 +158,20 @@ fn SalsaVecImpl(comptime rounds: comptime_int) type { fn hsalsa(input: [16]u8, key: [32]u8) [32]u8 { var c: [4]u32 = undefined; for (c, 0..) |_, i| { - c[i] = mem.readInt(u32, input[4 * i ..][0..4], .Little); + c[i] = mem.readInt(u32, input[4 * i ..][0..4], .little); } const ctx = initContext(keyToWords(key), c); var x: BlockVec = undefined; salsaCore(x[0..], ctx, false); var out: [32]u8 = undefined; - mem.writeInt(u32, out[0..4], x[0][0], .Little); - mem.writeInt(u32, out[4..8], x[1][1], .Little); - mem.writeInt(u32, out[8..12], x[2][2], .Little); - mem.writeInt(u32, out[12..16], x[3][3], .Little); - mem.writeInt(u32, out[16..20], x[1][2], .Little); - mem.writeInt(u32, out[20..24], x[1][3], .Little); - mem.writeInt(u32, out[24..28], x[2][0], .Little); - mem.writeInt(u32, out[28..32], x[2][1], .Little); + mem.writeInt(u32, out[0..4], x[0][0], .little); + mem.writeInt(u32, out[4..8], x[1][1], .little); + mem.writeInt(u32, out[8..12], x[2][2], .little); + mem.writeInt(u32, out[12..16], x[3][3], .little); + mem.writeInt(u32, out[16..20], x[1][2], .little); + mem.writeInt(u32, out[20..24], x[1][3], .little); + mem.writeInt(u32, out[24..28], x[2][0], .little); + mem.writeInt(u32, out[28..32], x[2][1], .little); return out; } }; @@ -184,10 +184,10 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type { fn initContext(key: [8]u32, d: [4]u32) BlockVec { const c = "expand 32-byte k"; const constant_le = comptime [4]u32{ - mem.readInt(u32, c[0..4], .Little), - mem.readInt(u32, c[4..8], .Little), - mem.readInt(u32, c[8..12], .Little), - mem.readInt(u32, c[12..16], .Little), + mem.readInt(u32, c[0..4], .little), + mem.readInt(u32, c[4..8], .little), + mem.readInt(u32, c[8..12], .little), + mem.readInt(u32, c[12..16], .little), }; return BlockVec{ constant_le[0], key[0], key[1], key[2], @@ -241,7 +241,7 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type { fn hashToBytes(out: *[64]u8, x: BlockVec) void { for (x, 0..) |w, i| { - mem.writeInt(u32, out[i * 4 ..][0..4], w, .Little); + mem.writeInt(u32, out[i * 4 ..][0..4], w, .little); } } @@ -283,20 +283,20 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type { fn hsalsa(input: [16]u8, key: [32]u8) [32]u8 { var c: [4]u32 = undefined; for (c, 0..) |_, i| { - c[i] = mem.readInt(u32, input[4 * i ..][0..4], .Little); + c[i] = mem.readInt(u32, input[4 * i ..][0..4], .little); } const ctx = initContext(keyToWords(key), c); var x: BlockVec = undefined; salsaCore(x[0..], ctx, false); var out: [32]u8 = undefined; - mem.writeInt(u32, out[0..4], x[0], .Little); - mem.writeInt(u32, out[4..8], x[5], .Little); - mem.writeInt(u32, out[8..12], x[10], .Little); - mem.writeInt(u32, out[12..16], x[15], .Little); - mem.writeInt(u32, out[16..20], x[6], .Little); - mem.writeInt(u32, out[20..24], x[7], .Little); - mem.writeInt(u32, out[24..28], x[8], .Little); - mem.writeInt(u32, out[28..32], x[9], .Little); + mem.writeInt(u32, out[0..4], x[0], .little); + mem.writeInt(u32, out[4..8], x[5], .little); + mem.writeInt(u32, out[8..12], x[10], .little); + mem.writeInt(u32, out[12..16], x[15], .little); + mem.writeInt(u32, out[16..20], x[6], .little); + mem.writeInt(u32, out[20..24], x[7], .little); + mem.writeInt(u32, out[24..28], x[8], .little); + mem.writeInt(u32, out[28..32], x[9], .little); return out; } }; @@ -308,7 +308,7 @@ fn keyToWords(key: [32]u8) [8]u32 { var k: [8]u32 = undefined; var i: usize = 0; while (i < 8) : (i += 1) { - k[i] = mem.readInt(u32, key[i * 4 ..][0..4], .Little); + k[i] = mem.readInt(u32, key[i * 4 ..][0..4], .little); } return k; } @@ -335,8 +335,8 @@ pub fn Salsa(comptime rounds: comptime_int) type { debug.assert(in.len == out.len); var d: [4]u32 = undefined; - d[0] = mem.readInt(u32, nonce[0..4], .Little); - d[1] = mem.readInt(u32, nonce[4..8], .Little); + d[0] = mem.readInt(u32, nonce[0..4], .little); + d[1] = mem.readInt(u32, nonce[4..8], .little); d[2] = @as(u32, @truncate(counter)); d[3] = @as(u32, @truncate(counter >> 32)); SalsaImpl(rounds).salsaXor(out, in, keyToWords(key), d); diff --git a/lib/std/crypto/scrypt.zig b/lib/std/crypto/scrypt.zig index 4589902aaf..cf16476d92 100644 --- a/lib/std/crypto/scrypt.zig +++ b/lib/std/crypto/scrypt.zig @@ -91,7 +91,7 @@ fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) var y: []align(16) u32 = @alignCast(xy[32 * r ..]); for (x, 0..) |*v1, j| { - v1.* = mem.readInt(u32, b[4 * j ..][0..4], .Little); + v1.* = mem.readInt(u32, b[4 * j ..][0..4], .little); } 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) } for (x, 0..) |v1, j| { - mem.writeInt(u32, b[4 * j ..][0..4], v1, .Little); + mem.writeInt(u32, b[4 * j ..][0..4], v1, .little); } } @@ -361,7 +361,7 @@ const crypt_format = struct { std.debug.assert(dst.len == decodedLen(src.len)); var i: usize = 0; while (i < src.len / 4) : (i += 1) { - mem.writeInt(u24, dst[i * 3 ..][0..3], try intDecode(u24, src[i * 4 ..][0..4]), .Little); + mem.writeInt(u24, dst[i * 3 ..][0..3], try intDecode(u24, src[i * 4 ..][0..4]), .little); } const leftover = src[i * 4 ..]; var v: u24 = 0; @@ -377,7 +377,7 @@ const crypt_format = struct { std.debug.assert(dst.len == encodedLen(src.len)); var i: usize = 0; while (i < src.len / 3) : (i += 1) { - intEncode(dst[i * 4 ..][0..4], mem.readInt(u24, src[i * 3 ..][0..3], .Little)); + intEncode(dst[i * 4 ..][0..4], mem.readInt(u24, src[i * 3 ..][0..3], .little)); } const leftover = src[i * 3 ..]; var v: u24 = 0; diff --git a/lib/std/crypto/sha1.zig b/lib/std/crypto/sha1.zig index 88a0a33262..2968517b68 100644 --- a/lib/std/crypto/sha1.zig +++ b/lib/std/crypto/sha1.zig @@ -111,7 +111,7 @@ pub const Sha1 = struct { d.round(d.buf[0..]); for (d.s, 0..) |s, j| { - mem.writeInt(u32, out[4 * j ..][0..4], s, .Big); + mem.writeInt(u32, out[4 * j ..][0..4], s, .big); } } @@ -151,7 +151,7 @@ pub const Sha1 = struct { roundParam(0, 1, 2, 3, 4, 15), }; inline for (round0a) |r| { - s[r.i] = mem.readInt(u32, b[r.i * 4 ..][0..4], .Big); + s[r.i] = mem.readInt(u32, b[r.i * 4 ..][0..4], .big); 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])); v[r.b] = math.rotl(u32, v[r.b], @as(u32, 30)); diff --git a/lib/std/crypto/sha2.zig b/lib/std/crypto/sha2.zig index 2beed0549b..31884c7381 100644 --- a/lib/std/crypto/sha2.zig +++ b/lib/std/crypto/sha2.zig @@ -171,7 +171,7 @@ fn Sha2x32(comptime params: Sha2Params32) type { const rr = d.s[0 .. params.digest_bits / 32]; for (rr, 0..) |s, j| { - mem.writeInt(u32, out[4 * j ..][0..4], s, .Big); + mem.writeInt(u32, out[4 * j ..][0..4], s, .big); } } @@ -195,7 +195,7 @@ fn Sha2x32(comptime params: Sha2Params32) type { fn round(d: *Self, b: *const [64]u8) void { var s: [64]u32 align(16) = undefined; for (@as(*align(1) const [16]u32, @ptrCast(b)), 0..) |*elem, i| { - s[i] = mem.readInt(u32, mem.asBytes(elem), .Big); + s[i] = mem.readInt(u32, mem.asBytes(elem), .big); } if (!@inComptime()) { @@ -663,7 +663,7 @@ fn Sha2x64(comptime params: Sha2Params64) type { const rr = d.s[0 .. params.digest_bits / 64]; for (rr, 0..) |s, j| { - mem.writeInt(u64, out[8 * j ..][0..8], s, .Big); + mem.writeInt(u64, out[8 * j ..][0..8], s, .big); } } @@ -678,7 +678,7 @@ fn Sha2x64(comptime params: Sha2Params64) type { var i: usize = 0; while (i < 16) : (i += 1) { - s[i] = mem.readInt(u64, b[i * 8 ..][0..8], .Big); + s[i] = mem.readInt(u64, b[i * 8 ..][0..8], .big); } while (i < 80) : (i += 1) { s[i] = s[i - 16] +% s[i - 7] +% diff --git a/lib/std/crypto/siphash.zig b/lib/std/crypto/siphash.zig index 905fb2c383..5d1ac4f874 100644 --- a/lib/std/crypto/siphash.zig +++ b/lib/std/crypto/siphash.zig @@ -56,8 +56,8 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round msg_len: u8, fn init(key: *const [key_length]u8) Self { - const k0 = mem.readInt(u64, key[0..8], .Little); - const k1 = mem.readInt(u64, key[8..16], .Little); + const k0 = mem.readInt(u64, key[0..8], .little); + const k1 = mem.readInt(u64, key[8..16], .little); var d = Self{ .v0 = k0 ^ 0x736f6d6570736575, @@ -124,7 +124,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round } fn round(self: *Self, b: [8]u8) void { - const m = mem.readInt(u64, &b, .Little); + const m = mem.readInt(u64, &b, .little); self.v3 ^= m; comptime var i: usize = 0; @@ -213,7 +213,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize) /// Return an authentication tag for the current state /// Assumes `out` is less than or equal to `mac_length`. pub fn final(self: *Self, out: *[mac_length]u8) void { - mem.writeInt(T, out, self.state.final(self.buf[0..self.buf_len]), .Little); + mem.writeInt(T, out, self.state.final(self.buf[0..self.buf_len]), .little); } pub fn finalResult(self: *Self) [mac_length]u8 { diff --git a/lib/std/crypto/tls.zig b/lib/std/crypto/tls.zig index 35c49d500e..ae19307b6f 100644 --- a/lib/std/crypto/tls.zig +++ b/lib/std/crypto/tls.zig @@ -370,7 +370,7 @@ pub fn hkdfExpandLabel( const max_context_len = 255; const tls13 = "tls13 "; var buf: [2 + 1 + tls13.len + max_label_len + 1 + max_context_len]u8 = undefined; - mem.writeInt(u16, buf[0..2], len, .Big); + mem.writeInt(u16, buf[0..2], len, .big); buf[2] = @as(u8, @intCast(tls13.len + label.len)); buf[3..][0..tls13.len].* = tls13.*; var i: usize = 3 + tls13.len; diff --git a/lib/std/crypto/tls/Client.zig b/lib/std/crypto/tls/Client.zig index 60c525ba70..5f6b1e4c14 100644 --- a/lib/std/crypto/tls/Client.zig +++ b/lib/std/crypto/tls/Client.zig @@ -332,10 +332,10 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In const pk = PublicKey.fromSec1(server_pub_key) catch { return error.TlsDecryptFailure; }; - const mul = pk.p.mulPublic(secp256r1_kp.secret_key.bytes, .Big) catch { + const mul = pk.p.mulPublic(secp256r1_kp.secret_key.bytes, .big) catch { return error.TlsDecryptFailure; }; - shared_key = &mul.affineCoordinates().x.toBytes(.Big); + shared_key = &mul.affineCoordinates().x.toBytes(.big); }, else => { return error.TlsIllegalParameter; @@ -1049,10 +1049,10 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec) } const ct: tls.ContentType = @enumFromInt(frag[in]); in += 1; - const legacy_version = mem.readInt(u16, frag[in..][0..2], .Big); + const legacy_version = mem.readInt(u16, frag[in..][0..2], .big); in += 2; _ = legacy_version; - const record_len = mem.readInt(u16, frag[in..][0..2], .Big); + const record_len = mem.readInt(u16, frag[in..][0..2], .big); if (record_len > max_ciphertext_len) return error.TlsRecordOverflow; in += 2; const end = in + record_len; @@ -1136,7 +1136,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec) while (true) { const handshake_type: tls.HandshakeType = @enumFromInt(cleartext[ct_i]); ct_i += 1; - const handshake_len = mem.readInt(u24, cleartext[ct_i..][0..3], .Big); + const handshake_len = mem.readInt(u24, cleartext[ct_i..][0..3], .big); ct_i += 3; const next_handshake_i = ct_i + handshake_len; if (next_handshake_i > cleartext.len - 1) @@ -1284,8 +1284,8 @@ const native_endian = builtin.cpu.arch.endian(); inline fn big(x: anytype) @TypeOf(x) { return switch (native_endian) { - .Big => x, - .Little => @byteSwap(x), + .big => x, + .little => @byteSwap(x), }; } diff --git a/lib/std/crypto/utils.zig b/lib/std/crypto/utils.zig index 4eb7281bc8..85e0730a44 100644 --- a/lib/std/crypto/utils.zig +++ b/lib/std/crypto/utils.zig @@ -54,7 +54,7 @@ pub fn timingSafeCompare(comptime T: type, a: []const T, b: []const T, endian: E const Cext = std.meta.Int(.unsigned, bits + 1); var gt: T = 0; var eq: T = 1; - if (endian == .Little) { + if (endian == .little) { var i = a.len; while (i != 0) { i -= 1; @@ -84,7 +84,7 @@ pub fn timingSafeAdd(comptime T: type, a: []const T, b: []const T, result: []T, const len = a.len; debug.assert(len == b.len and len == result.len); var carry: u1 = 0; - if (endian == .Little) { + if (endian == .little) { var i: usize = 0; while (i < len) : (i += 1) { const ov1 = @addWithOverflow(a[i], b[i]); @@ -111,7 +111,7 @@ pub fn timingSafeSub(comptime T: type, a: []const T, b: []const T, result: []T, const len = a.len; debug.assert(len == b.len and len == result.len); var borrow: u1 = 0; - if (endian == .Little) { + if (endian == .little) { var i: usize = 0; while (i < len) : (i += 1) { const ov1 = @subWithOverflow(a[i], b[i]); @@ -165,14 +165,14 @@ test "crypto.utils.timingSafeEql (vectors)" { test "crypto.utils.timingSafeCompare" { var a = [_]u8{10} ** 32; var b = [_]u8{10} ** 32; - try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .eq); - try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .eq); + try testing.expectEqual(timingSafeCompare(u8, &a, &b, .big), .eq); + try testing.expectEqual(timingSafeCompare(u8, &a, &b, .little), .eq); a[31] = 1; - try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .lt); - try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt); + try testing.expectEqual(timingSafeCompare(u8, &a, &b, .big), .lt); + try testing.expectEqual(timingSafeCompare(u8, &a, &b, .little), .lt); a[0] = 20; - try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Big), .gt); - try testing.expectEqual(timingSafeCompare(u8, &a, &b, .Little), .lt); + try testing.expectEqual(timingSafeCompare(u8, &a, &b, .big), .gt); + try testing.expectEqual(timingSafeCompare(u8, &a, &b, .little), .lt); } test "crypto.utils.timingSafe{Add,Sub}" { @@ -185,7 +185,7 @@ test "crypto.utils.timingSafe{Add,Sub}" { while (iterations != 0) : (iterations -= 1) { random.bytes(&a); random.bytes(&b); - const endian = if (iterations % 2 == 0) Endian.Big else Endian.Little; + const endian = if (iterations % 2 == 0) Endian.big else Endian.little; _ = timingSafeSub(u8, &a, &b, &c, endian); // a-b _ = timingSafeAdd(u8, &c, &b, &c, endian); // (a-b)+b try testing.expectEqualSlices(u8, &c, &a); diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 1bf1f7307c..9247ab4047 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -1098,8 +1098,8 @@ pub fn readElfDebugInfo( if (hdr.e_ident[elf.EI_VERSION] != 1) return error.InvalidElfVersion; const endian: std.builtin.Endian = switch (hdr.e_ident[elf.EI_DATA]) { - elf.ELFDATA2LSB => .Little, - elf.ELFDATA2MSB => .Big, + elf.ELFDATA2LSB => .little, + elf.ELFDATA2MSB => .big, else => return error.InvalidElfEndian, }; assert(endian == native_endian); // this is our own debug info @@ -2040,7 +2040,7 @@ pub const ModuleDebugInfo = switch (native_os) { if (missing_debug_info) return error.MissingDebugInfo; var di = DW.DwarfInfo{ - .endian = .Little, + .endian = .little, .sections = sections, .is_macho = true, }; diff --git a/lib/std/elf.zig b/lib/std/elf.zig index 4bb30b854d..7cb36a17ee 100644 --- a/lib/std/elf.zig +++ b/lib/std/elf.zig @@ -497,8 +497,8 @@ pub const Header = struct { if (hdr32.e_ident[EI_VERSION] != 1) return error.InvalidElfVersion; const endian: std.builtin.Endian = switch (hdr32.e_ident[EI_DATA]) { - ELFDATA2LSB => .Little, - ELFDATA2MSB => .Big, + ELFDATA2LSB => .little, + ELFDATA2MSB => .big, else => return error.InvalidElfEndian, }; const need_bswap = endian != native_endian; diff --git a/lib/std/fmt/parse_float/FloatStream.zig b/lib/std/fmt/parse_float/FloatStream.zig index 3b1a33df3a..ad31d15919 100644 --- a/lib/std/fmt/parse_float/FloatStream.zig +++ b/lib/std/fmt/parse_float/FloatStream.zig @@ -98,7 +98,7 @@ pub fn skipChars2(self: *FloatStream, c1: u8, c2: u8) void { } pub fn readU64Unchecked(self: FloatStream) u64 { - return std.mem.readInt(u64, self.slice[self.offset..][0..8], .Little); + return std.mem.readInt(u64, self.slice[self.offset..][0..8], .little); } pub fn readU64(self: FloatStream) ?u64 { diff --git a/lib/std/fmt/parse_float/decimal.zig b/lib/std/fmt/parse_float/decimal.zig index 57751903ab..f7612cffa3 100644 --- a/lib/std/fmt/parse_float/decimal.zig +++ b/lib/std/fmt/parse_float/decimal.zig @@ -260,7 +260,7 @@ pub fn Decimal(comptime T: type) type { if (!isEightDigits(v)) { break; } - std.mem.writeInt(u64, d.digits[d.num_digits..][0..8], v - 0x3030_3030_3030_3030, .Little); + std.mem.writeInt(u64, d.digits[d.num_digits..][0..8], v - 0x3030_3030_3030_3030, .little); d.num_digits += 8; stream.advance(8); } diff --git a/lib/std/fs/path.zig b/lib/std/fs/path.zig index 395b5a335d..55d4490053 100644 --- a/lib/std/fs/path.zig +++ b/lib/std/fs/path.zig @@ -1828,7 +1828,7 @@ test "ComponentIterator windows" { test "ComponentIterator windows UTF-16" { // TODO: Fix on big endian architectures - if (builtin.cpu.arch.endian() != .Little) { + if (builtin.cpu.arch.endian() != .little) { return error.SkipZigTest; } diff --git a/lib/std/hash/cityhash.zig b/lib/std/hash/cityhash.zig index 5c6139fe5e..cd240da964 100644 --- a/lib/std/hash/cityhash.zig +++ b/lib/std/hash/cityhash.zig @@ -6,11 +6,11 @@ inline fn offsetPtr(ptr: [*]const u8, offset: usize) [*]const u8 { } fn fetch32(ptr: [*]const u8, offset: usize) u32 { - return std.mem.readInt(u32, offsetPtr(ptr, offset)[0..4], .Little); + return std.mem.readInt(u32, offsetPtr(ptr, offset)[0..4], .little); } fn fetch64(ptr: [*]const u8, offset: usize) u64 { - return std.mem.readInt(u64, offsetPtr(ptr, offset)[0..8], .Little); + return std.mem.readInt(u64, offsetPtr(ptr, offset)[0..8], .little); } pub const CityHash32 = struct { diff --git a/lib/std/hash/crc.zig b/lib/std/hash/crc.zig index 56376ef675..0ac4de761e 100644 --- a/lib/std/hash/crc.zig +++ b/lib/std/hash/crc.zig @@ -163,7 +163,7 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type { const p = input[i..][0..8]; // Unrolling this way gives ~50Mb/s increase - self.crc ^= std.mem.readInt(u32, p[0..4], .Little); + self.crc ^= std.mem.readInt(u32, p[0..4], .little); self.crc = lookup_tables[0][p[7]] ^ diff --git a/lib/std/hash/murmur.zig b/lib/std/hash/murmur.zig index 80496be24f..a9299f245d 100644 --- a/lib/std/hash/murmur.zig +++ b/lib/std/hash/murmur.zig @@ -18,7 +18,7 @@ pub const Murmur2_32 = struct { var h1: u32 = seed ^ len; for (@as([*]align(1) const u32, @ptrCast(str.ptr))[0..(len >> 2)]) |v| { var k1: u32 = v; - if (native_endian == .Big) + if (native_endian == .big) k1 = @byteSwap(k1); k1 *%= m; k1 ^= k1 >> 24; @@ -102,7 +102,7 @@ pub const Murmur2_64 = struct { var h1: u64 = seed ^ (@as(u64, str.len) *% m); for (@as([*]align(1) const u64, @ptrCast(str.ptr))[0 .. str.len / 8]) |v| { var k1: u64 = v; - if (native_endian == .Big) + if (native_endian == .big) k1 = @byteSwap(k1); k1 *%= m; k1 ^= k1 >> 47; @@ -115,7 +115,7 @@ pub const Murmur2_64 = struct { if (rest > 0) { var k1: u64 = 0; @memcpy(@as([*]u8, @ptrCast(&k1))[0..rest], str[offset..]); - if (native_endian == .Big) + if (native_endian == .big) k1 = @byteSwap(k1); h1 ^= k1; h1 *%= m; @@ -182,7 +182,7 @@ pub const Murmur3_32 = struct { var h1: u32 = seed; for (@as([*]align(1) const u32, @ptrCast(str.ptr))[0..(len >> 2)]) |v| { var k1: u32 = v; - if (native_endian == .Big) + if (native_endian == .big) k1 = @byteSwap(k1); k1 *%= c1; k1 = rotl32(k1, 15); @@ -286,7 +286,7 @@ test "murmur2_32" { var v1: u64 = 0x1234567812345678; var v0le: u32 = v0; var v1le: u64 = v1; - if (native_endian == .Big) { + if (native_endian == .big) { v0le = @byteSwap(v0le); v1le = @byteSwap(v1le); } @@ -310,7 +310,7 @@ test "murmur2_64" { var v1: u64 = 0x1234567812345678; var v0le: u32 = v0; var v1le: u64 = v1; - if (native_endian == .Big) { + if (native_endian == .big) { v0le = @byteSwap(v0le); v1le = @byteSwap(v1le); } @@ -334,7 +334,7 @@ test "murmur3_32" { var v1: u64 = 0x1234567812345678; var v0le: u32 = v0; var v1le: u64 = v1; - if (native_endian == .Big) { + if (native_endian == .big) { v0le = @byteSwap(v0le); v1le = @byteSwap(v1le); } diff --git a/lib/std/hash/verify.zig b/lib/std/hash/verify.zig index c3aae0bcd8..485a1fd976 100644 --- a/lib/std/hash/verify.zig +++ b/lib/std/hash/verify.zig @@ -37,7 +37,7 @@ pub fn smhasher(comptime hash_fn: anytype) u32 { for (0..256) |i| { buf[i] = @intCast(i); const h = hashMaybeSeed(hash_fn, 256 - i, buf[0..i]); - std.mem.writeInt(HashResult, buf_all[i * hash_size ..][0..hash_size], h, .Little); + std.mem.writeInt(HashResult, buf_all[i * hash_size ..][0..hash_size], h, .little); } return @truncate(hashMaybeSeed(hash_fn, 0, buf_all[0..])); diff --git a/lib/std/hash/wyhash.zig b/lib/std/hash/wyhash.zig index d5c96fefbb..4dda2b9b14 100644 --- a/lib/std/hash/wyhash.zig +++ b/lib/std/hash/wyhash.zig @@ -131,7 +131,7 @@ pub const Wyhash = struct { inline fn read(comptime bytes: usize, data: []const u8) u64 { std.debug.assert(bytes <= 8); const T = std.meta.Int(.unsigned, 8 * bytes); - return @as(u64, std.mem.readInt(T, data[0..bytes], .Little)); + return @as(u64, std.mem.readInt(T, data[0..bytes], .little)); } inline fn mum(a: *u64, b: *u64) void { diff --git a/lib/std/hash/xxhash.zig b/lib/std/hash/xxhash.zig index 9e49c7c086..2e4c11e333 100644 --- a/lib/std/hash/xxhash.zig +++ b/lib/std/hash/xxhash.zig @@ -53,10 +53,10 @@ pub const XxHash64 = struct { } fn processStripe(self: *Accumulator, buf: *const [32]u8) void { - self.acc1 = round(self.acc1, mem.readInt(u64, buf[0..8], .Little)); - self.acc2 = round(self.acc2, mem.readInt(u64, buf[8..16], .Little)); - self.acc3 = round(self.acc3, mem.readInt(u64, buf[16..24], .Little)); - self.acc4 = round(self.acc4, mem.readInt(u64, buf[24..32], .Little)); + self.acc1 = round(self.acc1, mem.readInt(u64, buf[0..8], .little)); + self.acc2 = round(self.acc2, mem.readInt(u64, buf[8..16], .little)); + self.acc3 = round(self.acc3, mem.readInt(u64, buf[16..24], .little)); + self.acc4 = round(self.acc4, mem.readInt(u64, buf[24..32], .little)); } fn merge(self: Accumulator) u64 { @@ -139,7 +139,7 @@ pub const XxHash64 = struct { fn finalize8(v: u64, bytes: *const [8]u8) u64 { var acc = v; - const lane = mem.readInt(u64, bytes, .Little); + const lane = mem.readInt(u64, bytes, .little); acc ^= round(0, lane); acc = rotl(u64, acc, 27) *% prime_1; acc +%= prime_4; @@ -148,7 +148,7 @@ pub const XxHash64 = struct { fn finalize4(v: u64, bytes: *const [4]u8) u64 { var acc = v; - const lane = @as(u64, mem.readInt(u32, bytes, .Little)); + const lane = @as(u64, mem.readInt(u32, bytes, .little)); acc ^= lane *% prime_1; acc = rotl(u64, acc, 23) *% prime_2; acc +%= prime_3; @@ -291,10 +291,10 @@ pub const XxHash32 = struct { } fn processStripe(self: *Accumulator, buf: *const [16]u8) void { - self.acc1 = round(self.acc1, mem.readInt(u32, buf[0..4], .Little)); - self.acc2 = round(self.acc2, mem.readInt(u32, buf[4..8], .Little)); - self.acc3 = round(self.acc3, mem.readInt(u32, buf[8..12], .Little)); - self.acc4 = round(self.acc4, mem.readInt(u32, buf[12..16], .Little)); + self.acc1 = round(self.acc1, mem.readInt(u32, buf[0..4], .little)); + self.acc2 = round(self.acc2, mem.readInt(u32, buf[4..8], .little)); + self.acc3 = round(self.acc3, mem.readInt(u32, buf[8..12], .little)); + self.acc4 = round(self.acc4, mem.readInt(u32, buf[12..16], .little)); } fn merge(self: Accumulator) u32 { @@ -390,7 +390,7 @@ pub const XxHash32 = struct { fn finalize4(v: u32, bytes: *const [4]u8) u32 { var acc = v; - const lane = mem.readInt(u32, bytes, .Little); + const lane = mem.readInt(u32, bytes, .little); acc +%= lane *% prime_3; acc = rotl(u32, acc, 17) *% prime_4; return acc; @@ -472,7 +472,7 @@ pub const XxHash3 = struct { } inline fn swap(x: anytype) @TypeOf(x) { - return if (builtin.cpu.arch.endian() == .Big) @byteSwap(x) else x; + return if (builtin.cpu.arch.endian() == .big) @byteSwap(x) else x; } inline fn disableAutoVectorization(x: anytype) void { diff --git a/lib/std/heap/WasmPageAllocator.zig b/lib/std/heap/WasmPageAllocator.zig index 8f484c52f6..0fb45b70d4 100644 --- a/lib/std/heap/WasmPageAllocator.zig +++ b/lib/std/heap/WasmPageAllocator.zig @@ -28,7 +28,7 @@ const PageStatus = enum(u1) { const FreeBlock = struct { data: []u128, - const Io = std.packed_int_array.PackedIntIo(u1, .Little); + const Io = std.packed_int_array.PackedIntIo(u1, .little); fn totalPages(self: FreeBlock) usize { return self.data.len * 128; diff --git a/lib/std/http/Client.zig b/lib/std/http/Client.zig index 74afe53a3e..dd143cc83d 100644 --- a/lib/std/http/Client.zig +++ b/lib/std/http/Client.zig @@ -1581,7 +1581,7 @@ pub fn fetch(client: *Client, allocator: Allocator, options: FetchOptions) !Fetc test { const native_endian = comptime builtin.cpu.arch.endian(); - if (builtin.zig_backend == .stage2_llvm and native_endian == .Big) { + if (builtin.zig_backend == .stage2_llvm and native_endian == .big) { // https://github.com/ziglang/zig/issues/13782 return error.SkipZigTest; } diff --git a/lib/std/http/Server.zig b/lib/std/http/Server.zig index adb1ea0812..cd111ca42f 100644 --- a/lib/std/http/Server.zig +++ b/lib/std/http/Server.zig @@ -739,7 +739,7 @@ test "HTTP server handles a chunked transfer coding request" { if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; const native_endian = comptime builtin.cpu.arch.endian(); - if (builtin.zig_backend == .stage2_llvm and native_endian == .Big) { + if (builtin.zig_backend == .stage2_llvm and native_endian == .big) { // https://github.com/ziglang/zig/issues/13782 return error.SkipZigTest; } diff --git a/lib/std/http/protocol.zig b/lib/std/http/protocol.zig index 74e0207f34..8e458ed09c 100644 --- a/lib/std/http/protocol.zig +++ b/lib/std/http/protocol.zig @@ -617,8 +617,8 @@ inline fn int32(array: *const [4]u8) u32 { inline fn intShift(comptime T: type, x: anytype) T { switch (@import("builtin").cpu.arch.endian()) { - .Little => return @as(T, @truncate(x >> (@bitSizeOf(@TypeOf(x)) - @bitSizeOf(T)))), - .Big => return @as(T, @truncate(x)), + .little => return @as(T, @truncate(x >> (@bitSizeOf(@TypeOf(x)) - @bitSizeOf(T)))), + .big => return @as(T, @truncate(x)), } } diff --git a/lib/std/io/Reader.zig b/lib/std/io/Reader.zig index 4da04a3339..b5dd046867 100644 --- a/lib/std/io/Reader.zig +++ b/lib/std/io/Reader.zig @@ -334,7 +334,7 @@ pub fn readStruct(self: Self, comptime T: type) anyerror!T { pub fn readStructBig(self: Self, comptime T: type) anyerror!T { var res = try self.readStruct(T); - if (native_endian != std.builtin.Endian.Big) { + if (native_endian != std.builtin.Endian.big) { mem.byteSwapAllFields(T, &res); } return res; diff --git a/lib/std/io/bit_reader.zig b/lib/std/io/bit_reader.zig index 7ea2ff5009..1e3911ff57 100644 --- a/lib/std/io/bit_reader.zig +++ b/lib/std/io/bit_reader.zig @@ -63,14 +63,14 @@ pub fn BitReader(comptime endian: std.builtin.Endian, comptime ReaderType: type) const n = if (self.bit_count >= bits) @as(u3, @intCast(bits)) else self.bit_count; const shift = u7_bit_count - n; switch (endian) { - .Big => { + .big => { out_buffer = @as(Buf, self.bit_buffer >> shift); if (n >= u7_bit_count) self.bit_buffer = 0 else self.bit_buffer <<= n; }, - .Little => { + .little => { const value = (self.bit_buffer << shift) >> shift; out_buffer = @as(Buf, value); if (n >= u7_bit_count) @@ -93,7 +93,7 @@ pub fn BitReader(comptime endian: std.builtin.Endian, comptime ReaderType: type) }; switch (endian) { - .Big => { + .big => { if (n >= u8_bit_count) { out_buffer <<= @as(u3, @intCast(u8_bit_count - 1)); out_buffer <<= 1; @@ -109,7 +109,7 @@ pub fn BitReader(comptime endian: std.builtin.Endian, comptime ReaderType: type) self.bit_buffer = @as(u7, @truncate(next_byte << @as(u3, @intCast(n - 1)))); self.bit_count = shift; }, - .Little => { + .little => { if (n >= u8_bit_count) { out_buffer |= @as(Buf, next_byte) << @as(BufShift, @intCast(out_bits.*)); out_bits.* += u8_bit_count; @@ -168,7 +168,7 @@ test "api coverage" { const mem_le = [_]u8{ 0b00011101, 0b10010101 }; var mem_in_be = io.fixedBufferStream(&mem_be); - var bit_stream_be = bitReader(.Big, mem_in_be.reader()); + var bit_stream_be = bitReader(.big, mem_in_be.reader()); var out_bits: usize = undefined; @@ -205,7 +205,7 @@ test "api coverage" { try expectError(error.EndOfStream, bit_stream_be.readBitsNoEof(u1, 1)); var mem_in_le = io.fixedBufferStream(&mem_le); - var bit_stream_le = bitReader(.Little, mem_in_le.reader()); + var bit_stream_le = bitReader(.little, mem_in_le.reader()); try expect(1 == try bit_stream_le.readBits(u2, 1, &out_bits)); try expect(out_bits == 1); diff --git a/lib/std/io/bit_writer.zig b/lib/std/io/bit_writer.zig index ef8f007264..40fd603555 100644 --- a/lib/std/io/bit_writer.zig +++ b/lib/std/io/bit_writer.zig @@ -51,8 +51,8 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type) const high_byte_shift = @as(BufShift, @intCast(buf_bit_count - u8_bit_count)); var in_buffer = switch (endian) { - .Big => buf_value << @as(BufShift, @intCast(buf_bit_count - bits)), - .Little => buf_value, + .big => buf_value << @as(BufShift, @intCast(buf_bit_count - bits)), + .little => buf_value, }; var in_bits = bits; @@ -60,13 +60,13 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type) const bits_remaining = u8_bit_count - self.bit_count; const n = @as(u3, @intCast(if (bits_remaining > bits) bits else bits_remaining)); switch (endian) { - .Big => { + .big => { const shift = @as(BufShift, @intCast(high_byte_shift + self.bit_count)); const v = @as(u8, @intCast(in_buffer >> shift)); self.bit_buffer |= v; in_buffer <<= n; }, - .Little => { + .little => { const v = @as(u8, @truncate(in_buffer)) << @as(u3, @intCast(self.bit_count)); self.bit_buffer |= v; in_buffer >>= n; @@ -86,13 +86,13 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type) //copy bytes until we can't fill one anymore, then leave the rest in bit_buffer while (in_bits >= u8_bit_count) { switch (endian) { - .Big => { + .big => { const v = @as(u8, @intCast(in_buffer >> high_byte_shift)); try self.forward_writer.writeByte(v); in_buffer <<= @as(u3, @intCast(u8_bit_count - 1)); in_buffer <<= 1; }, - .Little => { + .little => { const v = @as(u8, @truncate(in_buffer)); try self.forward_writer.writeByte(v); in_buffer >>= @as(u3, @intCast(u8_bit_count - 1)); @@ -105,8 +105,8 @@ pub fn BitWriter(comptime endian: std.builtin.Endian, comptime WriterType: type) if (in_bits > 0) { self.bit_count = @as(u4, @intCast(in_bits)); self.bit_buffer = switch (endian) { - .Big => @as(u8, @truncate(in_buffer >> high_byte_shift)), - .Little => @as(u8, @truncate(in_buffer)), + .big => @as(u8, @truncate(in_buffer >> high_byte_shift)), + .little => @as(u8, @truncate(in_buffer)), }; } } @@ -148,7 +148,7 @@ test "api coverage" { var mem_le = [_]u8{0} ** 2; var mem_out_be = io.fixedBufferStream(&mem_be); - var bit_stream_be = bitWriter(.Big, mem_out_be.writer()); + var bit_stream_be = bitWriter(.big, mem_out_be.writer()); try bit_stream_be.writeBits(@as(u2, 1), 1); try bit_stream_be.writeBits(@as(u5, 2), 2); @@ -172,7 +172,7 @@ test "api coverage" { try bit_stream_be.writeBits(@as(u0, 0), 0); var mem_out_le = io.fixedBufferStream(&mem_le); - var bit_stream_le = bitWriter(.Little, mem_out_le.writer()); + var bit_stream_le = bitWriter(.little, mem_out_le.writer()); try bit_stream_le.writeBits(@as(u2, 1), 1); try bit_stream_le.writeBits(@as(u5, 2), 2); diff --git a/lib/std/io/test.zig b/lib/std/io/test.zig index 81d7b211cb..6de0fe1e53 100644 --- a/lib/std/io/test.zig +++ b/lib/std/io/test.zig @@ -183,7 +183,7 @@ test "GenericReader methods can return error.EndOfStream" { var fbs = std.io.fixedBufferStream(""); try std.testing.expectError( error.EndOfStream, - fbs.reader().readEnum(enum(u8) { a, b }, .Little), + fbs.reader().readEnum(enum(u8) { a, b }, .little), ); try std.testing.expectError( error.EndOfStream, diff --git a/lib/std/math/big/int.zig b/lib/std/math/big/int.zig index a761151e7b..4051a8cd31 100644 --- a/lib/std/math/big/int.zig +++ b/lib/std/math/big/int.zig @@ -798,7 +798,7 @@ pub const Mutable = struct { const endian_mask: usize = (@sizeOf(Limb) - 1) << 3; var bytes = std.mem.sliceAsBytes(r.limbs); - var bits = std.packed_int_array.PackedIntSliceEndian(u1, .Little).init(bytes, limbs_required * @bitSizeOf(Limb)); + var bits = std.packed_int_array.PackedIntSliceEndian(u1, .little).init(bytes, limbs_required * @bitSizeOf(Limb)); var k: usize = 0; while (k < ((bit_count + 1) / 2)) : (k += 1) { @@ -807,7 +807,7 @@ pub const Mutable = struct { // This "endian mask" remaps a low (LE) byte to the corresponding high // (BE) byte in the Limb, without changing which limbs we are indexing - if (native_endian == .Big) { + if (native_endian == .big) { i ^= endian_mask; rev_i ^= endian_mask; } @@ -821,8 +821,8 @@ pub const Mutable = struct { // Calculate signed-magnitude representation for output if (signedness == .signed) { const last_bit = switch (native_endian) { - .Little => bits.get(bit_count - 1), - .Big => bits.get((bit_count - 1) ^ endian_mask), + .little => bits.get(bit_count - 1), + .big => bits.get((bit_count - 1) ^ endian_mask), }; if (last_bit == 1) { r.bitNotWrap(r.toConst(), .unsigned, bit_count); // Bitwise NOT. @@ -869,7 +869,7 @@ pub const Mutable = struct { // This "endian mask" remaps a low (LE) byte to the corresponding high // (BE) byte in the Limb, without changing which limbs we are indexing - if (native_endian == .Big) { + if (native_endian == .big) { i ^= endian_mask; rev_i ^= endian_mask; } @@ -883,8 +883,8 @@ pub const Mutable = struct { // Calculate signed-magnitude representation for output if (signedness == .signed) { const last_byte = switch (native_endian) { - .Little => bytes[byte_count - 1], - .Big => bytes[(byte_count - 1) ^ endian_mask], + .little => bytes[byte_count - 1], + .big => bytes[(byte_count - 1) ^ endian_mask], }; if (last_byte & (1 << 7) != 0) { // Check sign bit of last byte @@ -1912,8 +1912,8 @@ pub const Mutable = struct { if (signedness == .signed) { const total_bits = bit_offset + bit_count; var last_byte = switch (endian) { - .Little => ((total_bits + 7) / 8) - 1, - .Big => buffer.len - ((total_bits + 7) / 8), + .little => ((total_bits + 7) / 8) - 1, + .big => buffer.len - ((total_bits + 7) / 8), }; const sign_bit = @as(u8, 1) << @as(u3, @intCast((total_bits - 1) % 8)); diff --git a/lib/std/math/big/int_test.zig b/lib/std/math/big/int_test.zig index d85c10f5c9..4a3bf10fcd 100644 --- a/lib/std/math/big/int_test.zig +++ b/lib/std/math/big/int_test.zig @@ -2774,7 +2774,7 @@ test "big int conversion read/write twos complement" { var buffer1 = try testing.allocator.alloc(u8, 64); defer testing.allocator.free(buffer1); - const endians = [_]std.builtin.Endian{ .Little, .Big }; + const endians = [_]std.builtin.Endian{ .little, .big }; const abi_size = 64; for (endians) |endian| { @@ -2804,26 +2804,26 @@ test "big int conversion read twos complement with padding" { // (3) should sign-extend any bits from bit_count to 8 * abi_size var bit_count: usize = 12 * 8 + 1; - a.toConst().writeTwosComplement(buffer1[0..13], .Little); + a.toConst().writeTwosComplement(buffer1[0..13], .little); try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1, 0xaa, 0xaa, 0xaa })); - a.toConst().writeTwosComplement(buffer1[0..13], .Big); + a.toConst().writeTwosComplement(buffer1[0..13], .big); try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xaa, 0xaa, 0xaa })); - a.toConst().writeTwosComplement(buffer1[0..16], .Little); + a.toConst().writeTwosComplement(buffer1[0..16], .little); try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1, 0x0, 0x0, 0x0 })); - a.toConst().writeTwosComplement(buffer1[0..16], .Big); + a.toConst().writeTwosComplement(buffer1[0..16], .big); try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0x0, 0x0, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd })); @memset(buffer1, 0xaa); try a.set(-0x01_02030405_06070809_0a0b0c0d); bit_count = 12 * 8 + 2; - a.toConst().writeTwosComplement(buffer1[0..13], .Little); + a.toConst().writeTwosComplement(buffer1[0..13], .little); try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0xf3, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xaa, 0xaa, 0xaa })); - a.toConst().writeTwosComplement(buffer1[0..13], .Big); + a.toConst().writeTwosComplement(buffer1[0..13], .big); try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf3, 0xaa, 0xaa, 0xaa })); - a.toConst().writeTwosComplement(buffer1[0..16], .Little); + a.toConst().writeTwosComplement(buffer1[0..16], .little); try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0xf3, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0xff, 0xff })); - a.toConst().writeTwosComplement(buffer1[0..16], .Big); + a.toConst().writeTwosComplement(buffer1[0..16], .big); try testing.expect(std.mem.eql(u8, buffer1, &[_]u8{ 0xff, 0xff, 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf3 })); } @@ -2838,13 +2838,13 @@ test "big int write twos complement +/- zero" { // Test zero - m.toConst().writeTwosComplement(buffer1[0..13], .Little); + m.toConst().writeTwosComplement(buffer1[0..13], .little); try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 13) ++ ([_]u8{0xaa} ** 3)))); - m.toConst().writeTwosComplement(buffer1[0..13], .Big); + m.toConst().writeTwosComplement(buffer1[0..13], .big); try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 13) ++ ([_]u8{0xaa} ** 3)))); - m.toConst().writeTwosComplement(buffer1[0..16], .Little); + m.toConst().writeTwosComplement(buffer1[0..16], .little); try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 16)))); - m.toConst().writeTwosComplement(buffer1[0..16], .Big); + m.toConst().writeTwosComplement(buffer1[0..16], .big); try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 16)))); @memset(buffer1, 0xaa); @@ -2852,13 +2852,13 @@ test "big int write twos complement +/- zero" { // Test negative zero - m.toConst().writeTwosComplement(buffer1[0..13], .Little); + m.toConst().writeTwosComplement(buffer1[0..13], .little); try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 13) ++ ([_]u8{0xaa} ** 3)))); - m.toConst().writeTwosComplement(buffer1[0..13], .Big); + m.toConst().writeTwosComplement(buffer1[0..13], .big); try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 13) ++ ([_]u8{0xaa} ** 3)))); - m.toConst().writeTwosComplement(buffer1[0..16], .Little); + m.toConst().writeTwosComplement(buffer1[0..16], .little); try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 16)))); - m.toConst().writeTwosComplement(buffer1[0..16], .Big); + m.toConst().writeTwosComplement(buffer1[0..16], .big); try testing.expect(std.mem.eql(u8, buffer1, &(([_]u8{0} ** 16)))); } @@ -2881,19 +2881,19 @@ test "big int conversion write twos complement with padding" { // Test 0x01_02030405_06070809_0a0b0c0d buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xb }; - m.readTwosComplement(buffer[0..13], bit_count, .Little, .unsigned); + m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); try testing.expect(m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d) == .eq); buffer = &[_]u8{ 0xb, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd }; - m.readTwosComplement(buffer[0..13], bit_count, .Big, .unsigned); + m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); try testing.expect(m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d) == .eq); buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xab, 0xaa, 0xaa, 0xaa }; - m.readTwosComplement(buffer[0..16], bit_count, .Little, .unsigned); + m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned); try testing.expect(m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d) == .eq); buffer = &[_]u8{ 0xaa, 0xaa, 0xaa, 0xab, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd }; - m.readTwosComplement(buffer[0..16], bit_count, .Big, .unsigned); + m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned); try testing.expect(m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d) == .eq); bit_count = @sizeOf(Limb) * 8; @@ -2901,19 +2901,19 @@ test "big int conversion write twos complement with padding" { // Test 0x0a0a0a0a_02030405_06070809_0a0b0c0d buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xaa }; - m.readTwosComplement(buffer[0..13], bit_count, .Little, .unsigned); + m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaa_02030405_06070809_0a0b0c0d))) == .eq); buffer = &[_]u8{ 0xaa, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd }; - m.readTwosComplement(buffer[0..13], bit_count, .Big, .unsigned); + m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaa_02030405_06070809_0a0b0c0d))) == .eq); buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xaa, 0xaa, 0xaa, 0xaa }; - m.readTwosComplement(buffer[0..16], bit_count, .Little, .unsigned); + m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned); try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaaaaaaaa_02030405_06070809_0a0b0c0d))) == .eq); buffer = &[_]u8{ 0xaa, 0xaa, 0xaa, 0xaa, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd }; - m.readTwosComplement(buffer[0..16], bit_count, .Big, .unsigned); + m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned); try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaaaaaaaa_02030405_06070809_0a0b0c0d))) == .eq); bit_count = 12 * 8 + 2; @@ -2921,42 +2921,42 @@ test "big int conversion write twos complement with padding" { // Test -0x01_02030405_06070809_0a0b0c0d buffer = &[_]u8{ 0xf3, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0x02 }; - m.readTwosComplement(buffer[0..13], bit_count, .Little, .signed); + m.readTwosComplement(buffer[0..13], bit_count, .little, .signed); try testing.expect(m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d) == .eq); buffer = &[_]u8{ 0x02, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf3 }; - m.readTwosComplement(buffer[0..13], bit_count, .Big, .signed); + m.readTwosComplement(buffer[0..13], bit_count, .big, .signed); try testing.expect(m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d) == .eq); buffer = &[_]u8{ 0xf3, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0x02, 0xaa, 0xaa, 0xaa }; - m.readTwosComplement(buffer[0..16], bit_count, .Little, .signed); + m.readTwosComplement(buffer[0..16], bit_count, .little, .signed); try testing.expect(m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d) == .eq); buffer = &[_]u8{ 0xaa, 0xaa, 0xaa, 0x02, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf3 }; - m.readTwosComplement(buffer[0..16], bit_count, .Big, .signed); + m.readTwosComplement(buffer[0..16], bit_count, .big, .signed); try testing.expect(m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d) == .eq); // Test 0 buffer = &([_]u8{0} ** 16); - m.readTwosComplement(buffer[0..13], bit_count, .Little, .unsigned); + m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); - m.readTwosComplement(buffer[0..13], bit_count, .Big, .unsigned); + m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); - m.readTwosComplement(buffer[0..16], bit_count, .Little, .unsigned); + m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned); try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); - m.readTwosComplement(buffer[0..16], bit_count, .Big, .unsigned); + m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned); try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); bit_count = 0; buffer = &([_]u8{0xaa} ** 16); - m.readTwosComplement(buffer[0..13], bit_count, .Little, .unsigned); + m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); - m.readTwosComplement(buffer[0..13], bit_count, .Big, .unsigned); + m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); - m.readTwosComplement(buffer[0..16], bit_count, .Little, .unsigned); + m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned); try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); - m.readTwosComplement(buffer[0..16], bit_count, .Big, .unsigned); + m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned); try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); } @@ -2975,15 +2975,15 @@ test "big int conversion write twos complement zero" { var buffer: []const u8 = undefined; buffer = &([_]u8{0} ** 13); - m.readTwosComplement(buffer[0..13], bit_count, .Little, .unsigned); + m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); - m.readTwosComplement(buffer[0..13], bit_count, .Big, .unsigned); + m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); buffer = &([_]u8{0} ** 16); - m.readTwosComplement(buffer[0..16], bit_count, .Little, .unsigned); + m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned); try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); - m.readTwosComplement(buffer[0..16], bit_count, .Big, .unsigned); + m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned); try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq); } diff --git a/lib/std/mem.zig b/lib/std/mem.zig index f8eabb0c8e..420e461ae5 100644 --- a/lib/std/mem.zig +++ b/lib/std/mem.zig @@ -1499,12 +1499,12 @@ test "containsAtLeast" { pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: Endian) ReturnType { var result: ReturnType = 0; switch (endian) { - .Big => { + .big => { for (bytes) |b| { result = (result << 8) | b; } }, - .Little => { + .little => { const ShiftType = math.Log2Int(ReturnType); for (bytes, 0..) |b, index| { result = result | (@as(ReturnType, b) << @as(ShiftType, @intCast(index * 8))); @@ -1539,8 +1539,8 @@ pub fn readVarPackedInt( const pad = @as(Log2N, @intCast(@bitSizeOf(T) - bit_count)); const lowest_byte = switch (endian) { - .Big => bytes.len - (bit_offset / 8) - read_size, - .Little => bit_offset / 8, + .big => bytes.len - (bit_offset / 8) - read_size, + .little => bit_offset / 8, }; const read_bytes = bytes[lowest_byte..][0..read_size]; @@ -1550,7 +1550,7 @@ pub fn readVarPackedInt( const value = if (read_size == 1) b: { break :b @as(uN, @truncate(read_bytes[0] >> bit_shift)); } else b: { - const i: u1 = @intFromBool(endian == .Big); + const i: u1 = @intFromBool(endian == .big); const head = @as(uN, @truncate(read_bytes[i] >> bit_shift)); const tail_shift = @as(Log2N, @intCast(@as(u4, 8) - bit_shift)); const tail = @as(uN, @truncate(read_bytes[1 - i])); @@ -1565,13 +1565,13 @@ pub fn readVarPackedInt( // Copy the value out (respecting endianness), accounting for bit_shift var int: uN = 0; switch (endian) { - .Big => { + .big => { for (read_bytes[0 .. read_size - 1]) |elem| { int = elem | (int << 8); } int = (read_bytes[read_size - 1] >> bit_shift) | (int << (@as(u4, 8) - bit_shift)); }, - .Little => { + .little => { int = read_bytes[0] >> bit_shift; for (read_bytes[1..], 0..) |elem, i| { int |= (@as(uN, elem) << @as(Log2N, @intCast((8 * (i + 1) - bit_shift)))); @@ -1593,23 +1593,23 @@ pub inline fn readInt(comptime T: type, buffer: *const [@divExact(@typeInfo(T).I } test readInt { - try testing.expect(readInt(u0, &[_]u8{}, .Big) == 0x0); - try testing.expect(readInt(u0, &[_]u8{}, .Little) == 0x0); + try testing.expect(readInt(u0, &[_]u8{}, .big) == 0x0); + try testing.expect(readInt(u0, &[_]u8{}, .little) == 0x0); - try testing.expect(readInt(u8, &[_]u8{0x32}, .Big) == 0x32); - try testing.expect(readInt(u8, &[_]u8{0x12}, .Little) == 0x12); + try testing.expect(readInt(u8, &[_]u8{0x32}, .big) == 0x32); + try testing.expect(readInt(u8, &[_]u8{0x12}, .little) == 0x12); - try testing.expect(readInt(u16, &[_]u8{ 0x12, 0x34 }, .Big) == 0x1234); - try testing.expect(readInt(u16, &[_]u8{ 0x12, 0x34 }, .Little) == 0x3412); + try testing.expect(readInt(u16, &[_]u8{ 0x12, 0x34 }, .big) == 0x1234); + try testing.expect(readInt(u16, &[_]u8{ 0x12, 0x34 }, .little) == 0x3412); - try testing.expect(readInt(u72, &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }, .Big) == 0x123456789abcdef024); - try testing.expect(readInt(u72, &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }, .Little) == 0xfedcba9876543210ec); + try testing.expect(readInt(u72, &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }, .big) == 0x123456789abcdef024); + try testing.expect(readInt(u72, &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }, .little) == 0xfedcba9876543210ec); - try testing.expect(readInt(i8, &[_]u8{0xff}, .Big) == -1); - try testing.expect(readInt(i8, &[_]u8{0xfe}, .Little) == -2); + try testing.expect(readInt(i8, &[_]u8{0xff}, .big) == -1); + try testing.expect(readInt(i8, &[_]u8{0xfe}, .little) == -2); - try testing.expect(readInt(i16, &[_]u8{ 0xff, 0xfd }, .Big) == -3); - try testing.expect(readInt(i16, &[_]u8{ 0xfc, 0xff }, .Little) == -4); + try testing.expect(readInt(i16, &[_]u8{ 0xff, 0xfd }, .big) == -3); + try testing.expect(readInt(i16, &[_]u8{ 0xfc, 0xff }, .little) == -4); } fn readPackedIntLittle(comptime T: type, bytes: []const u8, bit_offset: usize) T { @@ -1629,7 +1629,7 @@ fn readPackedIntLittle(comptime T: type, bytes: []const u8, bit_offset: usize) T // Read by loading a LoadInt, and then follow it up with a 1-byte read // of the tail if bit_offset pushed us over a byte boundary. const read_bytes = bytes[bit_offset / 8 ..]; - const val = @as(uN, @truncate(readInt(LoadInt, read_bytes[0..load_size], .Little) >> bit_shift)); + const val = @as(uN, @truncate(readInt(LoadInt, read_bytes[0..load_size], .little) >> bit_shift)); if (bit_shift > load_tail_bits) { const tail_bits = @as(Log2N, @intCast(bit_shift - load_tail_bits)); const tail_byte = read_bytes[load_size]; @@ -1657,7 +1657,7 @@ fn readPackedIntBig(comptime T: type, bytes: []const u8, bit_offset: usize) T { // of the tail if bit_offset pushed us over a byte boundary. const end = bytes.len - (bit_offset / 8); const read_bytes = bytes[(end - byte_count)..end]; - const val = @as(uN, @truncate(readInt(LoadInt, bytes[(end - load_size)..end][0..load_size], .Big) >> bit_shift)); + const val = @as(uN, @truncate(readInt(LoadInt, bytes[(end - load_size)..end][0..load_size], .big) >> bit_shift)); if (bit_shift > load_tail_bits) { const tail_bits = @as(Log2N, @intCast(bit_shift - load_tail_bits)); const tail_byte = if (bit_count < 8) @as(uN, @truncate(read_bytes[0])) else @as(uN, read_bytes[0]); @@ -1666,13 +1666,13 @@ fn readPackedIntBig(comptime T: type, bytes: []const u8, bit_offset: usize) T { } pub const readPackedIntNative = switch (native_endian) { - .Little => readPackedIntLittle, - .Big => readPackedIntBig, + .little => readPackedIntLittle, + .big => readPackedIntBig, }; pub const readPackedIntForeign = switch (native_endian) { - .Little => readPackedIntBig, - .Big => readPackedIntLittle, + .little => readPackedIntBig, + .big => readPackedIntLittle, }; /// Loads an integer from packed memory. @@ -1685,22 +1685,22 @@ pub const readPackedIntForeign = switch (native_endian) { /// pub fn readPackedInt(comptime T: type, bytes: []const u8, bit_offset: usize, endian: Endian) T { switch (endian) { - .Little => return readPackedIntLittle(T, bytes, bit_offset), - .Big => return readPackedIntBig(T, bytes, bit_offset), + .little => return readPackedIntLittle(T, bytes, bit_offset), + .big => return readPackedIntBig(T, bytes, bit_offset), } } test "comptime read/write int" { comptime { var bytes: [2]u8 = undefined; - writeInt(u16, &bytes, 0x1234, .Little); - const result = readInt(u16, &bytes, .Big); + writeInt(u16, &bytes, 0x1234, .little); + const result = readInt(u16, &bytes, .big); try testing.expect(result == 0x3412); } comptime { var bytes: [2]u8 = undefined; - writeInt(u16, &bytes, 0x1234, .Big); - const result = readInt(u16, &bytes, .Little); + writeInt(u16, &bytes, 0x1234, .big); + const result = readInt(u16, &bytes, .little); try testing.expect(result == 0x3412); } } @@ -1718,34 +1718,34 @@ test writeInt { var buf2: [2]u8 = undefined; var buf9: [9]u8 = undefined; - writeInt(u0, &buf0, 0x0, .Big); + writeInt(u0, &buf0, 0x0, .big); try testing.expect(eql(u8, buf0[0..], &[_]u8{})); - writeInt(u0, &buf0, 0x0, .Little); + writeInt(u0, &buf0, 0x0, .little); try testing.expect(eql(u8, buf0[0..], &[_]u8{})); - writeInt(u8, &buf1, 0x12, .Big); + writeInt(u8, &buf1, 0x12, .big); try testing.expect(eql(u8, buf1[0..], &[_]u8{0x12})); - writeInt(u8, &buf1, 0x34, .Little); + writeInt(u8, &buf1, 0x34, .little); try testing.expect(eql(u8, buf1[0..], &[_]u8{0x34})); - writeInt(u16, &buf2, 0x1234, .Big); + writeInt(u16, &buf2, 0x1234, .big); try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 })); - writeInt(u16, &buf2, 0x5678, .Little); + writeInt(u16, &buf2, 0x5678, .little); try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x78, 0x56 })); - writeInt(u72, &buf9, 0x123456789abcdef024, .Big); + writeInt(u72, &buf9, 0x123456789abcdef024, .big); try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 })); - writeInt(u72, &buf9, 0xfedcba9876543210ec, .Little); + writeInt(u72, &buf9, 0xfedcba9876543210ec, .little); try testing.expect(eql(u8, buf9[0..], &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe })); - writeInt(i8, &buf1, -1, .Big); + writeInt(i8, &buf1, -1, .big); try testing.expect(eql(u8, buf1[0..], &[_]u8{0xff})); - writeInt(i8, &buf1, -2, .Little); + writeInt(i8, &buf1, -2, .little); try testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe})); - writeInt(i16, &buf2, -3, .Big); + writeInt(i16, &buf2, -3, .big); try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd })); - writeInt(i16, &buf2, -4, .Little); + writeInt(i16, &buf2, -4, .little); try testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff })); } @@ -1779,7 +1779,7 @@ fn writePackedIntLittle(comptime T: type, bytes: []u8, bit_offset: usize, value: write_value |= @as(StoreInt, tail) << (8 * (store_size - 1)); } - writeInt(StoreInt, write_bytes[0..store_size], write_value, .Little); + writeInt(StoreInt, write_bytes[0..store_size], write_value, .little); } fn writePackedIntBig(comptime T: type, bytes: []u8, bit_offset: usize, value: T) void { @@ -1814,17 +1814,17 @@ fn writePackedIntBig(comptime T: type, bytes: []u8, bit_offset: usize, value: T) write_value |= @as(StoreInt, tail) << (8 * (store_size - 1)); } - writeInt(StoreInt, write_bytes[(byte_count - store_size)..][0..store_size], write_value, .Big); + writeInt(StoreInt, write_bytes[(byte_count - store_size)..][0..store_size], write_value, .big); } pub const writePackedIntNative = switch (native_endian) { - .Little => writePackedIntLittle, - .Big => writePackedIntBig, + .little => writePackedIntLittle, + .big => writePackedIntBig, }; pub const writePackedIntForeign = switch (native_endian) { - .Little => writePackedIntBig, - .Big => writePackedIntLittle, + .little => writePackedIntBig, + .big => writePackedIntLittle, }; /// Stores an integer to packed memory. @@ -1838,8 +1838,8 @@ pub const writePackedIntForeign = switch (native_endian) { /// pub fn writePackedInt(comptime T: type, bytes: []u8, bit_offset: usize, value: T, endian: Endian) void { switch (endian) { - .Little => writePackedIntLittle(T, bytes, bit_offset, value), - .Big => writePackedIntBig(T, bytes, bit_offset, value), + .little => writePackedIntLittle(T, bytes, bit_offset, value), + .big => writePackedIntBig(T, bytes, bit_offset, value), } } @@ -1860,8 +1860,8 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value const bit_shift = @as(u3, @intCast(bit_offset % 8)); const write_size = (bit_count + bit_shift + 7) / 8; const lowest_byte = switch (endian) { - .Big => bytes.len - (bit_offset / 8) - write_size, - .Little => bit_offset / 8, + .big => bytes.len - (bit_offset / 8) - write_size, + .little => bit_offset / 8, }; const write_bytes = bytes[lowest_byte..][0..write_size]; @@ -1877,8 +1877,8 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value var remaining: T = value; // Iterate bytes forward for Little-endian, backward for Big-endian - const delta: i2 = if (endian == .Big) -1 else 1; - const start = if (endian == .Big) @as(isize, @intCast(write_bytes.len - 1)) else 0; + const delta: i2 = if (endian == .big) -1 else 1; + const start = if (endian == .big) @as(isize, @intCast(write_bytes.len - 1)) else 0; var i: isize = start; // isize for signed index arithmetic @@ -3122,12 +3122,12 @@ fn testReadIntImpl() !void { 0x56, 0x78, }; - try testing.expect(readInt(u32, &bytes, .Big) == 0x12345678); - try testing.expect(readInt(u32, &bytes, .Big) == 0x12345678); - try testing.expect(readInt(i32, &bytes, .Big) == 0x12345678); - try testing.expect(readInt(u32, &bytes, .Little) == 0x78563412); - try testing.expect(readInt(u32, &bytes, .Little) == 0x78563412); - try testing.expect(readInt(i32, &bytes, .Little) == 0x78563412); + try testing.expect(readInt(u32, &bytes, .big) == 0x12345678); + try testing.expect(readInt(u32, &bytes, .big) == 0x12345678); + try testing.expect(readInt(i32, &bytes, .big) == 0x12345678); + try testing.expect(readInt(u32, &bytes, .little) == 0x78563412); + try testing.expect(readInt(u32, &bytes, .little) == 0x78563412); + try testing.expect(readInt(i32, &bytes, .little) == 0x78563412); } { const buf = [_]u8{ @@ -3136,7 +3136,7 @@ fn testReadIntImpl() !void { 0x12, 0x34, }; - const answer = readInt(u32, &buf, .Big); + const answer = readInt(u32, &buf, .big); try testing.expect(answer == 0x00001234); } { @@ -3146,7 +3146,7 @@ fn testReadIntImpl() !void { 0x00, 0x00, }; - const answer = readInt(u32, &buf, .Little); + const answer = readInt(u32, &buf, .little); try testing.expect(answer == 0x00003412); } { @@ -3154,10 +3154,10 @@ fn testReadIntImpl() !void { 0xff, 0xfe, }; - try testing.expect(readInt(u16, &bytes, .Big) == 0xfffe); - try testing.expect(readInt(i16, &bytes, .Big) == -0x0002); - try testing.expect(readInt(u16, &bytes, .Little) == 0xfeff); - try testing.expect(readInt(i16, &bytes, .Little) == -0x0101); + try testing.expect(readInt(u16, &bytes, .big) == 0xfffe); + try testing.expect(readInt(i16, &bytes, .big) == -0x0002); + try testing.expect(readInt(u16, &bytes, .little) == 0xfeff); + try testing.expect(readInt(i16, &bytes, .little) == -0x0101); } } @@ -3603,48 +3603,48 @@ test "replaceOwned" { /// Converts a little-endian integer to host endianness. pub fn littleToNative(comptime T: type, x: T) T { return switch (native_endian) { - .Little => x, - .Big => @byteSwap(x), + .little => x, + .big => @byteSwap(x), }; } /// Converts a big-endian integer to host endianness. pub fn bigToNative(comptime T: type, x: T) T { return switch (native_endian) { - .Little => @byteSwap(x), - .Big => x, + .little => @byteSwap(x), + .big => x, }; } /// Converts an integer from specified endianness to host endianness. pub fn toNative(comptime T: type, x: T, endianness_of_x: Endian) T { return switch (endianness_of_x) { - .Little => littleToNative(T, x), - .Big => bigToNative(T, x), + .little => littleToNative(T, x), + .big => bigToNative(T, x), }; } /// Converts an integer which has host endianness to the desired endianness. pub fn nativeTo(comptime T: type, x: T, desired_endianness: Endian) T { return switch (desired_endianness) { - .Little => nativeToLittle(T, x), - .Big => nativeToBig(T, x), + .little => nativeToLittle(T, x), + .big => nativeToBig(T, x), }; } /// Converts an integer which has host endianness to little endian. pub fn nativeToLittle(comptime T: type, x: T) T { return switch (native_endian) { - .Little => x, - .Big => @byteSwap(x), + .little => x, + .big => @byteSwap(x), }; } /// Converts an integer which has host endianness to big endian. pub fn nativeToBig(comptime T: type, x: T) T { return switch (native_endian) { - .Little => @byteSwap(x), - .Big => x, + .little => @byteSwap(x), + .big => x, }; } @@ -3748,8 +3748,8 @@ pub fn asBytes(ptr: anytype) AsBytesReturnType(@TypeOf(ptr)) { test "asBytes" { const deadbeef = @as(u32, 0xDEADBEEF); const deadbeef_bytes = switch (native_endian) { - .Big => "\xDE\xAD\xBE\xEF", - .Little => "\xEF\xBE\xAD\xDE", + .big => "\xDE\xAD\xBE\xEF", + .little => "\xEF\xBE\xAD\xDE", }; try testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes)); @@ -3773,10 +3773,10 @@ test "asBytes" { .d = 0xA1, }; switch (native_endian) { - .Little => { + .little => { try testing.expect(eql(u8, asBytes(&inst), "\xBE\xEF\xDE\xA1")); }, - .Big => { + .big => { try testing.expect(eql(u8, asBytes(&inst), "\xA1\xDE\xEF\xBE")); }, } @@ -3808,14 +3808,14 @@ pub fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8 { test "toBytes" { var my_bytes = toBytes(@as(u32, 0x12345678)); switch (native_endian) { - .Big => try testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")), - .Little => try testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")), + .big => try testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")), + .little => try testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")), } my_bytes[0] = '\x99'; switch (native_endian) { - .Big => try testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")), - .Little => try testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")), + .big => try testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")), + .little => try testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")), } } @@ -3840,15 +3840,15 @@ pub fn bytesAsValue(comptime T: type, bytes: anytype) BytesAsValueReturnType(T, test "bytesAsValue" { const deadbeef = @as(u32, 0xDEADBEEF); const deadbeef_bytes = switch (native_endian) { - .Big => "\xDE\xAD\xBE\xEF", - .Little => "\xEF\xBE\xAD\xDE", + .big => "\xDE\xAD\xBE\xEF", + .little => "\xEF\xBE\xAD\xDE", }; try testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*); var codeface_bytes: [4]u8 = switch (native_endian) { - .Big => "\xC0\xDE\xFA\xCE", - .Little => "\xCE\xFA\xDE\xC0", + .big => "\xC0\xDE\xFA\xCE", + .little => "\xCE\xFA\xDE\xC0", }.*; var codeface = bytesAsValue(u32, &codeface_bytes); try testing.expect(codeface.* == 0xC0DEFACE); @@ -3870,8 +3870,8 @@ test "bytesAsValue" { .d = 0xA1, }; const inst_bytes = switch (native_endian) { - .Little => "\xBE\xEF\xDE\xA1", - .Big => "\xA1\xDE\xEF\xBE", + .little => "\xBE\xEF\xDE\xA1", + .big => "\xA1\xDE\xEF\xBE", }; const inst2 = bytesAsValue(S, inst_bytes); try testing.expect(meta.eql(inst, inst2.*)); @@ -3898,8 +3898,8 @@ pub fn bytesToValue(comptime T: type, bytes: anytype) T { } test "bytesToValue" { const deadbeef_bytes = switch (native_endian) { - .Big => "\xDE\xAD\xBE\xEF", - .Little => "\xEF\xBE\xAD\xDE", + .big => "\xDE\xAD\xBE\xEF", + .little => "\xEF\xBE\xAD\xDE", }; const deadbeef = bytesToValue(u32, deadbeef_bytes); @@ -4028,8 +4028,8 @@ test "sliceAsBytes" { const slice = sliceAsBytes(bytes[0..]); try testing.expect(slice.len == 4); try testing.expect(eql(u8, slice, switch (native_endian) { - .Big => "\xDE\xAD\xBE\xEF", - .Little => "\xAD\xDE\xEF\xBE", + .big => "\xDE\xAD\xBE\xEF", + .little => "\xAD\xDE\xEF\xBE", })); } @@ -4204,7 +4204,7 @@ test "doNotOptimizeAway" { doNotOptimizeAway(@as(f64, 0.0)); doNotOptimizeAway([_]u8{0} ** 4); doNotOptimizeAway([_]u8{0} ** 100); - doNotOptimizeAway(@as(std.builtin.Endian, .Little)); + doNotOptimizeAway(@as(std.builtin.Endian, .little)); } test "alignForward" { @@ -4356,7 +4356,7 @@ test "read/write(Var)PackedInt" { return error.SkipZigTest; } - const foreign_endian: Endian = if (native_endian == .Big) .Little else .Big; + const foreign_endian: Endian = if (native_endian == .big) .little else .big; const expect = std.testing.expect; var prng = std.rand.DefaultPrng.init(1234); const random = prng.random(); diff --git a/lib/std/net.zig b/lib/std/net.zig index 1badada19e..9e32fe613f 100644 --- a/lib/std/net.zig +++ b/lib/std/net.zig @@ -602,8 +602,8 @@ pub const Ip6Address = extern struct { } const big_endian_parts = @as(*align(1) const [8]u16, @ptrCast(&self.sa.addr)); const native_endian_parts = switch (native_endian) { - .Big => big_endian_parts.*, - .Little => blk: { + .big => big_endian_parts.*, + .little => blk: { var buf: [8]u16 = undefined; for (big_endian_parts, 0..) |part, i| { buf[i] = mem.bigToNative(u16, part); diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index d1202dc2ed..08fef213e9 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -206,11 +206,11 @@ fn splitValueBE64(val: i64) [2]u32 { fn splitValue64(val: i64) [2]u32 { const u: u64 = @bitCast(val); switch (native_endian) { - .Little => return [2]u32{ + .little => return [2]u32{ @as(u32, @truncate(u)), @as(u32, @truncate(u >> 32)), }, - .Big => return [2]u32{ + .big => return [2]u32{ @as(u32, @truncate(u >> 32)), @as(u32, @truncate(u)), }, @@ -6028,7 +6028,7 @@ pub const AUDIT = struct { fn toAudit(arch: std.Target.Cpu.Arch) u32 { var res: u32 = @intFromEnum(arch.toElfMachine()); - if (arch.endian() == .Little) res |= LE; + if (arch.endian() == .little) res |= LE; switch (arch) { .aarch64, .mips64, diff --git a/lib/std/os/linux/bpf.zig b/lib/std/os/linux/bpf.zig index 4828b1d8ea..48561012c5 100644 --- a/lib/std/os/linux/bpf.zig +++ b/lib/std/os/linux/bpf.zig @@ -696,8 +696,8 @@ pub const Insn = packed struct { fn endian_swap(endian: std.builtin.Endian, comptime size: Size, dst: Reg) Insn { return Insn{ .code = switch (endian) { - .Big => 0xdc, - .Little => 0xd4, + .big => 0xdc, + .little => 0xd4, }, .dst = @intFromEnum(dst), .src = 0, @@ -712,11 +712,11 @@ pub const Insn = packed struct { } pub fn le(comptime size: Size, dst: Reg) Insn { - return endian_swap(.Little, size, dst); + return endian_swap(.little, size, dst); } pub fn be(comptime size: Size, dst: Reg) Insn { - return endian_swap(.Big, size, dst); + return endian_swap(.big, size, dst); } pub fn call(helper: Helper) Insn { diff --git a/lib/std/os/linux/seccomp.zig b/lib/std/os/linux/seccomp.zig index f10cb84aa0..8e38598c69 100644 --- a/lib/std/os/linux/seccomp.zig +++ b/lib/std/os/linux/seccomp.zig @@ -54,7 +54,7 @@ //! manner to the OpenSSH example: //! //! ```zig -//! const offset = if (native_endian == .Little) struct { +//! const offset = if (native_endian == .little) struct { //! pub const low = 0; //! pub const high = @sizeOf(u32); //! } else struct { diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig index 1fa629e5ae..b7c1b7b675 100644 --- a/lib/std/os/test.zig +++ b/lib/std/os/test.zig @@ -609,7 +609,7 @@ test "mmap" { var i: u32 = 0; while (i < alloc_size / @sizeOf(u32)) : (i += 1) { - try stream.writeInt(u32, i, .Little); + try stream.writeInt(u32, i, .little); } } @@ -633,7 +633,7 @@ test "mmap" { var i: u32 = 0; while (i < alloc_size / @sizeOf(u32)) : (i += 1) { - try testing.expectEqual(i, try stream.readInt(u32, .Little)); + try testing.expectEqual(i, try stream.readInt(u32, .little)); } } @@ -657,7 +657,7 @@ test "mmap" { var i: u32 = alloc_size / 2 / @sizeOf(u32); while (i < alloc_size / @sizeOf(u32)) : (i += 1) { - try testing.expectEqual(i, try stream.readInt(u32, .Little)); + try testing.expectEqual(i, try stream.readInt(u32, .little)); } } diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index c327d38dd6..e6d97ecbf3 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -3360,13 +3360,13 @@ pub const GUID = extern struct { Data4: [8]u8, const hex_offsets = switch (builtin.target.cpu.arch.endian()) { - .Big => [16]u6{ + .big => [16]u6{ 0, 2, 4, 6, 9, 11, 14, 16, 19, 21, 24, 26, 28, 30, 32, 34, }, - .Little => [16]u6{ + .little => [16]u6{ 6, 4, 2, 0, 11, 9, 16, 14, 19, 21, 24, 26, diff --git a/lib/std/packed_int_array.zig b/lib/std/packed_int_array.zig index cff9eb8cf1..7264fed599 100644 --- a/lib/std/packed_int_array.zig +++ b/lib/std/packed_int_array.zig @@ -79,12 +79,12 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type { if (endian != native_endian) value = @byteSwap(value); switch (endian) { - .Big => { + .big => { value <<= @as(Shift, @intCast(head_keep_bits)); value >>= @as(Shift, @intCast(head_keep_bits)); value >>= @as(Shift, @intCast(tail_keep_bits)); }, - .Little => { + .little => { value <<= @as(Shift, @intCast(tail_keep_bits)); value >>= @as(Shift, @intCast(tail_keep_bits)); value >>= @as(Shift, @intCast(head_keep_bits)); @@ -115,8 +115,8 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: Endian) type { const head_keep_bits = bit_index - (start_byte * 8); const tail_keep_bits = container_bits - (int_bits + head_keep_bits); const keep_shift = switch (endian) { - .Big => @as(Shift, @intCast(tail_keep_bits)), - .Little => @as(Shift, @intCast(head_keep_bits)), + .big => @as(Shift, @intCast(tail_keep_bits)), + .little => @as(Shift, @intCast(head_keep_bits)), }; //position the bits where they need to be in the container @@ -388,10 +388,10 @@ test "PackedIntArray" { test "PackedIntIo" { const bytes = [_]u8{ 0b01101_000, 0b01011_110, 0b00011_101 }; - try testing.expectEqual(@as(u15, 0x2bcd), PackedIntIo(u15, .Little).get(&bytes, 0, 3)); - try testing.expectEqual(@as(u16, 0xabcd), PackedIntIo(u16, .Little).get(&bytes, 0, 3)); - try testing.expectEqual(@as(u17, 0x1abcd), PackedIntIo(u17, .Little).get(&bytes, 0, 3)); - try testing.expectEqual(@as(u18, 0x3abcd), PackedIntIo(u18, .Little).get(&bytes, 0, 3)); + try testing.expectEqual(@as(u15, 0x2bcd), PackedIntIo(u15, .little).get(&bytes, 0, 3)); + try testing.expectEqual(@as(u16, 0xabcd), PackedIntIo(u16, .little).get(&bytes, 0, 3)); + try testing.expectEqual(@as(u17, 0x1abcd), PackedIntIo(u17, .little).get(&bytes, 0, 3)); + try testing.expectEqual(@as(u18, 0x3abcd), PackedIntIo(u18, .little).get(&bytes, 0, 3)); } test "PackedIntArray init" { @@ -555,16 +555,16 @@ test "PackedInt(Array/Slice) sliceCast" { var i = @as(usize, 0); while (i < packed_slice_cast_2.len) : (i += 1) { const val = switch (native_endian) { - .Big => 0b01, - .Little => 0b10, + .big => 0b01, + .little => 0b10, }; try testing.expect(packed_slice_cast_2.get(i) == val); } i = 0; while (i < packed_slice_cast_4.len) : (i += 1) { const val = switch (native_endian) { - .Big => 0b0101, - .Little => 0b1010, + .big => 0b0101, + .little => 0b1010, }; try testing.expect(packed_slice_cast_4.get(i) == val); } @@ -577,8 +577,8 @@ test "PackedInt(Array/Slice) sliceCast" { i = 0; while (i < packed_slice_cast_3.len) : (i += 1) { const val = switch (native_endian) { - .Big => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000), - .Little => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000), + .big => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000), + .little => if (i % 2 == 0) @as(u3, 0b111) else @as(u3, 0b000), }; try testing.expect(packed_slice_cast_3.get(i) == val); } @@ -586,7 +586,7 @@ test "PackedInt(Array/Slice) sliceCast" { test "PackedInt(Array/Slice)Endian" { { - const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8); + const PackedArrayBe = PackedIntArrayEndian(u4, .big, 8); var packed_array_be = PackedArrayBe.init([_]u4{ 0, 1, 2, 3, 4, 5, 6, 7 }); try testing.expect(packed_array_be.bytes[0] == 0b00000001); try testing.expect(packed_array_be.bytes[1] == 0b00100011); @@ -596,14 +596,14 @@ test "PackedInt(Array/Slice)Endian" { try testing.expect(packed_array_be.get(i) == i); } - var packed_slice_le = packed_array_be.sliceCastEndian(u4, .Little); + var packed_slice_le = packed_array_be.sliceCastEndian(u4, .little); i = 0; while (i < packed_slice_le.len) : (i += 1) { const val = if (i % 2 == 0) i + 1 else i - 1; try testing.expect(packed_slice_le.get(i) == val); } - var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u4, .Little); + var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u4, .little); i = 0; while (i < packed_slice_le_shift.len) : (i += 1) { const val = if (i % 2 == 0) i else i + 2; @@ -612,7 +612,7 @@ test "PackedInt(Array/Slice)Endian" { } { - const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8); + const PackedArrayBe = PackedIntArrayEndian(u11, .big, 8); var packed_array_be = PackedArrayBe.init([_]u11{ 0, 1, 2, 3, 4, 5, 6, 7 }); try testing.expect(packed_array_be.bytes[0] == 0b00000000); try testing.expect(packed_array_be.bytes[1] == 0b00000000); @@ -625,7 +625,7 @@ test "PackedInt(Array/Slice)Endian" { try testing.expect(packed_array_be.get(i) == i); } - var packed_slice_le = packed_array_be.sliceCastEndian(u11, .Little); + var packed_slice_le = packed_array_be.sliceCastEndian(u11, .little); try testing.expect(packed_slice_le.get(0) == 0b00000000000); try testing.expect(packed_slice_le.get(1) == 0b00010000000); try testing.expect(packed_slice_le.get(2) == 0b00000000100); @@ -635,7 +635,7 @@ test "PackedInt(Array/Slice)Endian" { try testing.expect(packed_slice_le.get(6) == 0b10000010000); try testing.expect(packed_slice_le.get(7) == 0b00000111001); - var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u11, .Little); + var packed_slice_le_shift = packed_array_be.slice(1, 5).sliceCastEndian(u11, .little); try testing.expect(packed_slice_le_shift.get(0) == 0b00010000000); try testing.expect(packed_slice_le_shift.get(1) == 0b00000000100); try testing.expect(packed_slice_le_shift.get(2) == 0b00000000000); diff --git a/lib/std/pdb.zig b/lib/std/pdb.zig index 3632adc138..acc8aa1ec7 100644 --- a/lib/std/pdb.zig +++ b/lib/std/pdb.zig @@ -464,12 +464,12 @@ pub const PDBStringTableHeader = extern struct { }; fn readSparseBitVector(stream: anytype, allocator: mem.Allocator) ![]u32 { - const num_words = try stream.readInt(u32, .Little); + const num_words = try stream.readInt(u32, .little); var list = ArrayList(u32).init(allocator); errdefer list.deinit(); var word_i: u32 = 0; while (word_i != num_words) : (word_i += 1) { - const word = try stream.readInt(u32, .Little); + const word = try stream.readInt(u32, .little); var bit_i: u5 = 0; while (true) : (bit_i += 1) { if (word & (@as(u32, 1) << bit_i) != 0) { @@ -599,7 +599,7 @@ pub const Pdb = struct { var sect_cont_offset: usize = 0; if (section_contrib_size != 0) { - const version = reader.readEnum(SectionContrSubstreamVersion, .Little) catch |err| switch (err) { + const version = reader.readEnum(SectionContrSubstreamVersion, .little) catch |err| switch (err) { error.InvalidValue => return error.InvalidDebugInfo, else => |e| return e, }; @@ -625,10 +625,10 @@ pub const Pdb = struct { const reader = stream.reader(); // Parse the InfoStreamHeader. - const version = try reader.readInt(u32, .Little); - const signature = try reader.readInt(u32, .Little); + const version = try reader.readInt(u32, .little); + const signature = try reader.readInt(u32, .little); _ = signature; - const age = try reader.readInt(u32, .Little); + const age = try reader.readInt(u32, .little); const guid = try reader.readBytesNoEof(16); if (version != 20000404) // VC70, only value observed by LLVM team @@ -639,7 +639,7 @@ pub const Pdb = struct { // Find the string table. const string_table_index = str_tab_index: { - const name_bytes_len = try reader.readInt(u32, .Little); + const name_bytes_len = try reader.readInt(u32, .little); const name_bytes = try self.allocator.alloc(u8, name_bytes_len); defer self.allocator.free(name_bytes); try reader.readNoEof(name_bytes); @@ -667,8 +667,8 @@ pub const Pdb = struct { defer self.allocator.free(deleted); for (present) |_| { - const name_offset = try reader.readInt(u32, .Little); - const name_index = try reader.readInt(u32, .Little); + const name_offset = try reader.readInt(u32, .little); + const name_index = try reader.readInt(u32, .little); if (name_offset > name_bytes.len) return error.InvalidDebugInfo; const name = mem.sliceTo(name_bytes[name_offset..], 0); @@ -821,7 +821,7 @@ pub const Pdb = struct { return error.MissingDebugInfo; const reader = stream.reader(); - const signature = try reader.readInt(u32, .Little); + const signature = try reader.readInt(u32, .little); if (signature != 4) return error.InvalidDebugInfo; @@ -899,7 +899,7 @@ const Msf = struct { try file.seekTo(superblock.BlockSize * superblock.BlockMapAddr); var dir_blocks = try allocator.alloc(u32, dir_block_count); for (dir_blocks) |*b| { - b.* = try in.readInt(u32, .Little); + b.* = try in.readInt(u32, .little); } var directory = MsfStream.init( superblock.BlockSize, @@ -908,7 +908,7 @@ const Msf = struct { ); const begin = directory.pos; - const stream_count = try directory.reader().readInt(u32, .Little); + const stream_count = try directory.reader().readInt(u32, .little); const stream_sizes = try allocator.alloc(u32, stream_count); defer allocator.free(stream_sizes); @@ -917,7 +917,7 @@ const Msf = struct { // and must be taken into account when resolving stream indices. const Nil = 0xFFFFFFFF; for (stream_sizes) |*s| { - const size = try directory.reader().readInt(u32, .Little); + const size = try directory.reader().readInt(u32, .little); s.* = if (size == Nil) 0 else blockCountFromSize(size, superblock.BlockSize); } @@ -932,7 +932,7 @@ const Msf = struct { var blocks = try allocator.alloc(u32, size); var j: u32 = 0; while (j < size) : (j += 1) { - const block_id = try directory.reader().readInt(u32, .Little); + const block_id = try directory.reader().readInt(u32, .little); const n = (block_id % superblock.BlockSize); // 0 is for SuperBlock, 1 and 2 for FPMs. if (block_id == 0 or n == 1 or n == 2 or block_id * superblock.BlockSize > file_len) diff --git a/lib/std/rand.zig b/lib/std/rand.zig index bca8289c85..aec461883b 100644 --- a/lib/std/rand.zig +++ b/lib/std/rand.zig @@ -113,7 +113,7 @@ pub const Random = struct { // use LE instead of native endian for better portability maybe? // TODO: endian portability is pointless if the underlying prng isn't endian portable. // TODO: document the endian portability of this library. - const byte_aligned_result = mem.readInt(ByteAlignedT, &rand_bytes, .Little); + const byte_aligned_result = mem.readInt(ByteAlignedT, &rand_bytes, .little); const unsigned_result: UnsignedT = @truncate(byte_aligned_result); return @bitCast(unsigned_result); } diff --git a/lib/std/rand/Ascon.zig b/lib/std/rand/Ascon.zig index da0ce66259..6a3cb13165 100644 --- a/lib/std/rand/Ascon.zig +++ b/lib/std/rand/Ascon.zig @@ -13,7 +13,7 @@ const mem = std.mem; const Random = std.rand.Random; const Self = @This(); -const Ascon = std.crypto.core.Ascon(.Little); +const Ascon = std.crypto.core.Ascon(.little); state: Ascon, diff --git a/lib/std/rand/Isaac64.zig b/lib/std/rand/Isaac64.zig index d3a6a19b5b..8684ba8e22 100644 --- a/lib/std/rand/Isaac64.zig +++ b/lib/std/rand/Isaac64.zig @@ -228,7 +228,7 @@ test "isaac64 fill" { for (seq) |s| { var buf0: [8]u8 = undefined; var buf1: [7]u8 = undefined; - std.mem.writeInt(u64, &buf0, s, .Little); + std.mem.writeInt(u64, &buf0, s, .little); r.fill(&buf1); try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); } diff --git a/lib/std/rand/Pcg.zig b/lib/std/rand/Pcg.zig index 6219954713..d7d233659f 100644 --- a/lib/std/rand/Pcg.zig +++ b/lib/std/rand/Pcg.zig @@ -111,8 +111,8 @@ test "pcg fill" { var i: u32 = 0; while (i < seq.len) : (i += 2) { var buf0: [8]u8 = undefined; - std.mem.writeInt(u32, buf0[0..4], seq[i], .Little); - std.mem.writeInt(u32, buf0[4..8], seq[i + 1], .Little); + std.mem.writeInt(u32, buf0[0..4], seq[i], .little); + std.mem.writeInt(u32, buf0[4..8], seq[i + 1], .little); var buf1: [7]u8 = undefined; r.fill(&buf1); diff --git a/lib/std/rand/RomuTrio.zig b/lib/std/rand/RomuTrio.zig index 9864b03327..4caf5f0ce8 100644 --- a/lib/std/rand/RomuTrio.zig +++ b/lib/std/rand/RomuTrio.zig @@ -115,7 +115,7 @@ test "RomuTrio fill" { for (seq) |s| { var buf0: [8]u8 = undefined; var buf1: [7]u8 = undefined; - std.mem.writeInt(u64, &buf0, s, .Little); + std.mem.writeInt(u64, &buf0, s, .little); r.fill(&buf1); try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); } diff --git a/lib/std/rand/Sfc64.zig b/lib/std/rand/Sfc64.zig index e3197cc3ec..b4a8988e4d 100644 --- a/lib/std/rand/Sfc64.zig +++ b/lib/std/rand/Sfc64.zig @@ -125,7 +125,7 @@ test "Sfc64 fill" { for (seq) |s| { var buf0: [8]u8 = undefined; var buf1: [7]u8 = undefined; - std.mem.writeInt(u64, &buf0, s, .Little); + std.mem.writeInt(u64, &buf0, s, .little); r.fill(&buf1); try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); } diff --git a/lib/std/rand/Xoroshiro128.zig b/lib/std/rand/Xoroshiro128.zig index 2b215fdc0c..0272419ba2 100644 --- a/lib/std/rand/Xoroshiro128.zig +++ b/lib/std/rand/Xoroshiro128.zig @@ -140,7 +140,7 @@ test "xoroshiro fill" { for (seq) |s| { var buf0: [8]u8 = undefined; var buf1: [7]u8 = undefined; - std.mem.writeInt(u64, &buf0, s, .Little); + std.mem.writeInt(u64, &buf0, s, .little); r.fill(&buf1); try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); } diff --git a/lib/std/rand/Xoshiro256.zig b/lib/std/rand/Xoshiro256.zig index c1cc897a05..85ae669ecd 100644 --- a/lib/std/rand/Xoshiro256.zig +++ b/lib/std/rand/Xoshiro256.zig @@ -139,7 +139,7 @@ test "xoroshiro fill" { for (seq) |s| { var buf0: [8]u8 = undefined; var buf1: [7]u8 = undefined; - std.mem.writeInt(u64, &buf0, s, .Little); + std.mem.writeInt(u64, &buf0, s, .little); r.fill(&buf1); try std.testing.expect(std.mem.eql(u8, buf0[0..7], buf1[0..])); } diff --git a/lib/std/rand/test.zig b/lib/std/rand/test.zig index 6746a05773..e8a1d4de8a 100644 --- a/lib/std/rand/test.zig +++ b/lib/std/rand/test.zig @@ -71,7 +71,7 @@ const Dilbert = struct { for (seq) |s| { var buf0: [8]u8 = undefined; var buf1: [8]u8 = undefined; - std.mem.writeInt(u64, &buf0, s, .Big); + std.mem.writeInt(u64, &buf0, s, .big); r.fill(&buf1); try std.testing.expect(std.mem.eql(u8, buf0[0..], buf1[0..])); } diff --git a/lib/std/target.zig b/lib/std/target.zig index 7296b30434..3764b71d8f 100644 --- a/lib/std/target.zig +++ b/lib/std/target.zig @@ -1191,7 +1191,7 @@ pub const Target = struct { .loongarch32, .loongarch64, .arc, - => .Little, + => .little, .armeb, .aarch64_be, @@ -1207,7 +1207,7 @@ pub const Target = struct { .tce, .lanai, .s390x, - => .Big, + => .big, }; } diff --git a/lib/std/tz.zig b/lib/std/tz.zig index a17756a7bb..bff0101439 100644 --- a/lib/std/tz.zig +++ b/lib/std/tz.zig @@ -59,7 +59,7 @@ pub const Tz = struct { if (!std.mem.eql(u8, &legacy_header.magic, "TZif")) return error.BadHeader; if (legacy_header.version != 0 and legacy_header.version != '2' and legacy_header.version != '3') return error.BadVersion; - if (builtin.target.cpu.arch.endian() != std.builtin.Endian.Big) { + if (builtin.target.cpu.arch.endian() != std.builtin.Endian.big) { std.mem.byteSwapAllFields(@TypeOf(legacy_header.counts), &legacy_header.counts); } @@ -73,7 +73,7 @@ pub const Tz = struct { var header = try reader.readStruct(Header); if (!std.mem.eql(u8, &header.magic, "TZif")) return error.BadHeader; if (header.version != '2' and header.version != '3') return error.BadVersion; - if (builtin.target.cpu.arch.endian() != std.builtin.Endian.Big) { + if (builtin.target.cpu.arch.endian() != std.builtin.Endian.big) { std.mem.byteSwapAllFields(@TypeOf(header.counts), &header.counts); } @@ -98,7 +98,7 @@ pub const Tz = struct { // Parse transition types var i: usize = 0; while (i < header.counts.timecnt) : (i += 1) { - transitions[i].ts = if (legacy) try reader.readInt(i32, .Big) else try reader.readInt(i64, .Big); + transitions[i].ts = if (legacy) try reader.readInt(i32, .big) else try reader.readInt(i64, .big); } i = 0; @@ -111,7 +111,7 @@ pub const Tz = struct { // Parse time types i = 0; while (i < header.counts.typecnt) : (i += 1) { - const offset = try reader.readInt(i32, .Big); + const offset = try reader.readInt(i32, .big); if (offset < -2147483648) return error.Malformed; // rfc8536: utoff [...] MUST NOT be -2**31 const dst = try reader.readByte(); 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 { // Parse leap seconds i = 0; while (i < header.counts.leapcnt) : (i += 1) { - const occur: i64 = if (legacy) try reader.readInt(i32, .Big) else try reader.readInt(i64, .Big); + const occur: i64 = if (legacy) try reader.readInt(i32, .big) else try reader.readInt(i64, .big); if (occur < 0) return error.Malformed; // rfc8536: occur [...] MUST be nonnegative 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 if (occur > std.math.maxInt(i48)) return error.Malformed; // Unreasonably far into the future - const corr = try reader.readInt(i32, .Big); + const corr = try reader.readInt(i32, .big); 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) 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) if (corr > std.math.maxInt(i16)) return error.Malformed; // Unreasonably large correction diff --git a/lib/std/unicode.zig b/lib/std/unicode.zig index 9336e6bbe8..bd73a3bea3 100644 --- a/lib/std/unicode.zig +++ b/lib/std/unicode.zig @@ -452,12 +452,12 @@ pub const Utf16LeIterator = struct { assert(it.i <= it.bytes.len); if (it.i == it.bytes.len) return null; var code_units: [2]u16 = undefined; - code_units[0] = mem.readInt(u16, it.bytes[it.i..][0..2], .Little); + code_units[0] = mem.readInt(u16, it.bytes[it.i..][0..2], .little); it.i += 2; if (utf16IsHighSurrogate(code_units[0])) { // surrogate pair if (it.i >= it.bytes.len) return error.DanglingSurrogateHalf; - code_units[1] = mem.readInt(u16, it.bytes[it.i..][0..2], .Little); + code_units[1] = mem.readInt(u16, it.bytes[it.i..][0..2], .little); const codepoint = try utf16DecodeSurrogatePair(&code_units); it.i += 2; return codepoint; @@ -878,16 +878,16 @@ test "utf16leToUtf8" { const utf16le_as_bytes = mem.sliceAsBytes(utf16le[0..]); { - mem.writeInt(u16, utf16le_as_bytes[0..2], 'A', .Little); - mem.writeInt(u16, utf16le_as_bytes[2..4], 'a', .Little); + mem.writeInt(u16, utf16le_as_bytes[0..2], 'A', .little); + mem.writeInt(u16, utf16le_as_bytes[2..4], 'a', .little); const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); defer std.testing.allocator.free(utf8); try testing.expect(mem.eql(u8, utf8, "Aa")); } { - mem.writeInt(u16, utf16le_as_bytes[0..2], 0x80, .Little); - mem.writeInt(u16, utf16le_as_bytes[2..4], 0xffff, .Little); + mem.writeInt(u16, utf16le_as_bytes[0..2], 0x80, .little); + mem.writeInt(u16, utf16le_as_bytes[2..4], 0xffff, .little); const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); defer std.testing.allocator.free(utf8); try testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf")); @@ -895,8 +895,8 @@ test "utf16leToUtf8" { { // the values just outside the surrogate half range - mem.writeInt(u16, utf16le_as_bytes[0..2], 0xd7ff, .Little); - mem.writeInt(u16, utf16le_as_bytes[2..4], 0xe000, .Little); + mem.writeInt(u16, utf16le_as_bytes[0..2], 0xd7ff, .little); + mem.writeInt(u16, utf16le_as_bytes[2..4], 0xe000, .little); const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); defer std.testing.allocator.free(utf8); try testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80")); @@ -904,8 +904,8 @@ test "utf16leToUtf8" { { // smallest surrogate pair - mem.writeInt(u16, utf16le_as_bytes[0..2], 0xd800, .Little); - mem.writeInt(u16, utf16le_as_bytes[2..4], 0xdc00, .Little); + mem.writeInt(u16, utf16le_as_bytes[0..2], 0xd800, .little); + mem.writeInt(u16, utf16le_as_bytes[2..4], 0xdc00, .little); const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); defer std.testing.allocator.free(utf8); try testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80")); @@ -913,24 +913,24 @@ test "utf16leToUtf8" { { // largest surrogate pair - mem.writeInt(u16, utf16le_as_bytes[0..2], 0xdbff, .Little); - mem.writeInt(u16, utf16le_as_bytes[2..4], 0xdfff, .Little); + mem.writeInt(u16, utf16le_as_bytes[0..2], 0xdbff, .little); + mem.writeInt(u16, utf16le_as_bytes[2..4], 0xdfff, .little); const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); defer std.testing.allocator.free(utf8); try testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf")); } { - mem.writeInt(u16, utf16le_as_bytes[0..2], 0xdbff, .Little); - mem.writeInt(u16, utf16le_as_bytes[2..4], 0xdc00, .Little); + mem.writeInt(u16, utf16le_as_bytes[0..2], 0xdbff, .little); + mem.writeInt(u16, utf16le_as_bytes[2..4], 0xdc00, .little); const utf8 = try utf16leToUtf8Alloc(std.testing.allocator, &utf16le); defer std.testing.allocator.free(utf8); try testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80")); } { - mem.writeInt(u16, utf16le_as_bytes[0..2], 0xdcdc, .Little); - mem.writeInt(u16, utf16le_as_bytes[2..4], 0xdcdc, .Little); + mem.writeInt(u16, utf16le_as_bytes[0..2], 0xdcdc, .little); + mem.writeInt(u16, utf16le_as_bytes[2..4], 0xdcdc, .little); const result = utf16leToUtf8Alloc(std.testing.allocator, &utf16le); try std.testing.expectError(error.UnexpectedSecondSurrogateHalf, result); } diff --git a/lib/std/zig/Server.zig b/lib/std/zig/Server.zig index d15020dcc0..7d5abaf6ea 100644 --- a/lib/std/zig/Server.zig +++ b/lib/std/zig/Server.zig @@ -279,12 +279,12 @@ fn bswap_u32_array(slice: []u32) void { /// workaround for https://github.com/ziglang/zig/issues/14904 fn bswap_and_workaround_u32(bytes_ptr: *const [4]u8) u32 { - return std.mem.readInt(u32, bytes_ptr, .Little); + return std.mem.readInt(u32, bytes_ptr, .little); } /// workaround for https://github.com/ziglang/zig/issues/14904 fn bswap_and_workaround_tag(bytes_ptr: *const [4]u8) InMessage.Tag { - const int = std.mem.readInt(u32, bytes_ptr, .Little); + const int = std.mem.readInt(u32, bytes_ptr, .little); return @as(InMessage.Tag, @enumFromInt(int)); } @@ -297,4 +297,4 @@ const std = @import("std"); const Allocator = std.mem.Allocator; const assert = std.debug.assert; const native_endian = builtin.target.cpu.arch.endian(); -const need_bswap = native_endian != .Little; +const need_bswap = native_endian != .little; diff --git a/lib/std/zig/system/NativeTargetInfo.zig b/lib/std/zig/system/NativeTargetInfo.zig index f2700b48ce..ba0d699f91 100644 --- a/lib/std/zig/system/NativeTargetInfo.zig +++ b/lib/std/zig/system/NativeTargetInfo.zig @@ -488,8 +488,8 @@ fn glibcVerFromSoFile(file: fs.File) !std.SemanticVersion { const hdr64 = @as(*elf.Elf64_Ehdr, @ptrCast(&hdr_buf)); if (!mem.eql(u8, hdr32.e_ident[0..4], elf.MAGIC)) return error.InvalidElfMagic; const elf_endian: std.builtin.Endian = switch (hdr32.e_ident[elf.EI_DATA]) { - elf.ELFDATA2LSB => .Little, - elf.ELFDATA2MSB => .Big, + elf.ELFDATA2LSB => .little, + elf.ELFDATA2MSB => .big, else => return error.InvalidElfEndian, }; const need_bswap = elf_endian != native_endian; @@ -635,8 +635,8 @@ pub fn abiAndDynamicLinkerFromFile( const hdr64 = @as(*elf.Elf64_Ehdr, @ptrCast(&hdr_buf)); if (!mem.eql(u8, hdr32.e_ident[0..4], elf.MAGIC)) return error.InvalidElfMagic; const elf_endian: std.builtin.Endian = switch (hdr32.e_ident[elf.EI_DATA]) { - elf.ELFDATA2LSB => .Little, - elf.ELFDATA2MSB => .Big, + elf.ELFDATA2LSB => .little, + elf.ELFDATA2MSB => .big, else => return error.InvalidElfEndian, }; const need_bswap = elf_endian != native_endian; diff --git a/src/Package/Fetch/git.zig b/src/Package/Fetch/git.zig index b584a9b64e..2a5344eaa4 100644 --- a/src/Package/Fetch/git.zig +++ b/src/Package/Fetch/git.zig @@ -305,12 +305,12 @@ const Odb = struct { const n_objects = odb.index_header.fan_out_table[255]; const offset_values_start = IndexHeader.size + n_objects * (oid_length + 4); try odb.index_file.seekTo(offset_values_start + found_index * 4); - const l1_offset: packed struct { value: u31, big: bool } = @bitCast(try odb.index_file.reader().readInt(u32, .Big)); + const l1_offset: packed struct { value: u31, big: bool } = @bitCast(try odb.index_file.reader().readInt(u32, .big)); const pack_offset = pack_offset: { if (l1_offset.big) { const l2_offset_values_start = offset_values_start + n_objects * 4; try odb.index_file.seekTo(l2_offset_values_start + l1_offset.value * 4); - break :pack_offset try odb.index_file.reader().readInt(u64, .Big); + break :pack_offset try odb.index_file.reader().readInt(u64, .big); } else { break :pack_offset l1_offset.value; } @@ -845,12 +845,12 @@ const PackHeader = struct { else => |other| return other, }; if (!mem.eql(u8, &actual_signature, signature)) return error.InvalidHeader; - const version = reader.readInt(u32, .Big) catch |e| switch (e) { + const version = reader.readInt(u32, .big) catch |e| switch (e) { error.EndOfStream => return error.InvalidHeader, else => |other| return other, }; if (version != supported_version) return error.UnsupportedVersion; - const total_objects = reader.readInt(u32, .Big) catch |e| switch (e) { + const total_objects = reader.readInt(u32, .big) catch |e| switch (e) { error.EndOfStream => return error.InvalidHeader, else => |other| return other, }; @@ -966,14 +966,14 @@ const IndexHeader = struct { fn read(reader: anytype) !IndexHeader { var header_bytes = try reader.readBytesNoEof(size); if (!mem.eql(u8, header_bytes[0..4], signature)) return error.InvalidHeader; - const version = mem.readInt(u32, header_bytes[4..8], .Big); + const version = mem.readInt(u32, header_bytes[4..8], .big); if (version != supported_version) return error.UnsupportedVersion; var fan_out_table: [256]u32 = undefined; var fan_out_table_stream = std.io.fixedBufferStream(header_bytes[8..]); const fan_out_table_reader = fan_out_table_stream.reader(); for (&fan_out_table) |*entry| { - entry.* = fan_out_table_reader.readInt(u32, .Big) catch unreachable; + entry.* = fan_out_table_reader.readInt(u32, .big) catch unreachable; } return .{ .fan_out_table = fan_out_table }; } @@ -1041,9 +1041,9 @@ pub fn indexPack(allocator: Allocator, pack: std.fs.File, index_writer: anytype) var index_hashed_writer = hashedWriter(index_writer, Sha1.init(.{})); const writer = index_hashed_writer.writer(); try writer.writeAll(IndexHeader.signature); - try writer.writeInt(u32, IndexHeader.supported_version, .Big); + try writer.writeInt(u32, IndexHeader.supported_version, .big); for (fan_out_table) |fan_out_entry| { - try writer.writeInt(u32, fan_out_entry, .Big); + try writer.writeInt(u32, fan_out_entry, .big); } for (oids.items) |oid| { @@ -1051,7 +1051,7 @@ pub fn indexPack(allocator: Allocator, pack: std.fs.File, index_writer: anytype) } for (oids.items) |oid| { - try writer.writeInt(u32, index_entries.get(oid).?.crc32, .Big); + try writer.writeInt(u32, index_entries.get(oid).?.crc32, .big); } var big_offsets = std.ArrayListUnmanaged(u64){}; @@ -1059,15 +1059,15 @@ pub fn indexPack(allocator: Allocator, pack: std.fs.File, index_writer: anytype) for (oids.items) |oid| { const offset = index_entries.get(oid).?.offset; if (offset <= std.math.maxInt(u31)) { - try writer.writeInt(u32, @intCast(offset), .Big); + try writer.writeInt(u32, @intCast(offset), .big); } else { const index = big_offsets.items.len; try big_offsets.append(allocator, offset); - try writer.writeInt(u32, @as(u32, @intCast(index)) | (1 << 31), .Big); + try writer.writeInt(u32, @as(u32, @intCast(index)) | (1 << 31), .big); } } for (big_offsets.items) |offset| { - try writer.writeInt(u64, offset, .Big); + try writer.writeInt(u64, offset, .big); } try writer.writeAll(&pack_checksum); diff --git a/src/Sema.zig b/src/Sema.zig index 293633dbc0..e8eeb78c71 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -26835,7 +26835,7 @@ fn structFieldPtrByIndex( // cause miscompilations; it only means the field pointer uses bit masking when it // might not be strictly necessary. if (parent_align != .none and ptr_ty_data.packed_offset.bit_offset % 8 == 0 and - target.cpu.arch.endian() == .Little) + target.cpu.arch.endian() == .little) { const elem_size_bytes = try sema.typeAbiSize(ptr_ty_data.child.toType()); const elem_size_bits = ptr_ty_data.child.toType().bitSize(mod); @@ -30736,8 +30736,8 @@ fn bitCastUnionFieldVal( if (field_size > old_size) { const min_size = @max(old_size, 1); switch (endian) { - .Little => @memset(buffer[min_size - 1 ..], 0xaa), - .Big => @memset(buffer[0 .. buffer.len - min_size + 1], 0xaa), + .little => @memset(buffer[min_size - 1 ..], 0xaa), + .big => @memset(buffer[0 .. buffer.len - min_size + 1], 0xaa), } } @@ -30746,7 +30746,7 @@ fn bitCastUnionFieldVal( error.ReinterpretDeclRef => return null, }; - break :offset if (endian == .Big) buffer.len - field_size else 0; + break :offset if (endian == .big) buffer.len - field_size else 0; }, .Auto => unreachable, }; diff --git a/src/arch/sparc64/CodeGen.zig b/src/arch/sparc64/CodeGen.zig index 26872ef29a..40f134ec90 100644 --- a/src/arch/sparc64/CodeGen.zig +++ b/src/arch/sparc64/CodeGen.zig @@ -1231,8 +1231,8 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void { const abi_size = int_info.bits >> 3; const abi_align = operand_ty.abiAlignment(mod); const opposite_endian_asi = switch (self.target.cpu.arch.endian()) { - Endian.Big => ASI.asi_primary_little, - Endian.Little => ASI.asi_primary, + Endian.big => ASI.asi_primary_little, + Endian.little => ASI.asi_primary, }; switch (operand) { diff --git a/src/arch/sparc64/Emit.zig b/src/arch/sparc64/Emit.zig index 2c39c70269..4701035bc9 100644 --- a/src/arch/sparc64/Emit.zig +++ b/src/arch/sparc64/Emit.zig @@ -677,7 +677,7 @@ fn writeInstruction(emit: *Emit, instruction: Instruction) !void { // SPARCv9 instructions are always arranged in BE regardless of the // endianness mode the CPU is running in (Section 3.1 of the ISA specification). // This is to ease porting in case someone wants to do a LE SPARCv9 backend. - const endian = Endian.Big; + const endian = Endian.big; std.mem.writeInt(u32, try emit.code.addManyAsArray(4), instruction.toU32(), endian); } diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index 3d12a015ed..9da4d3003b 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -3364,7 +3364,7 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue { const backing_int_ty = struct_type.backingIntType(ip).toType(); const int_val = try mod.intValue( backing_int_ty, - mem.readInt(u64, &buf, .Little), + mem.readInt(u64, &buf, .little), ); return func.lowerConstant(int_val, backing_int_ty); }, diff --git a/src/arch/wasm/Emit.zig b/src/arch/wasm/Emit.zig index 80f44d8ce2..1d0c461c96 100644 --- a/src/arch/wasm/Emit.zig +++ b/src/arch/wasm/Emit.zig @@ -330,14 +330,14 @@ fn emitImm64(emit: *Emit, inst: Mir.Inst.Index) !void { fn emitFloat32(emit: *Emit, inst: Mir.Inst.Index) !void { const value: f32 = emit.mir.instructions.items(.data)[inst].float32; try emit.code.append(std.wasm.opcode(.f32_const)); - try emit.code.writer().writeInt(u32, @bitCast(value), .Little); + try emit.code.writer().writeInt(u32, @bitCast(value), .little); } fn emitFloat64(emit: *Emit, inst: Mir.Inst.Index) !void { const extra_index = emit.mir.instructions.items(.data)[inst].payload; const value = emit.mir.extraData(Mir.Float64, extra_index); try emit.code.append(std.wasm.opcode(.f64_const)); - try emit.code.writer().writeInt(u64, value.data.toU64(), .Little); + try emit.code.writer().writeInt(u64, value.data.toU64(), .little); } fn emitMemArg(emit: *Emit, tag: Mir.Inst.Tag, inst: Mir.Inst.Index) !void { diff --git a/src/arch/x86_64/Disassembler.zig b/src/arch/x86_64/Disassembler.zig index 426cf10feb..b15327fd21 100644 --- a/src/arch/x86_64/Disassembler.zig +++ b/src/arch/x86_64/Disassembler.zig @@ -360,13 +360,13 @@ fn parseImm(dis: *Disassembler, kind: Encoding.Op) !Immediate { var creader = std.io.countingReader(stream.reader()); const reader = creader.reader(); const imm = switch (kind) { - .imm8s, .rel8 => Immediate.s(try reader.readInt(i8, .Little)), - .imm16s, .rel16 => Immediate.s(try reader.readInt(i16, .Little)), - .imm32s, .rel32 => Immediate.s(try reader.readInt(i32, .Little)), - .imm8 => Immediate.u(try reader.readInt(u8, .Little)), - .imm16 => Immediate.u(try reader.readInt(u16, .Little)), - .imm32 => Immediate.u(try reader.readInt(u32, .Little)), - .imm64 => Immediate.u(try reader.readInt(u64, .Little)), + .imm8s, .rel8 => Immediate.s(try reader.readInt(i8, .little)), + .imm16s, .rel16 => Immediate.s(try reader.readInt(i16, .little)), + .imm32s, .rel32 => Immediate.s(try reader.readInt(i32, .little)), + .imm8 => Immediate.u(try reader.readInt(u8, .little)), + .imm16 => Immediate.u(try reader.readInt(u16, .little)), + .imm32 => Immediate.u(try reader.readInt(u32, .little)), + .imm64 => Immediate.u(try reader.readInt(u64, .little)), else => unreachable, }; dis.pos += std.math.cast(usize, creader.bytes_read) orelse return error.Overflow; @@ -376,7 +376,7 @@ fn parseImm(dis: *Disassembler, kind: Encoding.Op) !Immediate { fn parseOffset(dis: *Disassembler) !u64 { var stream = std.io.fixedBufferStream(dis.code[dis.pos..]); const reader = stream.reader(); - const offset = try reader.readInt(u64, .Little); + const offset = try reader.readInt(u64, .little); dis.pos += 8; return offset; } @@ -457,16 +457,16 @@ fn parseDisplacement(dis: *Disassembler, modrm: ModRm, sib: ?Sib) !i32 { const disp = disp: { if (sib) |info| { if (info.base == 0b101 and modrm.mod == 0) { - break :disp try reader.readInt(i32, .Little); + break :disp try reader.readInt(i32, .little); } } if (modrm.rip()) { - break :disp try reader.readInt(i32, .Little); + break :disp try reader.readInt(i32, .little); } break :disp switch (modrm.mod) { 0b00 => 0, - 0b01 => try reader.readInt(i8, .Little), - 0b10 => try reader.readInt(i32, .Little), + 0b01 => try reader.readInt(i8, .little), + 0b10 => try reader.readInt(i32, .little), 0b11 => unreachable, }; }; diff --git a/src/arch/x86_64/Emit.zig b/src/arch/x86_64/Emit.zig index e6f2db3401..36f4b05a6e 100644 --- a/src/arch/x86_64/Emit.zig +++ b/src/arch/x86_64/Emit.zig @@ -253,7 +253,7 @@ fn fixupRelocs(emit: *Emit) Error!void { const target = emit.code_offset_mapping.get(reloc.target) orelse return emit.fail("JMP/CALL relocation target not found!", .{}); const disp = @as(i32, @intCast(@as(i64, @intCast(target)) - @as(i64, @intCast(reloc.source + reloc.length)))); - mem.writeInt(i32, emit.code.items[reloc.offset..][0..4], disp, .Little); + mem.writeInt(i32, emit.code.items[reloc.offset..][0..4], disp, .little); } } diff --git a/src/arch/x86_64/encoder.zig b/src/arch/x86_64/encoder.zig index 9d629dbff7..517dd1af8d 100644 --- a/src/arch/x86_64/encoder.zig +++ b/src/arch/x86_64/encoder.zig @@ -998,7 +998,7 @@ fn Encoder(comptime T: type, comptime opts: Options) type { /// /// It is sign-extended to 64 bits by the cpu. pub fn disp32(self: Self, disp: i32) !void { - try self.writer.writeInt(i32, disp, .Little); + try self.writer.writeInt(i32, disp, .little); } /// Encode an 8 bit immediate @@ -1012,21 +1012,21 @@ fn Encoder(comptime T: type, comptime opts: Options) type { /// /// It is sign-extended to 64 bits by the cpu. pub fn imm16(self: Self, imm: u16) !void { - try self.writer.writeInt(u16, imm, .Little); + try self.writer.writeInt(u16, imm, .little); } /// Encode an 32 bit immediate /// /// It is sign-extended to 64 bits by the cpu. pub fn imm32(self: Self, imm: u32) !void { - try self.writer.writeInt(u32, imm, .Little); + try self.writer.writeInt(u32, imm, .little); } /// Encode an 64 bit immediate /// /// It is sign-extended to 64 bits by the cpu. pub fn imm64(self: Self, imm: u64) !void { - try self.writer.writeInt(u64, imm, .Little); + try self.writer.writeInt(u64, imm, .little); } }; } diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 83d921ed9f..cf9467b70e 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -4666,8 +4666,8 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca try f.writeCValue(writer, local, .Other); if (dest_cty.castTag(.array)) |pl| { try writer.print("[{d}]", .{switch (target.cpu.arch.endian()) { - .Little => pl.data.len - 1, - .Big => 0, + .little => pl.data.len - 1, + .big => 0, }}); const elem_cty = f.indexToCType(pl.data.elem_type); wrap_cty = elem_cty.toSignedness(dest_info.signedness); @@ -4697,8 +4697,8 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca try f.writeCValue(writer, local, .Other); if (dest_cty.castTag(.array)) |pl| { try writer.print("[{d}]", .{switch (target.cpu.arch.endian()) { - .Little => pl.data.len - 1, - .Big => 0, + .little => pl.data.len - 1, + .big => 0, }}); } if (need_bitcasts) try writer.writeByte(')'); @@ -7652,13 +7652,13 @@ fn formatIntLiteral( else => .{ .cty = CType.initTag(.void), .count = 1, - .endian = .Little, + .endian = .little, .homogeneous = true, }, .zig_u128, .zig_i128 => .{ .cty = CType.initTag(.uint64_t), .count = 2, - .endian = .Big, + .endian = .big, .homogeneous = false, }, .array => info: { @@ -7729,8 +7729,8 @@ fn formatIntLiteral( const most_significant_limb_i = wrap.len - limbs_per_c_limb; while (limb_offset < wrap.len) : (limb_offset += limbs_per_c_limb) { const limb_i = switch (c_limb_info.endian) { - .Little => limb_offset, - .Big => most_significant_limb_i - limb_offset, + .little => limb_offset, + .big => most_significant_limb_i - limb_offset, }; var c_limb_mut = BigInt.Mutable{ .limbs = wrap.limbs[limb_i..][0..limbs_per_c_limb], diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 9edc456b35..356e4c318b 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -342,8 +342,8 @@ const DataLayoutBuilder = struct { writer: anytype, ) @TypeOf(writer).Error!void { try writer.writeByte(switch (self.target.cpu.arch.endian()) { - .Little => 'e', - .Big => 'E', + .little => 'e', + .big => 'E', }); switch (self.target.cpu.arch) { .amdgcn, @@ -10453,7 +10453,7 @@ pub const FuncGen = struct { else payload_llvm_ty; const loaded = try fg.wip.load(access_kind, load_llvm_ty, payload_ptr, payload_alignment, ""); - const shifted = if (payload_llvm_ty != load_llvm_ty and o.target.cpu.arch.endian() == .Big) + const shifted = if (payload_llvm_ty != load_llvm_ty and o.target.cpu.arch.endian() == .big) try fg.wip.bin(.lshr, loaded, try o.builder.intValue( load_llvm_ty, (payload_ty.abiSize(mod) - (std.math.divCeil(u64, payload_ty.bitSize(mod), 8) catch unreachable)) * 8, diff --git a/src/glibc.zig b/src/glibc.zig index 1a50f6b7c5..d719dab491 100644 --- a/src/glibc.zig +++ b/src/glibc.zig @@ -751,7 +751,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo var inc_i: usize = 0; - const fn_inclusions_len = mem.readInt(u16, metadata.inclusions[inc_i..][0..2], .Little); + const fn_inclusions_len = mem.readInt(u16, metadata.inclusions[inc_i..][0..2], .little); inc_i += 2; var sym_i: usize = 0; @@ -768,7 +768,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo versions_len = 0; break :n name; }; - const targets = mem.readInt(u32, metadata.inclusions[inc_i..][0..4], .Little); + const targets = mem.readInt(u32, metadata.inclusions[inc_i..][0..4], .little); inc_i += 4; const lib_index = metadata.inclusions[inc_i]; @@ -882,7 +882,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo try stubs_asm.appendSlice(".data\n"); - const obj_inclusions_len = mem.readInt(u16, metadata.inclusions[inc_i..][0..2], .Little); + const obj_inclusions_len = mem.readInt(u16, metadata.inclusions[inc_i..][0..2], .little); inc_i += 2; sym_i = 0; @@ -899,10 +899,10 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo versions_len = 0; break :n name; }; - const targets = mem.readInt(u32, metadata.inclusions[inc_i..][0..4], .Little); + const targets = mem.readInt(u32, metadata.inclusions[inc_i..][0..4], .little); inc_i += 4; - const size = mem.readInt(u16, metadata.inclusions[inc_i..][0..2], .Little); + const size = mem.readInt(u16, metadata.inclusions[inc_i..][0..2], .little); inc_i += 2; const lib_index = metadata.inclusions[inc_i]; diff --git a/src/link/Coff.zig b/src/link/Coff.zig index affc7406b7..fd2415bff5 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -856,12 +856,12 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void { switch (self.ptr_width) { .p32 => { var buf: [4]u8 = undefined; - mem.writeInt(u32, &buf, @as(u32, @intCast(entry_value + self.getImageBase())), .Little); + mem.writeInt(u32, &buf, @as(u32, @intCast(entry_value + self.getImageBase())), .little); try self.base.file.?.pwriteAll(&buf, file_offset); }, .p64 => { var buf: [8]u8 = undefined; - mem.writeInt(u64, &buf, entry_value + self.getImageBase(), .Little); + mem.writeInt(u64, &buf, entry_value + self.getImageBase(), .little); try self.base.file.?.pwriteAll(&buf, file_offset); }, } @@ -889,14 +889,14 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void { switch (self.ptr_width) { .p32 => { var buf: [4]u8 = undefined; - mem.writeInt(u32, &buf, @as(u32, @intCast(entry_value + slide)), .Little); + mem.writeInt(u32, &buf, @as(u32, @intCast(entry_value + slide)), .little); writeMem(handle, pvaddr, &buf) catch |err| { log.warn("writing to protected memory failed with error: {s}", .{@errorName(err)}); }; }, .p64 => { var buf: [8]u8 = undefined; - mem.writeInt(u64, &buf, entry_value + slide, .Little); + mem.writeInt(u64, &buf, entry_value + slide, .little); writeMem(handle, pvaddr, &buf) catch |err| { log.warn("writing to protected memory failed with error: {s}", .{@errorName(err)}); }; @@ -2076,7 +2076,7 @@ fn writeImportTables(self: *Coff) !void { lookup_table_offset += lookup_entry_size; // Names table entry - mem.writeInt(u16, buffer.items[names_table_offset..][0..2], 0, .Little); // Hint set to 0 until we learn how to parse DLLs + mem.writeInt(u16, buffer.items[names_table_offset..][0..2], 0, .little); // Hint set to 0 until we learn how to parse DLLs names_table_offset += 2; @memcpy(buffer.items[names_table_offset..][0..import_name.len], import_name); names_table_offset += @as(u32, @intCast(import_name.len)); @@ -2089,7 +2089,7 @@ fn writeImportTables(self: *Coff) !void { } // IAT sentinel - mem.writeInt(u64, buffer.items[iat_offset..][0..lookup_entry_size], 0, .Little); + mem.writeInt(u64, buffer.items[iat_offset..][0..lookup_entry_size], 0, .little); iat_offset += 8; // Lookup table sentinel @@ -2157,7 +2157,7 @@ fn writeStrtab(self: *Coff) !void { buffer.appendSliceAssumeCapacity(self.strtab.items()); // Here, we do a trick in that we do not commit the size of the strtab to strtab buffer, instead // we write the length of the strtab to a temporary buffer that goes to file. - mem.writeInt(u32, buffer.items[0..4], @as(u32, @intCast(self.strtab.len())), .Little); + mem.writeInt(u32, buffer.items[0..4], @as(u32, @intCast(self.strtab.len())), .little); try self.base.file.?.pwriteAll(buffer.items, self.strtab_offset.?); } @@ -2180,7 +2180,7 @@ fn writeHeader(self: *Coff) !void { try buffer.ensureTotalCapacity(self.getSizeOfHeaders()); writer.writeAll(msdos_stub) catch unreachable; - mem.writeInt(u32, buffer.items[0x3c..][0..4], msdos_stub.len, .Little); + mem.writeInt(u32, buffer.items[0x3c..][0..4], msdos_stub.len, .little); writer.writeAll("PE\x00\x00") catch unreachable; var flags = coff.CoffHeaderFlags{ @@ -2548,7 +2548,7 @@ fn setSymbolName(self: *Coff, symbol: *coff.Symbol, name: []const u8) !void { } const offset = try self.strtab.insert(self.base.allocator, name); @memset(symbol.name[0..4], 0); - mem.writeInt(u32, symbol.name[4..8], offset, .Little); + mem.writeInt(u32, symbol.name[4..8], offset, .little); } fn logSymAttributes(sym: *const coff.Symbol, buf: *[4]u8) []const u8 { diff --git a/src/link/Coff/Relocation.zig b/src/link/Coff/Relocation.zig index 050ab0d9be..84cfcdc18a 100644 --- a/src/link/Coff/Relocation.zig +++ b/src/link/Coff/Relocation.zig @@ -137,7 +137,7 @@ fn resolveAarch64(self: Relocation, ctx: Context) void { }; inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2)); inst.pc_relative_address.immlo = @as(u2, @truncate(pages)); - mem.writeInt(u32, buffer[0..4], inst.toU32(), .Little); + mem.writeInt(u32, buffer[0..4], inst.toU32(), .little); }, .got_pageoff, .import_pageoff, .pageoff => { assert(!self.pcrel); @@ -151,7 +151,7 @@ fn resolveAarch64(self: Relocation, ctx: Context) void { ), buffer[0..4]), }; inst.add_subtract_immediate.imm12 = narrowed; - mem.writeInt(u32, buffer[0..4], inst.toU32(), .Little); + mem.writeInt(u32, buffer[0..4], inst.toU32(), .little); } else { var inst = aarch64.Instruction{ .load_store_register = mem.bytesToValue(meta.TagPayload( @@ -173,7 +173,7 @@ fn resolveAarch64(self: Relocation, ctx: Context) void { } }; inst.load_store_register.offset = offset; - mem.writeInt(u32, buffer[0..4], inst.toU32(), .Little); + mem.writeInt(u32, buffer[0..4], inst.toU32(), .little); } }, .direct => { @@ -183,9 +183,9 @@ fn resolveAarch64(self: Relocation, ctx: Context) void { u32, buffer[0..4], @as(u32, @truncate(ctx.target_vaddr + ctx.image_base)), - .Little, + .little, ), - 3 => mem.writeInt(u64, buffer[0..8], ctx.target_vaddr + ctx.image_base, .Little), + 3 => mem.writeInt(u64, buffer[0..8], ctx.target_vaddr + ctx.image_base, .little), else => unreachable, } }, @@ -208,17 +208,17 @@ fn resolveX86(self: Relocation, ctx: Context) void { .got, .import => { assert(self.pcrel); const disp = @as(i32, @intCast(ctx.target_vaddr)) - @as(i32, @intCast(ctx.source_vaddr)) - 4; - mem.writeInt(i32, buffer[0..4], disp, .Little); + mem.writeInt(i32, buffer[0..4], disp, .little); }, .direct => { if (self.pcrel) { const disp = @as(i32, @intCast(ctx.target_vaddr)) - @as(i32, @intCast(ctx.source_vaddr)) - 4; - mem.writeInt(i32, buffer[0..4], disp, .Little); + mem.writeInt(i32, buffer[0..4], disp, .little); } else switch (ctx.ptr_width) { - .p32 => mem.writeInt(u32, buffer[0..4], @as(u32, @intCast(ctx.target_vaddr + ctx.image_base)), .Little), + .p32 => mem.writeInt(u32, buffer[0..4], @as(u32, @intCast(ctx.target_vaddr + ctx.image_base)), .little), .p64 => switch (self.length) { - 2 => mem.writeInt(u32, buffer[0..4], @as(u32, @truncate(ctx.target_vaddr + ctx.image_base)), .Little), - 3 => mem.writeInt(u64, buffer[0..8], ctx.target_vaddr + ctx.image_base, .Little), + 2 => mem.writeInt(u32, buffer[0..4], @as(u32, @truncate(ctx.target_vaddr + ctx.image_base)), .little), + 3 => mem.writeInt(u64, buffer[0..8], ctx.target_vaddr + ctx.image_base, .little), else => unreachable, }, } diff --git a/src/link/Elf.zig b/src/link/Elf.zig index d368e95edc..63642d4c6a 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -2719,8 +2719,8 @@ fn writeHeader(self: *Elf) !void { const endian = self.base.options.target.cpu.arch.endian(); hdr_buf[index] = switch (endian) { - .Little => elf.ELFDATA2LSB, - .Big => elf.ELFDATA2MSB, + .little => elf.ELFDATA2LSB, + .big => elf.ELFDATA2MSB, }; index += 1; diff --git a/src/link/Elf/Atom.zig b/src/link/Elf/Atom.zig index f3b41f2e10..7527b61988 100644 --- a/src/link/Elf/Atom.zig +++ b/src/link/Elf/Atom.zig @@ -786,43 +786,43 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void { elf.R_X86_64_PLT32, elf.R_X86_64_PC32, - => try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .Little), + => try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .little), - elf.R_X86_64_GOTPCREL => try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .Little), - elf.R_X86_64_GOTPC32 => try cwriter.writeInt(i32, @as(i32, @intCast(GOT + A - P)), .Little), - elf.R_X86_64_GOTPC64 => try cwriter.writeInt(i64, GOT + A - P, .Little), + elf.R_X86_64_GOTPCREL => try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .little), + elf.R_X86_64_GOTPC32 => try cwriter.writeInt(i32, @as(i32, @intCast(GOT + A - P)), .little), + elf.R_X86_64_GOTPC64 => try cwriter.writeInt(i64, GOT + A - P, .little), elf.R_X86_64_GOTPCRELX => { if (!target.flags.import and !target.isIFunc(elf_file) and !target.isAbs(elf_file)) blk: { x86_64.relaxGotpcrelx(code[r_offset - 2 ..]) catch break :blk; - try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .Little); + try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .little); continue; } - try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .Little); + try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .little); }, elf.R_X86_64_REX_GOTPCRELX => { if (!target.flags.import and !target.isIFunc(elf_file) and !target.isAbs(elf_file)) blk: { x86_64.relaxRexGotpcrelx(code[r_offset - 3 ..]) catch break :blk; - try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .Little); + try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .little); continue; } - try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .Little); + try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .little); }, - elf.R_X86_64_32 => try cwriter.writeInt(u32, @as(u32, @truncate(@as(u64, @intCast(S + A)))), .Little), - elf.R_X86_64_32S => try cwriter.writeInt(i32, @as(i32, @truncate(S + A)), .Little), + elf.R_X86_64_32 => try cwriter.writeInt(u32, @as(u32, @truncate(@as(u64, @intCast(S + A)))), .little), + elf.R_X86_64_32S => try cwriter.writeInt(i32, @as(i32, @truncate(S + A)), .little), - elf.R_X86_64_TPOFF32 => try cwriter.writeInt(i32, @as(i32, @truncate(S + A - TP)), .Little), - elf.R_X86_64_TPOFF64 => try cwriter.writeInt(i64, S + A - TP, .Little), + elf.R_X86_64_TPOFF32 => try cwriter.writeInt(i32, @as(i32, @truncate(S + A - TP)), .little), + elf.R_X86_64_TPOFF64 => try cwriter.writeInt(i64, S + A - TP, .little), - elf.R_X86_64_DTPOFF32 => try cwriter.writeInt(i32, @as(i32, @truncate(S + A - DTP)), .Little), - elf.R_X86_64_DTPOFF64 => try cwriter.writeInt(i64, S + A - DTP, .Little), + elf.R_X86_64_DTPOFF32 => try cwriter.writeInt(i32, @as(i32, @truncate(S + A - DTP)), .little), + elf.R_X86_64_DTPOFF64 => try cwriter.writeInt(i64, S + A - DTP, .little), elf.R_X86_64_TLSGD => { if (target.flags.has_tlsgd) { const S_ = @as(i64, @intCast(target.tlsGdAddress(elf_file))); - try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .Little); + try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .little); } else if (target.flags.has_gottp) { const S_ = @as(i64, @intCast(target.gotTpAddress(elf_file))); 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 { if (elf_file.got.tlsld_index) |entry_index| { const tlsld_entry = elf_file.got.entries.items[entry_index]; const S_ = @as(i64, @intCast(tlsld_entry.address(elf_file))); - try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .Little); + try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .little); } else { try x86_64.relaxTlsLdToLe( self, @@ -859,10 +859,10 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void { elf.R_X86_64_GOTPC32_TLSDESC => { if (target.flags.has_tlsdesc) { const S_ = @as(i64, @intCast(target.tlsDescAddress(elf_file))); - try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .Little); + try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .little); } else { try x86_64.relaxGotPcTlsDesc(code[r_offset - 3 ..]); - try cwriter.writeInt(i32, @as(i32, @intCast(S - TP)), .Little); + try cwriter.writeInt(i32, @as(i32, @intCast(S - TP)), .little); } }, @@ -874,18 +874,18 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) !void { elf.R_X86_64_GOTTPOFF => { if (target.flags.has_gottp) { const S_ = @as(i64, @intCast(target.gotTpAddress(elf_file))); - try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .Little); + try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .little); } else { x86_64.relaxGotTpOff(code[r_offset - 3 ..]) catch unreachable; - try cwriter.writeInt(i32, @as(i32, @intCast(S - TP)), .Little); + try cwriter.writeInt(i32, @as(i32, @intCast(S - TP)), .little); } }, - elf.R_X86_64_GOT32 => try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A)), .Little), + elf.R_X86_64_GOT32 => try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A)), .little), // Zig custom relocations - Elf.R_X86_64_ZIG_GOT32 => try cwriter.writeInt(u32, @as(u32, @intCast(ZIG_GOT + A)), .Little), - Elf.R_X86_64_ZIG_GOTPCREL => try cwriter.writeInt(i32, @as(i32, @intCast(ZIG_GOT + A - P)), .Little), + Elf.R_X86_64_ZIG_GOT32 => try cwriter.writeInt(u32, @as(u32, @intCast(ZIG_GOT + A)), .little), + Elf.R_X86_64_ZIG_GOTPCREL => try cwriter.writeInt(i32, @as(i32, @intCast(ZIG_GOT + A - P)), .little), else => {}, } @@ -920,7 +920,7 @@ fn resolveDynAbsReloc( .copyrel, .cplt, .none, - => try writer.writeInt(i32, @as(i32, @truncate(S + A)), .Little), + => try writer.writeInt(i32, @as(i32, @truncate(S + A)), .little), .dyn_copyrel => { if (is_writeable or elf_file.base.options.z_nocopyreloc) { @@ -932,7 +932,7 @@ fn resolveDynAbsReloc( }); try applyDynamicReloc(A, elf_file, writer); } else { - try writer.writeInt(i32, @as(i32, @truncate(S + A)), .Little); + try writer.writeInt(i32, @as(i32, @truncate(S + A)), .little); } }, @@ -946,7 +946,7 @@ fn resolveDynAbsReloc( }); try applyDynamicReloc(A, elf_file, writer); } else { - try writer.writeInt(i32, @as(i32, @truncate(S + A)), .Little); + try writer.writeInt(i32, @as(i32, @truncate(S + A)), .little); } }, @@ -984,7 +984,7 @@ fn resolveDynAbsReloc( fn applyDynamicReloc(value: i64, elf_file: *Elf, writer: anytype) !void { _ = elf_file; // if (elf_file.options.apply_dynamic_relocs) { - try writer.writeInt(i64, value, .Little); + try writer.writeInt(i64, value, .little); // } } @@ -1058,22 +1058,22 @@ pub fn resolveRelocsNonAlloc(self: Atom, elf_file: *Elf, code: []u8, undefs: any switch (r_type) { elf.R_X86_64_NONE => unreachable, - elf.R_X86_64_8 => try cwriter.writeInt(u8, @as(u8, @bitCast(@as(i8, @intCast(S + A)))), .Little), - elf.R_X86_64_16 => try cwriter.writeInt(u16, @as(u16, @bitCast(@as(i16, @intCast(S + A)))), .Little), - elf.R_X86_64_32 => try cwriter.writeInt(u32, @as(u32, @bitCast(@as(i32, @intCast(S + A)))), .Little), - elf.R_X86_64_32S => try cwriter.writeInt(i32, @as(i32, @intCast(S + A)), .Little), - elf.R_X86_64_64 => try cwriter.writeInt(i64, S + A, .Little), - elf.R_X86_64_DTPOFF32 => try cwriter.writeInt(i32, @as(i32, @intCast(S + A - DTP)), .Little), - elf.R_X86_64_DTPOFF64 => try cwriter.writeInt(i64, S + A - DTP, .Little), - elf.R_X86_64_GOTOFF64 => try cwriter.writeInt(i64, S + A - GOT, .Little), - elf.R_X86_64_GOTPC64 => try cwriter.writeInt(i64, GOT + A, .Little), + elf.R_X86_64_8 => try cwriter.writeInt(u8, @as(u8, @bitCast(@as(i8, @intCast(S + A)))), .little), + elf.R_X86_64_16 => try cwriter.writeInt(u16, @as(u16, @bitCast(@as(i16, @intCast(S + A)))), .little), + elf.R_X86_64_32 => try cwriter.writeInt(u32, @as(u32, @bitCast(@as(i32, @intCast(S + A)))), .little), + elf.R_X86_64_32S => try cwriter.writeInt(i32, @as(i32, @intCast(S + A)), .little), + elf.R_X86_64_64 => try cwriter.writeInt(i64, S + A, .little), + elf.R_X86_64_DTPOFF32 => try cwriter.writeInt(i32, @as(i32, @intCast(S + A - DTP)), .little), + elf.R_X86_64_DTPOFF64 => try cwriter.writeInt(i64, S + A - DTP, .little), + elf.R_X86_64_GOTOFF64 => try cwriter.writeInt(i64, S + A - GOT, .little), + elf.R_X86_64_GOTPC64 => try cwriter.writeInt(i64, GOT + A, .little), elf.R_X86_64_SIZE32 => { const size = @as(i64, @intCast(target.elfSym(elf_file).st_size)); - try cwriter.writeInt(u32, @as(u32, @bitCast(@as(i32, @intCast(size + A)))), .Little); + try cwriter.writeInt(u32, @as(u32, @bitCast(@as(i32, @intCast(size + A)))), .little); }, elf.R_X86_64_SIZE64 => { const size = @as(i64, @intCast(target.elfSym(elf_file).st_size)); - try cwriter.writeInt(i64, @as(i64, @intCast(size + A)), .Little); + try cwriter.writeInt(i64, @as(i64, @intCast(size + A)), .little); }, else => try self.reportUnhandledRelocError(rel, elf_file), } @@ -1254,7 +1254,7 @@ const x86_64 = struct { 0x64, 0x48, 0x8b, 0x04, 0x25, 0, 0, 0, 0, // movq %fs:0,%rax 0x48, 0x03, 0x05, 0, 0, 0, 0, // add foo@gottpoff(%rip), %rax }; - std.mem.writeInt(i32, insts[12..][0..4], value - 12, .Little); + std.mem.writeInt(i32, insts[12..][0..4], value - 12, .little); try stream.seekBy(-4); try writer.writeAll(&insts); }, @@ -1292,7 +1292,7 @@ const x86_64 = struct { 0x64, 0x48, 0x8b, 0, // mov %fs:(%rax), %rax 0x48, 0x2d, 0, 0, 0, 0, // sub $tls_size, %rax }; - std.mem.writeInt(i32, insts[8..][0..4], value, .Little); + std.mem.writeInt(i32, insts[8..][0..4], value, .little); try stream.seekBy(-3); try writer.writeAll(&insts); }, @@ -1306,7 +1306,7 @@ const x86_64 = struct { 0x48, 0x2d, 0, 0, 0, 0, // sub $tls_size, %rax 0x90, // nop }; - std.mem.writeInt(i32, insts[8..][0..4], value, .Little); + std.mem.writeInt(i32, insts[8..][0..4], value, .little); try stream.seekBy(-3); try writer.writeAll(&insts); }, @@ -1392,7 +1392,7 @@ const x86_64 = struct { 0x64, 0x48, 0x8b, 0x04, 0x25, 0, 0, 0, 0, // movq %fs:0,%rax 0x48, 0x81, 0xc0, 0, 0, 0, 0, // add $tp_offset, %rax }; - std.mem.writeInt(i32, insts[12..][0..4], value, .Little); + std.mem.writeInt(i32, insts[12..][0..4], value, .little); try stream.seekBy(-4); try writer.writeAll(&insts); relocs_log.debug(" relaxing {} and {}", .{ diff --git a/src/link/Elf/eh_frame.zig b/src/link/Elf/eh_frame.zig index 3f291f9a77..caf6f9a051 100644 --- a/src/link/Elf/eh_frame.zig +++ b/src/link/Elf/eh_frame.zig @@ -33,7 +33,7 @@ pub const Fde = struct { pub fn ciePointer(fde: Fde, elf_file: *Elf) u32 { const fde_data = fde.data(elf_file); - return std.mem.readInt(u32, fde_data[4..8], .Little); + return std.mem.readInt(u32, fde_data[4..8], .little); } pub fn calcSize(fde: Fde) usize { @@ -217,10 +217,10 @@ pub const Iterator = struct { var stream = std.io.fixedBufferStream(it.data[it.pos..]); const reader = stream.reader(); - var size = try reader.readInt(u32, .Little); + var size = try reader.readInt(u32, .little); if (size == 0xFFFFFFFF) @panic("TODO"); - const id = try reader.readInt(u32, .Little); + const id = try reader.readInt(u32, .little); const record = Record{ .tag = if (id == 0) .cie else .fde, .offset = it.pos, @@ -298,10 +298,10 @@ fn resolveReloc(rec: anytype, sym: *const Symbol, rel: elf.Elf64_Rela, elf_file: var where = contents[offset..]; switch (rel.r_type()) { - elf.R_X86_64_32 => std.mem.writeInt(i32, where[0..4], @as(i32, @truncate(S + A)), .Little), - elf.R_X86_64_64 => std.mem.writeInt(i64, where[0..8], S + A, .Little), - elf.R_X86_64_PC32 => std.mem.writeInt(i32, where[0..4], @as(i32, @intCast(S - P + A)), .Little), - elf.R_X86_64_PC64 => std.mem.writeInt(i64, where[0..8], S - P + A, .Little), + elf.R_X86_64_32 => std.mem.writeInt(i32, where[0..4], @as(i32, @truncate(S + A)), .little), + elf.R_X86_64_64 => std.mem.writeInt(i64, where[0..8], S + A, .little), + elf.R_X86_64_PC32 => std.mem.writeInt(i32, where[0..4], @as(i32, @intCast(S - P + A)), .little), + elf.R_X86_64_PC64 => std.mem.writeInt(i64, where[0..8], S - P + A, .little), else => unreachable, } } @@ -342,7 +342,7 @@ pub fn writeEhFrame(elf_file: *Elf, writer: anytype) !void { i32, contents[4..8], @truncate(@as(i64, @intCast(fde.out_offset + 4)) - @as(i64, @intCast(fde.cie(elf_file).out_offset))), - .Little, + .little, ); for (fde.relocs(elf_file)) |rel| { @@ -354,7 +354,7 @@ pub fn writeEhFrame(elf_file: *Elf, writer: anytype) !void { } } - try writer.writeInt(u32, 0, .Little); + try writer.writeInt(u32, 0, .little); } pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void { @@ -372,9 +372,9 @@ pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void { i32, @truncate(@as(i64, @intCast(eh_frame_shdr.sh_addr)) - @as(i64, @intCast(eh_frame_hdr_shdr.sh_addr)) - 4), ))), - .Little, + .little, ); - try writer.writeInt(u32, num_fdes, .Little); + try writer.writeInt(u32, num_fdes, .little); const Entry = struct { init_addr: u32, diff --git a/src/link/Elf/synthetic_sections.zig b/src/link/Elf/synthetic_sections.zig index 0d78aea322..cfc2064fbe 100644 --- a/src/link/Elf/synthetic_sections.zig +++ b/src/link/Elf/synthetic_sections.zig @@ -878,9 +878,9 @@ pub const PltSection = struct { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp qword ptr [rip] -> .got.plt[2] }; var disp = @as(i64, @intCast(got_plt_addr + 8)) - @as(i64, @intCast(plt_addr + 8)) - 4; - mem.writeInt(i32, preamble[8..][0..4], @as(i32, @intCast(disp)), .Little); + mem.writeInt(i32, preamble[8..][0..4], @as(i32, @intCast(disp)), .little); disp = @as(i64, @intCast(got_plt_addr + 16)) - @as(i64, @intCast(plt_addr + 14)) - 4; - mem.writeInt(i32, preamble[14..][0..4], @as(i32, @intCast(disp)), .Little); + mem.writeInt(i32, preamble[14..][0..4], @as(i32, @intCast(disp)), .little); try writer.writeAll(&preamble); try writer.writeByteNTimes(0xcc, preamble_size - preamble.len); @@ -894,8 +894,8 @@ pub const PltSection = struct { 0x41, 0xbb, 0x00, 0x00, 0x00, 0x00, // mov r11d, N 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp qword ptr [rip] -> .got.plt[N] }; - mem.writeInt(i32, entry[6..][0..4], @as(i32, @intCast(i)), .Little); - mem.writeInt(i32, entry[12..][0..4], @as(i32, @intCast(disp)), .Little); + mem.writeInt(i32, entry[6..][0..4], @as(i32, @intCast(i)), .little); + mem.writeInt(i32, entry[12..][0..4], @as(i32, @intCast(disp)), .little); try writer.writeAll(&entry); } } @@ -971,17 +971,17 @@ pub const GotPltSection = struct { { // [0]: _DYNAMIC const symbol = elf_file.symbol(elf_file.dynamic_index.?); - try writer.writeInt(u64, symbol.value, .Little); + try writer.writeInt(u64, symbol.value, .little); } // [1]: 0x0 // [2]: 0x0 - try writer.writeInt(u64, 0x0, .Little); - try writer.writeInt(u64, 0x0, .Little); + try writer.writeInt(u64, 0x0, .little); + try writer.writeInt(u64, 0x0, .little); if (elf_file.plt_section_index) |shndx| { const plt_addr = elf_file.shdrs.items[shndx].sh_addr; for (0..elf_file.plt.symbols.items.len) |_| { // [N]: .plt - try writer.writeInt(u64, plt_addr, .Little); + try writer.writeInt(u64, plt_addr, .little); } } } @@ -1023,7 +1023,7 @@ pub const PltGotSection = struct { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // jmp qword ptr [rip] -> .got[N] 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, }; - mem.writeInt(i32, entry[6..][0..4], @as(i32, @intCast(disp)), .Little); + mem.writeInt(i32, entry[6..][0..4], @as(i32, @intCast(disp)), .little); try writer.writeAll(&entry); } } @@ -1258,8 +1258,8 @@ pub const HashSection = struct { } try hs.buffer.ensureTotalCapacityPrecise(gpa, (2 + nsyms * 2) * 4); - hs.buffer.writer(gpa).writeInt(u32, @as(u32, @intCast(nsyms)), .Little) catch unreachable; - hs.buffer.writer(gpa).writeInt(u32, @as(u32, @intCast(nsyms)), .Little) catch unreachable; + hs.buffer.writer(gpa).writeInt(u32, @as(u32, @intCast(nsyms)), .little) catch unreachable; + hs.buffer.writer(gpa).writeInt(u32, @as(u32, @intCast(nsyms)), .little) catch unreachable; hs.buffer.writer(gpa).writeAll(mem.sliceAsBytes(buckets)) catch unreachable; hs.buffer.writer(gpa).writeAll(mem.sliceAsBytes(chains)) catch unreachable; } @@ -1322,10 +1322,10 @@ pub const GnuHashSection = struct { var counting = std.io.countingWriter(writer); const cwriter = counting.writer(); - try cwriter.writeInt(u32, hash.num_buckets, .Little); - try cwriter.writeInt(u32, export_off, .Little); - try cwriter.writeInt(u32, hash.num_bloom, .Little); - try cwriter.writeInt(u32, bloom_shift, .Little); + try cwriter.writeInt(u32, hash.num_buckets, .little); + try cwriter.writeInt(u32, export_off, .little); + try cwriter.writeInt(u32, hash.num_bloom, .little); + try cwriter.writeInt(u32, bloom_shift, .little); const gpa = elf_file.base.allocator; const hashes = try gpa.alloc(u32, exports.len); diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 55b9c617b1..5a246bcfd1 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -1222,7 +1222,7 @@ fn writeOffsetTableEntry(self: *MachO, index: usize) !void { log.debug("writing GOT entry {d}: @{x} => {x}", .{ index, vmaddr, entry_value }); var buf: [@sizeOf(u64)]u8 = undefined; - mem.writeInt(u64, &buf, entry_value, .Little); + mem.writeInt(u64, &buf, entry_value, .little); try self.base.file.?.pwriteAll(&buf, file_offset); if (is_hot_update_compatible) { @@ -1329,7 +1329,7 @@ fn writeStubTableEntry(self: *MachO, index: usize) !void { { var buf: [@sizeOf(u64)]u8 = undefined; - mem.writeInt(u64, &buf, stub_helper_addr, .Little); + mem.writeInt(u64, &buf, stub_helper_addr, .little); const off = laptr_header.offset + @sizeOf(u64) * index; try self.base.file.?.pwriteAll(&buf, off); } @@ -3773,7 +3773,7 @@ fn collectBindData(self: *MachO, bind: anytype, raw_bindings: anytype) !void { const base_offset = sym.n_value - segment.vmaddr; const rel_offset = @as(u32, @intCast(rel.r_address - ctx.base_offset)); const offset = @as(u64, @intCast(base_offset + rel_offset)); - const addend = mem.readInt(i64, code[rel_offset..][0..8], .Little); + const addend = mem.readInt(i64, code[rel_offset..][0..8], .little); const dylib_ordinal = @divTrunc(@as(i16, @bitCast(bind_sym.n_desc)), macho.N_SYMBOL_RESOLVER); log.debug(" | bind at {x}, import('{s}') in dylib({d})", .{ @@ -4502,7 +4502,7 @@ pub fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void { if (!self.stub_table.lookup.contains(entry)) continue; const target_sym = self.getSymbol(entry); assert(target_sym.undf()); - try writer.writeInt(u32, iundefsym + ctx.imports_table.get(entry).?, .Little); + try writer.writeInt(u32, iundefsym + ctx.imports_table.get(entry).?, .little); } } @@ -4513,9 +4513,9 @@ pub fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void { if (!self.got_table.lookup.contains(entry)) continue; const target_sym = self.getSymbol(entry); if (target_sym.undf()) { - try writer.writeInt(u32, iundefsym + ctx.imports_table.get(entry).?, .Little); + try writer.writeInt(u32, iundefsym + ctx.imports_table.get(entry).?, .little); } else { - try writer.writeInt(u32, macho.INDIRECT_SYMBOL_LOCAL, .Little); + try writer.writeInt(u32, macho.INDIRECT_SYMBOL_LOCAL, .little); } } } @@ -4527,7 +4527,7 @@ pub fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void { if (!self.stub_table.lookup.contains(entry)) continue; const target_sym = self.getSymbol(entry); assert(target_sym.undf()); - try writer.writeInt(u32, iundefsym + ctx.imports_table.get(entry).?, .Little); + try writer.writeInt(u32, iundefsym + ctx.imports_table.get(entry).?, .little); } } diff --git a/src/link/MachO/Archive.zig b/src/link/MachO/Archive.zig index fec7ce65ef..6bdc6d916d 100644 --- a/src/link/MachO/Archive.zig +++ b/src/link/MachO/Archive.zig @@ -123,7 +123,7 @@ fn parseName(allocator: Allocator, name_or_length: ar_hdr.NameOrLength, reader: } fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) !void { - const symtab_size = try reader.readInt(u32, .Little); + const symtab_size = try reader.readInt(u32, .little); var symtab = try allocator.alloc(u8, symtab_size); defer allocator.free(symtab); @@ -132,7 +132,7 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) ! return error.MalformedArchive; }; - const strtab_size = try reader.readInt(u32, .Little); + const strtab_size = try reader.readInt(u32, .little); var strtab = try allocator.alloc(u8, strtab_size); defer allocator.free(strtab); @@ -145,11 +145,11 @@ fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) ! var symtab_reader = symtab_stream.reader(); while (true) { - const n_strx = symtab_reader.readInt(u32, .Little) catch |err| switch (err) { + const n_strx = symtab_reader.readInt(u32, .little) catch |err| switch (err) { error.EndOfStream => break, else => |e| return e, }; - const object_offset = try symtab_reader.readInt(u32, .Little); + const object_offset = try symtab_reader.readInt(u32, .little); const sym_name = mem.sliceTo(@as([*:0]const u8, @ptrCast(strtab.ptr + n_strx)), 0); const owned_name = try allocator.dupe(u8, sym_name); diff --git a/src/link/MachO/Atom.zig b/src/link/MachO/Atom.zig index 4c8fc03e3c..290c67c45e 100644 --- a/src/link/MachO/Atom.zig +++ b/src/link/MachO/Atom.zig @@ -443,9 +443,9 @@ pub fn parseRelocTarget(macho_file: *MachO, ctx: struct { const address_in_section = if (ctx.rel.r_pcrel == 0) blk: { break :blk if (ctx.rel.r_length == 3) - mem.readInt(u64, ctx.code[rel_offset..][0..8], .Little) + mem.readInt(u64, ctx.code[rel_offset..][0..8], .little) else - mem.readInt(u32, ctx.code[rel_offset..][0..4], .Little); + mem.readInt(u32, ctx.code[rel_offset..][0..4], .little); } else blk: { assert(macho_file.base.options.target.cpu.arch == .x86_64); 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 { .X86_64_RELOC_SIGNED_4 => 4, else => unreachable, }; - const addend = mem.readInt(i32, ctx.code[rel_offset..][0..4], .Little); + const addend = mem.readInt(i32, ctx.code[rel_offset..][0..4], .little); const target_address = @as(i64, @intCast(ctx.base_addr)) + ctx.rel.r_address + 4 + correction + addend; break :blk @as(u64, @intCast(target_address)); }; @@ -781,7 +781,7 @@ fn resolveRelocsArm64( ), code), }; inst.unconditional_branch_immediate.imm26 = @as(u26, @truncate(@as(u28, @bitCast(displacement >> 2)))); - mem.writeInt(u32, code, inst.toU32(), .Little); + mem.writeInt(u32, code, inst.toU32(), .little); }, .ARM64_RELOC_PAGE21, @@ -802,7 +802,7 @@ fn resolveRelocsArm64( }; inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2)); inst.pc_relative_address.immlo = @as(u2, @truncate(pages)); - mem.writeInt(u32, code, inst.toU32(), .Little); + mem.writeInt(u32, code, inst.toU32(), .little); addend = null; }, @@ -821,7 +821,7 @@ fn resolveRelocsArm64( ), code), }; inst.add_subtract_immediate.imm12 = off; - mem.writeInt(u32, code, inst.toU32(), .Little); + mem.writeInt(u32, code, inst.toU32(), .little); } else { var inst = aarch64.Instruction{ .load_store_register = mem.bytesToValue(meta.TagPayload( @@ -839,7 +839,7 @@ fn resolveRelocsArm64( 3 => .load_store_64, }); inst.load_store_register.offset = off; - mem.writeInt(u32, code, inst.toU32(), .Little); + mem.writeInt(u32, code, inst.toU32(), .little); } addend = null; }, @@ -858,7 +858,7 @@ fn resolveRelocsArm64( ), code), }; inst.load_store_register.offset = off; - mem.writeInt(u32, code, inst.toU32(), .Little); + mem.writeInt(u32, code, inst.toU32(), .little); addend = null; }, @@ -918,7 +918,7 @@ fn resolveRelocsArm64( .sf = @as(u1, @truncate(reg_info.size)), }, }; - mem.writeInt(u32, code, inst.toU32(), .Little); + mem.writeInt(u32, code, inst.toU32(), .little); addend = null; }, @@ -926,14 +926,14 @@ fn resolveRelocsArm64( relocs_log.debug(" | target_addr = 0x{x}", .{target_addr}); const result = math.cast(i32, @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr))) orelse return error.Overflow; - mem.writeInt(u32, atom_code[rel_offset..][0..4], @as(u32, @bitCast(result)), .Little); + mem.writeInt(u32, atom_code[rel_offset..][0..4], @as(u32, @bitCast(result)), .little); }, .ARM64_RELOC_UNSIGNED => { var ptr_addend = if (rel.r_length == 3) - mem.readInt(i64, atom_code[rel_offset..][0..8], .Little) + mem.readInt(i64, atom_code[rel_offset..][0..8], .little) else - mem.readInt(i32, atom_code[rel_offset..][0..4], .Little); + mem.readInt(i32, atom_code[rel_offset..][0..4], .little); if (rel.r_extern == 0) { const base_addr = if (target.sym_index >= object.source_address_lookup.len) @@ -954,9 +954,9 @@ fn resolveRelocsArm64( relocs_log.debug(" | target_addr = 0x{x}", .{result}); if (rel.r_length == 3) { - mem.writeInt(u64, atom_code[rel_offset..][0..8], @as(u64, @bitCast(result)), .Little); + mem.writeInt(u64, atom_code[rel_offset..][0..8], @as(u64, @bitCast(result)), .little); } else { - mem.writeInt(u32, atom_code[rel_offset..][0..4], @as(u32, @truncate(@as(u64, @bitCast(result)))), .Little); + mem.writeInt(u32, atom_code[rel_offset..][0..4], @as(u32, @truncate(@as(u64, @bitCast(result)))), .little); } subtractor = null; @@ -1045,25 +1045,25 @@ fn resolveRelocsX86( switch (rel_type) { .X86_64_RELOC_BRANCH => { - const addend = mem.readInt(i32, atom_code[rel_offset..][0..4], .Little); + const addend = mem.readInt(i32, atom_code[rel_offset..][0..4], .little); const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend)); relocs_log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr}); const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0); - mem.writeInt(i32, atom_code[rel_offset..][0..4], disp, .Little); + mem.writeInt(i32, atom_code[rel_offset..][0..4], disp, .little); }, .X86_64_RELOC_GOT, .X86_64_RELOC_GOT_LOAD, => { - const addend = mem.readInt(i32, atom_code[rel_offset..][0..4], .Little); + const addend = mem.readInt(i32, atom_code[rel_offset..][0..4], .little); const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend)); relocs_log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr}); const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0); - mem.writeInt(i32, atom_code[rel_offset..][0..4], disp, .Little); + mem.writeInt(i32, atom_code[rel_offset..][0..4], disp, .little); }, .X86_64_RELOC_TLV => { - const addend = mem.readInt(i32, atom_code[rel_offset..][0..4], .Little); + const addend = mem.readInt(i32, atom_code[rel_offset..][0..4], .little); const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend)); relocs_log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr}); const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0); @@ -1073,7 +1073,7 @@ fn resolveRelocsX86( atom_code[rel_offset - 2] = 0x8d; } - mem.writeInt(i32, atom_code[rel_offset..][0..4], disp, .Little); + mem.writeInt(i32, atom_code[rel_offset..][0..4], disp, .little); }, .X86_64_RELOC_SIGNED, @@ -1088,7 +1088,7 @@ fn resolveRelocsX86( .X86_64_RELOC_SIGNED_4 => 4, else => unreachable, }; - var addend = mem.readInt(i32, atom_code[rel_offset..][0..4], .Little) + correction; + var addend = mem.readInt(i32, atom_code[rel_offset..][0..4], .little) + correction; if (rel.r_extern == 0) { const base_addr = if (target.sym_index >= object.source_address_lookup.len) @@ -1104,14 +1104,14 @@ fn resolveRelocsX86( relocs_log.debug(" | target_addr = 0x{x}", .{adjusted_target_addr}); const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, correction); - mem.writeInt(i32, atom_code[rel_offset..][0..4], disp, .Little); + mem.writeInt(i32, atom_code[rel_offset..][0..4], disp, .little); }, .X86_64_RELOC_UNSIGNED => { var addend = if (rel.r_length == 3) - mem.readInt(i64, atom_code[rel_offset..][0..8], .Little) + mem.readInt(i64, atom_code[rel_offset..][0..8], .little) else - mem.readInt(i32, atom_code[rel_offset..][0..4], .Little); + mem.readInt(i32, atom_code[rel_offset..][0..4], .little); if (rel.r_extern == 0) { const base_addr = if (target.sym_index >= object.source_address_lookup.len) @@ -1132,9 +1132,9 @@ fn resolveRelocsX86( relocs_log.debug(" | target_addr = 0x{x}", .{result}); if (rel.r_length == 3) { - mem.writeInt(u64, atom_code[rel_offset..][0..8], @as(u64, @bitCast(result)), .Little); + mem.writeInt(u64, atom_code[rel_offset..][0..8], @as(u64, @bitCast(result)), .little); } else { - mem.writeInt(u32, atom_code[rel_offset..][0..4], @as(u32, @truncate(@as(u64, @bitCast(result)))), .Little); + mem.writeInt(u32, atom_code[rel_offset..][0..4], @as(u32, @truncate(@as(u64, @bitCast(result)))), .little); } subtractor = null; diff --git a/src/link/MachO/CodeSignature.zig b/src/link/MachO/CodeSignature.zig index 35538b4e97..0f49ee6a64 100644 --- a/src/link/MachO/CodeSignature.zig +++ b/src/link/MachO/CodeSignature.zig @@ -115,14 +115,14 @@ pub fn writeAdhocSignature( self.code_directory.inner.length = self.code_directory.size(); header.length += self.code_directory.size(); - try writer.writeInt(u32, header.magic, .Big); - try writer.writeInt(u32, header.length, .Big); - try writer.writeInt(u32, header.count, .Big); + try writer.writeInt(u32, header.magic, .big); + try writer.writeInt(u32, header.length, .big); + try writer.writeInt(u32, header.count, .big); var offset: u32 = @sizeOf(macho.SuperBlob) + @sizeOf(macho.BlobIndex) * @as(u32, @intCast(blobs.items.len)); for (blobs.items) |blob| { - try writer.writeInt(u32, blob.slotType(), .Big); - try writer.writeInt(u32, offset, .Big); + try writer.writeInt(u32, blob.slotType(), .big); + try writer.writeInt(u32, offset, .big); offset += blob.size(); } @@ -272,27 +272,27 @@ const CodeDirectory = struct { } fn write(self: CodeDirectory, writer: anytype) !void { - try writer.writeInt(u32, self.inner.magic, .Big); - try writer.writeInt(u32, self.inner.length, .Big); - try writer.writeInt(u32, self.inner.version, .Big); - try writer.writeInt(u32, self.inner.flags, .Big); - try writer.writeInt(u32, self.inner.hashOffset, .Big); - try writer.writeInt(u32, self.inner.identOffset, .Big); - try writer.writeInt(u32, self.inner.nSpecialSlots, .Big); - try writer.writeInt(u32, self.inner.nCodeSlots, .Big); - try writer.writeInt(u32, self.inner.codeLimit, .Big); + try writer.writeInt(u32, self.inner.magic, .big); + try writer.writeInt(u32, self.inner.length, .big); + try writer.writeInt(u32, self.inner.version, .big); + try writer.writeInt(u32, self.inner.flags, .big); + try writer.writeInt(u32, self.inner.hashOffset, .big); + try writer.writeInt(u32, self.inner.identOffset, .big); + try writer.writeInt(u32, self.inner.nSpecialSlots, .big); + try writer.writeInt(u32, self.inner.nCodeSlots, .big); + try writer.writeInt(u32, self.inner.codeLimit, .big); try writer.writeByte(self.inner.hashSize); try writer.writeByte(self.inner.hashType); try writer.writeByte(self.inner.platform); try writer.writeByte(self.inner.pageSize); - try writer.writeInt(u32, self.inner.spare2, .Big); - try writer.writeInt(u32, self.inner.scatterOffset, .Big); - try writer.writeInt(u32, self.inner.teamOffset, .Big); - try writer.writeInt(u32, self.inner.spare3, .Big); - try writer.writeInt(u64, self.inner.codeLimit64, .Big); - try writer.writeInt(u64, self.inner.execSegBase, .Big); - try writer.writeInt(u64, self.inner.execSegLimit, .Big); - try writer.writeInt(u64, self.inner.execSegFlags, .Big); + try writer.writeInt(u32, self.inner.spare2, .big); + try writer.writeInt(u32, self.inner.scatterOffset, .big); + try writer.writeInt(u32, self.inner.teamOffset, .big); + try writer.writeInt(u32, self.inner.spare3, .big); + try writer.writeInt(u64, self.inner.codeLimit64, .big); + try writer.writeInt(u64, self.inner.execSegBase, .big); + try writer.writeInt(u64, self.inner.execSegLimit, .big); + try writer.writeInt(u64, self.inner.execSegFlags, .big); try writer.writeAll(self.ident); try writer.writeByte(0); @@ -325,9 +325,9 @@ const Requirements = struct { } fn write(self: Requirements, writer: anytype) !void { - try writer.writeInt(u32, macho.CSMAGIC_REQUIREMENTS, .Big); - try writer.writeInt(u32, self.size(), .Big); - try writer.writeInt(u32, 0, .Big); + try writer.writeInt(u32, macho.CSMAGIC_REQUIREMENTS, .big); + try writer.writeInt(u32, self.size(), .big); + try writer.writeInt(u32, 0, .big); } }; @@ -348,8 +348,8 @@ const Entitlements = struct { } fn write(self: Entitlements, writer: anytype) !void { - try writer.writeInt(u32, macho.CSMAGIC_EMBEDDED_ENTITLEMENTS, .Big); - try writer.writeInt(u32, self.size(), .Big); + try writer.writeInt(u32, macho.CSMAGIC_EMBEDDED_ENTITLEMENTS, .big); + try writer.writeInt(u32, self.size(), .big); try writer.writeAll(self.inner); } }; @@ -371,8 +371,8 @@ const Signature = struct { } fn write(self: Signature, writer: anytype) !void { - try writer.writeInt(u32, macho.CSMAGIC_BLOBWRAPPER, .Big); - try writer.writeInt(u32, self.size(), .Big); + try writer.writeInt(u32, macho.CSMAGIC_BLOBWRAPPER, .big); + try writer.writeInt(u32, self.size(), .big); } }; diff --git a/src/link/MachO/DwarfInfo.zig b/src/link/MachO/DwarfInfo.zig index 0db0238e54..a1e0ae458a 100644 --- a/src/link/MachO/DwarfInfo.zig +++ b/src/link/MachO/DwarfInfo.zig @@ -121,19 +121,19 @@ pub const CompileUnit = struct { address_size: u8, fn read(reader: anytype) !Header { - var length: u64 = try reader.readInt(u32, .Little); + var length: u64 = try reader.readInt(u32, .little); const is_64bit = length == 0xffffffff; if (is_64bit) { - length = try reader.readInt(u64, .Little); + length = try reader.readInt(u64, .little); } - const version = try reader.readInt(u16, .Little); + const version = try reader.readInt(u16, .little); const debug_abbrev_offset = if (is_64bit) - try reader.readInt(u64, .Little) + try reader.readInt(u64, .little) else - try reader.readInt(u32, .Little); - const address_size = try reader.readInt(u8, .Little); + try reader.readInt(u32, .little); + const address_size = try reader.readInt(u8, .little); return Header{ .is_64bit = is_64bit, @@ -251,9 +251,9 @@ pub const Attribute = struct { }, dwarf.FORM.strp => { const off = if (cuh.is_64bit) - mem.readInt(u64, debug_info[0..8], .Little) + mem.readInt(u64, debug_info[0..8], .little) else - mem.readInt(u32, debug_info[0..4], .Little); + mem.readInt(u32, debug_info[0..4], .little); return ctx.getString(off); }, else => return null, @@ -267,9 +267,9 @@ pub const Attribute = struct { return switch (self.form) { dwarf.FORM.data1 => debug_info[0], - dwarf.FORM.data2 => mem.readInt(u16, debug_info[0..2], .Little), - dwarf.FORM.data4 => mem.readInt(u32, debug_info[0..4], .Little), - dwarf.FORM.data8 => mem.readInt(u64, debug_info[0..8], .Little), + dwarf.FORM.data2 => mem.readInt(u16, debug_info[0..2], .little), + dwarf.FORM.data4 => mem.readInt(u32, debug_info[0..4], .little), + dwarf.FORM.data8 => mem.readInt(u64, debug_info[0..8], .little), dwarf.FORM.udata => try leb.readULEB128(u64, reader), dwarf.FORM.sdata => try leb.readILEB128(i64, reader), else => null, @@ -281,9 +281,9 @@ pub const Attribute = struct { const debug_info = self.getDebugInfo(ctx); return switch (cuh.address_size) { 1 => debug_info[0], - 2 => mem.readInt(u16, debug_info[0..2], .Little), - 4 => mem.readInt(u32, debug_info[0..4], .Little), - 8 => mem.readInt(u64, debug_info[0..8], .Little), + 2 => mem.readInt(u16, debug_info[0..2], .little), + 4 => mem.readInt(u32, debug_info[0..4], .little), + 8 => mem.readInt(u64, debug_info[0..8], .little), else => unreachable, }; } @@ -380,9 +380,9 @@ fn findFormSize(self: DwarfInfo, form: u64, di_off: usize, cuh: CompileUnit.Head dwarf.FORM.block, => { const len: u64 = switch (form) { - dwarf.FORM.block1 => try reader.readInt(u8, .Little), - dwarf.FORM.block2 => try reader.readInt(u16, .Little), - dwarf.FORM.block4 => try reader.readInt(u32, .Little), + dwarf.FORM.block1 => try reader.readInt(u8, .little), + dwarf.FORM.block2 => try reader.readInt(u16, .little), + dwarf.FORM.block4 => try reader.readInt(u32, .little), dwarf.FORM.block => try leb.readULEB128(u64, reader), else => unreachable, }; diff --git a/src/link/MachO/Relocation.zig b/src/link/MachO/Relocation.zig index 447e19be38..74be9eb0d5 100644 --- a/src/link/MachO/Relocation.zig +++ b/src/link/MachO/Relocation.zig @@ -128,7 +128,7 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: [] ), buffer[0..4]), }; inst.unconditional_branch_immediate.imm26 = @as(u26, @truncate(@as(u28, @bitCast(displacement >> 2)))); - mem.writeInt(u32, buffer[0..4], inst.toU32(), .Little); + mem.writeInt(u32, buffer[0..4], inst.toU32(), .little); }, .page, .got_page => { const source_page = @as(i32, @intCast(source_addr >> 12)); @@ -142,7 +142,7 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: [] }; inst.pc_relative_address.immhi = @as(u19, @truncate(pages >> 2)); inst.pc_relative_address.immlo = @as(u2, @truncate(pages)); - mem.writeInt(u32, buffer[0..4], inst.toU32(), .Little); + mem.writeInt(u32, buffer[0..4], inst.toU32(), .little); }, .pageoff, .got_pageoff => { 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: [] ), buffer[0..4]), }; inst.add_subtract_immediate.imm12 = narrowed; - mem.writeInt(u32, buffer[0..4], inst.toU32(), .Little); + mem.writeInt(u32, buffer[0..4], inst.toU32(), .little); } else { var inst = aarch64.Instruction{ .load_store_register = mem.bytesToValue(meta.TagPayload( @@ -176,12 +176,12 @@ fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: [] } }; inst.load_store_register.offset = offset; - mem.writeInt(u32, buffer[0..4], inst.toU32(), .Little); + mem.writeInt(u32, buffer[0..4], inst.toU32(), .little); } }, .tlv_initializer, .unsigned => switch (self.length) { - 2 => mem.writeInt(u32, buffer[0..4], @as(u32, @truncate(@as(u64, @bitCast(target_addr)))), .Little), - 3 => mem.writeInt(u64, buffer[0..8], @as(u64, @bitCast(target_addr)), .Little), + 2 => mem.writeInt(u32, buffer[0..4], @as(u32, @truncate(@as(u64, @bitCast(target_addr)))), .little), + 3 => mem.writeInt(u64, buffer[0..8], @as(u64, @bitCast(target_addr)), .little), else => unreachable, }, .got, .signed, .tlv => unreachable, // Invalid target architecture. @@ -192,15 +192,15 @@ fn resolveX8664(self: Relocation, source_addr: u64, target_addr: i64, code: []u8 switch (self.type) { .branch, .got, .tlv, .signed => { const displacement = @as(i32, @intCast(@as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr)) - 4)); - mem.writeInt(u32, code[self.offset..][0..4], @as(u32, @bitCast(displacement)), .Little); + mem.writeInt(u32, code[self.offset..][0..4], @as(u32, @bitCast(displacement)), .little); }, .tlv_initializer, .unsigned => { switch (self.length) { 2 => { - mem.writeInt(u32, code[self.offset..][0..4], @as(u32, @truncate(@as(u64, @bitCast(target_addr)))), .Little); + mem.writeInt(u32, code[self.offset..][0..4], @as(u32, @truncate(@as(u64, @bitCast(target_addr)))), .little); }, 3 => { - mem.writeInt(u64, code[self.offset..][0..8], @as(u64, @bitCast(target_addr)), .Little); + mem.writeInt(u64, code[self.offset..][0..8], @as(u64, @bitCast(target_addr)), .little); }, else => unreachable, } diff --git a/src/link/MachO/UnwindInfo.zig b/src/link/MachO/UnwindInfo.zig index e8c4a918ef..c588b65ea3 100644 --- a/src/link/MachO/UnwindInfo.zig +++ b/src/link/MachO/UnwindInfo.zig @@ -149,7 +149,7 @@ const Page = struct { for (page.page_encodings[0..page.page_encodings_count]) |record_id| { const enc = info.records.items[record_id].compactUnwindEncoding; - try writer.writeInt(u32, enc, .Little); + try writer.writeInt(u32, enc, .little); } assert(page.count > 0); diff --git a/src/link/MachO/eh_frame.zig b/src/link/MachO/eh_frame.zig index 12516db7a1..189d9b25cd 100644 --- a/src/link/MachO/eh_frame.zig +++ b/src/link/MachO/eh_frame.zig @@ -209,7 +209,7 @@ pub fn write(macho_file: *MachO, unwind_info: *UnwindInfo) !void { const writer = buffer.writer(); for (eh_records.values()) |record| { - try writer.writeInt(u32, record.size, .Little); + try writer.writeInt(u32, record.size, .little); try buffer.appendSlice(record.data); } @@ -259,7 +259,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { base_offset: u64, }) u64 { assert(rec.tag == .fde); - const addend = mem.readInt(i64, rec.data[4..][0..8], .Little); + const addend = mem.readInt(i64, rec.data[4..][0..8], .little); return @as(u64, @intCast(@as(i64, @intCast(ctx.base_addr + ctx.base_offset + 8)) + addend)); } @@ -269,7 +269,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { }) !void { assert(rec.tag == .fde); const addend = @as(i64, @intCast(value)) - @as(i64, @intCast(ctx.base_addr + ctx.base_offset + 8)); - mem.writeInt(i64, rec.data[4..][0..8], addend, .Little); + mem.writeInt(i64, rec.data[4..][0..8], addend, .little); } pub fn getPersonalityPointerReloc( @@ -343,13 +343,13 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { const target_addr = macho_file.getGotEntryAddress(target).?; const result = math.cast(i32, @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr))) orelse return error.Overflow; - mem.writeInt(i32, rec.data[rel_offset..][0..4], result, .Little); + mem.writeInt(i32, rec.data[rel_offset..][0..4], result, .little); }, .ARM64_RELOC_UNSIGNED => { assert(rel.r_extern == 1); const target_addr = Atom.getRelocTargetAddress(macho_file, target, false); const result = @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr)); - mem.writeInt(i64, rec.data[rel_offset..][0..8], @as(i64, @intCast(result)), .Little); + mem.writeInt(i64, rec.data[rel_offset..][0..8], @as(i64, @intCast(result)), .little); }, else => unreachable, } @@ -359,10 +359,10 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { switch (rel_type) { .X86_64_RELOC_GOT => { const target_addr = macho_file.getGotEntryAddress(target).?; - const addend = mem.readInt(i32, rec.data[rel_offset..][0..4], .Little); + const addend = mem.readInt(i32, rec.data[rel_offset..][0..4], .little); const adjusted_target_addr = @as(u64, @intCast(@as(i64, @intCast(target_addr)) + addend)); const disp = try Relocation.calcPcRelativeDisplacementX86(source_addr, adjusted_target_addr, 0); - mem.writeInt(i32, rec.data[rel_offset..][0..4], disp, .Little); + mem.writeInt(i32, rec.data[rel_offset..][0..4], disp, .little); }, else => unreachable, } @@ -375,7 +375,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { pub fn getCiePointerSource(rec: Record, object_id: u32, macho_file: *MachO, offset: u32) u32 { assert(rec.tag == .fde); const cpu_arch = macho_file.base.options.target.cpu.arch; - const addend = mem.readInt(u32, rec.data[0..4], .Little); + const addend = mem.readInt(u32, rec.data[0..4], .little); switch (cpu_arch) { .aarch64 => { const relocs = getRelocs(macho_file, object_id, offset); @@ -397,12 +397,12 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { pub fn getCiePointer(rec: Record) u32 { assert(rec.tag == .fde); - return mem.readInt(u32, rec.data[0..4], .Little); + return mem.readInt(u32, rec.data[0..4], .little); } pub fn setCiePointer(rec: *Record, ptr: u32) void { assert(rec.tag == .fde); - mem.writeInt(u32, rec.data[0..4], ptr, .Little); + mem.writeInt(u32, rec.data[0..4], ptr, .little); } pub fn getAugmentationString(rec: Record) []const u8 { @@ -509,14 +509,14 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { if (enc == EH_PE.omit) return null; var ptr: i64 = switch (enc & 0x0F) { - EH_PE.absptr => @as(i64, @bitCast(try reader.readInt(u64, .Little))), - EH_PE.udata2 => @as(i16, @bitCast(try reader.readInt(u16, .Little))), - EH_PE.udata4 => @as(i32, @bitCast(try reader.readInt(u32, .Little))), - EH_PE.udata8 => @as(i64, @bitCast(try reader.readInt(u64, .Little))), + EH_PE.absptr => @as(i64, @bitCast(try reader.readInt(u64, .little))), + EH_PE.udata2 => @as(i16, @bitCast(try reader.readInt(u16, .little))), + EH_PE.udata4 => @as(i32, @bitCast(try reader.readInt(u32, .little))), + EH_PE.udata8 => @as(i64, @bitCast(try reader.readInt(u64, .little))), EH_PE.uleb128 => @as(i64, @bitCast(try leb.readULEB128(u64, reader))), - EH_PE.sdata2 => try reader.readInt(i16, .Little), - EH_PE.sdata4 => try reader.readInt(i32, .Little), - EH_PE.sdata8 => try reader.readInt(i64, .Little), + EH_PE.sdata2 => try reader.readInt(i16, .little), + EH_PE.sdata4 => try reader.readInt(i32, .little), + EH_PE.sdata8 => try reader.readInt(i64, .little), EH_PE.sleb128 => try leb.readILEB128(i64, reader), else => return null, }; @@ -552,14 +552,14 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { } switch (enc & 0x0F) { - EH_PE.absptr => try writer.writeInt(u64, @as(u64, @bitCast(actual)), .Little), - EH_PE.udata2 => try writer.writeInt(u16, @as(u16, @bitCast(@as(i16, @intCast(actual)))), .Little), - EH_PE.udata4 => try writer.writeInt(u32, @as(u32, @bitCast(@as(i32, @intCast(actual)))), .Little), - EH_PE.udata8 => try writer.writeInt(u64, @as(u64, @bitCast(actual)), .Little), + EH_PE.absptr => try writer.writeInt(u64, @as(u64, @bitCast(actual)), .little), + EH_PE.udata2 => try writer.writeInt(u16, @as(u16, @bitCast(@as(i16, @intCast(actual)))), .little), + EH_PE.udata4 => try writer.writeInt(u32, @as(u32, @bitCast(@as(i32, @intCast(actual)))), .little), + EH_PE.udata8 => try writer.writeInt(u64, @as(u64, @bitCast(actual)), .little), EH_PE.uleb128 => try leb.writeULEB128(writer, @as(u64, @bitCast(actual))), - EH_PE.sdata2 => try writer.writeInt(i16, @as(i16, @intCast(actual)), .Little), - EH_PE.sdata4 => try writer.writeInt(i32, @as(i32, @intCast(actual)), .Little), - EH_PE.sdata8 => try writer.writeInt(i64, actual, .Little), + EH_PE.sdata2 => try writer.writeInt(i16, @as(i16, @intCast(actual)), .little), + EH_PE.sdata4 => try writer.writeInt(i32, @as(i32, @intCast(actual)), .little), + EH_PE.sdata8 => try writer.writeInt(i64, actual, .little), EH_PE.sleb128 => try leb.writeILEB128(writer, actual), else => unreachable, } @@ -586,13 +586,13 @@ pub const Iterator = struct { var stream = std.io.fixedBufferStream(it.data[it.pos..]); const reader = stream.reader(); - var size = try reader.readInt(u32, .Little); + var size = try reader.readInt(u32, .little); if (size == 0xFFFFFFFF) { log.debug("MachO doesn't support 64bit DWARF CFI __eh_frame records", .{}); return error.BadDwarfCfi; } - const id = try reader.readInt(u32, .Little); + const id = try reader.readInt(u32, .little); const tag: EhFrameRecordTag = if (id == 0) .cie else .fde; const offset: u32 = 4; const record = EhFrameRecord(false){ diff --git a/src/link/MachO/stubs.zig b/src/link/MachO/stubs.zig index 6d947983f6..925aeaa61f 100644 --- a/src/link/MachO/stubs.zig +++ b/src/link/MachO/stubs.zig @@ -53,7 +53,7 @@ pub fn writeStubHelperPreambleCode(args: struct { args.dyld_private_addr, 0, ); - try writer.writeInt(i32, disp, .Little); + try writer.writeInt(i32, disp, .little); } try writer.writeAll(&.{ 0x41, 0x53, 0xff, 0x25 }); { @@ -62,27 +62,27 @@ pub fn writeStubHelperPreambleCode(args: struct { args.dyld_stub_binder_got_addr, 0, ); - try writer.writeInt(i32, disp, .Little); + try writer.writeInt(i32, disp, .little); } }, .aarch64 => { { const pages = Relocation.calcNumberOfPages(args.source_addr, args.dyld_private_addr); - try writer.writeInt(u32, aarch64.Instruction.adrp(.x17, pages).toU32(), .Little); + try writer.writeInt(u32, aarch64.Instruction.adrp(.x17, pages).toU32(), .little); } { const off = try Relocation.calcPageOffset(args.dyld_private_addr, .arithmetic); - try writer.writeInt(u32, aarch64.Instruction.add(.x17, .x17, off, false).toU32(), .Little); + try writer.writeInt(u32, aarch64.Instruction.add(.x17, .x17, off, false).toU32(), .little); } try writer.writeInt(u32, aarch64.Instruction.stp( .x16, .x17, aarch64.Register.sp, aarch64.Instruction.LoadStorePairOffset.pre_index(-16), - ).toU32(), .Little); + ).toU32(), .little); { const pages = Relocation.calcNumberOfPages(args.source_addr + 12, args.dyld_stub_binder_got_addr); - try writer.writeInt(u32, aarch64.Instruction.adrp(.x16, pages).toU32(), .Little); + try writer.writeInt(u32, aarch64.Instruction.adrp(.x16, pages).toU32(), .little); } { const off = try Relocation.calcPageOffset(args.dyld_stub_binder_got_addr, .load_store_64); @@ -90,9 +90,9 @@ pub fn writeStubHelperPreambleCode(args: struct { .x16, .x16, aarch64.Instruction.LoadStoreOffset.imm(off), - ).toU32(), .Little); + ).toU32(), .little); } - try writer.writeInt(u32, aarch64.Instruction.br(.x16).toU32(), .Little); + try writer.writeInt(u32, aarch64.Instruction.br(.x16).toU32(), .little); }, else => unreachable, } @@ -108,7 +108,7 @@ pub fn writeStubHelperCode(args: struct { try writer.writeAll(&.{ 0x68, 0x0, 0x0, 0x0, 0x0, 0xe9 }); { const disp = try Relocation.calcPcRelativeDisplacementX86(args.source_addr + 6, args.target_addr, 0); - try writer.writeInt(i32, disp, .Little); + try writer.writeInt(i32, disp, .little); } }, .aarch64 => { @@ -120,10 +120,10 @@ pub fn writeStubHelperCode(args: struct { try writer.writeInt(u32, aarch64.Instruction.ldrLiteral( .w16, literal, - ).toU32(), .Little); + ).toU32(), .little); { const disp = try Relocation.calcPcRelativeDisplacementArm64(args.source_addr + 4, args.target_addr); - try writer.writeInt(u32, aarch64.Instruction.b(disp).toU32(), .Little); + try writer.writeInt(u32, aarch64.Instruction.b(disp).toU32(), .little); } try writer.writeAll(&.{ 0x0, 0x0, 0x0, 0x0 }); }, @@ -141,13 +141,13 @@ pub fn writeStubCode(args: struct { try writer.writeAll(&.{ 0xff, 0x25 }); { const disp = try Relocation.calcPcRelativeDisplacementX86(args.source_addr + 2, args.target_addr, 0); - try writer.writeInt(i32, disp, .Little); + try writer.writeInt(i32, disp, .little); } }, .aarch64 => { { const pages = Relocation.calcNumberOfPages(args.source_addr, args.target_addr); - try writer.writeInt(u32, aarch64.Instruction.adrp(.x16, pages).toU32(), .Little); + try writer.writeInt(u32, aarch64.Instruction.adrp(.x16, pages).toU32(), .little); } { const off = try Relocation.calcPageOffset(args.target_addr, .load_store_64); @@ -155,9 +155,9 @@ pub fn writeStubCode(args: struct { .x16, .x16, aarch64.Instruction.LoadStoreOffset.imm(off), - ).toU32(), .Little); + ).toU32(), .little); } - try writer.writeInt(u32, aarch64.Instruction.br(.x16).toU32(), .Little); + try writer.writeInt(u32, aarch64.Instruction.br(.x16).toU32(), .little); }, else => unreachable, } diff --git a/src/link/MachO/thunks.zig b/src/link/MachO/thunks.zig index 21f5d2f410..774a8f7344 100644 --- a/src/link/MachO/thunks.zig +++ b/src/link/MachO/thunks.zig @@ -349,10 +349,10 @@ pub fn writeThunkCode(macho_file: *MachO, thunk: *const Thunk, writer: anytype) .atom => macho_file.getSymbol(target).n_value, }; const pages = Relocation.calcNumberOfPages(source_addr, target_addr); - try writer.writeInt(u32, aarch64.Instruction.adrp(.x16, pages).toU32(), .Little); + try writer.writeInt(u32, aarch64.Instruction.adrp(.x16, pages).toU32(), .little); const off = try Relocation.calcPageOffset(target_addr, .arithmetic); - try writer.writeInt(u32, aarch64.Instruction.add(.x16, .x16, off, false).toU32(), .Little); - try writer.writeInt(u32, aarch64.Instruction.br(.x16).toU32(), .Little); + try writer.writeInt(u32, aarch64.Instruction.add(.x16, .x16, off, false).toU32(), .little); + try writer.writeInt(u32, aarch64.Instruction.br(.x16).toU32(), .little); } } diff --git a/src/link/MachO/zld.zig b/src/link/MachO/zld.zig index ed1d3f0258..b94da1d284 100644 --- a/src/link/MachO/zld.zig +++ b/src/link/MachO/zld.zig @@ -796,7 +796,7 @@ fn writePointerEntries(macho_file: *MachO, sect_id: u8, table: anytype) !void { defer buffer.deinit(); for (table.entries.items) |entry| { const sym = macho_file.getSymbol(entry); - buffer.writer().writeInt(u64, sym.n_value, .Little) catch unreachable; + buffer.writer().writeInt(u64, sym.n_value, .little) catch unreachable; } log.debug("writing __DATA_CONST,__got contents at file offset 0x{x}", .{header.offset}); try macho_file.base.file.?.pwriteAll(buffer.items, header.offset); @@ -880,7 +880,7 @@ fn writeLaSymbolPtrs(macho_file: *MachO) !void { for (0..macho_file.stub_table.count()) |index| { const target_addr = stub_helper_header.addr + stubs.stubHelperPreambleSize(cpu_arch) + stubs.stubHelperSize(cpu_arch) * index; - buffer.writer().writeInt(u64, target_addr, .Little) catch unreachable; + buffer.writer().writeInt(u64, target_addr, .little) catch unreachable; } log.debug("writing __DATA,__la_symbol_ptr contents at file offset 0x{x}", .{ diff --git a/src/link/Plan9.zig b/src/link/Plan9.zig index 04c8c9abe7..d8b6f39f76 100644 --- a/src/link/Plan9.zig +++ b/src/link/Plan9.zig @@ -348,7 +348,7 @@ fn putFn(self: *Plan9, decl_index: Module.Decl.Index, out: FnDeclOutput) !void { // every 'z' starts with 0 try a.append(0); // path component value of '/' - try a.writer().writeInt(u16, 1, .Big); + try a.writer().writeInt(u16, 1, .big); // getting the full file path 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 var it = std.mem.tokenizeScalar(u8, path, sep); while (it.next()) |component| { if (self.file_segments.get(component)) |num| { - try a.writer().writeInt(u16, num, .Big); + try a.writer().writeInt(u16, num, .big); } else { self.file_segments_i += 1; try self.file_segments.put(self.base.allocator, component, self.file_segments_i); - try a.writer().writeInt(u16, self.file_segments_i, .Big); + try a.writer().writeInt(u16, self.file_segments_i, .big); } } } @@ -607,7 +607,7 @@ pub fn changeLine(l: *std.ArrayList(u8), delta_line: i32) !void { try l.append(toadd); } else if (delta_line != 0) { try l.append(0); - try l.writer().writeInt(i32, delta_line, .Big); + try l.writer().writeInt(i32, delta_line, .big); } } @@ -922,7 +922,7 @@ pub fn flushModule(self: *Plan9, comp: *Compilation, prog_node: *std.Progress.No @memcpy(hdr_slice, self.hdr.toU8s()[0..hdr_size]); // write the fat header for 64 bit entry points if (self.sixtyfour_bit) { - mem.writeInt(u64, hdr_buf[32..40], self.entry_val.?, .Big); + mem.writeInt(u64, hdr_buf[32..40], self.entry_val.?, .big); } // perform the relocs { @@ -1311,9 +1311,9 @@ pub fn writeSym(self: *Plan9, w: anytype, sym: aout.Sym) !void { // log.debug("write sym{{name: {s}, value: {x}}}", .{ sym.name, sym.value }); if (sym.type == .bad) return; // we don't want to write free'd symbols if (!self.sixtyfour_bit) { - try w.writeInt(u32, @as(u32, @intCast(sym.value)), .Big); + try w.writeInt(u32, @as(u32, @intCast(sym.value)), .big); } else { - try w.writeInt(u64, sym.value, .Big); + try w.writeInt(u64, sym.value, .big); } try w.writeByte(@intFromEnum(sym.type)); try w.writeAll(sym.name); diff --git a/src/link/Plan9/aout.zig b/src/link/Plan9/aout.zig index 8879a4832f..12dfc45873 100644 --- a/src/link/Plan9/aout.zig +++ b/src/link/Plan9/aout.zig @@ -21,7 +21,7 @@ pub const ExecHdr = extern struct { var buf: [40]u8 = undefined; var i: u8 = 0; inline for (std.meta.fields(@This())) |f| { - std.mem.writeInt(u32, buf[i..][0..4], @field(self, f.name), .Big); + std.mem.writeInt(u32, buf[i..][0..4], @field(self, f.name), .big); i += 4; } return buf; diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 2be90fa15b..fdac89f837 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -2380,7 +2380,7 @@ fn setupErrorsLen(wasm: *Wasm) !void { atom.* = Atom.empty; atom.sym_index = loc.index; atom.size = 2; - try atom.code.writer(wasm.base.allocator).writeInt(u16, @intCast(errors_len), .Little); + try atom.code.writer(wasm.base.allocator).writeInt(u16, @intCast(errors_len), .little); try wasm.parseAtom(atom_index, .{ .data = .read_only }); } @@ -3151,7 +3151,7 @@ fn populateErrorNameTable(wasm: *Wasm) !void { const offset = @as(u32, @intCast(atom.code.items.len)); // first we create the data for the slice of the name try atom.code.appendNTimes(wasm.base.allocator, 0, 4); // ptr to name, will be relocated - try atom.code.writer(wasm.base.allocator).writeInt(u32, len - 1, .Little); + try atom.code.writer(wasm.base.allocator).writeInt(u32, len - 1, .little); // create relocation to the error name try atom.relocs.append(wasm.base.allocator, .{ .index = names_atom.sym_index, @@ -4286,11 +4286,11 @@ fn emitInit(writer: anytype, init_expr: std.wasm.InitExpression) !void { }, .f32_const => |val| { try writer.writeByte(std.wasm.opcode(.f32_const)); - try writer.writeInt(u32, @bitCast(val), .Little); + try writer.writeInt(u32, @bitCast(val), .little); }, .f64_const => |val| { try writer.writeByte(std.wasm.opcode(.f64_const)); - try writer.writeInt(u64, @bitCast(val), .Little); + try writer.writeInt(u64, @bitCast(val), .little); }, .global_get => |val| { try writer.writeByte(std.wasm.opcode(.global_get)); diff --git a/src/link/Wasm/Archive.zig b/src/link/Wasm/Archive.zig index 91e92ae36d..a618aaebbf 100644 --- a/src/link/Wasm/Archive.zig +++ b/src/link/Wasm/Archive.zig @@ -141,11 +141,11 @@ fn parseTableOfContents(archive: *Archive, allocator: Allocator, reader: anytype const size_trimmed = mem.trim(u8, &archive.header.ar_size, " "); const sym_tab_size = try std.fmt.parseInt(u32, size_trimmed, 10); - const num_symbols = try reader.readInt(u32, .Big); + const num_symbols = try reader.readInt(u32, .big); const symbol_positions = try allocator.alloc(u32, num_symbols); defer allocator.free(symbol_positions); for (symbol_positions) |*index| { - index.* = try reader.readInt(u32, .Big); + index.* = try reader.readInt(u32, .big); } const sym_tab = try allocator.alloc(u8, sym_tab_size - 4 - (4 * num_symbols)); diff --git a/src/link/Wasm/Atom.zig b/src/link/Wasm/Atom.zig index 65e92ed140..60727b6af1 100644 --- a/src/link/Wasm/Atom.zig +++ b/src/link/Wasm/Atom.zig @@ -114,10 +114,10 @@ pub fn resolveRelocs(atom: *Atom, wasm_bin: *const Wasm) void { .R_WASM_GLOBAL_INDEX_I32, .R_WASM_MEMORY_ADDR_I32, .R_WASM_SECTION_OFFSET_I32, - => std.mem.writeInt(u32, atom.code.items[reloc.offset..][0..4], @as(u32, @intCast(value)), .Little), + => std.mem.writeInt(u32, atom.code.items[reloc.offset..][0..4], @as(u32, @intCast(value)), .little), .R_WASM_TABLE_INDEX_I64, .R_WASM_MEMORY_ADDR_I64, - => std.mem.writeInt(u64, atom.code.items[reloc.offset..][0..8], value, .Little), + => std.mem.writeInt(u64, atom.code.items[reloc.offset..][0..8], value, .little), .R_WASM_GLOBAL_INDEX_LEB, .R_WASM_EVENT_INDEX_LEB, .R_WASM_FUNCTION_INDEX_LEB, diff --git a/src/link/Wasm/Object.zig b/src/link/Wasm/Object.zig index 6517d7ec20..359ff20d94 100644 --- a/src/link/Wasm/Object.zig +++ b/src/link/Wasm/Object.zig @@ -344,7 +344,7 @@ fn Parser(comptime ReaderType: type) type { fn parseObject(parser: *ObjectParser, gpa: Allocator, is_object_file: *bool) Error!void { errdefer parser.object.deinit(gpa); try parser.verifyMagicBytes(); - const version = try parser.reader.reader().readInt(u32, .Little); + const version = try parser.reader.reader().readInt(u32, .little); parser.object.version = version; var relocatable_data = std.ArrayList(RelocatableData).init(gpa); diff --git a/src/resinator/ani.zig b/src/resinator/ani.zig index a4273e8488..770351351e 100644 --- a/src/resinator/ani.zig +++ b/src/resinator/ani.zig @@ -25,14 +25,14 @@ fn getAniheaderFlags(reader: anytype) !u32 { const riff_header = try reader.readBytesNoEof(4); if (!std.mem.eql(u8, &riff_header, "RIFF")) return error.InvalidFormat; - _ = try reader.readInt(u32, .Little); // size of RIFF chunk + _ = try reader.readInt(u32, .little); // size of RIFF chunk const form_type = try reader.readBytesNoEof(4); if (!std.mem.eql(u8, &form_type, "ACON")) return error.InvalidFormat; while (true) { const chunk_id = try reader.readBytesNoEof(4); - const chunk_len = try reader.readInt(u32, .Little); + const chunk_len = try reader.readInt(u32, .little); if (!std.mem.eql(u8, &chunk_id, "anih")) { // TODO: Move file cursor instead of skipBytes try reader.skipBytes(chunk_len, .{}); diff --git a/src/resinator/bmp.zig b/src/resinator/bmp.zig index fb20dacdad..1c7e0f6aad 100644 --- a/src/resinator/bmp.zig +++ b/src/resinator/bmp.zig @@ -94,16 +94,16 @@ pub fn read(reader: anytype, max_size: u64) ReadError!BitmapInfo { const id = std.mem.readInt(u16, file_header[0..2], native_endian); if (id != windows_format_id) return error.InvalidFileHeader; - bitmap_info.pixel_data_offset = std.mem.readInt(u32, file_header[10..14], .Little); + bitmap_info.pixel_data_offset = std.mem.readInt(u32, file_header[10..14], .little); if (bitmap_info.pixel_data_offset > max_size) return error.ImpossiblePixelDataOffset; - bitmap_info.dib_header_size = reader.readInt(u32, .Little) catch return error.UnexpectedEOF; + bitmap_info.dib_header_size = reader.readInt(u32, .little) catch return error.UnexpectedEOF; if (bitmap_info.pixel_data_offset < file_header_len + bitmap_info.dib_header_size) return error.ImpossiblePixelDataOffset; const dib_version = BitmapHeader.Version.get(bitmap_info.dib_header_size); switch (dib_version) { .@"nt3.1", .@"nt4.0", .@"nt5.0" => { var dib_header_buf: [@sizeOf(BITMAPINFOHEADER)]u8 align(@alignOf(BITMAPINFOHEADER)) = undefined; - std.mem.writeInt(u32, dib_header_buf[0..4], bitmap_info.dib_header_size, .Little); + std.mem.writeInt(u32, dib_header_buf[0..4], bitmap_info.dib_header_size, .little); reader.readNoEof(dib_header_buf[4..]) catch return error.UnexpectedEOF; var dib_header: *BITMAPINFOHEADER = @ptrCast(&dib_header_buf); structFieldsLittleToNative(BITMAPINFOHEADER, dib_header); @@ -118,7 +118,7 @@ pub fn read(reader: anytype, max_size: u64) ReadError!BitmapInfo { }, .@"win2.0" => { var dib_header_buf: [@sizeOf(BITMAPCOREHEADER)]u8 align(@alignOf(BITMAPCOREHEADER)) = undefined; - std.mem.writeInt(u32, dib_header_buf[0..4], bitmap_info.dib_header_size, .Little); + std.mem.writeInt(u32, dib_header_buf[0..4], bitmap_info.dib_header_size, .little); reader.readNoEof(dib_header_buf[4..]) catch return error.UnexpectedEOF; var dib_header: *BITMAPCOREHEADER = @ptrCast(&dib_header_buf); structFieldsLittleToNative(BITMAPCOREHEADER, dib_header); diff --git a/src/resinator/compile.zig b/src/resinator/compile.zig index 6f8878c411..ae0232a737 100644 --- a/src/resinator/compile.zig +++ b/src/resinator/compile.zig @@ -585,8 +585,8 @@ pub const Compiler = struct { // > resource if a RESDIR structure contains information about a cursor. // where LOCALHEADER is `struct { WORD xHotSpot; WORD yHotSpot; }` if (icon_dir.image_type == .cursor) { - try writer.writeInt(u16, entry.type_specific_data.cursor.hotspot_x, .Little); - try writer.writeInt(u16, entry.type_specific_data.cursor.hotspot_y, .Little); + try writer.writeInt(u16, entry.type_specific_data.cursor.hotspot_x, .little); + try writer.writeInt(u16, entry.type_specific_data.cursor.hotspot_y, .little); } try file.seekTo(entry.data_offset_from_start_of_file); @@ -667,7 +667,7 @@ pub const Compiler = struct { }, .dib => { var bitmap_header: *ico.BitmapHeader = @ptrCast(@alignCast(&header_bytes)); - if (native_endian == .Big) { + if (native_endian == .big) { std.mem.byteSwapAllFields(ico.BitmapHeader, bitmap_header); } const bitmap_version = ico.BitmapHeader.Version.get(bitmap_header.bcSize); @@ -985,8 +985,8 @@ pub const Compiler = struct { pub fn write(self: Data, writer: anytype) !void { switch (self) { .number => |number| switch (number.is_long) { - false => try writer.writeInt(WORD, number.asWord(), .Little), - true => try writer.writeInt(DWORD, number.value, .Little), + false => try writer.writeInt(WORD, number.asWord(), .little), + true => try writer.writeInt(DWORD, number.value, .little), }, .ascii_string => |ascii_string| { try writer.writeAll(ascii_string); @@ -1316,9 +1316,9 @@ pub const Compiler = struct { try data_writer.writeByte(modifiers.value); try data_writer.writeByte(0); // padding - try data_writer.writeInt(u16, key, .Little); - try data_writer.writeInt(u16, cmd_id.asWord(), .Little); - try data_writer.writeInt(u16, 0, .Little); // padding + try data_writer.writeInt(u16, key, .little); + try data_writer.writeInt(u16, cmd_id.asWord(), .little); + try data_writer.writeInt(u16, 0, .little); // padding } } @@ -1701,34 +1701,34 @@ pub const Compiler = struct { if (node.help_id == null) break :help_id 0; break :help_id evaluateNumberExpression(node.help_id.?, self.source, self.input_code_pages).value; }; - try data_writer.writeInt(u16, 1, .Little); // version number, always 1 - try data_writer.writeInt(u16, 0xFFFF, .Little); // signature, always 0xFFFF - try data_writer.writeInt(u32, help_id, .Little); - try data_writer.writeInt(u32, optional_statement_values.exstyle, .Little); - try data_writer.writeInt(u32, optional_statement_values.style, .Little); + try data_writer.writeInt(u16, 1, .little); // version number, always 1 + try data_writer.writeInt(u16, 0xFFFF, .little); // signature, always 0xFFFF + try data_writer.writeInt(u32, help_id, .little); + try data_writer.writeInt(u32, optional_statement_values.exstyle, .little); + try data_writer.writeInt(u32, optional_statement_values.style, .little); } else { - try data_writer.writeInt(u32, optional_statement_values.style, .Little); - try data_writer.writeInt(u32, optional_statement_values.exstyle, .Little); + try data_writer.writeInt(u32, optional_statement_values.style, .little); + try data_writer.writeInt(u32, optional_statement_values.exstyle, .little); } // This limit is enforced by the parser, so we know the number of controls // is within the range of a u16. - try data_writer.writeInt(u16, @as(u16, @intCast(node.controls.len)), .Little); - try data_writer.writeInt(u16, x.asWord(), .Little); - try data_writer.writeInt(u16, y.asWord(), .Little); - try data_writer.writeInt(u16, width.asWord(), .Little); - try data_writer.writeInt(u16, height.asWord(), .Little); + try data_writer.writeInt(u16, @as(u16, @intCast(node.controls.len)), .little); + try data_writer.writeInt(u16, x.asWord(), .little); + try data_writer.writeInt(u16, y.asWord(), .little); + try data_writer.writeInt(u16, width.asWord(), .little); + try data_writer.writeInt(u16, height.asWord(), .little); // Menu if (optional_statement_values.menu) |menu| { try menu.write(data_writer); } else { - try data_writer.writeInt(u16, 0, .Little); + try data_writer.writeInt(u16, 0, .little); } // Class if (optional_statement_values.class) |class| { try class.write(data_writer); } else { - try data_writer.writeInt(u16, 0, .Little); + try data_writer.writeInt(u16, 0, .little); } // Caption if (optional_statement_values.caption) |caption| { @@ -1736,7 +1736,7 @@ pub const Compiler = struct { defer self.allocator.free(parsed); try data_writer.writeAll(std.mem.sliceAsBytes(parsed[0 .. parsed.len + 1])); } else { - try data_writer.writeInt(u16, 0, .Little); + try data_writer.writeInt(u16, 0, .little); } // Font if (optional_statement_values.font) |font| { @@ -1787,18 +1787,18 @@ pub const Compiler = struct { switch (resource) { .dialog => { // Note: Reverse order from DIALOGEX - try data_writer.writeInt(u32, style, .Little); - try data_writer.writeInt(u32, exstyle, .Little); + try data_writer.writeInt(u32, style, .little); + try data_writer.writeInt(u32, exstyle, .little); }, .dialogex => { const help_id: u32 = if (control.help_id) |help_id_expression| evaluateNumberExpression(help_id_expression, self.source, self.input_code_pages).value else 0; - try data_writer.writeInt(u32, help_id, .Little); + try data_writer.writeInt(u32, help_id, .little); // Note: Reverse order from DIALOG - try data_writer.writeInt(u32, exstyle, .Little); - try data_writer.writeInt(u32, style, .Little); + try data_writer.writeInt(u32, exstyle, .little); + try data_writer.writeInt(u32, style, .little); }, else => unreachable, } @@ -1808,15 +1808,15 @@ pub const Compiler = struct { const control_width = evaluateNumberExpression(control.width, self.source, self.input_code_pages); const control_height = evaluateNumberExpression(control.height, self.source, self.input_code_pages); - try data_writer.writeInt(u16, control_x.asWord(), .Little); - try data_writer.writeInt(u16, control_y.asWord(), .Little); - try data_writer.writeInt(u16, control_width.asWord(), .Little); - try data_writer.writeInt(u16, control_height.asWord(), .Little); + try data_writer.writeInt(u16, control_x.asWord(), .little); + try data_writer.writeInt(u16, control_y.asWord(), .little); + try data_writer.writeInt(u16, control_width.asWord(), .little); + try data_writer.writeInt(u16, control_height.asWord(), .little); const control_id = evaluateNumberExpression(control.id, self.source, self.input_code_pages); switch (resource) { - .dialog => try data_writer.writeInt(u16, control_id.asWord(), .Little), - .dialogex => try data_writer.writeInt(u32, control_id.value, .Little), + .dialog => try data_writer.writeInt(u16, control_id.asWord(), .little), + .dialogex => try data_writer.writeInt(u32, control_id.value, .little), else => unreachable, } @@ -1949,7 +1949,7 @@ pub const Compiler = struct { } // We know the extra_data_buf size fits within a u16. const extra_data_size: u16 = @intCast(extra_data_buf.items.len); - try data_writer.writeInt(u16, extra_data_size, .Little); + try data_writer.writeInt(u16, extra_data_size, .little); try data_writer.writeAll(extra_data_buf.items); } @@ -1963,21 +1963,21 @@ pub const Compiler = struct { // I'm assuming this is some sort of version // TODO: Try to find something mentioning this - try data_writer.writeInt(u16, 1, .Little); - try data_writer.writeInt(u16, button_width.asWord(), .Little); - try data_writer.writeInt(u16, button_height.asWord(), .Little); - try data_writer.writeInt(u16, @as(u16, @intCast(node.buttons.len)), .Little); + try data_writer.writeInt(u16, 1, .little); + try data_writer.writeInt(u16, button_width.asWord(), .little); + try data_writer.writeInt(u16, button_height.asWord(), .little); + try data_writer.writeInt(u16, @as(u16, @intCast(node.buttons.len)), .little); for (node.buttons) |button_or_sep| { switch (button_or_sep.id) { .literal => { // This is always SEPARATOR std.debug.assert(button_or_sep.cast(.literal).?.token.id == .literal); - try data_writer.writeInt(u16, 0, .Little); + try data_writer.writeInt(u16, 0, .little); }, .simple_statement => { const value_node = button_or_sep.cast(.simple_statement).?.value; const value = evaluateNumberExpression(value_node, self.source, self.input_code_pages); - try data_writer.writeInt(u16, value.asWord(), .Little); + try data_writer.writeInt(u16, value.asWord(), .little); }, else => unreachable, // This is a bug in the parser } @@ -2008,21 +2008,21 @@ pub const Compiler = struct { pub fn writeDialogFont(self: *Compiler, resource: Resource, values: FontStatementValues, writer: anytype) !void { const node = values.node; const point_size = evaluateNumberExpression(node.point_size, self.source, self.input_code_pages); - try writer.writeInt(u16, point_size.asWord(), .Little); + try writer.writeInt(u16, point_size.asWord(), .little); if (resource == .dialogex) { - try writer.writeInt(u16, values.weight, .Little); + try writer.writeInt(u16, values.weight, .little); } if (resource == .dialogex) { - try writer.writeInt(u8, @intFromBool(values.italic), .Little); + try writer.writeInt(u8, @intFromBool(values.italic), .little); } if (node.char_set) |char_set| { const value = evaluateNumberExpression(char_set, self.source, self.input_code_pages); - try writer.writeInt(u8, @as(u8, @truncate(value.value)), .Little); + try writer.writeInt(u8, @as(u8, @truncate(value.value)), .little); } else if (resource == .dialogex) { - try writer.writeInt(u8, 1, .Little); // DEFAULT_CHARSET + try writer.writeInt(u8, 1, .little); // DEFAULT_CHARSET } const typeface = try self.parseQuotedStringAsWideString(node.typeface); @@ -2077,9 +2077,9 @@ pub const Compiler = struct { pub fn writeMenuData(self: *Compiler, node: *Node.Menu, data_writer: anytype, resource: Resource) !void { // menu header const version: u16 = if (resource == .menu) 0 else 1; - try data_writer.writeInt(u16, version, .Little); + try data_writer.writeInt(u16, version, .little); const header_size: u16 = if (resource == .menu) 0 else 4; - try data_writer.writeInt(u16, header_size, .Little); // cbHeaderSize + try data_writer.writeInt(u16, header_size, .little); // cbHeaderSize // Note: There can be extra bytes at the end of this header (`rgbExtra`), // but they are always zero-length for us, so we don't write anything // (the length of the rgbExtra field is inferred from the header_size). @@ -2089,9 +2089,9 @@ pub const Compiler = struct { if (resource == .menuex) { if (node.help_id) |help_id_node| { const help_id = evaluateNumberExpression(help_id_node, self.source, self.input_code_pages); - try data_writer.writeInt(u32, help_id.value, .Little); + try data_writer.writeInt(u32, help_id.value, .little); } else { - try data_writer.writeInt(u32, 0, .Little); + try data_writer.writeInt(u32, 0, .little); } } @@ -2111,9 +2111,9 @@ pub const Compiler = struct { // compiler still uses this alternate form, so that's what we use too. var flags = res.MenuItemFlags{}; if (is_last_of_parent) flags.markLast(); - try writer.writeInt(u16, flags.value, .Little); - try writer.writeInt(u16, 0, .Little); // id - try writer.writeInt(u16, 0, .Little); // null-terminated UTF-16 text + try writer.writeInt(u16, flags.value, .little); + try writer.writeInt(u16, 0, .little); // id + try writer.writeInt(u16, 0, .little); // null-terminated UTF-16 text }, .menu_item => { const menu_item = @fieldParentPtr(Node.MenuItem, "base", node); @@ -2124,10 +2124,10 @@ pub const Compiler = struct { flags.apply(option); } if (is_last_of_parent) flags.markLast(); - try writer.writeInt(u16, flags.value, .Little); + try writer.writeInt(u16, flags.value, .little); var result = evaluateNumberExpression(menu_item.result, self.source, self.input_code_pages); - try writer.writeInt(u16, result.asWord(), .Little); + try writer.writeInt(u16, result.asWord(), .little); var text = try self.parseQuotedStringAsWideString(menu_item.text); defer self.allocator.free(text); @@ -2142,7 +2142,7 @@ pub const Compiler = struct { flags.apply(option); } if (is_last_of_parent) flags.markLast(); - try writer.writeInt(u16, flags.value, .Little); + try writer.writeInt(u16, flags.value, .little); var text = try self.parseQuotedStringAsWideString(popup.text); defer self.allocator.free(text); @@ -2158,30 +2158,30 @@ pub const Compiler = struct { if (menu_item.type) |flags| { const value = evaluateNumberExpression(flags, self.source, self.input_code_pages); - try writer.writeInt(u32, value.value, .Little); + try writer.writeInt(u32, value.value, .little); } else { - try writer.writeInt(u32, 0, .Little); + try writer.writeInt(u32, 0, .little); } if (menu_item.state) |state| { const value = evaluateNumberExpression(state, self.source, self.input_code_pages); - try writer.writeInt(u32, value.value, .Little); + try writer.writeInt(u32, value.value, .little); } else { - try writer.writeInt(u32, 0, .Little); + try writer.writeInt(u32, 0, .little); } if (menu_item.id) |id| { const value = evaluateNumberExpression(id, self.source, self.input_code_pages); - try writer.writeInt(u32, value.value, .Little); + try writer.writeInt(u32, value.value, .little); } else { - try writer.writeInt(u32, 0, .Little); + try writer.writeInt(u32, 0, .little); } var flags: u16 = 0; if (is_last_of_parent) flags |= comptime @as(u16, @intCast(res.MF.END)); // This constant doesn't seem to have a named #define, it's different than MF_POPUP if (node_type == .popup_ex) flags |= 0x01; - try writer.writeInt(u16, flags, .Little); + try writer.writeInt(u16, flags, .little); var text = try self.parseQuotedStringAsWideString(menu_item.text); defer self.allocator.free(text); @@ -2196,9 +2196,9 @@ pub const Compiler = struct { if (node_type == .popup_ex) { if (menu_item.help_id) |help_id_node| { const help_id = evaluateNumberExpression(help_id_node, self.source, self.input_code_pages); - try writer.writeInt(u32, help_id.value, .Little); + try writer.writeInt(u32, help_id.value, .little); } else { - try writer.writeInt(u32, 0, .Little); + try writer.writeInt(u32, 0, .little); } for (menu_item.items, 0..) |item, i| { @@ -2219,15 +2219,15 @@ pub const Compiler = struct { var limited_writer = limitedWriter(data_buffer.writer(), std.math.maxInt(u16)); const data_writer = limited_writer.writer(); - try data_writer.writeInt(u16, 0, .Little); // placeholder size - try data_writer.writeInt(u16, res.FixedFileInfo.byte_len, .Little); - try data_writer.writeInt(u16, res.VersionNode.type_binary, .Little); + try data_writer.writeInt(u16, 0, .little); // placeholder size + try data_writer.writeInt(u16, res.FixedFileInfo.byte_len, .little); + try data_writer.writeInt(u16, res.VersionNode.type_binary, .little); const key_bytes = std.mem.sliceAsBytes(res.FixedFileInfo.key[0 .. res.FixedFileInfo.key.len + 1]); try data_writer.writeAll(key_bytes); // The number of bytes written up to this point is always the same, since the name // of the node is a constant (FixedFileInfo.key). The total number of bytes // written so far is 38, so we need 2 padding bytes to get back to DWORD alignment - try data_writer.writeInt(u16, 0, .Little); + try data_writer.writeInt(u16, 0, .little); var fixed_file_info = res.FixedFileInfo{}; for (node.fixed_info) |fixed_info| { @@ -2322,7 +2322,7 @@ pub const Compiler = struct { // limited the writer to maxInt(u16) const data_size: u16 = @intCast(data_buffer.items.len); // And now that we know the full size of this node (including its children), set its size - std.mem.writeInt(u16, data_buffer.items[0..2], data_size, .Little); + std.mem.writeInt(u16, data_buffer.items[0..2], data_size, .little); var header = try self.resourceHeader(node.id, node.versioninfo, .{ .data_size = data_size, @@ -2345,12 +2345,12 @@ pub const Compiler = struct { try writeDataPadding(writer, @as(u16, @intCast(buf.items.len))); const node_and_children_size_offset = buf.items.len; - try writer.writeInt(u16, 0, .Little); // placeholder for size + try writer.writeInt(u16, 0, .little); // placeholder for size const data_size_offset = buf.items.len; - try writer.writeInt(u16, 0, .Little); // placeholder for data size + try writer.writeInt(u16, 0, .little); // placeholder for data size const data_type_offset = buf.items.len; // Data type is string unless the node contains values that are numbers. - try writer.writeInt(u16, res.VersionNode.type_string, .Little); + try writer.writeInt(u16, res.VersionNode.type_string, .little); switch (node.id) { inline .block, .block_value => |node_type| { @@ -2412,17 +2412,17 @@ pub const Compiler = struct { const is_empty = parsed_to_first_null.len == 0; const is_only = block_or_value.values.len == 1; if ((!is_empty or !is_only) and (is_last or value_value_node.trailing_comma)) { - try writer.writeInt(u16, 0, .Little); + try writer.writeInt(u16, 0, .little); values_size += if (has_number_value) 2 else 1; } } } var data_size_slice = buf.items[data_size_offset..]; - std.mem.writeInt(u16, data_size_slice[0..@sizeOf(u16)], @as(u16, @intCast(values_size)), .Little); + std.mem.writeInt(u16, data_size_slice[0..@sizeOf(u16)], @as(u16, @intCast(values_size)), .little); if (has_number_value) { const data_type_slice = buf.items[data_type_offset..]; - std.mem.writeInt(u16, data_type_slice[0..@sizeOf(u16)], res.VersionNode.type_binary, .Little); + std.mem.writeInt(u16, data_type_slice[0..@sizeOf(u16)], res.VersionNode.type_binary, .little); } if (node_type == .block) { @@ -2437,7 +2437,7 @@ pub const Compiler = struct { const node_and_children_size = buf.items.len - node_and_children_size_offset; const node_and_children_size_slice = buf.items[node_and_children_size_offset..]; - std.mem.writeInt(u16, node_and_children_size_slice[0..@sizeOf(u16)], @as(u16, @intCast(node_and_children_size)), .Little); + std.mem.writeInt(u16, node_and_children_size_slice[0..@sizeOf(u16)], @as(u16, @intCast(node_and_children_size)), .little); } pub fn writeStringTable(self: *Compiler, node: *Node.StringTable) !void { @@ -2645,17 +2645,17 @@ pub const Compiler = struct { } fn writeSizeInfo(self: ResourceHeader, writer: anytype, size_info: SizeInfo) !void { - try writer.writeInt(DWORD, self.data_size, .Little); // DataSize - try writer.writeInt(DWORD, size_info.bytes, .Little); // HeaderSize + try writer.writeInt(DWORD, self.data_size, .little); // DataSize + try writer.writeInt(DWORD, size_info.bytes, .little); // HeaderSize try self.type_value.write(writer); // TYPE try self.name_value.write(writer); // NAME try writer.writeByteNTimes(0, size_info.padding_after_name); - try writer.writeInt(DWORD, self.data_version, .Little); // DataVersion - try writer.writeInt(WORD, self.memory_flags.value, .Little); // MemoryFlags - try writer.writeInt(WORD, self.language.asInt(), .Little); // LanguageId - try writer.writeInt(DWORD, self.version, .Little); // Version - try writer.writeInt(DWORD, self.characteristics, .Little); // Characteristics + try writer.writeInt(DWORD, self.data_version, .little); // DataVersion + try writer.writeInt(WORD, self.memory_flags.value, .little); // MemoryFlags + try writer.writeInt(WORD, self.language.asInt(), .little); // LanguageId + try writer.writeInt(DWORD, self.version, .little); // Version + try writer.writeInt(DWORD, self.characteristics, .little); // Characteristics } pub fn predefinedResourceType(self: ResourceHeader) ?res.RT { @@ -2998,7 +2998,7 @@ pub const FontDir = struct { defer header.deinit(compiler.allocator); try header.writeAssertNoOverflow(writer); - try writer.writeInt(u16, num_fonts, .Little); + try writer.writeInt(u16, num_fonts, .little); for (self.fonts.items) |font| { // The format of the FONTDIR is a strange beast. // Technically, each FONT is seemingly meant to be written as a @@ -3050,7 +3050,7 @@ pub const FontDir = struct { // device name/face name in the FONTDIR is reliable. // First, the ID is written, though - try writer.writeInt(u16, font.id, .Little); + try writer.writeInt(u16, font.id, .little); try writer.writeAll(&font.header_bytes); try writer.writeByteNTimes(0, 2); } @@ -3187,7 +3187,7 @@ pub const StringTable = struct { var string_i: u8 = 0; while (true) : (i += 1) { if (!self.set_indexes.isSet(i)) { - try data_writer.writeInt(u16, 0, .Little); + try data_writer.writeInt(u16, 0, .little); if (i == 15) break else continue; } @@ -3218,10 +3218,10 @@ pub const StringTable = struct { // If the option is set, then a NUL terminator is added unconditionally. // We already trimmed any trailing NULs, so we know it will be a new addition to the string. if (compiler.null_terminate_string_table_strings) string_len_in_utf16_code_units += 1; - try data_writer.writeInt(u16, string_len_in_utf16_code_units, .Little); + try data_writer.writeInt(u16, string_len_in_utf16_code_units, .little); try data_writer.writeAll(std.mem.sliceAsBytes(trimmed_string)); if (compiler.null_terminate_string_table_strings) { - try data_writer.writeInt(u16, 0, .Little); + try data_writer.writeInt(u16, 0, .little); } if (i == 15) break; diff --git a/src/resinator/ico.zig b/src/resinator/ico.zig index 9075de4ccc..310db6ece2 100644 --- a/src/resinator/ico.zig +++ b/src/resinator/ico.zig @@ -39,17 +39,17 @@ pub fn read(allocator: std.mem.Allocator, reader: anytype, max_size: u64) ReadEr // to do this. Maybe it makes more sense to handle the translation // at the call site instead of having a helper function here. pub fn readAnyError(allocator: std.mem.Allocator, reader: anytype, max_size: u64) !IconDir { - const reserved = try reader.readInt(u16, .Little); + const reserved = try reader.readInt(u16, .little); if (reserved != 0) { return error.InvalidHeader; } - const image_type = reader.readEnum(ImageType, .Little) catch |err| switch (err) { + const image_type = reader.readEnum(ImageType, .little) catch |err| switch (err) { error.InvalidValue => return error.InvalidImageType, else => |e| return e, }; - const num_images = try reader.readInt(u16, .Little); + const num_images = try reader.readInt(u16, .little); // To avoid over-allocation in the case of a file that says it has way more // entries than it actually does, we use an ArrayList with a conservatively @@ -68,19 +68,19 @@ pub fn readAnyError(allocator: std.mem.Allocator, reader: anytype, max_size: u64 switch (image_type) { .icon => { entry.type_specific_data = .{ .icon = .{ - .color_planes = try reader.readInt(u16, .Little), - .bits_per_pixel = try reader.readInt(u16, .Little), + .color_planes = try reader.readInt(u16, .little), + .bits_per_pixel = try reader.readInt(u16, .little), } }; }, .cursor => { entry.type_specific_data = .{ .cursor = .{ - .hotspot_x = try reader.readInt(u16, .Little), - .hotspot_y = try reader.readInt(u16, .Little), + .hotspot_x = try reader.readInt(u16, .little), + .hotspot_y = try reader.readInt(u16, .little), } }; }, } - entry.data_size_in_bytes = try reader.readInt(u32, .Little); - entry.data_offset_from_start_of_file = try reader.readInt(u32, .Little); + entry.data_size_in_bytes = try reader.readInt(u32, .little); + entry.data_offset_from_start_of_file = try reader.readInt(u32, .little); // Validate that the offset/data size is feasible if (@as(u64, entry.data_offset_from_start_of_file) + entry.data_size_in_bytes > max_size) { return error.ImpossibleDataSize; @@ -135,10 +135,10 @@ pub const IconDir = struct { } pub fn writeResData(self: IconDir, writer: anytype, first_image_id: u16) !void { - try writer.writeInt(u16, 0, .Little); - try writer.writeInt(u16, @intFromEnum(self.image_type), .Little); + try writer.writeInt(u16, 0, .little); + try writer.writeInt(u16, @intFromEnum(self.image_type), .little); // We know that entries.len must fit into a u16 - try writer.writeInt(u16, @as(u16, @intCast(self.entries.len)), .Little); + try writer.writeInt(u16, @as(u16, @intCast(self.entries.len)), .little); var image_id = first_image_id; for (self.entries) |entry| { @@ -175,23 +175,23 @@ pub const Entry = struct { pub fn writeResData(self: Entry, writer: anytype, id: u16) !void { switch (self.type_specific_data) { .icon => |icon_data| { - try writer.writeInt(u8, @as(u8, @truncate(self.width)), .Little); - try writer.writeInt(u8, @as(u8, @truncate(self.height)), .Little); - try writer.writeInt(u8, self.num_colors, .Little); - try writer.writeInt(u8, self.reserved, .Little); - try writer.writeInt(u16, icon_data.color_planes, .Little); - try writer.writeInt(u16, icon_data.bits_per_pixel, .Little); - try writer.writeInt(u32, self.data_size_in_bytes, .Little); + try writer.writeInt(u8, @as(u8, @truncate(self.width)), .little); + try writer.writeInt(u8, @as(u8, @truncate(self.height)), .little); + try writer.writeInt(u8, self.num_colors, .little); + try writer.writeInt(u8, self.reserved, .little); + try writer.writeInt(u16, icon_data.color_planes, .little); + try writer.writeInt(u16, icon_data.bits_per_pixel, .little); + try writer.writeInt(u32, self.data_size_in_bytes, .little); }, .cursor => |cursor_data| { - try writer.writeInt(u16, self.width, .Little); - try writer.writeInt(u16, self.height, .Little); - try writer.writeInt(u16, cursor_data.hotspot_x, .Little); - try writer.writeInt(u16, cursor_data.hotspot_y, .Little); - try writer.writeInt(u32, self.data_size_in_bytes + 4, .Little); + try writer.writeInt(u16, self.width, .little); + try writer.writeInt(u16, self.height, .little); + try writer.writeInt(u16, cursor_data.hotspot_x, .little); + try writer.writeInt(u16, cursor_data.hotspot_y, .little); + try writer.writeInt(u32, self.data_size_in_bytes + 4, .little); }, } - try writer.writeInt(u16, id, .Little); + try writer.writeInt(u16, id, .little); } }; diff --git a/src/resinator/res.zig b/src/resinator/res.zig index c21f877245..7db3f0d749 100644 --- a/src/resinator/res.zig +++ b/src/resinator/res.zig @@ -249,14 +249,14 @@ pub const NameOrOrdinal = union(enum) { try writer.writeAll(std.mem.sliceAsBytes(name[0 .. name.len + 1])); }, .ordinal => |ordinal| { - try writer.writeInt(u16, 0xffff, .Little); - try writer.writeInt(u16, ordinal, .Little); + try writer.writeInt(u16, 0xffff, .little); + try writer.writeInt(u16, ordinal, .little); }, } } pub fn writeEmpty(writer: anytype) !void { - try writer.writeInt(u16, 0, .Little); + try writer.writeInt(u16, 0, .little); } pub fn fromString(allocator: Allocator, bytes: SourceBytes) !NameOrOrdinal { @@ -963,19 +963,19 @@ pub const FixedFileInfo = struct { }; pub fn write(self: FixedFileInfo, writer: anytype) !void { - try writer.writeInt(u32, signature, .Little); - try writer.writeInt(u32, version, .Little); - try writer.writeInt(u32, self.file_version.mostSignificantCombinedParts(), .Little); - try writer.writeInt(u32, self.file_version.leastSignificantCombinedParts(), .Little); - try writer.writeInt(u32, self.product_version.mostSignificantCombinedParts(), .Little); - try writer.writeInt(u32, self.product_version.leastSignificantCombinedParts(), .Little); - try writer.writeInt(u32, self.file_flags_mask, .Little); - try writer.writeInt(u32, self.file_flags, .Little); - try writer.writeInt(u32, self.file_os, .Little); - try writer.writeInt(u32, self.file_type, .Little); - try writer.writeInt(u32, self.file_subtype, .Little); - try writer.writeInt(u32, self.file_date.mostSignificantCombinedParts(), .Little); - try writer.writeInt(u32, self.file_date.leastSignificantCombinedParts(), .Little); + try writer.writeInt(u32, signature, .little); + try writer.writeInt(u32, version, .little); + try writer.writeInt(u32, self.file_version.mostSignificantCombinedParts(), .little); + try writer.writeInt(u32, self.file_version.leastSignificantCombinedParts(), .little); + try writer.writeInt(u32, self.product_version.mostSignificantCombinedParts(), .little); + try writer.writeInt(u32, self.product_version.leastSignificantCombinedParts(), .little); + try writer.writeInt(u32, self.file_flags_mask, .little); + try writer.writeInt(u32, self.file_flags, .little); + try writer.writeInt(u32, self.file_os, .little); + try writer.writeInt(u32, self.file_type, .little); + try writer.writeInt(u32, self.file_subtype, .little); + try writer.writeInt(u32, self.file_date.mostSignificantCombinedParts(), .little); + try writer.writeInt(u32, self.file_date.leastSignificantCombinedParts(), .little); } }; diff --git a/src/value.zig b/src/value.zig index d9dfd3a257..6af43063d1 100644 --- a/src/value.zig +++ b/src/value.zig @@ -778,8 +778,8 @@ pub const Value = struct { .Void => {}, .Bool => { const byte_index = switch (endian) { - .Little => bit_offset / 8, - .Big => buffer.len - bit_offset / 8 - 1, + .little => bit_offset / 8, + .big => buffer.len - bit_offset / 8 - 1, }; if (val.toBool()) { buffer[byte_index] |= (@as(u8, 1) << @as(u3, @intCast(bit_offset % 8))); @@ -815,7 +815,7 @@ pub const Value = struct { var elem_i: usize = 0; while (elem_i < len) : (elem_i += 1) { // On big-endian systems, LLVM reverses the element order of vectors by default - const tgt_elem_i = if (endian == .Big) len - elem_i - 1 else elem_i; + const tgt_elem_i = if (endian == .big) len - elem_i - 1 else elem_i; const elem_val = try val.elemValue(mod, tgt_elem_i); try elem_val.writeToPackedMemory(elem_ty, mod, buffer, bit_offset + bits); bits += elem_bit_size; @@ -1064,8 +1064,8 @@ pub const Value = struct { .Void => return Value.void, .Bool => { const byte = switch (endian) { - .Big => buffer[buffer.len - bit_offset / 8 - 1], - .Little => buffer[bit_offset / 8], + .big => buffer[buffer.len - bit_offset / 8 - 1], + .little => buffer[bit_offset / 8], }; if (((byte >> @as(u3, @intCast(bit_offset % 8))) & 1) == 0) { return Value.false; @@ -1127,7 +1127,7 @@ pub const Value = struct { const elem_bit_size = @as(u16, @intCast(elem_ty.bitSize(mod))); for (elems, 0..) |_, i| { // On big-endian systems, LLVM reverses the element order of vectors by default - const tgt_elem_i = if (endian == .Big) elems.len - i - 1 else i; + const tgt_elem_i = if (endian == .big) elems.len - i - 1 else i; elems[tgt_elem_i] = try (try readFromPackedMemory(elem_ty, mod, buffer, bit_offset + bits, arena)).intern(elem_ty, mod); bits += elem_bit_size; } diff --git a/test/behavior/align.zig b/test/behavior/align.zig index 217d0b7c15..7b95cf8a56 100644 --- a/test/behavior/align.zig +++ b/test/behavior/align.zig @@ -616,8 +616,8 @@ test "sub-aligned pointer field access" { const ptr: *align(1) Header = @ptrCast(buf[1..][0..8]); const x = ptr.bytes_len; switch (builtin.cpu.arch.endian()) { - .Big => try expect(x == 0x06070809), - .Little => try expect(x == 0x09080706), + .big => try expect(x == 0x06070809), + .little => try expect(x == 0x09080706), } } diff --git a/test/behavior/bitcast.zig b/test/behavior/bitcast.zig index 2f49283fb1..846a1c33af 100644 --- a/test/behavior/bitcast.zig +++ b/test/behavior/bitcast.zig @@ -107,14 +107,14 @@ fn testBitCastuXToBytes(comptime N: usize) !void { const byte_count = (N + 7) / 8; switch (native_endian) { - .Little => { + .little => { var byte_i = 0; while (byte_i < (byte_count - 1)) : (byte_i += 1) { try expect(bytes[byte_i] == 0xff); } try expect(((bytes[byte_i] ^ 0xff) << -%@as(u3, @truncate(N))) == 0); }, - .Big => { + .big => { var byte_i = byte_count - 1; while (byte_i > 0) : (byte_i -= 1) { try expect(bytes[byte_i] == 0xff); @@ -197,11 +197,11 @@ test "@bitCast extern structs at runtime and comptime" { var full = Full{ .number = 0x1234 }; var two_halves = @as(TwoHalves, @bitCast(full)); switch (native_endian) { - .Big => { + .big => { try expect(two_halves.half1 == 0x12); try expect(two_halves.half2 == 0x34); }, - .Little => { + .little => { try expect(two_halves.half1 == 0x34); try expect(two_halves.half2 == 0x12); }, @@ -332,7 +332,7 @@ test "comptime @bitCast packed struct to int and back" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; - if (builtin.zig_backend == .stage2_llvm and native_endian == .Big) { + if (builtin.zig_backend == .stage2_llvm and native_endian == .big) { // https://github.com/ziglang/zig/issues/13782 return error.SkipZigTest; } diff --git a/test/behavior/bugs/12169.zig b/test/behavior/bugs/12169.zig index b3db56e20b..c8bf7ae543 100644 --- a/test/behavior/bugs/12169.zig +++ b/test/behavior/bugs/12169.zig @@ -7,7 +7,7 @@ test { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO - if (comptime builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.endian() == .Big) { + if (comptime builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.endian() == .big) { // https://github.com/ziglang/zig/issues/13782 return error.SkipZigTest; } diff --git a/test/behavior/cast.zig b/test/behavior/cast.zig index a7029bf0b7..73036b9404 100644 --- a/test/behavior/cast.zig +++ b/test/behavior/cast.zig @@ -1077,7 +1077,7 @@ test "pointer reinterpret const float to int" { const float_ptr = &float; const int_ptr = @as(*const i32, @ptrCast(float_ptr)); const int_val = int_ptr.*; - if (native_endian == .Little) + if (native_endian == .little) try expect(int_val == 0x33333303) else try expect(int_val == 0x3fe33333); diff --git a/test/behavior/cast_int.zig b/test/behavior/cast_int.zig index 723691ab08..23e5a614f8 100644 --- a/test/behavior/cast_int.zig +++ b/test/behavior/cast_int.zig @@ -163,7 +163,7 @@ test "load non byte-sized optional value" { } test "load non byte-sized value in struct" { - if (builtin.cpu.arch.endian() != .Little) return error.SkipZigTest; // packed struct TODO + if (builtin.cpu.arch.endian() != .little) return error.SkipZigTest; // packed struct TODO if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // note: this bug is triggered by the == operator, expectEqual will hide it diff --git a/test/behavior/comptime_memory.zig b/test/behavior/comptime_memory.zig index 2cbdad830f..4245f332d6 100644 --- a/test/behavior/comptime_memory.zig +++ b/test/behavior/comptime_memory.zig @@ -73,7 +73,7 @@ test "type pun value and struct" { } fn bigToNativeEndian(comptime T: type, v: T) T { - return if (endian == .Big) v else @byteSwap(v); + return if (endian == .big) v else @byteSwap(v); } test "type pun endianness" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO @@ -385,7 +385,7 @@ test "accessing reinterpreted memory of parent object" { b: [4]u8, c: f32, }; - const expected = if (endian == .Little) 102 else 38; + const expected = if (endian == .little) 102 else 38; comptime { const x = S{ diff --git a/test/behavior/packed-struct.zig b/test/behavior/packed-struct.zig index 39dc9977c9..b6d2ee74ea 100644 --- a/test/behavior/packed-struct.zig +++ b/test/behavior/packed-struct.zig @@ -165,7 +165,7 @@ test "correct sizeOf and offsets in packed structs" { try expectEqual(22, @bitOffsetOf(PStruct, "u10_b")); try expectEqual(4, @sizeOf(PStruct)); - if (native_endian == .Little) { + if (native_endian == .little) { const s1 = @as(PStruct, @bitCast(@as(u32, 0x12345678))); try expectEqual(false, s1.bool_a); try expectEqual(false, s1.bool_b); @@ -206,7 +206,7 @@ test "nested packed structs" { try expectEqual(3, @offsetOf(S3, "y")); try expectEqual(24, @bitOffsetOf(S3, "y")); - if (native_endian == .Little) { + if (native_endian == .little) { const s3 = @as(S3Padded, @bitCast(@as(u64, 0xe952d5c71ff4))).s3; try expectEqual(@as(u8, 0xf4), s3.x.a); try expectEqual(@as(u8, 0x1f), s3.x.b); @@ -258,7 +258,7 @@ test "nested packed struct unaligned" { if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; - if (native_endian != .Little) return error.SkipZigTest; // Byte aligned packed struct field pointers have not been implemented yet + if (native_endian != .little) return error.SkipZigTest; // Byte aligned packed struct field pointers have not been implemented yet const S1 = packed struct { a: u4, @@ -352,13 +352,13 @@ test "byte-aligned field pointer offsets" { .d = 4, }; switch (comptime builtin.cpu.arch.endian()) { - .Little => { + .little => { comptime assert(@TypeOf(&a.a) == *align(4) u8); comptime assert(@TypeOf(&a.b) == *u8); comptime assert(@TypeOf(&a.c) == *align(2) u8); comptime assert(@TypeOf(&a.d) == *u8); }, - .Big => { + .big => { // TODO re-evaluate packed struct endianness comptime assert(@TypeOf(&a.a) == *align(4:0:4) u8); comptime assert(@TypeOf(&a.b) == *align(4:8:4) u8); @@ -400,11 +400,11 @@ test "byte-aligned field pointer offsets" { .b = 2, }; switch (comptime builtin.cpu.arch.endian()) { - .Little => { + .little => { comptime assert(@TypeOf(&b.a) == *align(4) u16); comptime assert(@TypeOf(&b.b) == *u16); }, - .Big => { + .big => { comptime assert(@TypeOf(&b.a) == *align(4:0:4) u16); comptime assert(@TypeOf(&b.b) == *align(4:16:4) u16); }, @@ -433,7 +433,7 @@ test "nested packed struct field pointers" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // ubsan unaligned pointer access if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; - if (native_endian != .Little) return error.SkipZigTest; // Byte aligned packed struct field pointers have not been implemented yet + if (native_endian != .little) return error.SkipZigTest; // Byte aligned packed struct field pointers have not been implemented yet const S2 = packed struct { base: u8, @@ -491,7 +491,7 @@ test "@intFromPtr on a packed struct field" { if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; - if (native_endian != .Little) return error.SkipZigTest; + if (native_endian != .little) return error.SkipZigTest; const S = struct { const P = packed struct { @@ -515,7 +515,7 @@ test "@intFromPtr on a packed struct field unaligned and nested" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; - if (native_endian != .Little) return error.SkipZigTest; // Byte aligned packed struct field pointers have not been implemented yet + if (native_endian != .little) return error.SkipZigTest; // Byte aligned packed struct field pointers have not been implemented yet const S1 = packed struct { a: u4, @@ -921,11 +921,11 @@ test "overaligned pointer to packed struct" { var foo: S align(4) = .{ .a = 123, .b = 456 }; const ptr: *align(4) S = &foo; switch (comptime builtin.cpu.arch.endian()) { - .Little => { + .little => { const ptr_to_b: *u32 = &ptr.b; try expect(ptr_to_b.* == 456); }, - .Big => { + .big => { // Byte aligned packed struct field pointers have not been implemented yet. const ptr_to_a: *align(4:0:8) u32 = &ptr.a; try expect(ptr_to_a.* == 123); diff --git a/test/behavior/packed_struct_explicit_backing_int.zig b/test/behavior/packed_struct_explicit_backing_int.zig index 9e476572ab..29b8c4aa9b 100644 --- a/test/behavior/packed_struct_explicit_backing_int.zig +++ b/test/behavior/packed_struct_explicit_backing_int.zig @@ -24,7 +24,7 @@ test "packed struct explicit backing integer" { try expectEqual(3, @offsetOf(S3, "y")); try expectEqual(24, @bitOffsetOf(S3, "y")); - if (native_endian == .Little) { + if (native_endian == .little) { const s3 = @as(S3Padded, @bitCast(@as(u64, 0xe952d5c71ff4))).s3; try expectEqual(@as(u8, 0xf4), s3.x.a); try expectEqual(@as(u8, 0x1f), s3.x.b); diff --git a/test/behavior/ptrcast.zig b/test/behavior/ptrcast.zig index 08e199ae60..635a4df843 100644 --- a/test/behavior/ptrcast.zig +++ b/test/behavior/ptrcast.zig @@ -13,8 +13,8 @@ test "reinterpret bytes as integer with nonzero offset" { fn testReinterpretBytesAsInteger() !void { const bytes = "\x12\x34\x56\x78\xab"; const expected = switch (native_endian) { - .Little => 0xab785634, - .Big => 0x345678ab, + .little => 0xab785634, + .big => 0x345678ab, }; try expect(@as(*align(1) const u32, @ptrCast(bytes[1..5])).* == expected); } @@ -48,8 +48,8 @@ fn testReinterpretStructWrappedBytesAsInteger() !void { const S = struct { bytes: [5:0]u8 }; const obj = S{ .bytes = "\x12\x34\x56\x78\xab".* }; const expected = switch (native_endian) { - .Little => 0xab785634, - .Big => 0x345678ab, + .little => 0xab785634, + .big => 0x345678ab, }; try expect(@as(*align(1) const u32, @ptrCast(obj.bytes[1..5])).* == expected); } @@ -176,7 +176,7 @@ test "reinterpret struct field at comptime" { if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; const numNative = comptime Bytes.init(0x12345678); - if (native_endian != .Little) { + if (native_endian != .little) { try expect(std.mem.eql(u8, &[_]u8{ 0x12, 0x34, 0x56, 0x78 }, &numNative.bytes)); } else { try expect(std.mem.eql(u8, &[_]u8{ 0x78, 0x56, 0x34, 0x12 }, &numNative.bytes)); @@ -201,7 +201,7 @@ test "ptrcast of const integer has the correct object size" { const is_bytes = @as([*]const u8, @ptrCast(&is_value))[0..@sizeOf(isize)]; if (@sizeOf(isize) == 8) { switch (native_endian) { - .Little => { + .little => { try expect(is_bytes[0] == 0xff); try expect(is_bytes[1] == 0xff); try expect(is_bytes[2] == 0xff); @@ -212,7 +212,7 @@ test "ptrcast of const integer has the correct object size" { try expect(is_bytes[6] == 0xff); try expect(is_bytes[7] == 0x7f); }, - .Big => { + .big => { try expect(is_bytes[0] == 0x7f); try expect(is_bytes[1] == 0xff); try expect(is_bytes[2] == 0xff); diff --git a/test/behavior/union.zig b/test/behavior/union.zig index 5e89bca0a3..da36a34d1d 100644 --- a/test/behavior/union.zig +++ b/test/behavior/union.zig @@ -1686,7 +1686,7 @@ test "memset packed union" { } fn littleToNativeEndian(comptime T: type, v: T) T { - return if (endian == .Little) v else @byteSwap(v); + return if (endian == .little) v else @byteSwap(v); } test "reinterpret extern union" { @@ -1723,8 +1723,8 @@ test "reinterpret extern union" { { const expected, const mask = switch (endian) { - .Little => .{ 0x2a, 0xff }, - .Big => .{ 0x2a000000, 0xff000000 }, + .little => .{ 0x2a, 0xff }, + .big => .{ 0x2a000000, 0xff000000 }, }; try expectEqual(@as(u8, 0x2a), u.foo); diff --git a/tools/gen_stubs.zig b/tools/gen_stubs.zig index 1b70023666..b603213566 100644 --- a/tools/gen_stubs.zig +++ b/tools/gen_stubs.zig @@ -234,12 +234,12 @@ pub fn main() !void { switch (header.is_64) { true => switch (header.endian) { - .Big => try parseElf(parse, true, .Big), - .Little => try parseElf(parse, true, .Little), + .big => try parseElf(parse, true, .big), + .little => try parseElf(parse, true, .little), }, false => switch (header.endian) { - .Big => try parseElf(parse, false, .Big), - .Little => try parseElf(parse, false, .Little), + .big => try parseElf(parse, false, .big), + .little => try parseElf(parse, false, .little), }, } }