tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

lib_intrinsics.h (2758B)


      1 #pragma once
      2 
      3 #include <sys/types.h>
      4 
      5 #if defined(__has_include)
      6 #if __has_include("config.h")
      7 #include "config.h"
      8 #endif
      9 #endif
     10 
     11 /*
     12   GCC versions prior to 5.5 incorrectly optimize certain intrinsics.
     13 
     14   See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81300
     15 
     16   CLANG versions prior to 5 crash on certain intrinsics.
     17 
     18   See https://bugs.llvm.org/show_bug.cgi?id=24943
     19 */
     20 
     21 #if !defined(HACL_CAN_COMPILE_INTRINSICS) ||         \
     22    (defined(__clang__) && (__clang_major__ < 5)) || \
     23    (defined(__GNUC__) && !defined(__clang__) &&     \
     24     (__GNUC__ < 5 || (__GNUC__ == 5 && (__GNUC_MINOR__ < 5))))
     25 
     26 #include "Hacl_IntTypes_Intrinsics.h"
     27 
     28 #if defined(HACL_CAN_COMPILE_UINT128)
     29 
     30 #include "Hacl_IntTypes_Intrinsics_128.h"
     31 
     32 #define Lib_IntTypes_Intrinsics_add_carry_u64(x1, x2, x3, x4) \
     33    (Hacl_IntTypes_Intrinsics_128_add_carry_u64(x1, x2, x3, x4))
     34 
     35 #define Lib_IntTypes_Intrinsics_sub_borrow_u64(x1, x2, x3, x4) \
     36    (Hacl_IntTypes_Intrinsics_128_sub_borrow_u64(x1, x2, x3, x4))
     37 
     38 #else
     39 
     40 #define Lib_IntTypes_Intrinsics_add_carry_u64(x1, x2, x3, x4) \
     41    (Hacl_IntTypes_Intrinsics_add_carry_u64(x1, x2, x3, x4))
     42 
     43 #define Lib_IntTypes_Intrinsics_sub_borrow_u64(x1, x2, x3, x4) \
     44    (Hacl_IntTypes_Intrinsics_sub_borrow_u64(x1, x2, x3, x4))
     45 
     46 #endif // defined(HACL_CAN_COMPILE_UINT128)
     47 
     48 #define Lib_IntTypes_Intrinsics_add_carry_u32(x1, x2, x3, x4) \
     49    (Hacl_IntTypes_Intrinsics_add_carry_u32(x1, x2, x3, x4))
     50 
     51 #define Lib_IntTypes_Intrinsics_sub_borrow_u32(x1, x2, x3, x4) \
     52    (Hacl_IntTypes_Intrinsics_sub_borrow_u32(x1, x2, x3, x4))
     53 
     54 #else // !defined(HACL_CAN_COMPILE_INTRINSICS)
     55 
     56 #if defined(_MSC_VER)
     57 #include <immintrin.h>
     58 #else
     59 #include <x86intrin.h>
     60 #endif
     61 
     62 #define Lib_IntTypes_Intrinsics_add_carry_u32(x1, x2, x3, x4) \
     63    (_addcarry_u32(x1, x2, x3, (unsigned int *)x4))
     64 
     65 #define Lib_IntTypes_Intrinsics_add_carry_u64(x1, x2, x3, x4) \
     66    (_addcarry_u64(x1, x2, x3, (long long unsigned int *)x4))
     67 
     68 /*
     69   GCC versions prior to 7.2 pass arguments to _subborrow_u{32,64}
     70   in an incorrect order.
     71 
     72   See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81294
     73 */
     74 #if defined(__GNUC__) && !defined(__clang__) && \
     75    (__GNUC__ < 7 || (__GNUC__ == 7 && (__GNUC_MINOR__ < 2)))
     76 
     77 #define Lib_IntTypes_Intrinsics_sub_borrow_u32(x1, x2, x3, x4) \
     78    (_subborrow_u32(x1, x3, x2, (unsigned int *)x4))
     79 
     80 #define Lib_IntTypes_Intrinsics_sub_borrow_u64(x1, x2, x3, x4) \
     81    (_subborrow_u64(x1, x3, x2, (long long unsigned int *)x4))
     82 
     83 #else
     84 
     85 #define Lib_IntTypes_Intrinsics_sub_borrow_u32(x1, x2, x3, x4) \
     86    (_subborrow_u32(x1, x2, x3, (unsigned int *)x4))
     87 
     88 #define Lib_IntTypes_Intrinsics_sub_borrow_u64(x1, x2, x3, x4) \
     89    (_subborrow_u64(x1, x2, x3, (long long unsigned int *)x4))
     90 
     91 #endif // GCC < 7.2
     92 
     93 #endif // !HACL_CAN_COMPILE_INTRINSICS