types.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* Copyright 2015, Kenneth MacKay. Licensed under the BSD 2-clause license. */
  2. #ifndef _UECC_TYPES_H_
  3. #define _UECC_TYPES_H_
  4. #ifndef uECC_PLATFORM
  5. #if __AVR__
  6. #define uECC_PLATFORM uECC_avr
  7. #elif defined(__thumb2__) || defined(_M_ARMT) /* I think MSVC only supports Thumb-2 targets */
  8. #define uECC_PLATFORM uECC_arm_thumb2
  9. #elif defined(__thumb__)
  10. #define uECC_PLATFORM uECC_arm_thumb
  11. #elif defined(__arm__) || defined(_M_ARM)
  12. #define uECC_PLATFORM uECC_arm
  13. #elif defined(__aarch64__)
  14. #define uECC_PLATFORM uECC_arm64
  15. #elif defined(__i386__) || defined(_M_IX86) || defined(_X86_) || defined(__I86__)
  16. #define uECC_PLATFORM uECC_x86
  17. #elif defined(__amd64__) || defined(_M_X64)
  18. #define uECC_PLATFORM uECC_x86_64
  19. #else
  20. #define uECC_PLATFORM uECC_arch_other
  21. #endif
  22. #endif
  23. #ifndef uECC_ARM_USE_UMAAL
  24. #if (uECC_PLATFORM == uECC_arm) && (__ARM_ARCH >= 6)
  25. #define uECC_ARM_USE_UMAAL 1
  26. #elif (uECC_PLATFORM == uECC_arm_thumb2) && (__ARM_ARCH >= 6) && !__ARM_ARCH_7M__
  27. #define uECC_ARM_USE_UMAAL 1
  28. #else
  29. #define uECC_ARM_USE_UMAAL 0
  30. #endif
  31. #endif
  32. #ifndef uECC_WORD_SIZE
  33. #if uECC_PLATFORM == uECC_avr
  34. #define uECC_WORD_SIZE 1
  35. #elif (uECC_PLATFORM == uECC_x86_64 || uECC_PLATFORM == uECC_arm64)
  36. #define uECC_WORD_SIZE 8
  37. #else
  38. #define uECC_WORD_SIZE 4
  39. #endif
  40. #endif
  41. #if (uECC_WORD_SIZE != 1) && (uECC_WORD_SIZE != 4) && (uECC_WORD_SIZE != 8)
  42. #error "Unsupported value for uECC_WORD_SIZE"
  43. #endif
  44. #if ((uECC_PLATFORM == uECC_avr) && (uECC_WORD_SIZE != 1))
  45. #pragma message ("uECC_WORD_SIZE must be 1 for AVR")
  46. #undef uECC_WORD_SIZE
  47. #define uECC_WORD_SIZE 1
  48. #endif
  49. #if ((uECC_PLATFORM == uECC_arm || uECC_PLATFORM == uECC_arm_thumb || \
  50. uECC_PLATFORM == uECC_arm_thumb2) && \
  51. (uECC_WORD_SIZE != 4))
  52. #pragma message ("uECC_WORD_SIZE must be 4 for ARM")
  53. #undef uECC_WORD_SIZE
  54. #define uECC_WORD_SIZE 4
  55. #endif
  56. #if defined(__SIZEOF_INT128__) || ((__clang_major__ * 100 + __clang_minor__) >= 302)
  57. #define SUPPORTS_INT128 1
  58. #else
  59. #define SUPPORTS_INT128 0
  60. #endif
  61. typedef int8_t wordcount_t;
  62. typedef int16_t bitcount_t;
  63. typedef int8_t cmpresult_t;
  64. #if (uECC_WORD_SIZE == 1)
  65. typedef uint8_t uECC_word_t;
  66. typedef uint16_t uECC_dword_t;
  67. #define HIGH_BIT_SET 0x80
  68. #define uECC_WORD_BITS 8
  69. #define uECC_WORD_BITS_SHIFT 3
  70. #define uECC_WORD_BITS_MASK 0x07
  71. #elif (uECC_WORD_SIZE == 4)
  72. typedef uint32_t uECC_word_t;
  73. typedef uint64_t uECC_dword_t;
  74. #define HIGH_BIT_SET 0x80000000
  75. #define uECC_WORD_BITS 32
  76. #define uECC_WORD_BITS_SHIFT 5
  77. #define uECC_WORD_BITS_MASK 0x01F
  78. #elif (uECC_WORD_SIZE == 8)
  79. typedef uint64_t uECC_word_t;
  80. #if SUPPORTS_INT128
  81. typedef unsigned __int128 uECC_dword_t;
  82. #endif
  83. #define HIGH_BIT_SET 0x8000000000000000ull
  84. #define uECC_WORD_BITS 64
  85. #define uECC_WORD_BITS_SHIFT 6
  86. #define uECC_WORD_BITS_MASK 0x03F
  87. #endif /* uECC_WORD_SIZE */
  88. #endif /* _UECC_TYPES_H_ */