utilasm.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * utilasm.h
  3. *
  4. */
  5. #ifndef INCLUDE_UTILASM_H_
  6. #define INCLUDE_UTILASM_H_
  7. #include <roaring/portability.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. namespace roaring {
  11. #endif
  12. #if defined(CROARING_INLINE_ASM)
  13. #define CROARING_ASMBITMANIPOPTIMIZATION // optimization flag
  14. #define ASM_SHIFT_RIGHT(srcReg, bitsReg, destReg) \
  15. __asm volatile("shrx %1, %2, %0" \
  16. : "=r"(destReg) \
  17. : /* write */ \
  18. "r"(bitsReg), /* read only */ \
  19. "r"(srcReg) /* read only */ \
  20. )
  21. #define ASM_INPLACESHIFT_RIGHT(srcReg, bitsReg) \
  22. __asm volatile("shrx %1, %0, %0" \
  23. : "+r"(srcReg) \
  24. : /* read/write */ \
  25. "r"(bitsReg) /* read only */ \
  26. )
  27. #define ASM_SHIFT_LEFT(srcReg, bitsReg, destReg) \
  28. __asm volatile("shlx %1, %2, %0" \
  29. : "=r"(destReg) \
  30. : /* write */ \
  31. "r"(bitsReg), /* read only */ \
  32. "r"(srcReg) /* read only */ \
  33. )
  34. // set bit at position testBit within testByte to 1 and
  35. // copy cmovDst to cmovSrc if that bit was previously clear
  36. #define ASM_SET_BIT_INC_WAS_CLEAR(testByte, testBit, count) \
  37. __asm volatile( \
  38. "bts %2, %0\n" \
  39. "sbb $-1, %1\n" \
  40. : "+r"(testByte), /* read/write */ \
  41. "+r"(count) \
  42. : /* read/write */ \
  43. "r"(testBit) /* read only */ \
  44. )
  45. #define ASM_CLEAR_BIT_DEC_WAS_SET(testByte, testBit, count) \
  46. __asm volatile( \
  47. "btr %2, %0\n" \
  48. "sbb $0, %1\n" \
  49. : "+r"(testByte), /* read/write */ \
  50. "+r"(count) \
  51. : /* read/write */ \
  52. "r"(testBit) /* read only */ \
  53. )
  54. #define ASM_BT64(testByte, testBit, count) \
  55. __asm volatile( \
  56. "bt %2,%1\n" \
  57. "sbb %0,%0" /*could use setb */ \
  58. : "=r"(count) \
  59. : /* write */ \
  60. "r"(testByte), /* read only */ \
  61. "r"(testBit) /* read only */ \
  62. )
  63. #endif
  64. #ifdef __cplusplus
  65. }
  66. } // extern "C" { namespace roaring {
  67. #endif
  68. #endif /* INCLUDE_UTILASM_H_ */