Skip to content

Commit c9be0f1

Browse files
committed
Merged i48abs from master into float64_long_double
2 parents fe16e3c + 2f5bd2f commit c9be0f1

File tree

6 files changed

+65
-2
lines changed

6 files changed

+65
-2
lines changed

examples/standalone_examples/math_test/src/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,12 @@ static int24_t iabs(int24_t x)
9595
{
9696
return x < 0 ? (int24_t)-x : x;
9797
}
98+
#ifndef _EZ80
9899
static int48_t i48abs(int48_t x)
99100
{
100101
return x < 0 ? (int48_t)-x : x;
101102
}
103+
#endif
102104

103105

104106
#if INTERACTIVE && defined(_EZ80)

src/crt/i48abs.src

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
assume adl=1
2+
3+
section .text
4+
5+
public _i48abs
6+
7+
; int48_t i48abs(int48_t)
8+
_i48abs:
9+
pop bc
10+
pop de
11+
ex (sp), hl
12+
13+
; read the signbit
14+
push hl
15+
add hl, hl
16+
ex (sp), hl
17+
18+
push bc
19+
ex de, hl
20+
ret nc ; positive
21+
jp __i48neg
22+
23+
extern __i48neg

src/crt/i48div.src

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
assume adl=1
2+
3+
section .text
4+
5+
; public _i48div
6+
7+
; i48div_t i48div(int48_t numer, int48_t denom);
8+
; _i48div:

src/libc/include/stdlib.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ typedef struct {
1313
long rem;
1414
} ldiv_t;
1515

16+
#ifdef __SIZEOF_INT48__
17+
typedef struct {
18+
signed __int48 quot;
19+
signed __int48 rem;
20+
} i48div_t;
21+
#endif /* __SIZEOF_INT48__ */
22+
1623
typedef struct {
1724
long long rem;
1825
long long quot;
@@ -95,9 +102,15 @@ void _Exit(int) __NOEXCEPT __attribute__((noreturn));
95102

96103
#ifndef _ABS_INT_DEFINED
97104
#define _ABS_INT_DEFINED
105+
98106
int abs(int n);
99107
long labs(long n);
100108
long long llabs(long long n);
109+
110+
#ifdef __SIZEOF_INT48__
111+
signed __int48 i48abs(signed __int48 n);
112+
#endif /* __SIZEOF_INT48__ */
113+
101114
#endif /* _ABS_INT_DEFINED */
102115

103116
div_t div(int numer, int denom);
@@ -106,6 +119,10 @@ ldiv_t ldiv(long numer, long denom);
106119

107120
lldiv_t lldiv(long long numer, long long denom);
108121

122+
#ifdef __SIZEOF_INT48__
123+
i48div_t i48div(signed __int48 numer, signed __int48 denom);
124+
#endif /* __SIZEOF_INT48__ */
125+
109126
__END_DECLS
110127

111128
#endif /* _STDLIB_H */

src/libcxx/include/__abs_overloads

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ int abs(int n);
1717
long labs(long n);
1818
long long llabs(long long n);
1919

20+
#ifdef __SIZEOF_INT48__
21+
signed __int48 i48abs(signed __int48 n);
22+
#endif // __SIZEOF_INT48__
23+
2024
__END_DECLS
2125

2226
#endif // _ABS_INT_DEFINED
@@ -36,6 +40,12 @@ namespace std {
3640
using ::abs;
3741
inline constexpr long abs(long __x) { return labs(__x); }
3842
inline constexpr long long abs(long long __x) { return llabs(__x); }
43+
44+
#ifdef __SIZEOF_INT48__
45+
using ::i48abs;
46+
inline signed __int48 abs(signed __int48 __x) { return i48abs(__x); }
47+
#endif // __SIZEOF_INT48__
48+
3949
inline constexpr float abs(float __x) { return fabsf(__x); }
4050
inline constexpr double abs(double __x) { return fabs(__x); }
4151
inline constexpr long double abs(long double __x) { return fabsl(__x); }

src/libcxx/include/cstdlib

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
#define _EZCXX_CSTDLIB
44

55
#include <stdlib.h>
6+
#include <__abs_overloads>
67

78
#pragma clang system_header
89

9-
#include <__abs_overloads>
10-
1110
namespace std {
1211
using ::calloc;
1312
using ::malloc;
@@ -48,6 +47,10 @@ using ::ldiv;
4847
using ::lldiv;
4948
inline constexpr ldiv_t div(long __x, long __y) { return ldiv(__x, __y); }
5049
inline constexpr lldiv_t div(long long __x, long long __y) { return lldiv(__x, __y); }
50+
#ifdef __SIZEOF_INT48__
51+
using ::i48div;
52+
inline i48div_t div(signed __int48 __x, signed __int48 __y) { return i48div(__x, __y); }
53+
#endif // __SIZEOF_INT48__
5154

5255
} // namespace std
5356

0 commit comments

Comments
 (0)