2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // x86 assembly-language math routines.
24 #define GLQUAKE 1 // don't include unneeded defs
34 Ljmptab
: .long Lcase0, Lcase1, Lcase2, Lcase3
35 .long Lcase4, Lcase5, Lcase6, Lcase7
39 // TODO
: rounding needed?
40 // stack parameter offset
43 .globl C(Invert24To16)
47 movl $
0x100,%edx
// 0x10000000000 as dividend
64 .globl C(TransformVector)
70 fmuls C
(vright
) // in
[0]*vright
[0]
71 flds
(%eax
) // in
[0] | in
[0]*vright
[0]
72 fmuls C
(vup
) // in
[0]*vup
[0] | in
[0]*vright
[0]
73 flds
(%eax
) // in
[0] | in
[0]*vup
[0] | in
[0]*vright
[0]
74 fmuls C
(vpn
) // in
[0]*vpn
[0] | in
[0]*vup
[0] | in
[0]*vright
[0]
76 flds
4(%eax
) // in
[1] |
...
77 fmuls C
(vright
)+4 // in
[1]*vright
[1] |
...
78 flds
4(%eax
) // in
[1] | in
[1]*vright
[1] |
...
79 fmuls C
(vup
)+4 // in
[1]*vup
[1] | in
[1]*vright
[1] |
...
80 flds
4(%eax
) // in
[1] | in
[1]*vup
[1] | in
[1]*vright
[1] |
...
81 fmuls C
(vpn
)+4 // in
[1]*vpn
[1] | in
[1]*vup
[1] | in
[1]*vright
[1] |
...
82 fxch
%st(2) // in
[1]*vright
[1] | in
[1]*vup
[1] | in
[1]*vpn
[1] |
...
84 faddp
%st(0),%st(5) // in
[1]*vup
[1] | in
[1]*vpn
[1] |
...
85 faddp
%st(0),%st(3) // in
[1]*vpn
[1] |
...
86 faddp
%st(0),%st(1) // vpn_accum | vup_accum | vright_accum
88 flds
8(%eax
) // in
[2] |
...
89 fmuls C
(vright
)+8 // in
[2]*vright
[2] |
...
90 flds
8(%eax
) // in
[2] | in
[2]*vright
[2] |
...
91 fmuls C
(vup
)+8 // in
[2]*vup
[2] | in
[2]*vright
[2] |
...
92 flds
8(%eax
) // in
[2] | in
[2]*vup
[2] | in
[2]*vright
[2] |
...
93 fmuls C
(vpn
)+8 // in
[2]*vpn
[2] | in
[2]*vup
[2] | in
[2]*vright
[2] |
...
94 fxch
%st(2) // in
[2]*vright
[2] | in
[2]*vup
[2] | in
[2]*vpn
[2] |
...
96 faddp
%st(0),%st(5) // in
[2]*vup
[2] | in
[2]*vpn
[2] |
...
97 faddp
%st(0),%st(3) // in
[2]*vpn
[2] |
...
98 faddp
%st(0),%st(1) // vpn_accum | vup_accum | vright_accum
100 fstps
8(%edx
) // out
[2]
101 fstps
4(%edx
) // out
[1]
102 fstps
(%edx
) // out
[0]
112 .globl C(BoxOnPlaneSide)
117 movl EMINS
(%esp
),%ecx
119 movl EMAXS
(%esp
),%ebx
120 movb pl_signbits
(%edx
),%al
123 flds pl_normal
(%edx
) // p-
>normal
[0]
124 fld
%st(0) // p-
>normal
[0] | p-
>normal
[0]
125 jmp
*Ljmptab
(,%eax
,4)
128 //dist1
= p-
>normal
[0]*emaxs
[0] + p-
>normal
[1]*emaxs
[1] + p-
>normal
[2]*emaxs
[2];
129 //dist2
= p-
>normal
[0]*emins
[0] + p-
>normal
[1]*emins
[1] + p-
>normal
[2]*emins
[2];
131 fmuls (%ebx
) // p-
>normal
[0]*emaxs
[0] | p-
>normal
[0]
132 flds pl_normal+
4(%edx
) // p-
>normal
[1] | p-
>normal
[0]*emaxs
[0] |
134 fxch
%st(2) // p-
>normal
[0] | p-
>normal
[0]*emaxs
[0] |
136 fmuls (%ecx
) // p-
>normal
[0]*emins
[0] |
137 // p-
>normal
[0]*emaxs
[0] | p-
>normal
[1]
138 fxch
%st(2) // p-
>normal
[1] | p-
>normal
[0]*emaxs
[0] |
139 // p-
>normal
[0]*emins
[0]
140 fld
%st(0) // p-
>normal
[1] | p-
>normal
[1] |
141 // p-
>normal
[0]*emaxs
[0] |
142 // p-
>normal
[0]*emins
[0]
143 fmuls 4(%ebx
) // p-
>normal
[1]*emaxs
[1] | p-
>normal
[1] |
144 // p-
>normal
[0]*emaxs
[0] |
145 // p-
>normal
[0]*emins
[0]
146 flds pl_normal+
8(%edx
) // p-
>normal
[2] | p-
>normal
[1]*emaxs
[1] |
147 // p-
>normal
[1] | p-
>normal
[0]*emaxs
[0] |
148 // p-
>normal
[0]*emins
[0]
149 fxch
%st(2) // p-
>normal
[1] | p-
>normal
[1]*emaxs
[1] |
150 // p-
>normal
[2] | p-
>normal
[0]*emaxs
[0] |
151 // p-
>normal
[0]*emins
[0]
152 fmuls 4(%ecx
) // p-
>normal
[1]*emins
[1] |
153 // p-
>normal
[1]*emaxs
[1] |
154 // p-
>normal
[2] | p-
>normal
[0]*emaxs
[0] |
155 // p-
>normal
[0]*emins
[0]
156 fxch
%st(2) // p-
>normal
[2] | p-
>normal
[1]*emaxs
[1] |
157 // p-
>normal
[1]*emins
[1] |
158 // p-
>normal
[0]*emaxs
[0] |
159 // p-
>normal
[0]*emins
[0]
160 fld
%st(0) // p-
>normal
[2] | p-
>normal
[2] |
161 // p-
>normal
[1]*emaxs
[1] |
162 // p-
>normal
[1]*emins
[1] |
163 // p-
>normal
[0]*emaxs
[0] |
164 // p-
>normal
[0]*emins
[0]
165 fmuls 8(%ebx
) // p-
>normal
[2]*emaxs
[2] |
167 // p-
>normal
[1]*emaxs
[1] |
168 // p-
>normal
[1]*emins
[1] |
169 // p-
>normal
[0]*emaxs
[0] |
170 // p-
>normal
[0]*emins
[0]
171 fxch
%st(5) // p-
>normal
[0]*emins
[0] |
173 // p-
>normal
[1]*emaxs
[1] |
174 // p-
>normal
[1]*emins
[1] |
175 // p-
>normal
[0]*emaxs
[0] |
176 // p-
>normal
[2]*emaxs
[2]
177 faddp
%st(0),%st(3) //p-
>normal
[2] |
178 // p-
>normal
[1]*emaxs
[1] |
179 // p-
>normal
[1]*emins
[1]+p-
>normal
[0]*emins
[0]|
180 // p-
>normal
[0]*emaxs
[0] |
181 // p-
>normal
[2]*emaxs
[2]
182 fmuls 8(%ecx
) //p-
>normal
[2]*emins
[2] |
183 // p-
>normal
[1]*emaxs
[1] |
184 // p-
>normal
[1]*emins
[1]+p-
>normal
[0]*emins
[0]|
185 // p-
>normal
[0]*emaxs
[0] |
186 // p-
>normal
[2]*emaxs
[2]
187 fxch
%st(1) //p-
>normal
[1]*emaxs
[1] |
188 // p-
>normal
[2]*emins
[2] |
189 // p-
>normal
[1]*emins
[1]+p-
>normal
[0]*emins
[0]|
190 // p-
>normal
[0]*emaxs
[0] |
191 // p-
>normal
[2]*emaxs
[2]
192 faddp
%st(0),%st(3) //p-
>normal
[2]*emins
[2] |
193 // p-
>normal
[1]*emins
[1]+p-
>normal
[0]*emins
[0]|
194 // p-
>normal
[0]*emaxs
[0]+p-
>normal
[1]*emaxs
[1]|
195 // p-
>normal
[2]*emaxs
[2]
196 fxch
%st(3) //p-
>normal
[2]*emaxs
[2] +
197 // p-
>normal
[1]*emins
[1]+p-
>normal
[0]*emins
[0]|
198 // p-
>normal
[0]*emaxs
[0]+p-
>normal
[1]*emaxs
[1]|
199 // p-
>normal
[2]*emins
[2]
200 faddp
%st(0),%st(2) //p-
>normal
[1]*emins
[1]+p-
>normal
[0]*emins
[0]|
201 // dist1 | p-
>normal
[2]*emins
[2]
205 //dist1
= p-
>normal
[0]*emins
[0] + p-
>normal
[1]*emaxs
[1] + p-
>normal
[2]*emaxs
[2];
206 //dist2
= p-
>normal
[0]*emaxs
[0] + p-
>normal
[1]*emins
[1] + p-
>normal
[2]*emins
[2];
208 fmuls (%ecx
) // emins
[0]
209 flds pl_normal+
4(%edx
)
211 fmuls (%ebx
) // emaxs
[0]
214 fmuls 4(%ebx
) // emaxs
[1]
215 flds pl_normal+
8(%edx
)
217 fmuls 4(%ecx
) // emins
[1]
220 fmuls 8(%ebx
) // emaxs
[2]
223 fmuls 8(%ecx
) // emins
[2]
231 //dist1
= p-
>normal
[0]*emaxs
[0] + p-
>normal
[1]*emins
[1] + p-
>normal
[2]*emaxs
[2];
232 //dist2
= p-
>normal
[0]*emins
[0] + p-
>normal
[1]*emaxs
[1] + p-
>normal
[2]*emins
[2];
234 fmuls (%ebx
) // emaxs
[0]
235 flds pl_normal+
4(%edx
)
237 fmuls (%ecx
) // emins
[0]
240 fmuls 4(%ecx
) // emins
[1]
241 flds pl_normal+
8(%edx
)
243 fmuls 4(%ebx
) // emaxs
[1]
246 fmuls 8(%ebx
) // emaxs
[2]
249 fmuls 8(%ecx
) // emins
[2]
257 //dist1
= p-
>normal
[0]*emins
[0] + p-
>normal
[1]*emins
[1] + p-
>normal
[2]*emaxs
[2];
258 //dist2
= p-
>normal
[0]*emaxs
[0] + p-
>normal
[1]*emaxs
[1] + p-
>normal
[2]*emins
[2];
260 fmuls (%ecx
) // emins
[0]
261 flds pl_normal+
4(%edx
)
263 fmuls (%ebx
) // emaxs
[0]
266 fmuls 4(%ecx
) // emins
[1]
267 flds pl_normal+
8(%edx
)
269 fmuls 4(%ebx
) // emaxs
[1]
272 fmuls 8(%ebx
) // emaxs
[2]
275 fmuls 8(%ecx
) // emins
[2]
283 //dist1
= p-
>normal
[0]*emaxs
[0] + p-
>normal
[1]*emaxs
[1] + p-
>normal
[2]*emins
[2];
284 //dist2
= p-
>normal
[0]*emins
[0] + p-
>normal
[1]*emins
[1] + p-
>normal
[2]*emaxs
[2];
286 fmuls (%ebx
) // emaxs
[0]
287 flds pl_normal+
4(%edx
)
289 fmuls (%ecx
) // emins
[0]
292 fmuls 4(%ebx
) // emaxs
[1]
293 flds pl_normal+
8(%edx
)
295 fmuls 4(%ecx
) // emins
[1]
298 fmuls 8(%ecx
) // emins
[2]
301 fmuls 8(%ebx
) // emaxs
[2]
309 //dist1
= p-
>normal
[0]*emins
[0] + p-
>normal
[1]*emaxs
[1] + p-
>normal
[2]*emins
[2];
310 //dist2
= p-
>normal
[0]*emaxs
[0] + p-
>normal
[1]*emins
[1] + p-
>normal
[2]*emaxs
[2];
312 fmuls (%ecx
) // emins
[0]
313 flds pl_normal+
4(%edx
)
315 fmuls (%ebx
) // emaxs
[0]
318 fmuls 4(%ebx
) // emaxs
[1]
319 flds pl_normal+
8(%edx
)
321 fmuls 4(%ecx
) // emins
[1]
324 fmuls 8(%ecx
) // emins
[2]
327 fmuls 8(%ebx
) // emaxs
[2]
335 //dist1
= p-
>normal
[0]*emaxs
[0] + p-
>normal
[1]*emins
[1] + p-
>normal
[2]*emins
[2];
336 //dist2
= p-
>normal
[0]*emins
[0] + p-
>normal
[1]*emaxs
[1] + p-
>normal
[2]*emaxs
[2];
338 fmuls (%ebx
) // emaxs
[0]
339 flds pl_normal+
4(%edx
)
341 fmuls (%ecx
) // emins
[0]
344 fmuls 4(%ecx
) // emins
[1]
345 flds pl_normal+
8(%edx
)
347 fmuls 4(%ebx
) // emaxs
[1]
350 fmuls 8(%ecx
) // emins
[2]
353 fmuls 8(%ebx
) // emaxs
[2]
361 //dist1
= p-
>normal
[0]*emins
[0] + p-
>normal
[1]*emins
[1] + p-
>normal
[2]*emins
[2];
362 //dist2
= p-
>normal
[0]*emaxs
[0] + p-
>normal
[1]*emaxs
[1] + p-
>normal
[2]*emaxs
[2];
364 fmuls (%ecx
) // emins
[0]
365 flds pl_normal+
4(%edx
)
367 fmuls (%ebx
) // emaxs
[0]
370 fmuls 4(%ecx
) // emins
[1]
371 flds pl_normal+
8(%edx
)
373 fmuls 4(%ebx
) // emaxs
[1]
376 fmuls 8(%ecx
) // emins
[2]
379 fmuls 8(%ebx
) // emaxs
[2]
388 // if
(dist1
>= p-
>dist
)
390 // if
(dist2
< p-
>dist
)
393 faddp
%st(0),%st(2) // dist1 | dist2
410 movl
%ecx
,%eax
// return status