2009-10-28 01:48:46 +08:00
|
|
|
/* ===-- int_lib.h - configuration header for compiler-rt -----------------===
|
2009-08-05 09:47:29 +08:00
|
|
|
*
|
|
|
|
* The LLVM Compiler Infrastructure
|
|
|
|
*
|
2010-11-17 06:13:33 +08:00
|
|
|
* This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
* Source Licenses. See LICENSE.TXT for details.
|
2009-08-05 09:47:29 +08:00
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*
|
2009-10-28 01:48:46 +08:00
|
|
|
* This file is a configuration header for compiler-rt.
|
2009-08-05 09:47:29 +08:00
|
|
|
* This file is not part of the interface of this library.
|
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*/
|
2009-06-27 00:47:03 +08:00
|
|
|
|
|
|
|
#ifndef INT_LIB_H
|
|
|
|
#define INT_LIB_H
|
|
|
|
|
2011-11-16 02:56:21 +08:00
|
|
|
/* Assumption: Signed integral is 2's complement. */
|
|
|
|
/* Assumption: Right shift of signed negative is arithmetic shift. */
|
|
|
|
/* Assumption: Endianness is little or big (not mixed). */
|
|
|
|
|
2015-08-21 12:39:52 +08:00
|
|
|
#if defined(__ELF__)
|
2015-08-21 10:51:17 +08:00
|
|
|
#define FNALIAS(alias_name, original_name) \
|
2017-10-04 05:25:07 +08:00
|
|
|
void alias_name() __attribute__((__alias__(#original_name)))
|
|
|
|
#define COMPILER_RT_ALIAS(aliasee) __attribute__((__alias__(#aliasee)))
|
2015-08-21 12:39:52 +08:00
|
|
|
#else
|
|
|
|
#define FNALIAS(alias, name) _Pragma("GCC error(\"alias unsupported on this file format\")")
|
2017-10-04 05:25:07 +08:00
|
|
|
#define COMPILER_RT_ALIAS(aliasee) _Pragma("GCC error(\"alias unsupported on this file format\")")
|
2015-08-21 12:39:52 +08:00
|
|
|
#endif
|
2015-08-21 10:51:17 +08:00
|
|
|
|
2011-11-16 02:34:44 +08:00
|
|
|
/* ABI macro definitions */
|
|
|
|
|
|
|
|
#if __ARM_EABI__
|
2017-03-29 11:36:46 +08:00
|
|
|
# ifdef COMPILER_RT_ARMHF_TARGET
|
|
|
|
# define COMPILER_RT_ABI
|
|
|
|
# else
|
2017-05-16 12:17:12 +08:00
|
|
|
# define COMPILER_RT_ABI __attribute__((__pcs__("aapcs")))
|
2017-03-29 11:36:46 +08:00
|
|
|
# endif
|
2011-11-16 02:34:44 +08:00
|
|
|
#else
|
2016-04-21 01:43:40 +08:00
|
|
|
# define COMPILER_RT_ABI
|
2011-11-16 02:34:44 +08:00
|
|
|
#endif
|
|
|
|
|
2017-05-17 00:41:37 +08:00
|
|
|
#define AEABI_RTABI __attribute__((__pcs__("aapcs")))
|
|
|
|
|
2015-10-06 12:33:05 +08:00
|
|
|
#ifdef _MSC_VER
|
2015-10-12 01:35:42 +08:00
|
|
|
#define ALWAYS_INLINE __forceinline
|
2015-10-06 12:33:05 +08:00
|
|
|
#define NOINLINE __declspec(noinline)
|
|
|
|
#define NORETURN __declspec(noreturn)
|
|
|
|
#define UNUSED
|
|
|
|
#else
|
2015-10-12 01:35:42 +08:00
|
|
|
#define ALWAYS_INLINE __attribute__((always_inline))
|
2015-10-06 12:33:05 +08:00
|
|
|
#define NOINLINE __attribute__((noinline))
|
|
|
|
#define NORETURN __attribute__((noreturn))
|
|
|
|
#define UNUSED __attribute__((unused))
|
|
|
|
#endif
|
|
|
|
|
2013-12-04 00:19:14 +08:00
|
|
|
#if defined(__NetBSD__) && (defined(_KERNEL) || defined(_STANDALONE))
|
|
|
|
/*
|
|
|
|
* Kernel and boot environment can't use normal headers,
|
|
|
|
* so use the equivalent system headers.
|
|
|
|
*/
|
|
|
|
# include <machine/limits.h>
|
|
|
|
# include <sys/stdint.h>
|
|
|
|
# include <sys/types.h>
|
|
|
|
#else
|
2011-11-16 08:20:36 +08:00
|
|
|
/* Include the standard compiler builtin headers we use functionality from. */
|
2013-12-04 00:19:14 +08:00
|
|
|
# include <limits.h>
|
|
|
|
# include <stdint.h>
|
|
|
|
# include <stdbool.h>
|
|
|
|
# include <float.h>
|
|
|
|
#endif
|
2011-11-16 08:20:36 +08:00
|
|
|
|
2011-11-16 02:56:13 +08:00
|
|
|
/* Include the commonly used internal type definitions. */
|
|
|
|
#include "int_types.h"
|
2009-06-27 00:47:03 +08:00
|
|
|
|
2011-11-16 09:19:19 +08:00
|
|
|
/* Include internal utility function declarations. */
|
|
|
|
#include "int_util.h"
|
|
|
|
|
2014-03-01 23:30:50 +08:00
|
|
|
COMPILER_RT_ABI si_int __paritysi2(si_int a);
|
|
|
|
COMPILER_RT_ABI si_int __paritydi2(di_int a);
|
|
|
|
|
|
|
|
COMPILER_RT_ABI di_int __divdi3(di_int a, di_int b);
|
|
|
|
COMPILER_RT_ABI si_int __divsi3(si_int a, si_int b);
|
|
|
|
COMPILER_RT_ABI su_int __udivsi3(su_int n, su_int d);
|
|
|
|
|
|
|
|
COMPILER_RT_ABI su_int __udivmodsi4(su_int a, su_int b, su_int* rem);
|
|
|
|
COMPILER_RT_ABI du_int __udivmoddi4(du_int a, du_int b, du_int* rem);
|
|
|
|
#ifdef CRT_HAS_128BIT
|
2014-03-01 23:57:30 +08:00
|
|
|
COMPILER_RT_ABI si_int __clzti2(ti_int a);
|
2014-03-01 23:30:50 +08:00
|
|
|
COMPILER_RT_ABI tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem);
|
|
|
|
#endif
|
|
|
|
|
2015-10-07 10:58:11 +08:00
|
|
|
/* Definitions for builtins unavailable on MSVC */
|
|
|
|
#if defined(_MSC_VER) && !defined(__clang__)
|
|
|
|
#include <intrin.h>
|
|
|
|
|
|
|
|
uint32_t __inline __builtin_ctz(uint32_t value) {
|
2016-08-02 02:39:27 +08:00
|
|
|
unsigned long trailing_zero = 0;
|
2015-10-07 10:58:11 +08:00
|
|
|
if (_BitScanForward(&trailing_zero, value))
|
|
|
|
return trailing_zero;
|
|
|
|
return 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t __inline __builtin_clz(uint32_t value) {
|
2016-08-02 02:39:27 +08:00
|
|
|
unsigned long leading_zero = 0;
|
2015-10-07 10:58:11 +08:00
|
|
|
if (_BitScanReverse(&leading_zero, value))
|
|
|
|
return 31 - leading_zero;
|
|
|
|
return 32;
|
|
|
|
}
|
|
|
|
|
2015-10-11 01:57:37 +08:00
|
|
|
#if defined(_M_ARM) || defined(_M_X64)
|
2015-10-07 10:58:11 +08:00
|
|
|
uint32_t __inline __builtin_clzll(uint64_t value) {
|
2016-08-02 02:39:27 +08:00
|
|
|
unsigned long leading_zero = 0;
|
2015-10-07 10:58:11 +08:00
|
|
|
if (_BitScanReverse64(&leading_zero, value))
|
|
|
|
return 63 - leading_zero;
|
|
|
|
return 64;
|
|
|
|
}
|
2015-10-15 10:46:37 +08:00
|
|
|
#else
|
|
|
|
uint32_t __inline __builtin_clzll(uint64_t value) {
|
|
|
|
if (value == 0)
|
|
|
|
return 64;
|
|
|
|
uint32_t msh = (uint32_t)(value >> 32);
|
|
|
|
uint32_t lsh = (uint32_t)(value & 0xFFFFFFFF);
|
|
|
|
if (msh != 0)
|
|
|
|
return __builtin_clz(msh);
|
|
|
|
return 32 + __builtin_clz(lsh);
|
|
|
|
}
|
|
|
|
#endif
|
2015-10-07 10:58:11 +08:00
|
|
|
|
|
|
|
#define __builtin_clzl __builtin_clzll
|
2015-12-23 01:22:25 +08:00
|
|
|
#endif /* defined(_MSC_VER) && !defined(__clang__) */
|
2015-10-07 10:58:11 +08:00
|
|
|
|
2009-08-06 03:57:20 +08:00
|
|
|
#endif /* INT_LIB_H */
|