?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. #ifndef included_f32tof64
  2. #define included_f32tof64
  3. #include "pushpop.z80"
  4.  
  5. ;bias is 1023, so 0x03FF is exponent of 0
  6. ;sign is 1 bit
  7. ;exponent is 11 bits
  8. ;mantissa is 53 bits (top bit is implicit)
  9.  
  10.  
  11. f32tof64:
  12. ;convert an IEEE-754 binary32 to an IEEE-754 binary64 float.
  13. ;Input: HL points to the input float, BC points to where to output
  14. ;Destroys: None
  15.   call pushpop
  16.   xor a
  17.   ld (bc),a
  18.   inc bc
  19.   ld (bc),a
  20.   inc bc
  21.   ld (bc),a
  22.   inc bc
  23.  
  24.   ld e,(hl)
  25.   inc hl
  26.   ld d,(hl)
  27.   inc hl
  28.   ld a,(hl)
  29.   inc hl
  30.   ld h,(hl)
  31.   ld l,a
  32.   ex de,hl
  33. ; The float is in DEHL
  34.   ld a,e
  35.   add a,a
  36.   ld a,d
  37.   adc a,a
  38.   jr z,f32tof64_zero
  39.   inc a
  40.   jr z,f32tof64_infnan
  41.  
  42.   ; to the exponent, substract 127 and add 1023 for a net of +896
  43.   ld a,%01100000
  44.   add hl,hl
  45.   rl e
  46.   rl d
  47.   rla           ;1110000s + 0
  48.   rla           ;110000s0 + 0
  49.   rla           ;10000s00 + 1
  50.   rla           ;0000s000 + 3
  51.   add hl,hl
  52.   rl e
  53.   rl d
  54.   rla           ;000s000e + 6
  55.   inc a         ;000s000e + 7
  56.   add hl,hl
  57.   rl e
  58.   rl d
  59.   rla           ;00s000ee + 14
  60.   add hl,hl
  61.   rl e
  62.   rl d
  63.   rla           ;0s000eee + 28
  64.   add hl,hl
  65.   rl e
  66.   rl d
  67.   rla           ;s000eeee + 56
  68.  
  69.  
  70.   push hl
  71.   ld h,b
  72.   ld l,c
  73.   pop bc
  74.   ld (hl),c
  75.   inc hl
  76.   ld (hl),b
  77.   inc hl
  78.   ld (hl),e
  79.   inc hl
  80.   ld (hl),d
  81.   inc hl
  82.   ld (hl),a
  83.   ret
  84.  
  85. f32tof64_zero:
  86.   ld (bc),a
  87.   inc bc
  88.   ld (bc),a
  89.   inc bc
  90.   ld (bc),a
  91.   inc bc
  92.   ld (bc),a
  93.   inc bc
  94.   rra
  95.   ld (bc),a
  96.   ret
  97.  
  98. f32tof64_infnan:
  99.   xor a
  100.   ld (bc),a
  101.   inc bc
  102.   ld (bc),a
  103.   inc bc
  104.   ld a,e
  105.   add a,a
  106.   or h
  107.   or l
  108.   ld (bc),a
  109.   inc bc
  110.   or %11110000
  111.   ld (bc),a
  112.   inc bc
  113.   ld a,d
  114.   or %01111111
  115.   ld (bc),a
  116.   ret
  117. #endif
  118.