?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1.  ifndef included_xpow2
  2.  define included_xpow2
  3.  include "../common/pushpop.asm"
  4.  include "../common/mov.asm"
  5.  include "routines/sla64.asm"
  6.  include "routines/normalizexOP1.asm"
  7.  include "constantsx.asm"
  8.  include "xmul.asm"
  9.  include "xadd.asm"
  10.  
  11. xexp_x=xOP3+42
  12. ;use range reduction to get x on [0,1]
  13. ;Then use the formula:
  14. ;2^x ~ 1+x(p1+x(p2+...+x(p11+x*p12)...))
  15.  
  16. caseexp:
  17. exp_too_big:
  18.   pop de
  19.   ret
  20.  
  21. xpow2:
  22.   call pushpop
  23.   push bc
  24.   ld de,xOP1
  25.   call mov10
  26.   ld hl,(xOP1+8)
  27.   res 7,h
  28.   ld a,h
  29.   or l
  30.   jr z,caseexp
  31.   ;If HL<3FF3 or HL>=400E, then magnitudes are too high
  32.   ld bc,-$3EF3
  33.   add hl,bc
  34.   dec h
  35.   jr nz,exp_too_big
  36.   ld a,l
  37.   cp 27
  38.   jr nc,exp_too_big
  39. ;Now we know the exponent isn't too big
  40. ;
  41. ;Range Reduction phase
  42. ;e=int(x+.5)
  43. ;x-=e
  44. ;now we compute 2^e*2^x, where e is an integer
  45.   ld de,0
  46.   sub 13
  47.   inc a
  48.   jr c,xexp_ipart0
  49.   ld b,a
  50.   ;now we need to shift bits in from the mantissa!
  51. xpow2rl0;_:
  52.   call sla64_xOP1
  53.   rl e : rl d
  54.   djnz xpow2rl0;-_
  55.   ld a,(xOP1+9)
  56.   add a,a
  57.   ld hl,$3FFF
  58.   jr nc,xpow2p;+_
  59.   xor a : sub e : ld e,a
  60.   sbc a,a : sub d : ld d,a
  61.   ld h,$BF
  62. xpow2p;_:
  63.   ld (xOP1+8),hl
  64.   call normalizexOP1
  65. xexp_ipart0:
  66. ;!!!! Future Zeda, investigate! I think this should actually be fine on (-1,1) :O
  67. ;!!!! If not, we'll need to check if the input is negative, add 1, decrement DE
  68.   push de
  69.   ld hl,xOP1
  70.   ld de,xexp_x
  71.   call mov10
  72.   ld hl,xOP1
  73.   ld b,h
  74.   ld c,l
  75.   ld de,xexp_p12
  76.   call xmul
  77.   ld de,xexp_p11 : call xpow2addmul;+_
  78.   ld de,xexp_p10 : call xpow2addmul;+_
  79.   ld de,xexp_p9 : call xpow2addmul;+_
  80.   ld de,xexp_p8 : call xpow2addmul;+_
  81.   ld de,xexp_p7 : call xpow2addmul;+_
  82.   ld de,xexp_p6 : call xpow2addmul;+_
  83.   ld de,xexp_p5 : call xpow2addmul;+_
  84.   ld de,xexp_p4 : call xpow2addmul;+_
  85.   ld de,xexp_p3 : call xpow2addmul;+_
  86.   ld de,xexp_p2 : call xpow2addmul;+_
  87.   ld de,xexp_p1 : call xpow2addmul;+_
  88.   ld de,xconst_1 : call xadd
  89.   pop de
  90.   ;now I need to add DE as a signed integer to the exponent
  91.   ld hl,(xOP1+8)
  92.   add hl,de
  93.   ld (xOP1+8),hl
  94.   pop de
  95.   ld h,b
  96.   ld l,c
  97.   jp mov10
  98. xpow2addmul;_:
  99.   call xadd
  100.   ld de,xexp_x
  101.   jp xmul
  102. xexp_p1:
  103. xexp_p2 = xexp_p1+10
  104. xexp_p3 = xexp_p1+20
  105. xexp_p4 = xexp_p1+30
  106. xexp_p5 = xexp_p1+40
  107. xexp_p6 = xexp_p1+50
  108. xexp_p7 = xexp_p1+60
  109. xexp_p8 = xexp_p1+70
  110. xexp_p9 = xexp_p1+80
  111. xexp_p10= xexp_p1+90
  112. xexp_p11= xexp_p1+100
  113. xexp_p12= xexp_p1+110
  114.  db $A2,$78,$CF,$D1,$F7,$17,$72,$B1,$FF,$3F    ;0.6931471805599452949907356518859092751897692718065
  115.  db $99,$67,$2D,$16,$FC,$EF,$FD,$F5,$FD,$3F    ;0.240226506959101553103846007431060297021429734606215
  116.  db $10,$CD,$AF,$24,$B8,$46,$58,$E3,$FB,$3F    ;5.55041086648024431020190322727610690536837023045e-2
  117.  db $F8,$78,$4B,$E2,$7D,$5B,$95,$9D,$F9,$3F    ;9.6181291078536164406046473880520178751949899000523e-3
  118.  db $5B,$9D,$F3,$DF,$38,$FF,$C3,$AE,$F6,$3F    ;1.33335581307383609544222238286864444825050937393667e-3
  119.  db $A4,$71,$3C,$26,$F7,$89,$84,$A1,$F3,$3F    ;1.540353109220040892607797490525175686435054921034e-4
  120.  db $BC,$AB,$25,$27,$57,$E7,$E5,$FF,$EF,$3F    ;1.5252713038026820986694573437398168701085442050318e-5
  121.  db $66,$AE,$E1,$25,$E7,$82,$61,$B1,$EC,$3F    ;1.32159071914904607697946887057043728604916889120466e-6
  122.  db $FA,$40,$26,$7A,$19,$AD,$72,$DA,$E8,$3F    ;1.01722755371157108831058054858407530634720014307972e-7
  123.  db $5F,$A3,$56,$C8,$B3,$E2,$40,$F4,$E4,$3F    ;7.1087112650916814301740895279260149232576576809875e-9
  124.  db $8C,$EE,$B8,$06,$1D,$21,$F6,$E2,$E0,$3F    ;4.1284045941236206883307640217911126100813512882446e-10
  125.  db $3E,$73,$CA,$31,$87,$36,$5F,$9F,$DD,$3F    ;3.6236980527707885031220529305671221862606493025011e-11
  126.  
  127. ;#undefine xexp_x
  128.  endif
  129.