test-arch.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. // Copyright © 2018-2019 Ariadne Devos
  3. /* sHT -- (x86) compare values without misinforming the compiler */
  4. /* This is transcluded from <sHT/test.h>. */
  5. /* Operand order: first the source, then the destination.
  6. E.g., cmp $3,%rdx.
  7. When compiling, the following diagnostic was print:
  8. > Error: too many memory references for cmp
  9. Use the alternative constraints feature of GCC to
  10. avoid this problem.
  11. When reading AMD and probably Intel documentation:
  12. 'greater' is for signed integers, 'above' for unsigned integers.
  13. %: commutative */
  14. #define _sHT_ge(a, b, correct) \
  15. __asm__ goto ("cmp %1,%0;jae %l[" #correct "]" : : "r,m" (a), "erm,er" (b) : "cc" : correct)
  16. #define _sHT_eq(a, b, correct) \
  17. __asm__ goto ("cmp %1,%0;je %l[" #correct "]" : : "%r,%m" (a), "erm,er" (b) : "cc" : correct)
  18. #define _sHT_neq(a, b, correct) \
  19. __asm__ goto ("cmp %1,%0;jne %l[" #correct "]" : : "%r,%m" (a), "erm,er" (b) : "cc" : correct)
  20. #define _sHT_eq_bool(a, b, c) \
  21. __asm__ ("cmp %2,%1;sete %0" : "=r,r" (c) : "%r,%m" (a), "erm,er" (b) : )
  22. #define _sHT_gt(a, b, correct) \
  23. __asm__ goto ("cmp %1,%0;ja %l[" #correct "]" : : "r,m" (a), "erm,er" (b) : "cc" : correct)
  24. /* testl is supposedlu smaller than cmp */
  25. #define _sHT_zero_p(a, correct) \
  26. __asm__ goto ("test %0,%0;je %l[" #correct "]" : : "r" (a) : "cc" : correct)
  27. #define _sHT_nonzero_p(a, correct) \
  28. __asm__ goto ("test %0,%0;jnz %l[" #correct "]" : : "r" (a) : "cc" : correct)
  29. /* cmp %0,%0 does not work! Try tests/cmp. */
  30. #define _sHT_lt0(a, correct) \
  31. __asm__ goto ("test %0,%0;js %l[" #correct "]" : : "r" (a) : "cc" : correct)
  32. #define _sHT_and_any_p(a, b, correct) \
  33. __asm__ goto ("test %1,%0;jnz %l[" #correct "]" : : "%rm" (a), "er" (b) : "cc" : correct)
  34. #define _sHT_and_none_p(a, b, correct) \
  35. __asm__ goto ("test %1,%0;je %l[" #correct "]" : : "%rm" (a), "er" (b) : "cc" : correct)