You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

56 lines
1.7 KiB

  1. /* Copyright (c) 2014 Cryptography Research, Inc.
  2. * Released under the MIT License. See LICENSE.txt for license information.
  3. */
  4. #ifndef __WORD_H__
  5. #define __WORD_H__
  6. #include <stdint.h>
  7. typedef uint64_t word_t;
  8. typedef __uint128_t dword_t;
  9. typedef int64_t sword_t;
  10. typedef __int128_t dsword_t;
  11. static const int WORD_BITS = sizeof(word_t) * 8;
  12. /* TODO: vector width for procs like ARM; gcc support */
  13. typedef uint64_t mask_t, vecmask_t __attribute__((ext_vector_type(4)));
  14. static const mask_t MASK_FAILURE = 0, MASK_SUCCESS = -1;
  15. /* FIXME this only works on clang */
  16. typedef uint64_t uint64x2_t __attribute__((ext_vector_type(2)));
  17. typedef int64_t int64x2_t __attribute__((ext_vector_type(2)));
  18. typedef uint64_t uint64x4_t __attribute__((ext_vector_type(4)));
  19. typedef int64_t int64x4_t __attribute__((ext_vector_type(4)));
  20. typedef uint32_t uint32x4_t __attribute__((ext_vector_type(4)));
  21. typedef int32_t int32x4_t __attribute__((ext_vector_type(4)));
  22. typedef uint32_t uint32x8_t __attribute__((ext_vector_type(8)));
  23. typedef int32_t int32x8_t __attribute__((ext_vector_type(8)));
  24. #if __AVX2__
  25. typedef uint32x8_t big_register_t;
  26. typedef uint64x4_t uint64xn_t;
  27. #elif __SSE2__ || __ARM_NEON__
  28. typedef uint32x4_t big_register_t;
  29. typedef uint64x2_t uint64xn_t;
  30. #elif _WIN64 || __amd64__ || __X86_64__ || __aarch64__
  31. typedef uint64_t big_register_t, uint64xn_t;
  32. #else
  33. typedef uint64_t uint64xn_t;
  34. typedef uint32_t big_register_t;
  35. #endif
  36. #if __AVX2__ || __SSE2__ || __ARM_NEON__
  37. static __inline__ big_register_t
  38. br_is_zero(big_register_t x) {
  39. return (big_register_t)(x == (big_register_t)0);
  40. }
  41. #else
  42. #error "TODO: constant-time equality on vectorless platforms"
  43. #endif
  44. #endif /* __WORD_H__ */