Stop inlining code to convert integers to floats.

Do the conversion by calling .cif8 or .cuf8 in libem, as it was done
before my commit 1de1e8f.  I used the inline conversion to experiment
with the register allocator, which was too slow until c5bb3be.

Now that libem has the only copy of the code, move some comments and
code changes there.
This commit is contained in:
George Koehler 2017-10-17 17:00:28 -04:00
parent 893e170015
commit 47bd0ef7a7
3 changed files with 31 additions and 66 deletions

View file

@ -8,25 +8,24 @@
.define .cif8 .define .cif8
.cif8: .cif8:
addi sp, sp, -4 ! make space for the double ! Conversion uses the pivot value
! 1 << 52 = 0x4330 0000 0000 0000
!
! From signed integer i, we compute
! ((1 << 52) + (1 << 31) + i) - ((1 << 52) + (1 << 31))
lis r3, 0x4330
stwu r3, -4(sp) ! make space for the double
lwz r3, 4(sp) lwz r3, 4(sp)
xoris r3, r3, 0x8000 xoris r3, r3, 0x8000
stw r3, 4(sp) ! flip sign of integer value stw r3, 4(sp) ! flip sign bit to get (1 << 31) + i
addis r3, r0, 0x4330 lfd f0, 0(sp) ! f0 = (1 << 52) + (1 << 31) + i
stw r3, 0(sp) ! set high word to construct a double lis r3, 0x8000
stw r3, 4(sp)
lfd f0, 0(sp) ! load value lfd f1, 0(sp) ! f1 = (1 << 52) + (1 << 31)
fsub f0, f0, f1 ! finish conversion
lis r3, ha16[pivot]
lfd f1, lo16[pivot](r3) ! load pivot value
fsub f0, f0, f1 ! adjust
stfd f0, 0(sp) ! save value again... stfd f0, 0(sp) ! save value again...
blr ! ...and return blr ! ...and return
.sect .rom
pivot:
.data4 0x43300000
.data4 0x80000000

View file

@ -6,21 +6,20 @@
.define .cuf8 .define .cuf8
.cuf8: .cuf8:
addi sp, sp, -4 ! make space for the double ! Conversion uses the pivot value
! 1 << 52 = 0x4330 0000 0000 0000
!
! From unsigned integer u, we compute
! ((1 << 52) + u) - (1 << 52)
lis r3, 0x4330 lis r3, 0x4330
stw r3, 0(sp) ! set high word to construct a double stwu r3, -4(sp) ! make space for the double
lfd f0, 0(sp) ! load value lfd f0, 0(sp) ! f0 = (1 << 52) + u
li r3, 0x0000
lis r3, ha16[pivot] stw r3, 4(sp)
lfd f1, lo16[pivot](r3) ! load pivot value lfd f1, 0(sp) ! f1 = (1 << 52)
fsub f0, f0, f1 ! adjust fsub f0, f0, f1 ! finish conversion
stfd f0, 0(sp) ! save value again... stfd f0, 0(sp) ! save value again...
blr ! ...and return blr ! ...and return
.sect .rom
pivot:
.data4 0x43300000
.data4 0x00000000

View file

@ -2353,48 +2353,15 @@ PATTERNS
leaving leaving
cal ".cfu8" cal ".cfu8"
/* /* Convert signed int to double */
* To convert integer to IEEE double, we pack the integer in
* the low bits of the magic double
* 1 << 52 == 0x 4330 0000 0000 0000
*
* For signed integer i, we flip its sign bit, then compute
* ((1 << 52) + i) - ((1 << 52) + (1 << 31))
*/
pat loc loc cif $1==4 && $2==8 pat loc loc cif $1==4 && $2==8
with REG leaving
uses reusing %1, REG={XOR_RIS, %1, 0x8000}, cal ".cif8"
REG={CONST_HZ, 0x43300000},
REG={CONST_HZ, 0x80000000},
FREG, FREG
gen
stwu %b, {IND_RC_W, sp, 0-8}
stw %a, {IND_RC_W, sp, 4}
lfd %d, {IND_RC_D, sp, 0}
stw %c, {IND_RC_W, sp, 4}
lfd %e, {IND_RC_D, sp, 0}
fsub %d, %d, %e
addi sp, sp, {CONST, 8}
yields %d
/* /* Convert unsigned int to double */
* To convert unsigned integer u to IEEE double, we compute
* ((1 << 52) + u) - (1 << 52)
*/
pat loc loc cuf $1==4 && $2==8 pat loc loc cuf $1==4 && $2==8
with REG leaving
uses REG={CONST_HZ, 0x43300000}, cal ".cuf8"
REG={CONST_0000_7FFF, 0},
FREG, FREG
gen
stwu %a, {IND_RC_W, sp, 0-8}
stw %1, {IND_RC_W, sp, 4}
lfd %c, {IND_RC_D, sp, 0}
stw %b, {IND_RC_W, sp, 4}
lfd %d, {IND_RC_D, sp, 0}
fsub %c, %c, %d
addi sp, sp, {CONST, 8}
yields %c
pat fef $1==8 /* Split fraction, exponent */ pat fef $1==8 /* Split fraction, exponent */
leaving leaving