Skip to content

Commit 079f70b

Browse files
committed
Optimized softfloat by precalculating signbit
1 parent c9b82ff commit 079f70b

File tree

14 files changed

+158
-70
lines changed

14 files changed

+158
-70
lines changed

src/crt/ddiv.src

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,23 @@
44

55
public __ddiv
66

7-
; float64_t f64_div(float64_t, const float64_t*)
7+
; float64_t f64_div(bool, float64_t, const float64_t*)
88
__ddiv:
99
push af, iy
1010
ld iy, 9
11-
add iy, sp
11+
add iy, sp
12+
1213
push iy, bc, de, hl
14+
15+
ld a, b ; signbit(x)
16+
xor a, (iy + 7) ; signbit(y)
17+
rla
18+
push af ; Carry = (signbit(x) != signbit(y))
19+
1320
call _f64_div
14-
pop af, af, af, af, iy, af
21+
22+
pop af, af, af, af, af
23+
pop iy, af ; restore
1524
ret
1625

1726
extern _f64_div

src/crt/dmul.src

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,23 @@
44

55
public __dmul
66

7-
; float64_t f64_mul(float64_t, const float64_t*)
7+
; float64_t f64_mul(bool, float64_t, const float64_t*)
88
__dmul:
99
push af, iy
1010
ld iy, 9
11-
add iy, sp
11+
add iy, sp
12+
1213
push iy, bc, de, hl
14+
15+
ld a, b ; signbit(x)
16+
xor a, (iy + 7) ; signbit(y)
17+
rla
18+
push af ; Carry = (signbit(x) != signbit(y))
19+
1320
call _f64_mul
14-
pop af, af, af, af, iy, af
21+
22+
pop af, af, af, af, af
23+
pop iy, af ; restore
1524
ret
1625

1726
extern _f64_mul

src/crt/drem.src

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@
44

55
public __drem
66

7-
; float64_t f64_rem(float64_t, const float64_t*)
7+
; float64_t f64_rem(bool, float64_t, const float64_t*)
88
__drem:
99
push af, iy
1010
ld iy, 9
1111
add iy, sp
1212
push iy, bc, de, hl
13+
14+
rl b
15+
push af ; Carry = signbit(x)
16+
1317
call _f64_rem
14-
pop af, af, af, af, iy, af
18+
19+
pop af, af, af, af, af
20+
pop iy, af ; restore
1521
ret
1622

1723
extern _f64_rem

src/libc/fmal.src

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@
44

55
public _fmal, __debug_fmal
66

7-
_fmal := _softfloat_mulAddF64
8-
__debug_fmal := _softfloat_mulAddF64
7+
_fmal:
8+
__debug_fmal:
99
; flags handled by softfloat
10+
ld iy, 0
11+
add iy, sp
12+
ld a, (iy + 28)
13+
rlca
14+
ld (iy + 11), a ; signC
15+
ld a, (iy + 10)
16+
xor a, (iy + 19)
17+
rlca
18+
ld (iy + 20), a ; signZ
19+
jq _softfloat_mulAddF64
1020

1121
extern _softfloat_mulAddF64

src/libc/fmodl.c

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/libc/fmodl.src

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
assume adl = 1
2+
3+
section .text
4+
5+
public _fmodl
6+
7+
_fmodl:
8+
call __frameset0
9+
10+
pea ix + 15 ; &y
11+
12+
ld hl, (ix + 12)
13+
push hl ; x[63:48]
14+
15+
ld hl, (ix + 9)
16+
push hl ; x[47:24]
17+
18+
ld hl, (ix + 6)
19+
push hl ; x[23:0]
20+
21+
ld a, h
22+
rla
23+
push af ; Carry = signbit(x)
24+
25+
call _f64_rem
26+
ld sp, ix
27+
pop ix
28+
ret
29+
30+
extern _f64_rem
31+
extern __frameset0

src/libc/sqrtl.src

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
section .text
44

55
public _sqrtl
6-
_sqrtl := _f64_sqrt
6+
7+
_sqrtl:
78
; flags handled by softfloat
9+
ld hl, 10
10+
add hl, sp
11+
ld a, (hl)
12+
rlca
13+
inc hl
14+
ld (hl), a
15+
jq _f64_sqrt
816

917
extern _f64_sqrt

src/softfloat/f64_div.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4141
#include "specialize.h"
4242
#include "softfloat.h"
4343

44-
float64_t f64_div( float64_t a, const float64_t *b )
44+
float64_t f64_div( bool signZ, float64_t a, float64_t *__restrict b )
4545
{
4646
union ui64_f64 uA;
4747
uint_fast64_t uiA;
48-
bool signA;
48+
// bool signA;
4949
int_fast16_t expA;
5050
uint_fast64_t sigA;
5151
union ui64_f64 uB;
5252
uint_fast64_t uiB;
53-
bool signB;
53+
// bool signB;
5454
int_fast16_t expB;
5555
uint_fast64_t sigB;
56-
bool signZ;
56+
// bool signZ;
5757
struct exp16_sig64 normExpSig;
5858
int_fast16_t expZ;
5959
uint32_t recip32, sig32Z, doubleTerm;
@@ -67,15 +67,15 @@ float64_t f64_div( float64_t a, const float64_t *b )
6767
*------------------------------------------------------------------------*/
6868
uA.f = a;
6969
uiA = uA.ui;
70-
signA = signF64UI( uiA );
70+
// signA = signF64UI( uiA );
7171
expA = expF64UI( uiA );
7272
sigA = fracF64UI( uiA );
7373
uB.f = *b;
7474
uiB = uB.ui;
75-
signB = signF64UI( uiB );
75+
// signB = signF64UI( uiB );
7676
expB = expF64UI( uiB );
7777
sigB = fracF64UI( uiB );
78-
signZ = signA ^ signB;
78+
// signZ = signA ^ signB;
7979
/*------------------------------------------------------------------------
8080
*------------------------------------------------------------------------*/
8181
if ( expA == 0x7FF ) {

src/softfloat/f64_mul.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4141
#include "specialize.h"
4242
#include "softfloat.h"
4343

44-
float64_t f64_mul( float64_t a, const float64_t *b )
44+
float64_t f64_mul( bool signZ, float64_t a, float64_t *__restrict b )
4545
{
4646
union ui64_f64 uA;
4747
uint_fast64_t uiA;
48-
bool signA;
48+
// bool signA;
4949
int_fast16_t expA;
5050
uint_fast64_t sigA;
5151
union ui64_f64 uB;
5252
uint_fast64_t uiB;
53-
bool signB;
53+
// bool signB;
5454
int_fast16_t expB;
5555
uint_fast64_t sigB;
56-
bool signZ;
56+
// bool signZ;
5757
uint_fast64_t magBits;
5858
struct exp16_sig64 normExpSig;
5959
int_fast16_t expZ;
@@ -69,15 +69,15 @@ float64_t f64_mul( float64_t a, const float64_t *b )
6969
*------------------------------------------------------------------------*/
7070
uA.f = a;
7171
uiA = uA.ui;
72-
signA = signF64UI( uiA );
72+
// signA = signF64UI( uiA );
7373
expA = expF64UI( uiA );
7474
sigA = fracF64UI( uiA );
7575
uB.f = *b;
7676
uiB = uB.ui;
77-
signB = signF64UI( uiB );
77+
// signB = signF64UI( uiB );
7878
expB = expF64UI( uiB );
7979
sigB = fracF64UI( uiB );
80-
signZ = signA ^ signB;
80+
// signZ = signA ^ signB;
8181
/*------------------------------------------------------------------------
8282
*------------------------------------------------------------------------*/
8383
if ( expA == 0x7FF ) {

src/softfloat/f64_rem.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4141
#include "specialize.h"
4242
#include "softfloat.h"
4343

44-
float64_t f64_rem( float64_t a, const float64_t *b )
44+
float64_t f64_rem( bool signA, float64_t a, float64_t *__restrict b )
4545
{
4646
union ui64_f64 uA;
4747
uint_fast64_t uiA;
48-
bool signA;
48+
// bool signA;
4949
int_fast16_t expA;
5050
uint_fast64_t sigA;
5151
union ui64_f64 uB;
@@ -66,7 +66,7 @@ float64_t f64_rem( float64_t a, const float64_t *b )
6666
*------------------------------------------------------------------------*/
6767
uA.f = a;
6868
uiA = uA.ui;
69-
signA = signF64UI( uiA );
69+
// signA = signF64UI( uiA );
7070
expA = expF64UI( uiA );
7171
sigA = fracF64UI( uiA );
7272
uB.f = *b;

0 commit comments

Comments
 (0)