diff options
author | Marat Dukhan <marat@fb.com> | 2018-02-05 11:47:52 -0800 |
---|---|---|
committer | Marat Dukhan <marat@fb.com> | 2018-02-05 11:47:52 -0800 |
commit | a9feb41dc9d05e59604c114c6b6a893d842b9d7b (patch) | |
tree | 163e82a78ff010477599077db960a27940c1e669 | |
parent | 8d6ecbee2f8261590fae277fb2c7a68ff962737d (diff) | |
download | FXdiv-a9feb41dc9d05e59604c114c6b6a893d842b9d7b.tar.gz |
Support option to disable inline assembly
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | include/fxdiv.h | 12 |
2 files changed, 12 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 00cb3c5..e084ca5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ PROJECT(FXdiv C CXX) # ---[ Options. OPTION(FXDIV_BUILD_TESTS "Build FXdiv unit tests" ON) OPTION(FXDIV_BUILD_BENCHMARKS "Build FXdiv micro-benchmarks" ON) +OPTION(FXDIV_USE_INLINE_ASSEMBLY "Allow use of inline assembly in FXdiv" ON) # ---[ CMake options IF(FXDIV_BUILD_TESTS) @@ -53,6 +54,9 @@ ELSE() ADD_LIBRARY(fxdiv INTERFACE) ENDIF() TARGET_INCLUDE_DIRECTORIES(fxdiv INTERFACE include) +IF(NOT FXDIV_USE_INLINE_ASSEMBLY) + TARGET_COMPILE_DEFINITIONS(fxdiv INTERFACE FXDIV_USE_INLINE_ASSEMBLY=0) +ENDIF() INSTALL(FILES include/fxdiv.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/include/fxdiv.h b/include/fxdiv.h index 5647db3..21a3dc1 100644 --- a/include/fxdiv.h +++ b/include/fxdiv.h @@ -16,6 +16,10 @@ #include <intrin.h> #endif +#ifndef FXDIV_USE_INLINE_ASSEMBLY + #define FXDIV_USE_INLINE_ASSEMBLY 1 +#endif + static inline uint64_t fxdiv_mulext_uint32_t(uint32_t a, uint32_t b) { #if defined(_MSC_VER) && defined(_M_IX86) return (uint64_t) __emulu((unsigned int) a, (unsigned int) b); @@ -120,7 +124,7 @@ static inline struct fxdiv_divisor_uint32_t fxdiv_init_uint32_t(uint32_t d) { #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) unsigned long l_minus_1; _BitScanReverse(&l_minus_1, (unsigned long) (d - 1)); - #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) + #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && FXDIV_USE_INLINE_ASSEMBLY uint32_t l_minus_1; __asm__("BSRL %[d_minus_1], %[l_minus_1]" : [l_minus_1] "=r" (l_minus_1) @@ -159,7 +163,7 @@ static inline struct fxdiv_divisor_uint32_t fxdiv_init_uint32_t(uint32_t d) { uint32_t u_hi = (UINT32_C(2) << (uint32_t) l_minus_1) - d; /* Division of 64-bit number u_hi:UINT32_C(0) by 32-bit number d, 32-bit quotient output q */ - #if defined(__GNUC__) && defined(__i386__) + #if defined(__GNUC__) && defined(__i386__) && FXDIV_USE_INLINE_ASSEMBLY uint32_t q; __asm__("DIVL %[d]" : "=a" (q), "+d" (u_hi) @@ -205,7 +209,7 @@ static inline struct fxdiv_divisor_uint64_t fxdiv_init_uint64_t(uint64_t d) { l_minus_1 += 32; } const uint32_t nlz_d = ((uint8_t) l_minus_1 ^ UINT8_C(0x3F)) - d_is_power_of_2; - #elif defined(__GNUC__) && defined(__x86_64__) + #elif defined(__GNUC__) && defined(__x86_64__) && FXDIV_USE_INLINE_ASSEMBLY uint64_t l_minus_1; __asm__("BSRQ %[d_minus_1], %[l_minus_1]" : [l_minus_1] "=r" (l_minus_1) @@ -252,7 +256,7 @@ static inline struct fxdiv_divisor_uint64_t fxdiv_init_uint64_t(uint64_t d) { uint64_t u_hi = (UINT64_C(2) << (uint32_t) l_minus_1) - d; /* Division of 128-bit number u_hi:UINT64_C(0) by 64-bit number d, 64-bit quotient output q */ - #if defined(__GNUC__) && defined(__x86_64__) + #if defined(__GNUC__) && defined(__x86_64__) && FXDIV_USE_INLINE_ASSEMBLY uint64_t q; __asm__("DIVQ %[d]" : "=a" (q), "+d" (u_hi) |