?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1.  ifndef included_xdiv
  2.  define included_xdiv
  3.  include "../common/mov.asm"
  4.  include "div/div64.asm"
  5.  include "routines/cmp64.asm"
  6.  
  7. var_q=xOP1
  8. var_x=xOP2
  9. var_n=xOP3
  10. xdiv:
  11. ;597+{0,220+{0,6}}+{0,3}+div64+cmp64+mov8+2*mov10
  12. ;1075+{0,220+{0,6}}+{0,3}+div64+cmp64
  13. ;min: 1075+div64+cmp64
  14. ;     7800cc
  15. ;max: 1532+div64
  16. ;     13001cc
  17. ;avg: 1075+{0,220+{0,6}}+{0,3}+div64+cmp64
  18. ;     10971.151cc
  19.   push hl
  20.   push de
  21.   push bc
  22.   push af
  23.   push ix
  24.   push bc
  25.   call xdivpp;+_
  26.   ex (sp),hl
  27.   ex de,hl
  28.   ld hl,var_q
  29.   call mov8
  30.   ex de,hl
  31.   pop de
  32.   ld (hl),e
  33.   inc hl
  34.   ld (hl),d
  35.   pop ix
  36.   pop af
  37.   pop bc
  38.   pop de
  39.   pop hl
  40.   ret
  41. xdivpp;_:
  42.   push hl
  43.   ex de,hl
  44.   ld de,xOP2    ;denom
  45.   call mov10
  46.   pop hl
  47.   call mov10
  48.         ld hl,(xOP3+8) ;numer
  49.         ld de,(xOP2+8) ;denom
  50.         ld a,h
  51.         xor d
  52. ;save the sign
  53.   push af
  54.  
  55.         res 7,d
  56.         res 7,h
  57.         ld a,h : or l : jp z,casediv
  58.         ld a,d : or e : jp z,casediv2
  59.   ld bc,$3FFF
  60.   add hl,bc
  61.   sbc hl,de
  62.   jp z,div_zero
  63.   jp c,div_zero
  64.   jp m,div_inf
  65.   ;HL is the new exponent
  66.   push hl
  67. ;Need to verify that mantissa var_n<var_x
  68.   ld de,var_n+7
  69.   ld hl,var_x+7
  70.   call cmp64
  71.   jr c,xdiv_nlessx;+_
  72.   pop hl
  73.   inc l
  74.   jr nz,$+5
  75.   inc h
  76.   jr z,div_zero
  77.   push hl
  78.   ld hl,var_n+7
  79.   srl (hl) : dec hl
  80.   rr (hl) : dec hl
  81.   rr (hl) : dec hl
  82.   rr (hl) : dec hl
  83.   rr (hl) : dec hl
  84.   rr (hl) : dec hl
  85.   rr (hl) : dec hl
  86.   rr (hl)
  87. xdiv_nlessx;_:
  88.   call div64
  89.   pop hl
  90.   sla h
  91.   pop af
  92.   add a,a
  93.   rr h  
  94.   ret
  95. div_zero:
  96.   xor a
  97.   ld (xOP1+7),a
  98.   ld l,a
  99.   pop bc
  100.   sla b
  101.   rra
  102.   ld h,a
  103.   ret
  104. div_inf:
  105.   ld hl,0
  106.   ld a,-1
  107.   ld (xOP1+7),a
  108.   pop bc
  109.   sla b
  110.   rr h
  111.   ret
  112. casediv:
  113. ;0/0   ==> NaN
  114. ;0/NaN ==> NaN
  115. ;0/x ==> 0
  116. ;inf/NaN ==> NaN
  117. ;inf/inf ==> NaN
  118. ;inf/x ==> inf
  119. ;NaN/x  ==> NaN
  120.  
  121.   ld a,(xOP3+7)
  122.   and $C0
  123.   ld a,d
  124.   jr z,casediv_0
  125.   jp p,div_NaN
  126. ;inf/NaN ==> NaN
  127. ;inf/inf ==> NaN
  128. ;inf/x ==> inf
  129.   or e
  130.   jr nz,div_inf
  131.   ld a,(xOP2+7)
  132.   and $C0
  133.   jr z,div_inf
  134.   jr div_NaN
  135.  
  136. casediv_0:
  137. ;0/0   ==> NaN
  138. ;0/NaN ==> NaN
  139. ;0/x ==> 0
  140.   or e
  141.   jr nz,div_zero
  142.   ld a,(xOP2+7)
  143.   and $C0
  144.   jp m,div_zero
  145.   jr div_NaN
  146. casediv2:
  147. ;x/0   -> inf
  148. ;x/inf -> 0
  149. ;x/NaN -> NaN
  150.   ld a,(xOP2+7)
  151.   and $C0
  152.   jr z,div_inf
  153.   jp m,div_zero
  154. div_NaN:
  155.   pop bc
  156.   ld hl,0
  157.   ld a,$40
  158.   ld (xOP1+7),a
  159.   ret
  160.  endif
  161.