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 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492
|
// ==========================================================================
// SeqAn - The Library for Sequence Analysis
// ==========================================================================
// Copyright (c) 2006-2018, Knut Reinert, FU Berlin
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Knut Reinert or the FU Berlin nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// ==========================================================================
// Author: David Weese <david.weese@fu-berlin.de>
// René Rahn <rene.rahn@fu-berlin.de>
// Stefan Budach <stefan.budach@fu-berlin.de>
// ==========================================================================
// generic SIMD interface for SSE3 / AVX2
// ==========================================================================
#ifndef SEQAN_INCLUDE_SEQAN_SIMD_SIMD_BASE_SEQAN_IMPL_AVX2_H_
#define SEQAN_INCLUDE_SEQAN_SIMD_SIMD_BASE_SEQAN_IMPL_AVX2_H_
namespace seqan {
// SimdParams_<32, 32>: 256bit = 32 elements * 8bit
SEQAN_DEFINE_SIMD_VECTOR_(SimdVector32Char, char, 32)
SEQAN_DEFINE_SIMD_VECTOR_(SimdVector32SChar, signed char, 32)
SEQAN_DEFINE_SIMD_VECTOR_(SimdVector32UChar, unsigned char, 32)
// SimdParams_<32, 16>: 256bit = 16 elements * 2 * 8bit
SEQAN_DEFINE_SIMD_VECTOR_(SimdVector16Short, short, 32)
SEQAN_DEFINE_SIMD_VECTOR_(SimdVector16UShort, unsigned short, 32)
// SimdParams_<32, 8>: 256bit = 8 elements * 4 * 8bit
SEQAN_DEFINE_SIMD_VECTOR_(SimdVector8Int, int, 32)
SEQAN_DEFINE_SIMD_VECTOR_(SimdVector8UInt, unsigned int, 32)
// SimdParams_<32, 4>: 256bit = 4 elements * 8 * 8bit
SEQAN_DEFINE_SIMD_VECTOR_(SimdVector4Int64, int64_t, 32)
SEQAN_DEFINE_SIMD_VECTOR_(SimdVector4UInt64, uint64_t, 32)
// ============================================================================
// Functions
// ============================================================================
// ============================================================================
// AVX/AVX2 wrappers (256bit vectors)
// ============================================================================
// --------------------------------------------------------------------------
// _fillVector (256bit)
// --------------------------------------------------------------------------
template <typename TSimdVector, typename ...TValue>
inline void
_fillVector(TSimdVector & vector,
std::tuple<TValue...> const & x,
std::index_sequence<0> const &, SimdParams_<32, 32>)
{
vector = SEQAN_VECTOR_CAST_(TSimdVector, _mm256_set1_epi8(std::get<0>(x)));
}
template <typename TSimdVector, typename ...TValue>
inline void
_fillVector(TSimdVector & vector,
std::tuple<TValue...> const & x,
std::index_sequence<0> const &, SimdParams_<32, 16>)
{
vector = SEQAN_VECTOR_CAST_(TSimdVector, _mm256_set1_epi16(std::get<0>(x)));
}
template <typename TSimdVector, typename ...TValue>
inline void
_fillVector(TSimdVector & vector,
std::tuple<TValue...> const & x,
std::index_sequence<0> const &, SimdParams_<32, 8>)
{
vector = SEQAN_VECTOR_CAST_(TSimdVector, _mm256_set1_epi32(std::get<0>(x)));
}
template <typename TSimdVector, typename ...TValue>
inline void
_fillVector(TSimdVector & vector,
std::tuple<TValue...> const & x,
std::index_sequence<0> const &, SimdParams_<32, 4>)
{
vector = SEQAN_VECTOR_CAST_(TSimdVector, _mm256_set1_epi64x(std::get<0>(x)));
}
template <typename TSimdVector, typename ...TValue, size_t ...INDICES>
inline void
_fillVector(TSimdVector & vector,
std::tuple<TValue...> const & args, std::index_sequence<INDICES...> const &, SimdParams_<32, 32>)
{
vector = SEQAN_VECTOR_CAST_(TSimdVector, _mm256_setr_epi8(std::get<INDICES>(args)...));
}
template <typename TSimdVector, typename ...TValue, size_t ...INDICES>
inline void
_fillVector(TSimdVector & vector,
std::tuple<TValue...> const & args, std::index_sequence<INDICES...> const &, SimdParams_<32, 16>)
{
vector = SEQAN_VECTOR_CAST_(TSimdVector, _mm256_setr_epi16(std::get<INDICES>(args)...));
}
template <typename TSimdVector, typename ...TValue, size_t ...INDICES>
inline void
_fillVector(TSimdVector & vector,
std::tuple<TValue...> const & args, std::index_sequence<INDICES...> const &, SimdParams_<32, 8>)
{
vector = SEQAN_VECTOR_CAST_(TSimdVector, _mm256_setr_epi32(std::get<INDICES>(args)...));
}
template <typename TSimdVector, typename ...TValue, size_t ...INDICES>
inline void
_fillVector(TSimdVector & vector,
std::tuple<TValue...> const & args, std::index_sequence<INDICES...> const &, SimdParams_<32, 4>)
{
// reverse argument list 0, 1, 2, 3 -> 3, 2, 1, 0
// NOTE(marehr): Intel linux fails to reverse argument list and only
// _mm256_set_epi64x has no reverse equivalent
vector = SEQAN_VECTOR_CAST_(TSimdVector, _mm256_set_epi64x(std::get<sizeof...(INDICES) - 1 - INDICES>(args)...));
}
// --------------------------------------------------------------------------
// _clearVector (256bit)
// --------------------------------------------------------------------------
template <typename TSimdVector, int L>
inline void _clearVector(TSimdVector & vector, SimdParams_<32, L>)
{
vector = SEQAN_VECTOR_CAST_(TSimdVector, _mm256_setzero_si256());
}
// --------------------------------------------------------------------------
// _createVector (256bit)
// --------------------------------------------------------------------------
template <typename TSimdVector, typename TValue>
inline TSimdVector _createVector(TValue const x, SimdParams_<32, 32>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_set1_epi8(x));
}
template <typename TSimdVector, typename TValue>
inline TSimdVector _createVector(TValue const x, SimdParams_<32, 16>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_set1_epi16(x));
}
template <typename TSimdVector, typename TValue>
inline TSimdVector _createVector(TValue const x, SimdParams_<32, 8>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_set1_epi32(x));
}
template <typename TSimdVector, typename TValue>
inline TSimdVector _createVector(TValue const x, SimdParams_< 32, 4>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_set1_epi64x(x));
}
// --------------------------------------------------------------------------
// _cmpEq (256bit)
// --------------------------------------------------------------------------
template <typename TSimdVector>
inline TSimdVector _cmpEq(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 32>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_cmpeq_epi8(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _cmpEq(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 16>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_cmpeq_epi16(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _cmpEq(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 8>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_cmpeq_epi32(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _cmpEq(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 4>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_cmpeq_epi64(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
// --------------------------------------------------------------------------
// _cmpGt (256bit)
// --------------------------------------------------------------------------
template <typename TSimdVector>
inline TSimdVector _cmpGt(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 32, int8_t>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_cmpgt_epi8(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _cmpGt(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 32, uint8_t>)
{
// There is no unsigned cmpgt, we reduce it to the signed case.
// Note that 0x80 = ~0x7F (prevent overflow messages).
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_cmpgt_epi8(
_mm256_xor_si256(SEQAN_VECTOR_CAST_(const __m256i&, a), _mm256_set1_epi8(~0x7F)),
_mm256_xor_si256(SEQAN_VECTOR_CAST_(const __m256i&, b), _mm256_set1_epi8(~0x7F))));
}
template <typename TSimdVector>
inline TSimdVector _cmpGt(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 16, int16_t>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_cmpgt_epi16(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _cmpGt(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 16, uint16_t>)
{
// There is no unsigned cmpgt, we reduce it to the signed case.
// Note that 0x8000 = ~0x7FFF (prevent overflow messages).
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_cmpgt_epi16(
_mm256_xor_si256(SEQAN_VECTOR_CAST_(const __m256i&, a), _mm256_set1_epi16(~0x7FFF)),
_mm256_xor_si256(SEQAN_VECTOR_CAST_(const __m256i&, b), _mm256_set1_epi16(~0x7FFF))));
}
template <typename TSimdVector>
inline TSimdVector _cmpGt(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 8, int32_t>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_cmpgt_epi32(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _cmpGt(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 8, uint32_t>)
{
// There is no unsigned cmpgt, we reduce it to the signed case.
// Note that 0x80000000 = ~0x7FFFFFFF (prevent overflow messages).
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_cmpgt_epi32(
_mm256_xor_si256(SEQAN_VECTOR_CAST_(const __m256i&, a), _mm256_set1_epi32(~0x7FFFFFFF)),
_mm256_xor_si256(SEQAN_VECTOR_CAST_(const __m256i&, b), _mm256_set1_epi32(~0x7FFFFFFF))));
}
template <typename TSimdVector>
inline TSimdVector _cmpGt(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 4, int64_t>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_cmpgt_epi64(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _cmpGt(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 4, uint64_t>)
{
// There is no unsigned cmpgt, we reduce it to the signed case.
// Note that 0x8000000000000000ul = ~0x7FFFFFFFFFFFFFFFul (prevent overflow messages).
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_cmpgt_epi64(
_mm256_xor_si256(SEQAN_VECTOR_CAST_(const __m256i&, a) ,_mm256_set1_epi64x(~0x7FFFFFFFFFFFFFFFul)),
_mm256_xor_si256(SEQAN_VECTOR_CAST_(const __m256i&, b), _mm256_set1_epi64x(~0x7FFFFFFFFFFFFFFFul))));
}
// --------------------------------------------------------------------------
// _bitwiseOr (256bit)
// --------------------------------------------------------------------------
template <typename TSimdVector, int L>
inline TSimdVector _bitwiseOr(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, L>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_or_si256(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
// --------------------------------------------------------------------------
// _bitwiseAnd (256bit)
// --------------------------------------------------------------------------
template <typename TSimdVector, int L>
inline TSimdVector _bitwiseAnd(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, L>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_and_si256(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
// --------------------------------------------------------------------------
// _bitwiseAndNot (256bit)
// --------------------------------------------------------------------------
template <typename TSimdVector, int L>
inline TSimdVector _bitwiseAndNot(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, L>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_andnot_si256(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
// --------------------------------------------------------------------------
// _bitwiseNot (256bit)
// --------------------------------------------------------------------------
template <typename TSimdVector>
inline TSimdVector _bitwiseNot(TSimdVector const & a, SimdParams_<32, 32>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_cmpeq_epi8(SEQAN_VECTOR_CAST_(const __m256i&, a), _mm256_setzero_si256()));
}
template <typename TSimdVector>
inline TSimdVector _bitwiseNot(TSimdVector const & a, SimdParams_<32, 16>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_cmpeq_epi16(SEQAN_VECTOR_CAST_(const __m256i&, a), _mm256_setzero_si256()));
}
template <typename TSimdVector>
inline TSimdVector _bitwiseNot(TSimdVector const & a, SimdParams_<32, 8>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_cmpeq_epi32(SEQAN_VECTOR_CAST_(const __m256i&, a), _mm256_setzero_si256()));
}
template <typename TSimdVector>
inline TSimdVector _bitwiseNot(TSimdVector const & a, SimdParams_<32, 4>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_cmpeq_epi64(SEQAN_VECTOR_CAST_(const __m256i&, a), _mm256_setzero_si256()));
}
// --------------------------------------------------------------------------
// _divide (256bit)
// --------------------------------------------------------------------------
template <typename TSimdVector>
inline TSimdVector _divide(TSimdVector const & a, int b, SimdParams_<32, 32>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_div_epi8(a, _mm256_set1_epi8(b)));
}
template <typename TSimdVector>
inline TSimdVector _divide(TSimdVector const & a, int b, SimdParams_<32, 16>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_div_epi16(a, _mm256_set1_epi16(b)));
}
template <typename TSimdVector>
inline TSimdVector _divide(TSimdVector const & a, int b, SimdParams_<32, 8>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_div_epi32(a, _mm256_set1_epi32(b)));
}
template <typename TSimdVector>
inline TSimdVector _divide(TSimdVector const & a, int b, SimdParams_<32, 4>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_div_epi64(a, _mm256_set1_epi64x(b)));
}
// --------------------------------------------------------------------------
// _add (256bit)
// --------------------------------------------------------------------------
template <typename TSimdVector>
inline TSimdVector _add(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 32>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_add_epi8(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _add(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 16>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_add_epi16(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _add(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 8>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_add_epi32(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _add(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 4>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_add_epi64(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
// --------------------------------------------------------------------------
// _sub (256bit)
// --------------------------------------------------------------------------
template <typename TSimdVector>
inline TSimdVector _sub(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 32>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_sub_epi8(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _sub(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 16>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_sub_epi16(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _sub(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 8>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_sub_epi32(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _sub(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 4>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_sub_epi64(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
// --------------------------------------------------------------------------
// _mult (256bit)
// --------------------------------------------------------------------------
template <typename TSimdVector>
inline TSimdVector _mult(TSimdVector const & a, TSimdVector const &/*b*/, SimdParams_<32, 32>)
{
SEQAN_SKIP_TEST;
SEQAN_ASSERT_FAIL("AVX2 intrinsics for multiplying 8 bit values not implemented!");
return a;
}
template <typename TSimdVector>
inline TSimdVector _mult(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 16>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_mullo_epi16(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _mult(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 8>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_mullo_epi32(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _mult(TSimdVector const & a, TSimdVector const &/*b*/, SimdParams_<32, 4>)
{
SEQAN_SKIP_TEST;
SEQAN_ASSERT_FAIL("AVX2 intrinsics for multiplying 64 bit values not implemented!");
return a;
}
// --------------------------------------------------------------------------
// _max (256bit)
// --------------------------------------------------------------------------
template <typename TSimdVector>
inline TSimdVector _max(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 32, int8_t>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_max_epi8(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _max(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 32, uint8_t>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_max_epu8(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _max(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 16, int16_t>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_max_epi16(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _max(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 16, uint16_t>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_max_epu16(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _max(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 8, int32_t>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_max_epi32(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _max(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 8, uint32_t>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_max_epu32(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _max(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 4, int64_t>)
{
#if defined(__AVX512VL__)
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_max_epi64(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
#else // defined(__AVX512VL__)
return blend(b, a, cmpGt(a, b));
#endif // defined(__AVX512VL__)
}
template <typename TSimdVector>
inline TSimdVector _max(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 4, uint64_t>)
{
#if defined(__AVX512VL__)
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_max_epu64(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
#else // defined(__AVX512VL__)
return blend(b, a, cmpGt(a, b));
#endif // defined(__AVX512VL__)
}
// --------------------------------------------------------------------------
// _min (256bit)
// --------------------------------------------------------------------------
template <typename TSimdVector>
inline TSimdVector _min(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 32, int8_t>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_min_epi8(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _min(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 32, uint8_t>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_min_epu8(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _min(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 16, int16_t>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_min_epi16(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _min(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 16, uint16_t>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_min_epu16(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _min(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 8, int32_t>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_min_epi32(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _min(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 8, uint32_t>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_min_epu32(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
}
template <typename TSimdVector>
inline TSimdVector _min(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 4, int64_t>)
{
#if defined(__AVX512VL__)
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_min_epi64(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
#else // defined(__AVX512VL__)
return blend(a, b, cmpGt(a, b));
#endif // defined(__AVX512VL__)
}
template <typename TSimdVector>
inline TSimdVector _min(TSimdVector const & a, TSimdVector const & b, SimdParams_<32, 4, uint64_t>)
{
#if defined(__AVX512VL__)
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_min_epu64(SEQAN_VECTOR_CAST_(const __m256i&, a),
SEQAN_VECTOR_CAST_(const __m256i&, b)));
#else // defined(__AVX512VL__)
return blend(a, b, cmpGt(a, b));
#endif // defined(__AVX512VL__)
}
// --------------------------------------------------------------------------
// _blend (256bit)
// --------------------------------------------------------------------------
template <typename TSimdVector, typename TSimdVectorMask, int L>
inline TSimdVector _blend(TSimdVector const & a, TSimdVector const & b, TSimdVectorMask const & mask, SimdParams_<32, L>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
_mm256_blendv_epi8(SEQAN_VECTOR_CAST_(const __m256i &, a),
SEQAN_VECTOR_CAST_(const __m256i &, b),
SEQAN_VECTOR_CAST_(const __m256i &, mask)));
}
// --------------------------------------------------------------------------
// _storeu (256bit)
// --------------------------------------------------------------------------
template <typename T, typename TSimdVector, int L>
inline void _storeu(T * memAddr, TSimdVector const & vec, SimdParams_<32, L>)
{
_mm256_storeu_si256((__m256i*)memAddr, SEQAN_VECTOR_CAST_(const __m256i&, vec));
}
// ----------------------------------------------------------------------------
// Function _load() 256bit
// ----------------------------------------------------------------------------
template <typename TSimdVector, typename T, int L>
inline TSimdVector _load(T const * memAddr, SimdParams_<32, L>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_load_si256((__m256i const *) memAddr));
}
// --------------------------------------------------------------------------
// _shiftRightLogical (256bit)
// --------------------------------------------------------------------------
template <typename TSimdVector>
inline TSimdVector _shiftRightLogical(TSimdVector const & vector, const int imm, SimdParams_<32, 32>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_srli_epi16(SEQAN_VECTOR_CAST_(const __m256i &, vector), imm) & _mm256_set1_epi8(0xff >> imm));
}
template <typename TSimdVector>
inline TSimdVector _shiftRightLogical(TSimdVector const & vector, const int imm, SimdParams_<32, 16>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_srli_epi16(SEQAN_VECTOR_CAST_(const __m256i &, vector), imm));
}
template <typename TSimdVector>
inline TSimdVector _shiftRightLogical(TSimdVector const & vector, const int imm, SimdParams_<32, 8>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_srli_epi32(SEQAN_VECTOR_CAST_(const __m256i &, vector), imm));
}
template <typename TSimdVector>
inline TSimdVector _shiftRightLogical(TSimdVector const & vector, const int imm, SimdParams_<32, 4>)
{
return SEQAN_VECTOR_CAST_(TSimdVector, _mm256_srli_epi64(SEQAN_VECTOR_CAST_(const __m256i &, vector), imm));
}
// --------------------------------------------------------------------------
// Extend sign from integer types 256bit
// --------------------------------------------------------------------------
inline __m256i
seqan_mm256_i16sign_extend_epis8(__m256i const & v)
{
return _mm256_or_si256( // extend sign (v | hi-bits)
v,
_mm256_and_si256( // select hi-bits (hi-bits = msk & 0xff00)
_mm256_sub_epi16( // msk = msb - 1
_mm256_andnot_si256( //msb = ~v & 0x80 (select msb)
v,
_mm256_set1_epi16(0x80)
),
_mm256_set1_epi16(1)
),
_mm256_set1_epi16(static_cast<uint16_t>(0xff00u))
)
);
}
inline __m256i
seqan_mm256_i32sign_extend_epis8(__m256i const & v)
{
return _mm256_or_si256( // extend sign (v | hi-bits)
v,
_mm256_and_si256( // select hi-bits (hi-bits = msk & 0xffffff00u)
_mm256_sub_epi32( // msk = msb - 1
_mm256_andnot_si256( //msb = ~v & 0x80 (select msb)
v,
_mm256_set1_epi32(0x80)
),
_mm256_set1_epi32(1)
),
_mm256_set1_epi32(static_cast<uint32_t>(0xffffff00u))
)
);
}
inline __m256i
seqan_mm256_i32sign_extend_epis16(__m256i const & v)
{
return _mm256_or_si256( // extend sign (v | hi-bits)
v,
_mm256_and_si256( // select hi-bits (hi-bits = msk & 0xffff0000u)
_mm256_sub_epi32( // msk = msb - 1
_mm256_andnot_si256( //msb = ~v & 0x8000 (select msb)
v,
_mm256_set1_epi32(0x8000)
),
_mm256_set1_epi32(1)
),
_mm256_set1_epi32(static_cast<uint32_t>(0xffff0000u))
)
);
}
inline __m256i
seqan_mm256_i64sign_extend_epis8(__m256i const & v)
{
return _mm256_or_si256( // extend sign (v | hi-bits)
v,
_mm256_and_si256( // select hi-bits (hi-bits = msk & 0xffffffffffffff00ul)
_mm256_sub_epi64( // msk = msb - 1
_mm256_andnot_si256( //msb = ~v & 0x80 (select msb)
v,
_mm256_set1_epi64x(0x80)
),
_mm256_set1_epi64x(1)
),
_mm256_set1_epi64x(static_cast<uint64_t>(0xffffffffffffff00ul))
)
);
}
inline __m256i
seqan_mm256_i64sign_extend_epis16(__m256i const & v)
{
return _mm256_or_si256( // extend sign (v | hi-bits)
v,
_mm256_and_si256( // select hi-bits (hi-bits = msk & 0xffffffffffff0000ul)
_mm256_sub_epi64( // msk = msb - 1
_mm256_andnot_si256( //msb = ~v & 0x8000 (select msb)
v,
_mm256_set1_epi64x(0x8000)
),
_mm256_set1_epi64x(1)
),
_mm256_set1_epi64x(static_cast<uint64_t>(0xffffffffffff0000ul))
)
);
}
inline __m256i
seqan_mm256_i64sign_extend_epis32(__m256i const & v)
{
return _mm256_or_si256( // extend sign (v | hi-bits)
v,
_mm256_and_si256( // select hi-bits (hi-bits = msk & 0xffffffffffff0000ul)
_mm256_sub_epi64( // msk = msb - 1
_mm256_andnot_si256( //msb = ~v & 0x80000000 (select msb)
v,
_mm256_set1_epi64x(0x80000000)
),
_mm256_set1_epi64x(1)
),
_mm256_set1_epi64x(static_cast<uint64_t>(0xffffffff00000000ul))
)
);
}
// --------------------------------------------------------------------------
// _gather (256bit)
// --------------------------------------------------------------------------
template <typename TValue, typename TSize, TSize SCALE>
inline __m256i
seqan_mm256_i8gather_epi(TValue const * memAddr,
__m256i const & idx,
std::integral_constant<TSize, SCALE> const & /*scale*/)
{
// mem: ( 0, 3, 6, 9 | 12, 15, 18, 21 | 24, 27, 30, 33 | 36, 39, 42, 45 || 48, 51, 54, 57 | 60, 63, 66, 69 | 72, 75, 78, 81 | 84, 87, 90, 93)
// idx: (31, 30, 29, 28 | 27, 26, 25, 24 | 23, 22, 21, 20 | 19, 18, 17, 16 || 15, 14, 13, 12 | 11, 10, 9, 8 | 7, 6, 5, 4 | 3, 2, 1, 0)
// pack: (93, 90, 87, 84 | 81, 78, 75, 72 | 69, 66, 63, 60 | 57, 54, 51, 48 || 45, 42, 39, 36 | 33, 30, 27, 24 | 21, 18, 15, 12 | 9, 6, 3, 0)
return _mm256_packus_epi16(
// pckLow: (93, 0, 90, 0 | 87, 0, 84, 0 | 81, 0, 78, 0 | 75, 0, 72, 0 || 45, 0, 42, 0 | 39, 0, 36, 0 | 33, 0, 30, 0 | 27, 0, 24, 0)
_mm256_packus_epi16(
// mskLL: (93, 0, 0, 0 | 90, 0, 0, 0 | 87, 0, 0, 0 | 84, 0, 0, 0 || 45, 0, 0, 0 | 42, 0, 0, 0 | 39, 0, 0, 0 | 36, 0, 0, 0)
_mm256_and_si256(
// gtrLL: (93, 31, 30, 29 | 90, 93, 31, 30 | 87, 90, 93, 31 | 84, 87, 90, 93 || 45, 48, 51, 54 | 42, 45, 48, 51 | 39, 42, 45, 48 | 36, 39, 42, 45)
_mm256_i32gather_epi32(
(const int *) memAddr,
// lowlow: (31, 0, 0, 0 | 30, 0, 0, 0 | 29, 0, 0, 0 | 28, 0, 0, 0 || 15, 0, 0, 0 | 14, 0, 0, 0 | 13, 0, 0, 0 | 12, 0, 0, 0)
_mm256_shuffle_epi8(idx, __m256i {
~0xFF000000FFl | 0x0100000000, ~0xFF000000FFl | 0x0300000002,
~0xFF000000FFl | 0x0100000000, ~0xFF000000FFl | 0x0300000002
}),
SCALE
),
_mm256_set1_epi32(0xFF)
),
// mskLH: (81, 0, 0, 0 | 78, 0, 0, 0 | 75, 0, 0, 0 | 72, 0, 0, 0 || 33, 0, 0, 0 | 30, 0, 0, 0 | 27, 0, 0, 0 | 24, 0, 0, 0)
_mm256_and_si256(
// gtrLH: (81, 84, 87, 90 | 78, 81, 84, 87 | 75, 78, 81, 84 | 72, 75, 78, 81 || 33, 36, 39, 42 | 30, 33, 36, 39 | 27, 30, 33, 36 | 24, 27, 30, 33)
_mm256_i32gather_epi32(
(const int *) memAddr,
// lowhig: (27, 0, 0, 0 | 26, 0, 0, 0 | 25, 0, 0, 0 | 24, 0, 0, 0 || 11, 0, 0, 0 | 10, 0, 0, 0 | 9, 0, 0, 0 | 8, 0, 0, 0)
_mm256_shuffle_epi8(idx, __m256i {
~0xFF000000FFl | 0x0500000004, ~0xFF000000FFl | 0x0700000006,
~0xFF000000FFl | 0x0500000004, ~0xFF000000FFl | 0x0700000006
}),
SCALE
),
_mm256_set1_epi32(0xFF)
)
),
// pckHih: (69, 0, 66, 0 | 63, 0, 60, 0 | 57, 0, 54, 0 | 51, 0, 48, 0 || 21, 0, 18, 0 | 15, 0, 12, 0 | 9, 0, 6, 0 | 3, 0, 0, 0)
_mm256_packus_epi16(
// mskHL: (69, 0, 0, 0 | 66, 0, 0, 0 | 63, 0, 0, 0 | 60, 0, 0, 0 || 21, 0, 0, 0 | 18, 0, 0, 0 | 15, 0, 0, 0 | 12, 0, 0, 0)
_mm256_and_si256(
// gtrHL: (69, 72, 75, 78 | 66, 69, 72, 75 | 63, 66, 69, 72 | 60, 63, 66, 69 || 21, 24, 27, 30 | 18, 21, 24, 27 | 15, 18, 21, 24 | 12, 15, 18, 21)
_mm256_i32gather_epi32(
(const int *) memAddr,
// higlow: (23, 0, 0, 0 | 22, 0, 0, 0 | 21, 0, 0, 0 | 20, 0, 0, 0 || 7, 0, 0, 0 | 6, 0, 0, 0 | 5, 0, 0, 0 | 4, 0, 0, 0)
_mm256_shuffle_epi8(idx, __m256i {
~0xFF000000FFl | 0x0900000008, ~0xFF000000FFl | 0x0B0000000A,
~0xFF000000FFl | 0x0900000008, ~0xFF000000FFl | 0x0B0000000A
}),
SCALE
),
_mm256_set1_epi32(0xFF)
),
// mskHH: (57, 0, 0, 0 | 54, 0, 0, 0 | 51, 0, 0, 0 | 48, 0, 0, 0 || 9, 0, 0, 0 | 6, 0, 0, 0 | 3, 0, 0, 0 | 0, 0, 0, 0)
_mm256_and_si256(
// gtrHH: (57, 60, 63, 66 | 54, 57, 60, 63 | 51, 54, 57, 60 | 48, 51, 54, 57 || 9, 12, 15, 18 | 6, 9, 12, 15 | 3, 6, 9, 12 | 0, 3, 6, 9)
_mm256_i32gather_epi32(
(const int *) memAddr,
// highig: (19, 0, 0, 0 | 18, 0, 0, 0 | 17, 0, 0, 0 | 16, 0, 0, 0 || 3, 0, 0, 0 | 2, 0, 0, 0 | 1, 0, 0, 0 | 0, 0, 0, 0)
_mm256_shuffle_epi8(idx, __m256i {
~0xFF000000FFl | 0x0D0000000C, ~0xFF000000FFl | 0x0F0000000E,
~0xFF000000FFl | 0x0D0000000C, ~0xFF000000FFl | 0x0F0000000E
}),
SCALE
),
_mm256_set1_epi32(0xFF)
)
)
);
}
template <typename TValue, typename TSize, TSize SCALE>
inline __m256i
seqan_mm256_i16gather_epi(TValue const * memAddr,
__m256i const & idx,
std::integral_constant<TSize, SCALE> const & /*scale*/)
{
using TUnsignedValue = typename MakeUnsigned<TValue>::Type;
// The cast makes sure that the max value of TValue = (u)int64_t and
// (u)int32_t will be max value of int16_t (i.e. `~0` in int16_t), because
// the resulting __m256i can only hold int16_t values.
//
// NOTE(marehr): the masking is only needed for TValue = (u)int8_t and
// (u)int16_t. It could be omitted if _mm256_packus_epi32 would be exchanged
// by _mm256_packs_epi32, because for (u)int32_t and (u)int64_t the masking
// operations are basically the identity function.
constexpr int const mask = static_cast<uint16_t>(MaxValue<TUnsignedValue>::VALUE);
// 1. Unpack low idx values and interleave with 0 and gather from memAddr.
// 2. Unpack high idx values and interleave with 0, than gather from memAddr.
// 3. Merge 2 8x32 vectors into 1x16 vector by signed saturation. This operation reverts the interleave by the unpack operations above.
//
// The following is an example for SimdVector<uint16_t, 16> idx and uint16_t
// const * memAddr:
// mem: ( 0, 0, 3, 0 | 6, 0, 9, 0 | 12, 0, 15, 0 | 18, 0, 21, 0 || 24, 0, 27, 0 | 30, 0, 33, 0 | 36, 0, 39, 0 | 42, 0, 45, 0)
// idx: (15, 0, 14, 0 | 13, 0, 12, 0 | 11, 0, 10, 0 | 9, 0, 8, 0 || 7, 0, 6, 0 | 5, 0, 4, 0 | 3, 0, 2, 0 | 1, 0, 0, 0)
// pack: (45, 0, 42, 0 | 39, 0, 36, 0 | 33, 0, 30, 0 | 27, 0, 24, 0 || 21, 0, 18, 0 | 15, 0, 12, 0 | 9, 0, 6, 0 | 3, 0, 0, 0)
return _mm256_packus_epi32(
// mskLow: (45, 0, 0, 0 | 42, 0, 0, 0 | 39, 0, 0, 0 | 36, 0, 0, 0 || 21, 0, 0, 0 | 18, 0, 0, 0 | 15, 0, 0, 0 | 12, 0, 0, 0)
_mm256_and_si256(
// gtrLow: (45, 0, 15, 0 | 42, 0, 45, 0 | 39, 0, 42, 0 | 36, 0, 39, 0 || 21, 0, 24, 0 | 18, 0, 21, 0 | 15, 0, 18, 0 | 12, 0, 15, 0)
_mm256_i32gather_epi32(
(const int *) memAddr,
// low: (15, 0, 0, 0 | 14, 0, 0, 0 | 13, 0, 0, 0 | 12, 0, 0, 0 || 7, 0, 0, 0 | 6, 0, 0, 0 | 5, 0, 0, 0 | 4, 0, 0, 0)
_mm256_unpacklo_epi16(
idx, _mm256_set1_epi16(0)
),
SCALE
),
_mm256_set1_epi32(mask)
),
// mskHih: (33, 0, 0, 0 | 30, 0, 0, 0 | 27, 0, 0, 0 | 24, 0, 0, 0 || 9, 0, 0, 0 | 6, 0, 0, 0 | 3, 0, 0, 0 | 0, 0, 0, 0)
_mm256_and_si256(
// gtrHih: (33, 0, 36, 0 | 30, 0, 33, 0 | 27, 0, 30, 0 | 24, 0, 27, 0 || 9, 0, 12, 0 | 6, 0, 9, 0 | 3, 0, 6, 0 | 0, 0, 3, 0)
_mm256_i32gather_epi32(
(const int *) memAddr,
// high: (11, 0, 0, 0 | 10, 0, 0, 0 | 9, 0, 0, 0 | 8, 0, 0, 0 || 3, 0, 0, 0 | 2, 0, 0, 0 | 1, 0, 0, 0 | 0, 0, 0, 0)
_mm256_unpackhi_epi16(
idx, _mm256_set1_epi16(0)
),
SCALE
),
_mm256_set1_epi32(mask)
)
);
}
template <typename TValue, typename TSize, TSize SCALE>
inline __m256i
seqan_mm256_i32gather_epi(TValue const * memAddr,
__m256i const & idx,
std::integral_constant<TSize, SCALE> const & /*scale*/)
{
using TUnsignedValue = typename MakeUnsigned<TValue>::Type;
constexpr auto const mask = static_cast<uint32_t>(MaxValue<TUnsignedValue>::VALUE);
return _mm256_and_si256(
_mm256_i32gather_epi32((const int *) memAddr, idx, SCALE),
_mm256_set1_epi32(mask)
);
}
template <typename TValue, typename TSize, TSize SCALE>
inline __m256i
seqan_mm256_i64gather_epi(TValue const * memAddr,
__m256i const & idx,
std::integral_constant<TSize, SCALE> const & /*scale*/)
{
using TUnsignedValue = typename MakeUnsigned<TValue>::Type;
constexpr auto const mask = static_cast<uint64_t>(MaxValue<TUnsignedValue>::VALUE);
return _mm256_and_si256(
_mm256_i64gather_epi64((const long long *) memAddr, idx, SCALE),
_mm256_set1_epi64x(mask)
);
}
template <typename TValue, typename TSimdVector, typename TSize, TSize SCALE>
inline TSimdVector
_gather(TValue const * memAddr,
TSimdVector const & idx,
std::integral_constant<TSize, SCALE> const & scale,
SimdParams_<32, 32>)
{
return SEQAN_VECTOR_CAST_(TSimdVector,
seqan_mm256_i8gather_epi(
memAddr,
SEQAN_VECTOR_CAST_(__m256i const &, idx),
scale
)
);
}
template <typename TSimdVector, typename TSize, TSize SCALE>
inline TSimdVector
_gather(int8_t const * memAddr,
TSimdVector const & idx,
std::integral_constant<TSize, SCALE> const & scale,
SimdParams_<32, 16>)
{
// Note that memAddr is a signed integer type, thus a cast would extend the
// sign. E.g., -3 = 253 in 8 bit, but would be 65533 in 16 bit.
// Use _gather(uint8_t) and extend the sign to [u]int16_t.
return SEQAN_VECTOR_CAST_(
TSimdVector,
seqan_mm256_i16sign_extend_epis8(
seqan_mm256_i16gather_epi(
memAddr,
SEQAN_VECTOR_CAST_(__m256i const &, idx),
scale
)
)
);
}
template <typename TValue, typename TSimdVector, typename TSize, TSize SCALE>
inline TSimdVector
_gather(TValue const * memAddr,
TSimdVector const & idx,
std::integral_constant<TSize, SCALE> const & scale,
SimdParams_<32, 16>)
{
return SEQAN_VECTOR_CAST_(
TSimdVector,
seqan_mm256_i16gather_epi(
memAddr,
SEQAN_VECTOR_CAST_(__m256i const &, idx),
scale
)
);
}
template <typename TSimdVector, typename TSize, TSize SCALE>
inline TSimdVector
_gather(int8_t const * memAddr,
TSimdVector const & idx,
std::integral_constant<TSize, SCALE> const & scale,
SimdParams_<32, 8>)
{
// Note that memAddr is a signed integer type, thus a cast would extend the
// sign.
return SEQAN_VECTOR_CAST_(
TSimdVector,
seqan_mm256_i32sign_extend_epis8(
seqan_mm256_i32gather_epi(
memAddr,
SEQAN_VECTOR_CAST_(__m256i const &, idx),
scale
)
)
);
}
template <typename TSimdVector, typename TSize, TSize SCALE>
inline TSimdVector
_gather(int16_t const * memAddr,
TSimdVector const & idx,
std::integral_constant<TSize, SCALE> const & scale,
SimdParams_<32, 8>)
{
// Note that memAddr is a signed integer type, thus a cast would extend the
// sign.
return SEQAN_VECTOR_CAST_(
TSimdVector,
seqan_mm256_i32sign_extend_epis16(
seqan_mm256_i32gather_epi(
memAddr,
SEQAN_VECTOR_CAST_(__m256i const &, idx),
scale
)
)
);
}
template <typename TValue, typename TSimdVector, typename TSize, TSize SCALE>
inline TSimdVector
_gather(TValue const * memAddr,
TSimdVector const & idx,
std::integral_constant<TSize, SCALE> const & scale,
SimdParams_<32, 8>)
{
return SEQAN_VECTOR_CAST_(
TSimdVector,
seqan_mm256_i32gather_epi(
memAddr,
SEQAN_VECTOR_CAST_(__m256i const &, idx),
scale
)
);
}
template <typename TSimdVector, typename TSize, TSize SCALE>
inline TSimdVector
_gather(int8_t const * memAddr,
TSimdVector const & idx,
std::integral_constant<TSize, SCALE> const & scale,
SimdParams_<32, 4>)
{
return SEQAN_VECTOR_CAST_(
TSimdVector,
seqan_mm256_i64sign_extend_epis8(
seqan_mm256_i64gather_epi(
memAddr,
SEQAN_VECTOR_CAST_(__m256i const &, idx),
scale
)
)
);
}
template <typename TSimdVector, typename TSize, TSize SCALE>
inline TSimdVector
_gather(int16_t const * memAddr,
TSimdVector const & idx,
std::integral_constant<TSize, SCALE> const & scale,
SimdParams_<32, 4>)
{
return SEQAN_VECTOR_CAST_(
TSimdVector,
seqan_mm256_i64sign_extend_epis16(
seqan_mm256_i64gather_epi(
memAddr,
SEQAN_VECTOR_CAST_(__m256i const &, idx),
scale
)
)
);
}
template <typename TSimdVector, typename TSize, TSize SCALE>
inline TSimdVector
_gather(int32_t const * memAddr,
TSimdVector const & idx,
std::integral_constant<TSize, SCALE> const & scale,
SimdParams_<32, 4>)
{
return SEQAN_VECTOR_CAST_(
TSimdVector,
seqan_mm256_i64sign_extend_epis32(
seqan_mm256_i64gather_epi(
memAddr,
SEQAN_VECTOR_CAST_(__m256i const &, idx),
scale
)
)
);
}
template <typename TValue, typename TSimdVector, typename TSize, TSize SCALE>
inline TSimdVector
_gather(TValue const * memAddr,
TSimdVector const & idx,
std::integral_constant<TSize, SCALE> const & scale,
SimdParams_<32, 4>)
{
return SEQAN_VECTOR_CAST_(
TSimdVector,
seqan_mm256_i64gather_epi(
memAddr,
SEQAN_VECTOR_CAST_(__m256i const &, idx),
scale
)
);
}
// --------------------------------------------------------------------------
// _shuffleVector (256bit)
// --------------------------------------------------------------------------
inline __m256i
seqan_m256_shuffle_epi8(__m256i const & vector, __m256i const & indices)
{
return _mm256_xor_si256(
// shuffle bytes from the lower bytes of vector
_mm256_shuffle_epi8(
// repeat twice the low bytes of vector in a new __m256i vector i.e.
// vh[127:0] = v[127:0]
// vh[255:128] = v[127:0]
_mm256_broadcastsi128_si256(
_mm256_extracti128_si256(vector, 0)
),
// ((indices[i] << 3) & 0b1000 0000) ^ indices[i]:
// Adds the 5th bit of indices[i] as most significant bit. If the
// 5th bit is set, that means that indices[i] >= 16.
// r = _mm256_shuffle_epi8(vl, indices) will set r[i] = 0 if the
// most significant bit of indices[i] is 1. Since this bit is the
// 5th bit, r[i] = 0 if indices[i] >= 16 and r[i] = vl[indices[i]]
// if indices[i] < 16.
_mm256_xor_si256(
_mm256_and_si256(
_mm256_slli_epi16(indices, 3),
_mm256_set1_epi8(-127) // 0b1000 0000
),
indices
)
),
// shuffle bytes from the higher bytes of vector
_mm256_shuffle_epi8(
// repeat twice the higher bytes of vector in a new __m256i vector
// i.e.
// vh[127:0] = v[255:128]
// vh[255:128] = v[255:128]
_mm256_broadcastsi128_si256(
_mm256_extracti128_si256(vector, 1)
),
// indices[i] - 16:
// r = _mm256_shuffle_epi8(vh, indices)
// will return r[i] = 0 if the most significant bit of the byte
// indices[i] is 1. Thus, indices[i] - 16 will select all high
// bytes in vh, i.e. r[i] = vh[indices[i] - 16], if indices[i] >=
// 16 and r[i] = 0 if indices[i] < 16.
_mm256_sub_epi8(
indices,
_mm256_set1_epi8(16)
)
)
);
}
inline __m256i
seqan_m256_shuffle_epi16(const __m256i a, const __m256i b)
{
// multiply by 2
__m256i idx = _mm256_slli_epi16(
_mm256_permute4x64_epi64(b, 0b01010000),
1
);
// _print(_mm256_add_epi8(idx, _mm256_set1_epi8(1)));
// _print( _mm256_unpacklo_epi8(
// idx,
// _mm256_add_epi8(idx, _mm256_set1_epi8(1))
// ));
return seqan_m256_shuffle_epi8(
a,
// interleave idx[15:0] = 2*indices[15], ..., 2*indices[0]
// with idx[15:0]+1 = 2*indices[15]+1, ..., 2*indices[0]+1
// => 2*indices[15]+1, 2*indices[15], ..., 2*indices[0]+1, 2*indices[0]
_mm256_unpacklo_epi8(
idx,
_mm256_add_epi8(idx, _mm256_set1_epi8(1))
)
);
}
inline __m256i
seqan_m256_shuffle_epi32(const __m256i a, const __m256i b)
{
// multiply by 4
__m256i idx = _mm256_slli_epi16(
_mm256_permutevar8x32_epi32(b, __m256i {0x0, 0x0, 0x1, 0x0}),
2
);
return seqan_m256_shuffle_epi8(
a,
// interleave 4*indices[7]+1, 4*indices[7]+0; ..., 4*indices[0]+1, 4*indices[0]+0
// with 4*indices[7]+3, 4*indices[7]+2; ..., 4*indices[0]+3, 4*indices[0]+2
// => 4*indices[7]+3, 4*indices[7]+2; 4*indices[7]+1, 4*indices[7]+0;
// ...
// 4*indices[0]+3, 4*indices[0]+2; 4*indices[0]+1, 4*indices[0]+0
_mm256_unpacklo_epi16(
// interleave idx[7:0]+0 = 4*indices[7]+0; ...; 4*indices[0]+0
// with idx[7:0]+1 = 4*indices[7]+1; ...; 4*indices[0]+1
// => 4*indices[7]+1; 4*indices[7]+0; ...; 4*indices[0]+1; 4*indices[0]+0
_mm256_unpacklo_epi8(
idx,
_mm256_add_epi8(idx, _mm256_set1_epi8(1))
),
// interleave idx[7:0]+2 = 4*indices[7]+2; ...; 4*indices[0]+2
// with idx[7:0]+3 = 4*indices[7]+3; ...; 4*indices[0]+3
// => 4*indices[7]+3; 4*indices[7]+2; ...; 4*indices[0]+3; 4*indices[0]+2
_mm256_unpacklo_epi8(
_mm256_add_epi8(idx, _mm256_set1_epi8(2)),
_mm256_add_epi8(idx, _mm256_set1_epi8(3))
)
));
}
#define seqan_mm256_set_m128i(v0, v1) _mm256_insertf128_si256(_mm256_castsi128_si256(v1), (v0), 1)
inline __m256i
seqan_m256_shuffle_epi64(const __m256i a, const __m256i b)
{
__m128i lowidx = _mm256_extracti128_si256(
// multiply by 8
_mm256_slli_epi16(b, 3),
0
);
__m256i idx = seqan_mm256_set_m128i(
_mm_srli_si128(lowidx, 2),
lowidx
);
return seqan_m256_shuffle_epi8(
a,
_mm256_unpacklo_epi32(
// interleave 8*indices[3]+1, 8*indices[3]+0; ..., 8*indices[0]+1, 8*indices[0]+0
// with 8*indices[3]+3, 8*indices[3]+2; ..., 8*indices[0]+3, 8*indices[0]+2
// => 8*indices[3]+3, 8*indices[3]+2; 8*indices[3]+1, 8*indices[3]+0;
// ...
// 8*indices[0]+3, 8*indices[0]+2; 8*indices[0]+1, 8*indices[0]+0
_mm256_unpacklo_epi16(
// interleave idx[3:0]+0 = 8*indices[3]+0; ...; 8*indices[0]+0
// with idx[3:0]+1 = 8*indices[3]+1; ...; 8*indices[0]+1
// => 8*indices[3]+1; 8*indices[3]+0; ...; 8*indices[0]+1; 8*indices[0]+0
_mm256_unpacklo_epi8(
idx,
_mm256_add_epi8(idx, _mm256_set1_epi8(1))
),
// interleave idx[3:0]+2 = 8*indices[3]+2; ...; 8*indices[0]+2
// with idx[3:0]+3 = 8*indices[3]+3; ...; 8*indices[0]+3
// => 8*indices[3]+3; 8*indices[3]+2; ...; 8*indices[0]+3; 8*indices[0]+2
_mm256_unpacklo_epi8(
_mm256_add_epi8(idx, _mm256_set1_epi8(2)),
_mm256_add_epi8(idx, _mm256_set1_epi8(3))
)
),
// interleave 8*indices[3]+5, 8*indices[3]+4; ..., 8*indices[0]+5, 8*indices[0]+4
// with 8*indices[3]+7, 8*indices[3]+6; ..., 8*indices[0]+7, 8*indices[0]+6
// => 8*indices[3]+7, 8*indices[3]+6; 8*indices[3]+5, 8*indices[3]+4;
// ...
// 8*indices[0]+7, 8*indices[0]+6; 8*indices[0]+5, 8*indices[0]+4
_mm256_unpacklo_epi16(
// interleave idx[3:0]+4 = 8*indices[3]+4; ...; 8*indices[0]+4
// with idx[3:0]+5 = 8*indices[3]+5; ...; 8*indices[0]+5
// => 8*indices[3]+5; 8*indices[3]+4; ...; 8*indices[0]+5; 8*indices[0]+4
_mm256_unpacklo_epi8(
_mm256_add_epi8(idx, _mm256_set1_epi8(4)),
_mm256_add_epi8(idx, _mm256_set1_epi8(5))
),
// interleave idx[3:0]+6 = 8*indices[3]+6; ...; 8*indices[0]+6
// with idx[3:0]+7 = 8*indices[3]+7; ...; 8*indices[0]+7
// => 8*indices[3]+7; 8*indices[3]+6; ...; 8*indices[0]+7; 8*indices[0]+6
_mm256_unpacklo_epi8(
_mm256_add_epi8(idx, _mm256_set1_epi8(6)),
_mm256_add_epi8(idx, _mm256_set1_epi8(7))
)
)
)
);
}
template <typename TSimdVector1, typename TSimdVector2>
inline TSimdVector1
_shuffleVector(TSimdVector1 const & vector, TSimdVector2 const & indices, SimdParams_<32, 16>, SimdParams_<16, 16>)
{
// copy 2nd 64bit word to 3rd, compute 2*idx
__m256i idx = _mm256_slli_epi16(_mm256_permute4x64_epi64(_mm256_castsi128_si256(SEQAN_VECTOR_CAST_(const __m128i &, indices)), 0x50), 1);
// interleave with 2*idx+1 and call shuffle
return SEQAN_VECTOR_CAST_(TSimdVector1,
_mm256_shuffle_epi8(
SEQAN_VECTOR_CAST_(const __m256i &, vector),
_mm256_unpacklo_epi8(
idx,
_mm256_add_epi8(
idx, _mm256_set1_epi8(1)
)
)
)
);
}
template <typename TSimdVector1, typename TSimdVector2>
inline TSimdVector1
_shuffleVector(TSimdVector1 const & vector, TSimdVector2 const & indices, SimdParams_<32, 32>, SimdParams_<32, 32>)
{
return SEQAN_VECTOR_CAST_(TSimdVector1, seqan_m256_shuffle_epi8(
SEQAN_VECTOR_CAST_(const __m256i &, vector),
SEQAN_VECTOR_CAST_(const __m256i &, indices)
));
}
template <typename TSimdVector1, typename TSimdVector2>
inline TSimdVector1
_shuffleVector(TSimdVector1 const & vector, TSimdVector2 const & indices, SimdParams_<32, 16>, SimdParams_<32, 32>)
{
return SEQAN_VECTOR_CAST_(TSimdVector1, seqan_m256_shuffle_epi16(
SEQAN_VECTOR_CAST_(const __m256i &, vector),
SEQAN_VECTOR_CAST_(const __m256i &, indices)
));
}
template <typename TSimdVector1, typename TSimdVector2>
inline TSimdVector1
_shuffleVector(TSimdVector1 const & vector, TSimdVector2 const & indices, SimdParams_<32, 8>, SimdParams_<32, 32>)
{
return SEQAN_VECTOR_CAST_(TSimdVector1, seqan_m256_shuffle_epi32(
SEQAN_VECTOR_CAST_(const __m256i &, vector),
SEQAN_VECTOR_CAST_(const __m256i &, indices)
));
}
template <typename TSimdVector1, typename TSimdVector2>
inline TSimdVector1
_shuffleVector(TSimdVector1 const & vector, TSimdVector2 const & indices, SimdParams_<32, 4>, SimdParams_<32, 32>)
{
return SEQAN_VECTOR_CAST_(TSimdVector1, seqan_m256_shuffle_epi64(
SEQAN_VECTOR_CAST_(const __m256i &, vector),
SEQAN_VECTOR_CAST_(const __m256i &, indices)
));
}
// --------------------------------------------------------------------------
// _transposeMatrix (256bit)
// --------------------------------------------------------------------------
// emulate missing _mm256_unpacklo_epi128/_mm256_unpackhi_epi128 instructions
inline __m256i _mm256_unpacklo_epi128(__m256i const & a, __m256i const & b)
{
return _mm256_permute2x128_si256(a, b, 0x20);
// return _mm256_inserti128_si256(a, _mm256_extracti128_si256(b, 0), 1);
}
inline __m256i _mm256_unpackhi_epi128(__m256i const & a, __m256i const & b)
{
return _mm256_permute2x128_si256(a, b, 0x31);
// return _mm256_inserti128_si256(b, _mm256_extracti128_si256(a, 1), 0);
}
template <typename TSimdVector>
inline void
_transposeMatrix(TSimdVector matrix[], SimdMatrixParams_<32, 32, 8>)
{
// we need a look-up table to reverse the lowest 4 bits
// in order to place the permute the transposed rows
static const unsigned char bitRev[] = { 0, 8, 4,12, 2,10, 6,14, 1, 9, 5,13, 3,11, 7,15,
16,24,20,28,18,26,22,30,17,25,21,29,19,27,23,31};
// transpose a 32x32 byte matrix
__m256i tmp1[32];
for (int i = 0; i < 16; ++i)
{
tmp1[i] = _mm256_unpacklo_epi8(
SEQAN_VECTOR_CAST_(const __m256i &, matrix[2*i]),
SEQAN_VECTOR_CAST_(const __m256i &, matrix[2*i+1])
);
tmp1[i+16] = _mm256_unpackhi_epi8(
SEQAN_VECTOR_CAST_(const __m256i &, matrix[2*i]),
SEQAN_VECTOR_CAST_(const __m256i &, matrix[2*i+1])
);
}
__m256i tmp2[32];
for (int i = 0; i < 16; ++i)
{
tmp2[i] = _mm256_unpacklo_epi16(tmp1[2*i], tmp1[2*i+1]);
tmp2[i+16] = _mm256_unpackhi_epi16(tmp1[2*i], tmp1[2*i+1]);
}
for (int i = 0; i < 16; ++i)
{
tmp1[i] = _mm256_unpacklo_epi32(tmp2[2*i], tmp2[2*i+1]);
tmp1[i+16] = _mm256_unpackhi_epi32(tmp2[2*i], tmp2[2*i+1]);
}
for (int i = 0; i < 16; ++i)
{
tmp2[i] = _mm256_unpacklo_epi64(tmp1[2*i], tmp1[2*i+1]);
tmp2[i+16] = _mm256_unpackhi_epi64(tmp1[2*i], tmp1[2*i+1]);
}
for (int i = 0; i < 16; ++i)
{
matrix[bitRev[i]] = SEQAN_VECTOR_CAST_(TSimdVector, _mm256_unpacklo_epi128(tmp2[2*i],tmp2[2*i+1]));
matrix[bitRev[i+16]] = SEQAN_VECTOR_CAST_(TSimdVector, _mm256_unpackhi_epi128(tmp2[2*i],tmp2[2*i+1]));
}
}
// --------------------------------------------------------------------------
// Function _testAllZeros (256bit)
// --------------------------------------------------------------------------
template <typename TSimdVector>
SEQAN_FUNC_ENABLE_IF(Is<SimdVectorConcept<TSimdVector> >, int)
inline _testAllZeros(TSimdVector const & vector, TSimdVector const & mask, SimdParams_<32>)
{
return _mm256_testz_si256(SEQAN_VECTOR_CAST_(const __m256i &, vector),
SEQAN_VECTOR_CAST_(const __m256i &, mask));
}
// --------------------------------------------------------------------------
// Function _testAllOnes (256bit)
// --------------------------------------------------------------------------
template <typename TSimdVector>
inline int _testAllOnes(TSimdVector const & vector, SimdParams_<32>)
{
__m256i vec = SEQAN_VECTOR_CAST_(const __m256i &, vector);
return _mm256_testc_si256(vec, _mm256_cmpeq_epi32(vec, vec));
}
} // namespace seqan
#endif // SEQAN_INCLUDE_SEQAN_SIMD_SIMD_BASE_SEQAN_IMPL_AVX2_H_
|