| 1 |
/* i386 assembly routines for inner loop fraction routines in Metafont |
| 2 |
and MetaPost. Included from texmfmp.c. By Wayne Sullivan |
| 3 |
<[email protected]>. */ |
| 4 |
|
| 5 |
/* |
| 6 |
Converted to inline assembler for Visual C++ [45].xx |
| 7 |
by Fabrice Popineau <[email protected]> */ |
| 8 |
|
| 9 |
__declspec(naked) fraction __stdcall ztakefraction(integer p, integer q) { |
| 10 |
__asm { |
| 11 |
push ebp |
| 12 |
mov ebp,esp |
| 13 |
xor ecx,ecx |
| 14 |
mov eax, p |
| 15 |
; mov eax, [ebp+8] |
| 16 |
cmp eax, 0x80000000 |
| 17 |
jz LL5 |
| 18 |
imul q |
| 19 |
or edx,edx |
| 20 |
jns LL2 |
| 21 |
neg edx |
| 22 |
neg eax |
| 23 |
sbb edx, ecx |
| 24 |
inc ecx |
| 25 |
LL2: |
| 26 |
add eax, 0x08000000 |
| 27 |
adc edx, 0 |
| 28 |
cmp edx, 0x07ffffff |
| 29 |
ja LL3 |
| 30 |
shrd eax,edx,28 |
| 31 |
LL1: |
| 32 |
jecxz LL4 |
| 33 |
neg eax |
| 34 |
LL4: |
| 35 |
mov esp,ebp |
| 36 |
pop ebp |
| 37 |
ret 8 |
| 38 |
LL5: |
| 39 |
inc ecx |
| 40 |
LL3: |
| 41 |
mov eax, 0x7fffffff |
| 42 |
mov aritherror, 1 |
| 43 |
jmp LL1 |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
__declspec(naked) integer __stdcall ztakescaled(integer p, scaled q) { |
| 48 |
__asm { |
| 49 |
push ebp |
| 50 |
mov ebp,esp |
| 51 |
; mov eax, [ebp+8] |
| 52 |
xor ecx,ecx |
| 53 |
mov eax, p |
| 54 |
cmp eax, 0x80000000 |
| 55 |
jz LL5 |
| 56 |
imul q |
| 57 |
or edx,edx |
| 58 |
jns LL12 |
| 59 |
neg edx |
| 60 |
neg eax |
| 61 |
sbb edx,ecx |
| 62 |
inc ecx |
| 63 |
LL12: |
| 64 |
add eax, 0x00008000 |
| 65 |
adc edx, 0x0 |
| 66 |
cmp edx, 0x00007fff |
| 67 |
ja LL3 |
| 68 |
shrd eax,edx,16 |
| 69 |
LL1: |
| 70 |
jecxz LL4 |
| 71 |
neg eax |
| 72 |
LL4: |
| 73 |
mov esp,ebp |
| 74 |
pop ebp |
| 75 |
ret 8 |
| 76 |
LL5: |
| 77 |
inc ecx |
| 78 |
LL3: |
| 79 |
mov eax, 0x7fffffff |
| 80 |
mov aritherror, 1 |
| 81 |
jmp LL1 |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
__declspec(naked) scaled __stdcall zmakescaled(integer p, integer q) { |
| 86 |
__asm { |
| 87 |
mov cx, 16 |
| 88 |
push ebp |
| 89 |
mov ebp,esp |
| 90 |
push ebx |
| 91 |
; mov edx, [ebp+8] |
| 92 |
mov edx, p |
| 93 |
xor eax,eax |
| 94 |
or edx,edx |
| 95 |
jns LL32 |
| 96 |
inc ch |
| 97 |
neg edx |
| 98 |
LL32: |
| 99 |
; mov ebx, [ebp+12] |
| 100 |
mov ebx,q |
| 101 |
or ebx,ebx |
| 102 |
jns LL33 |
| 103 |
dec ch |
| 104 |
neg ebx |
| 105 |
or ebx,ebx |
| 106 |
js LL34 |
| 107 |
LL33: |
| 108 |
or edx,edx |
| 109 |
js LL34 |
| 110 |
shrd eax,edx,cl |
| 111 |
shr edx,cl |
| 112 |
cmp edx,ebx |
| 113 |
jae LL34 |
| 114 |
div ebx |
| 115 |
add edx,edx |
| 116 |
inc edx |
| 117 |
sub ebx,edx |
| 118 |
adc eax, 0 |
| 119 |
jc LL34 |
| 120 |
cmp eax, 0x7fffffff |
| 121 |
ja LL34 |
| 122 |
LL31: or ch,ch |
| 123 |
jz LL35 |
| 124 |
neg eax |
| 125 |
LL35: |
| 126 |
pop ebx |
| 127 |
mov esp, ebp |
| 128 |
pop ebp |
| 129 |
ret 8 |
| 130 |
LL34: |
| 131 |
mov eax, 0x7fffffff |
| 132 |
mov aritherror, 1 |
| 133 |
jmp LL31 |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
__declspec(naked) fraction __stdcall zmakefraction(integer p, integer q) { |
| 138 |
__asm { |
| 139 |
mov cx, 4 |
| 140 |
push ebp |
| 141 |
mov ebp,esp |
| 142 |
push ebx |
| 143 |
mov edx, p |
| 144 |
; mov [ebp+8],edx |
| 145 |
xor eax,eax |
| 146 |
or edx,edx |
| 147 |
jns LL32 |
| 148 |
inc ch |
| 149 |
neg edx |
| 150 |
LL32: |
| 151 |
; mov [ebp+12],ebx |
| 152 |
mov ebx, q |
| 153 |
or ebx,ebx |
| 154 |
jns LL33 |
| 155 |
dec ch |
| 156 |
neg ebx |
| 157 |
or ebx,ebx |
| 158 |
js LL34 |
| 159 |
LL33: |
| 160 |
or edx,edx |
| 161 |
js LL34 |
| 162 |
shrd eax,edx, cl |
| 163 |
shr edx,cl |
| 164 |
cmp edx,ebx |
| 165 |
jae LL34 |
| 166 |
div ebx |
| 167 |
add edx,edx |
| 168 |
inc edx |
| 169 |
sub ebx,edx |
| 170 |
adc eax, 0 |
| 171 |
jc LL34 |
| 172 |
cmp eax, 0x7fffffff |
| 173 |
ja LL34 |
| 174 |
LL31: or ch,ch |
| 175 |
jz LL35 |
| 176 |
neg eax |
| 177 |
LL35: |
| 178 |
pop ebx |
| 179 |
mov esp, ebp |
| 180 |
pop ebp |
| 181 |
ret 8 |
| 182 |
LL34: |
| 183 |
mov eax, 0x7fffffff |
| 184 |
mov aritherror, 1 |
| 185 |
jmp LL31 |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
|