Home | History | Annotate | Line # | Download | only in builtins
      1  1.1  joerg /* ===-- int_lib.h - configuration header for compiler-rt  -----------------===
      2  1.1  joerg  *
      3  1.1  joerg  *                     The LLVM Compiler Infrastructure
      4  1.1  joerg  *
      5  1.1  joerg  * This file is dual licensed under the MIT and the University of Illinois Open
      6  1.1  joerg  * Source Licenses. See LICENSE.TXT for details.
      7  1.1  joerg  *
      8  1.1  joerg  * ===----------------------------------------------------------------------===
      9  1.1  joerg  *
     10  1.1  joerg  * This file is a configuration header for compiler-rt.
     11  1.1  joerg  * This file is not part of the interface of this library.
     12  1.1  joerg  *
     13  1.1  joerg  * ===----------------------------------------------------------------------===
     14  1.1  joerg  */
     15  1.1  joerg 
     16  1.1  joerg #ifndef INT_LIB_H
     17  1.1  joerg #define INT_LIB_H
     18  1.1  joerg 
     19  1.1  joerg /* Assumption: Signed integral is 2's complement. */
     20  1.1  joerg /* Assumption: Right shift of signed negative is arithmetic shift. */
     21  1.1  joerg /* Assumption: Endianness is little or big (not mixed). */
     22  1.1  joerg 
     23  1.2    rin #if defined(__ELF__)
     24  1.2    rin #define FNALIAS(alias_name, original_name) \
     25  1.6    rin   void alias_name() __attribute__((__alias__(#original_name)))
     26  1.6    rin #define COMPILER_RT_ALIAS(aliasee) __attribute__((__alias__(#aliasee)))
     27  1.2    rin #else
     28  1.2    rin #define FNALIAS(alias, name) _Pragma("GCC error(\"alias unsupported on this file format\")")
     29  1.6    rin #define COMPILER_RT_ALIAS(aliasee) _Pragma("GCC error(\"alias unsupported on this file format\")")
     30  1.2    rin #endif
     31  1.2    rin 
     32  1.1  joerg /* ABI macro definitions */
     33  1.1  joerg 
     34  1.1  joerg #if __ARM_EABI__
     35  1.3    rin # ifdef COMPILER_RT_ARMHF_TARGET
     36  1.3    rin #   define COMPILER_RT_ABI
     37  1.3    rin # else
     38  1.4    rin #   define COMPILER_RT_ABI __attribute__((__pcs__("aapcs")))
     39  1.3    rin # endif
     40  1.1  joerg #else
     41  1.1  joerg # define COMPILER_RT_ABI
     42  1.1  joerg #endif
     43  1.1  joerg 
     44  1.5    rin #define AEABI_RTABI __attribute__((__pcs__("aapcs")))
     45  1.5    rin 
     46  1.2    rin #ifdef _MSC_VER
     47  1.2    rin #define ALWAYS_INLINE __forceinline
     48  1.2    rin #define NOINLINE __declspec(noinline)
     49  1.2    rin #define NORETURN __declspec(noreturn)
     50  1.2    rin #define UNUSED
     51  1.2    rin #else
     52  1.2    rin #define ALWAYS_INLINE __attribute__((always_inline))
     53  1.2    rin #define NOINLINE __attribute__((noinline))
     54  1.2    rin #define NORETURN __attribute__((noreturn))
     55  1.2    rin #define UNUSED __attribute__((unused))
     56  1.2    rin #endif
     57  1.2    rin 
     58  1.1  joerg #if defined(__NetBSD__) && (defined(_KERNEL) || defined(_STANDALONE))
     59  1.1  joerg /*
     60  1.1  joerg  * Kernel and boot environment can't use normal headers,
     61  1.1  joerg  * so use the equivalent system headers.
     62  1.1  joerg  */
     63  1.1  joerg #  include <machine/limits.h>
     64  1.1  joerg #  include <sys/stdint.h>
     65  1.1  joerg #  include <sys/types.h>
     66  1.1  joerg #else
     67  1.1  joerg /* Include the standard compiler builtin headers we use functionality from. */
     68  1.1  joerg #  include <limits.h>
     69  1.1  joerg #  include <stdint.h>
     70  1.1  joerg #  include <stdbool.h>
     71  1.1  joerg #  include <float.h>
     72  1.1  joerg #endif
     73  1.1  joerg 
     74  1.1  joerg /* Include the commonly used internal type definitions. */
     75  1.1  joerg #include "int_types.h"
     76  1.1  joerg 
     77  1.1  joerg /* Include internal utility function declarations. */
     78  1.1  joerg #include "int_util.h"
     79  1.1  joerg 
     80  1.2    rin COMPILER_RT_ABI si_int __paritysi2(si_int a);
     81  1.2    rin COMPILER_RT_ABI si_int __paritydi2(di_int a);
     82  1.2    rin 
     83  1.2    rin COMPILER_RT_ABI di_int __divdi3(di_int a, di_int b);
     84  1.2    rin COMPILER_RT_ABI si_int __divsi3(si_int a, si_int b);
     85  1.2    rin COMPILER_RT_ABI su_int __udivsi3(su_int n, su_int d);
     86  1.2    rin 
     87  1.2    rin COMPILER_RT_ABI su_int __udivmodsi4(su_int a, su_int b, su_int* rem);
     88  1.2    rin COMPILER_RT_ABI du_int __udivmoddi4(du_int a, du_int b, du_int* rem);
     89  1.2    rin #ifdef CRT_HAS_128BIT
     90  1.2    rin COMPILER_RT_ABI si_int __clzti2(ti_int a);
     91  1.2    rin COMPILER_RT_ABI tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem);
     92  1.2    rin #endif
     93  1.2    rin 
     94  1.2    rin /* Definitions for builtins unavailable on MSVC */
     95  1.2    rin #if defined(_MSC_VER) && !defined(__clang__)
     96  1.2    rin #include <intrin.h>
     97  1.2    rin 
     98  1.2    rin uint32_t __inline __builtin_ctz(uint32_t value) {
     99  1.2    rin   uint32_t trailing_zero = 0;
    100  1.2    rin   if (_BitScanForward(&trailing_zero, value))
    101  1.2    rin     return trailing_zero;
    102  1.2    rin   return 32;
    103  1.2    rin }
    104  1.2    rin 
    105  1.2    rin uint32_t __inline __builtin_clz(uint32_t value) {
    106  1.2    rin   uint32_t leading_zero = 0;
    107  1.2    rin   if (_BitScanReverse(&leading_zero, value))
    108  1.2    rin     return 31 - leading_zero;
    109  1.2    rin   return 32;
    110  1.2    rin }
    111  1.2    rin 
    112  1.2    rin #if defined(_M_ARM) || defined(_M_X64)
    113  1.2    rin uint32_t __inline __builtin_clzll(uint64_t value) {
    114  1.2    rin   uint32_t leading_zero = 0;
    115  1.2    rin   if (_BitScanReverse64(&leading_zero, value))
    116  1.2    rin     return 63 - leading_zero;
    117  1.2    rin   return 64;
    118  1.2    rin }
    119  1.2    rin #else
    120  1.2    rin uint32_t __inline __builtin_clzll(uint64_t value) {
    121  1.2    rin   if (value == 0)
    122  1.2    rin     return 64;
    123  1.2    rin   uint32_t msh = (uint32_t)(value >> 32);
    124  1.2    rin   uint32_t lsh = (uint32_t)(value & 0xFFFFFFFF);
    125  1.2    rin   if (msh != 0)
    126  1.2    rin     return __builtin_clz(msh);
    127  1.2    rin   return 32 + __builtin_clz(lsh);
    128  1.2    rin }
    129  1.2    rin #endif
    130  1.2    rin 
    131  1.2    rin #define __builtin_clzl __builtin_clzll
    132  1.2    rin #endif /* defined(_MSC_VER) && !defined(__clang__) */
    133  1.2    rin 
    134  1.1  joerg #endif /* INT_LIB_H */
    135