path
stringlengths 14
112
| content
stringlengths 0
6.32M
| size
int64 0
6.32M
| max_lines
int64 1
100k
| repo_name
stringclasses 2
values | autogenerated
bool 1
class |
---|---|---|---|---|---|
cosmopolitan/third_party/compiler_rt/fixsfti.c | /* clang-format off */
/* ===-- fixsfti.c - Implement __fixsfti -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
#ifdef CRT_HAS_128BIT
#define SINGLE_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
typedef ti_int fixint_t;
typedef tu_int fixuint_t;
#include "third_party/compiler_rt/fp_fixint_impl.inc"
COMPILER_RT_ABI ti_int
__fixsfti(fp_t a) {
return __fixint(a);
}
#endif /* CRT_HAS_128BIT */
| 769 | 30 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/fixunsxfdi.c | /* clang-format off */
/* ===-- fixunsxfdi.c - Implement __fixunsxfdi -----------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __fixunsxfdi for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#if !_ARCH_PPC
#include "third_party/compiler_rt/int_lib.h"
/* Returns: convert a to a unsigned long long, rounding toward zero.
* Negative values all become zero.
*/
/* Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
* du_int is a 64 bit integral type
* value in long double is representable in du_int or is negative
* (no range checking performed)
*/
/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
* 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
*/
COMPILER_RT_ABI du_int
__fixunsxfdi(long double a)
{
long_double_bits fb;
fb.f = a;
int e = (fb.u.high.s.low & 0x00007FFF) - 16383;
if (e < 0 || (fb.u.high.s.low & 0x00008000))
return 0;
if ((unsigned)e > sizeof(du_int) * CHAR_BIT)
return ~(du_int)0;
return fb.u.low.all >> (63 - e);
}
#endif
| 1,536 | 50 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/fixtfdi.c | /* clang-format off */
/* ===-- fixtfdi.c - Implement __fixtfdi -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#define QUAD_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
typedef di_int fixint_t;
typedef du_int fixuint_t;
#include "third_party/compiler_rt/fp_fixint_impl.inc"
COMPILER_RT_ABI di_int
__fixtfdi(fp_t a) {
return __fixint(a);
}
#endif
| 733 | 27 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/umoddi3.c | /* clang-format off */
/* ===-- umoddi3.c - Implement __umoddi3 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __umoddi3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
/* Returns: a % b */
COMPILER_RT_ABI du_int
__umoddi3(du_int a, du_int b)
{
du_int r;
__udivmoddi4(a, b, &r);
return r;
}
| 754 | 29 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/powitf2.c | /* clang-format off */
/* ===-- powitf2.cpp - Implement __powitf2 ---------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __powitf2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
#if _ARCH_PPC
/* Returns: a ^ b */
COMPILER_RT_ABI long double
__powitf2(long double a, si_int b)
{
const int recip = b < 0;
long double r = 1;
while (1)
{
if (b & 1)
r *= a;
b /= 2;
if (b == 0)
break;
a *= a;
}
return recip ? 1/r : r;
}
#endif
| 948 | 42 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/fixunsxfsi.c | /* clang-format off */
/* ===-- fixunsxfsi.c - Implement __fixunsxfsi -----------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __fixunsxfsi for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#if !_ARCH_PPC
#include "third_party/compiler_rt/int_lib.h"
/* Returns: convert a to a unsigned int, rounding toward zero.
* Negative values all become zero.
*/
/* Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
* su_int is a 32 bit integral type
* value in long double is representable in su_int or is negative
*/
/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
* 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
*/
COMPILER_RT_ABI su_int
__fixunsxfsi(long double a)
{
long_double_bits fb;
fb.f = a;
int e = (fb.u.high.s.low & 0x00007FFF) - 16383;
if (e < 0 || (fb.u.high.s.low & 0x00008000))
return 0;
if ((unsigned)e > sizeof(su_int) * CHAR_BIT)
return ~(su_int)0;
return fb.u.low.s.high >> (31 - e);
}
#endif /* !_ARCH_PPC */
| 1,501 | 49 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/mulosi4.c | /* clang-format off */
/*===-- mulosi4.c - Implement __mulosi4 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __mulosi4 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
/* Returns: a * b */
/* Effects: sets *overflow to 1 if a * b overflows */
COMPILER_RT_ABI si_int
__mulosi4(si_int a, si_int b, int* overflow)
{
const int N = (int)(sizeof(si_int) * CHAR_BIT);
const si_int MIN = (si_int)1 << (N-1);
const si_int MAX = ~MIN;
*overflow = 0;
si_int result = a * b;
if (a == MIN)
{
if (b != 0 && b != 1)
*overflow = 1;
return result;
}
if (b == MIN)
{
if (a != 0 && a != 1)
*overflow = 1;
return result;
}
si_int sa = a >> (N - 1);
si_int abs_a = (a ^ sa) - sa;
si_int sb = b >> (N - 1);
si_int abs_b = (b ^ sb) - sb;
if (abs_a < 2 || abs_b < 2)
return result;
if (sa == sb)
{
if (abs_a > MAX / abs_b)
*overflow = 1;
}
else
{
if (abs_a > MIN / -abs_b)
*overflow = 1;
}
return result;
}
| 1,513 | 62 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/mulsf3.c | /* clang-format off */
//===-- lib/mulsf3.c - Single-precision multiplication ------------*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements single-precision soft-float multiplication
// with the IEEE-754 default rounding (to nearest, ties to even).
//
//===----------------------------------------------------------------------===//
STATIC_YOINK("huge_compiler_rt_license");
#define SINGLE_PRECISION
#include "third_party/compiler_rt/fp_mul_impl.inc"
COMPILER_RT_ABI fp_t __mulsf3(fp_t a, fp_t b) {
return __mulXf3__(a, b);
}
#if defined(__ARM_EABI__)
#if defined(COMPILER_RT_ARMHF_TARGET)
AEABI_RTABI fp_t __aeabi_fmul(fp_t a, fp_t b) {
return __mulsf3(a, b);
}
#else
AEABI_RTABI fp_t __aeabi_fmul(fp_t a, fp_t b) COMPILER_RT_ALIAS(__mulsf3);
#endif
#endif
| 1,034 | 34 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/divxc3.c | /* clang-format off */
/* ===-- divxc3.c - Implement __divxc3 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __divxc3 for the compiler_rt library.
*
*/
STATIC_YOINK("huge_compiler_rt_license");
#if !_ARCH_PPC
#include "third_party/compiler_rt/int_lib.h"
#include "third_party/compiler_rt/int_math.h"
/* Returns: the quotient of (a + ib) / (c + id) */
COMPILER_RT_ABI Lcomplex
__divxc3(long double __a, long double __b, long double __c, long double __d)
{
int __ilogbw = 0;
long double __logbw = crt_logbl(crt_fmaxl(crt_fabsl(__c), crt_fabsl(__d)));
if (crt_isfinite(__logbw))
{
__ilogbw = (int)__logbw;
__c = crt_scalbnl(__c, -__ilogbw);
__d = crt_scalbnl(__d, -__ilogbw);
}
long double __denom = __c * __c + __d * __d;
Lcomplex z;
COMPLEX_REAL(z) = crt_scalbnl((__a * __c + __b * __d) / __denom, -__ilogbw);
COMPLEX_IMAGINARY(z) = crt_scalbnl((__b * __c - __a * __d) / __denom, -__ilogbw);
if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z)))
{
if ((__denom == 0) && (!crt_isnan(__a) || !crt_isnan(__b)))
{
COMPLEX_REAL(z) = crt_copysignl(CRT_INFINITY, __c) * __a;
COMPLEX_IMAGINARY(z) = crt_copysignl(CRT_INFINITY, __c) * __b;
}
else if ((crt_isinf(__a) || crt_isinf(__b)) &&
crt_isfinite(__c) && crt_isfinite(__d))
{
__a = crt_copysignl(crt_isinf(__a) ? 1 : 0, __a);
__b = crt_copysignl(crt_isinf(__b) ? 1 : 0, __b);
COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c + __b * __d);
COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__b * __c - __a * __d);
}
else if (crt_isinf(__logbw) && __logbw > 0 &&
crt_isfinite(__a) && crt_isfinite(__b))
{
__c = crt_copysignl(crt_isinf(__c) ? 1 : 0, __c);
__d = crt_copysignl(crt_isinf(__d) ? 1 : 0, __d);
COMPLEX_REAL(z) = 0 * (__a * __c + __b * __d);
COMPLEX_IMAGINARY(z) = 0 * (__b * __c - __a * __d);
}
}
return z;
}
#endif
| 2,372 | 67 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/muldf3.c | /* clang-format off */
//===-- lib/muldf3.c - Double-precision multiplication ------------*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements double-precision soft-float multiplication
// with the IEEE-754 default rounding (to nearest, ties to even).
//
//===----------------------------------------------------------------------===//
STATIC_YOINK("huge_compiler_rt_license");
#define DOUBLE_PRECISION
#include "third_party/compiler_rt/fp_mul_impl.inc"
COMPILER_RT_ABI fp_t __muldf3(fp_t a, fp_t b) {
return __mulXf3__(a, b);
}
#if defined(__ARM_EABI__)
#if defined(COMPILER_RT_ARMHF_TARGET)
AEABI_RTABI fp_t __aeabi_dmul(fp_t a, fp_t b) {
return __muldf3(a, b);
}
#else
AEABI_RTABI fp_t __aeabi_dmul(fp_t a, fp_t b) COMPILER_RT_ALIAS(__muldf3);
#endif
#endif
| 1,034 | 34 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/floattisf.c | /* clang-format off */
/* ===-- floattisf.c - Implement __floattisf -------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __floattisf for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
#ifdef CRT_HAS_128BIT
/* Returns: convert a to a float, rounding toward even. */
/* Assumption: float is a IEEE 32 bit floating point type
* ti_int is a 128 bit integral type
*/
/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
COMPILER_RT_ABI float
__floattisf(ti_int a)
{
if (a == 0)
return 0.0F;
const unsigned N = sizeof(ti_int) * CHAR_BIT;
const ti_int s = a >> (N-1);
a = (a ^ s) - s;
int sd = N - __clzti2(a); /* number of significant digits */
int e = sd - 1; /* exponent */
if (sd > FLT_MANT_DIG)
{
/* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
* finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
* 12345678901234567890123456
* 1 = msb 1 bit
* P = bit FLT_MANT_DIG-1 bits to the right of 1
* Q = bit FLT_MANT_DIG bits to the right of 1
* R = "or" of all bits to the right of Q
*/
switch (sd)
{
case FLT_MANT_DIG + 1:
a <<= 1;
break;
case FLT_MANT_DIG + 2:
break;
default:
a = ((tu_int)a >> (sd - (FLT_MANT_DIG+2))) |
((a & ((tu_int)(-1) >> ((N + FLT_MANT_DIG+2) - sd))) != 0);
};
/* finish: */
a |= (a & 4) != 0; /* Or P into R */
++a; /* round - this step may add a significant bit */
a >>= 2; /* dump Q and R */
/* a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits */
if (a & ((tu_int)1 << FLT_MANT_DIG))
{
a >>= 1;
++e;
}
/* a is now rounded to FLT_MANT_DIG bits */
}
else
{
a <<= (FLT_MANT_DIG - sd);
/* a is now rounded to FLT_MANT_DIG bits */
}
float_bits fb;
fb.u = ((su_int)s & 0x80000000) | /* sign */
((e + 127) << 23) | /* exponent */
((su_int)a & 0x007FFFFF); /* mantissa */
return fb.f;
}
#endif /* CRT_HAS_128BIT */
| 2,692 | 86 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/floatunsitf.c | /* clang-format off */
//===-- lib/floatunsitf.c - uint -> quad-precision conversion -----*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements unsigned integer to quad-precision conversion for the
// compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even
// mode.
//
//===----------------------------------------------------------------------===//
STATIC_YOINK("huge_compiler_rt_license");
#define QUAD_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
COMPILER_RT_ABI fp_t __floatunsitf(unsigned int a) {
const int aWidth = sizeof a * CHAR_BIT;
// Handle zero as a special case to protect clz
if (a == 0) return fromRep(0);
// Exponent of (fp_t)a is the width of abs(a).
const int exponent = (aWidth - 1) - __builtin_clz(a);
rep_t result;
// Shift a into the significand field and clear the implicit bit.
const int shift = significandBits - exponent;
result = (rep_t)a << shift ^ implicitBit;
// Insert the exponent
result += (rep_t)(exponent + exponentBias) << significandBits;
return fromRep(result);
}
#endif
| 1,415 | 44 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/floatunsisf.c | /* clang-format off */
//===-- lib/floatunsisf.c - uint -> single-precision conversion ---*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements unsigned integer to single-precision conversion for the
// compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even
// mode.
//
//===----------------------------------------------------------------------===//
STATIC_YOINK("huge_compiler_rt_license");
#define SINGLE_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#include "third_party/compiler_rt/int_lib.h"
COMPILER_RT_ABI fp_t
__floatunsisf(unsigned int a) {
const int aWidth = sizeof a * CHAR_BIT;
// Handle zero as a special case to protect clz
if (a == 0) return fromRep(0);
// Exponent of (fp_t)a is the width of abs(a).
const int exponent = (aWidth - 1) - __builtin_clz(a);
rep_t result;
// Shift a into the significand field, rounding if it is a right-shift
if (exponent <= significandBits) {
const int shift = significandBits - exponent;
result = (rep_t)a << shift ^ implicitBit;
} else {
const int shift = exponent - significandBits;
result = (rep_t)a >> shift ^ implicitBit;
rep_t round = (rep_t)a << (typeWidth - shift);
if (round > signBit) result++;
if (round == signBit) result += result & 1;
}
// Insert the exponent
result += (rep_t)(exponent + exponentBias) << significandBits;
return fromRep(result);
}
#if defined(__ARM_EABI__)
#if defined(COMPILER_RT_ARMHF_TARGET)
AEABI_RTABI fp_t __aeabi_ui2f(unsigned int a) {
return __floatunsisf(a);
}
#else
AEABI_RTABI fp_t __aeabi_ui2f(unsigned int a) COMPILER_RT_ALIAS(__floatunsisf);
#endif
#endif
| 1,984 | 62 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/ashldi3.c | /* clang-format off */
/* ====-- ashldi3.c - Implement __ashldi3 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __ashldi3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
/* Returns: a << b */
/* Precondition: 0 <= b < bits_in_dword */
COMPILER_RT_ABI di_int
__ashldi3(di_int a, si_int b)
{
const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT);
dwords input;
dwords result;
input.all = a;
if (b & bits_in_word) /* bits_in_word <= b < bits_in_dword */
{
result.s.low = 0;
result.s.high = input.s.low << (b - bits_in_word);
}
else /* 0 <= b < bits_in_word */
{
if (b == 0)
return a;
result.s.low = input.s.low << b;
result.s.high = (input.s.high << b) | (input.s.low >> (bits_in_word - b));
}
return result.all;
}
#if defined(__ARM_EABI__)
AEABI_RTABI di_int __aeabi_llsl(di_int a, si_int b) COMPILER_RT_ALIAS(__ashldi3);
#endif
| 1,385 | 49 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/clzsi2.c | /* clang-format off */
/* ===-- clzsi2.c - Implement __clzsi2 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __clzsi2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
/* Returns: the number of leading 0-bits */
/* Precondition: a != 0 */
COMPILER_RT_ABI si_int
__clzsi2(si_int a)
{
su_int x = (su_int)a;
si_int t = ((x & 0xFFFF0000) == 0) << 4; /* if (x is small) t = 16 else 0 */
x >>= 16 - t; /* x = [0 - 0xFFFF] */
su_int r = t; /* r = [0, 16] */
/* return r + clz(x) */
t = ((x & 0xFF00) == 0) << 3;
x >>= 8 - t; /* x = [0 - 0xFF] */
r += t; /* r = [0, 8, 16, 24] */
/* return r + clz(x) */
t = ((x & 0xF0) == 0) << 2;
x >>= 4 - t; /* x = [0 - 0xF] */
r += t; /* r = [0, 4, 8, 12, 16, 20, 24, 28] */
/* return r + clz(x) */
t = ((x & 0xC) == 0) << 1;
x >>= 2 - t; /* x = [0 - 3] */
r += t; /* r = [0 - 30] and is even */
/* return r + clz(x) */
/* switch (x)
* {
* case 0:
* return r + 2;
* case 1:
* return r + 1;
* case 2:
* case 3:
* return r;
* }
*/
return r + ((2 - x) & -((x & 2) == 0));
}
| 1,645 | 57 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/int_math.h | /* clang-format off */
/* ===-- int_math.h - internal math inlines ---------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===-----------------------------------------------------------------------===
*
* This file is not part of the interface of this library.
*
* This file defines substitutes for the libm functions used in some of the
* compiler-rt implementations, defined in such a way that there is not a direct
* dependency on libm or math.h. Instead, we use the compiler builtin versions
* where available. This reduces our dependencies on the system SDK by foisting
* the responsibility onto the compiler.
*
* ===-----------------------------------------------------------------------===
*/
#ifndef INT_MATH_H
#define INT_MATH_H
#ifndef __has_builtin
# define __has_builtin(x) 0
#endif
#if defined(_MSC_VER) && !defined(__clang__)
#define CRT_INFINITY INFINITY
#else
#define CRT_INFINITY __builtin_huge_valf()
#endif
#if defined(_MSC_VER) && !defined(__clang__)
#define crt_isfinite(x) _finite((x))
#define crt_isinf(x) !_finite((x))
#define crt_isnan(x) _isnan((x))
#else
/* Define crt_isfinite in terms of the builtin if available, otherwise provide
* an alternate version in terms of our other functions. This supports some
* versions of GCC which didn't have __builtin_isfinite.
*/
#if __has_builtin(__builtin_isfinite)
# define crt_isfinite(x) __builtin_isfinite((x))
#elif defined(__GNUC__)
# define crt_isfinite(x) \
(({ \
__typeof((x)) x_ = (x); \
!crt_isinf(x_) && !crt_isnan(x_); \
}))
#else
# error "Do not know how to check for infinity"
#endif /* __has_builtin(__builtin_isfinite) */
#define crt_isinf(x) __builtin_isinf((x))
#define crt_isnan(x) __builtin_isnan((x))
#endif /* _MSC_VER */
#if defined(_MSC_VER) && !defined(__clang__)
#define crt_copysign(x, y) copysign((x), (y))
#define crt_copysignf(x, y) copysignf((x), (y))
#define crt_copysignl(x, y) copysignl((x), (y))
#else
#define crt_copysign(x, y) __builtin_copysign((x), (y))
#define crt_copysignf(x, y) __builtin_copysignf((x), (y))
#define crt_copysignl(x, y) __builtin_copysignl((x), (y))
#endif
#if defined(_MSC_VER) && !defined(__clang__)
#define crt_fabs(x) fabs((x))
#define crt_fabsf(x) fabsf((x))
#define crt_fabsl(x) fabs((x))
#else
#define crt_fabs(x) __builtin_fabs((x))
#define crt_fabsf(x) __builtin_fabsf((x))
#define crt_fabsl(x) __builtin_fabsl((x))
#endif
#if defined(_MSC_VER) && !defined(__clang__)
#define crt_fmax(x, y) __max((x), (y))
#define crt_fmaxf(x, y) __max((x), (y))
#define crt_fmaxl(x, y) __max((x), (y))
#else
#define crt_fmax(x, y) __builtin_fmax((x), (y))
#define crt_fmaxf(x, y) __builtin_fmaxf((x), (y))
#define crt_fmaxl(x, y) __builtin_fmaxl((x), (y))
#endif
#if defined(_MSC_VER) && !defined(__clang__)
#define crt_logbl(x) logbl((x))
#else
#define crt_logbl(x) __builtin_logbl((x))
#endif
#if defined(_MSC_VER) && !defined(__clang__)
#define crt_scalbn(x, y) scalbn((x), (y))
#define crt_scalbnf(x, y) scalbnf((x), (y))
#define crt_scalbnl(x, y) scalbnl((x), (y))
#else
#define crt_scalbn(x, y) __builtin_scalbn((x), (y))
#define crt_scalbnf(x, y) __builtin_scalbnf((x), (y))
#define crt_scalbnl(x, y) __builtin_scalbnl((x), (y))
#endif
#endif /* INT_MATH_H */
| 3,413 | 106 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/floatsidf.c | /* clang-format off */
//===-- lib/floatsidf.c - integer -> double-precision conversion --*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements integer to double-precision conversion for the
// compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even
// mode.
//
//===----------------------------------------------------------------------===//
STATIC_YOINK("huge_compiler_rt_license");
#define DOUBLE_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#include "third_party/compiler_rt/int_lib.h"
COMPILER_RT_ABI fp_t
__floatsidf(int a) {
const int aWidth = sizeof a * CHAR_BIT;
// Handle zero as a special case to protect clz
if (a == 0)
return fromRep(0);
// All other cases begin by extracting the sign and absolute value of a
rep_t sign = 0;
if (a < 0) {
sign = signBit;
a = -a;
}
// Exponent of (fp_t)a is the width of abs(a).
const int exponent = (aWidth - 1) - __builtin_clz(a);
rep_t result;
// Shift a into the significand field and clear the implicit bit. Extra
// cast to unsigned int is necessary to get the correct behavior for
// the input INT_MIN.
const int shift = significandBits - exponent;
result = (rep_t)(unsigned int)a << shift ^ implicitBit;
// Insert the exponent
result += (rep_t)(exponent + exponentBias) << significandBits;
// Insert the sign bit and return
return fromRep(result | sign);
}
#if defined(__ARM_EABI__)
#if defined(COMPILER_RT_ARMHF_TARGET)
AEABI_RTABI fp_t __aeabi_i2d(int a) {
return __floatsidf(a);
}
#else
AEABI_RTABI fp_t __aeabi_i2d(int a) COMPILER_RT_ALIAS(__floatsidf);
#endif
#endif
| 1,956 | 65 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/floattidf.c | /* clang-format off */
/* ===-- floattidf.c - Implement __floattidf -------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __floattidf for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
#ifdef CRT_HAS_128BIT
/* Returns: convert a to a double, rounding toward even.*/
/* Assumption: double is a IEEE 64 bit floating point type
* ti_int is a 128 bit integral type
*/
/* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */
COMPILER_RT_ABI double
__floattidf(ti_int a)
{
if (a == 0)
return 0.0;
const unsigned N = sizeof(ti_int) * CHAR_BIT;
const ti_int s = a >> (N-1);
a = (a ^ s) - s;
int sd = N - __clzti2(a); /* number of significant digits */
int e = sd - 1; /* exponent */
if (sd > DBL_MANT_DIG)
{
/* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
* finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
* 12345678901234567890123456
* 1 = msb 1 bit
* P = bit DBL_MANT_DIG-1 bits to the right of 1
* Q = bit DBL_MANT_DIG bits to the right of 1
* R = "or" of all bits to the right of Q
*/
switch (sd)
{
case DBL_MANT_DIG + 1:
a <<= 1;
break;
case DBL_MANT_DIG + 2:
break;
default:
a = ((tu_int)a >> (sd - (DBL_MANT_DIG+2))) |
((a & ((tu_int)(-1) >> ((N + DBL_MANT_DIG+2) - sd))) != 0);
};
/* finish: */
a |= (a & 4) != 0; /* Or P into R */
++a; /* round - this step may add a significant bit */
a >>= 2; /* dump Q and R */
/* a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits */
if (a & ((tu_int)1 << DBL_MANT_DIG))
{
a >>= 1;
++e;
}
/* a is now rounded to DBL_MANT_DIG bits */
}
else
{
a <<= (DBL_MANT_DIG - sd);
/* a is now rounded to DBL_MANT_DIG bits */
}
double_bits fb;
fb.u.s.high = ((su_int)s & 0x80000000) | /* sign */
((e + 1023) << 20) | /* exponent */
((su_int)(a >> 32) & 0x000FFFFF); /* mantissa-high */
fb.u.s.low = (su_int)a; /* mantissa-low */
return fb.f;
}
#endif /* CRT_HAS_128BIT */
| 2,846 | 87 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/floatundisf.c | /* clang-format off */
/*===-- floatundisf.c - Implement __floatundisf ---------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __floatundisf for the compiler_rt library.
*
*===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
/* Returns: convert a to a float, rounding toward even. */
/* Assumption: float is a IEEE 32 bit floating point type
* du_int is a 64 bit integral type
*/
/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
#include "third_party/compiler_rt/int_lib.h"
COMPILER_RT_ABI float
__floatundisf(du_int a)
{
if (a == 0)
return 0.0F;
const unsigned N = sizeof(du_int) * CHAR_BIT;
int sd = N - __builtin_clzll(a); /* number of significant digits */
int e = sd - 1; /* 8 exponent */
if (sd > FLT_MANT_DIG)
{
/* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
* finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
* 12345678901234567890123456
* 1 = msb 1 bit
* P = bit FLT_MANT_DIG-1 bits to the right of 1
* Q = bit FLT_MANT_DIG bits to the right of 1
* R = "or" of all bits to the right of Q
*/
switch (sd)
{
case FLT_MANT_DIG + 1:
a <<= 1;
break;
case FLT_MANT_DIG + 2:
break;
default:
a = (a >> (sd - (FLT_MANT_DIG+2))) |
((a & ((du_int)(-1) >> ((N + FLT_MANT_DIG+2) - sd))) != 0);
};
/* finish: */
a |= (a & 4) != 0; /* Or P into R */
++a; /* round - this step may add a significant bit */
a >>= 2; /* dump Q and R */
/* a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits */
if (a & ((du_int)1 << FLT_MANT_DIG))
{
a >>= 1;
++e;
}
/* a is now rounded to FLT_MANT_DIG bits */
}
else
{
a <<= (FLT_MANT_DIG - sd);
/* a is now rounded to FLT_MANT_DIG bits */
}
float_bits fb;
fb.u = ((e + 127) << 23) | /* exponent */
((su_int)a & 0x007FFFFF); /* mantissa */
return fb.f;
}
#if defined(__ARM_EABI__)
#if defined(COMPILER_RT_ARMHF_TARGET)
AEABI_RTABI float __aeabi_ul2f(du_int a) {
return __floatundisf(a);
}
#else
AEABI_RTABI float __aeabi_ul2f(du_int a) COMPILER_RT_ALIAS(__floatundisf);
#endif
#endif
| 2,776 | 89 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/comparedf2.c | /* clang-format off */
//===-- lib/comparedf2.c - Double-precision comparisons -----------*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// // This file implements the following soft-float comparison routines:
//
// __eqdf2 __gedf2 __unorddf2
// __ledf2 __gtdf2
// __ltdf2
// __nedf2
//
// The semantics of the routines grouped in each column are identical, so there
// is a single implementation for each, and wrappers to provide the other names.
//
// The main routines behave as follows:
//
// __ledf2(a,b) returns -1 if a < b
// 0 if a == b
// 1 if a > b
// 1 if either a or b is NaN
//
// __gedf2(a,b) returns -1 if a < b
// 0 if a == b
// 1 if a > b
// -1 if either a or b is NaN
//
// __unorddf2(a,b) returns 0 if both a and b are numbers
// 1 if either a or b is NaN
//
// Note that __ledf2( ) and __gedf2( ) are identical except in their handling of
// NaN values.
//
//===----------------------------------------------------------------------===//
STATIC_YOINK("huge_compiler_rt_license");
#define DOUBLE_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
enum LE_RESULT {
LE_LESS = -1,
LE_EQUAL = 0,
LE_GREATER = 1,
LE_UNORDERED = 1
};
COMPILER_RT_ABI enum LE_RESULT
__ledf2(fp_t a, fp_t b) {
const srep_t aInt = toRep(a);
const srep_t bInt = toRep(b);
const rep_t aAbs = aInt & absMask;
const rep_t bAbs = bInt & absMask;
// If either a or b is NaN, they are unordered.
if (aAbs > infRep || bAbs > infRep) return LE_UNORDERED;
// If a and b are both zeros, they are equal.
if ((aAbs | bAbs) == 0) return LE_EQUAL;
// If at least one of a and b is positive, we get the same result comparing
// a and b as signed integers as we would with a floating-point compare.
if ((aInt & bInt) >= 0) {
if (aInt < bInt) return LE_LESS;
else if (aInt == bInt) return LE_EQUAL;
else return LE_GREATER;
}
// Otherwise, both are negative, so we need to flip the sense of the
// comparison to get the correct result. (This assumes a twos- or ones-
// complement integer representation; if integers are represented in a
// sign-magnitude representation, then this flip is incorrect).
else {
if (aInt > bInt) return LE_LESS;
else if (aInt == bInt) return LE_EQUAL;
else return LE_GREATER;
}
}
// Alias for libgcc compatibility
COMPILER_RT_ABI enum LE_RESULT
__cmpdf2(fp_t a, fp_t b) {
return __ledf2(a, b);
}
enum GE_RESULT {
GE_LESS = -1,
GE_EQUAL = 0,
GE_GREATER = 1,
GE_UNORDERED = -1 // Note: different from LE_UNORDERED
};
COMPILER_RT_ABI enum GE_RESULT
__gedf2(fp_t a, fp_t b) {
const srep_t aInt = toRep(a);
const srep_t bInt = toRep(b);
const rep_t aAbs = aInt & absMask;
const rep_t bAbs = bInt & absMask;
if (aAbs > infRep || bAbs > infRep) return GE_UNORDERED;
if ((aAbs | bAbs) == 0) return GE_EQUAL;
if ((aInt & bInt) >= 0) {
if (aInt < bInt) return GE_LESS;
else if (aInt == bInt) return GE_EQUAL;
else return GE_GREATER;
} else {
if (aInt > bInt) return GE_LESS;
else if (aInt == bInt) return GE_EQUAL;
else return GE_GREATER;
}
}
COMPILER_RT_ABI int
__unorddf2(fp_t a, fp_t b) {
const rep_t aAbs = toRep(a) & absMask;
const rep_t bAbs = toRep(b) & absMask;
return aAbs > infRep || bAbs > infRep;
}
// The following are alternative names for the preceding routines.
COMPILER_RT_ABI enum LE_RESULT
__eqdf2(fp_t a, fp_t b) {
return __ledf2(a, b);
}
COMPILER_RT_ABI enum LE_RESULT
__ltdf2(fp_t a, fp_t b) {
return __ledf2(a, b);
}
COMPILER_RT_ABI enum LE_RESULT
__nedf2(fp_t a, fp_t b) {
return __ledf2(a, b);
}
COMPILER_RT_ABI enum GE_RESULT
__gtdf2(fp_t a, fp_t b) {
return __gedf2(a, b);
}
#if defined(__ARM_EABI__)
#if defined(COMPILER_RT_ARMHF_TARGET)
AEABI_RTABI int __aeabi_dcmpun(fp_t a, fp_t b) {
return __unorddf2(a, b);
}
#else
AEABI_RTABI int __aeabi_dcmpun(fp_t a, fp_t b) COMPILER_RT_ALIAS(__unorddf2);
#endif
#endif
| 4,520 | 158 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/extendsfdf2.c | /* clang-format off */
//===-- lib/extendsfdf2.c - single -> double conversion -----------*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
STATIC_YOINK("huge_compiler_rt_license");
#define SRC_SINGLE
#define DST_DOUBLE
#include "third_party/compiler_rt/fp_extend_impl.inc"
COMPILER_RT_ABI double __extendsfdf2(float a) {
return __extendXfYf2__(a);
}
#if defined(__ARM_EABI__)
#if defined(COMPILER_RT_ARMHF_TARGET)
AEABI_RTABI double __aeabi_f2d(float a) {
return __extendsfdf2(a);
}
#else
AEABI_RTABI double __aeabi_f2d(float a) COMPILER_RT_ALIAS(__extendsfdf2);
#endif
#endif
| 830 | 31 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/int_lib.h | /* clang-format off */
/* ===-- int_lib.h - configuration header for compiler-rt -----------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file is a configuration header for compiler-rt.
* This file is not part of the interface of this library.
*
* ===----------------------------------------------------------------------===
*/
#ifndef INT_LIB_H
#define INT_LIB_H
#define CRT_HAS_128BIT 1
/* Assumption: lool univac arithmetic */
/* Assumption: lool cray signed shift */
/* Assumption: lool pdp11 float byte order */
#if defined(__ELF__)
#define FNALIAS(alias_name, original_name) \
void alias_name() __attribute__((__alias__(#original_name)))
#define COMPILER_RT_ALIAS(aliasee) __attribute__((__alias__(#aliasee)))
#else
#define FNALIAS(alias, name) _Pragma("GCC error(\"alias unsupported on this file format\")")
#define COMPILER_RT_ALIAS(aliasee) _Pragma("GCC error(\"alias unsupported on this file format\")")
#endif
/* ABI macro definitions */
#if __ARM_EABI__
# ifdef COMPILER_RT_ARMHF_TARGET
# define COMPILER_RT_ABI
# else
# define COMPILER_RT_ABI __attribute__((__pcs__("aapcs")))
# endif
#else
# define COMPILER_RT_ABI
#endif
#define AEABI_RTABI __attribute__((__pcs__("aapcs")))
#ifdef _MSC_VER
#define ALWAYS_INLINE __forceinline
#define NORETURN __declspec(noreturn)
#define UNUSED
#else
#define ALWAYS_INLINE __attribute__((__always_inline__))
#define NORETURN __attribute__((__noreturn__))
#define UNUSED __attribute__((__unused__))
#endif
#include "libc/literal.h"
#include "libc/math.h"
/* Include the commonly used internal type definitions. */
#include "third_party/compiler_rt/int_types.h"
/* Include internal utility function declarations. */
#include "third_party/compiler_rt/int_util.h"
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
COMPILER_RT_ABI si_int __clzti2(ti_int a);
COMPILER_RT_ABI ti_int __divmodti4(ti_int a, ti_int b, tu_int *rem);
COMPILER_RT_ABI tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem);
#endif
/* Definitions for builtins unavailable on MSVC */
#if defined(_MSC_VER) && !defined(__clang__)
#include <intrin.h>
uint32_t __inline __builtin_ctz(uint32_t value) {
unsigned long trailing_zero = 0;
if (_BitScanForward(&trailing_zero, value))
return trailing_zero;
return 32;
}
uint32_t __inline __builtin_clz(uint32_t value) {
unsigned long leading_zero = 0;
if (_BitScanReverse(&leading_zero, value))
return 31 - leading_zero;
return 32;
}
#if defined(_M_ARM) || defined(_M_X64)
uint32_t __inline __builtin_clzll(uint64_t value) {
unsigned long leading_zero = 0;
if (_BitScanReverse64(&leading_zero, value))
return 63 - leading_zero;
return 64;
}
#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
#define __builtin_clzl __builtin_clzll
#endif /* defined(_MSC_VER) && !defined(__clang__) */
#endif /* INT_LIB_H */
| 3,659 | 123 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/muldc3.c | /* clang-format off */
/* ===-- muldc3.c - Implement __muldc3 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __muldc3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
#include "third_party/compiler_rt/int_math.h"
/* Returns: the product of a + ib and c + id */
COMPILER_RT_ABI Dcomplex
__muldc3(double __a, double __b, double __c, double __d)
{
double __ac = __a * __c;
double __bd = __b * __d;
double __ad = __a * __d;
double __bc = __b * __c;
Dcomplex z;
COMPLEX_REAL(z) = __ac - __bd;
COMPLEX_IMAGINARY(z) = __ad + __bc;
if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z)))
{
int __recalc = 0;
if (crt_isinf(__a) || crt_isinf(__b))
{
__a = crt_copysign(crt_isinf(__a) ? 1 : 0, __a);
__b = crt_copysign(crt_isinf(__b) ? 1 : 0, __b);
if (crt_isnan(__c))
__c = crt_copysign(0, __c);
if (crt_isnan(__d))
__d = crt_copysign(0, __d);
__recalc = 1;
}
if (crt_isinf(__c) || crt_isinf(__d))
{
__c = crt_copysign(crt_isinf(__c) ? 1 : 0, __c);
__d = crt_copysign(crt_isinf(__d) ? 1 : 0, __d);
if (crt_isnan(__a))
__a = crt_copysign(0, __a);
if (crt_isnan(__b))
__b = crt_copysign(0, __b);
__recalc = 1;
}
if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) ||
crt_isinf(__ad) || crt_isinf(__bc)))
{
if (crt_isnan(__a))
__a = crt_copysign(0, __a);
if (crt_isnan(__b))
__b = crt_copysign(0, __b);
if (crt_isnan(__c))
__c = crt_copysign(0, __c);
if (crt_isnan(__d))
__d = crt_copysign(0, __d);
__recalc = 1;
}
if (__recalc)
{
COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c - __b * __d);
COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__a * __d + __b * __c);
}
}
return z;
}
| 2,526 | 77 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/popcountsi2.c | /* clang-format off */
/* ===-- popcountsi2.c - Implement __popcountsi2 ---------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __popcountsi2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
/* Returns: count of 1 bits */
COMPILER_RT_ABI si_int
__popcountsi2(si_int a)
{
su_int x = (su_int)a;
x = x - ((x >> 1) & 0x55555555);
/* Every 2 bits holds the sum of every pair of bits */
x = ((x >> 2) & 0x33333333) + (x & 0x33333333);
/* Every 4 bits holds the sum of every 4-set of bits (3 significant bits) */
x = (x + (x >> 4)) & 0x0F0F0F0F;
/* Every 8 bits holds the sum of every 8-set of bits (4 significant bits) */
x = (x + (x >> 16));
/* The lower 16 bits hold two 8 bit sums (5 significant bits).*/
/* Upper 16 bits are garbage */
return (x + (x >> 8)) & 0x0000003F; /* (6 significant bits) */
}
| 1,281 | 37 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/fixunsxfti.c | /* clang-format off */
/* ===-- fixunsxfti.c - Implement __fixunsxfti -----------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __fixunsxfti for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
#ifdef CRT_HAS_128BIT
/* Returns: convert a to a unsigned long long, rounding toward zero.
* Negative values all become zero.
*/
/* Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
* tu_int is a 128 bit integral type
* value in long double is representable in tu_int or is negative
*/
/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
* 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
*/
COMPILER_RT_ABI tu_int
__fixunsxfti(long double a)
{
long_double_bits fb;
fb.f = a;
int e = (fb.u.high.s.low & 0x00007FFF) - 16383;
if (e < 0 || (fb.u.high.s.low & 0x00008000))
return 0;
if ((unsigned)e > sizeof(tu_int) * CHAR_BIT)
return ~(tu_int)0;
tu_int r = fb.u.low.all;
if (e > 63)
r <<= (e - 63);
else
r >>= (63 - e);
return r;
}
#endif /* CRT_HAS_128BIT */
| 1,588 | 54 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/floatunditf.c | /* clang-format off */
//===-- lib/floatunditf.c - uint -> quad-precision conversion -----*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements du_int to quad-precision conversion for the
// compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even
// mode.
//
//===----------------------------------------------------------------------===//
STATIC_YOINK("huge_compiler_rt_license");
#define QUAD_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
COMPILER_RT_ABI fp_t __floatunditf(du_int a) {
const int aWidth = sizeof a * CHAR_BIT;
// Handle zero as a special case to protect clz
if (a == 0) return fromRep(0);
// Exponent of (fp_t)a is the width of abs(a).
const int exponent = (aWidth - 1) - __builtin_clzll(a);
rep_t result;
// Shift a into the significand field and clear the implicit bit.
const int shift = significandBits - exponent;
result = (rep_t)a << shift ^ implicitBit;
// Insert the exponent
result += (rep_t)(exponent + exponentBias) << significandBits;
return fromRep(result);
}
#endif
| 1,401 | 44 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/adddf3.c | /* clang-format off */
//===-- lib/adddf3.c - Double-precision addition ------------------*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements double-precision soft-float addition with the IEEE-754
// default rounding (to nearest, ties to even).
//
//===----------------------------------------------------------------------===//
STATIC_YOINK("huge_compiler_rt_license");
#define DOUBLE_PRECISION
#include "third_party/compiler_rt/fp_add_impl.inc"
COMPILER_RT_ABI double __adddf3(double a, double b){
return __addXf3__(a, b);
}
#if defined(__ARM_EABI__)
#if defined(COMPILER_RT_ARMHF_TARGET)
AEABI_RTABI double __aeabi_dadd(double a, double b) {
return __adddf3(a, b);
}
#else
AEABI_RTABI double __aeabi_dadd(double a, double b) COMPILER_RT_ALIAS(__adddf3);
#endif
#endif
| 1,045 | 34 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/fixunsdfdi.c | /* clang-format off */
/* ===-- fixunsdfdi.c - Implement __fixunsdfdi -----------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#define DOUBLE_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#ifndef __SOFT_FP__
/* Support for systems that have hardware floating-point; can set the invalid
* flag as a side-effect of computation.
*/
COMPILER_RT_ABI du_int
__fixunsdfdi(double a)
{
if (a <= 0.0) return 0;
su_int high = a / 4294967296.f; /* a / 0x1p32f; */
su_int low = a - (double)high * 4294967296.f; /* high * 0x1p32f; */
return ((du_int)high << 32) | low;
}
#else
/* Support for systems that don't have hardware floating-point; there are no
* flags to set, and we don't want to code-gen to an unknown soft-float
* implementation.
*/
typedef du_int fixuint_t;
#include "third_party/compiler_rt/fp_fixuint_impl.inc"
COMPILER_RT_ABI du_int
__fixunsdfdi(fp_t a) {
return __fixuint(a);
}
#endif
#if defined(__ARM_EABI__)
#if defined(COMPILER_RT_ARMHF_TARGET)
AEABI_RTABI du_int __aeabi_d2ulz(fp_t a) {
return __fixunsdfdi(a);
}
#else
AEABI_RTABI du_int __aeabi_d2ulz(fp_t a) COMPILER_RT_ALIAS(__fixunsdfdi);
#endif
#endif
| 1,472 | 56 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/absvsi2.c | /* clang-format off */
/* ===-- absvsi2.c - Implement __absvsi2 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __absvsi2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
/* Returns: absolute value */
/* Effects: aborts if abs(x) < 0 */
COMPILER_RT_ABI si_int
__absvsi2(si_int a)
{
const int N = (int)(sizeof(si_int) * CHAR_BIT);
if (a == (1 << (N-1)))
compilerrt_abort();
const si_int t = a >> (N - 1);
return (a ^ t) - t;
}
| 902 | 33 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/floatdixf.c | /* clang-format off */
/* ===-- floatdixf.c - Implement __floatdixf -------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __floatdixf for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#if !_ARCH_PPC
#include "third_party/compiler_rt/int_lib.h"
/* Returns: convert a to a long double, rounding toward even. */
/* Assumption: long double is a IEEE 80 bit floating point type padded to 128 bits
* di_int is a 64 bit integral type
*/
/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
* 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
*/
COMPILER_RT_ABI long double
__floatdixf(di_int a)
{
if (a == 0)
return 0.0;
const unsigned N = sizeof(di_int) * CHAR_BIT;
const di_int s = a >> (N-1);
a = (a ^ s) - s;
int clz = __builtin_clzll(a);
int e = (N - 1) - clz ; /* exponent */
long_double_bits fb;
fb.u.high.s.low = ((su_int)s & 0x00008000) | /* sign */
(e + 16383); /* exponent */
fb.u.low.all = a << clz; /* mantissa */
return fb.f;
}
#endif /* !_ARCH_PPC */
| 1,534 | 50 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/fp_fixint_impl.inc | /* clang-format off */
//===-- lib/fixdfsi.c - Double-precision -> integer conversion ----*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements float to integer conversion for the
// compiler-rt library.
//
//===----------------------------------------------------------------------===//
#include "third_party/compiler_rt/fp_lib.inc"
static __inline fixint_t __fixint(fp_t a) {
const fixint_t fixint_max = (fixint_t)((~(fixuint_t)0) / 2);
const fixint_t fixint_min = -fixint_max - 1;
// Break a into sign, exponent, significand
const rep_t aRep = toRep(a);
const rep_t aAbs = aRep & absMask;
const fixint_t sign = aRep & signBit ? -1 : 1;
const int exponent = (aAbs >> significandBits) - exponentBias;
const rep_t significand = (aAbs & significandMask) | implicitBit;
// If exponent is negative, the result is zero.
if (exponent < 0)
return 0;
// If the value is too large for the integer type, saturate.
if ((unsigned)exponent >= sizeof(fixint_t) * CHAR_BIT)
return sign == 1 ? fixint_max : fixint_min;
// If 0 <= exponent < significandBits, right shift to get the result.
// Otherwise, shift left.
if (exponent < significandBits)
return sign * (significand >> (significandBits - exponent));
else
return sign * ((fixint_t)significand << (exponent - significandBits));
}
| 1,634 | 43 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/absvdi2.c | /* clang-format off */
/*===-- absvdi2.c - Implement __absvdi2 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
*===----------------------------------------------------------------------===
*
* This file implements __absvdi2 for the compiler_rt library.
*
*===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
/* Returns: absolute value */
/* Effects: aborts if abs(x) < 0 */
COMPILER_RT_ABI di_int
__absvdi2(di_int a)
{
const int N = (int)(sizeof(di_int) * CHAR_BIT);
if (a == ((di_int)1 << (N-1)))
compilerrt_abort();
const di_int t = a >> (N - 1);
return (a ^ t) - t;
}
| 907 | 33 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/ctzti2.c | /* clang-format off */
/* ===-- ctzti2.c - Implement __ctzti2 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __ctzti2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
#ifdef CRT_HAS_128BIT
/* Returns: the number of trailing 0-bits */
/* Precondition: a != 0 */
COMPILER_RT_ABI si_int
__ctzti2(ti_int a)
{
twords x;
x.all = a;
const di_int f = -(x.s.low == 0);
return __builtin_ctzll((x.s.high & f) | (x.s.low & ~f)) +
((si_int)f & ((si_int)(sizeof(di_int) * CHAR_BIT)));
}
#endif /* CRT_HAS_128BIT */
| 987 | 37 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/fp_add_impl.inc | /* clang-format off */
//===----- lib/fp_add_impl.inc - floaing point addition -----------*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements soft-float addition with the IEEE-754 default rounding
// (to nearest, ties to even).
//
//===----------------------------------------------------------------------===//
#include "libc/literal.h"
#include "third_party/compiler_rt/fp_lib.inc"
static __inline fp_t __addXf3__(fp_t a, fp_t b) {
rep_t aRep = toRep(a);
rep_t bRep = toRep(b);
const rep_t aAbs = aRep & absMask;
const rep_t bAbs = bRep & absMask;
// Detect if a or b is zero, infinity, or NaN.
if (aAbs - REP_C(1) >= infRep - REP_C(1) ||
bAbs - REP_C(1) >= infRep - REP_C(1)) {
// NaN + anything = qNaN
if (aAbs > infRep) return fromRep(toRep(a) | quietBit);
// anything + NaN = qNaN
if (bAbs > infRep) return fromRep(toRep(b) | quietBit);
if (aAbs == infRep) {
// +/-infinity + -/+infinity = qNaN
if ((toRep(a) ^ toRep(b)) == signBit) return fromRep(qnanRep);
// +/-infinity + anything remaining = +/- infinity
else return a;
}
// anything remaining + +/-infinity = +/-infinity
if (bAbs == infRep) return b;
// zero + anything = anything
if (!aAbs) {
// but we need to get the sign right for zero + zero
if (!bAbs) return fromRep(toRep(a) & toRep(b));
else return b;
}
// anything + zero = anything
if (!bAbs) return a;
}
// Swap a and b if necessary so that a has the larger absolute value.
if (bAbs > aAbs) {
const rep_t temp = aRep;
aRep = bRep;
bRep = temp;
}
// Extract the exponent and significand from the (possibly swapped) a and b.
int aExponent = aRep >> significandBits & maxExponent;
int bExponent = bRep >> significandBits & maxExponent;
rep_t aSignificand = aRep & significandMask;
rep_t bSignificand = bRep & significandMask;
// Normalize any denormals, and adjust the exponent accordingly.
if (aExponent == 0) aExponent = normalize(&aSignificand);
if (bExponent == 0) bExponent = normalize(&bSignificand);
// The sign of the result is the sign of the larger operand, a. If they
// have opposite signs, we are performing a subtraction; otherwise addition.
const rep_t resultSign = aRep & signBit;
const bool subtraction = (aRep ^ bRep) & signBit;
// Shift the significands to give us round, guard and sticky, and or in the
// implicit significand bit. (If we fell through from the denormal path it
// was already set by normalize( ), but setting it twice won't hurt
// anything.)
aSignificand = (aSignificand | implicitBit) << 3;
bSignificand = (bSignificand | implicitBit) << 3;
// Shift the significand of b by the difference in exponents, with a sticky
// bottom bit to get rounding correct.
const unsigned int align = aExponent - bExponent;
if (align) {
if (align < typeWidth) {
const bool sticky = bSignificand << (typeWidth - align);
bSignificand = bSignificand >> align | sticky;
} else {
bSignificand = 1; // sticky; b is known to be non-zero.
}
}
if (subtraction) {
aSignificand -= bSignificand;
// If a == -b, return +zero.
if (aSignificand == 0) return fromRep(0);
// If partial cancellation occured, we need to left-shift the result
// and adjust the exponent:
if (aSignificand < implicitBit << 3) {
const int shift = rep_clz(aSignificand) - rep_clz(implicitBit << 3);
aSignificand <<= shift;
aExponent -= shift;
}
}
else /* addition */ {
aSignificand += bSignificand;
// If the addition carried up, we need to right-shift the result and
// adjust the exponent:
if (aSignificand & implicitBit << 4) {
const bool sticky = aSignificand & 1;
aSignificand = aSignificand >> 1 | sticky;
aExponent += 1;
}
}
// If we have overflowed the type, return +/- infinity:
if (aExponent >= maxExponent) return fromRep(infRep | resultSign);
if (aExponent <= 0) {
// Result is denormal before rounding; the exponent is zero and we
// need to shift the significand.
const int shift = 1 - aExponent;
const bool sticky = aSignificand << (typeWidth - shift);
aSignificand = aSignificand >> shift | sticky;
aExponent = 0;
}
// Low three bits are round, guard, and sticky.
const int roundGuardSticky = aSignificand & 0x7;
// Shift the significand into place, and mask off the implicit bit.
rep_t result = aSignificand >> 3 & significandMask;
// Insert the exponent and sign.
result |= (rep_t)aExponent << significandBits;
result |= resultSign;
// Final rounding. The result may overflow to infinity, but that is the
// correct result in that case.
if (roundGuardSticky > 0x4) result++;
if (roundGuardSticky == 0x4) result += result & 1;
return fromRep(result);
}
| 5,467 | 147 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/floattixf.c | /* clang-format off */
/* ===-- floattixf.c - Implement __floattixf -------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __floattixf for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
#ifdef CRT_HAS_128BIT
/* Returns: convert a to a long double, rounding toward even. */
/* Assumption: long double is a IEEE 80 bit floating point type padded to 128 bits
* ti_int is a 128 bit integral type
*/
/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
* 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
*/
COMPILER_RT_ABI long double
__floattixf(ti_int a)
{
if (a == 0)
return 0.0;
const unsigned N = sizeof(ti_int) * CHAR_BIT;
const ti_int s = a >> (N-1);
a = (a ^ s) - s;
int sd = N - __clzti2(a); /* number of significant digits */
int e = sd - 1; /* exponent */
if (sd > LDBL_MANT_DIG)
{
/* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
* finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
* 12345678901234567890123456
* 1 = msb 1 bit
* P = bit LDBL_MANT_DIG-1 bits to the right of 1
* Q = bit LDBL_MANT_DIG bits to the right of 1
* R = "or" of all bits to the right of Q
*/
switch (sd)
{
case LDBL_MANT_DIG + 1:
a <<= 1;
break;
case LDBL_MANT_DIG + 2:
break;
default:
a = ((tu_int)a >> (sd - (LDBL_MANT_DIG+2))) |
((a & ((tu_int)(-1) >> ((N + LDBL_MANT_DIG+2) - sd))) != 0);
};
/* finish: */
a |= (a & 4) != 0; /* Or P into R */
++a; /* round - this step may add a significant bit */
a >>= 2; /* dump Q and R */
/* a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits */
if (a & ((tu_int)1 << LDBL_MANT_DIG))
{
a >>= 1;
++e;
}
/* a is now rounded to LDBL_MANT_DIG bits */
}
else
{
a <<= (LDBL_MANT_DIG - sd);
/* a is now rounded to LDBL_MANT_DIG bits */
}
long_double_bits fb;
fb.u.high.s.low = ((su_int)s & 0x8000) | /* sign */
(e + 16383); /* exponent */
fb.u.low.all = (du_int)a; /* mantissa */
return fb.f;
}
#endif /* CRT_HAS_128BIT */
| 2,913 | 88 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/divsf3.c | /* clang-format off */
//===-- lib/divsf3.c - Single-precision division ------------------*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements single-precision soft-float division
// with the IEEE-754 default rounding (to nearest, ties to even).
//
// For simplicity, this implementation currently flushes denormals to zero.
// It should be a fairly straightforward exercise to implement gradual
// underflow with correct rounding.
//
//===----------------------------------------------------------------------===//
STATIC_YOINK("huge_compiler_rt_license");
#define SINGLE_PRECISION
#include "libc/literal.h"
#include "third_party/compiler_rt/fp_lib.inc"
COMPILER_RT_ABI fp_t
__divsf3(fp_t a, fp_t b) {
const unsigned int aExponent = toRep(a) >> significandBits & maxExponent;
const unsigned int bExponent = toRep(b) >> significandBits & maxExponent;
const rep_t quotientSign = (toRep(a) ^ toRep(b)) & signBit;
rep_t aSignificand = toRep(a) & significandMask;
rep_t bSignificand = toRep(b) & significandMask;
int scale = 0;
// Detect if a or b is zero, denormal, infinity, or NaN.
if (aExponent-1U >= maxExponent-1U || bExponent-1U >= maxExponent-1U) {
const rep_t aAbs = toRep(a) & absMask;
const rep_t bAbs = toRep(b) & absMask;
// NaN / anything = qNaN
if (aAbs > infRep) return fromRep(toRep(a) | quietBit);
// anything / NaN = qNaN
if (bAbs > infRep) return fromRep(toRep(b) | quietBit);
if (aAbs == infRep) {
// infinity / infinity = NaN
if (bAbs == infRep) return fromRep(qnanRep);
// infinity / anything else = +/- infinity
else return fromRep(aAbs | quotientSign);
}
// anything else / infinity = +/- 0
if (bAbs == infRep) return fromRep(quotientSign);
if (!aAbs) {
// zero / zero = NaN
if (!bAbs) return fromRep(qnanRep);
// zero / anything else = +/- zero
else return fromRep(quotientSign);
}
// anything else / zero = +/- infinity
if (!bAbs) return fromRep(infRep | quotientSign);
// one or both of a or b is denormal, the other (if applicable) is a
// normal number. Renormalize one or both of a and b, and set scale to
// include the necessary exponent adjustment.
if (aAbs < implicitBit) scale += normalize(&aSignificand);
if (bAbs < implicitBit) scale -= normalize(&bSignificand);
}
// Or in the implicit significand bit. (If we fell through from the
// denormal path it was already set by normalize( ), but setting it twice
// won't hurt anything.)
aSignificand |= implicitBit;
bSignificand |= implicitBit;
int quotientExponent = aExponent - bExponent + scale;
// Align the significand of b as a Q31 fixed-point number in the range
// [1, 2.0) and get a Q32 approximate reciprocal using a small minimax
// polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
// is accurate to about 3.5 binary digits.
uint32_t q31b = bSignificand << 8;
uint32_t reciprocal = UINT32_C(0x7504f333) - q31b;
// Now refine the reciprocal estimate using a Newton-Raphson iteration:
//
// x1 = x0 * (2 - x0 * b)
//
// This doubles the number of correct binary digits in the approximation
// with each iteration, so after three iterations, we have about 28 binary
// digits of accuracy.
uint32_t correction;
correction = -((uint64_t)reciprocal * q31b >> 32);
reciprocal = (uint64_t)reciprocal * correction >> 31;
correction = -((uint64_t)reciprocal * q31b >> 32);
reciprocal = (uint64_t)reciprocal * correction >> 31;
correction = -((uint64_t)reciprocal * q31b >> 32);
reciprocal = (uint64_t)reciprocal * correction >> 31;
// Exhaustive testing shows that the error in reciprocal after three steps
// is in the interval [-0x1.f58108p-31, 0x1.d0e48cp-29], in line with our
// expectations. We bump the reciprocal by a tiny value to force the error
// to be strictly positive (in the range [0x1.4fdfp-37,0x1.287246p-29], to
// be specific). This also causes 1/1 to give a sensible approximation
// instead of zero (due to overflow).
reciprocal -= 2;
// The numerical reciprocal is accurate to within 2^-28, lies in the
// interval [0x1.000000eep-1, 0x1.fffffffcp-1], and is strictly smaller
// than the true reciprocal of b. Multiplying a by this reciprocal thus
// gives a numerical q = a/b in Q24 with the following properties:
//
// 1. q < a/b
// 2. q is in the interval [0x1.000000eep-1, 0x1.fffffffcp0)
// 3. the error in q is at most 2^-24 + 2^-27 -- the 2^24 term comes
// from the fact that we truncate the product, and the 2^27 term
// is the error in the reciprocal of b scaled by the maximum
// possible value of a. As a consequence of this error bound,
// either q or nextafter(q) is the correctly rounded
rep_t quotient = (uint64_t)reciprocal*(aSignificand << 1) >> 32;
// Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).
// In either case, we are going to compute a residual of the form
//
// r = a - q*b
//
// We know from the construction of q that r satisfies:
//
// 0 <= r < ulp(q)*b
//
// if r is greater than 1/2 ulp(q)*b, then q rounds up. Otherwise, we
// already have the correct result. The exact halfway case cannot occur.
// We also take this time to right shift quotient if it falls in the [1,2)
// range and adjust the exponent accordingly.
rep_t residual;
if (quotient < (implicitBit << 1)) {
residual = (aSignificand << 24) - quotient * bSignificand;
quotientExponent--;
} else {
quotient >>= 1;
residual = (aSignificand << 23) - quotient * bSignificand;
}
const int writtenExponent = quotientExponent + exponentBias;
if (writtenExponent >= maxExponent) {
// If we have overflowed the exponent, return infinity.
return fromRep(infRep | quotientSign);
}
else if (writtenExponent < 1) {
// Flush denormals to zero. In the future, it would be nice to add
// code to round them correctly.
return fromRep(quotientSign);
}
else {
const bool round = (residual << 1) > bSignificand;
// Clear the implicit bit
rep_t absResult = quotient & significandMask;
// Insert the exponent
absResult |= (rep_t)writtenExponent << significandBits;
// Round
absResult += round;
// Insert the sign and return
return fromRep(absResult | quotientSign);
}
}
#if defined(__ARM_EABI__)
#if defined(COMPILER_RT_ARMHF_TARGET)
AEABI_RTABI fp_t __aeabi_fdiv(fp_t a, fp_t b) {
return __divsf3(a, b);
}
#else
AEABI_RTABI fp_t __aeabi_fdiv(fp_t a, fp_t b) COMPILER_RT_ALIAS(__divsf3);
#endif
#endif
| 7,365 | 182 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/extendsftf2.c | /* clang-format off */
//===-- lib/extendsftf2.c - single -> quad conversion -------------*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
STATIC_YOINK("huge_compiler_rt_license");
#define QUAD_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
#define SRC_SINGLE
#define DST_QUAD
#include "third_party/compiler_rt/fp_extend_impl.inc"
COMPILER_RT_ABI long double __extendsftf2(float a) {
return __extendXfYf2__(a);
}
#endif
| 737 | 27 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/udivdi3.c | /* clang-format off */
/* ===-- udivdi3.c - Implement __udivdi3 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __udivdi3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
/* Returns: a / b */
COMPILER_RT_ABI du_int
__udivdi3(du_int a, du_int b)
{
return __udivmoddi4(a, b, 0);
}
| 732 | 27 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/floatdisf.c | /* clang-format off */
/*===-- floatdisf.c - Implement __floatdisf -------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
*===----------------------------------------------------------------------===
*
* This file implements __floatdisf for the compiler_rt library.
*
*===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
/* Returns: convert a to a float, rounding toward even.*/
/* Assumption: float is a IEEE 32 bit floating point type
* di_int is a 64 bit integral type
*/
/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
#include "third_party/compiler_rt/int_lib.h"
COMPILER_RT_ABI float
__floatdisf(di_int a)
{
if (a == 0)
return 0.0F;
const unsigned N = sizeof(di_int) * CHAR_BIT;
const di_int s = a >> (N-1);
a = (a ^ s) - s;
int sd = N - __builtin_clzll(a); /* number of significant digits */
int e = sd - 1; /* exponent */
if (sd > FLT_MANT_DIG)
{
/* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
* finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
* 12345678901234567890123456
* 1 = msb 1 bit
* P = bit FLT_MANT_DIG-1 bits to the right of 1
* Q = bit FLT_MANT_DIG bits to the right of 1
* R = "or" of all bits to the right of Q
*/
switch (sd)
{
case FLT_MANT_DIG + 1:
a <<= 1;
break;
case FLT_MANT_DIG + 2:
break;
default:
a = ((du_int)a >> (sd - (FLT_MANT_DIG+2))) |
((a & ((du_int)(-1) >> ((N + FLT_MANT_DIG+2) - sd))) != 0);
};
/* finish: */
a |= (a & 4) != 0; /* Or P into R */
++a; /* round - this step may add a significant bit */
a >>= 2; /* dump Q and R */
/* a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits */
if (a & ((du_int)1 << FLT_MANT_DIG))
{
a >>= 1;
++e;
}
/* a is now rounded to FLT_MANT_DIG bits */
}
else
{
a <<= (FLT_MANT_DIG - sd);
/* a is now rounded to FLT_MANT_DIG bits */
}
float_bits fb;
fb.u = ((su_int)s & 0x80000000) | /* sign */
((e + 127) << 23) | /* exponent */
((su_int)a & 0x007FFFFF); /* mantissa */
return fb.f;
}
#if defined(__ARM_EABI__)
#if defined(COMPILER_RT_ARMHF_TARGET)
AEABI_RTABI float __aeabi_l2f(di_int a) {
return __floatdisf(a);
}
#else
AEABI_RTABI float __aeabi_l2f(di_int a) COMPILER_RT_ALIAS(__floatdisf);
#endif
#endif
| 2,886 | 92 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/fp_extend_impl.inc | /* clang-format off */
//=-lib/fp_extend_impl.inc - low precision -> high precision conversion -*-- -//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements a fairly generic conversion from a narrower to a wider
// IEEE-754 floating-point type. The constants and types defined following the
// includes below parameterize the conversion.
//
// It does not support types that don't use the usual IEEE-754 interchange
// formats; specifically, some work would be needed to adapt it to
// (for example) the Intel 80-bit format or PowerPC double-double format.
//
// Note please, however, that this implementation is only intended to support
// *widening* operations; if you need to convert to a *narrower* floating-point
// type (e.g. double -> float), then this routine will not do what you want it
// to.
//
// It also requires that integer types at least as large as both formats
// are available on the target platform; this may pose a problem when trying
// to add support for quad on some 32-bit systems, for example. You also may
// run into trouble finding an appropriate CLZ function for wide source types;
// you will likely need to roll your own on some platforms.
//
// Finally, the following assumptions are made:
//
// 1. floating-point types and integer types have the same endianness on the
// target platform
//
// 2. quiet NaNs, if supported, are indicated by the leading bit of the
// significand field being set
//
//===----------------------------------------------------------------------===//
#include "libc/literal.h"
#include "third_party/compiler_rt/fp_extend_common.inc"
static __inline dst_t __extendXfYf2__(src_t a) {
// Various constants whose values follow from the type parameters.
// Any reasonable optimizer will fold and propagate all of these.
const int srcBits = sizeof(src_t)*CHAR_BIT;
const int srcExpBits = srcBits - srcSigBits - 1;
const int srcInfExp = (1u << srcExpBits) - 1;
const int srcExpBias = srcInfExp >> 1;
const src_rep_t srcMinNormal = SRC_REP_C(1) << srcSigBits;
const src_rep_t srcInfinity = (src_rep_t)srcInfExp << srcSigBits;
const src_rep_t srcSignMask = SRC_REP_C(1) << (srcSigBits + srcExpBits);
const src_rep_t srcAbsMask = srcSignMask - 1;
const src_rep_t srcQNaN = SRC_REP_C(1) << (srcSigBits - 1);
const src_rep_t srcNaNCode = srcQNaN - 1;
const int dstBits = sizeof(dst_t)*CHAR_BIT;
const int dstExpBits = dstBits - dstSigBits - 1;
const int dstInfExp = (1u << dstExpBits) - 1;
const int dstExpBias = dstInfExp >> 1;
const dst_rep_t dstMinNormal = DST_REP_C(1) << dstSigBits;
// Break a into a sign and representation of the absolute value
const src_rep_t aRep = srcToRep(a);
const src_rep_t aAbs = aRep & srcAbsMask;
const src_rep_t sign = aRep & srcSignMask;
dst_rep_t absResult;
// If sizeof(src_rep_t) < sizeof(int), the subtraction result is promoted
// to (signed) int. To avoid that, explicitly cast to src_rep_t.
if ((src_rep_t)(aAbs - srcMinNormal) < srcInfinity - srcMinNormal) {
// a is a normal number.
// Extend to the destination type by shifting the significand and
// exponent into the proper position and rebiasing the exponent.
absResult = (dst_rep_t)aAbs << (dstSigBits - srcSigBits);
absResult += (dst_rep_t)(dstExpBias - srcExpBias) << dstSigBits;
}
else if (aAbs >= srcInfinity) {
// a is NaN or infinity.
// Conjure the result by beginning with infinity, then setting the qNaN
// bit (if needed) and right-aligning the rest of the trailing NaN
// payload field.
absResult = (dst_rep_t)dstInfExp << dstSigBits;
absResult |= (dst_rep_t)(aAbs & srcQNaN) << (dstSigBits - srcSigBits);
absResult |= (dst_rep_t)(aAbs & srcNaNCode) << (dstSigBits - srcSigBits);
}
else if (aAbs) {
// a is denormal.
// renormalize the significand and clear the leading bit, then insert
// the correct adjusted exponent in the destination type.
const int scale = src_rep_t_clz(aAbs) - src_rep_t_clz(srcMinNormal);
absResult = (dst_rep_t)aAbs << (dstSigBits - srcSigBits + scale);
absResult ^= dstMinNormal;
const int resultExponent = dstExpBias - srcExpBias - scale + 1;
absResult |= (dst_rep_t)resultExponent << dstSigBits;
}
else {
// a is zero.
absResult = 0;
}
// Apply the signbit to (dst_t)abs(a).
const dst_rep_t result = absResult | (dst_rep_t)sign << (dstBits - srcBits);
return dstFromRep(result);
}
| 4,855 | 111 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/divtf3.c | /* clang-format off */
//===-- lib/divtf3.c - Quad-precision division --------------------*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements quad-precision soft-float division
// with the IEEE-754 default rounding (to nearest, ties to even).
//
// For simplicity, this implementation currently flushes denormals to zero.
// It should be a fairly straightforward exercise to implement gradual
// underflow with correct rounding.
//
//===----------------------------------------------------------------------===//
STATIC_YOINK("huge_compiler_rt_license");
#define QUAD_PRECISION
#include "libc/literal.h"
#include "third_party/compiler_rt/fp_lib.inc"
#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
COMPILER_RT_ABI fp_t __divtf3(fp_t a, fp_t b) {
const unsigned int aExponent = toRep(a) >> significandBits & maxExponent;
const unsigned int bExponent = toRep(b) >> significandBits & maxExponent;
const rep_t quotientSign = (toRep(a) ^ toRep(b)) & signBit;
rep_t aSignificand = toRep(a) & significandMask;
rep_t bSignificand = toRep(b) & significandMask;
int scale = 0;
// Detect if a or b is zero, denormal, infinity, or NaN.
if (aExponent-1U >= maxExponent-1U || bExponent-1U >= maxExponent-1U) {
const rep_t aAbs = toRep(a) & absMask;
const rep_t bAbs = toRep(b) & absMask;
// NaN / anything = qNaN
if (aAbs > infRep) return fromRep(toRep(a) | quietBit);
// anything / NaN = qNaN
if (bAbs > infRep) return fromRep(toRep(b) | quietBit);
if (aAbs == infRep) {
// infinity / infinity = NaN
if (bAbs == infRep) return fromRep(qnanRep);
// infinity / anything else = +/- infinity
else return fromRep(aAbs | quotientSign);
}
// anything else / infinity = +/- 0
if (bAbs == infRep) return fromRep(quotientSign);
if (!aAbs) {
// zero / zero = NaN
if (!bAbs) return fromRep(qnanRep);
// zero / anything else = +/- zero
else return fromRep(quotientSign);
}
// anything else / zero = +/- infinity
if (!bAbs) return fromRep(infRep | quotientSign);
// one or both of a or b is denormal, the other (if applicable) is a
// normal number. Renormalize one or both of a and b, and set scale to
// include the necessary exponent adjustment.
if (aAbs < implicitBit) scale += normalize(&aSignificand);
if (bAbs < implicitBit) scale -= normalize(&bSignificand);
}
// Or in the implicit significand bit. (If we fell through from the
// denormal path it was already set by normalize( ), but setting it twice
// won't hurt anything.)
aSignificand |= implicitBit;
bSignificand |= implicitBit;
int quotientExponent = aExponent - bExponent + scale;
// Align the significand of b as a Q63 fixed-point number in the range
// [1, 2.0) and get a Q64 approximate reciprocal using a small minimax
// polynomial approximation: reciprocal = 3/4 + 1/sqrt(2) - b/2. This
// is accurate to about 3.5 binary digits.
const uint64_t q63b = bSignificand >> 49;
uint64_t recip64 = UINT64_C(0x7504f333F9DE6484) - q63b;
// 0x7504f333F9DE6484 / 2^64 + 1 = 3/4 + 1/sqrt(2)
// Now refine the reciprocal estimate using a Newton-Raphson iteration:
//
// x1 = x0 * (2 - x0 * b)
//
// This doubles the number of correct binary digits in the approximation
// with each iteration.
uint64_t correction64;
correction64 = -((rep_t)recip64 * q63b >> 64);
recip64 = (rep_t)recip64 * correction64 >> 63;
correction64 = -((rep_t)recip64 * q63b >> 64);
recip64 = (rep_t)recip64 * correction64 >> 63;
correction64 = -((rep_t)recip64 * q63b >> 64);
recip64 = (rep_t)recip64 * correction64 >> 63;
correction64 = -((rep_t)recip64 * q63b >> 64);
recip64 = (rep_t)recip64 * correction64 >> 63;
correction64 = -((rep_t)recip64 * q63b >> 64);
recip64 = (rep_t)recip64 * correction64 >> 63;
// recip64 might have overflowed to exactly zero in the preceeding
// computation if the high word of b is exactly 1.0. This would sabotage
// the full-width final stage of the computation that follows, so we adjust
// recip64 downward by one bit.
recip64--;
// We need to perform one more iteration to get us to 112 binary digits;
// The last iteration needs to happen with extra precision.
const uint64_t q127blo = bSignificand << 15;
rep_t correction, reciprocal;
// NOTE: This operation is equivalent to __multi3, which is not implemented
// in some architechure
rep_t r64q63, r64q127, r64cH, r64cL, dummy;
wideMultiply((rep_t)recip64, (rep_t)q63b, &dummy, &r64q63);
wideMultiply((rep_t)recip64, (rep_t)q127blo, &dummy, &r64q127);
correction = -(r64q63 + (r64q127 >> 64));
uint64_t cHi = correction >> 64;
uint64_t cLo = correction;
wideMultiply((rep_t)recip64, (rep_t)cHi, &dummy, &r64cH);
wideMultiply((rep_t)recip64, (rep_t)cLo, &dummy, &r64cL);
reciprocal = r64cH + (r64cL >> 64);
// We already adjusted the 64-bit estimate, now we need to adjust the final
// 128-bit reciprocal estimate downward to ensure that it is strictly smaller
// than the infinitely precise exact reciprocal. Because the computation
// of the Newton-Raphson step is truncating at every step, this adjustment
// is small; most of the work is already done.
reciprocal -= 2;
// The numerical reciprocal is accurate to within 2^-112, lies in the
// interval [0.5, 1.0), and is strictly smaller than the true reciprocal
// of b. Multiplying a by this reciprocal thus gives a numerical q = a/b
// in Q127 with the following properties:
//
// 1. q < a/b
// 2. q is in the interval [0.5, 2.0)
// 3. the error in q is bounded away from 2^-113 (actually, we have a
// couple of bits to spare, but this is all we need).
// We need a 128 x 128 multiply high to compute q, which isn't a basic
// operation in C, so we need to be a little bit fussy.
rep_t quotient, quotientLo;
wideMultiply(aSignificand << 2, reciprocal, "ient, "ientLo);
// Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).
// In either case, we are going to compute a residual of the form
//
// r = a - q*b
//
// We know from the construction of q that r satisfies:
//
// 0 <= r < ulp(q)*b
//
// if r is greater than 1/2 ulp(q)*b, then q rounds up. Otherwise, we
// already have the correct result. The exact halfway case cannot occur.
// We also take this time to right shift quotient if it falls in the [1,2)
// range and adjust the exponent accordingly.
rep_t residual;
rep_t qb;
if (quotient < (implicitBit << 1)) {
wideMultiply(quotient, bSignificand, &dummy, &qb);
residual = (aSignificand << 113) - qb;
quotientExponent--;
} else {
quotient >>= 1;
wideMultiply(quotient, bSignificand, &dummy, &qb);
residual = (aSignificand << 112) - qb;
}
const int writtenExponent = quotientExponent + exponentBias;
if (writtenExponent >= maxExponent) {
// If we have overflowed the exponent, return infinity.
return fromRep(infRep | quotientSign);
}
else if (writtenExponent < 1) {
// Flush denormals to zero. In the future, it would be nice to add
// code to round them correctly.
return fromRep(quotientSign);
}
else {
const bool round = (residual << 1) >= bSignificand;
// Clear the implicit bit
rep_t absResult = quotient & significandMask;
// Insert the exponent
absResult |= (rep_t)writtenExponent << significandBits;
// Round
absResult += round;
// Insert the sign and return
const long double result = fromRep(absResult | quotientSign);
return result;
}
}
#endif
| 8,318 | 208 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/floatuntidf.c | /* clang-format off */
/* ===-- floatuntidf.c - Implement __floatuntidf ---------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __floatuntidf for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
#ifdef CRT_HAS_128BIT
/* Returns: convert a to a double, rounding toward even. */
/* Assumption: double is a IEEE 64 bit floating point type
* tu_int is a 128 bit integral type
*/
/* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */
COMPILER_RT_ABI double
__floatuntidf(tu_int a)
{
if (a == 0)
return 0.0;
const unsigned N = sizeof(tu_int) * CHAR_BIT;
int sd = N - __clzti2(a); /* number of significant digits */
int e = sd - 1; /* exponent */
if (sd > DBL_MANT_DIG)
{
/* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
* finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
* 12345678901234567890123456
* 1 = msb 1 bit
* P = bit DBL_MANT_DIG-1 bits to the right of 1
* Q = bit DBL_MANT_DIG bits to the right of 1
* R = "or" of all bits to the right of Q
*/
switch (sd)
{
case DBL_MANT_DIG + 1:
a <<= 1;
break;
case DBL_MANT_DIG + 2:
break;
default:
a = (a >> (sd - (DBL_MANT_DIG+2))) |
((a & ((tu_int)(-1) >> ((N + DBL_MANT_DIG+2) - sd))) != 0);
};
/* finish: */
a |= (a & 4) != 0; /* Or P into R */
++a; /* round - this step may add a significant bit */
a >>= 2; /* dump Q and R */
/* a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits */
if (a & ((tu_int)1 << DBL_MANT_DIG))
{
a >>= 1;
++e;
}
/* a is now rounded to DBL_MANT_DIG bits */
}
else
{
a <<= (DBL_MANT_DIG - sd);
/* a is now rounded to DBL_MANT_DIG bits */
}
double_bits fb;
fb.u.s.high = ((e + 1023) << 20) | /* exponent */
((su_int)(a >> 32) & 0x000FFFFF); /* mantissa-high */
fb.u.s.low = (su_int)a; /* mantissa-low */
return fb.f;
}
#endif /* CRT_HAS_128BIT */
| 2,736 | 84 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/floatsisf.c | /* clang-format off */
//===-- lib/floatsisf.c - integer -> single-precision conversion --*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements integer to single-precision conversion for the
// compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even
// mode.
//
//===----------------------------------------------------------------------===//
STATIC_YOINK("huge_compiler_rt_license");
#define SINGLE_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#include "third_party/compiler_rt/int_lib.h"
COMPILER_RT_ABI fp_t
__floatsisf(int a) {
const int aWidth = sizeof a * CHAR_BIT;
// Handle zero as a special case to protect clz
if (a == 0)
return fromRep(0);
// All other cases begin by extracting the sign and absolute value of a
rep_t sign = 0;
if (a < 0) {
sign = signBit;
a = -a;
}
// Exponent of (fp_t)a is the width of abs(a).
const int exponent = (aWidth - 1) - __builtin_clz(a);
rep_t result;
// Shift a into the significand field, rounding if it is a right-shift
if (exponent <= significandBits) {
const int shift = significandBits - exponent;
result = (rep_t)a << shift ^ implicitBit;
} else {
const int shift = exponent - significandBits;
result = (rep_t)a >> shift ^ implicitBit;
rep_t round = (rep_t)a << (typeWidth - shift);
if (round > signBit) result++;
if (round == signBit) result += result & 1;
}
// Insert the exponent
result += (rep_t)(exponent + exponentBias) << significandBits;
// Insert the sign bit and return
return fromRep(result | sign);
}
#if defined(__ARM_EABI__)
#if defined(COMPILER_RT_ARMHF_TARGET)
AEABI_RTABI fp_t __aeabi_i2f(int a) {
return __floatsisf(a);
}
#else
AEABI_RTABI fp_t __aeabi_i2f(int a) COMPILER_RT_ALIAS(__floatsisf);
#endif
#endif
| 2,157 | 71 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/mulodi4.c | /* clang-format off */
/*===-- mulodi4.c - Implement __mulodi4 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __mulodi4 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
/* Returns: a * b */
/* Effects: sets *overflow to 1 if a * b overflows */
COMPILER_RT_ABI di_int
__mulodi4(di_int a, di_int b, int* overflow)
{
const int N = (int)(sizeof(di_int) * CHAR_BIT);
const di_int MIN = (di_int)1 << (N-1);
const di_int MAX = ~MIN;
*overflow = 0;
di_int result = a * b;
if (a == MIN)
{
if (b != 0 && b != 1)
*overflow = 1;
return result;
}
if (b == MIN)
{
if (a != 0 && a != 1)
*overflow = 1;
return result;
}
di_int sa = a >> (N - 1);
di_int abs_a = (a ^ sa) - sa;
di_int sb = b >> (N - 1);
di_int abs_b = (b ^ sb) - sb;
if (abs_a < 2 || abs_b < 2)
return result;
if (sa == sb)
{
if (abs_a > MAX / abs_b)
*overflow = 1;
}
else
{
if (abs_a > MIN / -abs_b)
*overflow = 1;
}
return result;
}
| 1,513 | 62 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/truncdfsf2.c | /* clang-format off */
//===-- lib/truncdfsf2.c - double -> single conversion ------------*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
STATIC_YOINK("huge_compiler_rt_license");
#define SRC_DOUBLE
#define DST_SINGLE
#include "third_party/compiler_rt/fp_trunc_impl.inc"
COMPILER_RT_ABI float __truncdfsf2(double a) {
return __truncXfYf2__(a);
}
#if defined(__ARM_EABI__)
#if defined(COMPILER_RT_ARMHF_TARGET)
AEABI_RTABI float __aeabi_d2f(double a) {
return __truncdfsf2(a);
}
#else
AEABI_RTABI float __aeabi_d2f(double a) COMPILER_RT_ALIAS(__truncdfsf2);
#endif
#endif
| 822 | 30 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/parityti2.c | /* clang-format off */
/* ===-- parityti2.c - Implement __parityti2 -------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __parityti2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
#ifdef CRT_HAS_128BIT
/* Returns: 1 if number of bits is odd else returns 0 */
COMPILER_RT_ABI si_int
__parityti2(ti_int a)
{
twords x;
x.all = a;
return __paritydi2(x.s.high ^ x.s.low);
}
#endif /* CRT_HAS_128BIT */
| 855 | 33 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/mingw_fixfloat.c | /* clang-format off */
/* ===-- mingw_fixfloat.c - Wrap int/float conversions for arm/windows -----===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
COMPILER_RT_ABI di_int __fixdfdi(double a);
COMPILER_RT_ABI di_int __fixsfdi(float a);
COMPILER_RT_ABI du_int __fixunsdfdi(double a);
COMPILER_RT_ABI du_int __fixunssfdi(float a);
COMPILER_RT_ABI double __floatdidf(di_int a);
COMPILER_RT_ABI float __floatdisf(di_int a);
COMPILER_RT_ABI double __floatundidf(du_int a);
COMPILER_RT_ABI float __floatundisf(du_int a);
COMPILER_RT_ABI di_int __dtoi64(double a) { return __fixdfdi(a); }
COMPILER_RT_ABI di_int __stoi64(float a) { return __fixsfdi(a); }
COMPILER_RT_ABI du_int __dtou64(double a) { return __fixunsdfdi(a); }
COMPILER_RT_ABI du_int __stou64(float a) { return __fixunssfdi(a); }
COMPILER_RT_ABI double __i64tod(di_int a) { return __floatdidf(a); }
COMPILER_RT_ABI float __i64tos(di_int a) { return __floatdisf(a); }
COMPILER_RT_ABI double __u64tod(du_int a) { return __floatundidf(a); }
COMPILER_RT_ABI float __u64tos(du_int a) { return __floatundisf(a); }
| 1,395 | 40 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/floatuntisf.c | /* clang-format off */
/* ===-- floatuntisf.c - Implement __floatuntisf ---------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __floatuntisf for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
#ifdef CRT_HAS_128BIT
/* Returns: convert a to a float, rounding toward even. */
/* Assumption: float is a IEEE 32 bit floating point type
* tu_int is a 128 bit integral type
*/
/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
COMPILER_RT_ABI float
__floatuntisf(tu_int a)
{
if (a == 0)
return 0.0F;
const unsigned N = sizeof(tu_int) * CHAR_BIT;
int sd = N - __clzti2(a); /* number of significant digits */
int e = sd - 1; /* exponent */
if (sd > FLT_MANT_DIG)
{
/* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
* finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
* 12345678901234567890123456
* 1 = msb 1 bit
* P = bit FLT_MANT_DIG-1 bits to the right of 1
* Q = bit FLT_MANT_DIG bits to the right of 1
* R = "or" of all bits to the right of Q
*/
switch (sd)
{
case FLT_MANT_DIG + 1:
a <<= 1;
break;
case FLT_MANT_DIG + 2:
break;
default:
a = (a >> (sd - (FLT_MANT_DIG+2))) |
((a & ((tu_int)(-1) >> ((N + FLT_MANT_DIG+2) - sd))) != 0);
};
/* finish: */
a |= (a & 4) != 0; /* Or P into R */
++a; /* round - this step may add a significant bit */
a >>= 2; /* dump Q and R */
/* a is now rounded to FLT_MANT_DIG or FLT_MANT_DIG+1 bits */
if (a & ((tu_int)1 << FLT_MANT_DIG))
{
a >>= 1;
++e;
}
/* a is now rounded to FLT_MANT_DIG bits */
}
else
{
a <<= (FLT_MANT_DIG - sd);
/* a is now rounded to FLT_MANT_DIG bits */
}
float_bits fb;
fb.u = ((e + 127) << 23) | /* exponent */
((su_int)a & 0x007FFFFF); /* mantissa */
return fb.f;
}
#endif /* CRT_HAS_128BIT */
| 2,584 | 83 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/umodti3.c | /* clang-format off */
/* ===-- umodti3.c - Implement __umodti3 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __umodti3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
#ifdef CRT_HAS_128BIT
/* Returns: a % b */
COMPILER_RT_ABI tu_int
__umodti3(tu_int a, tu_int b)
{
tu_int r;
__udivmodti4(a, b, &r);
return r;
}
#endif /* CRT_HAS_128BIT */
| 807 | 33 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/fixtfti.c | /* clang-format off */
/* ===-- fixtfti.c - Implement __fixtfti -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#define QUAD_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
typedef ti_int fixint_t;
typedef tu_int fixuint_t;
#include "third_party/compiler_rt/fp_fixint_impl.inc"
COMPILER_RT_ABI ti_int
__fixtfti(fp_t a) {
return __fixint(a);
}
#endif
| 733 | 27 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/fixunstfti.c | /* clang-format off */
/* ===-- fixunstfsi.c - Implement __fixunstfsi -----------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#define QUAD_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
typedef tu_int fixuint_t;
#include "third_party/compiler_rt/fp_fixuint_impl.inc"
COMPILER_RT_ABI tu_int
__fixunstfti(fp_t a) {
return __fixuint(a);
}
#endif
| 713 | 26 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/floatditf.c | /* clang-format off */
//===-- lib/floatditf.c - integer -> quad-precision conversion ----*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements di_int to quad-precision conversion for the
// compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even
// mode.
//
//===----------------------------------------------------------------------===//
STATIC_YOINK("huge_compiler_rt_license");
#define QUAD_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
COMPILER_RT_ABI fp_t __floatditf(di_int a) {
const int aWidth = sizeof a * CHAR_BIT;
// Handle zero as a special case to protect clz
if (a == 0)
return fromRep(0);
// All other cases begin by extracting the sign and absolute value of a
rep_t sign = 0;
du_int aAbs = (du_int)a;
if (a < 0) {
sign = signBit;
aAbs = ~(du_int)a + 1U;
}
// Exponent of (fp_t)a is the width of abs(a).
const int exponent = (aWidth - 1) - __builtin_clzll(aAbs);
rep_t result;
// Shift a into the significand field, rounding if it is a right-shift
const int shift = significandBits - exponent;
result = (rep_t)aAbs << shift ^ implicitBit;
// Insert the exponent
result += (rep_t)(exponent + exponentBias) << significandBits;
// Insert the sign bit and return
return fromRep(result | sign);
}
#endif
| 1,668 | 54 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/assembly.h | /* clang-format off */
/* ===-- assembly.h - compiler-rt assembler support macros -----------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file defines macros for use in compiler-rt assembler source.
* This file is not part of the interface of this library.
*
* ===----------------------------------------------------------------------===
*/
#ifndef COMPILERRT_ASSEMBLY_H
#define COMPILERRT_ASSEMBLY_H
#if defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__)
#define SEPARATOR @
#else
#define SEPARATOR ;
#endif
#if defined(__APPLE__)
#define HIDDEN(name) .private_extern name
#define LOCAL_LABEL(name) L_##name
// tell linker it can break up file at label boundaries
#define FILE_LEVEL_DIRECTIVE .subsections_via_symbols
#define SYMBOL_IS_FUNC(name)
#define CONST_SECTION .const
#define NO_EXEC_STACK_DIRECTIVE
#elif defined(__ELF__)
#define HIDDEN(name) .hidden name
#define LOCAL_LABEL(name) .L_##name
#define FILE_LEVEL_DIRECTIVE
#if defined(__arm__)
#define SYMBOL_IS_FUNC(name) .type name,%function
#else
#define SYMBOL_IS_FUNC(name) .type name,@function
#endif
#define CONST_SECTION .section .rodata
#if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
defined(__linux__)
#define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits
#else
#define NO_EXEC_STACK_DIRECTIVE
#endif
#else // !__APPLE__ && !__ELF__
#define HIDDEN(name)
#define LOCAL_LABEL(name) .L ## name
#define FILE_LEVEL_DIRECTIVE
#define SYMBOL_IS_FUNC(name) \
.def name SEPARATOR \
.scl 2 SEPARATOR \
.type 32 SEPARATOR \
.endef
#define CONST_SECTION .section .rdata,"rd"
#define NO_EXEC_STACK_DIRECTIVE
#endif
#if defined(__arm__)
/*
* Determine actual [ARM][THUMB[1][2]] ISA using compiler predefined macros:
* - for '-mthumb -march=armv6' compiler defines '__thumb__'
* - for '-mthumb -march=armv7' compiler defines '__thumb__' and '__thumb2__'
*/
#if defined(__thumb2__) || defined(__thumb__)
#define DEFINE_CODE_STATE .thumb SEPARATOR
#define DECLARE_FUNC_ENCODING .thumb_func SEPARATOR
#if defined(__thumb2__)
#define USE_THUMB_2
#define IT(cond) it cond
#define ITT(cond) itt cond
#define ITE(cond) ite cond
#else
#define USE_THUMB_1
#define IT(cond)
#define ITT(cond)
#define ITE(cond)
#endif // defined(__thumb__2)
#else // !defined(__thumb2__) && !defined(__thumb__)
#define DEFINE_CODE_STATE .arm SEPARATOR
#define DECLARE_FUNC_ENCODING
#define IT(cond)
#define ITT(cond)
#define ITE(cond)
#endif
#if defined(USE_THUMB_1) && defined(USE_THUMB_2)
#error "USE_THUMB_1 and USE_THUMB_2 can't be defined together."
#endif
#if defined(__ARM_ARCH_4T__) || __ARM_ARCH >= 5
#define ARM_HAS_BX
#endif
#if !defined(__ARM_FEATURE_CLZ) && !defined(USE_THUMB_1) && \
(__ARM_ARCH >= 6 || (__ARM_ARCH == 5 && !defined(__ARM_ARCH_5__)))
#define __ARM_FEATURE_CLZ
#endif
#ifdef ARM_HAS_BX
#define JMP(r) bx r
#define JMPc(r, c) bx##c r
#else
#define JMP(r) mov pc, r
#define JMPc(r, c) mov##c pc, r
#endif
// pop {pc} can't switch Thumb mode on ARMv4T
#if __ARM_ARCH >= 5
#define POP_PC() pop {pc}
#else
#define POP_PC() \
pop {ip}; \
JMP(ip)
#endif
#if defined(USE_THUMB_2)
#define WIDE(op) op.w
#else
#define WIDE(op) op
#endif
#else // !defined(__arm)
#define DECLARE_FUNC_ENCODING
#define DEFINE_CODE_STATE
#endif
#define GLUE2(a, b) a##b
#define GLUE(a, b) GLUE2(a, b)
#define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
#ifdef VISIBILITY_HIDDEN
#define DECLARE_SYMBOL_VISIBILITY(name) \
HIDDEN(SYMBOL_NAME(name)) SEPARATOR
#else
#define DECLARE_SYMBOL_VISIBILITY(name)
#endif
#define DEFINE_COMPILERRT_FUNCTION(name) \
DEFINE_CODE_STATE \
FILE_LEVEL_DIRECTIVE SEPARATOR \
.globl SYMBOL_NAME(name) SEPARATOR \
SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
DECLARE_SYMBOL_VISIBILITY(name) \
DECLARE_FUNC_ENCODING \
SYMBOL_NAME(name):
#define DEFINE_COMPILERRT_THUMB_FUNCTION(name) \
DEFINE_CODE_STATE \
FILE_LEVEL_DIRECTIVE SEPARATOR \
.globl SYMBOL_NAME(name) SEPARATOR \
SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
DECLARE_SYMBOL_VISIBILITY(name) SEPARATOR \
.thumb_func SEPARATOR \
SYMBOL_NAME(name):
#define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \
DEFINE_CODE_STATE \
FILE_LEVEL_DIRECTIVE SEPARATOR \
.globl SYMBOL_NAME(name) SEPARATOR \
SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
HIDDEN(SYMBOL_NAME(name)) SEPARATOR \
DECLARE_FUNC_ENCODING \
SYMBOL_NAME(name):
#define DEFINE_COMPILERRT_PRIVATE_FUNCTION_UNMANGLED(name) \
DEFINE_CODE_STATE \
.globl name SEPARATOR \
SYMBOL_IS_FUNC(name) SEPARATOR \
HIDDEN(name) SEPARATOR \
DECLARE_FUNC_ENCODING \
name:
#define DEFINE_COMPILERRT_FUNCTION_ALIAS(name, target) \
.globl SYMBOL_NAME(name) SEPARATOR \
SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
DECLARE_SYMBOL_VISIBILITY(SYMBOL_NAME(name)) SEPARATOR \
.set SYMBOL_NAME(name), SYMBOL_NAME(target) SEPARATOR
#if defined(__ARM_EABI__)
#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name) \
DEFINE_COMPILERRT_FUNCTION_ALIAS(aeabi_name, name)
#else
#define DEFINE_AEABI_FUNCTION_ALIAS(aeabi_name, name)
#endif
#ifdef __ELF__
#define END_COMPILERRT_FUNCTION(name) \
.size SYMBOL_NAME(name), . - SYMBOL_NAME(name)
#else
#define END_COMPILERRT_FUNCTION(name)
#endif
#endif /* COMPILERRT_ASSEMBLY_H */
| 7,301 | 206 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/fixunssfti.c | /* clang-format off */
/* ===-- fixunssfti.c - Implement __fixunssfti -----------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __fixunssfti for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#define SINGLE_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#if defined(CRT_HAS_128BIT)
typedef tu_int fixuint_t;
#include "third_party/compiler_rt/fp_fixuint_impl.inc"
COMPILER_RT_ABI tu_int
__fixunssfti(fp_t a) {
return __fixuint(a);
}
#endif
| 839 | 30 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/negti2.c | /* clang-format off */
/* ===-- negti2.c - Implement __negti2 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __negti2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
#ifdef CRT_HAS_128BIT
/* Returns: -a */
COMPILER_RT_ABI ti_int
__negti2(ti_int a)
{
/* Note: this routine is here for API compatibility; any sane compiler
* should expand it inline.
*/
return -a;
}
#endif /* CRT_HAS_128BIT */
| 859 | 34 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/fp_trunc.inc | /* clang-format off */
//= lib/fp_trunc_impl.inc - high precision -> low precision conversion *-*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements a fairly generic conversion from a wider to a narrower
// IEEE-754 floating-point type in the default (round to nearest, ties to even)
// rounding mode. The constants and types defined following the includes below
// parameterize the conversion.
//
// This routine can be trivially adapted to support conversions to
// half-precision or from quad-precision. It does not support types that don't
// use the usual IEEE-754 interchange formats; specifically, some work would be
// needed to adapt it to (for example) the Intel 80-bit format or PowerPC
// double-double format.
//
// Note please, however, that this implementation is only intended to support
// *narrowing* operations; if you need to convert to a *wider* floating-point
// type (e.g. float -> double), then this routine will not do what you want it
// to.
//
// It also requires that integer types at least as large as both formats
// are available on the target platform; this may pose a problem when trying
// to add support for quad on some 32-bit systems, for example.
//
// Finally, the following assumptions are made:
//
// 1. floating-point types and integer types have the same endianness on the
// target platform
//
// 2. quiet NaNs, if supported, are indicated by the leading bit of the
// significand field being set
//
//===----------------------------------------------------------------------===//
#include "third_party/compiler_rt/fp_trunc_common.inc"
#include "libc/literal.h"
static __inline dst_t __truncXfYf2__(src_t a) {
// Various constants whose values follow from the type parameters.
// Any reasonable optimizer will fold and propagate all of these.
const int srcBits = sizeof(src_t)*CHAR_BIT;
const int srcExpBits = srcBits - srcSigBits - 1;
const int srcInfExp = (1u << srcExpBits) - 1;
const int srcExpBias = srcInfExp >> 1;
const src_rep_t srcMinNormal = SRC_REP_C(1) << srcSigBits;
const src_rep_t srcSignificandMask = srcMinNormal - 1;
const src_rep_t srcInfinity = (src_rep_t)srcInfExp << srcSigBits;
const src_rep_t srcSignMask = SRC_REP_C(1) << (srcSigBits + srcExpBits);
const src_rep_t srcAbsMask = srcSignMask - 1;
const src_rep_t roundMask = (SRC_REP_C(1) << (srcSigBits - dstSigBits)) - 1;
const src_rep_t halfway = SRC_REP_C(1) << (srcSigBits - dstSigBits - 1);
const src_rep_t srcQNaN = SRC_REP_C(1) << (srcSigBits - 1);
const src_rep_t srcNaNCode = srcQNaN - 1;
const int dstBits = sizeof(dst_t)*CHAR_BIT;
const int dstExpBits = dstBits - dstSigBits - 1;
const int dstInfExp = (1u << dstExpBits) - 1;
const int dstExpBias = dstInfExp >> 1;
const int underflowExponent = srcExpBias + 1 - dstExpBias;
const int overflowExponent = srcExpBias + dstInfExp - dstExpBias;
const src_rep_t underflow = (src_rep_t)underflowExponent << srcSigBits;
const src_rep_t overflow = (src_rep_t)overflowExponent << srcSigBits;
const dst_rep_t dstQNaN = DST_REP_C(1) << (dstSigBits - 1);
const dst_rep_t dstNaNCode = dstQNaN - 1;
// Break a into a sign and representation of the absolute value
const src_rep_t aRep = srcToRep(a);
const src_rep_t aAbs = aRep & srcAbsMask;
const src_rep_t sign = aRep & srcSignMask;
dst_rep_t absResult;
if (aAbs - underflow < aAbs - overflow) {
// The exponent of a is within the range of normal numbers in the
// destination format. We can convert by simply right-shifting with
// rounding and adjusting the exponent.
absResult = aAbs >> (srcSigBits - dstSigBits);
absResult -= (dst_rep_t)(srcExpBias - dstExpBias) << dstSigBits;
const src_rep_t roundBits = aAbs & roundMask;
// Round to nearest
if (roundBits > halfway)
absResult++;
// Ties to even
else if (roundBits == halfway)
absResult += absResult & 1;
}
else if (aAbs > srcInfinity) {
// a is NaN.
// Conjure the result by beginning with infinity, setting the qNaN
// bit and inserting the (truncated) trailing NaN field.
absResult = (dst_rep_t)dstInfExp << dstSigBits;
absResult |= dstQNaN;
absResult |= ((aAbs & srcNaNCode) >> (srcSigBits - dstSigBits)) & dstNaNCode;
}
else if (aAbs >= overflow) {
// a overflows to infinity.
absResult = (dst_rep_t)dstInfExp << dstSigBits;
}
else {
// a underflows on conversion to the destination type or is an exact
// zero. The result may be a denormal or zero. Extract the exponent
// to get the shift amount for the denormalization.
const int aExp = aAbs >> srcSigBits;
const int shift = srcExpBias - dstExpBias - aExp + 1;
const src_rep_t significand = (aRep & srcSignificandMask) | srcMinNormal;
// Right shift by the denormalization amount with sticky.
if (shift > srcSigBits) {
absResult = 0;
} else {
const bool sticky = significand << (srcBits - shift);
src_rep_t denormalizedSignificand = significand >> shift | sticky;
absResult = denormalizedSignificand >> (srcSigBits - dstSigBits);
const src_rep_t roundBits = denormalizedSignificand & roundMask;
// Round to nearest
if (roundBits > halfway)
absResult++;
// Ties to even
else if (roundBits == halfway)
absResult += absResult & 1;
}
}
// Apply the signbit to (dst_t)abs(a).
const dst_rep_t result = absResult | sign >> (srcBits - dstBits);
return dstFromRep(result);
}
| 6,026 | 138 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/negsf2.c | /* clang-format off */
//===-- lib/negsf2.c - single-precision negation ------------------*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements single-precision soft-float negation.
//
//===----------------------------------------------------------------------===//
STATIC_YOINK("huge_compiler_rt_license");
#define SINGLE_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
COMPILER_RT_ABI fp_t
__negsf2(fp_t a) {
return fromRep(toRep(a) ^ signBit);
}
#if defined(__ARM_EABI__)
#if defined(COMPILER_RT_ARMHF_TARGET)
AEABI_RTABI fp_t __aeabi_fneg(fp_t a) {
return __negsf2(a);
}
#else
AEABI_RTABI fp_t __aeabi_fneg(fp_t a) COMPILER_RT_ALIAS(__negsf2);
#endif
#endif
| 942 | 34 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/subtf3.c | /* clang-format off */
//===-- lib/subtf3.c - Quad-precision subtraction -----------------*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements quad-precision soft-float subtraction with the
// IEEE-754 default rounding (to nearest, ties to even).
//
//===----------------------------------------------------------------------===//
STATIC_YOINK("huge_compiler_rt_license");
#define QUAD_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
COMPILER_RT_ABI fp_t __addtf3(fp_t a, fp_t b);
// Subtraction; flip the sign bit of b and add.
COMPILER_RT_ABI fp_t
__subtf3(fp_t a, fp_t b) {
return __addtf3(a, fromRep(toRep(b) ^ signBit));
}
#endif
| 971 | 31 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/divti3.c | #if 0
/*ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â To the extent possible under law, Justine Tunney has waived â
â all copyright and related or neighboring rights to division, â
â as it is written in the following disclaimers: â
â ⢠http://unlicense.org/ â
â ⢠http://creativecommons.org/publicdomain/zero/1.0/ â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#endif
#include "third_party/compiler_rt/int_lib.h"
/**
* Divides 128-bit signed integers.
*
* @param a is numerator
* @param b is denominator
* @return quotient or result of division
* @note rounds towards zero
*/
COMPILER_RT_ABI ti_int __divti3(ti_int a, ti_int b) {
return __divmodti4(a, b, NULL);
}
| 1,090 | 23 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/modti3.c | /* clang-format off */
/* ===-- modti3.c - Implement __modti3 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __modti3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
#ifdef CRT_HAS_128BIT
/*Returns: a % b */
COMPILER_RT_ABI ti_int
__modti3(ti_int a, ti_int b)
{
const int bits_in_tword_m1 = (int)(sizeof(ti_int) * CHAR_BIT) - 1;
ti_int s = b >> bits_in_tword_m1; /* s = b < 0 ? -1 : 0 */
b = (b ^ s) - s; /* negate if s == -1 */
s = a >> bits_in_tword_m1; /* s = a < 0 ? -1 : 0 */
a = (a ^ s) - s; /* negate if s == -1 */
tu_int r;
__udivmodti4(a, b, &r);
return ((ti_int)r ^ s) - s; /* negate if s == -1 */
}
#endif /* CRT_HAS_128BIT */
| 1,186 | 38 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/divsi3.c | /* clang-format off */
/* ===-- divsi3.c - Implement __divsi3 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __divsi3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
/* Returns: a / b */
COMPILER_RT_ABI si_int
__divsi3(si_int a, si_int b)
{
const int bits_in_word_m1 = (int)(sizeof(si_int) * CHAR_BIT) - 1;
si_int s_a = a >> bits_in_word_m1; /* s_a = a < 0 ? -1 : 0 */
si_int s_b = b >> bits_in_word_m1; /* s_b = b < 0 ? -1 : 0 */
a = (a ^ s_a) - s_a; /* negate if s_a == -1 */
b = (b ^ s_b) - s_b; /* negate if s_b == -1 */
s_a ^= s_b; /* sign of quotient */
/*
* On CPUs without unsigned hardware division support,
* this calls __udivsi3 (notice the cast to su_int).
* On CPUs with unsigned hardware division support,
* this uses the unsigned division instruction.
*/
return ((su_int)a/(su_int)b ^ s_a) - s_a; /* negate if s_a == -1 */
}
#if defined(__ARM_EABI__)
AEABI_RTABI si_int __aeabi_idiv(si_int a, si_int b) COMPILER_RT_ALIAS(__divsi3);
#endif
| 1,572 | 43 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/trunctfdf2.c | /* clang-format off */
//===-- lib/truncdfsf2.c - quad -> double conversion --------------*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
STATIC_YOINK("huge_compiler_rt_license");
#define QUAD_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
#define SRC_QUAD
#define DST_DOUBLE
#include "third_party/compiler_rt/fp_trunc_impl.inc"
COMPILER_RT_ABI double __trunctfdf2(long double a) {
return __truncXfYf2__(a);
}
#endif
| 732 | 26 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/floatsitf.c | /* clang-format off */
//===-- lib/floatsitf.c - integer -> quad-precision conversion ----*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements integer to quad-precision conversion for the
// compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even
// mode.
//
//===----------------------------------------------------------------------===//
STATIC_YOINK("huge_compiler_rt_license");
#define QUAD_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
COMPILER_RT_ABI fp_t __floatsitf(int a) {
const int aWidth = sizeof a * CHAR_BIT;
// Handle zero as a special case to protect clz
if (a == 0)
return fromRep(0);
// All other cases begin by extracting the sign and absolute value of a
rep_t sign = 0;
unsigned aAbs = (unsigned)a;
if (a < 0) {
sign = signBit;
aAbs = ~(unsigned)a + 1U;
}
// Exponent of (fp_t)a is the width of abs(a).
const int exponent = (aWidth - 1) - __builtin_clz(aAbs);
rep_t result;
// Shift a into the significand field and clear the implicit bit.
const int shift = significandBits - exponent;
result = (rep_t)aAbs << shift ^ implicitBit;
// Insert the exponent
result += (rep_t)(exponent + exponentBias) << significandBits;
// Insert the sign bit and return
return fromRep(result | sign);
}
#endif
| 1,665 | 54 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/bswapdi2.c | /* clang-format off */
/* ===-- bswapdi2.c - Implement __bswapdi2 ---------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __bswapdi2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
COMPILER_RT_ABI uint64_t __bswapdi2(uint64_t u) {
return (
(((u)&0xff00000000000000ULL) >> 56) |
(((u)&0x00ff000000000000ULL) >> 40) |
(((u)&0x0000ff0000000000ULL) >> 24) |
(((u)&0x000000ff00000000ULL) >> 8) |
(((u)&0x00000000ff000000ULL) << 8) |
(((u)&0x0000000000ff0000ULL) << 24) |
(((u)&0x000000000000ff00ULL) << 40) |
(((u)&0x00000000000000ffULL) << 56));
}
| 1,030 | 31 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/fixdfdi.c | /* clang-format off */
/* ===-- fixdfdi.c - Implement __fixdfdi -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#define DOUBLE_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#ifndef __SOFT_FP__
/* Support for systems that have hardware floating-point; can set the invalid
* flag as a side-effect of computation.
*/
COMPILER_RT_ABI du_int __fixunsdfdi(double a);
COMPILER_RT_ABI di_int
__fixdfdi(double a)
{
if (a < 0.0) {
return -__fixunsdfdi(-a);
}
return __fixunsdfdi(a);
}
#else
/* Support for systems that don't have hardware floating-point; there are no
* flags to set, and we don't want to code-gen to an unknown soft-float
* implementation.
*/
typedef di_int fixint_t;
typedef du_int fixuint_t;
#include "third_party/compiler_rt/fp_fixint_impl.inc"
COMPILER_RT_ABI di_int
__fixdfdi(fp_t a) {
return __fixint(a);
}
#endif
#if defined(__ARM_EABI__)
#if defined(COMPILER_RT_ARMHF_TARGET)
AEABI_RTABI di_int __aeabi_d2lz(fp_t a) {
return __fixdfdi(a);
}
#else
AEABI_RTABI di_int __aeabi_d2lz(fp_t a) COMPILER_RT_ALIAS(__fixdfdi);
#endif
#endif
| 1,408 | 59 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/powisf2.c | /* clang-format off */
/*===-- powisf2.cpp - Implement __powisf2 ---------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __powisf2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
/* Returns: a ^ b */
COMPILER_RT_ABI float
__powisf2(float a, si_int b)
{
const int recip = b < 0;
float r = 1;
while (1)
{
if (b & 1)
r *= a;
b /= 2;
if (b == 0)
break;
a *= a;
}
return recip ? 1/r : r;
}
| 905 | 38 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/bswapsi2.c | /* clang-format off */
/* ===-- bswapsi2.c - Implement __bswapsi2 ---------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __bswapsi2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
COMPILER_RT_ABI uint32_t __bswapsi2(uint32_t u) {
return (
(((u)&0xff000000) >> 24) |
(((u)&0x00ff0000) >> 8) |
(((u)&0x0000ff00) << 8) |
(((u)&0x000000ff) << 24));
}
| 810 | 27 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/floatundidf.c | /* clang-format off */
/* ===-- floatundidf.c - Implement __floatundidf ---------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __floatundidf for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
/* Returns: convert a to a double, rounding toward even. */
/* Assumption: double is a IEEE 64 bit floating point type
* du_int is a 64 bit integral type
*/
/* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */
#include "libc/literal.h"
#include "third_party/compiler_rt/int_lib.h"
#ifndef __SOFT_FP__
/* Support for systems that have hardware floating-point; we'll set the inexact flag
* as a side-effect of this computation.
*/
COMPILER_RT_ABI double
__floatundidf(du_int a)
{
static const double twop52 = 4503599627370496.0; // 0x1.0p52
static const double twop84 = 19342813113834066795298816.0; // 0x1.0p84
static const double twop84_plus_twop52 = 19342813118337666422669312.0; // 0x1.00000001p84
union { uint64_t x; double d; } high = { .d = twop84 };
union { uint64_t x; double d; } low = { .d = twop52 };
high.x |= a >> 32;
low.x |= a & UINT64_C(0x00000000ffffffff);
const double result = (high.d - twop84_plus_twop52) + low.d;
return result;
}
#else
/* Support for systems that don't have hardware floating-point; there are no flags to
* set, and we don't want to code-gen to an unknown soft-float implementation.
*/
COMPILER_RT_ABI double
__floatundidf(du_int a)
{
if (a == 0)
return 0.0;
const unsigned N = sizeof(du_int) * CHAR_BIT;
int sd = N - __builtin_clzll(a); /* number of significant digits */
int e = sd - 1; /* exponent */
if (sd > DBL_MANT_DIG)
{
/* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
* finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
* 12345678901234567890123456
* 1 = msb 1 bit
* P = bit DBL_MANT_DIG-1 bits to the right of 1
* Q = bit DBL_MANT_DIG bits to the right of 1
* R = "or" of all bits to the right of Q
*/
switch (sd)
{
case DBL_MANT_DIG + 1:
a <<= 1;
break;
case DBL_MANT_DIG + 2:
break;
default:
a = (a >> (sd - (DBL_MANT_DIG+2))) |
((a & ((du_int)(-1) >> ((N + DBL_MANT_DIG+2) - sd))) != 0);
};
/* finish: */
a |= (a & 4) != 0; /* Or P into R */
++a; /* round - this step may add a significant bit */
a >>= 2; /* dump Q and R */
/* a is now rounded to DBL_MANT_DIG or DBL_MANT_DIG+1 bits */
if (a & ((du_int)1 << DBL_MANT_DIG))
{
a >>= 1;
++e;
}
/* a is now rounded to DBL_MANT_DIG bits */
}
else
{
a <<= (DBL_MANT_DIG - sd);
/* a is now rounded to DBL_MANT_DIG bits */
}
double_bits fb;
fb.u.s.high = ((e + 1023) << 20) | /* exponent */
((su_int)(a >> 32) & 0x000FFFFF); /* mantissa-high */
fb.u.s.low = (su_int)a; /* mantissa-low */
return fb.f;
}
#endif
#if defined(__ARM_EABI__)
#if defined(COMPILER_RT_ARMHF_TARGET)
AEABI_RTABI double __aeabi_ul2d(du_int a) {
return __floatundidf(a);
}
#else
AEABI_RTABI double __aeabi_ul2d(du_int a) COMPILER_RT_ALIAS(__floatundidf);
#endif
#endif
| 3,850 | 119 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/popcountti2.c | /* clang-format off */
/* ===-- popcountti2.c - Implement __popcountti2 ----------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __popcountti2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
#ifdef CRT_HAS_128BIT
/* Returns: count of 1 bits */
COMPILER_RT_ABI si_int
__popcountti2(ti_int a)
{
tu_int x3 = (tu_int)a;
x3 = x3 - ((x3 >> 1) & (((tu_int)0x5555555555555555uLL << 64) |
0x5555555555555555uLL));
/* Every 2 bits holds the sum of every pair of bits (64) */
x3 = ((x3 >> 2) & (((tu_int)0x3333333333333333uLL << 64) | 0x3333333333333333uLL))
+ (x3 & (((tu_int)0x3333333333333333uLL << 64) | 0x3333333333333333uLL));
/* Every 4 bits holds the sum of every 4-set of bits (3 significant bits) (32) */
x3 = (x3 + (x3 >> 4))
& (((tu_int)0x0F0F0F0F0F0F0F0FuLL << 64) | 0x0F0F0F0F0F0F0F0FuLL);
/* Every 8 bits holds the sum of every 8-set of bits (4 significant bits) (16) */
du_int x2 = (du_int)(x3 + (x3 >> 64));
/* Every 8 bits holds the sum of every 8-set of bits (5 significant bits) (8) */
su_int x = (su_int)(x2 + (x2 >> 32));
/* Every 8 bits holds the sum of every 8-set of bits (6 significant bits) (4) */
x = x + (x >> 16);
/* Every 8 bits holds the sum of every 8-set of bits (7 significant bits) (2) */
/* Upper 16 bits are garbage */
return (x + (x >> 8)) & 0xFF; /* (8 significant bits) */
}
#endif /* CRT_HAS_128BIT */
| 1,882 | 48 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/udivmodti4.c | #if 0
/*ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â To the extent possible under law, Justine Tunney has waived â
â all copyright and related or neighboring rights to division, â
â as it is written in the following disclaimers: â
â ⢠http://unlicense.org/ â
â ⢠http://creativecommons.org/publicdomain/zero/1.0/ â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#endif
#include "third_party/compiler_rt/int_lib.h"
/**
* Returns 128 bit division result by 64 bit.
*
* Result must fit in 64 bits. Remainder is stored in r.
*
* @see libdivide libdivide_128_div_64_to_64() division fallback
* @see Knuth, Volume 2, section 4.3.1, Algorithm D for correctness proof
* @see https://danlark.org/2020/06/14/128-bit-division/
*/
forceinline du_int udiv128by64to64default(du_int u1, du_int u0, du_int v,
du_int *r) {
const unsigned n_udword_bits = sizeof(du_int) * CHAR_BIT;
const du_int b = 1ULL << (n_udword_bits / 2); // Number base (32 bits)
du_int un1, un0; // Norm. dividend LSD's
du_int vn1, vn0; // Norm. divisor digits
du_int q1, q0; // Quotient digits
du_int un64, un21, un10; // Dividend digit pairs
du_int rhat; // Remainder
si_int s; // Normalization shift
s = __builtin_clzll(v);
if (s > 0) {
// Normalize the divisor.
v = v << s;
un64 = (u1 << s) | (u0 >> (n_udword_bits - s));
un10 = u0 << s; // Shift dividend left
} else {
// Avoid undefined behavior of (u0 >> 64).
un64 = u1;
un10 = u0;
}
// Break divisor up into two 32-bit digits.
vn1 = v >> (n_udword_bits / 2);
vn0 = v & 0xFFFFFFFF;
// Break right half of dividend into two digits.
un1 = un10 >> (n_udword_bits / 2);
un0 = un10 & 0xFFFFFFFF;
// Compute the first quotient digit, q1.
q1 = un64 / vn1;
rhat = un64 - q1 * vn1;
// q1 has at most error 2. No more than 2 iterations.
while (q1 >= b || q1 * vn0 > b * rhat + un1) {
q1 = q1 - 1;
rhat = rhat + vn1;
if (rhat >= b) break;
}
un21 = un64 * b + un1 - q1 * v;
// Compute the second quotient digit.
q0 = un21 / vn1;
rhat = un21 - q0 * vn1;
// q0 has at most error 2. No more than 2 iterations.
while (q0 >= b || q0 * vn0 > b * rhat + un0) {
q0 = q0 - 1;
rhat = rhat + vn1;
if (rhat >= b) break;
}
*r = (un21 * b + un0 - q0 * v) >> s;
return q1 * b + q0;
}
forceinline du_int udiv128by64to64(du_int u1, du_int u0, du_int v, du_int *r) {
#ifdef __x86_64__
du_int result;
asm("div\t%2" : "=a"(result), "=d"(*r) : "r"(v), "0"(u0), "1"(u1) : "cc");
return result;
#else
return udiv128by64to64default(u1, u0, v, r);
#endif
}
/**
* Performs 128-bit unsigned division and remainder.
*
* @param a is dividend
* @param b is divisor
* @param rem receives remainder if not NULL
*/
COMPILER_RT_ABI tu_int __udivmodti4(tu_int a, tu_int b, tu_int *rem) {
const unsigned n_utword_bits = sizeof(tu_int) * CHAR_BIT;
utwords dividend, divisor, quotient, remainder;
si_int shift;
dividend.all = a;
divisor.all = b;
if (divisor.all > dividend.all) {
if (rem) *rem = dividend.all;
return 0;
}
// When the divisor fits in 64 bits, we can use an optimized path.
if (divisor.s.high == 0) {
remainder.s.high = 0;
if (dividend.s.high < divisor.s.low) {
// The result fits in 64 bits.
quotient.s.low = udiv128by64to64(dividend.s.high, dividend.s.low,
divisor.s.low, &remainder.s.low);
quotient.s.high = 0;
} else {
// First, divide with the high part to get the remainder in
// dividend.s.high. After that dividend.s.high < divisor.s.low.
quotient.s.high = dividend.s.high / divisor.s.low;
dividend.s.high = dividend.s.high % divisor.s.low;
quotient.s.low = udiv128by64to64(dividend.s.high, dividend.s.low,
divisor.s.low, &remainder.s.low);
}
if (rem) *rem = remainder.all;
return quotient.all;
}
// 0 <= shift <= 63.
shift = __builtin_clzll(divisor.s.high) - __builtin_clzll(dividend.s.high);
divisor.all <<= shift;
quotient.s.high = 0;
quotient.s.low = 0;
for (; shift >= 0; --shift) {
quotient.s.low <<= 1;
// Branch free version of.
// if (dividend.all >= divisor.all)
// {
// dividend.all -= divisor.all;
// carry = 1;
// }
ti_int s = (ti_int)(divisor.all - dividend.all - 1) >> (n_utword_bits - 1);
quotient.s.low |= s & 1;
dividend.all -= divisor.all & s;
divisor.all >>= 1;
}
if (rem) *rem = dividend.all;
return quotient.all;
}
| 5,156 | 138 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/fixunstfsi.c | /* clang-format off */
/* ===-- fixunstfsi.c - Implement __fixunstfsi -----------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#define QUAD_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
typedef su_int fixuint_t;
#include "third_party/compiler_rt/fp_fixuint_impl.inc"
COMPILER_RT_ABI su_int
__fixunstfsi(fp_t a) {
return __fixuint(a);
}
#endif
| 713 | 26 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/trunctfsf2.c | /* clang-format off */
//===-- lib/trunctfsf2.c - quad -> single conversion --------------*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
STATIC_YOINK("huge_compiler_rt_license");
#define QUAD_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
#define SRC_QUAD
#define DST_SINGLE
#include "third_party/compiler_rt/fp_trunc_impl.inc"
COMPILER_RT_ABI float __trunctfsf2(long double a) {
return __truncXfYf2__(a);
}
#endif
| 731 | 26 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/subdf3.c | /* clang-format off */
//===-- lib/adddf3.c - Double-precision subtraction ---------------*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements double-precision soft-float subtraction with the
// IEEE-754 default rounding (to nearest, ties to even).
//
//===----------------------------------------------------------------------===//
STATIC_YOINK("huge_compiler_rt_license");
#define DOUBLE_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
// Subtraction; flip the sign bit of b and add.
COMPILER_RT_ABI fp_t
__subdf3(fp_t a, fp_t b) {
return __adddf3(a, fromRep(toRep(b) ^ signBit));
}
#if defined(__ARM_EABI__)
#if defined(COMPILER_RT_ARMHF_TARGET)
AEABI_RTABI fp_t __aeabi_dsub(fp_t a, fp_t b) {
return __subdf3(a, b);
}
#else
AEABI_RTABI fp_t __aeabi_dsub(fp_t a, fp_t b) COMPILER_RT_ALIAS(__subdf3);
#endif
#endif
| 1,098 | 36 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/floatuntixf.c | /* clang-format off */
/* ===-- floatuntixf.c - Implement __floatuntixf ---------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __floatuntixf for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
#ifdef CRT_HAS_128BIT
/* Returns: convert a to a long double, rounding toward even. */
/* Assumption: long double is a IEEE 80 bit floating point type padded to 128 bits
* tu_int is a 128 bit integral type
*/
/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
* 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
*/
COMPILER_RT_ABI long double
__floatuntixf(tu_int a)
{
if (a == 0)
return 0.0;
const unsigned N = sizeof(tu_int) * CHAR_BIT;
int sd = N - __clzti2(a); /* number of significant digits */
int e = sd - 1; /* exponent */
if (sd > LDBL_MANT_DIG)
{
/* start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
* finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
* 12345678901234567890123456
* 1 = msb 1 bit
* P = bit LDBL_MANT_DIG-1 bits to the right of 1
* Q = bit LDBL_MANT_DIG bits to the right of 1
* R = "or" of all bits to the right of Q
*/
switch (sd)
{
case LDBL_MANT_DIG + 1:
a <<= 1;
break;
case LDBL_MANT_DIG + 2:
break;
default:
a = (a >> (sd - (LDBL_MANT_DIG+2))) |
((a & ((tu_int)(-1) >> ((N + LDBL_MANT_DIG+2) - sd))) != 0);
};
/* finish: */
a |= (a & 4) != 0; /* Or P into R */
++a; /* round - this step may add a significant bit */
a >>= 2; /* dump Q and R */
/* a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits */
if (a & ((tu_int)1 << LDBL_MANT_DIG))
{
a >>= 1;
++e;
}
/* a is now rounded to LDBL_MANT_DIG bits */
}
else
{
a <<= (LDBL_MANT_DIG - sd);
/* a is now rounded to LDBL_MANT_DIG bits */
}
long_double_bits fb;
fb.u.high.s.low = (e + 16383); /* exponent */
fb.u.low.all = (du_int)a; /* mantissa */
return fb.f;
}
#endif
| 2,773 | 85 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/paritydi2.c | /* clang-format off */
/* ===-- paritydi2.c - Implement __paritydi2 -------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __paritydi2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
/* Returns: 1 if number of bits is odd else returns 0 */
COMPILER_RT_ABI si_int
__paritydi2(di_int a)
{
dwords x;
x.all = a;
return __paritysi2(x.s.high ^ x.s.low);
}
| 802 | 29 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/powixf2.c | /* clang-format off */
/* ===-- powixf2.cpp - Implement __powixf2 ---------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __powixf2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#if !_ARCH_PPC
#include "third_party/compiler_rt/int_lib.h"
/* Returns: a ^ b */
COMPILER_RT_ABI long double
__powixf2(long double a, si_int b)
{
const int recip = b < 0;
long double r = 1;
while (1)
{
if (b & 1)
r *= a;
b /= 2;
if (b == 0)
break;
a *= a;
}
return recip ? 1/r : r;
}
#endif
| 949 | 42 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/clzti2.c | /* clang-format off */
/* ===-- clzti2.c - Implement __clzti2 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __clzti2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
#ifdef CRT_HAS_128BIT
/* Returns: the number of leading 0-bits */
/* Precondition: a != 0 */
COMPILER_RT_ABI si_int
__clzti2(ti_int a)
{
twords x;
x.all = a;
const di_int f = -(x.s.high == 0);
return __builtin_clzll((x.s.high & ~f) | (x.s.low & f)) +
((si_int)f & ((si_int)(sizeof(di_int) * CHAR_BIT)));
}
#endif /* CRT_HAS_128BIT */
| 977 | 37 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/int_util.h | /* clang-format off */
/* ===-- int_util.h - internal utility functions ----------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===-----------------------------------------------------------------------===
*
* This file is not part of the interface of this library.
*
* This file defines non-inline utilities which are available for use in the
* library. The function definitions themselves are all contained in int_util.c
* which will always be compiled into any compiler-rt library.
*
* ===-----------------------------------------------------------------------===
*/
#ifndef INT_UTIL_H
#define INT_UTIL_H
#include "libc/runtime/runtime.h"
/** \brief Trigger a program abort (or panic for kernel code). */
#define compilerrt_abort() __builtin_trap()
/* #define compilerrt_abort() __compilerrt_abort_impl(__FILE__, __LINE__, __func__) */
wontreturn void __compilerrt_abort_impl(const char *file, int line,
const char *function);
#define COMPILE_TIME_ASSERT(expr) COMPILE_TIME_ASSERT1(expr, __COUNTER__)
#define COMPILE_TIME_ASSERT1(expr, cnt) COMPILE_TIME_ASSERT2(expr, cnt)
#define COMPILE_TIME_ASSERT2(expr, cnt) \
typedef char ct_assert_##cnt[(expr) ? 1 : -1] UNUSED
#endif /* INT_UTIL_H */
| 1,462 | 38 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/mulsc3.c | /* clang-format off */
/* ===-- mulsc3.c - Implement __mulsc3 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __mulsc3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
#include "third_party/compiler_rt/int_math.h"
/* Returns: the product of a + ib and c + id */
COMPILER_RT_ABI Fcomplex
__mulsc3(float __a, float __b, float __c, float __d)
{
float __ac = __a * __c;
float __bd = __b * __d;
float __ad = __a * __d;
float __bc = __b * __c;
Fcomplex z;
COMPLEX_REAL(z) = __ac - __bd;
COMPLEX_IMAGINARY(z) = __ad + __bc;
if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z)))
{
int __recalc = 0;
if (crt_isinf(__a) || crt_isinf(__b))
{
__a = crt_copysignf(crt_isinf(__a) ? 1 : 0, __a);
__b = crt_copysignf(crt_isinf(__b) ? 1 : 0, __b);
if (crt_isnan(__c))
__c = crt_copysignf(0, __c);
if (crt_isnan(__d))
__d = crt_copysignf(0, __d);
__recalc = 1;
}
if (crt_isinf(__c) || crt_isinf(__d))
{
__c = crt_copysignf(crt_isinf(__c) ? 1 : 0, __c);
__d = crt_copysignf(crt_isinf(__d) ? 1 : 0, __d);
if (crt_isnan(__a))
__a = crt_copysignf(0, __a);
if (crt_isnan(__b))
__b = crt_copysignf(0, __b);
__recalc = 1;
}
if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) ||
crt_isinf(__ad) || crt_isinf(__bc)))
{
if (crt_isnan(__a))
__a = crt_copysignf(0, __a);
if (crt_isnan(__b))
__b = crt_copysignf(0, __b);
if (crt_isnan(__c))
__c = crt_copysignf(0, __c);
if (crt_isnan(__d))
__d = crt_copysignf(0, __d);
__recalc = 1;
}
if (__recalc)
{
COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c - __b * __d);
COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__a * __d + __b * __c);
}
}
return z;
}
| 2,530 | 77 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/udivti3.c | #if 0
/*ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â To the extent possible under law, Justine Tunney has waived â
â all copyright and related or neighboring rights to division, â
â as it is written in the following disclaimers: â
â ⢠http://unlicense.org/ â
â ⢠http://creativecommons.org/publicdomain/zero/1.0/ â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#endif
#include "third_party/compiler_rt/int_lib.h"
COMPILER_RT_ABI tu_int __udivti3(tu_int a, tu_int b) {
return __udivmodti4(a, b, NULL);
}
| 922 | 15 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/fixdfti.c | /* clang-format off */
/* ===-- fixdfti.c - Implement __fixdfti -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
#ifdef CRT_HAS_128BIT
#define DOUBLE_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
typedef ti_int fixint_t;
typedef tu_int fixuint_t;
#include "third_party/compiler_rt/fp_fixint_impl.inc"
COMPILER_RT_ABI ti_int
__fixdfti(fp_t a) {
return __fixint(a);
}
#endif /* CRT_HAS_128BIT */
| 769 | 30 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/popcountdi2.c | /* clang-format off */
/* ===-- popcountdi2.c - Implement __popcountdi2 ----------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __popcountdi2 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
/* Returns: count of 1 bits */
COMPILER_RT_ABI si_int
__popcountdi2(di_int a)
{
#ifdef __POPCNT__
asm("popcnt\t%1,%0" : "=r"(a) : "r"(a) : "cc");
return a;
#else
du_int x2 = (du_int)a;
x2 = x2 - ((x2 >> 1) & 0x5555555555555555uLL);
/* Every 2 bits holds the sum of every pair of bits (32) */
x2 = ((x2 >> 2) & 0x3333333333333333uLL) + (x2 & 0x3333333333333333uLL);
/* Every 4 bits holds the sum of every 4-set of bits (3 significant bits) (16) */
x2 = (x2 + (x2 >> 4)) & 0x0F0F0F0F0F0F0F0FuLL;
/* Every 8 bits holds the sum of every 8-set of bits (4 significant bits) (8) */
su_int x = (su_int)(x2 + (x2 >> 32));
/* The lower 32 bits hold four 16 bit sums (5 significant bits). */
/* Upper 32 bits are garbage */
x = x + (x >> 16);
/* The lower 16 bits hold two 32 bit sums (6 significant bits). */
/* Upper 16 bits are garbage */
return (x + (x >> 8)) & 0x0000007F; /* (7 significant bits) */
#endif
}
| 1,598 | 45 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/divtc3.c | /* clang-format off */
/*===-- divtc3.c - Implement __divtc3 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __divtc3 for the compiler_rt library.
*
*===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#define QUAD_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#include "third_party/compiler_rt/int_lib.h"
#include "third_party/compiler_rt/int_math.h"
/* Returns: the quotient of (a + ib) / (c + id) */
COMPILER_RT_ABI Lcomplex
__divtc3(long double __a, long double __b, long double __c, long double __d)
{
int __ilogbw = 0;
long double __logbw =
__compiler_rt_logbl(crt_fmaxl(crt_fabsl(__c), crt_fabsl(__d)));
if (crt_isfinite(__logbw))
{
__ilogbw = (int)__logbw;
__c = crt_scalbnl(__c, -__ilogbw);
__d = crt_scalbnl(__d, -__ilogbw);
}
long double __denom = __c * __c + __d * __d;
Lcomplex z;
COMPLEX_REAL(z) = crt_scalbnl((__a * __c + __b * __d) / __denom, -__ilogbw);
COMPLEX_IMAGINARY(z) = crt_scalbnl((__b * __c - __a * __d) / __denom, -__ilogbw);
if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z)))
{
if ((__denom == 0.0) && (!crt_isnan(__a) || !crt_isnan(__b)))
{
COMPLEX_REAL(z) = crt_copysignl(CRT_INFINITY, __c) * __a;
COMPLEX_IMAGINARY(z) = crt_copysignl(CRT_INFINITY, __c) * __b;
}
else if ((crt_isinf(__a) || crt_isinf(__b)) &&
crt_isfinite(__c) && crt_isfinite(__d))
{
__a = crt_copysignl(crt_isinf(__a) ? 1.0 : 0.0, __a);
__b = crt_copysignl(crt_isinf(__b) ? 1.0 : 0.0, __b);
COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c + __b * __d);
COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__b * __c - __a * __d);
}
else if (crt_isinf(__logbw) && __logbw > 0.0 &&
crt_isfinite(__a) && crt_isfinite(__b))
{
__c = crt_copysignl(crt_isinf(__c) ? 1.0 : 0.0, __c);
__d = crt_copysignl(crt_isinf(__d) ? 1.0 : 0.0, __d);
COMPLEX_REAL(z) = 0.0 * (__a * __c + __b * __d);
COMPLEX_IMAGINARY(z) = 0.0 * (__b * __c - __a * __d);
}
}
return z;
}
| 2,537 | 67 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/divdc3.c | /* clang-format off */
/* ===-- divdc3.c - Implement __divdc3 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __divdc3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#define DOUBLE_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#include "third_party/compiler_rt/int_lib.h"
#include "third_party/compiler_rt/int_math.h"
/* Returns: the quotient of (a + ib) / (c + id) */
COMPILER_RT_ABI Dcomplex __divdc3(double __a, double __b, double __c,
double __d) {
int __ilogbw = 0;
double __logbw = __compiler_rt_logb(crt_fmax(crt_fabs(__c), crt_fabs(__d)));
if (crt_isfinite(__logbw)) {
__ilogbw = (int)__logbw;
__c = crt_scalbn(__c, -__ilogbw);
__d = crt_scalbn(__d, -__ilogbw);
}
double __denom = __c * __c + __d * __d;
Dcomplex z;
COMPLEX_REAL(z) = crt_scalbn((__a * __c + __b * __d) / __denom, -__ilogbw);
COMPLEX_IMAGINARY(z) =
crt_scalbn((__b * __c - __a * __d) / __denom, -__ilogbw);
if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z))) {
if ((__denom == 0.0) && (!crt_isnan(__a) || !crt_isnan(__b))) {
COMPLEX_REAL(z) = crt_copysign(CRT_INFINITY, __c) * __a;
COMPLEX_IMAGINARY(z) = crt_copysign(CRT_INFINITY, __c) * __b;
} else if ((crt_isinf(__a) || crt_isinf(__b)) && crt_isfinite(__c) &&
crt_isfinite(__d)) {
__a = crt_copysign(crt_isinf(__a) ? 1.0 : 0.0, __a);
__b = crt_copysign(crt_isinf(__b) ? 1.0 : 0.0, __b);
COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c + __b * __d);
COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__b * __c - __a * __d);
} else if (crt_isinf(__logbw) && __logbw > 0.0 && crt_isfinite(__a) &&
crt_isfinite(__b)) {
__c = crt_copysign(crt_isinf(__c) ? 1.0 : 0.0, __c);
__d = crt_copysign(crt_isinf(__d) ? 1.0 : 0.0, __d);
COMPLEX_REAL(z) = 0.0 * (__a * __c + __b * __d);
COMPLEX_IMAGINARY(z) = 0.0 * (__b * __c - __a * __d);
}
}
return z;
}
| 2,367 | 59 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/multi3.c | /* clang-format off */
/* ===-- multi3.c - Implement __multi3 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
STATIC_YOINK("huge_compiler_rt_license");
* This file implements __multi3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
#include "third_party/compiler_rt/int_lib.h"
#ifdef CRT_HAS_128BIT
/* Returns: a * b */
static
ti_int
__mulddi3(du_int a, du_int b)
{
twords r;
const int bits_in_dword_2 = (int)(sizeof(di_int) * CHAR_BIT) / 2;
const du_int lower_mask = (du_int)~0 >> bits_in_dword_2;
r.s.low = (a & lower_mask) * (b & lower_mask);
du_int t = r.s.low >> bits_in_dword_2;
r.s.low &= lower_mask;
t += (a >> bits_in_dword_2) * (b & lower_mask);
r.s.low += (t & lower_mask) << bits_in_dword_2;
r.s.high = t >> bits_in_dword_2;
t = r.s.low >> bits_in_dword_2;
r.s.low &= lower_mask;
t += (b >> bits_in_dword_2) * (a & lower_mask);
r.s.low += (t & lower_mask) << bits_in_dword_2;
r.s.high += t >> bits_in_dword_2;
r.s.high += (a >> bits_in_dword_2) * (b >> bits_in_dword_2);
return r.all;
}
/* Returns: a * b */
COMPILER_RT_ABI ti_int
__multi3(ti_int a, ti_int b)
{
twords x;
x.all = a;
twords y;
y.all = b;
twords r;
r.all = __mulddi3(x.s.low, y.s.low);
r.s.high += x.s.high * y.s.low + x.s.low * y.s.high;
return r.all;
}
#endif /* CRT_HAS_128BIT */
| 1,701 | 62 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/modsi3.c | /* clang-format off */
/* ===-- modsi3.c - Implement __modsi3 -------------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __modsi3 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
/* Returns: a % b */
COMPILER_RT_ABI si_int
__modsi3(si_int a, si_int b)
{
return a - __divsi3(a, b) * b;
}
| 732 | 27 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/addtf3.c | /* clang-format off */
//===-- lib/addtf3.c - Quad-precision addition --------------------*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements quad-precision soft-float addition with the IEEE-754
// default rounding (to nearest, ties to even).
//
//===----------------------------------------------------------------------===//
STATIC_YOINK("huge_compiler_rt_license");
#define QUAD_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
#include "third_party/compiler_rt/fp_add_impl.inc"
COMPILER_RT_ABI long double __addtf3(long double a, long double b){
return __addXf3__(a, b);
}
#endif
| 920 | 29 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/muloti4.c | /* clang-format off */
/*===-- muloti4.c - Implement __muloti4 -----------------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __muloti4 for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#include "third_party/compiler_rt/int_lib.h"
#ifdef CRT_HAS_128BIT
/* Returns: a * b */
/* Effects: sets *overflow to 1 if a * b overflows */
COMPILER_RT_ABI ti_int
__muloti4(ti_int a, ti_int b, int* overflow)
{
const int N = (int)(sizeof(ti_int) * CHAR_BIT);
const ti_int MIN = (ti_int)1 << (N-1);
const ti_int MAX = ~MIN;
*overflow = 0;
ti_int result = a * b;
if (a == MIN)
{
if (b != 0 && b != 1)
*overflow = 1;
return result;
}
if (b == MIN)
{
if (a != 0 && a != 1)
*overflow = 1;
return result;
}
ti_int sa = a >> (N - 1);
ti_int abs_a = (a ^ sa) - sa;
ti_int sb = b >> (N - 1);
ti_int abs_b = (b ^ sb) - sb;
if (abs_a < 2 || abs_b < 2)
return result;
if (sa == sb)
{
if (abs_a > MAX / abs_b)
*overflow = 1;
}
else
{
if (abs_a > MIN / -abs_b)
*overflow = 1;
}
return result;
}
#endif /* CRT_HAS_128BIT */
| 1,564 | 66 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/extenddftf2.c | /* clang-format off */
//===-- lib/extenddftf2.c - double -> quad conversion -------------*- C -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
STATIC_YOINK("huge_compiler_rt_license");
#define QUAD_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
#define SRC_DOUBLE
#define DST_QUAD
#include "third_party/compiler_rt/fp_extend_impl.inc"
COMPILER_RT_ABI long double __extenddftf2(double a) {
return __extendXfYf2__(a);
}
#endif
| 738 | 27 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/fixunssfsi.c | /* clang-format off */
/* ===-- fixunssfsi.c - Implement __fixunssfsi -----------------------------===
*
* The LLVM Compiler Infrastructure
*
* This file is dual licensed under the MIT and the University of Illinois Open
* Source Licenses. See LICENSE.TXT for details.
*
* ===----------------------------------------------------------------------===
*
* This file implements __fixunssfsi for the compiler_rt library.
*
* ===----------------------------------------------------------------------===
*/
STATIC_YOINK("huge_compiler_rt_license");
#define SINGLE_PRECISION
#include "third_party/compiler_rt/fp_lib.inc"
typedef su_int fixuint_t;
#include "third_party/compiler_rt/fp_fixuint_impl.inc"
COMPILER_RT_ABI su_int
__fixunssfsi(fp_t a) {
return __fixuint(a);
}
#if defined(__ARM_EABI__)
#if defined(COMPILER_RT_ARMHF_TARGET)
AEABI_RTABI su_int __aeabi_f2uiz(fp_t a) {
return __fixunssfsi(a);
}
#else
AEABI_RTABI su_int __aeabi_f2uiz(fp_t a) COMPILER_RT_ALIAS(__fixunssfsi);
#endif
#endif
| 1,033 | 37 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/divmodti4.c | #if 0
/*ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â To the extent possible under law, Justine Tunney has waived â
â all copyright and related or neighboring rights to division, â
â as it is written in the following disclaimers: â
â ⢠http://unlicense.org/ â
â ⢠http://creativecommons.org/publicdomain/zero/1.0/ â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#endif
#include "third_party/compiler_rt/int_lib.h"
/**
* Divides 128-bit signed integers w/ remainder.
*
* @param a is numerator
* @param b is denominator
* @param opt_out_rem receives euclidean division remainder if not null
* @return quotient or result of division
* @note rounds towards zero
*/
COMPILER_RT_ABI ti_int __divmodti4(ti_int a, ti_int b, tu_int *opt_out_rem) {
int k;
tu_int r;
ti_int sa, sb, sq, sr, x, y, q;
k = sizeof(ti_int) * CHAR_BIT - 1;
if (b == -1 && a == ((ti_int)1 << k)) {
volatile int x = 0;
x = 1 / x; // raise(SIGFPE)
}
sa = a >> k; // sa = a < 0 ? -1 : 0
sb = b >> k; // sb = b < 0 ? -1 : 0
x = (a ^ sa) - sa; // negate if sa == -1
y = (b ^ sb) - sb; // negate if sb == -1
sq = sa ^ sb; // sign of quotient
sr = sa; // sign of remainder
q = __udivmodti4(x, y, &r); // unsigned divide
q = (q ^ sq) - sq; // fix quotient sign
r = (r ^ sr) - sr; // fix remainder sign
if (opt_out_rem) *opt_out_rem = r;
return q;
}
/*
Intel Kabylake i9-9900 @ 3.10GHz Client Grade
idiv32 l: 27ð 9ðð
idiv64 l: 27ð 9ðð
divmodti4 small / small l: 42ð 14ðð
divmodti4 small / large l: 14ð 5ðð
divmodti4 large / small l: 92ð 30ðð
divmodti4 large / large l: 209ð 68ðð
Intel Kabylake i3-8100 @ 3.60GHz Client Grade
idiv32 l: 51ð 14ðð
idiv64 l: 51ð 14ðð
divmodti4 small / small l: 83ð 23ðð
divmodti4 small / large l: 26ð 7ðð
divmodti4 large / small l: 175ð 48ðð
divmodti4 large / large l: 389ð 107ðð
*/
| 2,853 | 64 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/nexgen32e/floatundisf.S | // This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
#include "third_party/compiler_rt/assembly.h"
// float __floatundisf(du_int a);
#ifdef __x86_64__
.section .yoink
nopl huge_compiler_rt_license(%rip)
.previous
CONST_SECTION
.balign 16
two:
.single 2.0
#define REL_ADDR(_a) (_a)(%rip)
.text
.balign 4
DEFINE_COMPILERRT_FUNCTION(__floatundisf)
movq $1, %rsi
testq %rdi, %rdi
js 1f
cvtsi2ssq %rdi, %xmm0
ret
1: andq %rdi, %rsi
shrq %rdi
orq %rsi, %rdi
cvtsi2ssq %rdi, %xmm0
mulss REL_ADDR(two), %xmm0
ret
END_COMPILERRT_FUNCTION(__floatundisf)
#endif // __x86_64__
NO_EXEC_STACK_DIRECTIVE
| 708 | 43 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/nexgen32e/chkstk.S | // This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
#include "third_party/compiler_rt/assembly.h"
// _chkstk routine
// This routine is windows specific
// http://msdn.microsoft.com/en-us/library/ms648426.aspx
// Notes from r227519
// MSVC x64s __chkstk and cygmings ___chkstk_ms do not adjust %rsp
// themselves. It also does not clobber %rax so we can reuse it when
// adjusting %rsp.
#ifdef __x86_64__
.section .yoink
nopl huge_compiler_rt_license(%rip)
.previous
.text
.balign 4
DEFINE_COMPILERRT_FUNCTION(___chkstk_ms)
push %rcx
push %rax
cmp $0x1000,%rax
lea 24(%rsp),%rcx
jb 1f
2:
sub $0x1000,%rcx
test %rcx,(%rcx)
sub $0x1000,%rax
cmp $0x1000,%rax
ja 2b
1:
sub %rax,%rcx
test %rcx,(%rcx)
pop %rax
pop %rcx
ret
END_COMPILERRT_FUNCTION(___chkstk_ms)
#endif // __x86_64__
| 1,024 | 44 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/nexgen32e/floatdidf.c | /* clang-format off */
/* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*/
STATIC_YOINK("huge_compiler_rt_license");
/* double __floatdidf(di_int a); */
#if defined(__x86_64__) || defined(_M_X64)
#include "third_party/compiler_rt/int_lib.h"
double __floatdidf(int64_t a)
{
return (double)a;
}
#endif /* __x86_64__ */
| 390 | 20 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/nexgen32e/floatundixf.S | // This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
#include "third_party/compiler_rt/assembly.h"
// long double __floatundixf(du_int a);
#ifdef __x86_64__
.section .yoink
nopl huge_compiler_rt_license(%rip)
.previous
CONST_SECTION
.balign 16
twop64:
.quad 0x43f0000000000000
#define REL_ADDR(_a) (_a)(%rip)
.text
.balign 4
DEFINE_COMPILERRT_FUNCTION(__floatundixf)
movq %rdi, -8(%rsp)
fildq -8(%rsp)
test %rdi, %rdi
js 1f
ret
1: faddl REL_ADDR(twop64)
ret
END_COMPILERRT_FUNCTION(__floatundixf)
#endif // __x86_64__
/* Branch-free implementation is ever so slightly slower, but more beautiful.
It is likely superior for inlining, so I kept it around for future reference.
#ifdef __x86_64__
CONST_SECTION
.balign 4
twop52:
.quad 0x4330000000000000
twop84_plus_twop52_neg:
.quad 0xc530000000100000
twop84:
.quad 0x4530000000000000
#define REL_ADDR(_a) (_a)(%rip)
.text
.balign 4
DEFINE_COMPILERRT_FUNCTION(__floatundixf)
movl %edi, %esi // low 32 bits of input
shrq $32, %rdi // hi 32 bits of input
orq REL_ADDR(twop84), %rdi // 2^84 + hi (as a double)
orq REL_ADDR(twop52), %rsi // 2^52 + lo (as a double)
movq %rdi, -8(%rsp)
movq %rsi, -16(%rsp)
fldl REL_ADDR(twop84_plus_twop52_neg)
faddl -8(%rsp) // hi - 2^52 (as double extended, no rounding occurs)
faddl -16(%rsp) // hi + lo (as double extended)
ret
END_COMPILERRT_FUNCTION(__floatundixf)
#endif // __x86_64__
*/
NO_EXEC_STACK_DIRECTIVE
| 1,546 | 76 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/nexgen32e/chkstk2.S | // This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
#include "third_party/compiler_rt/assembly.h"
#ifdef __x86_64__
.section .yoink
nopl huge_compiler_rt_license(%rip)
.previous
// _chkstk (_alloca) routine - probe stack between %rsp and (%rsp-%rax) in 4k increments,
// then decrement %rsp by %rax. Preserves all registers except %rsp and flags.
// This routine is windows specific
// http://msdn.microsoft.com/en-us/library/ms648426.aspx
.text
.balign 4
DEFINE_COMPILERRT_FUNCTION(__alloca)
mov %rcx,%rax // x64 _alloca is a normal function with parameter in rcx
// fallthrough
DEFINE_COMPILERRT_FUNCTION(___chkstk)
push %rcx
cmp $0x1000,%rax
lea 16(%rsp),%rcx // rsp before calling this routine -> rcx
jb 1f
2:
sub $0x1000,%rcx
test %rcx,(%rcx)
sub $0x1000,%rax
cmp $0x1000,%rax
ja 2b
1:
sub %rax,%rcx
test %rcx,(%rcx)
lea 8(%rsp),%rax // load pointer to the return address into rax
mov %rcx,%rsp // install the new top of stack pointer into rsp
mov -8(%rax),%rcx // restore rcx
push (%rax) // push return address onto the stack
sub %rsp,%rax // restore the original value in rax
ret
END_COMPILERRT_FUNCTION(___chkstk)
END_COMPILERRT_FUNCTION(__alloca)
#endif // __x86_64__
| 1,508 | 47 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/nexgen32e/floatundidf.S | //===-- floatundidf.S - Implement __floatundidf for x86_64 ----------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements __floatundidf for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
#include "third_party/compiler_rt/assembly.h"
// double __floatundidf(du_int a);
#ifdef __x86_64__
.section .yoink
nopl huge_compiler_rt_license(%rip)
.previous
CONST_SECTION
.balign 16
twop52:
.quad 0x4330000000000000
.balign 16
twop84_plus_twop52:
.quad 0x4530000000100000
.balign 16
twop84:
.quad 0x4530000000000000
#define REL_ADDR(_a) (_a)(%rip)
.text
.balign 4
DEFINE_COMPILERRT_FUNCTION(__floatundidf)
movd %edi, %xmm0 // low 32 bits of a
shrq $32, %rdi // high 32 bits of a
orq REL_ADDR(twop84), %rdi // 0x1p84 + a_hi (no rounding occurs)
orpd REL_ADDR(twop52), %xmm0 // 0x1p52 + a_lo (no rounding occurs)
movd %rdi, %xmm1
subsd REL_ADDR(twop84_plus_twop52), %xmm1 // a_hi - 0x1p52 (no rounding occurs)
addsd %xmm1, %xmm0 // a_hi + a_lo (round happens here)
ret
END_COMPILERRT_FUNCTION(__floatundidf)
#endif // __x86_64__
NO_EXEC_STACK_DIRECTIVE
| 1,429 | 57 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/nexgen32e/floatdixf.c | /* clang-format off */
/* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*/
STATIC_YOINK("huge_compiler_rt_license");
/* long double __floatdixf(di_int a); */
#ifdef __x86_64__
#include "third_party/compiler_rt/int_lib.h"
long double __floatdixf(int64_t a)
{
return (long double)a;
}
#endif /* __i386__ */
| 378 | 20 | jart/cosmopolitan | false |
cosmopolitan/third_party/compiler_rt/nexgen32e/floatdisf.c | /* clang-format off */
/* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*/
STATIC_YOINK("huge_compiler_rt_license");
#if defined(__x86_64__) || defined(_M_X64)
#include "third_party/compiler_rt/int_lib.h"
float __floatdisf(int64_t a)
{
return (float)a;
}
#endif /* __x86_64__ */
| 351 | 18 | jart/cosmopolitan | false |
cosmopolitan/third_party/gdtoa/g_dfmt.c | /*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-â
âvi: set et ft=c ts=8 tw=8 fenc=utf-8 :viâ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â â
â The author of this software is David M. Gay. â
â Please send bug reports to David M. Gay <[email protected]> â
â or Justine Tunney <[email protected]> â
â â
â Copyright (C) 1998, 1999 by Lucent Technologies â
â All Rights Reserved â
â â
â Permission to use, copy, modify, and distribute this software and â
â its documentation for any purpose and without fee is hereby â
â granted, provided that the above copyright notice appear in all â
â copies and that both that the copyright notice and this â
â permission notice and warranty disclaimer appear in supporting â
â documentation, and that the name of Lucent or any of its entities â
â not be used in advertising or publicity pertaining to â
â distribution of the software without specific, written prior â
â permission. â
â â
â LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, â
â INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. â
â IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY â
â SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES â
â WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER â
â IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, â
â ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF â
â THIS SOFTWARE. â
â â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "third_party/gdtoa/gdtoa.internal.h"
/* clang-format off */
char*
g_dfmt(char *buf, double *d, int ndig, size_t bufsize)
{
static const FPI fpi0 = { 53, 1-1023-53+1, 2046-1023-53+1, 1, 0, Int_max };
char *b, *s, *se;
ULong bits[2], *L, sign;
int decpt, ex, i, mode;
#include "third_party/gdtoa/gdtoa_fltrnds.inc"
if (ndig < 0)
ndig = 0;
if (bufsize < (size_t)(ndig + 10))
return 0;
L = (ULong*)d;
sign = L[1] & 0x80000000L;
if ((L[1] & 0x7ff00000) == 0x7ff00000) {
/* Infinity or NaN */
if (bufsize < 10)
return 0;
if (L[1] & 0xfffff || L[0]) {
return stpcpy(buf, "NaN");
}
b = buf;
if (sign)
*b++ = '-';
return stpcpy(b, "Infinity");
}
if (L[0] == 0 && (L[1] ^ sign) == 0 /*d == 0.*/) {
b = buf;
if (L[1] & 0x80000000L)
*b++ = '-';
*b++ = '0';
*b = 0;
return b;
}
bits[0] = L[0];
bits[1] = L[1] & 0xfffff;
if ( (ex = (L[1] >> 20) & 0x7ff) !=0)
bits[1] |= 0x100000;
else
ex = 1;
ex -= 0x3ff + 52;
mode = 2;
if (ndig <= 0)
mode = 0;
i = STRTOG_Normal;
if (sign)
i = STRTOG_Normal | STRTOG_Neg;
s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se);
return __gdtoa_g__fmt(buf, s, se, decpt, sign, bufsize);
}
| 4,129 | 85 | jart/cosmopolitan | false |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.