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