?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1.  ifndef included_xmul
  2.  define included_xmul
  3.  include "../common/pushpop.asm"
  4.  include "../common/mov.asm"
  5.  include "mul/mul64.asm"
  6.  include "routines/rl64.asm"
  7.  
  8. var_z=xOP3+16
  9. ;uses 60 bytes after xOP1
  10. xmul:
  11. ;Input:
  12. ;  HL points to one number
  13. ;  DE points to another
  14. ;Timing, excluding special cases (which take ~ 800cc):
  15. ;1057+{0,3}+{0,172}+mul64
  16. ;max: 1232+max(mul64)
  17. ;     11245cc
  18. ;min: 1057+min(mul64)
  19. ;     6688cc
  20. ;avg: 1144.5+avg(mul64)
  21. ;     9865.233ccs
  22.  
  23.  
  24.   push hl
  25.   push de
  26.   push bc
  27.   push af
  28.   push ix
  29.   push bc
  30.   call xmulpp;+_
  31.   pop hl
  32.   push de
  33.   ex de,hl
  34.   ld hl,var_z+8
  35.   call mov8
  36.   ex de,hl
  37.   pop de
  38.   ld (hl),e
  39.   inc hl
  40.   ld (hl),d
  41.   pop ix
  42.   pop af
  43.   pop bc
  44.   pop de
  45.   pop hl
  46.   ret
  47. xmulpp;_:
  48.   push de
  49.   ld de,xOP1
  50.   call mov10
  51.   pop hl
  52.   call mov10
  53.         ld de,(xOP2+8)
  54.         ld hl,(xOP1+8)
  55. xmul_stepin_geomean:
  56.         ld a,h
  57.         xor d
  58.   ld b,a
  59.         res 7,d
  60.         res 7,h
  61.         ld a,h : or l : jp z,casemul
  62.         ld a,d : or e : jp z,casemul2
  63.   add hl,de
  64.   ld de,$4000
  65.   sbc hl,de
  66.   jp c,mul_zero
  67.   jp m,mul_inf
  68.   sla b
  69.   jr nc,$+4;+_
  70.   set 7,h
  71. ;_:
  72.   push hl
  73.         call mul64
  74.   ld a,(var_z+15)
  75.   add a,a
  76.   pop de
  77.   jr c,xmul_incderet;+_
  78.  ifdef inc_FMA
  79.   ld hl,var_z
  80.   call rl64
  81.  else
  82.   ld hl,var_z+7
  83.   sla (hl)
  84.  endif
  85.   inc hl
  86.   jp rl64
  87.  
  88. xmul_incderet;_:
  89.   inc de
  90.   ret
  91.  
  92. casemul:
  93. ;xOP1 is inf/nan/0
  94.   ld hl,xOP2+9
  95.   ld a,(hl)
  96.   and $7F
  97.   dec hl
  98.   or (hl)
  99.   dec hl
  100.   ld a,(hl)
  101.   ld hl,xOP1
  102.   jr nz,casemul2_copy
  103.   ;now we have two special cases to multipy together
  104. ;inf*inf-> inf
  105. ;0*0    -> 0
  106. ;
  107. ;nan*nan-> NaN
  108. ;inf*nan-> NaN
  109. ;inf*0  -> NaN
  110. ;nan*inf-> NaN
  111. ;nan*0  -> NaN
  112. ;0*inf  -> NaN
  113. ;0*nan  -> NaN
  114.  
  115.   sla b
  116.   ld de,0
  117.   rr d
  118.   and $C0
  119.   ld c,a
  120.   ld a,(xOP1+7)
  121.   and $C0
  122.   cp c
  123.   jr z,$+4;+_
  124.   ld a,$40
  125. ;_:
  126.   ld (var_z+15),a
  127.   ret
  128. casemul2:
  129. ;finite times inf/nan/0, so xOP2 -> out
  130.   ld hl,xOP2
  131. casemul2_copy:
  132.   ld de,var_z+8
  133.   call mov8
  134.   ld e,(hl)
  135.   inc hl
  136.   ld d,(hl)
  137.   ret
  138. mul_zero:
  139.   xor a
  140.   ld (var_z+15),a
  141.   ld d,a
  142.   ret
  143. mul_inf:
  144.   ld d,e
  145.   ld a,255
  146.   ld (var_z+15),a
  147.   ret
  148.  endif
  149.