Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
70 giacomo 1
/* $Id: x86_cliptest.s,v 1.1 2003-03-13 12:11:49 giacomo Exp $ */
2
 
3
/*
4
 * Mesa 3-D graphics library
5
 * Version:  3.5
6
 *
7
 * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a
10
 * copy of this software and associated documentation files (the "Software"),
11
 * to deal in the Software without restriction, including without limitation
12
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13
 * and/or sell copies of the Software, and to permit persons to whom the
14
 * Software is furnished to do so, subject to the following conditions:
15
 *
16
 * The above copyright notice and this permission notice shall be included
17
 * in all copies or substantial portions of the Software.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22
 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
 */
26
 
27
/*
28
 * NOTE: Avoid using spaces in between '(' ')' and arguments, especially
29
 * with macros like CONST, LLBL that expand to CONCAT(...).  Putting spaces
30
 * in there will break the build on some platforms.
31
 */
32
 
33
#include "matypes.h"
34
#include "clip_args.h"
35
 
36
#define SRC0		REGOFF(0, ESI)
37
#define SRC1		REGOFF(4, ESI)
38
#define SRC2		REGOFF(8, ESI)
39
#define SRC3		REGOFF(12, ESI)
40
#define DST0		REGOFF(0, EDI)
41
#define DST1		REGOFF(4, EDI)
42
#define DST2		REGOFF(8, EDI)
43
#define DST3		REGOFF(12, EDI)
44
#define MAT0		REGOFF(0, EDX)
45
#define MAT1		REGOFF(4, EDX)
46
#define MAT2		REGOFF(8, EDX)
47
#define MAT3		REGOFF(12, EDX)
48
 
49
 
50
/*
51
 * Table for clip test.
52
 *
53
 * 	bit6 = SRC3 < 0
54
 * 	bit5 = SRC2 < 0
55
 * 	bit4 = abs(S(2)) > abs(S(3))
56
 * 	bit3 = SRC1 < 0
57
 * 	bit2 = abs(S(1)) > abs(S(3))
58
 * 	bit1 = SRC0 < 0
59
 * 	bit0 = abs(S(0)) > abs(S(3))
60
 */
61
 
62
	SEG_DATA
63
 
64
clip_table:
65
	D_BYTE 0x00, 0x01, 0x00, 0x02, 0x04, 0x05, 0x04, 0x06
66
	D_BYTE 0x00, 0x01, 0x00, 0x02, 0x08, 0x09, 0x08, 0x0a
67
	D_BYTE 0x20, 0x21, 0x20, 0x22, 0x24, 0x25, 0x24, 0x26
68
	D_BYTE 0x20, 0x21, 0x20, 0x22, 0x28, 0x29, 0x28, 0x2a
69
	D_BYTE 0x00, 0x01, 0x00, 0x02, 0x04, 0x05, 0x04, 0x06
70
	D_BYTE 0x00, 0x01, 0x00, 0x02, 0x08, 0x09, 0x08, 0x0a
71
	D_BYTE 0x10, 0x11, 0x10, 0x12, 0x14, 0x15, 0x14, 0x16
72
	D_BYTE 0x10, 0x11, 0x10, 0x12, 0x18, 0x19, 0x18, 0x1a
73
	D_BYTE 0x3f, 0x3d, 0x3f, 0x3e, 0x37, 0x35, 0x37, 0x36
74
	D_BYTE 0x3f, 0x3d, 0x3f, 0x3e, 0x3b, 0x39, 0x3b, 0x3a
75
	D_BYTE 0x2f, 0x2d, 0x2f, 0x2e, 0x27, 0x25, 0x27, 0x26
76
	D_BYTE 0x2f, 0x2d, 0x2f, 0x2e, 0x2b, 0x29, 0x2b, 0x2a
77
	D_BYTE 0x3f, 0x3d, 0x3f, 0x3e, 0x37, 0x35, 0x37, 0x36
78
	D_BYTE 0x3f, 0x3d, 0x3f, 0x3e, 0x3b, 0x39, 0x3b, 0x3a
79
	D_BYTE 0x1f, 0x1d, 0x1f, 0x1e, 0x17, 0x15, 0x17, 0x16
80
	D_BYTE 0x1f, 0x1d, 0x1f, 0x1e, 0x1b, 0x19, 0x1b, 0x1a
81
 
82
 
83
	SEG_TEXT
84
 
85
/*
86
 * _mesa_x86_cliptest_points4
87
 *
88
 *   AL:  ormask
89
 *   AH:  andmask
90
 *   EBX: temp0
91
 *   ECX: temp1
92
 *   EDX: clipmask[]
93
 *   ESI: clip[]
94
 *   EDI: proj[]
95
 *   EBP: temp2
96
 */
97
 
98
#if defined(__ELF__) && defined(__PIC__) && defined(GNU_ASSEMBLER) && !defined(ELFPIC)
99
#define ELFPIC
100
#endif
101
 
102
ALIGNTEXT16
103
GLOBL GLNAME( _mesa_x86_cliptest_points4 )
104
GLNAME( _mesa_x86_cliptest_points4 ):
105
 
106
#ifdef ELFPIC
107
#define FRAME_OFFSET 20
108
#else
109
#define FRAME_OFFSET 16
110
#endif
111
	PUSH_L( ESI )
112
	PUSH_L( EDI )
113
	PUSH_L( EBP )
114
	PUSH_L( EBX )
115
 
116
#ifdef ELFPIC
117
	/* store pointer to clip_table on stack */
118
	CALL( LLBL(ctp4_get_eip) )
119
	ADD_L( CONST(_GLOBAL_OFFSET_TABLE_), EBX )
120
	MOV_L( REGOFF(clip_table@GOT, EBX), EBX )
121
	PUSH_L( EBX )
122
	JMP( LLBL(ctp4_clip_table_ready) )
123
 
124
LLBL(ctp4_get_eip):
125
	/* store eip in ebx */
126
	MOV_L( REGIND(ESP), EBX )
127
	RET
128
 
129
LLBL(ctp4_clip_table_ready):
130
#endif
131
 
132
	MOV_L( ARG_SOURCE, ESI )
133
	MOV_L( ARG_DEST, EDI )
134
 
135
	MOV_L( ARG_CLIP, EDX )
136
	MOV_L( ARG_OR, EBX )
137
 
138
	MOV_L( ARG_AND, EBP )
139
	MOV_L( REGOFF(V4F_STRIDE, ESI), EAX )
140
 
141
	MOV_L( REGOFF(V4F_COUNT, ESI), ECX )
142
	MOV_L( REGOFF(V4F_START, ESI), ESI )
143
 
144
	OR_L( CONST(VEC_SIZE_4), REGOFF(V4F_FLAGS, EDI) )
145
	MOV_L( EAX, ARG_SOURCE )	/* put stride in ARG_SOURCE */
146
 
147
	MOV_L( CONST(4), REGOFF(V4F_SIZE, EDI) )
148
	MOV_L( ECX, REGOFF(V4F_COUNT, EDI) )
149
 
150
	MOV_L( REGOFF(V4F_START, EDI), EDI )
151
	ADD_L( EDX, ECX )
152
 
153
	MOV_L( ECX, ARG_CLIP )		/* put clipmask + count in ARG_CLIP */
154
	CMP_L( ECX, EDX )
155
 
156
	MOV_B( REGIND(EBX), AL )
157
	MOV_B( REGIND(EBP), AH )
158
 
159
	JZ( LLBL(ctp4_finish) )
160
 
161
ALIGNTEXT16
162
LLBL(ctp4_top):
163
 
164
	FLD1				/* F3 */
165
	FDIV_S( SRC3 )		/* GH: don't care about div-by-zero */
166
 
167
	MOV_L( SRC3, EBP )
168
	MOV_L( SRC2, EBX )
169
 
170
	XOR_L( ECX, ECX )
171
	ADD_L( EBP, EBP )	/* ebp = abs(S(3))*2 ; carry = sign of S(3) */
172
 
173
	ADC_L( ECX, ECX )
174
	ADD_L( EBX, EBX )	/* ebx = abs(S(2))*2 ; carry = sign of S(2) */
175
 
176
	ADC_L( ECX, ECX )
177
	CMP_L( EBX, EBP )	/* carry = abs(S(2))*2 > abs(S(3))*2 */
178
 
179
	ADC_L( ECX, ECX )
180
	MOV_L( SRC1, EBX )
181
 
182
	ADD_L( EBX, EBX )	/* ebx = abs(S(1))*2 ; carry = sign of S(1) */
183
 
184
	ADC_L( ECX, ECX )
185
	CMP_L( EBX, EBP )	/* carry = abs(S(1))*2 > abs(S(3))*2 */
186
 
187
	ADC_L( ECX, ECX )
188
	MOV_L( SRC0, EBX )
189
 
190
	ADD_L( EBX, EBX )	/* ebx = abs(S(0))*2 ; carry = sign of S(0) */
191
 
192
	ADC_L( ECX, ECX )
193
	CMP_L( EBX, EBP )	/* carry = abs(S(0))*2 > abs(S(3))*2 */
194
 
195
	ADC_L( ECX, ECX )
196
 
197
#ifdef ELFPIC
198
	MOV_L( REGIND(ESP), EBP )	/* clip_table */
199
 
200
	MOV_B( REGBI(EBP, ECX), CL )
201
#else
202
	MOV_B( REGOFF(clip_table,ECX), CL )
203
#endif
204
 
205
	OR_B( CL, AL )
206
	AND_B( CL, AH )
207
 
208
	TEST_B( CL, CL )
209
	MOV_B( CL, REGIND(EDX) )
210
 
211
	JZ( LLBL(ctp4_proj) )
212
 
213
LLBL(ctp4_noproj):
214
 
215
	FSTP( ST(0) )			/* */
216
 
217
	MOV_L( CONST(0), DST0 )
218
	MOV_L( CONST(0), DST1 )
219
	MOV_L( CONST(0), DST2 )
220
	MOV_L( CONST(0x3f800000), DST3 )
221
 
222
	JMP( LLBL(ctp4_next) )
223
 
224
LLBL(ctp4_proj):
225
 
226
	FLD_S( SRC0 )			/* F0 F3 */
227
	FMUL2( ST(1), ST0 )
228
 
229
	FLD_S( SRC1 )			/* F1 F0 F3 */
230
	FMUL2( ST(2), ST0 )
231
 
232
	FLD_S( SRC2 )			/* F2 F1 F0 F3 */
233
	FMUL2( ST(3), ST0 )
234
 
235
	FXCH( ST(2) )			/* F0 F1 F2 F3 */
236
	FSTP_S( DST0 )		/* F1 F2 F3 */
237
	FSTP_S( DST1 )		/* F2 F3 */
238
	FSTP_S( DST2 )		/* F3 */
239
	FSTP_S( DST3 )		/* */
240
 
241
LLBL(ctp4_next):
242
 
243
	INC_L( EDX )
244
	ADD_L( CONST(16), EDI )
245
 
246
	ADD_L( ARG_SOURCE, ESI )
247
	CMP_L( EDX, ARG_CLIP )
248
 
249
	JNZ( LLBL(ctp4_top) )
250
 
251
	MOV_L( ARG_OR, ECX )
252
	MOV_L( ARG_AND, EDX )
253
 
254
	MOV_B( AL, REGIND(ECX) )
255
	MOV_B( AH, REGIND(EDX) )
256
 
257
LLBL(ctp4_finish):
258
 
259
	MOV_L( ARG_DEST, EAX )
260
#ifdef ELFPIC
261
	POP_L( ESI )			/* discard ptr to clip_table */
262
#endif
263
	POP_L( EBX )
264
	POP_L( EBP )
265
	POP_L( EDI )
266
	POP_L( ESI )
267
 
268
	RET
269
 
270
 
271
 
272
 
273
 
274
 
275
 
276
ALIGNTEXT16
277
GLOBL GLNAME( _mesa_x86_cliptest_points4_np )
278
GLNAME( _mesa_x86_cliptest_points4_np ):
279
 
280
#ifdef ELFPIC
281
#define FRAME_OFFSET 20
282
#else
283
#define FRAME_OFFSET 16
284
#endif
285
	PUSH_L( ESI )
286
	PUSH_L( EDI )
287
	PUSH_L( EBP )
288
	PUSH_L( EBX )
289
 
290
#ifdef ELFPIC
291
	/* store pointer to clip_table on stack */
292
	CALL( LLBL(ctp4_np_get_eip) )
293
	ADD_L( CONST(_GLOBAL_OFFSET_TABLE_), EBX )
294
	MOV_L( REGOFF(clip_table@GOT, EBX), EBX )
295
	PUSH_L( EBX )
296
	JMP( LLBL(ctp4_np_clip_table_ready) )
297
 
298
LLBL(ctp4_np_get_eip):
299
	/* store eip in ebx */
300
	MOV_L( REGIND(ESP), EBX )
301
	RET
302
 
303
LLBL(ctp4_np_clip_table_ready):
304
#endif
305
 
306
	MOV_L( ARG_SOURCE, ESI )
307
	/* slot */
308
 
309
	MOV_L( ARG_CLIP, EDX )
310
	MOV_L( ARG_OR, EBX )
311
 
312
	MOV_L( ARG_AND, EBP )
313
	MOV_L( REGOFF(V4F_STRIDE, ESI), EAX )
314
 
315
	MOV_L( REGOFF(V4F_COUNT, ESI), ECX )
316
	MOV_L( REGOFF(V4F_START, ESI), ESI )
317
 
318
	MOV_L( EAX, ARG_DEST )   	/* put stride in ARG_DEST */
319
	ADD_L( EDX, ECX )
320
 
321
	MOV_L( ECX, EDI )		/* put clipmask + count in EDI */
322
	CMP_L( ECX, EDX )
323
 
324
	MOV_B( REGIND(EBX), AL )
325
	MOV_B( REGIND(EBP), AH )
326
 
327
	JZ( LLBL(ctp4_np_finish) )
328
 
329
ALIGNTEXT16
330
LLBL(ctp4_np_top):
331
 
332
	MOV_L( SRC3, EBP )
333
	MOV_L( SRC2, EBX )
334
 
335
	XOR_L( ECX, ECX )
336
	ADD_L( EBP, EBP )	/* ebp = abs(S(3))*2 ; carry = sign of S(3) */
337
 
338
	ADC_L( ECX, ECX )
339
	ADD_L( EBX, EBX )	/* ebx = abs(S(2))*2 ; carry = sign of S(2) */
340
 
341
	ADC_L( ECX, ECX )
342
	CMP_L( EBX, EBP )	/* carry = abs(S(2))*2 > abs(S(3))*2 */
343
 
344
	ADC_L( ECX, ECX )
345
	MOV_L( SRC1, EBX )
346
 
347
	ADD_L( EBX, EBX )	/* ebx = abs(S(1))*2 ; carry = sign of S(1) */
348
 
349
	ADC_L( ECX, ECX )
350
	CMP_L( EBX, EBP )	/* carry = abs(S(1))*2 > abs(S(3))*2 */
351
 
352
	ADC_L( ECX, ECX )
353
	MOV_L( SRC0, EBX )
354
 
355
	ADD_L( EBX, EBX )	/* ebx = abs(S(0))*2 ; carry = sign of S(0) */
356
 
357
	ADC_L( ECX, ECX )
358
	CMP_L( EBX, EBP )	/* carry = abs(S(0))*2 > abs(S(3))*2 */
359
 
360
	ADC_L( ECX, ECX )
361
 
362
#ifdef ELFPIC
363
	MOV_L( REGIND(ESP), EBP )	/* clip_table */
364
 
365
	MOV_B( REGBI(EBP, ECX), CL )
366
#else
367
	MOV_B( REGOFF(clip_table,ECX), CL )
368
#endif
369
 
370
	OR_B( CL, AL )
371
	AND_B( CL, AH )
372
 
373
	TEST_B( CL, CL )
374
	MOV_B( CL, REGIND(EDX) )
375
 
376
	INC_L( EDX )
377
	/* slot */
378
 
379
	ADD_L( ARG_DEST, ESI )
380
	CMP_L( EDX, EDI )
381
 
382
	JNZ( LLBL(ctp4_np_top) )
383
 
384
	MOV_L( ARG_OR, ECX )
385
	MOV_L( ARG_AND, EDX )
386
 
387
	MOV_B( AL, REGIND(ECX) )
388
	MOV_B( AH, REGIND(EDX) )
389
 
390
LLBL(ctp4_np_finish):
391
 
392
	MOV_L( ARG_SOURCE, EAX )
393
#ifdef ELFPIC
394
	POP_L( ESI )			/* discard ptr to clip_table */
395
#endif
396
	POP_L( EBX )
397
	POP_L( EBP )
398
	POP_L( EDI )
399
	POP_L( ESI )
400
 
401
	RET