1 /* $Id: x86_cliptest.S,v 1.11 2005/01/04 14:33:47 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
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.
34 #include "clip_args.h"
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)
51 * Table for clip test.
55 * bit4 = abs(S(2)) > abs(S(3))
57 * bit2 = abs(S(1)) > abs(S(3))
59 * bit0 = abs(S(0)) > abs(S(3))
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
86 * _mesa_x86_cliptest_points4
98 #if defined(__ELF__) && defined(__PIC__) && defined(GNU_ASSEMBLER) && !defined(ELFPIC)
103 GLOBL GLNAME( _mesa_x86_cliptest_points4 )
104 HIDDEN(_mesa_x86_cliptest_points4)
105 GLNAME( _mesa_x86_cliptest_points4 ):
108 #define FRAME_OFFSET 20
110 #define FRAME_OFFSET 16
118 /* store pointer to clip_table on stack */
119 CALL( LLBL(ctp4_get_eip) )
120 ADD_L( CONST(_GLOBAL_OFFSET_TABLE_), EBX )
121 MOV_L( REGOFF(clip_table@GOT, EBX), EBX )
123 JMP( LLBL(ctp4_clip_table_ready) )
126 /* store eip in ebx */
127 MOV_L( REGIND(ESP), EBX )
130 LLBL(ctp4_clip_table_ready):
133 MOV_L( ARG_SOURCE, ESI )
134 MOV_L( ARG_DEST, EDI )
136 MOV_L( ARG_CLIP, EDX )
139 MOV_L( ARG_AND, EBP )
140 MOV_L( REGOFF(V4F_STRIDE, ESI), EAX )
142 MOV_L( REGOFF(V4F_COUNT, ESI), ECX )
143 MOV_L( REGOFF(V4F_START, ESI), ESI )
145 OR_L( CONST(VEC_SIZE_4), REGOFF(V4F_FLAGS, EDI) )
146 MOV_L( EAX, ARG_SOURCE ) /* put stride in ARG_SOURCE */
148 MOV_L( CONST(4), REGOFF(V4F_SIZE, EDI) )
149 MOV_L( ECX, REGOFF(V4F_COUNT, EDI) )
151 MOV_L( REGOFF(V4F_START, EDI), EDI )
154 MOV_L( ECX, ARG_CLIP ) /* put clipmask + count in ARG_CLIP */
157 MOV_B( REGIND(EBX), AL )
158 MOV_B( REGIND(EBP), AH )
160 JZ( LLBL(ctp4_finish) )
166 FDIV_S( SRC3 ) /* GH: don't care about div-by-zero */
172 ADD_L( EBP, EBP ) /* ebp = abs(S(3))*2 ; carry = sign of S(3) */
175 ADD_L( EBX, EBX ) /* ebx = abs(S(2))*2 ; carry = sign of S(2) */
178 CMP_L( EBX, EBP ) /* carry = abs(S(2))*2 > abs(S(3))*2 */
183 ADD_L( EBX, EBX ) /* ebx = abs(S(1))*2 ; carry = sign of S(1) */
186 CMP_L( EBX, EBP ) /* carry = abs(S(1))*2 > abs(S(3))*2 */
191 ADD_L( EBX, EBX ) /* ebx = abs(S(0))*2 ; carry = sign of S(0) */
194 CMP_L( EBX, EBP ) /* carry = abs(S(0))*2 > abs(S(3))*2 */
199 MOV_L( REGIND(ESP), EBP ) /* clip_table */
201 MOV_B( REGBI(EBP, ECX), CL )
203 MOV_B( REGOFF(clip_table,ECX), CL )
210 MOV_B( CL, REGIND(EDX) )
212 JZ( LLBL(ctp4_proj) )
218 MOV_L( CONST(0), DST0 )
219 MOV_L( CONST(0), DST1 )
220 MOV_L( CONST(0), DST2 )
221 MOV_L( CONST(0x3f800000), DST3 )
223 JMP( LLBL(ctp4_next) )
227 FLD_S( SRC0 ) /* F0 F3 */
230 FLD_S( SRC1 ) /* F1 F0 F3 */
233 FLD_S( SRC2 ) /* F2 F1 F0 F3 */
236 FXCH( ST(2) ) /* F0 F1 F2 F3 */
237 FSTP_S( DST0 ) /* F1 F2 F3 */
238 FSTP_S( DST1 ) /* F2 F3 */
239 FSTP_S( DST2 ) /* F3 */
245 ADD_L( CONST(16), EDI )
247 ADD_L( ARG_SOURCE, ESI )
248 CMP_L( EDX, ARG_CLIP )
250 JNZ( LLBL(ctp4_top) )
253 MOV_L( ARG_AND, EDX )
255 MOV_B( AL, REGIND(ECX) )
256 MOV_B( AH, REGIND(EDX) )
260 MOV_L( ARG_DEST, EAX )
262 POP_L( ESI ) /* discard ptr to clip_table */
278 GLOBL GLNAME( _mesa_x86_cliptest_points4_np )
279 HIDDEN(_mesa_x86_cliptest_points4_np)
280 GLNAME( _mesa_x86_cliptest_points4_np ):
283 #define FRAME_OFFSET 20
285 #define FRAME_OFFSET 16
293 /* store pointer to clip_table on stack */
294 CALL( LLBL(ctp4_np_get_eip) )
295 ADD_L( CONST(_GLOBAL_OFFSET_TABLE_), EBX )
296 MOV_L( REGOFF(clip_table@GOT, EBX), EBX )
298 JMP( LLBL(ctp4_np_clip_table_ready) )
300 LLBL(ctp4_np_get_eip):
301 /* store eip in ebx */
302 MOV_L( REGIND(ESP), EBX )
305 LLBL(ctp4_np_clip_table_ready):
308 MOV_L( ARG_SOURCE, ESI )
311 MOV_L( ARG_CLIP, EDX )
314 MOV_L( ARG_AND, EBP )
315 MOV_L( REGOFF(V4F_STRIDE, ESI), EAX )
317 MOV_L( REGOFF(V4F_COUNT, ESI), ECX )
318 MOV_L( REGOFF(V4F_START, ESI), ESI )
320 MOV_L( EAX, ARG_DEST ) /* put stride in ARG_DEST */
323 MOV_L( ECX, EDI ) /* put clipmask + count in EDI */
326 MOV_B( REGIND(EBX), AL )
327 MOV_B( REGIND(EBP), AH )
329 JZ( LLBL(ctp4_np_finish) )
338 ADD_L( EBP, EBP ) /* ebp = abs(S(3))*2 ; carry = sign of S(3) */
341 ADD_L( EBX, EBX ) /* ebx = abs(S(2))*2 ; carry = sign of S(2) */
344 CMP_L( EBX, EBP ) /* carry = abs(S(2))*2 > abs(S(3))*2 */
349 ADD_L( EBX, EBX ) /* ebx = abs(S(1))*2 ; carry = sign of S(1) */
352 CMP_L( EBX, EBP ) /* carry = abs(S(1))*2 > abs(S(3))*2 */
357 ADD_L( EBX, EBX ) /* ebx = abs(S(0))*2 ; carry = sign of S(0) */
360 CMP_L( EBX, EBP ) /* carry = abs(S(0))*2 > abs(S(3))*2 */
365 MOV_L( REGIND(ESP), EBP ) /* clip_table */
367 MOV_B( REGBI(EBP, ECX), CL )
369 MOV_B( REGOFF(clip_table,ECX), CL )
376 MOV_B( CL, REGIND(EDX) )
381 ADD_L( ARG_DEST, ESI )
384 JNZ( LLBL(ctp4_np_top) )
387 MOV_L( ARG_AND, EDX )
389 MOV_B( AL, REGIND(ECX) )
390 MOV_B( AH, REGIND(EDX) )
392 LLBL(ctp4_np_finish):
394 MOV_L( ARG_SOURCE, EAX )
396 POP_L( ESI ) /* discard ptr to clip_table */