riscv_arch.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright 2022 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. #endif