Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit 1da7d29

Browse files
committed
Misc adjustments to avoid having to inline routines from .inc files
1 parent ffb7a86 commit 1da7d29

23 files changed

+116
-25
lines changed

.github/workflows/pack.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@ jobs:
1515

1616
- name: Pack cc-runtime
1717
run: |
18-
set -e
19-
cat assembly.h int_endianness.h int_types.h int_lib.h int_util.h $(find . -name '*.c' | LC_ALL=C sort) > /tmp/cc-runtime.c
20-
grep '#include <' /tmp/cc-runtime.c > /tmp/saved-includes
21-
sed -i '/#include/d' /tmp/cc-runtime.c
22-
cat /tmp/saved-includes /tmp/cc-runtime.c > /tmp/cc-runtime.c.tmp
23-
mv /tmp/cc-runtime.c.tmp /tmp/cc-runtime.c
18+
set -ex
19+
./pack.sh
20+
mv cc-runtime.c /tmp/
2421
2522
- name: Push packed cc-runtime
2623
run: |

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/cc-runtime.c
2+
/cc-runtime.o

clzdi2.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
// On 64-bit architectures with neither a native clz instruction nor a native
2323
// ctz instruction, gcc resolves __builtin_clz to __clzdi2 rather than
2424
// __clzsi2, leading to infinite recursion.
25-
#ifdef __builtin_clz
26-
#undef __builtin_clz
27-
#endif
2825
#define __builtin_clz(a) __clzsi2(a)
2926
extern int __clzsi2(si_int);
3027
#endif

ctzdi2.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
// On 64-bit architectures with neither a native clz instruction nor a native
2323
// ctz instruction, gcc resolves __builtin_ctz to __ctzdi2 rather than
2424
// __ctzsi2, leading to infinite recursion.
25-
#ifdef __builtin_ctz
26-
#undef __builtin_ctz
27-
#endif
2825
#define __builtin_ctz(a) __ctzsi2(a)
2926
extern int __ctzsi2(si_int);
3027
#endif

divdi3.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@
2222
#include "int_div_impl.inc"
2323

2424
COMPILER_RT_ABI di_int __divdi3(di_int a, di_int b) { return __divXi3(a, b); }
25+
26+
#undef fixint_t
27+
#undef fixuint_t
28+
#undef COMPUTE_UDIV

divsi3.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ COMPILER_RT_ABI si_int __divsi3(si_int a, si_int b) { return __divXi3(a, b); }
3030
#if defined(__ARM_EABI__)
3131
COMPILER_RT_ALIAS(__divsi3, __aeabi_idiv)
3232
#endif
33+
34+
#undef fixint_t
35+
#undef fixuint_t
36+
#undef COMPUTE_UDIV

divti3.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@
2525

2626
COMPILER_RT_ABI ti_int __divti3(ti_int a, ti_int b) { return __divXi3(a, b); }
2727

28+
#undef fixint_t
29+
#undef fixuint_t
30+
#undef COMPUTE_UDIV
31+
2832
#endif // CRT_HAS_128BIT

int_div_impl.inc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
7+
// 2024/10/20 - Modified by mintsuki for use inside cc-runtime
8+
//
79
//===----------------------------------------------------------------------===//
810
//
911
// Helpers used by __udivsi3, __umodsi3, __udivdi3, and __umodsi3.
@@ -12,6 +14,9 @@
1214

1315
#define clz(a) (sizeof(a) == sizeof(unsigned long long) ? __builtin_clzll(a) : clzsi(a))
1416

17+
#undef __udivXi3
18+
#define __udivXi3 __udivXi3__EXTERNAL_COUNTER
19+
1520
// Adapted from Figure 3-40 of The PowerPC Compiler Writer's Guide
1621
static __inline fixuint_t __udivXi3(fixuint_t n, fixuint_t d) {
1722
const unsigned N = sizeof(fixuint_t) * CHAR_BIT;
@@ -41,6 +46,9 @@ static __inline fixuint_t __udivXi3(fixuint_t n, fixuint_t d) {
4146
return n;
4247
}
4348

49+
#undef __umodXi3
50+
#define __umodXi3 __umodXi3__EXTERNAL_COUNTER
51+
4452
// Mostly identical to __udivXi3 but the return values are different.
4553
static __inline fixuint_t __umodXi3(fixuint_t n, fixuint_t d) {
4654
const unsigned N = sizeof(fixuint_t) * CHAR_BIT;
@@ -69,7 +77,12 @@ static __inline fixuint_t __umodXi3(fixuint_t n, fixuint_t d) {
6977
return r;
7078
}
7179

80+
#undef __divXi3
81+
7282
#ifdef COMPUTE_UDIV
83+
84+
#define __divXi3 __divXi3__EXTERNAL_COUNTER
85+
7386
static __inline fixint_t __divXi3(fixint_t a, fixint_t b) {
7487
const int N = (int)(sizeof(fixint_t) * CHAR_BIT) - 1;
7588
fixint_t s_a = a >> N; // s_a = a < 0 ? -1 : 0
@@ -81,7 +94,12 @@ static __inline fixint_t __divXi3(fixint_t a, fixint_t b) {
8194
}
8295
#endif // COMPUTE_UDIV
8396

97+
#undef __modXi3
98+
8499
#ifdef ASSIGN_UMOD
100+
101+
#define __modXi3 __modXi3__EXTERNAL_COUNTER
102+
85103
static __inline fixint_t __modXi3(fixint_t a, fixint_t b) {
86104
const int N = (int)(sizeof(fixint_t) * CHAR_BIT) - 1;
87105
fixint_t s = b >> N; // s = b < 0 ? -1 : 0
@@ -93,3 +111,5 @@ static __inline fixint_t __modXi3(fixint_t a, fixint_t b) {
93111
return (res ^ s) + (-s); // negate if s == -1
94112
}
95113
#endif // ASSIGN_UMOD
114+
115+
#undef clz

int_mulo_impl.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
7+
// 2024/10/20 - Modified by mintsuki for use inside cc-runtime
8+
//
79
//===----------------------------------------------------------------------===//
810
//
911
// Helper used by __mulosi4, __mulodi4 and __muloti4.
@@ -16,6 +18,9 @@
1618

1719
// Effects: sets *overflow to 1 if a * b overflows
1820

21+
#undef __muloXi4
22+
#define __muloXi4 __muloXi4__EXTERNAL_COUNTER
23+
1924
static __inline fixint_t __muloXi4(fixint_t a, fixint_t b, int *overflow) {
2025
const int N = (int)(sizeof(fixint_t) * CHAR_BIT);
2126
const fixint_t MIN = (fixint_t)((fixuint_t)1 << (N - 1));

int_mulv_impl.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
7+
// 2024/10/20 - Modified by mintsuki for use inside cc-runtime
8+
//
79
//===----------------------------------------------------------------------===//
810
//
911
// Helper used by __mulvsi3, __mulvdi3 and __mulvti3.
@@ -16,6 +18,9 @@
1618

1719
// Effects: aborts if a * b overflows
1820

21+
#undef __mulvXi3
22+
#define __mulvXi3 __mulvXi3__EXTERNAL_COUNTER
23+
1924
static __inline fixint_t __mulvXi3(fixint_t a, fixint_t b) {
2025
const int N = (int)(sizeof(fixint_t) * CHAR_BIT);
2126
const fixint_t MIN = (fixint_t)((fixuint_t)1 << (N - 1));

0 commit comments

Comments
 (0)