home *** CD-ROM | disk | FTP | other *** search
/ The Equalizer BBS / equalizer-bbs-collection_2004.zip / equalizer-bbs-collection / DEMOSCENE-STUFF / BUDYN1.ZIP / FASTDIV.ZIP / FASTDIV.IN3
Text File  |  1996-05-28  |  3KB  |  101 lines

  1. ;Fast Div Macro by Ozir/Hypnotize. Remember that eax&ebx are single (-128;127)
  2. ;┌───────────────────────────────────────────────────────────────────────────┐
  3. ;│ Fast Div Init                                                             │
  4. ;└───────────────────────────────────────────────────────────────────────────┘
  5. FastDivInit:       mov eax,65536*4
  6.                    call _getHiMem
  7.                    mov FastDivOff,eax
  8.  
  9.                    ;first table (+)
  10.                    mov ebp,FastDivOff
  11.                    xor ecx,ecx
  12.                    mov esi,0
  13. FastDivY1:         mov edi,0
  14. FastDivX1:         mov eax,esi
  15.                    shl eax,16
  16.                    cdq
  17.                    cmp edi,0
  18.                    je FastDivZeroM1
  19.                    idiv edi
  20. FastDivZeroM1:     mov [ebp],eax
  21.                    add ebp,4
  22.                    inc ecx
  23.                    inc edi
  24.                    cmp edi,128
  25.                    jne FastDivX1
  26.                    mov edi,-128
  27. FastDivXX1:        mov eax,esi
  28.                    shl eax,16
  29.                    cdq
  30.                    cmp edi,0
  31.                    je FastDivZeroW1
  32.                    idiv edi
  33. FastDivZeroW1:     mov [ebp],eax
  34.                    add ebp,4
  35.                    inc ecx
  36.                    inc edi
  37.                    cmp edi,0
  38.                    jne FastDivXX1
  39.                    inc esi
  40.                    cmp esi,128
  41.                    jne FastDivY1
  42.  
  43.                    ;second table (-)
  44.                    mov ebp,FastDivOff
  45.                    add ebp,32768*4
  46.                    xor ecx,ecx
  47.                    mov esi,-128
  48. FastDivY2:         mov edi,0
  49. FastDivX2:         mov eax,esi
  50.                    shl eax,16
  51.                    cdq
  52.                    cmp edi,0
  53.                    je FastDivZeroM2
  54.                    idiv edi
  55. FastDivZeroM2:     mov [ebp],eax
  56.                    add ebp,4
  57.                    inc ecx
  58.                    inc edi
  59.                    cmp edi,128
  60.                    jne FastDivX2
  61.                    mov edi,-128
  62. FastDivXX2:        mov eax,esi
  63.                    shl eax,16
  64.                    cdq
  65.                    cmp edi,0
  66.                    je FastDivZeroW2
  67.                    idiv edi
  68. FastDivZeroW2:     mov [ebp],eax
  69.                    add ebp,4
  70.                    inc ecx
  71.                    inc edi
  72.                    cmp edi,0
  73.                    jne FastDivXX2
  74.                    inc esi
  75.                    cmp esi,0
  76.                    jne FastDivY2
  77.                    ret
  78.  
  79. FastDivOff         dd 0
  80.  
  81.  
  82. ;┌───────────────────────────────────────────────────────────────────────────┐
  83. ;│ Fast Div Macro                                                            │
  84. ;└───────────────────────────────────────────────────────────────────────────┘
  85. ;                |
  86. ;  in:eax,ebx    | in:eax,ebx
  87. ; ---------------|--------------
  88. ;  shl eax,16    | FastDiv
  89. ;  cdq           |
  90. ;  idiv ebx      |
  91. ; ---------------|--------------
  92. ;  48 cycles     | 18 cycles
  93.  
  94. FastDiv            macro
  95.                    mov bh,al
  96.                    movzx ebx,bx
  97.                    shl ebx,2
  98.                    add ebx,FastDivOff
  99.                    mov eax,[ebx]
  100.                    endm
  101.