blob 031f1d9e (13144B) - Raw
1 fn testBinary(comptime op: anytype) !void { 2 const testType = struct { 3 fn testType(comptime Type: type, comptime imm_lhs: Type, comptime imm_rhs: Type) !void { 4 const expected = op(Type, imm_lhs, imm_rhs); 5 try struct { 6 fn testOne(actual: @TypeOf(expected)) !void { 7 if (switch (@typeInfo(@TypeOf(expected))) { 8 else => actual != expected, 9 .vector => @reduce(.Or, actual != expected), 10 }) return error.Unexpected; 11 } 12 noinline fn testOps(mem_lhs: Type, mem_rhs: Type) !void { 13 var reg_lhs = mem_lhs; 14 var reg_rhs = mem_rhs; 15 _ = .{ ®_lhs, ®_rhs }; 16 try testOne(op(Type, reg_lhs, reg_rhs)); 17 try testOne(op(Type, reg_lhs, mem_rhs)); 18 try testOne(op(Type, reg_lhs, imm_rhs)); 19 try testOne(op(Type, mem_lhs, reg_rhs)); 20 try testOne(op(Type, mem_lhs, mem_rhs)); 21 try testOne(op(Type, mem_lhs, imm_rhs)); 22 try testOne(op(Type, imm_lhs, reg_rhs)); 23 try testOne(op(Type, imm_lhs, mem_rhs)); 24 } 25 }.testOps(imm_lhs, imm_rhs); 26 } 27 }.testType; 28 29 try testType(u8, 0xbb, 0x43); 30 try testType(u16, 0xb8bf, 0x626d); 31 try testType(u32, 0x80d7a2c6, 0xbff6a402); 32 try testType(u64, 0x71138bc6b4a38898, 0x1bc4043de9438c7b); 33 try testType(u128, 0xe05fc132ef2cd8affee00a907f0a851f, 0x29f912a72cfc6a7c6973426a9636da9a); 34 try testType( 35 u256, 36 0xb7935f5c2f3b1ae7a422c0a7c446884294b7d5370bada307d2fe5a4c4284a999, 37 0x310e6e196ba4f143b8d285ca6addf7f3bb3344224aff221b27607a31e148be08, 38 ); 39 try testType( 40 u512, 41 0xe5b1fedca3c77db765e517aabd05ffc524a3a8aff1784bbf67c45b894447ede32b65b9940e78173c591e56e078932d465f235aece7ad47b7f229df7ba8f12295, 42 0x8b4bb7c2969e3b121cc1082c442f8b4330f0a50058438fed56447175bb10178607ecfe425cb54dacc25ef26810f3e04681de1844f1aa8d029aca75d658634806, 43 ); 44 45 try testType(@Vector(1, u8), .{ 46 0x1f, 47 }, .{ 48 0x06, 49 }); 50 try testType(@Vector(2, u8), .{ 51 0x80, 0x63, 52 }, .{ 53 0xe4, 0x28, 54 }); 55 try testType(@Vector(4, u8), .{ 56 0x83, 0x9e, 0x1e, 0xc1, 57 }, .{ 58 0xf0, 0x5c, 0x46, 0x85, 59 }); 60 try testType(@Vector(8, u8), .{ 61 0x1e, 0x4d, 0x9d, 0x2a, 0x4c, 0x74, 0x0a, 0x83, 62 }, .{ 63 0x28, 0x60, 0xa9, 0xb5, 0xd9, 0xa6, 0xf1, 0xb6, 64 }); 65 try testType(@Vector(16, u8), .{ 66 0xea, 0x80, 0xbb, 0xe8, 0x74, 0x81, 0xc8, 0x66, 0x7b, 0x41, 0x90, 0xcb, 0x30, 0x70, 0x4b, 0x0f, 67 }, .{ 68 0x61, 0x26, 0xbe, 0x47, 0x00, 0x9c, 0x55, 0xa5, 0x59, 0xf0, 0xb2, 0x20, 0x30, 0xaf, 0x82, 0x3e, 69 }); 70 try testType(@Vector(32, u8), .{ 71 0xa1, 0x88, 0xc4, 0xf4, 0x77, 0x0b, 0xf5, 0xbb, 0x09, 0x03, 0xbf, 0xf5, 0xcc, 0x7f, 0x6b, 0x2a, 72 0x4c, 0x05, 0x37, 0xc9, 0x8a, 0xcb, 0x91, 0x23, 0x09, 0x5f, 0xb8, 0x99, 0x4a, 0x75, 0x26, 0xe4, 73 }, .{ 74 0xff, 0x0f, 0x99, 0x49, 0xa6, 0x25, 0xa7, 0xd4, 0xc9, 0x2f, 0x97, 0x6a, 0x01, 0xd6, 0x6e, 0x41, 75 0xa4, 0xb5, 0x3c, 0x03, 0xea, 0x82, 0x9c, 0x5f, 0xac, 0x07, 0x16, 0x15, 0x1c, 0x64, 0x25, 0x2f, 76 }); 77 try testType(@Vector(64, u8), .{ 78 0xaa, 0x08, 0xeb, 0xb2, 0xd7, 0x89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x74, 0xaa, 0x65, 0xfd, 0xc8, 0x2a, 0x8a, 0xdb, 0xae, 0x44, 0x28, 0x62, 0xa4, 105 0x56, 0x4f, 0xf1, 0xaa, 0x0a, 0x0f, 0xdb, 0x1b, 0xc8, 0x45, 0x9b, 0x12, 0xb4, 0x1a, 0xe4, 0xa3, 106 }); 107 108 try testType(@Vector(1, u16), .{ 109 0x9d6f, 110 }, .{ 111 0x44b1, 112 }); 113 try testType(@Vector(2, u16), .{ 114 0xa0fa, 0xc365, 115 }, .{ 116 0xe736, 0xc394, 117 }); 118 try testType(@Vector(4, u16), .{ 119 0x9608, 0xa558, 0x161b, 0x206f, 120 }, .{ 121 0x3088, 0xf25c, 0x7837, 0x9b3f, 122 }); 123 try testType(@Vector(8, u16), .{ 124 0xcf61, 0xb121, 0x3cf1, 0x3e9f, 0x43a7, 0x8d69, 0x96f5, 0xc11e, 125 }, .{ 126 0xee30, 0x82f0, 0x270b, 0x1498, 0x4c60, 0x6e72, 0x0b64, 0x02d4, 127 }); 128 try testType(@Vector(16, u16), .{ 129 0x9191, 0xd23e, 0xf844, 0xd84a, 0xe907, 0xf1e8, 0x712d, 0x90af, 130 0x6541, 0x3fa6, 0x92eb, 0xe35a, 0xc0c9, 0xcb47, 0xb790, 0x4453, 131 }, .{ 132 0x21c3, 0x4039, 0x9b71, 0x60bd, 0xcd7f, 0x2ec8, 0x50ba, 0xe810, 133 0xebd4, 0x06e5, 0xed18, 0x2f66, 0x7e31, 0xe282, 0xad63, 0xb25e, 134 }); 135 try testType(@Vector(32, u16), .{ 136 0x6b6a, 0x30a9, 0xc267, 0x2231, 0xbf4c, 0x00bc, 0x9c2c, 0x2928, 137 0xecad, 0x82df, 0xcfb0, 0xa4e5, 0x909b, 0x1b05, 0xaf40, 0x1fd9, 138 0xcec6, 0xd8dc, 0xd4b5, 0x6d59, 0x8e3f, 0x4d8a, 0xb83a, 0x808e, 139 0x47e2, 0x5782, 0x59bf, 0xcefc, 0x5179, 0x3f48, 0x93dc, 0x66d2, 140 }, .{ 141 0x1be8, 0xe98c, 0xf9b3, 0xb008, 0x2f8d, 0xf087, 0xc9b9, 0x75aa, 142 0xbd16, 0x9540, 0xc5bd, 0x2b2c, 0xd43f, 0x9394, 0x3e1d, 0xf695, 143 0x167d, 0xff7a, 0xf09d, 0xdff8, 0xdfa2, 0xc779, 0x70b7, 0x01bd, 144 0x46b3, 0x995a, 0xb7bc, 0xa79d, 0x5542, 0x961e, 0x37cd, 0x9c2a, 145 }); 146 try testType(@Vector(64, u16), .{ 147 0x6b87, 0xfd84, 0x436b, 0xe345, 0xfb82, 0x81fc, 0x0992, 0x45f9, 148 0x5527, 0x1f6d, 0xda46, 0x6a16, 0xf6e1, 0x8fb7, 0x3619, 0xdfe3, 149 0x64ce, 0x8ac6, 0x3ae8, 0x30e3, 0xec3b, 0x4ba7, 0x02a4, 0xa694, 150 0x8e68, 0x8f0c, 0x5e30, 0x0e55, 0x6538, 0x9852, 0xea35, 0x7be2, 151 0xdabd, 0x57e6, 0x5b38, 0x0fb2, 0x2604, 0x85e7, 0x6595, 0x8de9, 152 0x49b1, 0xe9a2, 0x3758, 0xa4d9, 0x505b, 0xc9d3, 0xddc5, 0x9a43, 153 0xfd44, 0x50f5, 0x379e, 0x03b6, 0x6375, 0x692f, 0x5586, 0xc717, 154 0x94dd, 0xee06, 0xb32d, 0x0bb9, 0x0e35, 0x5f8f, 0x0ba4, 0x19a8, 155 }, .{ 156 0xbeeb, 0x3e54, 0x6486, 0x5167, 0xe432, 0x57cf, 0x9cac, 0x922e, 157 0xd2f8, 0x5614, 0x2e7f, 0x19cf, 0x9a07, 0x0524, 0x168f, 0x4464, 158 0x4def, 0x83ce, 0x97b4, 0xf269, 0xda5f, 0x28c1, 0x9cc3, 0xfa7c, 159 0x25a0, 0x912d, 0x25b2, 0xd60d, 0xcd82, 0x0e03, 0x40cc, 0xc9dc, 160 0x18eb, 0xc609, 0xb06d, 0x29e0, 0xf3c7, 0x997b, 0x8ca2, 0xa750, 161 0xc9bc, 0x8f0e, 0x3916, 0xd905, 0x94f8, 0x397f, 0x98b5, 0xc61d, 162 0x05db, 0x3e7a, 0xf750, 0xe8de, 0x3225, 0x81d9, 0x612e, 0x0a7e, 163 0x2c02, 0xff5b, 0x19ca, 0xbbf5, 0x870e, 0xc9ca, 0x47bb, 0xcfcc, 164 }); 165 166 try testType(@Vector(1, u32), .{ 167 0x1d0d9cc4, 168 }, .{ 169 0xce2d0ab6, 170 }); 171 try testType(@Vector(2, u32), .{ 172 0x5ab78c03, 0xd21bb513, 173 }, .{ 174 0x8a6664eb, 0x79eac37d, 175 }); 176 try testType(@Vector(4, u32), .{ 177 0x234d576e, 0x4151cc9c, 0x39f558e4, 0xba935a32, 178 }, .{ 179 0x398f2a9d, 0x4540f093, 0x9225551c, 0x3bac865b, 180 }); 181 try testType(@Vector(8, u32), .{ 182 0xb8336635, 0x2fc3182c, 0x27a00123, 0x71587fbe, 183 0x9cbc65d2, 0x6f4bb0e6, 0x362594ce, 0x9971df38, 184 }, .{ 185 0x5727e734, 0x972b0313, 0xff25f5dc, 0x924f8e55, 186 0x04920a61, 0xa1c3b334, 0xf52df4b6, 0x5ef72ecc, 187 }); 188 try testType(@Vector(16, u32), .{ 189 0xfb566f9e, 0x9ad4691a, 0x5b5f9ec0, 0x5a572d2a, 190 0x8f2f226b, 0x2dfc7e33, 0x9fb07e32, 0x9d672a2e, 191 0xbedc3cee, 0x6872428d, 0xbc73a9fd, 0xd4d5f055, 192 0x69c1e9ee, 0x65038deb, 0x1449061a, 0x48412ec2, 193 }, .{ 194 0x96cbe946, 0x3f24f60b, 0xaeacdc53, 0x7611a8b4, 195 0x031a67a8, 0x52a26828, 0x75646f4b, 0xb75902c3, 196 0x1f881f08, 0x834e02a4, 0x5e5b40eb, 0xc75c264d, 197 0xa8251e09, 0x28e46bbd, 0x12cb1f31, 0x9a2af615, 198 }); 199 try testType(@Vector(32, u32), .{ 200 0x131bbb7b, 0xa7311026, 0x9d5e59a0, 0x99b090d6, 201 0xfe969e2e, 0x04547697, 0x357d3250, 0x43be6d7a, 202 0x16ecf5c5, 0xf60febcc, 0x1d1e2602, 0x138a96d2, 203 0x9117ba72, 0x9f185b32, 0xc10e23fd, 0x3e6b7fd8, 204 0x4dc9be70, 0x2ee30047, 0xaffeab60, 0x7172d362, 205 0x6154bfcf, 0x5388dc3e, 0xd6e5a76e, 0x8b782f2d, 206 0xacbef4a2, 0x843aca71, 0x25d8ab5c, 0xe1a63a39, 207 0xc26212e5, 0x0847b84b, 0xb53541e5, 0x0c8e44db, 208 }, .{ 209 0x4ad92822, 0x715b623f, 0xa5bed8a7, 0x937447a9, 210 0x7ecb38eb, 0x0a2f3dfc, 0x96f467a2, 0xec882793, 211 0x41a8707f, 0xf7310656, 0x76217b80, 0x2058e5fc, 212 0x26682154, 0x87313e31, 0x4bdc480a, 0x193572ff, 213 0x60b03c75, 0x0fe45908, 0x56c73703, 0xdb86554c, 214 0xdda2dd7d, 0x34371b27, 0xe4e6ad50, 0x422d1828, 215 0x1de3801b, 0xdce268d3, 0x20af9ec8, 0x188a591f, 216 0xf080e943, 0xc8718d14, 0x3f920382, 0x18d101b5, 217 }); 218 219 try testType(@Vector(1, u64), .{ 220 0x333f593bf9d08546, 221 }, .{ 222 0x6918bd767e730778, 223 }); 224 try testType(@Vector(2, u64), .{ 225 0x4cd89a317b03d430, 0x28998f61842f63a9, 226 }, .{ 227 0x6c34db64af0e217e, 0x57aa5d02cd45dceb, 228 }); 229 try testType(@Vector(4, u64), .{ 230 0x946cf7e7484691c9, 0xf4fc5be2a762fcbf, 231 0x71cc83bc25abaf14, 0xc69cef44c6f833a1, 232 }, .{ 233 0x9f90cbd6c3ce1d4e, 0x182f65295dff4e84, 234 0x4dfe62c59fed0040, 0x18402347c1db1999, 235 }); 236 try testType(@Vector(8, u64), .{ 237 0x92c6281333943e2c, 0xa97750504668efb5, 238 0x234be51057c0181f, 0xefbc1f407f3df4fb, 239 0x8da6cc7c39cebb94, 0xb408f7e56feee497, 240 0x2363f1f8821592ed, 0x01716e800c0619e1, 241 }, .{ 242 0xa617426684147e7e, 0x7542da7ebe093a7b, 243 0x3f21d99ac57606b7, 0x65cd36d697d22de4, 244 0xed23d6bdf176c844, 0x2d4573f100ff7b58, 245 0x4968f4d21b49f8ab, 0xf5d9a205d453e933, 246 }); 247 try testType(@Vector(16, u64), .{ 248 0x2f61a4ee66177b4a, 0xf13b286b279f6a93, 249 0x36b46beb63665318, 0x74294dbde0da98d2, 250 0x3aa872ba60b936eb, 0xe8f698b36e62600b, 251 0x9e8930c21a6a1a76, 0x876998b09b8eb03c, 252 0xa0244771a2ec0adb, 0xb4c72bff3d3ac1a2, 253 0xd70677210830eced, 0x6622abc1734dd72d, 254 0x157e2bb0d57d6596, 0x2aac8192fb7ef973, 255 0xc4a0ca92f34d7b13, 0x04300f8ad1845246, 256 }, .{ 257 0xeaf71dcf0eb76f5d, 0x0e84b1b63dc97139, 258 0x0f64cc38d23c94a1, 0x12775cf0816349b7, 259 0xfdcf13387ba48d54, 0xf8d3c672cacd8779, 260 0xe728c1f5eb56ab1e, 0x05931a34877f7a69, 261 0x1861a763c8dafd1f, 0x4ac97573ecd5739f, 262 0x3384414c9bf77b8c, 0x32c15bbd04a5ddc4, 263 0xbfd88aee1d82ed32, 0x20e91c15b701059a, 264 0xed533d18f8657f3f, 0x1ddd7cd7f6bab957, 265 }); 266 267 if (false) try testType(@Vector(1, u128), .{ 268 0x5f11e16b0ca3392f907a857881455d2e, 269 }, .{ 270 0xf9142d73b408fd6955922f9fc147f7d7, 271 }); 272 } 273 274 inline fn bitAnd(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs & rhs) { 275 return lhs & rhs; 276 } 277 test bitAnd { 278 try testBinary(bitAnd); 279 } 280 281 inline fn bitOr(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs | rhs) { 282 return lhs | rhs; 283 } 284 test bitOr { 285 try testBinary(bitOr); 286 } 287 288 inline fn bitXor(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs ^ rhs) { 289 return lhs ^ rhs; 290 } 291 test bitXor { 292 try testBinary(bitXor); 293 }