1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330
|
#include <stdint.h>
#include <stdio.h>
#include <math.h>
#include <emscripten.h>
typedef signed char i8x16 __attribute((vector_size(16)));
typedef short i16x8 __attribute((vector_size(16)));
typedef int i32x4 __attribute((vector_size(16)));
typedef long long i64x2 __attribute((vector_size(16)));
typedef unsigned char u8x16 __attribute((vector_size(16)));
typedef unsigned short u16x8 __attribute((vector_size(16)));
typedef unsigned int u32x4 __attribute((vector_size(16)));
typedef unsigned long long u64x2 __attribute((vector_size(16)));
typedef float f32x4 __attribute((vector_size(16)));
typedef double f64x2 __attribute((vector_size(16)));
typedef char i8x8 __attribute((vector_size(8)));
typedef unsigned char u8x8 __attribute((vector_size(8)));
typedef short i16x4 __attribute((vector_size(8)));
typedef unsigned short u16x4 __attribute((vector_size(8)));
typedef int i32x2 __attribute((vector_size(8)));
typedef unsigned int u32x2 __attribute((vector_size(8)));
#define TESTFN EMSCRIPTEN_KEEPALIVE __attribute__((noinline))
i8x16 TESTFN i8x16_load(i8x16 *ptr) {
return *ptr;
}
i8x16 TESTFN v8x16_load_splat(int8_t *ptr) {
return (i8x16){*ptr, *ptr, *ptr, *ptr, *ptr, *ptr, *ptr, *ptr,
*ptr, *ptr, *ptr, *ptr, *ptr, *ptr, *ptr, *ptr};
}
i16x8 TESTFN v16x8_load_splat(int16_t *ptr) {
return (i16x8){*ptr, *ptr, *ptr, *ptr, *ptr, *ptr, *ptr, *ptr};
}
i32x4 TESTFN v32x4_load_splat(int32_t *ptr) {
return (i32x4){*ptr, *ptr, *ptr, *ptr};
}
i64x2 TESTFN v64x2_load_splat(int64_t *ptr) {
return (i64x2){*ptr, *ptr};
}
i16x8 TESTFN i16x8_load8x8_s(i8x8 *ptr) {
return __builtin_convertvector(*ptr, i16x8);
}
i16x8 TESTFN i16x8_load8x8_u(i8x8 *ptr) {
return (i16x8)__builtin_convertvector(*(u8x8*)ptr, u16x8);
}
i32x4 TESTFN i32x4_load16x4_s(i16x4 *ptr) {
return __builtin_convertvector(*ptr, i32x4);
}
i32x4 TESTFN i32x4_load16x4_u(i16x4 *ptr) {
return (i32x4)__builtin_convertvector(*(u16x4*)ptr, u32x4);
}
i64x2 TESTFN i64x2_load32x2_s(i32x2 *ptr) {
return __builtin_convertvector(*ptr, i64x2);
}
i64x2 TESTFN i64x2_load32x2_u(i32x2 *ptr) {
return (i64x2) __builtin_convertvector(*(u32x2*)ptr, u64x2);
}
void TESTFN i8x16_store(i8x16 *ptr, i8x16 vec) {
*ptr = vec;
}
i32x4 TESTFN i32x4_const(void) {
return (i32x4) {1, 2, 3, 4};
}
i8x16 TESTFN i8x16_shuffle_interleave_bytes(i8x16 x, i8x16 y) {
return __builtin_shufflevector(x, y, 0, 17, 2, 19, 4, 21, 6, 23, 8, 25, 10, 27, 12, 29, 14, 31);
}
i32x4 TESTFN i32x4_shuffle_reverse(i32x4 vec) {
return __builtin_shufflevector(vec, vec, 3, 2, 1, 0);
}
i8x16 TESTFN v8x16_swizzle(i8x16 x, i8x16 y) {
return __builtin_wasm_swizzle_v8x16(x, y);
}
i8x16 TESTFN i8x16_splat(int32_t x) {
return (i8x16) {x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x};
}
int32_t TESTFN i8x16_extract_lane_s_first(i8x16 vec) {
return __builtin_wasm_extract_lane_s_i8x16(vec, 0);
}
int32_t TESTFN i8x16_extract_lane_s_last(i8x16 vec) {
return __builtin_wasm_extract_lane_s_i8x16(vec, 15);
}
uint32_t TESTFN i8x16_extract_lane_u_first(u8x16 vec) {
return __builtin_wasm_extract_lane_u_i8x16(vec, 0);
}
uint32_t TESTFN i8x16_extract_lane_u_last(u8x16 vec) {
return __builtin_wasm_extract_lane_u_i8x16(vec, 15);
}
i8x16 TESTFN i8x16_replace_lane_first(i8x16 vec, int32_t val) {
return (i8x16){__builtin_wasm_replace_lane_i8x16(vec, 0, val)};
}
i8x16 TESTFN i8x16_replace_lane_last(i8x16 vec, int32_t val) {
return (i8x16){__builtin_wasm_replace_lane_i8x16(vec, 15, val)};
}
i16x8 TESTFN i16x8_splat(int32_t x) {
return (i16x8) {x, x, x, x, x, x, x, x};
}
int32_t TESTFN i16x8_extract_lane_s_first(i16x8 vec) {
return __builtin_wasm_extract_lane_s_i16x8(vec, 0);
}
int32_t TESTFN i16x8_extract_lane_s_last(i16x8 vec) {
return __builtin_wasm_extract_lane_s_i16x8(vec, 7);
}
int32_t TESTFN i16x8_extract_lane_u_first(u16x8 vec) {
return __builtin_wasm_extract_lane_u_i16x8(vec, 0);
}
int32_t TESTFN i16x8_extract_lane_u_last(u16x8 vec) {
return __builtin_wasm_extract_lane_u_i16x8(vec, 7);
}
i16x8 TESTFN i16x8_replace_lane_first(i16x8 vec, int32_t val) {
return __builtin_wasm_replace_lane_i16x8(vec, 0, val);
}
i16x8 TESTFN i16x8_replace_lane_last(i16x8 vec, int32_t val) {
return __builtin_wasm_replace_lane_i16x8(vec, 7, val);
}
i32x4 TESTFN i32x4_splat(int32_t x) {
return (i32x4) {x, x, x, x};
}
int32_t TESTFN i32x4_extract_lane_first(i32x4 vec) {
return __builtin_wasm_extract_lane_i32x4(vec, 0);
}
int32_t TESTFN i32x4_extract_lane_last(i32x4 vec) {
return __builtin_wasm_extract_lane_i32x4(vec, 3);
}
i32x4 TESTFN i32x4_replace_lane_first(i32x4 vec, int32_t val) {
return __builtin_wasm_replace_lane_i32x4(vec, 0, val);
}
i32x4 TESTFN i32x4_replace_lane_last(i32x4 vec, int32_t val) {
return __builtin_wasm_replace_lane_i32x4(vec, 3, val);
}
i64x2 TESTFN i64x2_splat(int64_t x) {
return (i64x2) {x, x};
}
int64_t TESTFN i64x2_extract_lane_first(i64x2 vec) {
return __builtin_wasm_extract_lane_i64x2(vec, 0);
}
int64_t TESTFN i64x2_extract_lane_last(i64x2 vec) {
return __builtin_wasm_extract_lane_i64x2(vec, 1);
}
i64x2 TESTFN i64x2_replace_lane_first(i64x2 vec, int64_t val) {
return __builtin_wasm_replace_lane_i64x2(vec, 0, val);
}
i64x2 TESTFN i64x2_replace_lane_last(i64x2 vec, int64_t val) {
return __builtin_wasm_replace_lane_i64x2(vec, 1, val);
}
f32x4 TESTFN f32x4_splat(float x) {
return (f32x4) {x, x, x, x};
}
float TESTFN f32x4_extract_lane_first(f32x4 vec) {
return __builtin_wasm_extract_lane_f32x4(vec, 0);
}
float TESTFN f32x4_extract_lane_last(f32x4 vec) {
return __builtin_wasm_extract_lane_f32x4(vec, 3);
}
f32x4 TESTFN f32x4_replace_lane_first(f32x4 vec, float val) {
return __builtin_wasm_replace_lane_f32x4(vec, 0, val);
}
f32x4 TESTFN f32x4_replace_lane_last(f32x4 vec, float val) {
return __builtin_wasm_replace_lane_f32x4(vec, 3, val);
}
f64x2 TESTFN f64x2_splat(int64_t x) {
return (f64x2) {x, x};
}
double TESTFN f64x2_extract_lane_first(f64x2 vec) {
return __builtin_wasm_extract_lane_f64x2(vec, 0);
}
double TESTFN f64x2_extract_lane_last(f64x2 vec) {
return __builtin_wasm_extract_lane_f64x2(vec, 1);
}
f64x2 TESTFN f64x2_replace_lane_first(f64x2 vec, double val) {
return __builtin_wasm_replace_lane_f64x2(vec, 0, val);
}
f64x2 TESTFN f64x2_replace_lane_last(f64x2 vec, double val) {
return __builtin_wasm_replace_lane_f64x2(vec, 1, val);
}
i8x16 TESTFN i8x16_eq(i8x16 x, i8x16 y) {
return (i8x16)(x == y);
}
i8x16 TESTFN i8x16_ne(i8x16 x, i8x16 y) {
return (i8x16)(x != y);
}
i8x16 TESTFN i8x16_lt_s(i8x16 x, i8x16 y) {
return (i8x16)(x < y);
}
i8x16 TESTFN i8x16_lt_u(i8x16 x, i8x16 y) {
return (i8x16)((u8x16)x < (u8x16)y);
}
i8x16 TESTFN i8x16_gt_s(i8x16 x, i8x16 y) {
return (i8x16)(x > y);
}
i8x16 TESTFN i8x16_gt_u(i8x16 x, i8x16 y) {
return (i8x16)((u8x16)x > (u8x16)y);
}
i8x16 TESTFN i8x16_le_s(i8x16 x, i8x16 y) {
return (i8x16)(x <= y);
}
i8x16 TESTFN i8x16_le_u(i8x16 x, i8x16 y) {
return (i8x16)((u8x16)x <= (u8x16)y);
}
i8x16 TESTFN i8x16_ge_s(i8x16 x, i8x16 y) {
return (i8x16)(x >= y);
}
i8x16 TESTFN i8x16_ge_u(i8x16 x, i8x16 y) {
return (i8x16)((u8x16)x >= (u8x16)y);
}
i16x8 TESTFN i16x8_eq(i16x8 x, i16x8 y) {
return x == y;
}
i16x8 TESTFN i16x8_ne(i16x8 x, i16x8 y) {
return x != y;
}
i16x8 TESTFN i16x8_lt_s(i16x8 x, i16x8 y) {
return x < y;
}
i16x8 TESTFN i16x8_lt_u(i16x8 x, i16x8 y) {
return (u16x8)x < (u16x8)y;
}
i16x8 TESTFN i16x8_gt_s(i16x8 x, i16x8 y) {
return x > y;
}
i16x8 TESTFN i16x8_gt_u(i16x8 x, i16x8 y) {
return (u16x8)x > (u16x8)y;
}
i16x8 TESTFN i16x8_le_s(i16x8 x, i16x8 y) {
return x <= y;
}
i16x8 TESTFN i16x8_le_u(i16x8 x, i16x8 y) {
return (u16x8)x <= (u16x8)y;
}
i16x8 TESTFN i16x8_ge_s(i16x8 x, i16x8 y) {
return x >= y;
}
i16x8 TESTFN i16x8_ge_u(i16x8 x, i16x8 y) {
return (u16x8)x >= (u16x8)y;
}
i32x4 TESTFN i32x4_eq(i32x4 x, i32x4 y) {
return (i32x4)(x == y);
}
i32x4 TESTFN i32x4_ne(i32x4 x, i32x4 y) {
return (i32x4)(x != y);
}
i32x4 TESTFN i32x4_lt_s(i32x4 x, i32x4 y) {
return (i32x4)(x < y);
}
i32x4 TESTFN i32x4_lt_u(i32x4 x, i32x4 y) {
return (i32x4)((u32x4)x < (u32x4)y);
}
i32x4 TESTFN i32x4_gt_s(i32x4 x, i32x4 y) {
return (i32x4)(x > y);
}
i32x4 TESTFN i32x4_gt_u(i32x4 x, i32x4 y) {
return (i32x4)((u32x4)x > (u32x4)y);
}
i32x4 TESTFN i32x4_le_s(i32x4 x, i32x4 y) {
return (i32x4)(x <= y);
}
i32x4 TESTFN i32x4_le_u(i32x4 x, i32x4 y) {
return (i32x4)((u32x4)x <= (u32x4)y);
}
i32x4 TESTFN i32x4_ge_s(i32x4 x, i32x4 y) {
return (i32x4)(x >= y);
}
i32x4 TESTFN i32x4_ge_u(i32x4 x, i32x4 y) {
return (i32x4)((u32x4)x >= (u32x4)y);
}
i32x4 TESTFN f32x4_eq(f32x4 x, f32x4 y) {
return (i32x4)(x == y);
}
i32x4 TESTFN f32x4_ne(f32x4 x, f32x4 y) {
return (i32x4)(x != y);
}
i32x4 TESTFN f32x4_lt(f32x4 x, f32x4 y) {
return (i32x4)(x < y);
}
i32x4 TESTFN f32x4_gt(f32x4 x, f32x4 y) {
return (i32x4)(x > y);
}
i32x4 TESTFN f32x4_le(f32x4 x, f32x4 y) {
return (i32x4)(x <= y);
}
i32x4 TESTFN f32x4_ge(f32x4 x, f32x4 y) {
return (i32x4)(x >= y);
}
i64x2 TESTFN f64x2_eq(f64x2 x, f64x2 y) {
return (i64x2)(x == y);
}
i64x2 TESTFN f64x2_ne(f64x2 x, f64x2 y) {
return (i64x2)(x != y);
}
i64x2 TESTFN f64x2_lt(f64x2 x, f64x2 y) {
return (i64x2)(x < y);
}
i64x2 TESTFN f64x2_gt(f64x2 x, f64x2 y) {
return (i64x2)(x > y);
}
i64x2 TESTFN f64x2_le(f64x2 x, f64x2 y) {
return (i64x2)(x <= y);
}
i64x2 TESTFN f64x2_ge(f64x2 x, f64x2 y) {
return (i64x2)(x >= y);
}
i8x16 TESTFN i8x16_not(i8x16 vec) {
return ~vec;
}
i8x16 TESTFN i8x16_and(i8x16 x, i8x16 y) {
return x & y;
}
i8x16 TESTFN i8x16_or(i8x16 x, i8x16 y) {
return x | y;
}
i8x16 TESTFN i8x16_xor(i8x16 x, i8x16 y) {
return x ^ y;
}
i8x16 TESTFN i8x16_andnot(i8x16 x, i8x16 y) {
return x & ~y;
}
i8x16 TESTFN i8x16_bitselect(i8x16 x, i8x16 y, i8x16 cond) {
return (i8x16)__builtin_wasm_bitselect((i32x4)x, (i32x4)y, (i32x4)cond);
}
i8x16 TESTFN i8x16_abs(i8x16 vec) {
return (i8x16)__builtin_wasm_abs_i8x16(vec);
}
i8x16 TESTFN i8x16_neg(i8x16 vec) {
return -vec;
}
int32_t TESTFN i8x16_any_true(i8x16 vec) {
return __builtin_wasm_any_true_i8x16(vec);
}
int32_t TESTFN i8x16_all_true(i8x16 vec) {
return __builtin_wasm_all_true_i8x16(vec);
}
i8x16 TESTFN i8x16_shl(i8x16 vec, int32_t shift) {
return vec << shift;
}
i8x16 TESTFN i8x16_shr_s(i8x16 vec, int32_t shift) {
return vec >> shift;
}
i8x16 TESTFN i8x16_shr_u(i8x16 vec, int32_t shift) {
return (i8x16)((u8x16)vec >> shift);
}
i8x16 TESTFN i8x16_add(i8x16 x, i8x16 y) {
return x + y;
}
i8x16 TESTFN i8x16_add_saturate_s(i8x16 x, i8x16 y) {
return __builtin_wasm_add_saturate_s_i8x16(x, y);
}
u8x16 TESTFN i8x16_add_saturate_u(u8x16 x, u8x16 y) {
return __builtin_wasm_add_saturate_u_i8x16(x, y);
}
i8x16 TESTFN i8x16_sub(i8x16 x, i8x16 y) {
return x - y;
}
i8x16 TESTFN i8x16_sub_saturate_s(i8x16 x, i8x16 y) {
return __builtin_wasm_sub_saturate_s_i8x16(x, y);
}
u8x16 TESTFN i8x16_sub_saturate_u(u8x16 x, u8x16 y) {
return __builtin_wasm_sub_saturate_u_i8x16(x, y);
}
// TODO: min_s / min_u / max_s / max_u
u8x16 TESTFN i8x16_avgr_u(u8x16 x, u8x16 y) {
return __builtin_wasm_avgr_u_i8x16(x, y);
}
i16x8 TESTFN i16x8_abs(i16x8 vec) {
return (i16x8)__builtin_wasm_abs_i16x8(vec);
}
i16x8 TESTFN i16x8_neg(i16x8 vec) {
return -vec;
}
int32_t TESTFN i16x8_any_true(i16x8 vec) {
return __builtin_wasm_any_true_i16x8(vec);
}
int32_t TESTFN i16x8_all_true(i16x8 vec) {
return __builtin_wasm_all_true_i16x8(vec);
}
i16x8 TESTFN i16x8_shl(i16x8 vec, int32_t shift) {
return vec << shift;
}
i16x8 TESTFN i16x8_shr_s(i16x8 vec, int32_t shift) {
return vec >> shift;
}
i16x8 TESTFN i16x8_shr_u(i16x8 vec, int32_t shift) {
return (i16x8)((u16x8)vec >> shift);
}
i16x8 TESTFN i16x8_add(i16x8 x, i16x8 y) {
return x + y;
}
i16x8 TESTFN i16x8_add_saturate_s(i16x8 x, i16x8 y) {
return __builtin_wasm_add_saturate_s_i16x8(x, y);
}
u16x8 TESTFN i16x8_add_saturate_u(u16x8 x, u16x8 y) {
return __builtin_wasm_add_saturate_u_i16x8(x, y);
}
i16x8 TESTFN i16x8_sub(i16x8 x, i16x8 y) {
return x - y;
}
i16x8 TESTFN i16x8_sub_saturate_s(i16x8 x, i16x8 y) {
return __builtin_wasm_sub_saturate_s_i16x8(x, y);
}
u16x8 TESTFN i16x8_sub_saturate_u(u16x8 x, u16x8 y) {
return __builtin_wasm_sub_saturate_u_i16x8(x, y);
}
i16x8 TESTFN i16x8_mul(i16x8 x, i16x8 y) {
return x * y;
}
// TODO: min_s / min_u / max_s / max_u
u16x8 TESTFN i16x8_avgr_u(u16x8 x, u16x8 y) {
return __builtin_wasm_avgr_u_i16x8(x, y);
}
i32x4 TESTFN i32x4_abs(i32x4 vec) {
return (i32x4)__builtin_wasm_abs_i32x4(vec);
}
i32x4 TESTFN i32x4_neg(i32x4 vec) {
return -vec;
}
int32_t TESTFN i32x4_any_true(i32x4 vec) {
return __builtin_wasm_any_true_i32x4(vec);
}
int32_t TESTFN i32x4_all_true(i32x4 vec) {
return __builtin_wasm_all_true_i32x4(vec);
}
i32x4 TESTFN i32x4_shl(i32x4 vec, int32_t shift) {
return vec << shift;
}
i32x4 TESTFN i32x4_shr_s(i32x4 vec, int32_t shift) {
return vec >> shift;
}
i32x4 TESTFN i32x4_shr_u(i32x4 vec, int32_t shift) {
return (i32x4)((u32x4)vec >> shift);
}
i32x4 TESTFN i32x4_add(i32x4 x, i32x4 y) {
return x + y;
}
i32x4 TESTFN i32x4_sub(i32x4 x, i32x4 y) {
return x - y;
}
i32x4 TESTFN i32x4_mul(i32x4 x, i32x4 y) {
return x * y;
}
// TODO: min_s / min_u / max_s / max_u
i64x2 TESTFN i64x2_neg(i64x2 vec) {
return -vec;
}
i64x2 TESTFN i64x2_shl(i64x2 vec, int32_t shift) {
return vec << shift;
}
i64x2 TESTFN i64x2_shr_s(i64x2 vec, int32_t shift) {
return vec >> shift;
}
i64x2 TESTFN i64x2_shr_u(i64x2 vec, int32_t shift) {
return (i64x2)((u64x2)vec >> shift);
}
i64x2 TESTFN i64x2_add(i64x2 x, i64x2 y) {
return x + y;
}
i64x2 TESTFN i64x2_sub(i64x2 x, i64x2 y) {
return x - y;
}
f32x4 TESTFN f32x4_abs(f32x4 vec) {
return __builtin_wasm_abs_f32x4(vec);
}
f32x4 TESTFN f32x4_neg(f32x4 vec) {
return -vec;
}
f32x4 TESTFN f32x4_sqrt(f32x4 vec) {
return __builtin_wasm_sqrt_f32x4(vec);
}
#ifdef __wasm_unimplemented_simd128__
f32x4 TESTFN f32x4_qfma(f32x4 a, f32x4 b, f32x4 c) {
return __builtin_wasm_qfma_f32x4(a, b, c);
}
f32x4 TESTFN f32x4_qfms(f32x4 a, f32x4 b, f32x4 c) {
return __builtin_wasm_qfms_f32x4(a, b, c);
}
#endif // __wasm_unimplemented_simd128__
f32x4 TESTFN f32x4_add(f32x4 x, f32x4 y) {
return x + y;
}
f32x4 TESTFN f32x4_sub(f32x4 x, f32x4 y) {
return x - y;
}
f32x4 TESTFN f32x4_mul(f32x4 x, f32x4 y) {
return x * y;
}
f32x4 TESTFN f32x4_div(f32x4 x, f32x4 y) {
return x / y;
}
f32x4 TESTFN f32x4_min(f32x4 x, f32x4 y) {
return __builtin_wasm_min_f32x4(x, y);
}
f32x4 TESTFN f32x4_max(f32x4 x, f32x4 y) {
return __builtin_wasm_max_f32x4(x, y);
}
f64x2 TESTFN f64x2_abs(f64x2 vec) {
return __builtin_wasm_abs_f64x2(vec);
}
f64x2 TESTFN f64x2_neg(f64x2 vec) {
return -vec;
}
f64x2 TESTFN f64x2_sqrt(f64x2 vec) {
return __builtin_wasm_sqrt_f64x2(vec);
}
#ifdef __wasm_unimplemented_simd128__
f64x2 TESTFN f64x2_qfma(f64x2 a, f64x2 b, f64x2 c) {
return __builtin_wasm_qfma_f64x2(a, b, c);
}
f64x2 TESTFN f64x2_qfms(f64x2 a, f64x2 b, f64x2 c) {
return __builtin_wasm_qfms_f64x2(a, b, c);
}
#endif // __wasm_unimplemented_simd128__
f64x2 TESTFN f64x2_add(f64x2 x, f64x2 y) {
return x + y;
}
f64x2 TESTFN f64x2_sub(f64x2 x, f64x2 y) {
return x - y;
}
f64x2 TESTFN f64x2_mul(f64x2 x, f64x2 y) {
return x * y;
}
f64x2 TESTFN f64x2_div(f64x2 x, f64x2 y) {
return x / y;
}
f64x2 TESTFN f64x2_min(f64x2 x, f64x2 y) {
return __builtin_wasm_min_f64x2(x, y);
}
f64x2 TESTFN f64x2_max(f64x2 x, f64x2 y) {
return __builtin_wasm_max_f64x2(x, y);
}
i32x4 TESTFN i32x4_trunc_s_f32x4_sat(f32x4 vec) {
return __builtin_wasm_trunc_saturate_s_i32x4_f32x4(vec);
}
i32x4 TESTFN i32x4_trunc_u_f32x4_sat(f32x4 vec) {
return __builtin_wasm_trunc_saturate_u_i32x4_f32x4(vec);
}
f32x4 TESTFN f32x4_convert_s_i32x4(i32x4 vec) {
return __builtin_convertvector(vec, f32x4);
}
f32x4 TESTFN f32x4_convert_u_i32x4(i32x4 vec) {
return __builtin_convertvector((u32x4)vec, f32x4);
}
i8x16 TESTFN i8x16_narrow_i16x8_s(i16x8 a, i16x8 b) {
return __builtin_wasm_narrow_s_i8x16_i16x8(a, b);
}
u8x16 TESTFN i8x16_narrow_i16x8_u(u16x8 a, u16x8 b) {
return __builtin_wasm_narrow_u_i8x16_i16x8(a, b);
}
i16x8 TESTFN i16x8_narrow_i32x4_s(i32x4 a, i32x4 b) {
return __builtin_wasm_narrow_s_i16x8_i32x4(a, b);
}
u16x8 TESTFN i16x8_narrow_i32x4_u(u32x4 a, u32x4 b) {
return __builtin_wasm_narrow_u_i16x8_i32x4(a, b);
}
static int failures = 0;
#define formatter(x) _Generic((x), \
signed char: "%d", \
unsigned char: "%d", \
short: "%d", \
unsigned short: "%d", \
int32_t: "%d", \
uint32_t: "%d", \
int64_t: "%ld", \
float: "%f", \
double: "%f" \
)
#define err(x) fprintf(stderr, formatter(x), x)
#define eq(a, b) ({ \
bool anan = _Generic((a), \
float: isnan(a), \
double: isnan(a), \
default: false); \
bool bnan = _Generic((b), \
float: isnan(b), \
double: isnan(b), \
default: false); \
((anan && bnan) || (!anan && a == b)); \
})
#define expect_eq(_a, _b) ({ \
__typeof__(_a) a = (_a), b = (_b); \
if (!eq(a, b)) { \
failures++; \
fprintf(stderr, "line %d: expected ", __LINE__); \
err(b); \
fprintf(stderr, ", got "); \
err(a); \
fprintf(stderr, "\n"); \
} \
})
#define expect_vec(_a, _b) ({ \
__typeof__(_a) a = (_a), b = (_b); \
bool err = false; \
size_t lanes = _Generic((a), \
u8x16: 16, \
i8x16: 16, \
i16x8: 8, \
u16x8: 8, \
i32x4: 4, \
i64x2: 2, \
f32x4: 4, \
f64x2: 2); \
for (size_t i = 0; i < lanes; i++) { \
if (!eq(a[i], b[i])) { \
err = true; \
break; \
} \
} \
if (err) { \
failures++; \
fprintf(stderr, "line %d: expected {", __LINE__); \
for (size_t i = 0; i < lanes - 1; i++) { \
err(b[i]); \
fprintf(stderr, ", "); \
} \
err(b[lanes - 1]); \
fprintf(stderr, "}, got {"); \
for (size_t i = 0; i < lanes - 1; i++) { \
err(a[i]); \
fprintf(stderr, ", "); \
} \
err(a[lanes - 1]); \
fprintf(stderr, "}\n"); \
} \
})
int EMSCRIPTEN_KEEPALIVE __attribute__((__optnone__)) main(int argc, char** argv) {
{
i8x16 vec = {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3};
expect_vec(i8x16_load(&vec),
((i8x16){3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}));
i8x16_store(&vec, (i8x16){7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7});
expect_vec(i8x16_load(&vec),
((i8x16){7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7}));
}
{
i8x8 vec = {0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0};
expect_vec(
v8x16_load_splat((int8_t*)&vec),
((i8x16){0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80})
);
expect_vec(
v16x8_load_splat((int16_t*)&vec),
((i16x8){0x9080, 0x9080, 0x9080, 0x9080, 0x9080, 0x9080, 0x9080, 0x9080})
);
expect_vec(v32x4_load_splat((int32_t*)&vec), ((i32x4){0xb0a09080, 0xb0a09080, 0xb0a09080, 0xb0a09080}));
expect_vec(v64x2_load_splat((int64_t*)&vec), ((i64x2){0xf0e0d0c0b0a09080, 0xf0e0d0c0b0a09080}));
// expect_vec(
// i16x8_load8x8_s(&vec),
// ((i16x8){0xff80, 0xff90, 0xffa0, 0xffb0, 0xffc0, 0xffd0, 0xffe0, 0xfff0})
// );
// expect_vec(
// i16x8_load8x8_u(&vec),
// ((i16x8){0x0080, 0x0090, 0x00a0, 0x00b0, 0x00c0, 0x00d0, 0x00e0, 0x00f0})
// );
// expect_vec(
// i32x4_load16x4_s((i16x4*)&vec),
// ((i32x4){0xffff9080, 0xffffb0a0, 0xffffd0c0, 0xfffff0e0})
// );
// expect_vec(
// i32x4_load16x4_u((i16x4*)&vec),
// ((i32x4){0x00009080, 0x0000b0a0, 0x0000d0c0, 0x0000f0e0})
// );
// expect_vec(
// i64x2_load32x2_s((i32x2*)&vec),
// ((i64x2){0xffffffffb0a09080, 0xfffffffff0e0d0c0})
// );
// expect_vec(
// i64x2_load32x2_u((i32x2*)&vec),
// ((i64x2){0x00000000b0a09080, 0x00000000f0e0d0c0})
// );
}
expect_vec(i32x4_const(), ((i32x4){1, 2, 3, 4}));
expect_vec(
i8x16_shuffle_interleave_bytes(
(i8x16){1, 0, 3, 0, 5, 0, 7, 0, 9, 0, 11, 0, 13, 0, 15, 0},
(i8x16){0, 2, 0, 4, 0, 6, 0, 8, 0, 10, 0, 12, 0, 14, 0, 16}
),
((i8x16){1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})
);
expect_vec(i32x4_shuffle_reverse((i32x4){1, 2, 3, 4}), ((i32x4){4, 3, 2, 1}));
expect_vec(
v8x16_swizzle(
(i8x16){0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff},
(i8x16){0, 4, 8, 12, 16, 255, 129, 128, 127, 17, 15, 13, 12, 8, 4, 0}
),
((i8x16){0xf0, 0xf4, 0xf8, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0xfd, 0xfc, 0xf8, 0xf4, 0xf0})
);
// i8x16 lane accesses
expect_vec(i8x16_splat(5), ((i8x16){5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}));
expect_vec(i8x16_splat(257), ((i8x16){1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}));
expect_eq(i8x16_extract_lane_s_first((i8x16){-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}), -1);
expect_eq(i8x16_extract_lane_s_last((i8x16){0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}), -1);
expect_eq(i8x16_extract_lane_u_first((u8x16){-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}), 255);
expect_eq(i8x16_extract_lane_u_last((u8x16){0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}), 255);
expect_vec(
i8x16_replace_lane_first((i8x16){0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 7),
((i8x16){7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})
);
expect_vec(
i8x16_replace_lane_last((i8x16){0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 7),
((i8x16){0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7})
);
// i16x8 lane accesses
expect_vec(i16x8_splat(5), ((i16x8){5, 5, 5, 5, 5, 5, 5, 5}));
expect_vec(i16x8_splat(65537), ((i16x8){1, 1, 1, 1, 1, 1, 1, 1}));
expect_eq(i16x8_extract_lane_s_first((i16x8){-1, 0, 0, 0, 0, 0, 0, 0}), -1);
expect_eq(i16x8_extract_lane_s_last((i16x8){0, 0, 0, 0, 0, 0, 0, -1}), -1);
expect_eq(i16x8_extract_lane_u_first((u16x8){-1, 0, 0, 0, 0, 0, 0, 0}), 65535);
expect_eq(i16x8_extract_lane_u_last((u16x8){0, 0, 0, 0, 0, 0, 0, -1}), 65535);
expect_vec(i16x8_replace_lane_first((i16x8){0, 0, 0, 0, 0, 0, 0, 0}, 7), ((i16x8){7, 0, 0, 0, 0, 0, 0, 0}));
expect_vec(i16x8_replace_lane_last((i16x8){0, 0, 0, 0, 0, 0, 0, 0}, 7), ((i16x8){0, 0, 0, 0, 0, 0, 0, 7}));
// i32x4 lane accesses
expect_vec(i32x4_splat(-5), ((i32x4){-5, -5, -5, -5}));
expect_eq(i32x4_extract_lane_first((i32x4){-5, 0, 0, 0}), -5);
expect_eq(i32x4_extract_lane_last((i32x4){0, 0, 0, -5}), -5);
expect_vec(i32x4_replace_lane_first((i32x4){0, 0, 0, 0}, 53), ((i32x4){53, 0, 0, 0}));
expect_vec(i32x4_replace_lane_last((i32x4){0, 0, 0, 0}, 53), ((i32x4){0, 0, 0, 53}));
// i64x2 lane accesses
expect_vec(i64x2_splat(-5), ((i64x2){-5, -5}));
expect_eq(i64x2_extract_lane_first((i64x2){-5, 0}), -5);
expect_eq(i64x2_extract_lane_last((i64x2){0, -5}), -5);
expect_vec(i64x2_replace_lane_first((i64x2){0, 0}, 53), ((i64x2){53, 0}));
expect_vec(i64x2_replace_lane_last((i64x2){0, 0}, 53), ((i64x2){0, 53}));
// f32x4 lane accesses
expect_vec(f32x4_splat(-5), ((f32x4){-5, -5, -5, -5}));
expect_eq(f32x4_extract_lane_first((f32x4){-5, 0, 0, 0}), -5);
expect_eq(f32x4_extract_lane_last((f32x4){0, 0, 0, -5}), -5);
expect_vec(f32x4_replace_lane_first((f32x4){0, 0, 0, 0}, 53), ((f32x4){53, 0, 0, 0}));
expect_vec(f32x4_replace_lane_last((f32x4){0, 0, 0, 0}, 53), ((f32x4){0, 0, 0, 53}));
// f64x2 lane accesses
expect_vec(f64x2_splat(-5), ((f64x2){-5, -5}));
expect_eq(f64x2_extract_lane_first((f64x2){-5, 0}), -5);
expect_eq(f64x2_extract_lane_last((f64x2){0, -5}), -5);
expect_vec(f64x2_replace_lane_first((f64x2){0, 0}, 53), ((f64x2){53, 0}));
expect_vec(f64x2_replace_lane_last((f64x2){0, 0}, 53), ((f64x2){0, 53}));
// i8x16 comparisons
expect_vec(
i8x16_eq(
(i8x16){0, 127, 13, 128, 1, 13, 129, 42, 0, 127, 255, 42, 1, 13, 129, 42},
(i8x16){0, 255, 13, 42, 129, 127, 0, 128, 0, 255, 13, 42, 129, 127, 0, 128}
),
((i8x16){-1, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, -1, 0, 0, 0, 0})
);
expect_vec(
i8x16_ne(
(i8x16){0, 127, 13, 128, 1, 13, 129, 42, 0, 127, 255, 42, 1, 13, 129, 42},
(i8x16){0, 255, 13, 42, 129, 127, 0, 128, 0, 255, 13, 42, 129, 127, 0, 128}
),
((i8x16){0, -1, 0, -1, -1, -1, -1, -1, 0, -1, -1, 0, -1, -1, -1, -1})
);
expect_vec(
i8x16_lt_s(
(i8x16){0, 127, 13, 128, 1, 13, 129, 42, 0, 127, 255, 42, 1, 13, 129, 42},
(i8x16){0, 255, 13, 42, 129, 127, 0, 128, 0, 255, 13, 42, 129, 127, 0, 128}
),
((i8x16){0, 0, 0, -1, 0, -1, -1, 0, 0, 0, -1, 0, 0, -1, -1, 0})
);
expect_vec(
i8x16_lt_u(
(i8x16){0, 127, 13, 128, 1, 13, 129, 42, 0, 127, 255, 42, 1, 13, 129, 42},
(i8x16){0, 255, 13, 42, 129, 127, 0, 128, 0, 255, 13, 42, 129, 127, 0, 128}
),
((i8x16){0, -1, 0, 0, -1, -1, 0, -1, 0, -1, 0, 0, -1, -1, 0, -1})
);
expect_vec(
i8x16_gt_s(
(i8x16){0, 127, 13, 128, 1, 13, 129, 42, 0, 127, 255, 42, 1, 13, 129, 42},
(i8x16){0, 255, 13, 42, 129, 127, 0, 128, 0, 255, 13, 42, 129, 127, 0, 128}
),
((i8x16){0, -1, 0, 0, -1, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, -1})
);
expect_vec(
i8x16_gt_u(
(i8x16){0, 127, 13, 128, 1, 13, 129, 42, 0, 127, 255, 42, 1, 13, 129, 42},
(i8x16){0, 255, 13, 42, 129, 127, 0, 128, 0, 255, 13, 42, 129, 127, 0, 128}
),
((i8x16){0, 0, 0, -1, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0})
);
expect_vec(
i8x16_le_s(
(i8x16){0, 127, 13, 128, 1, 13, 129, 42, 0, 127, 255, 42, 1, 13, 129, 42},
(i8x16){0, 255, 13, 42, 129, 127, 0, 128, 0, 255, 13, 42, 129, 127, 0, 128}
),
((i8x16){-1, 0, -1, -1, 0, -1, -1, 0, -1, 0, -1, -1, 0, -1, -1, 0})
);
expect_vec(
i8x16_le_u(
(i8x16){0, 127, 13, 128, 1, 13, 129, 42, 0, 127, 255, 42, 1, 13, 129, 42},
(i8x16){0, 255, 13, 42, 129, 127, 0, 128, 0, 255, 13, 42, 129, 127, 0, 128}
),
((i8x16){-1, -1, -1, 0, -1, -1, 0, -1, -1, -1, 0, -1, -1, -1, 0, -1})
);
expect_vec(
i8x16_ge_s(
(i8x16){0, 127, 13, 128, 1, 13, 129, 42, 0, 127, 255, 42, 1, 13, 129, 42},
(i8x16){0, 255, 13, 42, 129, 127, 0, 128, 0, 255, 13, 42, 129, 127, 0, 128}
),
((i8x16){-1, -1, -1, 0, -1, 0, 0, -1, -1, -1, 0, -1, -1, 0, 0, -1})
);
expect_vec(
i8x16_ge_u(
(i8x16){0, 127, 13, 128, 1, 13, 129, 42, 0, 127, 255, 42, 1, 13, 129, 42},
(i8x16){0, 255, 13, 42, 129, 127, 0, 128, 0, 255, 13, 42, 129, 127, 0, 128}
),
((i8x16){-1, 0, -1, -1, 0, 0, -1, 0, -1, 0, -1, -1, 0, 0, -1, 0})
);
// i16x8 comparisons
expect_vec(
i16x8_eq(
(i16x8){0, 32767, 13, -32768, 1, -32767, 42, -25536},
(i16x8){0, 13, 1, 32767, -32767, 42, -25536, 32767}
),
((i16x8){-1, 0, 0, 0, 0, 0, 0, 0})
);
expect_vec(
i16x8_ne(
(i16x8){0, 32767, 13, -32768, 1, -32767, 42, -25536},
(i16x8){0, 13, 1, 32767, -32767, 42, -25536, 32767}
),
((i16x8){0, -1, -1, -1, -1, -1, -1, -1})
);
expect_vec(
i16x8_lt_s(
(i16x8){0, 32767, 13, -32768, 1, -32767, 42, -25536},
(i16x8){0, 13, 1, 32767, -32767, 42, -25536, 32767}
),
((i16x8){0, 0, 0, -1, 0, -1, 0, -1})
);
expect_vec(
i16x8_lt_u(
(i16x8){0, 32767, 13, -32768, 1, -32767, 42, -25536},
(i16x8){0, 13, 1, 32767, -32767, 42, -25536, 32767}
),
((i16x8){0, 0, 0, 0, -1, 0, -1, 0})
);
expect_vec(
i16x8_gt_s(
(i16x8){0, 32767, 13, -32768, 1, -32767, 42, -25536},
(i16x8){0, 13, 1, 32767, -32767, 42, -25536, 32767}
),
((i16x8){0, -1, -1, 0, -1, 0, -1, 0})
);
expect_vec(
i16x8_gt_u(
(i16x8){0, 32767, 13, -32768, 1, -32767, 42, -25536},
(i16x8){0, 13, 1, 32767, -32767, 42, -25536, 32767}
),
((i16x8){0, -1, -1, -1, 0, -1, 0, -1})
);
expect_vec(
i16x8_le_s(
(i16x8){0, 32767, 13, -32768, 1, -32767, 42, -25536},
(i16x8){0, 13, 1, 32767, -32767, 42, -25536, 32767}
),
((i16x8){-1, 0, 0, -1, 0, -1, 0, -1})
);
expect_vec(
i16x8_le_u(
(i16x8){0, 32767, 13, -32768, 1, -32767, 42, -25536},
(i16x8){0, 13, 1, 32767, -32767, 42, -25536, 32767}
),
((i16x8){-1, 0, 0, 0, -1, 0, -1, 0})
);
expect_vec(
i16x8_ge_s(
(i16x8){0, 32767, 13, -32768, 1, -32767, 42, -25536},
(i16x8){0, 13, 1, 32767, -32767, 42, -25536, 32767}
),
((i16x8){-1, -1, -1, 0, -1, 0, -1, 0})
);
expect_vec(
i16x8_ge_u(
(i16x8){0, 32767, 13, -32768, 1, -32767, 42, -25536},
(i16x8){0, 13, 1, 32767, -32767, 42, -25536, 32767}
),
((i16x8){-1, -1, -1, -1, 0, -1, 0, -1})
);
// i342x4 comparisons
expect_vec(
i32x4_eq((i32x4){0, -1, 53, -7}, (i32x4){0, 53, -7, -1}), ((i32x4){-1, 0, 0, 0})
);
expect_vec(
i32x4_ne((i32x4){0, -1, 53, -7}, (i32x4){0, 53, -7, -1}), ((i32x4){0, -1, -1, -1})
);
expect_vec(
i32x4_lt_s((i32x4){0, -1, 53, -7}, (i32x4){0, 53, -7, -1}), ((i32x4){0, -1, 0, -1})
);
expect_vec(
i32x4_lt_u((i32x4){0, -1, 53, -7}, (i32x4){0, 53, -7, -1}), ((i32x4){0, 0, -1, -1})
);
expect_vec(
i32x4_gt_s((i32x4){0, -1, 53, -7}, (i32x4){0, 53, -7, -1}), ((i32x4){0, 0, -1, 0})
);
expect_vec(
i32x4_gt_u((i32x4){0, -1, 53, -7}, (i32x4){0, 53, -7, -1}), ((i32x4){0, -1, 0, 0})
);
expect_vec(
i32x4_le_s((i32x4){0, -1, 53, -7}, (i32x4){0, 53, -7, -1}), ((i32x4){-1, -1, 0, -1})
);
expect_vec(
i32x4_le_u((i32x4){0, -1, 53, -7}, (i32x4){0, 53, -7, -1}), ((i32x4){-1, 0, -1, -1})
);
expect_vec(
i32x4_ge_s((i32x4){0, -1, 53, -7}, (i32x4){0, 53, -7, -1}), ((i32x4){-1, 0, -1, 0})
);
expect_vec(
i32x4_ge_u((i32x4){0, -1, 53, -7}, (i32x4){0, 53, -7, -1}), ((i32x4){-1, -1, 0, 0})
);
// f32x4 comparisons
expect_vec(
f32x4_eq((f32x4){0, -1, 1, 0}, (f32x4){0, 0, -1, 1}), ((i32x4){-1, 0, 0, 0})
);
expect_vec(
f32x4_ne((f32x4){0, -1, 1, 0}, (f32x4){0, 0, -1, 1}), ((i32x4){0, -1, -1, -1})
);
expect_vec(
f32x4_lt((f32x4){0, -1, 1, 0}, (f32x4){0, 0, -1, 1}), ((i32x4){0, -1, 0, -1})
);
expect_vec(
f32x4_gt((f32x4){0, -1, 1, 0}, (f32x4){0, 0, -1, 1}), ((i32x4){0, 0, -1, 0})
);
expect_vec(
f32x4_le((f32x4){0, -1, 1, 0}, (f32x4){0, 0, -1, 1}), ((i32x4){-1, -1, 0, -1})
);
expect_vec(
f32x4_ge((f32x4){0, -1, 1, 0}, (f32x4){0, 0, -1, 1}), ((i32x4){-1, 0, -1, 0})
);
expect_vec(
f32x4_eq((f32x4){NAN, 0, NAN, INFINITY}, (f32x4){0, NAN, NAN, INFINITY}),
((i32x4){0, 0, 0, -1})
);
expect_vec(
f32x4_ne((f32x4){NAN, 0, NAN, INFINITY}, (f32x4){0, NAN, NAN, INFINITY}),
((i32x4){-1, -1, -1, 0})
);
expect_vec(
f32x4_lt((f32x4){NAN, 0, NAN, INFINITY}, (f32x4){0, NAN, NAN, INFINITY}),
((i32x4){0, 0, 0, 0})
);
expect_vec(
f32x4_gt((f32x4){NAN, 0, NAN, INFINITY}, (f32x4){0, NAN, NAN, INFINITY}),
((i32x4){0, 0, 0, 0})
);
expect_vec(
f32x4_le((f32x4){NAN, 0, NAN, INFINITY}, (f32x4){0, NAN, NAN, INFINITY}),
((i32x4){0, 0, 0, -1})
);
expect_vec(
f32x4_ge((f32x4){NAN, 0, NAN, INFINITY}, (f32x4){0, NAN, NAN, INFINITY}),
((i32x4){0, 0, 0, -1})
);
expect_vec(
f32x4_eq((f32x4){-INFINITY, 0, NAN, -INFINITY}, (f32x4){0, INFINITY, INFINITY, NAN}),
((i32x4){0, 0, 0, 0})
);
expect_vec(
f32x4_ne((f32x4){-INFINITY, 0, NAN, -INFINITY}, (f32x4){0, INFINITY, INFINITY, NAN}),
((i32x4){-1, -1, -1, -1})
);
expect_vec(
f32x4_lt((f32x4){-INFINITY, 0, NAN, -INFINITY}, (f32x4){0, INFINITY, INFINITY, NAN}),
((i32x4){-1, -1, 0, 0})
);
expect_vec(
f32x4_gt((f32x4){-INFINITY, 0, NAN, -INFINITY}, (f32x4){0, INFINITY, INFINITY, NAN}),
((i32x4){0, 0, 0, 0})
);
expect_vec(
f32x4_le((f32x4){-INFINITY, 0, NAN, -INFINITY}, (f32x4){0, INFINITY, INFINITY, NAN}),
((i32x4){-1, -1, 0, 0})
);
expect_vec(
f32x4_ge((f32x4){-INFINITY, 0, NAN, -INFINITY}, (f32x4){0, INFINITY, INFINITY, NAN}),
((i32x4){0, 0, 0, 0})
);
// f64x2 comparisons
expect_vec(f64x2_eq((f64x2){0, 1}, (f64x2){0, 0}), ((i64x2){-1, 0}));
expect_vec(f64x2_ne((f64x2){0, 1}, (f64x2){0, 0}), ((i64x2){0, -1}));
expect_vec(f64x2_lt((f64x2){0, 1}, (f64x2){0, 0}), ((i64x2){0, 0}));
expect_vec(f64x2_gt((f64x2){0, 1}, (f64x2){0, 0}), ((i64x2){0, -1}));
expect_vec(f64x2_le((f64x2){0, 1}, (f64x2){0, 0}), ((i64x2){-1, 0}));
expect_vec(f64x2_ge((f64x2){0, 1}, (f64x2){0, 0}), ((i64x2){-1, -1}));
expect_vec(f64x2_eq((f64x2){NAN, 0}, (f64x2){INFINITY, INFINITY}), ((i64x2){0, 0}));
expect_vec(f64x2_ne((f64x2){NAN, 0}, (f64x2){INFINITY, INFINITY}), ((i64x2){-1, -1}));
expect_vec(f64x2_lt((f64x2){NAN, 0}, (f64x2){INFINITY, INFINITY}), ((i64x2){0, -1}));
expect_vec(f64x2_gt((f64x2){NAN, 0}, (f64x2){INFINITY, INFINITY}), ((i64x2){0, 0}));
expect_vec(f64x2_le((f64x2){NAN, 0}, (f64x2){INFINITY, INFINITY}), ((i64x2){0, -1}));
expect_vec(f64x2_ge((f64x2){NAN, 0}, (f64x2){INFINITY, INFINITY}), ((i64x2){0, 0}));
// bitwise operations
expect_vec(i8x16_not((i8x16)(i32x4){0, -1, 0, -1}), (i8x16)((i32x4){-1, 0, -1, 0}));
expect_vec(
i8x16_and((i8x16)(i32x4){0, 0, -1, -1}, (i8x16)(i32x4){0, -1, 0, -1}),
(i8x16)((i32x4){0, 0, 0, -1})
);
expect_vec(
i8x16_or((i8x16)(i32x4){0, 0, -1, -1}, (i8x16)(i32x4){0, -1, 0, -1}),
(i8x16)((i32x4){0, -1, -1, -1})
);
expect_vec(
i8x16_xor((i8x16)(i32x4){0, 0, -1, -1}, (i8x16)(i32x4){0, -1, 0, -1}),
(i8x16)((i32x4){0, -1, -1, 0})
);
expect_vec(
i8x16_andnot((i8x16)(i32x4){0, 0, -1, -1}, (i8x16)(i32x4){0, -1, 0, -1}),
(i8x16)((i32x4){0, 0, -1, 0})
);
expect_vec(
i8x16_bitselect(
(i8x16)(i32x4){0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA},
(i8x16)(i32x4){0xBBBBBBBB, 0xBBBBBBBB, 0xBBBBBBBB, 0xBBBBBBBB},
(i8x16)(i32x4){0xF0F0F0F0, 0xFFFFFFFF, 0x00000000, 0xFF00FF00}
),
(i8x16)((i32x4){0xABABABAB, 0xAAAAAAAA, 0xBBBBBBBB, 0xAABBAABB})
);
// i8x16 arithmetic
expect_vec(
i8x16_abs((i8x16){0, 1, 42, -3, -56, 127, -128, -126, 0, -1, -42, 3, 56, -127, -128, 126}),
((i8x16){0, 1, 42, 3, 56, 127, -128, 126, 0, 1, 42, 3, 56, 127, -128, 126})
);
expect_vec(
i8x16_neg((i8x16){0, 1, 42, -3, -56, 127, -128, -126, 0, -1, -42, 3, 56, -127, -128, 126}),
((i8x16){0, -1, -42, 3, 56, -127, -128, 126, 0, 1, 42, -3, -56, 127, -128, -126})
);
expect_eq(i8x16_any_true((i8x16){0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}), 0);
expect_eq(i8x16_any_true((i8x16){0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}), 1);
expect_eq(i8x16_any_true((i8x16){1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}), 1);
expect_eq(i8x16_any_true((i8x16){1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}), 1);
expect_eq(i8x16_all_true((i8x16){0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}), 0);
expect_eq(i8x16_all_true((i8x16){0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}), 0);
expect_eq(i8x16_all_true((i8x16){1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}), 0);
expect_eq(i8x16_all_true((i8x16){1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}), 1);
expect_vec(
i8x16_shl((i8x16){0, 1, 2, 4, 8, 16, 32, 64, -128, 3, 6, 12, 24, 48, 96, -64}, 1),
((i8x16){0, 2, 4, 8, 16, 32, 64, -128, 0, 6, 12, 24, 48, 96, -64, -128})
);
expect_vec(
i8x16_shl((i8x16){0, 1, 2, 4, 8, 16, 32, 64, -128, 3, 6, 12, 24, 48, 96, -64}, 8),
((i8x16){0, 1, 2, 4, 8, 16, 32, 64, -128, 3, 6, 12, 24, 48, 96, -64})
);
expect_vec(
i8x16_shr_u((i8x16){0, 1, 2, 4, 8, 16, 32, 64, -128, 3, 6, 12, 24, 48, 96, -64}, 1),
((i8x16){0, 0, 1, 2, 4, 8, 16, 32, 64, 1, 3, 6, 12, 24, 48, 96})
);
expect_vec(
i8x16_shr_u((i8x16){0, 1, 2, 4, 8, 16, 32, 64, -128, 3, 6, 12, 24, 48, 96, -64}, 8),
((i8x16){0, 1, 2, 4, 8, 16, 32, 64, -128, 3, 6, 12, 24, 48, 96, -64})
);
expect_vec(
i8x16_shr_s((i8x16){0, 1, 2, 4, 8, 16, 32, 64, -128, 3, 6, 12, 24, 48, 96, -64}, 1),
((i8x16){0, 0, 1, 2, 4, 8, 16, 32, -64, 1, 3, 6, 12, 24, 48, -32})
);
expect_vec(
i8x16_shr_s((i8x16){0, 1, 2, 4, 8, 16, 32, 64, -128, 3, 6, 12, 24, 48, 96, -64}, 8),
((i8x16){0, 1, 2, 4, 8, 16, 32, 64, -128, 3, 6, 12, 24, 48, 96, -64})
);
expect_vec(
i8x16_add(
(i8x16){0, 42, 255, 128, 127, 129, 6, 29, 103, 196, 231, 142, 17, 250, 1, 73},
(i8x16){3, 231, 1, 128, 129, 6, 103, 17, 42, 29, 73, 42, 0, 255, 127, 142}
),
((i8x16){3, 17, 0, 0, 0, 135, 109, 46, 145, 225, 48, 184, 17, 249, 128, 215})
);
expect_vec(
i8x16_add_saturate_s(
(i8x16){0, 42, 255, 128, 127, 129, 6, 29, 103, 196, 231, 142, 17, 250, 1, 73},
(i8x16){3, 231, 1, 128, 129, 6, 103, 17, 42, 29, 73, 42, 0, 255, 127, 142}
),
((i8x16){3, 17, 0, 128, 0, 135, 109, 46, 127, 225, 48, 184, 17, 249, 127, 215})
);
expect_vec(
i8x16_add_saturate_u(
(u8x16){0, 42, 255, 128, 127, 129, 6, 29, 103, 196, 231, 142, 17, 250, 1, 73},
(u8x16){3, 231, 1, 128, 129, 6, 103, 17, 42, 29, 73, 42, 0, 255, 127, 142}
),
((u8x16){3, 255, 255, 255, 255, 135, 109, 46, 145, 225, 255, 184, 17, 255, 128, 215})
);
expect_vec(
i8x16_sub(
(i8x16){0, 42, 255, 128, 127, 129, 6, 29, 103, 196, 231, 142, 17, 250, 1, 73},
(i8x16){3, 231, 1, 128, 129, 6, 103, 17, 42, 29, 73, 42, 0, 255, 127, 142}
),
((i8x16){253, 67, 254, 0, 254, 123, 159, 12, 61, 167, 158, 100, 17, 251, 130, 187})
);
expect_vec(
i8x16_sub_saturate_s(
(i8x16){0, 42, 255, 128, 127, 129, 6, 29, 103, 196, 231, 142, 17, 250, 1, 73},
(i8x16){3, 231, 1, 128, 129, 6, 103, 17, 42, 29, 73, 42, 0, 255, 127, 142}
),
((i8x16){253, 67, 254, 0, 127, 128, 159, 12, 61, 167, 158, 128, 17, 251, 130, 127})
);
expect_vec(
i8x16_sub_saturate_u(
(u8x16){0, 42, 255, 128, 127, 129, 6, 29, 103, 196, 231, 142, 17, 250, 1, 73},
(u8x16){3, 231, 1, 128, 129, 6, 103, 17, 42, 29, 73, 42, 0, 255, 127, 142}
),
((u8x16){0, 0, 254, 0, 0, 123, 0, 12, 61, 167, 158, 100, 17, 0, 0, 0})
);
expect_vec(
i8x16_avgr_u(
(u8x16){0, 42, 255, 128, 127, 129, 6, 29, 103, 196, 231, 142, 17, 250, 1, 73},
(u8x16){3, 231, 1, 128, 129, 6, 103, 17, 42, 29, 73, 42, 0, 255, 127, 142}
),
((u8x16){2, 137, 128, 128, 128, 68, 55, 23, 73, 113, 152, 92, 9, 253, 64, 108})
);
// i16x8 arithmetic
expect_vec(
i16x8_abs((i16x8){0, 1, 42, -3, -56, 32767, -32768, 32766}),
((i16x8){0, 1, 42, 3, 56, 32767, -32768, 32766})
);
expect_vec(
i16x8_neg((i16x8){0, 1, 42, -3, -56, 32767, -32768, 32766}),
((i16x8){0, -1, -42, 3, 56, -32767, -32768, -32766})
);
expect_eq(i16x8_any_true((i16x8){0, 0, 0, 0, 0, 0, 0, 0}), 0);
expect_eq(i16x8_any_true((i16x8){0, 0, 1, 0, 0, 0, 0, 0}), 1);
expect_eq(i16x8_any_true((i16x8){1, 1, 1, 1, 1, 0, 1, 1}), 1);
expect_eq(i16x8_any_true((i16x8){1, 1, 1, 1, 1, 1, 1, 1}), 1);
expect_eq(i16x8_all_true((i16x8){0, 0, 0, 0, 0, 0, 0, 0}), 0);
expect_eq(i16x8_all_true((i16x8){0, 0, 1, 0, 0, 0, 0, 0}), 0);
expect_eq(i16x8_all_true((i16x8){1, 1, 1, 1, 1, 0, 1, 1}), 0);
expect_eq(i16x8_all_true((i16x8){1, 1, 1, 1, 1, 1, 1, 1}), 1);
expect_vec(
i16x8_shl((i16x8){0, 8, 16, 128, 256, 2048, 4096, -32768}, 1),
((i16x8){0, 16, 32, 256, 512, 4096, 8192, 0})
);
expect_vec(
i16x8_shl((i16x8){0, 8, 16, 128, 256, 2048, 4096, -32768}, 16),
((i16x8){0, 8, 16, 128, 256, 2048, 4096, -32768})
);
expect_vec(
i16x8_shr_u((i16x8){0, 8, 16, 128, 256, 2048, 4096, -32768}, 1),
((i16x8){0, 4, 8, 64, 128, 1024, 2048, 16384})
);
expect_vec(
i16x8_shr_u((i16x8){0, 8, 16, 128, 256, 2048, 4096, -32768}, 16),
((i16x8){0, 8, 16, 128, 256, 2048, 4096, -32768})
);
expect_vec(
i16x8_shr_s((i16x8){0, 8, 16, 128, 256, 2048, 4096, -32768}, 1),
((i16x8){0, 4, 8, 64, 128, 1024, 2048, -16384})
);
expect_vec(
i16x8_shr_s((i16x8){0, 8, 16, 128, 256, 2048, 4096, -32768}, 16),
((i16x8){0, 8, 16, 128, 256, 2048, 4096, -32768})
);
expect_vec(
i16x8_add(
(i16x8){0, -256, -32768, 32512, -32512, -6400, -1536, 32766},
(i16x8){768, 1, -32768, -32512, 1536, 18688, -256, 2}
),
((i16x8){768, -255, 0, 0, -30976, 12288, -1792, -32768})
);
expect_vec(
i16x8_add_saturate_s(
(i16x8){0, -256, -32768, 32512, -32512, -6400, -1536, 32766},
(i16x8){768, 1, -32768, -32512, 1536, 18688, -256, 2}
),
((i16x8){768, -255, -32768, 0, -30976, 12288, -1792, 32767})
);
expect_vec(
i16x8_add_saturate_u(
(u16x8){0, -256, -32768, 32512, -32512, -6400, -1536, 32766},
(u16x8){768, 1, -32768, -32512, 1536, 18688, -256, 2}
),
((u16x8){768, -255, -1, -1, -30976, -1, -1, -32768})
);
expect_vec(
i16x8_sub(
(i16x8){0, -256, -32768, 32512, -32512, -6400, -1536, 32766},
(i16x8){768, 1, -32768, -32512, 1536, 18688, -256, 2}
),
((i16x8){-768, -257, 0, -512, 31488, -25088, -1280, 32764})
);
expect_vec(
i16x8_sub_saturate_s(
(i16x8){0, -256, -32768, 32512, -32512, -6400, -1536, 32766},
(i16x8){768, 1, -32768, -32512, 1536, 18688, -256, 2}
),
((i16x8){-768, -257, 0, 32767, -32768, -25088, -1280, 32764})
);
expect_vec(
i16x8_sub_saturate_u(
(u16x8){0, -256, -32768, 32512, -32512, -6400, -1536, 32766},
(u16x8){768, 1, -32768, -32512, 1536, 18688, -256, 2}
),
((u16x8){0, -257, 0, 0, 31488, -25088, 0, 32764})
);
expect_vec(
i16x8_mul(
(i16x8){0, -256, -32768, 32512, -32512, -6400, -1536, 32766},
(i16x8){768, 1, -32768, -32512, 1536, 18688, -256, 2}
),
((i16x8){0, -256, 0, 0, 0, 0, 0, -4})
);
expect_vec(
i16x8_avgr_u(
(u16x8){0, -256, -32768, 32512, -32512, -6400, -1536, 32766},
(u16x8){768, 1, -32768, -32512, 1536, 18688, -256, 2}
),
((u16x8){384, 32641, -32768, -32768, 17280, -26624, -896, 16384})
);
// i32x4 arithmetic
expect_vec(i32x4_abs((i32x4){0, 1, 0x80000000, 0x80000001}), ((i32x4){0, 1, 0x80000000, 0x7fffffff}));
expect_vec(i32x4_neg((i32x4){0, 1, 0x80000000, 0x80000001}), ((i32x4){0, -1, 0x80000000, 0x7fffffff}));
expect_eq(i32x4_any_true((i32x4){0, 0, 0, 0}), 0);
expect_eq(i32x4_any_true((i32x4){0, 0, 1, 0}), 1);
expect_eq(i32x4_any_true((i32x4){1, 0, 1, 1}), 1);
expect_eq(i32x4_any_true((i32x4){1, 1, 1, 1}), 1);
expect_eq(i32x4_all_true((i32x4){0, 0, 0, 0}), 0);
expect_eq(i32x4_all_true((i32x4){0, 0, 1, 0}), 0);
expect_eq(i32x4_all_true((i32x4){1, 0, 1, 1}), 0);
expect_eq(i32x4_all_true((i32x4){1, 1, 1, 1}), 1);
expect_vec(i32x4_shl((i32x4){1, 0x40000000, 0x80000000, -1}, 1), ((i32x4){2, 0x80000000, 0, -2}));
expect_vec(i32x4_shl((i32x4){1, 0x40000000, 0x80000000, -1}, 32), ((i32x4){1, 0x40000000, 0x80000000, -1}));
expect_vec(i32x4_shr_s((i32x4){1, 0x40000000, 0x80000000, -1}, 1), ((i32x4){0, 0x20000000, 0xc0000000, -1}));
expect_vec(i32x4_shr_s((i32x4){1, 0x40000000, 0x80000000, -1}, 32), ((i32x4){1, 0x40000000, 0x80000000, -1}));
expect_vec(i32x4_shr_u((i32x4){1, 0x40000000, 0x80000000, -1}, 1), ((i32x4){0, 0x20000000, 0x40000000, 0x7fffffff}));
expect_vec(i32x4_shr_u((i32x4){1, 0x40000000, 0x80000000, -1}, 32), ((i32x4){1, 0x40000000, 0x80000000, -1}));
expect_vec(i32x4_add((i32x4){0, 0x80000001, 42, 5}, (i32x4){0, 0x80000001, 5, 42}), ((i32x4){0, 2, 47, 47}));
expect_vec(i32x4_sub((i32x4){0, 2, 47, 47}, (i32x4){0, 0x80000001, 42, 5}), ((i32x4){0, 0x80000001, 5, 42}));
expect_vec(i32x4_mul((i32x4){0, 0x80000001, 42, 5}, (i32x4){0, 0x80000001, 42, 5}), ((i32x4){0, 1, 1764, 25}));
// i64x2 arithmetic
expect_vec(i64x2_neg((i64x2){0x8000000000000000, 42}), ((i64x2){0x8000000000000000, -42}));
expect_vec(i64x2_shl((i64x2){1, 0x8000000000000000}, 1), ((i64x2){2, 0}));
expect_vec(i64x2_shl((i64x2){1, 0x8000000000000000}, 64), ((i64x2){1, 0x8000000000000000}));
expect_vec(i64x2_shr_s((i64x2){1, 0x8000000000000000}, 1), ((i64x2){0, 0xc000000000000000}));
expect_vec(i64x2_shr_s((i64x2){1, 0x8000000000000000}, 64), ((i64x2){1, 0x8000000000000000}));
expect_vec(i64x2_shr_u((i64x2){1, 0x8000000000000000}, 1), ((i64x2){0, 0x4000000000000000}));
expect_vec(i64x2_shr_u((i64x2){1, 0x8000000000000000}, 64), ((i64x2){1, 0x8000000000000000}));
expect_vec(i64x2_add((i64x2){0x8000000000000001, 42}, (i64x2){0x8000000000000001, 0}), ((i64x2){2, 42}));
expect_vec(i64x2_sub((i64x2){2, 42}, (i64x2){0x8000000000000001, 0}), ((i64x2){0x8000000000000001, 42}));
// f32x4 arithmetic
expect_vec(f32x4_abs((f32x4){-0., NAN, -INFINITY, 5}), ((f32x4){0, NAN, INFINITY, 5}));
expect_vec(f32x4_neg((f32x4){-0., NAN, -INFINITY, 5}), ((f32x4){0, -NAN, INFINITY, -5}));
expect_vec(f32x4_sqrt((f32x4){-0., NAN, INFINITY, 4}), ((f32x4){-0., NAN, INFINITY, 2}));
// TODO: Test QFMA/QFMS
expect_vec(f32x4_add((f32x4){NAN, -NAN, INFINITY, 42}, (f32x4){42, INFINITY, INFINITY, 1}), ((f32x4){NAN, -NAN, INFINITY, 43}));
expect_vec(f32x4_sub((f32x4){NAN, -NAN, INFINITY, 42}, (f32x4){42, INFINITY, -INFINITY, 1}), ((f32x4){NAN, -NAN, INFINITY, 41}));
expect_vec(f32x4_mul((f32x4){NAN, -NAN, INFINITY, 42}, (f32x4){42, INFINITY, INFINITY, 2}), ((f32x4){NAN, -NAN, INFINITY, 84}));
expect_vec(f32x4_div((f32x4){NAN, -NAN, INFINITY, 42}, (f32x4){42, INFINITY, 2, 2}), ((f32x4){NAN, -NAN, INFINITY, 21}));
expect_vec(f32x4_min((f32x4){-0., 0, NAN, 5}, (f32x4){0, -0., 5, NAN}), ((f32x4){-0., -0., NAN, NAN}));
expect_vec(f32x4_max((f32x4){-0., 0, NAN, 5}, (f32x4){0, -0., 5, NAN}), ((f32x4){0, 0, NAN, NAN}));
// f64x2 arithmetic
expect_vec(f64x2_abs((f64x2){-0., NAN}), ((f64x2){0, NAN}));
expect_vec(f64x2_abs((f64x2){-INFINITY, 5}), ((f64x2){INFINITY, 5}));
expect_vec(f64x2_neg((f64x2){-0., NAN}), ((f64x2){0, -NAN}));
expect_vec(f64x2_neg((f64x2){-INFINITY, 5}), ((f64x2){INFINITY, -5}));
// https://bugs.chromium.org/p/v8/issues/detail?id=10170
// expect_vec(f64x2_sqrt((f64x2){-0., NAN}), ((f64x2){-0., NAN}));
// expect_vec(f64x2_sqrt((f64x2){INFINITY, 4}), ((f64x2){INFINITY, 2}));
// TODO: Test QFMA/QFMS
expect_vec(f64x2_add((f64x2){NAN, -NAN}, (f64x2){42, INFINITY}), ((f64x2){NAN, -NAN}));
expect_vec(f64x2_add((f64x2){INFINITY, 42}, (f64x2){INFINITY, 1}), ((f64x2){INFINITY, 43}));
expect_vec(f64x2_sub((f64x2){NAN, -NAN}, (f64x2){42, INFINITY}), ((f64x2){NAN, -NAN}));
expect_vec(f64x2_sub((f64x2){INFINITY, 42}, (f64x2){-INFINITY, 1}), ((f64x2){INFINITY, 41}));
expect_vec(f64x2_mul((f64x2){NAN, -NAN}, (f64x2){42, INFINITY}), ((f64x2){NAN, -NAN}));
expect_vec(f64x2_mul((f64x2){INFINITY, 42}, (f64x2){INFINITY, 2}), ((f64x2){INFINITY, 84}));
expect_vec(f64x2_div((f64x2){NAN, -NAN}, (f64x2){42, INFINITY}), ((f64x2){NAN, -NAN}));
expect_vec(f64x2_div((f64x2){INFINITY, 42}, (f64x2){2, 2}), ((f64x2){INFINITY, 21}));
expect_vec(f64x2_min((f64x2){-0., 0}, (f64x2){0, -0}), ((f64x2){-0., -0}));
expect_vec(f64x2_min((f64x2){NAN, 5}, (f64x2){5, NAN}), ((f64x2){NAN, NAN}));
expect_vec(f64x2_max((f64x2){-0., 0}, (f64x2){0, -0}), ((f64x2){0, 0}));
expect_vec(f64x2_max((f64x2){NAN, 5}, (f64x2){5, NAN}), ((f64x2){NAN, NAN}));
// conversions
expect_vec(i32x4_trunc_s_f32x4_sat((f32x4){42, NAN, INFINITY, -INFINITY}), ((i32x4){42, 0, 2147483647, -2147483648ll}));
expect_vec(i32x4_trunc_u_f32x4_sat((f32x4){42, NAN, INFINITY, -INFINITY}), ((i32x4){42, 0, 4294967295ull, 0}));
expect_vec(f32x4_convert_s_i32x4((i32x4){0, -1, 2147483647, -2147483647 - 1}), ((f32x4){0, -1, 2147483648., -2147483648.}));
expect_vec(f32x4_convert_u_i32x4((i32x4){0, -1, 2147483647, -2147483647 - 1}), ((f32x4){0, 4294967296., 2147483648., 2147483648.}));
expect_vec(
i8x16_narrow_i16x8_s(
(i16x8){129, 127, -32767, 32767, -32768, -1, 1, 0},
(i16x8){0, 1, -1, -32768, 32767, -32767, 127, 129}
),
((i8x16){127, 127, -128, 127, -128, -1, 1, 0, 0, 1, -1, -128, 127, -128, 127, 127})
);
expect_vec(
i8x16_narrow_i16x8_u(
(u16x8){129, 127, -32767, 32767, -32768, -1, 1, 0},
(u16x8){0, 1, -1, -32768, 32767, -32767, 127, 129}
),
((u8x16){129, 127, 0, 255, 0, 0, 1, 0, 0, 1, 0, 0, 255, 0, 127, 129})
);
expect_vec(
i16x8_narrow_i32x4_s(
(i32x4){32769, 32767, -2147483647, 2147483647},
(i32x4){0, 1, -1, -2147483647 - 1}
),
((i16x8){32767, 32767, -32768, 32767, 0, 1, -1, -32768})
);
expect_vec(
i16x8_narrow_i32x4_u(
(u32x4){32769, 32767, -2147483647, 2147483647},
(u32x4){0, 1, -1, -2147483647 - 1}
),
((u16x8){-32767, 32767, 0, -1, 0, 1, 0, 0})
);
if (failures == 0) {
printf("Success!\n");
} else {
printf("Failed :(\n");
}
}
|