|
|
1.1 root 1: //
2: // math.s
3: // x86 assembly-language math routines.
4:
1.1.1.3 ! root 5: #define GLQUAKE 1 // don't include unneeded defs
1.1 root 6: #include "asm_i386.h"
7: #include "quakeasm.h"
8:
9:
1.1.1.3 ! root 10: #if id386
1.1 root 11:
12: .data
13:
14: .align 4
15: Ljmptab: .long Lcase0, Lcase1, Lcase2, Lcase3
16: .long Lcase4, Lcase5, Lcase6, Lcase7
17:
18: .text
19:
20: // TODO: rounding needed?
21: // stack parameter offset
1.1.1.3 ! root 22: #define val 4
1.1 root 23:
24: .globl C(Invert24To16)
25: C(Invert24To16):
26:
27: movl val(%esp),%ecx
28: movl $0x100,%edx // 0x10000000000 as dividend
29: cmpl %edx,%ecx
30: jle LOutOfRange
31:
32: subl %eax,%eax
33: divl %ecx
34:
35: ret
36:
37: LOutOfRange:
38: movl $0xFFFFFFFF,%eax
39: ret
40:
41: #define in 4
42: #define out 8
43:
44: .align 2
45: .globl C(TransformVector)
46: C(TransformVector):
47: movl in(%esp),%eax
48: movl out(%esp),%edx
49:
50: flds (%eax) // in[0]
51: fmuls C(vright) // in[0]*vright[0]
52: flds (%eax) // in[0] | in[0]*vright[0]
53: fmuls C(vup) // in[0]*vup[0] | in[0]*vright[0]
54: flds (%eax) // in[0] | in[0]*vup[0] | in[0]*vright[0]
55: fmuls C(vpn) // in[0]*vpn[0] | in[0]*vup[0] | in[0]*vright[0]
56:
57: flds 4(%eax) // in[1] | ...
58: fmuls C(vright)+4 // in[1]*vright[1] | ...
59: flds 4(%eax) // in[1] | in[1]*vright[1] | ...
60: fmuls C(vup)+4 // in[1]*vup[1] | in[1]*vright[1] | ...
61: flds 4(%eax) // in[1] | in[1]*vup[1] | in[1]*vright[1] | ...
62: fmuls C(vpn)+4 // in[1]*vpn[1] | in[1]*vup[1] | in[1]*vright[1] | ...
63: fxch %st(2) // in[1]*vright[1] | in[1]*vup[1] | in[1]*vpn[1] | ...
64:
65: faddp %st(0),%st(5) // in[1]*vup[1] | in[1]*vpn[1] | ...
66: faddp %st(0),%st(3) // in[1]*vpn[1] | ...
67: faddp %st(0),%st(1) // vpn_accum | vup_accum | vright_accum
68:
69: flds 8(%eax) // in[2] | ...
70: fmuls C(vright)+8 // in[2]*vright[2] | ...
71: flds 8(%eax) // in[2] | in[2]*vright[2] | ...
72: fmuls C(vup)+8 // in[2]*vup[2] | in[2]*vright[2] | ...
73: flds 8(%eax) // in[2] | in[2]*vup[2] | in[2]*vright[2] | ...
74: fmuls C(vpn)+8 // in[2]*vpn[2] | in[2]*vup[2] | in[2]*vright[2] | ...
75: fxch %st(2) // in[2]*vright[2] | in[2]*vup[2] | in[2]*vpn[2] | ...
76:
77: faddp %st(0),%st(5) // in[2]*vup[2] | in[2]*vpn[2] | ...
78: faddp %st(0),%st(3) // in[2]*vpn[2] | ...
79: faddp %st(0),%st(1) // vpn_accum | vup_accum | vright_accum
80:
81: fstps 8(%edx) // out[2]
82: fstps 4(%edx) // out[1]
83: fstps (%edx) // out[0]
84:
85: ret
86:
87:
88: #define EMINS 4+4
89: #define EMAXS 4+8
90: #define P 4+12
91:
92: .align 2
93: .globl C(BoxOnPlaneSide)
94: C(BoxOnPlaneSide):
95: pushl %ebx
96:
97: movl P(%esp),%edx
98: movl EMINS(%esp),%ecx
99: xorl %eax,%eax
100: movl EMAXS(%esp),%ebx
101: movb pl_signbits(%edx),%al
102: cmpb $8,%al
103: jge Lerror
104: flds pl_normal(%edx) // p->normal[0]
105: fld %st(0) // p->normal[0] | p->normal[0]
1.1.1.3 ! root 106: jmp Ljmptab(,%eax,4)
1.1 root 107:
108:
109: //dist1= p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
110: //dist2= p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
111: Lcase0:
112: fmuls (%ebx) // p->normal[0]*emaxs[0] | p->normal[0]
113: flds pl_normal+4(%edx) // p->normal[1] | p->normal[0]*emaxs[0] |
114: // p->normal[0]
115: fxch %st(2) // p->normal[0] | p->normal[0]*emaxs[0] |
116: // p->normal[1]
117: fmuls (%ecx) // p->normal[0]*emins[0] |
118: // p->normal[0]*emaxs[0] | p->normal[1]
119: fxch %st(2) // p->normal[1] | p->normal[0]*emaxs[0] |
120: // p->normal[0]*emins[0]
121: fld %st(0) // p->normal[1] | p->normal[1] |
122: // p->normal[0]*emaxs[0] |
123: // p->normal[0]*emins[0]
124: fmuls 4(%ebx) // p->normal[1]*emaxs[1] | p->normal[1] |
125: // p->normal[0]*emaxs[0] |
126: // p->normal[0]*emins[0]
127: flds pl_normal+8(%edx) // p->normal[2] | p->normal[1]*emaxs[1] |
128: // p->normal[1] | p->normal[0]*emaxs[0] |
129: // p->normal[0]*emins[0]
130: fxch %st(2) // p->normal[1] | p->normal[1]*emaxs[1] |
131: // p->normal[2] | p->normal[0]*emaxs[0] |
132: // p->normal[0]*emins[0]
133: fmuls 4(%ecx) // p->normal[1]*emins[1] |
134: // p->normal[1]*emaxs[1] |
135: // p->normal[2] | p->normal[0]*emaxs[0] |
136: // p->normal[0]*emins[0]
137: fxch %st(2) // p->normal[2] | p->normal[1]*emaxs[1] |
138: // p->normal[1]*emins[1] |
139: // p->normal[0]*emaxs[0] |
140: // p->normal[0]*emins[0]
141: fld %st(0) // p->normal[2] | p->normal[2] |
142: // p->normal[1]*emaxs[1] |
143: // p->normal[1]*emins[1] |
144: // p->normal[0]*emaxs[0] |
145: // p->normal[0]*emins[0]
146: fmuls 8(%ebx) // p->normal[2]*emaxs[2] |
147: // p->normal[2] |
148: // p->normal[1]*emaxs[1] |
149: // p->normal[1]*emins[1] |
150: // p->normal[0]*emaxs[0] |
151: // p->normal[0]*emins[0]
152: fxch %st(5) // p->normal[0]*emins[0] |
153: // p->normal[2] |
154: // p->normal[1]*emaxs[1] |
155: // p->normal[1]*emins[1] |
156: // p->normal[0]*emaxs[0] |
157: // p->normal[2]*emaxs[2]
158: faddp %st(0),%st(3) //p->normal[2] |
159: // p->normal[1]*emaxs[1] |
160: // p->normal[1]*emins[1]+p->normal[0]*emins[0]|
161: // p->normal[0]*emaxs[0] |
162: // p->normal[2]*emaxs[2]
163: fmuls 8(%ecx) //p->normal[2]*emins[2] |
164: // p->normal[1]*emaxs[1] |
165: // p->normal[1]*emins[1]+p->normal[0]*emins[0]|
166: // p->normal[0]*emaxs[0] |
167: // p->normal[2]*emaxs[2]
168: fxch %st(1) //p->normal[1]*emaxs[1] |
169: // p->normal[2]*emins[2] |
170: // p->normal[1]*emins[1]+p->normal[0]*emins[0]|
171: // p->normal[0]*emaxs[0] |
172: // p->normal[2]*emaxs[2]
173: faddp %st(0),%st(3) //p->normal[2]*emins[2] |
174: // p->normal[1]*emins[1]+p->normal[0]*emins[0]|
175: // p->normal[0]*emaxs[0]+p->normal[1]*emaxs[1]|
176: // p->normal[2]*emaxs[2]
177: fxch %st(3) //p->normal[2]*emaxs[2] +
178: // p->normal[1]*emins[1]+p->normal[0]*emins[0]|
179: // p->normal[0]*emaxs[0]+p->normal[1]*emaxs[1]|
180: // p->normal[2]*emins[2]
181: faddp %st(0),%st(2) //p->normal[1]*emins[1]+p->normal[0]*emins[0]|
182: // dist1 | p->normal[2]*emins[2]
183:
184: jmp LSetSides
185:
186: //dist1= p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
187: //dist2= p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
188: Lcase1:
189: fmuls (%ecx) // emins[0]
190: flds pl_normal+4(%edx)
191: fxch %st(2)
192: fmuls (%ebx) // emaxs[0]
193: fxch %st(2)
194: fld %st(0)
195: fmuls 4(%ebx) // emaxs[1]
196: flds pl_normal+8(%edx)
197: fxch %st(2)
198: fmuls 4(%ecx) // emins[1]
199: fxch %st(2)
200: fld %st(0)
201: fmuls 8(%ebx) // emaxs[2]
202: fxch %st(5)
203: faddp %st(0),%st(3)
204: fmuls 8(%ecx) // emins[2]
205: fxch %st(1)
206: faddp %st(0),%st(3)
207: fxch %st(3)
208: faddp %st(0),%st(2)
209:
210: jmp LSetSides
211:
212: //dist1= p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
213: //dist2= p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
214: Lcase2:
215: fmuls (%ebx) // emaxs[0]
216: flds pl_normal+4(%edx)
217: fxch %st(2)
218: fmuls (%ecx) // emins[0]
219: fxch %st(2)
220: fld %st(0)
221: fmuls 4(%ecx) // emins[1]
222: flds pl_normal+8(%edx)
223: fxch %st(2)
224: fmuls 4(%ebx) // emaxs[1]
225: fxch %st(2)
226: fld %st(0)
227: fmuls 8(%ebx) // emaxs[2]
228: fxch %st(5)
229: faddp %st(0),%st(3)
230: fmuls 8(%ecx) // emins[2]
231: fxch %st(1)
232: faddp %st(0),%st(3)
233: fxch %st(3)
234: faddp %st(0),%st(2)
235:
236: jmp LSetSides
237:
238: //dist1= p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
239: //dist2= p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
240: Lcase3:
241: fmuls (%ecx) // emins[0]
242: flds pl_normal+4(%edx)
243: fxch %st(2)
244: fmuls (%ebx) // emaxs[0]
245: fxch %st(2)
246: fld %st(0)
247: fmuls 4(%ecx) // emins[1]
248: flds pl_normal+8(%edx)
249: fxch %st(2)
250: fmuls 4(%ebx) // emaxs[1]
251: fxch %st(2)
252: fld %st(0)
253: fmuls 8(%ebx) // emaxs[2]
254: fxch %st(5)
255: faddp %st(0),%st(3)
256: fmuls 8(%ecx) // emins[2]
257: fxch %st(1)
258: faddp %st(0),%st(3)
259: fxch %st(3)
260: faddp %st(0),%st(2)
261:
262: jmp LSetSides
263:
264: //dist1= p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
265: //dist2= p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
266: Lcase4:
267: fmuls (%ebx) // emaxs[0]
268: flds pl_normal+4(%edx)
269: fxch %st(2)
270: fmuls (%ecx) // emins[0]
271: fxch %st(2)
272: fld %st(0)
273: fmuls 4(%ebx) // emaxs[1]
274: flds pl_normal+8(%edx)
275: fxch %st(2)
276: fmuls 4(%ecx) // emins[1]
277: fxch %st(2)
278: fld %st(0)
279: fmuls 8(%ecx) // emins[2]
280: fxch %st(5)
281: faddp %st(0),%st(3)
282: fmuls 8(%ebx) // emaxs[2]
283: fxch %st(1)
284: faddp %st(0),%st(3)
285: fxch %st(3)
286: faddp %st(0),%st(2)
287:
288: jmp LSetSides
289:
290: //dist1= p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
291: //dist2= p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
292: Lcase5:
293: fmuls (%ecx) // emins[0]
294: flds pl_normal+4(%edx)
295: fxch %st(2)
296: fmuls (%ebx) // emaxs[0]
297: fxch %st(2)
298: fld %st(0)
299: fmuls 4(%ebx) // emaxs[1]
300: flds pl_normal+8(%edx)
301: fxch %st(2)
302: fmuls 4(%ecx) // emins[1]
303: fxch %st(2)
304: fld %st(0)
305: fmuls 8(%ecx) // emins[2]
306: fxch %st(5)
307: faddp %st(0),%st(3)
308: fmuls 8(%ebx) // emaxs[2]
309: fxch %st(1)
310: faddp %st(0),%st(3)
311: fxch %st(3)
312: faddp %st(0),%st(2)
313:
314: jmp LSetSides
315:
316: //dist1= p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
317: //dist2= p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
318: Lcase6:
319: fmuls (%ebx) // emaxs[0]
320: flds pl_normal+4(%edx)
321: fxch %st(2)
322: fmuls (%ecx) // emins[0]
323: fxch %st(2)
324: fld %st(0)
325: fmuls 4(%ecx) // emins[1]
326: flds pl_normal+8(%edx)
327: fxch %st(2)
328: fmuls 4(%ebx) // emaxs[1]
329: fxch %st(2)
330: fld %st(0)
331: fmuls 8(%ecx) // emins[2]
332: fxch %st(5)
333: faddp %st(0),%st(3)
334: fmuls 8(%ebx) // emaxs[2]
335: fxch %st(1)
336: faddp %st(0),%st(3)
337: fxch %st(3)
338: faddp %st(0),%st(2)
339:
340: jmp LSetSides
341:
342: //dist1= p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
343: //dist2= p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
344: Lcase7:
345: fmuls (%ecx) // emins[0]
346: flds pl_normal+4(%edx)
347: fxch %st(2)
348: fmuls (%ebx) // emaxs[0]
349: fxch %st(2)
350: fld %st(0)
351: fmuls 4(%ecx) // emins[1]
352: flds pl_normal+8(%edx)
353: fxch %st(2)
354: fmuls 4(%ebx) // emaxs[1]
355: fxch %st(2)
356: fld %st(0)
357: fmuls 8(%ecx) // emins[2]
358: fxch %st(5)
359: faddp %st(0),%st(3)
360: fmuls 8(%ebx) // emaxs[2]
361: fxch %st(1)
362: faddp %st(0),%st(3)
363: fxch %st(3)
364: faddp %st(0),%st(2)
365:
366: LSetSides:
367:
368: // sides = 0;
369: // if (dist1 >= p->dist)
370: // sides = 1;
371: // if (dist2 < p->dist)
372: // sides |= 2;
373:
374: faddp %st(0),%st(2) // dist1 | dist2
375: fcomps pl_dist(%edx)
376: xorl %ecx,%ecx
377: fnstsw %ax
378: fcomps pl_dist(%edx)
379: andb $1,%ah
380: xorb $1,%ah
381: addb %ah,%cl
382:
383: fnstsw %ax
384: andb $1,%ah
385: addb %ah,%ah
386: addb %ah,%cl
387:
388: // return sides;
389:
390: popl %ebx
391: movl %ecx,%eax // return status
392:
393: ret
394:
395:
396: Lerror:
397: call C(BOPS_Error)
398:
399: #endif // id386
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.