Skip to content

Commit

Permalink
misc: Replace libgcc with cc-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsuki committed Nov 7, 2024
1 parent 6a9f25e commit 365217c
Show file tree
Hide file tree
Showing 188 changed files with 9,796 additions and 0 deletions.
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ rtld_sources += [

rtld_dso_sources += ['options/rtld' / host_machine.cpu_family() / 'entry.S']

subdir('options/cc-runtime')
subdir('options/elf')
subdir('options/ansi')
subdir('options/posix')
Expand Down
36 changes: 36 additions & 0 deletions options/cc-runtime/CREDITS.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This file is a partial list of people who have contributed to the LLVM/CompilerRT
project. If you have contributed a patch or made some other contribution to
LLVM/CompilerRT, please submit a patch to this file to add yourself, and it will be
done!

The list is sorted by surname and formatted to allow easy grepping and
beautification by scripts. The fields are: name (N), email (E), web-address
(W), PGP key ID and fingerprint (P), description (D), and snail-mail address
(S).

N: Craig van Vliet
E: [email protected]
W: http://www.auroraux.org
D: Code style and Readability fixes.

N: Edward O'Callaghan
E: [email protected]
W: http://www.auroraux.org
D: CMake'ify Compiler-RT build system
D: Maintain Solaris & AuroraUX ports of Compiler-RT

N: Howard Hinnant
E: [email protected]
D: Architect and primary author of compiler-rt

N: Guan-Hong Liu
E: [email protected]
D: IEEE Quad-precision functions

N: Joerg Sonnenberger
E: [email protected]
D: Maintains NetBSD port.

N: Matt Thomas
E: [email protected]
D: ARM improvements.
311 changes: 311 additions & 0 deletions options/cc-runtime/LICENSE.TXT

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions options/cc-runtime/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cc-runtime
==========

cc-runtime is a freestanding, easy to integrate subset of LLVM's compiler-rt
libgcc-compatibility functions.

Relevant licenses apply: see license headers in source files and LICENSE.TXT.
25 changes: 25 additions & 0 deletions options/cc-runtime/absvdi2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===-- absvdi2.c - Implement __absvdi2 -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements __absvdi2 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//

#include "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)((du_int)1 << (N - 1))))
compilerrt_abort();
const di_int t = a >> (N - 1);
return (a ^ t) - t;
}
25 changes: 25 additions & 0 deletions options/cc-runtime/absvsi2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===-- absvsi2.c - Implement __absvsi2 -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements __absvsi2 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//

#include "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 == ((si_int)((su_int)1 << (N - 1))))
compilerrt_abort();
const si_int t = a >> (N - 1);
return (a ^ t) - t;
}
29 changes: 29 additions & 0 deletions options/cc-runtime/absvti2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===-- absvti2.c - Implement __absvdi2 -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements __absvti2 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//

#include "int_lib.h"

#ifdef CRT_HAS_128BIT

// Returns: absolute value

// Effects: aborts if abs(x) < 0

COMPILER_RT_ABI ti_int __absvti2(ti_int a) {
const int N = (int)(sizeof(ti_int) * CHAR_BIT);
if (a == (ti_int)((tu_int)1 << (N - 1)))
compilerrt_abort();
const ti_int s = a >> (N - 1);
return (a ^ s) - s;
}

#endif // CRT_HAS_128BIT
28 changes: 28 additions & 0 deletions options/cc-runtime/adddf3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//===-- lib/adddf3.c - Double-precision addition ------------------*- C -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements double-precision soft-float addition.
//
//===----------------------------------------------------------------------===//

#ifndef CC_RUNTIME_NO_FLOAT

#define DOUBLE_PRECISION
#include "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
COMPILER_RT_ALIAS(__adddf3, __aeabi_dadd)
#endif
#endif

#endif
28 changes: 28 additions & 0 deletions options/cc-runtime/addsf3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//===-- lib/addsf3.c - Single-precision addition ------------------*- C -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements single-precision soft-float addition.
//
//===----------------------------------------------------------------------===//

#ifndef CC_RUNTIME_NO_FLOAT

#define SINGLE_PRECISION
#include "fp_add_impl.inc"

COMPILER_RT_ABI float __addsf3(float a, float b) { return __addXf3__(a, b); }

#if defined(__ARM_EABI__)
#if defined(COMPILER_RT_ARMHF_TARGET)
AEABI_RTABI float __aeabi_fadd(float a, float b) { return __addsf3(a, b); }
#else
COMPILER_RT_ALIAS(__addsf3, __aeabi_fadd)
#endif
#endif

#endif
31 changes: 31 additions & 0 deletions options/cc-runtime/addtf3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//===-- lib/addtf3.c - Quad-precision addition --------------------*- C -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements quad-precision soft-float addition.
//
//===----------------------------------------------------------------------===//

#ifndef CC_RUNTIME_NO_FLOAT

#define QUAD_PRECISION
#include "fp_lib.h"

#if defined(CRT_HAS_IEEE_TF)

#if defined(CRT_HAS_TF_MODE)
#include "fp_add_impl.inc"

COMPILER_RT_ABI fp_t __addtf3(fp_t a, fp_t b) {
return __addXf3__(a, b);
}

#endif

#endif

#endif
29 changes: 29 additions & 0 deletions options/cc-runtime/addvdi3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===-- addvdi3.c - Implement __addvdi3 -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements __addvdi3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//

#include "int_lib.h"

// Returns: a + b

// Effects: aborts if a + b overflows

COMPILER_RT_ABI di_int __addvdi3(di_int a, di_int b) {
di_int s = (du_int)a + (du_int)b;
if (b >= 0) {
if (s < a)
compilerrt_abort();
} else {
if (s >= a)
compilerrt_abort();
}
return s;
}
29 changes: 29 additions & 0 deletions options/cc-runtime/addvsi3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===-- addvsi3.c - Implement __addvsi3 -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements __addvsi3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//

#include "int_lib.h"

// Returns: a + b

// Effects: aborts if a + b overflows

COMPILER_RT_ABI si_int __addvsi3(si_int a, si_int b) {
si_int s = (su_int)a + (su_int)b;
if (b >= 0) {
if (s < a)
compilerrt_abort();
} else {
if (s >= a)
compilerrt_abort();
}
return s;
}
33 changes: 33 additions & 0 deletions options/cc-runtime/addvti3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//===-- addvti3.c - Implement __addvti3 -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements __addvti3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//

#include "int_lib.h"

#ifdef CRT_HAS_128BIT

// Returns: a + b

// Effects: aborts if a + b overflows

COMPILER_RT_ABI ti_int __addvti3(ti_int a, ti_int b) {
ti_int s = (tu_int)a + (tu_int)b;
if (b >= 0) {
if (s < a)
compilerrt_abort();
} else {
if (s >= a)
compilerrt_abort();
}
return s;
}

#endif // CRT_HAS_128BIT
39 changes: 39 additions & 0 deletions options/cc-runtime/ashldi3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ====-- ashldi3.c - Implement __ashldi3 ---------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements __ashldi3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//

#include "int_lib.h"

// Returns: a << b

// Precondition: 0 <= b < bits_in_dword

COMPILER_RT_ABI di_int __ashldi3(di_int a, 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 =
((su_int)input.s.high << b) | (input.s.low >> (bits_in_word - b));
}
return result.all;
}

#if defined(__ARM_EABI__)
COMPILER_RT_ALIAS(__ashldi3, __aeabi_llsl)
#endif
39 changes: 39 additions & 0 deletions options/cc-runtime/ashlti3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//===-- ashlti3.c - Implement __ashlti3 -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements __ashlti3 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//

#include "int_lib.h"

#ifdef CRT_HAS_128BIT

// Returns: a << b

// Precondition: 0 <= b < bits_in_tword

COMPILER_RT_ABI ti_int __ashlti3(ti_int a, int b) {
const int bits_in_dword = (int)(sizeof(di_int) * CHAR_BIT);
twords input;
twords result;
input.all = a;
if (b & bits_in_dword) /* bits_in_dword <= b < bits_in_tword */ {
result.s.low = 0;
result.s.high = input.s.low << (b - bits_in_dword);
} else /* 0 <= b < bits_in_dword */ {
if (b == 0)
return a;
result.s.low = input.s.low << b;
result.s.high =
((du_int)input.s.high << b) | (input.s.low >> (bits_in_dword - b));
}
return result.all;
}

#endif // CRT_HAS_128BIT
Loading

0 comments on commit 365217c

Please sign in to comment.