cpu-aarch64-linux.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* Copyright (c) 2016, Google Inc.
  2. *
  3. * Permission to use, copy, modify, and/or distribute this software for any
  4. * purpose with or without fee is hereby granted, provided that the above
  5. * copyright notice and this permission notice appear in all copies.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  14. #include <openssl/cpu.h>
  15. #if defined(OPENSSL_AARCH64) && defined(OPENSSL_LINUX) && \
  16. !defined(OPENSSL_STATIC_ARMCAP)
  17. #include <sys/auxv.h>
  18. #include <openssl/arm_arch.h>
  19. #include "internal.h"
  20. extern uint32_t OPENSSL_armcap_P;
  21. void OPENSSL_cpuid_setup(void) {
  22. unsigned long hwcap = getauxval(AT_HWCAP);
  23. // See /usr/include/asm/hwcap.h on an aarch64 installation for the source of
  24. // these values.
  25. static const unsigned long kNEON = 1 << 1;
  26. static const unsigned long kAES = 1 << 3;
  27. static const unsigned long kPMULL = 1 << 4;
  28. static const unsigned long kSHA1 = 1 << 5;
  29. static const unsigned long kSHA256 = 1 << 6;
  30. if ((hwcap & kNEON) == 0) {
  31. // Matching OpenSSL, if NEON is missing, don't report other features
  32. // either.
  33. return;
  34. }
  35. OPENSSL_armcap_P |= ARMV7_NEON;
  36. if (hwcap & kAES) {
  37. OPENSSL_armcap_P |= ARMV8_AES;
  38. }
  39. if (hwcap & kPMULL) {
  40. OPENSSL_armcap_P |= ARMV8_PMULL;
  41. }
  42. if (hwcap & kSHA1) {
  43. OPENSSL_armcap_P |= ARMV8_SHA1;
  44. }
  45. if (hwcap & kSHA256) {
  46. OPENSSL_armcap_P |= ARMV8_SHA256;
  47. }
  48. }
  49. #endif // OPENSSL_AARCH64 && !OPENSSL_STATIC_ARMCAP