riscv_arch.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef OSSL_CRYPTO_RISCV_ARCH_H
  10. # define OSSL_CRYPTO_RISCV_ARCH_H
  11. # include <ctype.h>
  12. # include <stdint.h>
  13. # define RISCV_DEFINE_CAP(NAME, INDEX, BIT_INDEX) +1
  14. extern uint32_t OPENSSL_riscvcap_P[ ((
  15. # include "riscv_arch.def"
  16. ) + sizeof(uint32_t) - 1) / sizeof(uint32_t) ];
  17. # ifdef OPENSSL_RISCVCAP_IMPL
  18. # define RISCV_DEFINE_CAP(NAME, INDEX, BIT_INDEX) +1
  19. uint32_t OPENSSL_riscvcap_P[ ((
  20. # include "riscv_arch.def"
  21. ) + sizeof(uint32_t) - 1) / sizeof(uint32_t) ];
  22. # endif
  23. # define RISCV_DEFINE_CAP(NAME, INDEX, BIT_INDEX) \
  24. static inline int RISCV_HAS_##NAME(void) \
  25. { \
  26. return (OPENSSL_riscvcap_P[INDEX] & (1 << BIT_INDEX)) != 0; \
  27. }
  28. # include "riscv_arch.def"
  29. struct RISCV_capability_s {
  30. const char *name;
  31. size_t index;
  32. size_t bit_offset;
  33. };
  34. # define RISCV_DEFINE_CAP(NAME, INDEX, BIT_INDEX) +1
  35. extern const struct RISCV_capability_s RISCV_capabilities[
  36. # include "riscv_arch.def"
  37. ];
  38. # ifdef OPENSSL_RISCVCAP_IMPL
  39. # define RISCV_DEFINE_CAP(NAME, INDEX, BIT_INDEX) \
  40. { #NAME, INDEX, BIT_INDEX },
  41. const struct RISCV_capability_s RISCV_capabilities[] = {
  42. # include "riscv_arch.def"
  43. };
  44. # endif
  45. # define RISCV_DEFINE_CAP(NAME, INDEX, BIT_INDEX) +1
  46. static const size_t kRISCVNumCaps =
  47. # include "riscv_arch.def"
  48. ;
  49. /* Extension combination tests. */
  50. #define RISCV_HAS_ZBB_AND_ZBC() (RISCV_HAS_ZBB() && RISCV_HAS_ZBC())
  51. #define RISCV_HAS_ZBKB_AND_ZKND_AND_ZKNE() (RISCV_HAS_ZBKB() && RISCV_HAS_ZKND() && RISCV_HAS_ZKNE())
  52. #define RISCV_HAS_ZKND_AND_ZKNE() (RISCV_HAS_ZKND() && RISCV_HAS_ZKNE())
  53. #endif