Skip to content

Commit f475781

Browse files
ZERICO2005mateoconlechuga
authored andcommitted
Implemented i48abs(int48_t) and added prototypes for i48div
1 parent d93d724 commit f475781

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

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: 15 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;
@@ -96,12 +103,20 @@ long labs(long n);
96103

97104
long long llabs(long long n);
98105

106+
#ifdef __SIZEOF_INT48__
107+
signed __int48 i48abs(signed __int48 n);
108+
#endif /* __SIZEOF_INT48__ */
109+
99110
div_t div(int numer, int denom);
100111

101112
ldiv_t ldiv(long numer, long denom);
102113

103114
lldiv_t lldiv(long long numer, long long denom);
104115

116+
#ifdef __SIZEOF_INT48__
117+
i48div_t i48div(signed __int48 numer, signed __int48 denom);
118+
#endif /* __SIZEOF_INT48__ */
119+
105120
__END_DECLS
106121

107122
#endif /* _STDLIB_H */

src/libcxx/include/cstdlib

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,20 @@ using ::labs;
4242
using ::llabs;
4343
inline constexpr long abs(long __x) { return labs(__x); }
4444
inline constexpr long long abs(long long __x) { return llabs(__x); }
45+
#ifdef __SIZEOF_INT48__
46+
using ::i48abs;
47+
inline signed __int48 abs(signed __int48 __x) { return i48abs(__x); }
48+
#endif // __SIZEOF_INT48__
4549

4650
using ::div;
4751
using ::ldiv;
4852
using ::lldiv;
4953
inline constexpr ldiv_t div(long __x, long __y) { return ldiv(__x, __y); }
5054
inline constexpr lldiv_t div(long long __x, long long __y) { return lldiv(__x, __y); }
55+
#ifdef __SIZEOF_INT48__
56+
using ::i48div;
57+
inline i48div_t div(signed __int48 __x, signed __int48 __y) { return i48div(__x, __y); }
58+
#endif // __SIZEOF_INT48__
5159

5260
} // namespace std
5361

0 commit comments

Comments
 (0)