Path: blob/master/libs/compiler-rt/lib/builtins/int_lib.h
4395 views
/* ===-- int_lib.h - configuration header for compiler-rt -----------------===1*2* The LLVM Compiler Infrastructure3*4* This file is dual licensed under the MIT and the University of Illinois Open5* Source Licenses. See LICENSE.TXT for details.6*7* ===----------------------------------------------------------------------===8*9* This file is a configuration header for compiler-rt.10* This file is not part of the interface of this library.11*12* ===----------------------------------------------------------------------===13*/1415#ifndef INT_LIB_H16#define INT_LIB_H1718/* Assumption: Signed integral is 2's complement. */19/* Assumption: Right shift of signed negative is arithmetic shift. */20/* Assumption: Endianness is little or big (not mixed). */2122#if defined(__ELF__)23#define FNALIAS(alias_name, original_name) \24void alias_name() __attribute__((__alias__(#original_name)))25#define COMPILER_RT_ALIAS(aliasee) __attribute__((__alias__(#aliasee)))26#else27#define FNALIAS(alias, name) _Pragma("GCC error(\"alias unsupported on this file format\")")28#define COMPILER_RT_ALIAS(aliasee) _Pragma("GCC error(\"alias unsupported on this file format\")")29#endif3031/* ABI macro definitions */3233#if __ARM_EABI__34# ifdef COMPILER_RT_ARMHF_TARGET35# define COMPILER_RT_ABI36# else37# define COMPILER_RT_ABI __attribute__((__pcs__("aapcs")))38# endif39#else40# define COMPILER_RT_ABI41#endif4243#define AEABI_RTABI __attribute__((__pcs__("aapcs")))4445#if defined(_MSC_VER) && !defined(__clang__)46#define ALWAYS_INLINE __forceinline47#define NOINLINE __declspec(noinline)48#define NORETURN __declspec(noreturn)49#define UNUSED50#else51#define ALWAYS_INLINE __attribute__((always_inline))52#define NOINLINE __attribute__((noinline))53#define NORETURN __attribute__((noreturn))54#define UNUSED __attribute__((unused))55#endif5657#if defined(__NetBSD__) && (defined(_KERNEL) || defined(_STANDALONE))58/*59* Kernel and boot environment can't use normal headers,60* so use the equivalent system headers.61*/62# include <machine/limits.h>63# include <sys/stdint.h>64# include <sys/types.h>65#else66/* Include the standard compiler builtin headers we use functionality from. */67# include <limits.h>68# include <stdint.h>69# include <stdbool.h>70# include <float.h>71#endif7273/* Include the commonly used internal type definitions. */74#include "int_types.h"7576/* Include internal utility function declarations. */77#include "int_util.h"7879COMPILER_RT_ABI si_int __paritysi2(si_int a);80COMPILER_RT_ABI si_int __paritydi2(di_int a);8182COMPILER_RT_ABI di_int __divdi3(di_int a, di_int b);83COMPILER_RT_ABI si_int __divsi3(si_int a, si_int b);84COMPILER_RT_ABI su_int __udivsi3(su_int n, su_int d);8586COMPILER_RT_ABI su_int __udivmodsi4(su_int a, su_int b, su_int* rem);87COMPILER_RT_ABI du_int __udivmoddi4(du_int a, du_int b, du_int* rem);88#ifdef CRT_HAS_128BIT89COMPILER_RT_ABI si_int __clzti2(ti_int a);90COMPILER_RT_ABI tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem);91#endif9293/* Definitions for builtins unavailable on MSVC */94#if defined(_MSC_VER) && !defined(__clang__)95#include <intrin.h>9697uint32_t __inline __builtin_ctz(uint32_t value) {98unsigned long trailing_zero = 0;99if (_BitScanForward(&trailing_zero, value))100return trailing_zero;101return 32;102}103104uint32_t __inline __builtin_clz(uint32_t value) {105unsigned long leading_zero = 0;106if (_BitScanReverse(&leading_zero, value))107return 31 - leading_zero;108return 32;109}110111#if defined(_M_ARM) || defined(_M_X64)112uint32_t __inline __builtin_clzll(uint64_t value) {113unsigned long leading_zero = 0;114if (_BitScanReverse64(&leading_zero, value))115return 63 - leading_zero;116return 64;117}118#else119uint32_t __inline __builtin_clzll(uint64_t value) {120if (value == 0)121return 64;122uint32_t msh = (uint32_t)(value >> 32);123uint32_t lsh = (uint32_t)(value & 0xFFFFFFFF);124if (msh != 0)125return __builtin_clz(msh);126return 32 + __builtin_clz(lsh);127}128#endif129130#define __builtin_clzl __builtin_clzll131#endif /* defined(_MSC_VER) && !defined(__clang__) */132133#endif /* INT_LIB_H */134135136