zig/lib/std/special/compiler_rt/bswapsi2_test.zig
Jan Philipp Hafer efdb94486b compiler_rt: add __bswapsi2, __bswapdi2 and __bswapti2
- each byte gets masked, shifted and combined
- use boring masks instead of comptime for readability
- tests: bit patterns with reverse operation, if applicable

See #1290
2021-12-11 01:43:37 -08:00

21 lines
838 B
Zig

const bswap = @import("bswap.zig");
const testing = @import("std").testing;
fn test__bswapsi2(a: u32, expected: u32) !void {
var result = bswap.__bswapsi2(a);
try testing.expectEqual(expected, result);
}
test "bswapsi2" {
try test__bswapsi2(0x01234567, 0x67452301); // 0..7
try test__bswapsi2(0x67452301, 0x01234567);
try test__bswapsi2(0x89abcdef, 0xefcdab89); // 8..f
try test__bswapsi2(0xefcdab89, 0x89abcdef);
try test__bswapsi2(0xdeadbeef, 0xefbeadde); // deadbeef
try test__bswapsi2(0xefbeadde, 0xdeadbeef);
try test__bswapsi2(0xdeadface, 0xcefaadde); // deadface
try test__bswapsi2(0xcefaadde, 0xdeadface);
try test__bswapsi2(0xaaaaaaaa, 0xaaaaaaaa); // uninitialized memory
try test__bswapsi2(0x00000000, 0x00000000); // 0s
try test__bswapsi2(0xffffffff, 0xffffffff); // fs
}