| author | |
| committer | |
| log | 00be934569d25e3b041091ff63a4cf6c456d1403 |
| tree | 0e041a8f62b213acec0016cdb041fec59f50a07d |
| parent | 3c1432701129bacf95b944f0f86af2d96ae72c69 |
19 files changed, 97 insertions(+), 103 deletions(-)
lib/std/build.zig+4-4| ... | ... | @@ -1898,10 +1898,10 @@ pub const LibExeObjStep = struct { |
| 1898 | 1898 | } |
| 1899 | 1899 | |
| 1900 | 1900 | switch (self.build_mode) { |
| 1901 | builtin.Mode.Debug => {}, | |
| 1902 | builtin.Mode.ReleaseSafe => zig_args.append("--release-safe") catch unreachable, | |
| 1903 | builtin.Mode.ReleaseFast => zig_args.append("--release-fast") catch unreachable, | |
| 1904 | builtin.Mode.ReleaseSmall => zig_args.append("--release-small") catch unreachable, | |
| 1901 | .Debug => {}, | |
| 1902 | .ReleaseSafe => zig_args.append("--release-safe") catch unreachable, | |
| 1903 | .ReleaseFast => zig_args.append("--release-fast") catch unreachable, | |
| 1904 | .ReleaseSmall => zig_args.append("--release-small") catch unreachable, | |
| 1905 | 1905 | } |
| 1906 | 1906 | |
| 1907 | 1907 | try zig_args.append("--cache-dir"); |
lib/std/crypto/benchmark.zig+1-1| ... | ... | @@ -120,7 +120,7 @@ fn usage() void { |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | fn mode(comptime x: comptime_int) comptime_int { |
| 123 | return if (builtin.mode == builtin.Mode.Debug) x / 64 else x; | |
| 123 | return if (builtin.mode == .Debug) x / 64 else x; | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // TODO(#1358): Replace with builtin formatted padding when available. |
lib/std/elf.zig+2-2| ... | ... | @@ -370,8 +370,8 @@ pub const Elf = struct { |
| 370 | 370 | }; |
| 371 | 371 | |
| 372 | 372 | elf.endian = switch (try in.readByte()) { |
| 373 | 1 => builtin.Endian.Little, | |
| 374 | 2 => builtin.Endian.Big, | |
| 373 | 1 => .Little, | |
| 374 | 2 => .Big, | |
| 375 | 375 | else => return error.InvalidFormat, |
| 376 | 376 | }; |
| 377 | 377 |
lib/std/hash/auto_hash.zig+3-5| ... | ... | @@ -25,13 +25,13 @@ pub fn hashPointer(hasher: var, key: var, comptime strat: HashStrategy) void { |
| 25 | 25 | const info = @typeInfo(@TypeOf(key)); |
| 26 | 26 | |
| 27 | 27 | switch (info.Pointer.size) { |
| 28 | builtin.TypeInfo.Pointer.Size.One => switch (strat) { | |
| 28 | .One => switch (strat) { | |
| 29 | 29 | .Shallow => hash(hasher, @ptrToInt(key), .Shallow), |
| 30 | 30 | .Deep => hash(hasher, key.*, .Shallow), |
| 31 | 31 | .DeepRecursive => hash(hasher, key.*, .DeepRecursive), |
| 32 | 32 | }, |
| 33 | 33 | |
| 34 | builtin.TypeInfo.Pointer.Size.Slice => switch (strat) { | |
| 34 | .Slice => switch (strat) { | |
| 35 | 35 | .Shallow => { |
| 36 | 36 | hashPointer(hasher, key.ptr, .Shallow); |
| 37 | 37 | hash(hasher, key.len, .Shallow); |
| ... | ... | @@ -40,9 +40,7 @@ pub fn hashPointer(hasher: var, key: var, comptime strat: HashStrategy) void { |
| 40 | 40 | .DeepRecursive => hashArray(hasher, key, .DeepRecursive), |
| 41 | 41 | }, |
| 42 | 42 | |
| 43 | builtin.TypeInfo.Pointer.Size.Many, | |
| 44 | builtin.TypeInfo.Pointer.Size.C, | |
| 45 | => switch (strat) { | |
| 43 | .Many, .C, => switch (strat) { | |
| 46 | 44 | .Shallow => hash(hasher, @ptrToInt(key), .Shallow), |
| 47 | 45 | else => @compileError( |
| 48 | 46 | \\ unknown-length pointers and C pointers cannot be hashed deeply. |
lib/std/hash/benchmark.zig+1-1| ... | ... | @@ -168,7 +168,7 @@ fn usage() void { |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | fn mode(comptime x: comptime_int) comptime_int { |
| 171 | return if (builtin.mode == builtin.Mode.Debug) x / 64 else x; | |
| 171 | return if (builtin.mode == .Debug) x / 64 else x; | |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | pub fn main() !void { |
lib/std/hash/cityhash.zig+4-4| ... | ... | @@ -11,7 +11,7 @@ pub const CityHash32 = struct { |
| 11 | 11 | fn fetch32(ptr: [*]const u8) u32 { |
| 12 | 12 | var v: u32 = undefined; |
| 13 | 13 | @memcpy(@ptrCast([*]u8, &v), ptr, 4); |
| 14 | if (builtin.endian == builtin.Endian.Big) | |
| 14 | if (builtin.endian == .Big) | |
| 15 | 15 | return @byteSwap(u32, v); |
| 16 | 16 | return v; |
| 17 | 17 | } |
| ... | ... | @@ -174,7 +174,7 @@ pub const CityHash64 = struct { |
| 174 | 174 | fn fetch32(ptr: [*]const u8) u32 { |
| 175 | 175 | var v: u32 = undefined; |
| 176 | 176 | @memcpy(@ptrCast([*]u8, &v), ptr, 4); |
| 177 | if (builtin.endian == builtin.Endian.Big) | |
| 177 | if (builtin.endian == .Big) | |
| 178 | 178 | return @byteSwap(u32, v); |
| 179 | 179 | return v; |
| 180 | 180 | } |
| ... | ... | @@ -182,7 +182,7 @@ pub const CityHash64 = struct { |
| 182 | 182 | fn fetch64(ptr: [*]const u8) u64 { |
| 183 | 183 | var v: u64 = undefined; |
| 184 | 184 | @memcpy(@ptrCast([*]u8, &v), ptr, 8); |
| 185 | if (builtin.endian == builtin.Endian.Big) | |
| 185 | if (builtin.endian == .Big) | |
| 186 | 186 | return @byteSwap(u64, v); |
| 187 | 187 | return v; |
| 188 | 188 | } |
| ... | ... | @@ -369,7 +369,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 { |
| 369 | 369 | key[i] = @intCast(u8, i); |
| 370 | 370 | |
| 371 | 371 | var h = hash_fn(key[0..i], 256 - i); |
| 372 | if (builtin.endian == builtin.Endian.Big) | |
| 372 | if (builtin.endian == .Big) | |
| 373 | 373 | h = @byteSwap(@TypeOf(h), h); |
| 374 | 374 | @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes); |
| 375 | 375 | } |
lib/std/hash/murmur.zig+8-8| ... | ... | @@ -17,7 +17,7 @@ pub const Murmur2_32 = struct { |
| 17 | 17 | var h1: u32 = seed ^ len; |
| 18 | 18 | for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| { |
| 19 | 19 | var k1: u32 = v; |
| 20 | if (builtin.endian == builtin.Endian.Big) | |
| 20 | if (builtin.endian == .Big) | |
| 21 | 21 | k1 = @byteSwap(u32, k1); |
| 22 | 22 | k1 *%= m; |
| 23 | 23 | k1 ^= k1 >> 24; |
| ... | ... | @@ -102,7 +102,7 @@ pub const Murmur2_64 = struct { |
| 102 | 102 | var h1: u64 = seed ^ (len *% m); |
| 103 | 103 | for (@ptrCast([*]align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| { |
| 104 | 104 | var k1: u64 = v; |
| 105 | if (builtin.endian == builtin.Endian.Big) | |
| 105 | if (builtin.endian == .Big) | |
| 106 | 106 | k1 = @byteSwap(u64, k1); |
| 107 | 107 | k1 *%= m; |
| 108 | 108 | k1 ^= k1 >> 47; |
| ... | ... | @@ -115,7 +115,7 @@ pub const Murmur2_64 = struct { |
| 115 | 115 | if (rest > 0) { |
| 116 | 116 | var k1: u64 = 0; |
| 117 | 117 | @memcpy(@ptrCast([*]u8, &k1), @ptrCast([*]const u8, &str[@intCast(usize, offset)]), @intCast(usize, rest)); |
| 118 | if (builtin.endian == builtin.Endian.Big) | |
| 118 | if (builtin.endian == .Big) | |
| 119 | 119 | k1 = @byteSwap(u64, k1); |
| 120 | 120 | h1 ^= k1; |
| 121 | 121 | h1 *%= m; |
| ... | ... | @@ -182,7 +182,7 @@ pub const Murmur3_32 = struct { |
| 182 | 182 | var h1: u32 = seed; |
| 183 | 183 | for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| { |
| 184 | 184 | var k1: u32 = v; |
| 185 | if (builtin.endian == builtin.Endian.Big) | |
| 185 | if (builtin.endian == .Big) | |
| 186 | 186 | k1 = @byteSwap(u32, k1); |
| 187 | 187 | k1 *%= c1; |
| 188 | 188 | k1 = rotl32(k1, 15); |
| ... | ... | @@ -294,7 +294,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 { |
| 294 | 294 | key[i] = @truncate(u8, i); |
| 295 | 295 | |
| 296 | 296 | var h = hash_fn(key[0..i], 256 - i); |
| 297 | if (builtin.endian == builtin.Endian.Big) | |
| 297 | if (builtin.endian == .Big) | |
| 298 | 298 | h = @byteSwap(@TypeOf(h), h); |
| 299 | 299 | @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes); |
| 300 | 300 | } |
| ... | ... | @@ -308,7 +308,7 @@ test "murmur2_32" { |
| 308 | 308 | var v1: u64 = 0x1234567812345678; |
| 309 | 309 | var v0le: u32 = v0; |
| 310 | 310 | var v1le: u64 = v1; |
| 311 | if (builtin.endian == builtin.Endian.Big) { | |
| 311 | if (builtin.endian == .Big) { | |
| 312 | 312 | v0le = @byteSwap(u32, v0le); |
| 313 | 313 | v1le = @byteSwap(u64, v1le); |
| 314 | 314 | } |
| ... | ... | @@ -322,7 +322,7 @@ test "murmur2_64" { |
| 322 | 322 | var v1: u64 = 0x1234567812345678; |
| 323 | 323 | var v0le: u32 = v0; |
| 324 | 324 | var v1le: u64 = v1; |
| 325 | if (builtin.endian == builtin.Endian.Big) { | |
| 325 | if (builtin.endian == .Big) { | |
| 326 | 326 | v0le = @byteSwap(u32, v0le); |
| 327 | 327 | v1le = @byteSwap(u64, v1le); |
| 328 | 328 | } |
| ... | ... | @@ -336,7 +336,7 @@ test "murmur3_32" { |
| 336 | 336 | var v1: u64 = 0x1234567812345678; |
| 337 | 337 | var v0le: u32 = v0; |
| 338 | 338 | var v1le: u64 = v1; |
| 339 | if (builtin.endian == builtin.Endian.Big) { | |
| 339 | if (builtin.endian == .Big) { | |
| 340 | 340 | v0le = @byteSwap(u32, v0le); |
| 341 | 341 | v1le = @byteSwap(u64, v1le); |
| 342 | 342 | } |
lib/std/hash_map.zig+1-1| ... | ... | @@ -10,7 +10,7 @@ const Wyhash = std.hash.Wyhash; |
| 10 | 10 | const Allocator = mem.Allocator; |
| 11 | 11 | const builtin = @import("builtin"); |
| 12 | 12 | |
| 13 | const want_modification_safety = builtin.mode != builtin.Mode.ReleaseFast; | |
| 13 | const want_modification_safety = builtin.mode != .ReleaseFast; | |
| 14 | 14 | const debug_u32 = if (want_modification_safety) u32 else void; |
| 15 | 15 | |
| 16 | 16 | pub fn AutoHashMap(comptime K: type, comptime V: type) type { |
lib/std/io.zig+14-14| ... | ... | @@ -348,11 +348,11 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type { |
| 348 | 348 | const n = if (self.bit_count >= bits) @intCast(u3, bits) else self.bit_count; |
| 349 | 349 | const shift = u7_bit_count - n; |
| 350 | 350 | switch (endian) { |
| 351 | builtin.Endian.Big => { | |
| 351 | .Big => { | |
| 352 | 352 | out_buffer = @as(Buf, self.bit_buffer >> shift); |
| 353 | 353 | self.bit_buffer <<= n; |
| 354 | 354 | }, |
| 355 | builtin.Endian.Little => { | |
| 355 | .Little => { | |
| 356 | 356 | const value = (self.bit_buffer << shift) >> shift; |
| 357 | 357 | out_buffer = @as(Buf, value); |
| 358 | 358 | self.bit_buffer >>= n; |
| ... | ... | @@ -376,7 +376,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type { |
| 376 | 376 | }; |
| 377 | 377 | |
| 378 | 378 | switch (endian) { |
| 379 | builtin.Endian.Big => { | |
| 379 | .Big => { | |
| 380 | 380 | if (n >= u8_bit_count) { |
| 381 | 381 | out_buffer <<= @intCast(u3, u8_bit_count - 1); |
| 382 | 382 | out_buffer <<= 1; |
| ... | ... | @@ -392,7 +392,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type { |
| 392 | 392 | self.bit_buffer = @truncate(u7, next_byte << @intCast(u3, n - 1)); |
| 393 | 393 | self.bit_count = shift; |
| 394 | 394 | }, |
| 395 | builtin.Endian.Little => { | |
| 395 | .Little => { | |
| 396 | 396 | if (n >= u8_bit_count) { |
| 397 | 397 | out_buffer |= @as(Buf, next_byte) << @intCast(BufShift, out_bits.*); |
| 398 | 398 | out_bits.* += u8_bit_count; |
| ... | ... | @@ -666,8 +666,8 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type { |
| 666 | 666 | |
| 667 | 667 | const high_byte_shift = @intCast(BufShift, buf_bit_count - u8_bit_count); |
| 668 | 668 | var in_buffer = switch (endian) { |
| 669 | builtin.Endian.Big => buf_value << @intCast(BufShift, buf_bit_count - bits), | |
| 670 | builtin.Endian.Little => buf_value, | |
| 669 | .Big => buf_value << @intCast(BufShift, buf_bit_count - bits), | |
| 670 | .Little => buf_value, | |
| 671 | 671 | }; |
| 672 | 672 | var in_bits = bits; |
| 673 | 673 | |
| ... | ... | @@ -675,13 +675,13 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type { |
| 675 | 675 | const bits_remaining = u8_bit_count - self.bit_count; |
| 676 | 676 | const n = @intCast(u3, if (bits_remaining > bits) bits else bits_remaining); |
| 677 | 677 | switch (endian) { |
| 678 | builtin.Endian.Big => { | |
| 678 | .Big => { | |
| 679 | 679 | const shift = @intCast(BufShift, high_byte_shift + self.bit_count); |
| 680 | 680 | const v = @intCast(u8, in_buffer >> shift); |
| 681 | 681 | self.bit_buffer |= v; |
| 682 | 682 | in_buffer <<= n; |
| 683 | 683 | }, |
| 684 | builtin.Endian.Little => { | |
| 684 | .Little => { | |
| 685 | 685 | const v = @truncate(u8, in_buffer) << @intCast(u3, self.bit_count); |
| 686 | 686 | self.bit_buffer |= v; |
| 687 | 687 | in_buffer >>= n; |
| ... | ... | @@ -701,13 +701,13 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type { |
| 701 | 701 | //copy bytes until we can't fill one anymore, then leave the rest in bit_buffer |
| 702 | 702 | while (in_bits >= u8_bit_count) { |
| 703 | 703 | switch (endian) { |
| 704 | builtin.Endian.Big => { | |
| 704 | .Big => { | |
| 705 | 705 | const v = @intCast(u8, in_buffer >> high_byte_shift); |
| 706 | 706 | try self.out_stream.writeByte(v); |
| 707 | 707 | in_buffer <<= @intCast(u3, u8_bit_count - 1); |
| 708 | 708 | in_buffer <<= 1; |
| 709 | 709 | }, |
| 710 | builtin.Endian.Little => { | |
| 710 | .Little => { | |
| 711 | 711 | const v = @truncate(u8, in_buffer); |
| 712 | 712 | try self.out_stream.writeByte(v); |
| 713 | 713 | in_buffer >>= @intCast(u3, u8_bit_count - 1); |
| ... | ... | @@ -720,8 +720,8 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type { |
| 720 | 720 | if (in_bits > 0) { |
| 721 | 721 | self.bit_count = @intCast(u4, in_bits); |
| 722 | 722 | self.bit_buffer = switch (endian) { |
| 723 | builtin.Endian.Big => @truncate(u8, in_buffer >> high_byte_shift), | |
| 724 | builtin.Endian.Little => @truncate(u8, in_buffer), | |
| 723 | .Big => @truncate(u8, in_buffer >> high_byte_shift), | |
| 724 | .Little => @truncate(u8, in_buffer), | |
| 725 | 725 | }; |
| 726 | 726 | } |
| 727 | 727 | } |
| ... | ... | @@ -858,10 +858,10 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing, |
| 858 | 858 | var result = @as(U, 0); |
| 859 | 859 | for (buffer) |byte, i| { |
| 860 | 860 | switch (endian) { |
| 861 | builtin.Endian.Big => { | |
| 861 | .Big => { | |
| 862 | 862 | result = (result << u8_bit_count) | byte; |
| 863 | 863 | }, |
| 864 | builtin.Endian.Little => { | |
| 864 | .Little => { | |
| 865 | 865 | result |= @as(U, byte) << @intCast(Log2U, u8_bit_count * i); |
| 866 | 866 | }, |
| 867 | 867 | } |
lib/std/math/pow.zig+1-1| ... | ... | @@ -32,7 +32,7 @@ const expect = std.testing.expect; |
| 32 | 32 | /// - pow(-inf, y) = pow(-0, -y) |
| 33 | 33 | /// - pow(x, y) = nan for finite x < 0 and finite non-integer y |
| 34 | 34 | pub fn pow(comptime T: type, x: T, y: T) T { |
| 35 | if (@typeInfo(T) == builtin.TypeId.Int) { | |
| 35 | if (@typeInfo(T) == .Int) { | |
| 36 | 36 | return math.powi(T, x, y) catch unreachable; |
| 37 | 37 | } |
| 38 | 38 |
lib/std/math/powi.zig+1-1| ... | ... | @@ -25,7 +25,7 @@ pub fn powi(comptime T: type, x: T, y: T) (error{ |
| 25 | 25 | }!T) { |
| 26 | 26 | const info = @typeInfo(T); |
| 27 | 27 | |
| 28 | comptime assert(@typeInfo(T) == builtin.TypeId.Int); | |
| 28 | comptime assert(@typeInfo(T) == .Int); | |
| 29 | 29 | |
| 30 | 30 | // powi(x, +-0) = 1 for any x |
| 31 | 31 | if (y == 0 or y == -0) { |
lib/std/mem.zig+48-48| ... | ... | @@ -746,12 +746,12 @@ test "mem.indexOf" { |
| 746 | 746 | pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: builtin.Endian) ReturnType { |
| 747 | 747 | var result: ReturnType = 0; |
| 748 | 748 | switch (endian) { |
| 749 | builtin.Endian.Big => { | |
| 749 | .Big => { | |
| 750 | 750 | for (bytes) |b| { |
| 751 | 751 | result = (result << 8) | b; |
| 752 | 752 | } |
| 753 | 753 | }, |
| 754 | builtin.Endian.Little => { | |
| 754 | .Little => { | |
| 755 | 755 | const ShiftType = math.Log2Int(ReturnType); |
| 756 | 756 | for (bytes) |b, index| { |
| 757 | 757 | result = result | (@as(ReturnType, b) << @intCast(ShiftType, index * 8)); |
| ... | ... | @@ -779,13 +779,13 @@ pub fn readIntForeign(comptime T: type, bytes: *const [@divExact(T.bit_count, 8) |
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | pub const readIntLittle = switch (builtin.endian) { |
| 782 | builtin.Endian.Little => readIntNative, | |
| 783 | builtin.Endian.Big => readIntForeign, | |
| 782 | .Little => readIntNative, | |
| 783 | .Big => readIntForeign, | |
| 784 | 784 | }; |
| 785 | 785 | |
| 786 | 786 | pub const readIntBig = switch (builtin.endian) { |
| 787 | builtin.Endian.Little => readIntForeign, | |
| 788 | builtin.Endian.Big => readIntNative, | |
| 787 | .Little => readIntForeign, | |
| 788 | .Big => readIntNative, | |
| 789 | 789 | }; |
| 790 | 790 | |
| 791 | 791 | /// Asserts that bytes.len >= T.bit_count / 8. Reads the integer starting from index 0 |
| ... | ... | @@ -809,13 +809,13 @@ pub fn readIntSliceForeign(comptime T: type, bytes: []const u8) T { |
| 809 | 809 | } |
| 810 | 810 | |
| 811 | 811 | pub const readIntSliceLittle = switch (builtin.endian) { |
| 812 | builtin.Endian.Little => readIntSliceNative, | |
| 813 | builtin.Endian.Big => readIntSliceForeign, | |
| 812 | .Little => readIntSliceNative, | |
| 813 | .Big => readIntSliceForeign, | |
| 814 | 814 | }; |
| 815 | 815 | |
| 816 | 816 | pub const readIntSliceBig = switch (builtin.endian) { |
| 817 | builtin.Endian.Little => readIntSliceForeign, | |
| 818 | builtin.Endian.Big => readIntSliceNative, | |
| 817 | .Little => readIntSliceForeign, | |
| 818 | .Big => readIntSliceNative, | |
| 819 | 819 | }; |
| 820 | 820 | |
| 821 | 821 | /// Reads an integer from memory with bit count specified by T. |
| ... | ... | @@ -892,13 +892,13 @@ pub fn writeIntForeign(comptime T: type, buf: *[@divExact(T.bit_count, 8)]u8, va |
| 892 | 892 | } |
| 893 | 893 | |
| 894 | 894 | pub const writeIntLittle = switch (builtin.endian) { |
| 895 | builtin.Endian.Little => writeIntNative, | |
| 896 | builtin.Endian.Big => writeIntForeign, | |
| 895 | .Little => writeIntNative, | |
| 896 | .Big => writeIntForeign, | |
| 897 | 897 | }; |
| 898 | 898 | |
| 899 | 899 | pub const writeIntBig = switch (builtin.endian) { |
| 900 | builtin.Endian.Little => writeIntForeign, | |
| 901 | builtin.Endian.Big => writeIntNative, | |
| 900 | .Little => writeIntForeign, | |
| 901 | .Big => writeIntNative, | |
| 902 | 902 | }; |
| 903 | 903 | |
| 904 | 904 | /// Writes an integer to memory, storing it in twos-complement. |
| ... | ... | @@ -950,13 +950,13 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void { |
| 950 | 950 | } |
| 951 | 951 | |
| 952 | 952 | pub const writeIntSliceNative = switch (builtin.endian) { |
| 953 | builtin.Endian.Little => writeIntSliceLittle, | |
| 954 | builtin.Endian.Big => writeIntSliceBig, | |
| 953 | .Little => writeIntSliceLittle, | |
| 954 | .Big => writeIntSliceBig, | |
| 955 | 955 | }; |
| 956 | 956 | |
| 957 | 957 | pub const writeIntSliceForeign = switch (builtin.endian) { |
| 958 | builtin.Endian.Little => writeIntSliceBig, | |
| 959 | builtin.Endian.Big => writeIntSliceLittle, | |
| 958 | .Little => writeIntSliceBig, | |
| 959 | .Big => writeIntSliceLittle, | |
| 960 | 960 | }; |
| 961 | 961 | |
| 962 | 962 | /// Writes a twos-complement integer to memory, with the specified endianness. |
| ... | ... | @@ -967,10 +967,10 @@ pub const writeIntSliceForeign = switch (builtin.endian) { |
| 967 | 967 | /// use writeInt instead. |
| 968 | 968 | pub fn writeIntSlice(comptime T: type, buffer: []u8, value: T, endian: builtin.Endian) void { |
| 969 | 969 | comptime assert(T.bit_count % 8 == 0); |
| 970 | switch (endian) { | |
| 971 | builtin.Endian.Little => return writeIntSliceLittle(T, buffer, value), | |
| 972 | builtin.Endian.Big => return writeIntSliceBig(T, buffer, value), | |
| 973 | } | |
| 970 | return switch (endian) { | |
| 971 | .Little => writeIntSliceLittle(T, buffer, value), | |
| 972 | .Big => writeIntSliceBig(T, buffer, value), | |
| 973 | }; | |
| 974 | 974 | } |
| 975 | 975 | |
| 976 | 976 | test "writeIntBig and writeIntLittle" { |
| ... | ... | @@ -1506,54 +1506,54 @@ test "rotate" { |
| 1506 | 1506 | /// Converts a little-endian integer to host endianness. |
| 1507 | 1507 | pub fn littleToNative(comptime T: type, x: T) T { |
| 1508 | 1508 | return switch (builtin.endian) { |
| 1509 | builtin.Endian.Little => x, | |
| 1510 | builtin.Endian.Big => @byteSwap(T, x), | |
| 1509 | .Little => x, | |
| 1510 | .Big => @byteSwap(T, x), | |
| 1511 | 1511 | }; |
| 1512 | 1512 | } |
| 1513 | 1513 | |
| 1514 | 1514 | /// Converts a big-endian integer to host endianness. |
| 1515 | 1515 | pub fn bigToNative(comptime T: type, x: T) T { |
| 1516 | 1516 | return switch (builtin.endian) { |
| 1517 | builtin.Endian.Little => @byteSwap(T, x), | |
| 1518 | builtin.Endian.Big => x, | |
| 1517 | .Little => @byteSwap(T, x), | |
| 1518 | .Big => x, | |
| 1519 | 1519 | }; |
| 1520 | 1520 | } |
| 1521 | 1521 | |
| 1522 | 1522 | /// Converts an integer from specified endianness to host endianness. |
| 1523 | 1523 | pub fn toNative(comptime T: type, x: T, endianness_of_x: builtin.Endian) T { |
| 1524 | 1524 | return switch (endianness_of_x) { |
| 1525 | builtin.Endian.Little => littleToNative(T, x), | |
| 1526 | builtin.Endian.Big => bigToNative(T, x), | |
| 1525 | .Little => littleToNative(T, x), | |
| 1526 | .Big => bigToNative(T, x), | |
| 1527 | 1527 | }; |
| 1528 | 1528 | } |
| 1529 | 1529 | |
| 1530 | 1530 | /// Converts an integer which has host endianness to the desired endianness. |
| 1531 | 1531 | pub fn nativeTo(comptime T: type, x: T, desired_endianness: builtin.Endian) T { |
| 1532 | 1532 | return switch (desired_endianness) { |
| 1533 | builtin.Endian.Little => nativeToLittle(T, x), | |
| 1534 | builtin.Endian.Big => nativeToBig(T, x), | |
| 1533 | .Little => nativeToLittle(T, x), | |
| 1534 | .Big => nativeToBig(T, x), | |
| 1535 | 1535 | }; |
| 1536 | 1536 | } |
| 1537 | 1537 | |
| 1538 | 1538 | /// Converts an integer which has host endianness to little endian. |
| 1539 | 1539 | pub fn nativeToLittle(comptime T: type, x: T) T { |
| 1540 | 1540 | return switch (builtin.endian) { |
| 1541 | builtin.Endian.Little => x, | |
| 1542 | builtin.Endian.Big => @byteSwap(T, x), | |
| 1541 | .Little => x, | |
| 1542 | .Big => @byteSwap(T, x), | |
| 1543 | 1543 | }; |
| 1544 | 1544 | } |
| 1545 | 1545 | |
| 1546 | 1546 | /// Converts an integer which has host endianness to big endian. |
| 1547 | 1547 | pub fn nativeToBig(comptime T: type, x: T) T { |
| 1548 | 1548 | return switch (builtin.endian) { |
| 1549 | builtin.Endian.Little => @byteSwap(T, x), | |
| 1550 | builtin.Endian.Big => x, | |
| 1549 | .Little => @byteSwap(T, x), | |
| 1550 | .Big => x, | |
| 1551 | 1551 | }; |
| 1552 | 1552 | } |
| 1553 | 1553 | |
| 1554 | 1554 | fn AsBytesReturnType(comptime P: type) type { |
| 1555 | 1555 | if (comptime !trait.isSingleItemPtr(P)) |
| 1556 | @compileError("expected single item " ++ "pointer, passed " ++ @typeName(P)); | |
| 1556 | @compileError("expected single item pointer, passed " ++ @typeName(P)); | |
| 1557 | 1557 | |
| 1558 | 1558 | const size = @as(usize, @sizeOf(meta.Child(P))); |
| 1559 | 1559 | const alignment = comptime meta.alignment(P); |
| ... | ... | @@ -1578,8 +1578,8 @@ pub fn asBytes(ptr: var) AsBytesReturnType(@TypeOf(ptr)) { |
| 1578 | 1578 | test "asBytes" { |
| 1579 | 1579 | const deadbeef = @as(u32, 0xDEADBEEF); |
| 1580 | 1580 | const deadbeef_bytes = switch (builtin.endian) { |
| 1581 | builtin.Endian.Big => "\xDE\xAD\xBE\xEF", | |
| 1582 | builtin.Endian.Little => "\xEF\xBE\xAD\xDE", | |
| 1581 | .Big => "\xDE\xAD\xBE\xEF", | |
| 1582 | .Little => "\xEF\xBE\xAD\xDE", | |
| 1583 | 1583 | }; |
| 1584 | 1584 | |
| 1585 | 1585 | testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes)); |
| ... | ... | @@ -1617,21 +1617,21 @@ pub fn toBytes(value: var) [@sizeOf(@TypeOf(value))]u8 { |
| 1617 | 1617 | test "toBytes" { |
| 1618 | 1618 | var my_bytes = toBytes(@as(u32, 0x12345678)); |
| 1619 | 1619 | switch (builtin.endian) { |
| 1620 | builtin.Endian.Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")), | |
| 1621 | builtin.Endian.Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")), | |
| 1620 | .Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")), | |
| 1621 | .Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")), | |
| 1622 | 1622 | } |
| 1623 | 1623 | |
| 1624 | 1624 | my_bytes[0] = '\x99'; |
| 1625 | 1625 | switch (builtin.endian) { |
| 1626 | builtin.Endian.Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")), | |
| 1627 | builtin.Endian.Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")), | |
| 1626 | .Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")), | |
| 1627 | .Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")), | |
| 1628 | 1628 | } |
| 1629 | 1629 | } |
| 1630 | 1630 | |
| 1631 | 1631 | fn BytesAsValueReturnType(comptime T: type, comptime B: type) type { |
| 1632 | 1632 | const size = @as(usize, @sizeOf(T)); |
| 1633 | 1633 | |
| 1634 | if (comptime !trait.is(builtin.TypeId.Pointer)(B) or | |
| 1634 | if (comptime !trait.is(.Pointer)(B) or | |
| 1635 | 1635 | (meta.Child(B) != [size]u8 and meta.Child(B) != [size:0]u8)) |
| 1636 | 1636 | { |
| 1637 | 1637 | @compileError("expected *[N]u8 " ++ ", passed " ++ @typeName(B)); |
| ... | ... | @@ -1651,15 +1651,15 @@ pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @Typ |
| 1651 | 1651 | test "bytesAsValue" { |
| 1652 | 1652 | const deadbeef = @as(u32, 0xDEADBEEF); |
| 1653 | 1653 | const deadbeef_bytes = switch (builtin.endian) { |
| 1654 | builtin.Endian.Big => "\xDE\xAD\xBE\xEF", | |
| 1655 | builtin.Endian.Little => "\xEF\xBE\xAD\xDE", | |
| 1654 | .Big => "\xDE\xAD\xBE\xEF", | |
| 1655 | .Little => "\xEF\xBE\xAD\xDE", | |
| 1656 | 1656 | }; |
| 1657 | 1657 | |
| 1658 | 1658 | testing.expect(deadbeef == bytesAsValue(u32, deadbeef_bytes).*); |
| 1659 | 1659 | |
| 1660 | 1660 | var codeface_bytes: [4]u8 = switch (builtin.endian) { |
| 1661 | builtin.Endian.Big => "\xC0\xDE\xFA\xCE", | |
| 1662 | builtin.Endian.Little => "\xCE\xFA\xDE\xC0", | |
| 1661 | .Big => "\xC0\xDE\xFA\xCE", | |
| 1662 | .Little => "\xCE\xFA\xDE\xC0", | |
| 1663 | 1663 | }.*; |
| 1664 | 1664 | var codeface = bytesAsValue(u32, &codeface_bytes); |
| 1665 | 1665 | testing.expect(codeface.* == 0xC0DEFACE); |
| ... | ... | @@ -1692,8 +1692,8 @@ pub fn bytesToValue(comptime T: type, bytes: var) T { |
| 1692 | 1692 | } |
| 1693 | 1693 | test "bytesToValue" { |
| 1694 | 1694 | const deadbeef_bytes = switch (builtin.endian) { |
| 1695 | builtin.Endian.Big => "\xDE\xAD\xBE\xEF", | |
| 1696 | builtin.Endian.Little => "\xEF\xBE\xAD\xDE", | |
| 1695 | .Big => "\xDE\xAD\xBE\xEF", | |
| 1696 | .Little => "\xEF\xBE\xAD\xDE", | |
| 1697 | 1697 | }; |
| 1698 | 1698 | |
| 1699 | 1699 | const deadbeef = bytesToValue(u32, deadbeef_bytes); |
lib/std/special/compiler_rt/ashlti3.zig+1-1| ... | ... | @@ -24,7 +24,7 @@ const twords = extern union { |
| 24 | 24 | all: i128, |
| 25 | 25 | s: S, |
| 26 | 26 | |
| 27 | const S = if (builtin.endian == builtin.Endian.Little) | |
| 27 | const S = if (builtin.endian == .Little) | |
| 28 | 28 | struct { |
| 29 | 29 | low: u64, |
| 30 | 30 | high: u64, |
lib/std/special/compiler_rt/ashrti3.zig+1-1| ... | ... | @@ -25,7 +25,7 @@ const twords = extern union { |
| 25 | 25 | all: i128, |
| 26 | 26 | s: S, |
| 27 | 27 | |
| 28 | const S = if (builtin.endian == builtin.Endian.Little) | |
| 28 | const S = if (builtin.endian == .Little) | |
| 29 | 29 | struct { |
| 30 | 30 | low: i64, |
| 31 | 31 | high: i64, |
lib/std/special/compiler_rt/lshrti3.zig+1-1| ... | ... | @@ -24,7 +24,7 @@ const twords = extern union { |
| 24 | 24 | all: i128, |
| 25 | 25 | s: S, |
| 26 | 26 | |
| 27 | const S = if (builtin.endian == builtin.Endian.Little) | |
| 27 | const S = if (builtin.endian == .Little) | |
| 28 | 28 | struct { |
| 29 | 29 | low: u64, |
| 30 | 30 | high: u64, |
lib/std/special/compiler_rt/multi3.zig+1-1| ... | ... | @@ -45,7 +45,7 @@ const twords = extern union { |
| 45 | 45 | all: i128, |
| 46 | 46 | s: S, |
| 47 | 47 | |
| 48 | const S = if (builtin.endian == builtin.Endian.Little) | |
| 48 | const S = if (builtin.endian == .Little) | |
| 49 | 49 | struct { |
| 50 | 50 | low: u64, |
| 51 | 51 | high: u64, |
lib/std/special/compiler_rt/udivmod.zig+2-2| ... | ... | @@ -2,8 +2,8 @@ const builtin = @import("builtin"); |
| 2 | 2 | const is_test = builtin.is_test; |
| 3 | 3 | |
| 4 | 4 | const low = switch (builtin.endian) { |
| 5 | builtin.Endian.Big => 1, | |
| 6 | builtin.Endian.Little => 0, | |
| 5 | .Big => 1, | |
| 6 | .Little => 0, | |
| 7 | 7 | }; |
| 8 | 8 | const high = 1 - low; |
| 9 | 9 |
lib/std/testing.zig+1-5| ... | ... | @@ -63,15 +63,11 @@ pub fn expectEqual(expected: var, actual: @TypeOf(expected)) void { |
| 63 | 63 | |
| 64 | 64 | .Pointer => |pointer| { |
| 65 | 65 | switch (pointer.size) { |
| 66 | .One, | |
| 67 | .Many, | |
| 68 | .C, | |
| 69 | => { | |
| 66 | .One, .Many, .C => { | |
| 70 | 67 | if (actual != expected) { |
| 71 | 68 | std.debug.panic("expected {*}, found {*}", .{ expected, actual }); |
| 72 | 69 | } |
| 73 | 70 | }, |
| 74 | ||
| 75 | 71 | .Slice => { |
| 76 | 72 | if (actual.ptr != expected.ptr) { |
| 77 | 73 | std.debug.panic("expected slice ptr {}, found {}", .{ expected.ptr, actual.ptr }); |
lib/std/valgrind.zig+2-2| ... | ... | @@ -8,7 +8,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3: |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | switch (builtin.arch) { |
| 11 | builtin.Arch.i386 => { | |
| 11 | .i386 => { | |
| 12 | 12 | return asm volatile ( |
| 13 | 13 | \\ roll $3, %%edi ; roll $13, %%edi |
| 14 | 14 | \\ roll $29, %%edi ; roll $19, %%edi |
| ... | ... | @@ -19,7 +19,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3: |
| 19 | 19 | : "cc", "memory" |
| 20 | 20 | ); |
| 21 | 21 | }, |
| 22 | builtin.Arch.x86_64 => { | |
| 22 | .x86_64 => { | |
| 23 | 23 | return asm volatile ( |
| 24 | 24 | \\ rolq $3, %%rdi ; rolq $13, %%rdi |
| 25 | 25 | \\ rolq $61, %%rdi ; rolq $51, %%rdi |