Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/crt/dcmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,31 @@ typedef union F64_pun {
#define F64_CMP_GREATER 1 /* doesn't trigger flags */
#define F64_CMP_UNORDERED 1 /* doesn't trigger flags */

typedef struct f64_cmp_arg {
long double x;
bool x_sign; /* <-- unimplemented */
unsigned int const return_address;
long double y;
bool y_sign; /* <-- unimplemented */
} f64_cmp_arg;

// assumes no NaN
int _dcmp_c(const long double *__restrict x, const long double *__restrict y) {
F64_pun arg_x, arg_y;
arg_x.flt = *x;
arg_y.flt = *y;
int _dcmp_c(f64_cmp_arg *__restrict const arg) {
F64_pun x, y;
x.flt = arg->x;
y.flt = arg->y;

bool x_sign = signbit(arg_x.flt);
bool y_sign = signbit(arg_y.flt);
bool x_sign = signbit(x.flt);
bool y_sign = signbit(y.flt);
if (x_sign != y_sign) {
if (iszero(arg_x.flt) && iszero(arg_y.flt)) {
if (iszero(x.flt) && iszero(y.flt)) {
return F64_CMP_EQUAL;
}
return (x_sign ? F64_CMP_LESS : F64_CMP_GREATER);
}

if (arg_x.bin == arg_y.bin) {
if (x.bin == y.bin) {
return F64_CMP_EQUAL;
}
return ((arg_x.bin < arg_y.bin) != x_sign) ? F64_CMP_LESS : F64_CMP_GREATER;
return ((x.bin < y.bin) != x_sign) ? F64_CMP_LESS : F64_CMP_GREATER;
}
18 changes: 10 additions & 8 deletions src/crt/dcmp.src
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

public __dcmp

; int _dcmp_c(const long double *__restrict x, const long double *__restrict y)
; int _dcmp_c(f64_cmp_arg const *__restrict const arg)
__dcmp:
; f64*_f64*_ret_i24
push bc, de, hl, af, iy
ld iy, 6
add iy, sp
pea iy + 12
push iy
; f64_cmp_arg*_ret_i24
push bc, de, hl
or a, a
sbc hl, hl
add hl, sp
push iy, af
push hl ; f64_cmp_arg*
call __dcmp_c
pop af, af, iy, af
pop af
pop af, iy
; Set the comparison flags
add hl, de
or a, a
Expand Down
15 changes: 12 additions & 3 deletions src/crt/ddiv.src
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@

public __ddiv

; float64_t f64_div(float64_t, const float64_t*)
; float64_t f64_div(bool, float64_t, const float64_t*)
__ddiv:
push af, iy
ld iy, 9
add iy, sp
add iy, sp

push iy, bc, de, hl

ld a, b ; signbit(x)
xor a, (iy + 7) ; signbit(y)
rla
push af ; Carry = (signbit(x) != signbit(y))

call _f64_div
pop af, af, af, af, iy, af

pop af, af, af, af, af
pop iy, af ; restore
ret

extern _f64_div
15 changes: 12 additions & 3 deletions src/crt/dmul.src
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@

public __dmul

; float64_t f64_mul(float64_t, const float64_t*)
; float64_t f64_mul(bool, float64_t, const float64_t*)
__dmul:
push af, iy
ld iy, 9
add iy, sp
add iy, sp

push iy, bc, de, hl

ld a, b ; signbit(x)
xor a, (iy + 7) ; signbit(y)
rla
push af ; Carry = (signbit(x) != signbit(y))

call _f64_mul
pop af, af, af, af, iy, af

pop af, af, af, af, af
pop iy, af ; restore
ret

extern _f64_mul
10 changes: 8 additions & 2 deletions src/crt/drem.src
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@

public __drem

; float64_t f64_rem(float64_t, const float64_t*)
; float64_t f64_rem(bool, float64_t, const float64_t*)
__drem:
push af, iy
ld iy, 9
add iy, sp
push iy, bc, de, hl

rl b
push af ; Carry = signbit(x)

call _f64_rem
pop af, af, af, af, iy, af

pop af, af, af, af, af
pop iy, af ; restore
ret

extern _f64_rem
12 changes: 10 additions & 2 deletions src/crt/dtol.src
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@

__dtol:
; f64_ret_i32
push af, iy, bc, de, hl
push af, iy
ld a, b
push bc, de, hl
ld hl, 7
add hl, sp
res 7, (hl) ; fabsl(x)
inc hl
rlca
ld (hl), a ; store the sign of x in the padding byte
call __dtol_c
pop af, af, af, iy, af
pop af, af, bc, iy, af
ret

extern __dtol_c
9 changes: 8 additions & 1 deletion src/crt/dtoll.src
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@

__dtoll:
; f64_ret_i64
push af, iy, bc, de, hl
push af, iy
ld a, b
res 7, b ; fabsl(x)
push bc, de, hl
ld hl, 8
add hl, sp
rlca
ld (hl), a ; store the sign of x in the padding byte
call __dtoll_c
pop af, af, af, iy, af
ret
Expand Down
2 changes: 1 addition & 1 deletion src/crt/dtoul.src
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ __dtoul:
; f64_ret_u32
push af, iy, bc, de, hl
call __dtoul_c
pop af, af, af, iy, af
pop af, af, bc, iy, af
ret

extern __dtoul_c
17 changes: 11 additions & 6 deletions src/crt/float64_to_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ uint64_t _dtoull_c(long double x) {
*/
#define HANDLE_INT_MIN 1

typedef struct f64_sign {
long double flt;
bool sign;
} f64_sign;

/**
* @note val must have the signbit cleared
*/
Expand Down Expand Up @@ -123,10 +128,10 @@ uint32_t _dtoul_c(long double x) {
return (uint32_t)f64_to_unsigned(val);
}

int64_t _dtoll_c(long double x) {
int64_t _dtoll_c(f64_sign arg) {
F64_pun val;
bool x_sign = signbit(x);
val.flt = fabsl(x);
bool x_sign = arg.sign;
val.flt = arg.flt;

/* overflow || isinf(x) || isnan(x) */
if (val.reg.BC >= ((Float64_bias + Float64_i64_max_exp) << Float64_exp_BC_shift)) {
Expand All @@ -145,10 +150,10 @@ int64_t _dtoll_c(long double x) {
return ret;
}

int32_t _dtol_c(long double x) {
int32_t _dtol_c(f64_sign arg) {
F64_pun val;
bool x_sign = signbit(x);
val.flt = fabsl(x);
bool x_sign = arg.sign;
val.flt = arg.flt;

/* overflow || isinf(x) || isnan(x) */
if (val.reg.BC >= ((Float64_bias + Float64_i32_max_exp) << Float64_exp_BC_shift)) {
Expand Down
6 changes: 0 additions & 6 deletions src/libc/ceill.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include <math.h>

#ifdef ceill
#undef ceill
#endif

long double ceill(long double x) {
if (signbit(x)) {
return truncl(x);
Expand All @@ -17,5 +13,3 @@ long double ceill(long double x) {
}
return x;
}

long double _debug_ceill(long double) __attribute__((alias("ceill")));
4 changes: 1 addition & 3 deletions src/libc/copysignl.src
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

section .text

public _copysignl, __debug_copysignl

__debug_copysignl:
public _copysignl
_copysignl:
ld hl, 19 ; upper 8 bits of y
add hl, sp
Expand Down
3 changes: 1 addition & 2 deletions src/libc/fabsl.src
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

section .text

public _fabsl, __debug_fabsl
public _fabsl

__debug_fabsl:
_fabsl:
pop iy, hl ,de, bc
push bc, de, hl
Expand Down
17 changes: 0 additions & 17 deletions src/libc/float64_rounding.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ long double roundevenl(long double x) {
return ret.flt;
}

#ifdef roundl
#undef roundl
#endif

long double roundl(long double x) {
F64_pun arg_x, ret;
arg_x.flt = x;
Expand Down Expand Up @@ -93,21 +89,13 @@ long long llroundl(long double x) {
}
#endif

#ifdef nearbyintl
#undef nearbyintl
#endif

long double nearbyintl(long double x) {
F64_pun arg_x, ret;
arg_x.flt = x;
ret.soft = f64_roundToInt(arg_x.soft, GET_FENV_SOFTFLOAT_ROUNDING(), false);
return ret.flt;
}

#ifdef rintl
#undef rintl
#endif

/* flags handled by softfloat */
long double rintl(long double x) {
F64_pun arg_x, ret;
Expand All @@ -129,8 +117,3 @@ long long llrintl(long double x) {
arg_x.flt = x;
return f64_to_i64(arg_x.soft, GET_FENV_SOFTFLOAT_ROUNDING(), true);
}

long double _debug_roundl(long double) __attribute__((alias("roundl")));
long double _debug_rintl(long double) __attribute__((alias("rintl")));
long double _debug_nearbyintl(long double) __attribute__((alias("nearbyintl")));

6 changes: 0 additions & 6 deletions src/libc/floorl.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include <math.h>

#ifdef floorl
#undef floorl
#endif

long double floorl(long double x) {
if (!signbit(x)) {
return truncl(x);
Expand All @@ -17,5 +13,3 @@ long double floorl(long double x) {
}
return x;
}

long double _debug_floorl(long double) __attribute__((alias("floorl")));
15 changes: 12 additions & 3 deletions src/libc/fmal.src
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

section .text

public _fmal, __debug_fmal
public _fmal

_fmal := _softfloat_mulAddF64
__debug_fmal := _softfloat_mulAddF64
_fmal:
; flags handled by softfloat
ld iy, 0
add iy, sp
ld a, (iy + 28)
rlca
ld (iy + 11), a ; signC
ld a, (iy + 10)
xor a, (iy + 19)
rlca
ld (iy + 20), a ; signZ
jq _softfloat_mulAddF64

extern _softfloat_mulAddF64
6 changes: 0 additions & 6 deletions src/libc/fmax.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ float fmaxf(float x, float y) {

double fmax(double, double) __attribute__((alias("fmaxf")));

#ifdef fmaxl
#undef fmaxl
#endif

long double fmaxl(long double x, long double y) {
return
isless(x, y) ? y :
Expand All @@ -27,5 +23,3 @@ long double fmaxl(long double x, long double y) {
/* arguments are equal or signed zero */
signbit(x) ? y : x;
}

long double _debug_fmaxl(long double, long double) __attribute__((alias("fmaxl")));
6 changes: 0 additions & 6 deletions src/libc/fmin.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ float fminf(float x, float y) {

double fmin(double, double) __attribute__((alias("fminf")));

#ifdef fminl
#undef fminl
#endif

long double fminl(long double x, long double y) {
return
isless(x, y) ? x :
Expand All @@ -27,5 +23,3 @@ long double fminl(long double x, long double y) {
/* arguments are equal or signed zero */
signbit(x) ? x : y;
}

long double _debug_fminl(long double, long double) __attribute__((alias("fminl")));
Loading
Loading