cpuid.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* cpuid.h
  2. *
  3. * Copyright (C) 2006-2023 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #ifndef WOLF_CRYPT_CPUID_H
  22. #define WOLF_CRYPT_CPUID_H
  23. #include <wolfssl/wolfcrypt/types.h>
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #if (defined(WOLFSSL_X86_64_BUILD) || defined(USE_INTEL_SPEEDUP) || \
  28. defined(WOLFSSL_AESNI) || defined(WOLFSSL_SP_X86_64_ASM)) && \
  29. !defined(WOLFSSL_NO_ASM)
  30. #define HAVE_CPUID
  31. #define HAVE_CPUID_INTEL
  32. #endif
  33. #ifdef HAVE_CPUID_INTEL
  34. #define CPUID_AVX1 0x0001
  35. #define CPUID_AVX2 0x0002
  36. #define CPUID_RDRAND 0x0004
  37. #define CPUID_RDSEED 0x0008
  38. #define CPUID_BMI2 0x0010 /* MULX, RORX */
  39. #define CPUID_AESNI 0x0020
  40. #define CPUID_ADX 0x0040 /* ADCX, ADOX */
  41. #define CPUID_MOVBE 0x0080 /* Move and byte swap */
  42. #define CPUID_BMI1 0x0100 /* ANDN */
  43. #define IS_INTEL_AVX1(f) ((f) & CPUID_AVX1)
  44. #define IS_INTEL_AVX2(f) ((f) & CPUID_AVX2)
  45. #define IS_INTEL_RDRAND(f) ((f) & CPUID_RDRAND)
  46. #define IS_INTEL_RDSEED(f) ((f) & CPUID_RDSEED)
  47. #define IS_INTEL_BMI2(f) ((f) & CPUID_BMI2)
  48. #define IS_INTEL_AESNI(f) ((f) & CPUID_AESNI)
  49. #define IS_INTEL_ADX(f) ((f) & CPUID_ADX)
  50. #define IS_INTEL_MOVBE(f) ((f) & CPUID_MOVBE)
  51. #define IS_INTEL_BMI1(f) ((f) & CPUID_BMI1)
  52. #endif
  53. #ifdef HAVE_CPUID
  54. void cpuid_set_flags(void);
  55. word32 cpuid_get_flags(void);
  56. /* Public APIs to modify flags. */
  57. WOLFSSL_API void cpuid_select_flags(word32 flags);
  58. WOLFSSL_API void cpuid_set_flag(word32 flag);
  59. WOLFSSL_API void cpuid_clear_flag(word32 flag);
  60. #endif
  61. #ifdef __cplusplus
  62. } /* extern "C" */
  63. #endif
  64. #endif /* WOLF_CRYPT_CPUID_H */