]>
git.proxmox.com Git - rustc.git/blob - src/compiler-rt/lib/builtins/int_lib.h
1 /* ===-- int_lib.h - configuration header for compiler-rt -----------------===
3 * The LLVM Compiler Infrastructure
5 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
8 * ===----------------------------------------------------------------------===
10 * This file is a configuration header for compiler-rt.
11 * This file is not part of the interface of this library.
13 * ===----------------------------------------------------------------------===
19 /* Assumption: Signed integral is 2's complement. */
20 /* Assumption: Right shift of signed negative is arithmetic shift. */
21 /* Assumption: Endianness is little or big (not mixed). */
24 #define FNALIAS(alias_name, original_name) \
25 void alias_name() __attribute__((alias(#original_name)))
27 #define FNALIAS(alias, name) _Pragma("GCC error(\"alias unsupported on this file format\")")
30 /* ABI macro definitions */
33 # define ARM_EABI_FNALIAS(aeabi_name, name) \
34 void __aeabi_##aeabi_name() __attribute__((alias("__" #name)));
35 # define COMPILER_RT_ABI __attribute__((pcs("aapcs")))
37 # define ARM_EABI_FNALIAS(aeabi_name, name)
38 # define COMPILER_RT_ABI
42 #define ALWAYS_INLINE __forceinline
43 #define NOINLINE __declspec(noinline)
44 #define NORETURN __declspec(noreturn)
47 #define ALWAYS_INLINE __attribute__((always_inline))
48 #define NOINLINE __attribute__((noinline))
49 #define NORETURN __attribute__((noreturn))
50 #define UNUSED __attribute__((unused))
53 #if defined(__NetBSD__) && (defined(_KERNEL) || defined(_STANDALONE))
55 * Kernel and boot environment can't use normal headers,
56 * so use the equivalent system headers.
58 # include <machine/limits.h>
59 # include <sys/stdint.h>
60 # include <sys/types.h>
62 /* Include the standard compiler builtin headers we use functionality from. */
69 /* Include the commonly used internal type definitions. */
70 #include "int_types.h"
72 /* Include internal utility function declarations. */
75 COMPILER_RT_ABI si_int
__paritysi2(si_int a
);
76 COMPILER_RT_ABI si_int
__paritydi2(di_int a
);
78 COMPILER_RT_ABI di_int
__divdi3(di_int a
, di_int b
);
79 COMPILER_RT_ABI si_int
__divsi3(si_int a
, si_int b
);
80 COMPILER_RT_ABI su_int
__udivsi3(su_int n
, su_int d
);
82 COMPILER_RT_ABI su_int
__udivmodsi4(su_int a
, su_int b
, su_int
* rem
);
83 COMPILER_RT_ABI du_int
__udivmoddi4(du_int a
, du_int b
, du_int
* rem
);
85 COMPILER_RT_ABI si_int
__clzti2(ti_int a
);
86 COMPILER_RT_ABI tu_int
__udivmodti4(tu_int a
, tu_int b
, tu_int
* rem
);
89 /* Definitions for builtins unavailable on MSVC */
90 #if defined(_MSC_VER) && !defined(__clang__)
93 uint32_t __inline
__builtin_ctz(uint32_t value
) {
94 uint32_t trailing_zero
= 0;
95 if (_BitScanForward(&trailing_zero
, value
))
100 uint32_t __inline
__builtin_clz(uint32_t value
) {
101 uint32_t leading_zero
= 0;
102 if (_BitScanReverse(&leading_zero
, value
))
103 return 31 - leading_zero
;
107 #if defined(_M_ARM) || defined(_M_X64)
108 uint32_t __inline
__builtin_clzll(uint64_t value
) {
109 uint32_t leading_zero
= 0;
110 if (_BitScanReverse64(&leading_zero
, value
))
111 return 63 - leading_zero
;
115 uint32_t __inline
__builtin_clzll(uint64_t value
) {
118 uint32_t msh
= (uint32_t)(value
>> 32);
119 uint32_t lsh
= (uint32_t)(value
& 0xFFFFFFFF);
121 return __builtin_clz(msh
);
122 return 32 + __builtin_clz(lsh
);
126 #define __builtin_clzl __builtin_clzll
127 #endif /* defined(_MSC_VER) && !defined(__clang__) */
129 #endif /* INT_LIB_H */