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.
 
 
 

51 lines
1.2 KiB

  1. // XXX: Temporary placeholder for a faster sort.
  2. // Copied from supercop-20190110/crypto_sort/int32/portable3
  3. #include <stdint.h>
  4. #include "crypto_sort.h"
  5. #define int32_MINMAX(a,b) \
  6. do { \
  7. int32_t ab = (b) ^ (a); \
  8. int32_t c = (int32_t)((int64_t)(b) - (int64_t)(a)); \
  9. c ^= ab & (c ^ (b)); \
  10. c >>= 31; \
  11. c &= ab; \
  12. (a) ^= c; \
  13. (b) ^= c; \
  14. } while(0)
  15. void PQCLEAN_NTRUHPS4096821_CLEAN_crypto_sort(void *array, long long n) {
  16. long long top, p, q, r, i;
  17. int32_t *x = array;
  18. if (n < 2) {
  19. return;
  20. }
  21. top = 1;
  22. while (top < n - top) {
  23. top += top;
  24. }
  25. for (p = top; p > 0; p >>= 1) {
  26. for (i = 0; i < n - p; ++i) {
  27. if (!(i & p)) {
  28. int32_MINMAX(x[i], x[i + p]);
  29. }
  30. }
  31. i = 0;
  32. for (q = top; q > p; q >>= 1) {
  33. for (; i < n - q; ++i) {
  34. if (!(i & p)) {
  35. int32_t a = x[i + p];
  36. for (r = q; r > p; r >>= 1) {
  37. int32_MINMAX(a, x[i + r]);
  38. }
  39. x[i + p] = a;
  40. }
  41. }
  42. }
  43. }
  44. }