- Combine some assembly files together and move them to rtl
[reactos.git] / reactos / lib / rtl / i386 / math.S
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: Run-Time Library
5 * FILE: lib/rtl/i386/math.S
6 * PROGRAMER: Alex Ionescu (alex@relsoft.net)
7 * Eric Kohl (ekohl@rz-online.de)
8 * REVISION HISTORY: 27/07/2005 Created
9 */
10
11 /* GLOBALS ****************************************************************/
12
13 .globl __ftol
14 .globl __aullshr
15 .globl __allrem
16 .globl __aulldiv
17 .globl __allshr
18 .globl __allshl
19 .globl __aullrem
20 .globl __allmul
21 .globl __alldiv
22
23 /* FUNCTIONS ***************************************************************/
24
25 /*
26 * long long
27 * __alldiv(long long Dividend, long long Divisor);
28 *
29 * Parameters:
30 * [ESP+04h] - long long Dividend
31 * [ESP+0Ch] - long long Divisor
32 * Registers:
33 * Unknown
34 * Returns:
35 * EDX:EAX - long long quotient (Dividend/Divisor)
36 * Notes:
37 * Routine removes the arguments from the stack.
38 */
39 __alldiv:
40 call ___divdi3
41 ret $0x10
42
43 /*
44 * long long
45 * __allmul(long long Multiplier, long long Multiplicand);
46 *
47 * Parameters:
48 * [ESP+04h] - long long Multiplier
49 * [ESP+0Ch] - long long Multiplicand
50 * Registers:
51 * Unknown
52 * Returns:
53 * EDX:EAX - long long product (Multiplier*Multiplicand)
54 * Notes:
55 * Routine removes the arguments from the stack.
56 */
57 __allmul:
58 pushl %ebp
59 movl %esp, %ebp
60 pushl %edi
61 pushl %esi
62 pushl %ebx
63 subl $12, %esp
64 movl 16(%ebp), %ebx
65 movl 8(%ebp), %eax
66 mull %ebx
67 movl 20(%ebp), %ecx
68 movl %eax, -24(%ebp)
69 movl 8(%ebp), %eax
70 movl %edx, %esi
71 imull %ecx, %eax
72 addl %eax, %esi
73 movl 12(%ebp), %eax
74 imull %eax, %ebx
75 leal (%ebx,%esi), %eax
76 movl %eax, -20(%ebp)
77 movl -24(%ebp), %eax
78 movl -20(%ebp), %edx
79 addl $12, %esp
80 popl %ebx
81 popl %esi
82 popl %edi
83 popl %ebp
84 ret $0x10
85
86 /*
87 * unsigned long long
88 * __aullrem(unsigned long long Dividend, unsigned long long Divisor);
89 *
90 * Parameters:
91 * [ESP+04h] - unsigned long long Dividend
92 * [ESP+0Ch] - unsigned long long Divisor
93 * Registers:
94 * Unknown
95 * Returns:
96 * EDX:EAX - unsigned long long remainder (Dividend%Divisor)
97 * Notes:
98 * Routine removes the arguments from the stack.
99 */
100 __aullrem:
101 call ___umoddi3
102 ret $16
103
104 /*
105 * long long
106 * __allshl(long long Value, unsigned char Shift);
107 *
108 * Parameters:
109 * EDX:EAX - signed long long value to be shifted left
110 * CL - number of bits to shift by
111 * Registers:
112 * Destroys CL
113 * Returns:
114 * EDX:EAX - shifted value
115 */
116 __allshl:
117 shldl %cl, %eax, %edx
118 sall %cl, %eax
119 andl $32, %ecx
120 je 1f
121 movl %eax, %edx
122 xorl %eax, %eax
123 1:
124 ret
125
126 /*
127 * long long
128 * __allshr(long long Value, unsigned char Shift);
129 *
130 * Parameters:
131 * EDX:EAX - signed long long value to be shifted right
132 * CL - number of bits to shift by
133 * Registers:
134 * Destroys CL
135 * Returns:
136 * EDX:EAX - shifted value
137 */
138 __allshr:
139 shrdl %cl, %edx, %eax
140 sarl %cl, %edx
141 andl $32, %ecx
142 je 1f
143 movl %edx, %eax
144 sarl $31, %edx
145 1:
146 ret
147
148 /*
149 * unsigned long long
150 * __aulldiv(unsigned long long Dividend, unsigned long long Divisor);
151 *
152 * Parameters:
153 * [ESP+04h] - unsigned long long Dividend
154 * [ESP+0Ch] - unsigned long long Divisor
155 * Registers:
156 * Unknown
157 * Returns:
158 * EDX:EAX - unsigned long long quotient (Dividend/Divisor)
159 * Notes:
160 * Routine removes the arguments from the stack.
161 */
162 __aulldiv:
163 call ___udivdi3
164 ret $16
165
166 /*
167 * unsigned long long
168 * __aullshr(unsigned long long Value, unsigned char Shift);
169 *
170 * Parameters:
171 * EDX:EAX - unsigned long long value to be shifted right
172 * CL - number of bits to shift by
173 * Registers:
174 * Destroys CL
175 * Returns:
176 * EDX:EAX - shifted value
177 */
178 __aullshr:
179 shrdl %cl, %edx, %eax
180 shrl %cl, %edx
181 andl $32, %ecx
182 je 1f
183 movl %edx, %eax
184 1:
185 ret
186
187 /*
188 * long long
189 * __allrem(long long Dividend, long long Divisor);
190 *
191 * Parameters:
192 * [ESP+04h] - long long Dividend
193 * [ESP+0Ch] - long long Divisor
194 * Registers:
195 * Unknown
196 * Returns:
197 * EDX:EAX - long long remainder (Dividend/Divisor)
198 * Notes:
199 * Routine removes the arguments from the stack.
200 */
201 __allrem:
202 call ___moddi3
203 ret $16
204
205 .intel_syntax noprefix
206
207 __ftol:
208 /* Set up stack frame */
209 push ebp
210 mov ebp, esp
211
212 /* Set "round towards zero" mode */
213 fstcw [ebp-2]
214 wait
215 mov ax, [ebp-2]
216 or ah, 0xC
217 fldcw [ebp-4]
218
219 /* Do the conversion */
220 fistp qword ptr [ebp-8]
221
222 /* Restore rounding mode */
223 fldcw [ebp-2]
224
225 /* Return value */
226 mov eax, [ebp-12]
227 mov edx, [ebp-8]
228
229 /* Remove stack frame and return*/
230 leave
231 ret