|
Lines 111-117
Link Here
|
| 111 |
#endif /* CRC32_ARM64 */ |
111 |
#endif /* CRC32_ARM64 */ |
| 112 |
|
112 |
|
| 113 |
#ifdef CRC32_ARM64_DEFAULT |
113 |
#ifdef CRC32_ARM64_DEFAULT |
|
|
114 |
#ifndef __FreeBSD__ |
| 114 |
#include <asm/hwcap.h> |
115 |
#include <asm/hwcap.h> |
|
|
116 |
#endif |
| 115 |
#include <sys/auxv.h> |
117 |
#include <sys/auxv.h> |
| 116 |
#endif /* CRC32_ARM64_DEFAULT */ |
118 |
#endif /* CRC32_ARM64_DEFAULT */ |
| 117 |
|
119 |
|
|
Lines 360-367
Link Here
|
| 360 |
#endif /* CRC32_ARM64_APPLE */ |
362 |
#endif /* CRC32_ARM64_APPLE */ |
| 361 |
|
363 |
|
| 362 |
#ifdef CRC32_ARM64_DEFAULT |
364 |
#ifdef CRC32_ARM64_DEFAULT |
|
|
365 |
#ifdef __FreeBSD__ |
| 366 |
bool can_use_crc32() { |
| 367 |
unsigned long capabilities; |
| 368 |
|
| 369 |
if (elf_aux_info(AT_HWCAP, &capabilities, sizeof(unsigned long))) |
| 370 |
return false; |
| 371 |
return capabilities & HWCAP_CRC32; |
| 372 |
} |
| 373 |
bool can_use_poly_mul() { |
| 374 |
unsigned long capabilities; |
| 375 |
|
| 376 |
if (elf_aux_info(AT_HWCAP, &capabilities, sizeof(unsigned long))) |
| 377 |
return false; |
| 378 |
return capabilities & HWCAP_CRC32; |
| 379 |
} |
| 380 |
#else |
| 363 |
bool can_use_crc32() { return getauxval(AT_HWCAP) & HWCAP_CRC32; } |
381 |
bool can_use_crc32() { return getauxval(AT_HWCAP) & HWCAP_CRC32; } |
| 364 |
bool can_use_poly_mul() { return getauxval(AT_HWCAP) & HWCAP_PMULL; } |
382 |
bool can_use_poly_mul() { return getauxval(AT_HWCAP) & HWCAP_PMULL; } |
|
|
383 |
#endif |
| 365 |
#endif /* CRC32_ARM64_DEFAULT */ |
384 |
#endif /* CRC32_ARM64_DEFAULT */ |
| 366 |
|
385 |
|
| 367 |
/** A helper template to statically unroll a loop with a fixed number of |
386 |
/** A helper template to statically unroll a loop with a fixed number of |
|
Lines 470-498
Link Here
|
| 470 |
|
489 |
|
| 471 |
#ifdef CRC32_ARM64 |
490 |
#ifdef CRC32_ARM64 |
| 472 |
#ifdef CRC32_ARM64_DEFAULT |
491 |
#ifdef CRC32_ARM64_DEFAULT |
|
|
492 |
#ifdef __clang__ |
| 493 |
MY_ATTRIBUTE((target("crc"))) |
| 494 |
#else |
| 473 |
MY_ATTRIBUTE((target("+crc"))) |
495 |
MY_ATTRIBUTE((target("+crc"))) |
|
|
496 |
#endif |
| 474 |
#endif /* CRC32_ARM64_DEFAULT */ |
497 |
#endif /* CRC32_ARM64_DEFAULT */ |
|
|
498 |
#ifdef __FreeBSD__ |
| 499 |
#include <arm_acle.h> |
| 475 |
uint32_t crc32_impl::update(uint32_t crc, unsigned char data) { |
500 |
uint32_t crc32_impl::update(uint32_t crc, unsigned char data) { |
| 476 |
return __crc32cb(crc, data); |
501 |
__crc32cb(crc, data); |
|
|
502 |
return crc; |
| 477 |
} |
503 |
} |
|
|
504 |
uint32_t crc32_impl::update(uint32_t crc, uint16_t data) { |
| 505 |
__crc32ch(crc, data); |
| 506 |
return crc; |
| 507 |
} |
| 508 |
uint32_t crc32_impl::update(uint32_t crc, uint32_t data) { |
| 509 |
__crc32cw(crc, data); |
| 510 |
return crc; |
| 511 |
} |
| 512 |
uint64_t crc32_impl::update(uint64_t crc, uint64_t data) { |
| 513 |
__crc32cd(crc, data); |
| 514 |
return crc; |
| 515 |
} |
| 516 |
#else |
| 478 |
#ifdef CRC32_ARM64_DEFAULT |
517 |
#ifdef CRC32_ARM64_DEFAULT |
|
|
518 |
#ifdef __clang__ |
| 519 |
MY_ATTRIBUTE((target("crc"))) |
| 520 |
#else |
| 479 |
MY_ATTRIBUTE((target("+crc"))) |
521 |
MY_ATTRIBUTE((target("+crc"))) |
|
|
522 |
#endif |
| 480 |
#endif /* CRC32_ARM64_DEFAULT */ |
523 |
#endif /* CRC32_ARM64_DEFAULT */ |
| 481 |
uint32_t crc32_impl::update(uint32_t crc, uint16_t data) { |
524 |
uint32_t crc32_impl::update(uint32_t crc, uint16_t data) { |
| 482 |
return __crc32ch(crc, data); |
525 |
__crc32ch(crc, data); |
|
|
526 |
return crc; |
| 483 |
} |
527 |
} |
| 484 |
#ifdef CRC32_ARM64_DEFAULT |
528 |
#ifdef CRC32_ARM64_DEFAULT |
|
|
529 |
#ifdef __clang__ |
| 530 |
MY_ATTRIBUTE((target("crc"))) |
| 531 |
#else |
| 485 |
MY_ATTRIBUTE((target("+crc"))) |
532 |
MY_ATTRIBUTE((target("+crc"))) |
|
|
533 |
#endif |
| 486 |
#endif /* CRC32_ARM64_DEFAULT */ |
534 |
#endif /* CRC32_ARM64_DEFAULT */ |
| 487 |
uint32_t crc32_impl::update(uint32_t crc, uint32_t data) { |
535 |
uint32_t crc32_impl::update(uint32_t crc, uint32_t data) { |
| 488 |
return __crc32cw(crc, data); |
536 |
__crc32cw(crc, data); |
|
|
537 |
return crc; |
| 489 |
} |
538 |
} |
| 490 |
#ifdef CRC32_ARM64_DEFAULT |
539 |
#ifdef CRC32_ARM64_DEFAULT |
|
|
540 |
#ifdef __clang__ |
| 541 |
MY_ATTRIBUTE((target("crc"))) |
| 542 |
#else |
| 491 |
MY_ATTRIBUTE((target("+crc"))) |
543 |
MY_ATTRIBUTE((target("+crc"))) |
|
|
544 |
#endif |
| 492 |
#endif /* CRC32_ARM64_DEFAULT */ |
545 |
#endif /* CRC32_ARM64_DEFAULT */ |
| 493 |
uint64_t crc32_impl::update(uint64_t crc, uint64_t data) { |
546 |
uint64_t crc32_impl::update(uint64_t crc, uint64_t data) { |
| 494 |
return (uint64_t)__crc32cd((uint32_t)crc, data); |
547 |
__crc32cd((uint32_t)crc, data); |
|
|
548 |
return crc; |
| 495 |
} |
549 |
} |
|
|
550 |
#endif |
| 496 |
#endif /* CRC32_ARM64 */ |
551 |
#endif /* CRC32_ARM64 */ |
| 497 |
|
552 |
|
| 498 |
/** Implementation of polynomial_mul_rev<w>(rev_u) function which uses hardware |
553 |
/** Implementation of polynomial_mul_rev<w>(rev_u) function which uses hardware |
|
Lines 534-540
Link Here
|
| 534 |
} |
589 |
} |
| 535 |
template <uint32_t w> |
590 |
template <uint32_t w> |
| 536 |
#ifdef CRC32_ARM64_DEFAULT |
591 |
#ifdef CRC32_ARM64_DEFAULT |
|
|
592 |
#ifdef __clang__ |
| 593 |
MY_ATTRIBUTE((target("crypto"))) |
| 594 |
#else |
| 537 |
MY_ATTRIBUTE((target("+crypto"))) |
595 |
MY_ATTRIBUTE((target("+crypto"))) |
|
|
596 |
#endif |
| 538 |
#endif /* CRC32_ARM64_DEFAULT */ |
597 |
#endif /* CRC32_ARM64_DEFAULT */ |
| 539 |
uint64_t use_pclmul::polynomial_mul_rev(uint32_t rev_u) { |
598 |
uint64_t use_pclmul::polynomial_mul_rev(uint32_t rev_u) { |
| 540 |
constexpr uint64_t flipped_w = flip_at_32(w); |
599 |
constexpr uint64_t flipped_w = flip_at_32(w); |
|
Lines 777-783
Link Here
|
| 777 |
MY_ATTRIBUTE((flatten)) |
836 |
MY_ATTRIBUTE((flatten)) |
| 778 |
#endif /* CRC32_ARM64_APPLE */ |
837 |
#endif /* CRC32_ARM64_APPLE */ |
| 779 |
#ifdef CRC32_ARM64_DEFAULT |
838 |
#ifdef CRC32_ARM64_DEFAULT |
|
|
839 |
#ifdef __clang__ |
| 840 |
MY_ATTRIBUTE((target("crc,crypto"))) |
| 841 |
#else |
| 780 |
MY_ATTRIBUTE((target("+crc+crypto"), flatten)) |
842 |
MY_ATTRIBUTE((target("+crc+crypto"), flatten)) |
|
|
843 |
#endif |
| 781 |
#endif /* CRC32_ARM64_DEFAULT */ |
844 |
#endif /* CRC32_ARM64_DEFAULT */ |
| 782 |
uint32_t crc32_using_pclmul(const byte *data, size_t len) { |
845 |
uint32_t crc32_using_pclmul(const byte *data, size_t len) { |
| 783 |
return crc32<use_pclmul>(0, data, len); |
846 |
return crc32<use_pclmul>(0, data, len); |
|
Lines 797-803
Link Here
|
| 797 |
MY_ATTRIBUTE((flatten)) |
860 |
MY_ATTRIBUTE((flatten)) |
| 798 |
#endif /* CRC32_ARM64_APPLE */ |
861 |
#endif /* CRC32_ARM64_APPLE */ |
| 799 |
#ifdef CRC32_ARM64_DEFAULT |
862 |
#ifdef CRC32_ARM64_DEFAULT |
|
|
863 |
#ifdef __clang__ |
| 864 |
MY_ATTRIBUTE((target("crc"))) |
| 865 |
#else |
| 800 |
MY_ATTRIBUTE((target("+crc"), flatten)) |
866 |
MY_ATTRIBUTE((target("+crc"), flatten)) |
|
|
867 |
#endif |
| 801 |
#endif /* CRC32_ARM64_DEFAULT */ |
868 |
#endif /* CRC32_ARM64_DEFAULT */ |
| 802 |
uint32_t crc32_using_unrolled_loop_poly_mul(const byte *data, size_t len) { |
869 |
uint32_t crc32_using_unrolled_loop_poly_mul(const byte *data, size_t len) { |
| 803 |
return crc32<use_unrolled_loop_poly_mul>(0, data, len); |
870 |
return crc32<use_unrolled_loop_poly_mul>(0, data, len); |