Skip to content

Commit 6c118b7

Browse files
authored
Fix DNRM2 returning INF instead of zero due to intermediate overflow
1 parent c43ec53 commit 6c118b7

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

kernel/power/nrm2.S

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
#define FZERO 144(SP)
5151
#define FONE 148(SP)
5252
#define FMAX 152(SP)
53-
54-
#define STACKSIZE 160
53+
#define FINF 160(SP)
54+
#define STACKSIZE 168
5555

5656
PROLOGUE
5757
PROFCODE
@@ -87,6 +87,16 @@
8787
stw r10, FZERO
8888
stw r11, FONE
8989
stw r12, FMAX
90+
91+
#ifdef DOUBLE
92+
lis r12, 0x7ff0
93+
ori r12, r12, 0x0
94+
sldi r12, r12, 32
95+
oris r12, r12,0x0
96+
ori r12, r12, 0x0
97+
std r12, FINF
98+
#endif
99+
90100
stw r10, 4 + FMAX
91101

92102
lfs f1, FZERO
@@ -334,10 +344,17 @@ LL(100):
334344
lfs f0, FONE
335345

336346
fcmpu cr0, f1, f31
347+
nop
337348
beq- cr0, LL(9999)
338-
339349
fdiv f30, f0, f31
340350

351+
#ifdef DOUBLE
352+
lfd f1, FINF
353+
fcmpu cr0, f1, f30
354+
lfs f1, FZERO
355+
beq- cr0, LL(9999)
356+
#endif
357+
341358
fmr f0, f1
342359
fmr f2, f1
343360
fmr f3, f1
@@ -712,9 +729,16 @@ LL(1999):
712729

713730
fcmpu cr0, f1, f31
714731
beq- cr0, LL(9999)
715-
732+
716733
fdiv f30, f0, f31
717734

735+
#ifdef DOUBLE
736+
lfd f1, FINF
737+
fcmpu cr0, f1, f30
738+
lfs f1, FZERO
739+
beq- cr0, LL(9999)
740+
#endif
741+
718742
fmr f0, f1
719743
fmr f2, f1
720744
fmr f3, f1
@@ -875,6 +899,7 @@ LL(2170):
875899
fadd f0, f0, f4
876900

877901
fsqrt f0, f0
902+
878903
fmul f1, f31, f0
879904
.align 4
880905

0 commit comments

Comments
 (0)