llvm/compiler-rt/lib/builtins/int_types.h

//===-- int_lib.h - configuration header for compiler-rt  -----------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file is not part of the interface of this library.
//
// This file defines various standard types, most importantly a number of unions
// used to access parts of larger types.
//
//===----------------------------------------------------------------------===//

#ifndef INT_TYPES_H
#define INT_TYPES_H

#include "int_endianness.h"

// si_int is defined in Linux sysroot's asm-generic/siginfo.h
#ifdef si_int
#undef si_int
#endif
si_int;
su_int;
#if UINT_MAX == 0xFFFFFFFF
#define clzsi
#define ctzsi
#elif ULONG_MAX == 0xFFFFFFFF
#define clzsi
#define ctzsi
#else
#error could not determine appropriate clzsi macro for this system
#endif

di_int;
du_int;

dwords;

udwords;

#if defined(__LP64__) || defined(__wasm__) || defined(__mips64) ||             \
    defined(__SIZEOF_INT128__) || defined(_WIN64)
#define CRT_HAS_128BIT
#endif

// MSVC doesn't have a working 128bit integer type. Users should really compile
// compiler-rt with clang, but if they happen to be doing a standalone build for
// asan or something else, disable the 128 bit parts so things sort of work.
#if defined(_MSC_VER) && !defined(__clang__)
#undef CRT_HAS_128BIT
#endif

#ifdef CRT_HAS_128BIT
ti_int __attribute__((mode));
tu_int __attribute__((mode));

twords;

utwords;

static __inline ti_int make_ti(di_int h, di_int l) {}

static __inline tu_int make_tu(du_int h, du_int l) {}

#endif // CRT_HAS_128BIT

// FreeBSD's boot environment does not support using floating-point and poisons
// the float and double keywords.
#if defined(__FreeBSD__) && defined(_STANDALONE)
#define CRT_HAS_FLOATING_POINT
#else
#define CRT_HAS_FLOATING_POINT
#endif

#if CRT_HAS_FLOATING_POINT
float_bits;

double_bits;

uqwords;

// Check if the target supports 80 bit extended precision long doubles.
// Notably, on x86 Windows, MSVC only provides a 64-bit long double, but GCC
// still makes it 80 bits. Clang will match whatever compiler it is trying to
// be compatible with. On 32-bit x86 Android, long double is 64 bits, while on
// x86_64 Android, long double is 128 bits.
#if (defined(__i386__) || defined(__x86_64__)) &&                              \
    !(defined(_MSC_VER) || defined(__ANDROID__))
#define HAS_80_BIT_LONG_DOUBLE
#elif defined(__m68k__) || defined(__ia64__)
#define HAS_80_BIT_LONG_DOUBLE
#else
#define HAS_80_BIT_LONG_DOUBLE
#endif

#if HAS_80_BIT_LONG_DOUBLE
xf_float;
xf_bits;
#endif

#ifdef __powerpc64__
// From https://gcc.gnu.org/wiki/Ieee128PowerPC:
// PowerPC64 uses the following suffixes:
// IFmode: IBM extended double
// KFmode: IEEE 128-bit floating point
// TFmode: Matches the default for long double. With -mabi=ieeelongdouble,
//         it is IEEE 128-bit, with -mabi=ibmlongdouble IBM extended double
// Since compiler-rt only implements the tf set of libcalls, we use long double
// for the tf_float typedef.
typedef long double tf_float;
#define CRT_LDBL_128BIT
#define CRT_HAS_F128
#if __LDBL_MANT_DIG__ == 113 && !defined(__LONG_DOUBLE_IBM128__)
#define CRT_HAS_IEEE_TF
#define CRT_LDBL_IEEE_F128
#endif
#define TF_C
#elif __LDBL_MANT_DIG__ == 113 ||                                              \
    (__FLT_RADIX__ == 16 && __LDBL_MANT_DIG__ == 28)
// Use long double instead of __float128 if it matches the IEEE 128-bit format
// or the IBM hexadecimal format.
#define CRT_LDBL_128BIT
#define CRT_HAS_F128
#if __LDBL_MANT_DIG__ == 113
#define CRT_HAS_IEEE_TF
#define CRT_LDBL_IEEE_F128
#endif
typedef long double tf_float;
#define TF_C
#elif defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)
#define CRT_HAS___FLOAT128_KEYWORD
#define CRT_HAS_F128
// NB: we assume the __float128 type uses IEEE representation.
#define CRT_HAS_IEEE_TF
tf_float;
#define TF_C(x)
#endif

#ifdef CRT_HAS_F128
tf_bits;
#endif

// __(u)int128_t is currently needed to compile the *tf builtins as we would
// otherwise need to manually expand the bit manipulation on two 64-bit value.
#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128)
#define CRT_HAS_TF_MODE
#endif

#if __STDC_VERSION__ >= 199901L
Fcomplex;
Dcomplex;
Lcomplex;
#if defined(CRT_LDBL_128BIT)
typedef Lcomplex Qcomplex;
#define CRT_HAS_NATIVE_COMPLEX_F128
#elif defined(CRT_HAS___FLOAT128_KEYWORD)
#if defined(__clang_major__) && __clang_major__ > 10
// Clang prior to 11 did not support __float128 _Complex.
Qcomplex;
#define CRT_HAS_NATIVE_COMPLEX_F128
#elif defined(__GNUC__) && __GNUC__ >= 7
// GCC does not allow __float128 _Complex, but accepts _Float128 _Complex.
typedef _Float128 _Complex Qcomplex;
#define CRT_HAS_NATIVE_COMPLEX_F128
#endif
#endif

#define COMPLEX_REAL(x)
#define COMPLEX_IMAGINARY(x)
#else
typedef struct {
  float real, imaginary;
} Fcomplex;

typedef struct {
  double real, imaginary;
} Dcomplex;

typedef struct {
  long double real, imaginary;
} Lcomplex;

#define COMPLEX_REAL
#define COMPLEX_IMAGINARY
#endif

#ifdef CRT_HAS_NATIVE_COMPLEX_F128
#define COMPLEXTF_REAL(x)
#define COMPLEXTF_IMAGINARY(x)
#elif defined(CRT_HAS_F128)
typedef struct {
  tf_float real, imaginary;
} Qcomplex;
#define COMPLEXTF_REAL
#define COMPLEXTF_IMAGINARY
#endif

#endif // CRT_HAS_FLOATING_POINT
#endif // INT_TYPES_H