Skip to content

Commit

Permalink
Ensure no macro leakage between .c files
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsuki committed Aug 10, 2024
1 parent ccb0ec7 commit 9032e9f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clzdi2.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
// On 64-bit architectures with neither a native clz instruction nor a native
// ctz instruction, gcc resolves __builtin_clz to __clzdi2 rather than
// __clzsi2, leading to infinite recursion.
#ifdef __builtin_clz
#undef __builtin_clz
#endif
#define __builtin_clz(a) __clzsi2(a)
extern int __clzsi2(si_int);
#endif
Expand Down
3 changes: 3 additions & 0 deletions ctzdi2.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
// On 64-bit architectures with neither a native clz instruction nor a native
// ctz instruction, gcc resolves __builtin_ctz to __ctzdi2 rather than
// __ctzsi2, leading to infinite recursion.
#ifdef __builtin_ctz
#undef __builtin_ctz
#endif
#define __builtin_ctz(a) __ctzsi2(a)
extern int __ctzsi2(si_int);
#endif
Expand Down
4 changes: 4 additions & 0 deletions udivdi3.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

// Returns: a / b

#ifdef clz
#undef clz
#endif
#define clz(a) (sizeof(a) == sizeof(unsigned long long) ? __builtin_clzll(a) : clzsi(a))

// Adapted from Figure 3-40 of The PowerPC Compiler Writer's Guide
Expand Down Expand Up @@ -47,3 +49,5 @@ COMPILER_RT_ABI du_int __udivdi3(du_int n, du_int d) {
n = (n << 1) | carry;
return n;
}

#undef clz
4 changes: 4 additions & 0 deletions udivsi3.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

// Returns: a / b

#ifdef clz
#undef clz
#endif
#define clz(a) (sizeof(a) == sizeof(unsigned long long) ? __builtin_clzll(a) : clzsi(a))

// Adapted from Figure 3-40 of The PowerPC Compiler Writer's Guide
Expand Down Expand Up @@ -48,6 +50,8 @@ COMPILER_RT_ABI su_int __udivsi3(su_int n, su_int d) {
return n;
}

#undef clz

#if defined(__ARM_EABI__)
COMPILER_RT_ALIAS(__udivsi3, __aeabi_uidiv)
#endif
4 changes: 4 additions & 0 deletions umoddi3.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

// Returns: a % b

#ifdef clz
#undef clz
#endif
#define clz(a) (sizeof(a) == sizeof(unsigned long long) ? __builtin_clzll(a) : clzsi(a))

// Mostly identical to __udivdi3 but the return values are different.
Expand Down Expand Up @@ -46,3 +48,5 @@ COMPILER_RT_ABI du_int __umoddi3(du_int n, du_int d) {
}
return r;
}

#undef clz
4 changes: 4 additions & 0 deletions umodsi3.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

// Returns: a % b

#ifdef clz
#undef clz
#endif
#define clz(a) (sizeof(a) == sizeof(unsigned long long) ? __builtin_clzll(a) : clzsi(a))

// Mostly identical to __udivsi3 but the return values are different.
Expand Down Expand Up @@ -46,3 +48,5 @@ COMPILER_RT_ABI su_int __umodsi3(su_int n, su_int d) {
}
return r;
}

#undef clz

0 comments on commit 9032e9f

Please sign in to comment.