1fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
2fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes/*
3fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes * Mesa 3-D graphics library
4fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes * Version:  3.5
5fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes *
60a59ca6cae6ef24990f1c41c8c7857214489443cGareth Hughes * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
7fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes *
8fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes * Permission is hereby granted, free of charge, to any person obtaining a
9fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes * copy of this software and associated documentation files (the "Software"),
10fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes * to deal in the Software without restriction, including without limitation
11fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes * and/or sell copies of the Software, and to permit persons to whom the
13fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes * Software is furnished to do so, subject to the following conditions:
14fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes *
15fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes * The above copyright notice and this permission notice shall be included
16fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes * in all copies or substantial portions of the Software.
17fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes *
18fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
21fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes */
25fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
260b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul/*
270b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul * NOTE: Avoid using spaces in between '(' ')' and arguments, especially
280b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul * with macros like CONST, LLBL that expand to CONCAT(...).  Putting spaces
290b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul * in there will break the build on some platforms.
300b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul */
310b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul
323474e9de924d92a941b4ea33ecc694f5fad2651fJosé Fonseca#include "assyntax.h"
330a59ca6cae6ef24990f1c41c8c7857214489443cGareth Hughes#include "matypes.h"
34fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes#include "clip_args.h"
35fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
360b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul#define SRC0		REGOFF(0, ESI)
370b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul#define SRC1		REGOFF(4, ESI)
380b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul#define SRC2		REGOFF(8, ESI)
390b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul#define SRC3		REGOFF(12, ESI)
400b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul#define DST0		REGOFF(0, EDI)
410b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul#define DST1		REGOFF(4, EDI)
420b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul#define DST2		REGOFF(8, EDI)
430b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul#define DST3		REGOFF(12, EDI)
440b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul#define MAT0		REGOFF(0, EDX)
450b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul#define MAT1		REGOFF(4, EDX)
460b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul#define MAT2		REGOFF(8, EDX)
470b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul#define MAT3		REGOFF(12, EDX)
48fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
49fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
50fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes/*
51fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes * Table for clip test.
52fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes *
530b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul * 	bit6 = SRC3 < 0
540b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul * 	bit5 = SRC2 < 0
55fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes * 	bit4 = abs(S(2)) > abs(S(3))
560b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul * 	bit3 = SRC1 < 0
57fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes * 	bit2 = abs(S(1)) > abs(S(3))
580b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul * 	bit1 = SRC0 < 0
59fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes * 	bit0 = abs(S(0)) > abs(S(3))
60fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes */
61fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
62fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	SEG_DATA
63fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
64fc2427e81b1c648550d0368652d6a475df785027Gareth Hughesclip_table:
65e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes	D_BYTE 0x00, 0x01, 0x00, 0x02, 0x04, 0x05, 0x04, 0x06
66e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes	D_BYTE 0x00, 0x01, 0x00, 0x02, 0x08, 0x09, 0x08, 0x0a
67e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes	D_BYTE 0x20, 0x21, 0x20, 0x22, 0x24, 0x25, 0x24, 0x26
68e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes	D_BYTE 0x20, 0x21, 0x20, 0x22, 0x28, 0x29, 0x28, 0x2a
69e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes	D_BYTE 0x00, 0x01, 0x00, 0x02, 0x04, 0x05, 0x04, 0x06
70e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes	D_BYTE 0x00, 0x01, 0x00, 0x02, 0x08, 0x09, 0x08, 0x0a
71e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes	D_BYTE 0x10, 0x11, 0x10, 0x12, 0x14, 0x15, 0x14, 0x16
72e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes	D_BYTE 0x10, 0x11, 0x10, 0x12, 0x18, 0x19, 0x18, 0x1a
73e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes	D_BYTE 0x3f, 0x3d, 0x3f, 0x3e, 0x37, 0x35, 0x37, 0x36
74e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes	D_BYTE 0x3f, 0x3d, 0x3f, 0x3e, 0x3b, 0x39, 0x3b, 0x3a
75e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes	D_BYTE 0x2f, 0x2d, 0x2f, 0x2e, 0x27, 0x25, 0x27, 0x26
76e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes	D_BYTE 0x2f, 0x2d, 0x2f, 0x2e, 0x2b, 0x29, 0x2b, 0x2a
77e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes	D_BYTE 0x3f, 0x3d, 0x3f, 0x3e, 0x37, 0x35, 0x37, 0x36
78e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes	D_BYTE 0x3f, 0x3d, 0x3f, 0x3e, 0x3b, 0x39, 0x3b, 0x3a
79e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes	D_BYTE 0x1f, 0x1d, 0x1f, 0x1e, 0x17, 0x15, 0x17, 0x16
80e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes	D_BYTE 0x1f, 0x1d, 0x1f, 0x1e, 0x1b, 0x19, 0x1b, 0x1a
81fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
82fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
83fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	SEG_TEXT
84fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
85fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes/*
86865322f931197c5c73c57b366b64300894565dabBrian Paul * _mesa_x86_cliptest_points4
87fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes *
88fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes *   AL:  ormask
89fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes *   AH:  andmask
90fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes *   EBX: temp0
91fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes *   ECX: temp1
92fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes *   EDX: clipmask[]
93fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes *   ESI: clip[]
94fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes *   EDI: proj[]
95fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes *   EBP: temp2
96fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes */
97fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
9835883ceb9389f9e5b4be8233f2326367c6aecddbBrian Paul#if defined(__ELF__) && defined(__PIC__) && defined(GNU_ASSEMBLER) && !defined(ELFPIC)
99fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes#define ELFPIC
100fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes#endif
101fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
102fc2427e81b1c648550d0368652d6a475df785027Gareth HughesALIGNTEXT16
103865322f931197c5c73c57b366b64300894565dabBrian PaulGLOBL GLNAME( _mesa_x86_cliptest_points4 )
104932dee87e3002be87dc3bcc49efd8ac9ac3e1fa4Brian PaulHIDDEN(_mesa_x86_cliptest_points4)
105865322f931197c5c73c57b366b64300894565dabBrian PaulGLNAME( _mesa_x86_cliptest_points4 ):
106fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
107fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes#ifdef ELFPIC
108fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes#define FRAME_OFFSET 20
109fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes#else
110fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes#define FRAME_OFFSET 16
111fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes#endif
112fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	PUSH_L( ESI )
113fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	PUSH_L( EDI )
114fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	PUSH_L( EBP )
115fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	PUSH_L( EBX )
116fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
117fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes#ifdef ELFPIC
118fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	/* store pointer to clip_table on stack */
1190b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	CALL( LLBL(ctp4_get_eip) )
120fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	ADD_L( CONST(_GLOBAL_OFFSET_TABLE_), EBX )
121fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_L( REGOFF(clip_table@GOT, EBX), EBX )
122fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	PUSH_L( EBX )
1230b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	JMP( LLBL(ctp4_clip_table_ready) )
124fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
1250b2fa873c6da02f169a76d74d3bedd91236f8e28Brian PaulLLBL(ctp4_get_eip):
126fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	/* store eip in ebx */
127fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_L( REGIND(ESP), EBX )
128fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	RET
129fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
1300b2fa873c6da02f169a76d74d3bedd91236f8e28Brian PaulLLBL(ctp4_clip_table_ready):
131fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes#endif
132fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
133fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_L( ARG_SOURCE, ESI )
134fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_L( ARG_DEST, EDI )
135fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
136fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_L( ARG_CLIP, EDX )
137fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_L( ARG_OR, EBX )
138fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
139fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_L( ARG_AND, EBP )
140fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_L( REGOFF(V4F_STRIDE, ESI), EAX )
141fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
142fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_L( REGOFF(V4F_COUNT, ESI), ECX )
143fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_L( REGOFF(V4F_START, ESI), ESI )
144fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
145fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	OR_L( CONST(VEC_SIZE_4), REGOFF(V4F_FLAGS, EDI) )
146fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_L( EAX, ARG_SOURCE )	/* put stride in ARG_SOURCE */
147fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
148cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell	MOV_L( CONST(4), REGOFF(V4F_SIZE, EDI) )
149fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_L( ECX, REGOFF(V4F_COUNT, EDI) )
150fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
151fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_L( REGOFF(V4F_START, EDI), EDI )
152fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	ADD_L( EDX, ECX )
153fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
154fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_L( ECX, ARG_CLIP )		/* put clipmask + count in ARG_CLIP */
155fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	CMP_L( ECX, EDX )
156fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
157fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_B( REGIND(EBX), AL )
158fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_B( REGIND(EBP), AH )
159fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
1600b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	JZ( LLBL(ctp4_finish) )
161fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
162fc2427e81b1c648550d0368652d6a475df785027Gareth HughesALIGNTEXT16
1630b2fa873c6da02f169a76d74d3bedd91236f8e28Brian PaulLLBL(ctp4_top):
164fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
16553e4ebd4e36c0ae462d71c87cda3533f9d001324Gareth Hughes	FLD1				/* F3 */
1660b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	FDIV_S( SRC3 )		/* GH: don't care about div-by-zero */
167fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
1680b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	MOV_L( SRC3, EBP )
1690b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	MOV_L( SRC2, EBX )
170fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
171fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	XOR_L( ECX, ECX )
172fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	ADD_L( EBP, EBP )	/* ebp = abs(S(3))*2 ; carry = sign of S(3) */
173fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
174fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	ADC_L( ECX, ECX )
175fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	ADD_L( EBX, EBX )	/* ebx = abs(S(2))*2 ; carry = sign of S(2) */
176fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
177fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	ADC_L( ECX, ECX )
178fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	CMP_L( EBX, EBP )	/* carry = abs(S(2))*2 > abs(S(3))*2 */
179fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
180fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	ADC_L( ECX, ECX )
1810b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	MOV_L( SRC1, EBX )
182fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
183fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	ADD_L( EBX, EBX )	/* ebx = abs(S(1))*2 ; carry = sign of S(1) */
184fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
185fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	ADC_L( ECX, ECX )
186fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	CMP_L( EBX, EBP )	/* carry = abs(S(1))*2 > abs(S(3))*2 */
187fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
188fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	ADC_L( ECX, ECX )
1890b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	MOV_L( SRC0, EBX )
190fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
191fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	ADD_L( EBX, EBX )	/* ebx = abs(S(0))*2 ; carry = sign of S(0) */
192fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
193fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	ADC_L( ECX, ECX )
194fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	CMP_L( EBX, EBP )	/* carry = abs(S(0))*2 > abs(S(3))*2 */
195fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
196fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	ADC_L( ECX, ECX )
197fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
198fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes#ifdef ELFPIC
199fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_L( REGIND(ESP), EBP )	/* clip_table */
200fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
201fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_B( REGBI(EBP, ECX), CL )
202fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes#else
203fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_B( REGOFF(clip_table,ECX), CL )
204fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes#endif
205fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
206fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	OR_B( CL, AL )
207fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	AND_B( CL, AH )
208fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
209fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	TEST_B( CL, CL )
210fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_B( CL, REGIND(EDX) )
211fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
2120b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	JZ( LLBL(ctp4_proj) )
213fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
2140b2fa873c6da02f169a76d74d3bedd91236f8e28Brian PaulLLBL(ctp4_noproj):
21553e4ebd4e36c0ae462d71c87cda3533f9d001324Gareth Hughes
216e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes	FSTP( ST(0) )			/* */
21753e4ebd4e36c0ae462d71c87cda3533f9d001324Gareth Hughes
2180b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	MOV_L( CONST(0), DST0 )
2190b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	MOV_L( CONST(0), DST1 )
2200b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	MOV_L( CONST(0), DST2 )
2210b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	MOV_L( CONST(0x3f800000), DST3 )
22253e4ebd4e36c0ae462d71c87cda3533f9d001324Gareth Hughes
2230b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	JMP( LLBL(ctp4_next) )
224fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
2250b2fa873c6da02f169a76d74d3bedd91236f8e28Brian PaulLLBL(ctp4_proj):
226fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
2270b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	FLD_S( SRC0 )			/* F0 F3 */
2280b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	FMUL2( ST(1), ST0 )
229fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
2300b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	FLD_S( SRC1 )			/* F1 F0 F3 */
2310b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	FMUL2( ST(2), ST0 )
232fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
2330b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	FLD_S( SRC2 )			/* F2 F1 F0 F3 */
2340b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	FMUL2( ST(3), ST0 )
235fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
236fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	FXCH( ST(2) )			/* F0 F1 F2 F3 */
2370b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	FSTP_S( DST0 )		/* F1 F2 F3 */
2380b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	FSTP_S( DST1 )		/* F2 F3 */
2390b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	FSTP_S( DST2 )		/* F3 */
2400b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	FSTP_S( DST3 )		/* */
241fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
2420b2fa873c6da02f169a76d74d3bedd91236f8e28Brian PaulLLBL(ctp4_next):
243fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
244fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	INC_L( EDX )
245fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	ADD_L( CONST(16), EDI )
246fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
247fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	ADD_L( ARG_SOURCE, ESI )
248fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	CMP_L( EDX, ARG_CLIP )
249fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
2500b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	JNZ( LLBL(ctp4_top) )
251fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
252fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_L( ARG_OR, ECX )
253fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_L( ARG_AND, EDX )
254fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
255fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_B( AL, REGIND(ECX) )
256fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_B( AH, REGIND(EDX) )
257fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
2580b2fa873c6da02f169a76d74d3bedd91236f8e28Brian PaulLLBL(ctp4_finish):
259fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
260fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	MOV_L( ARG_DEST, EAX )
261fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes#ifdef ELFPIC
262fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	POP_L( ESI )			/* discard ptr to clip_table */
263fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes#endif
264fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	POP_L( EBX )
265fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	POP_L( EBP )
266fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	POP_L( EDI )
267fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	POP_L( ESI )
268fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes
269fc2427e81b1c648550d0368652d6a475df785027Gareth Hughes	RET
270321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
271321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
272321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
273321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
274321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
275321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
276321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
277321f67c4729adeebd7aa9ef9e22c95e709952851Keith WhitwellALIGNTEXT16
278865322f931197c5c73c57b366b64300894565dabBrian PaulGLOBL GLNAME( _mesa_x86_cliptest_points4_np )
279932dee87e3002be87dc3bcc49efd8ac9ac3e1fa4Brian PaulHIDDEN(_mesa_x86_cliptest_points4_np)
280865322f931197c5c73c57b366b64300894565dabBrian PaulGLNAME( _mesa_x86_cliptest_points4_np ):
281321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
282321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell#ifdef ELFPIC
283321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell#define FRAME_OFFSET 20
284321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell#else
285321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell#define FRAME_OFFSET 16
286321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell#endif
287321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	PUSH_L( ESI )
288321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	PUSH_L( EDI )
289321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	PUSH_L( EBP )
290321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	PUSH_L( EBX )
291321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
292321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell#ifdef ELFPIC
293321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	/* store pointer to clip_table on stack */
2940b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	CALL( LLBL(ctp4_np_get_eip) )
295321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	ADD_L( CONST(_GLOBAL_OFFSET_TABLE_), EBX )
296321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_L( REGOFF(clip_table@GOT, EBX), EBX )
297321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	PUSH_L( EBX )
2980b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	JMP( LLBL(ctp4_np_clip_table_ready) )
299321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
3000b2fa873c6da02f169a76d74d3bedd91236f8e28Brian PaulLLBL(ctp4_np_get_eip):
301321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	/* store eip in ebx */
302321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_L( REGIND(ESP), EBX )
303321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	RET
304321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
3050b2fa873c6da02f169a76d74d3bedd91236f8e28Brian PaulLLBL(ctp4_np_clip_table_ready):
306321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell#endif
307321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
308321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_L( ARG_SOURCE, ESI )
309321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	/* slot */
310321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
311321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_L( ARG_CLIP, EDX )
312321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_L( ARG_OR, EBX )
313321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
314321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_L( ARG_AND, EBP )
315321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_L( REGOFF(V4F_STRIDE, ESI), EAX )
316321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
317321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_L( REGOFF(V4F_COUNT, ESI), ECX )
318321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_L( REGOFF(V4F_START, ESI), ESI )
319321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
320321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_L( EAX, ARG_DEST )   	/* put stride in ARG_DEST */
321321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	ADD_L( EDX, ECX )
322321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
323321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_L( ECX, EDI )		/* put clipmask + count in EDI */
324321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	CMP_L( ECX, EDX )
325321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
326321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_B( REGIND(EBX), AL )
327321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_B( REGIND(EBP), AH )
328321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
3290b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	JZ( LLBL(ctp4_np_finish) )
330321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
331321f67c4729adeebd7aa9ef9e22c95e709952851Keith WhitwellALIGNTEXT16
3320b2fa873c6da02f169a76d74d3bedd91236f8e28Brian PaulLLBL(ctp4_np_top):
333321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
3340b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	MOV_L( SRC3, EBP )
3350b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	MOV_L( SRC2, EBX )
336321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
337321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	XOR_L( ECX, ECX )
338321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	ADD_L( EBP, EBP )	/* ebp = abs(S(3))*2 ; carry = sign of S(3) */
339321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
340321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	ADC_L( ECX, ECX )
341321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	ADD_L( EBX, EBX )	/* ebx = abs(S(2))*2 ; carry = sign of S(2) */
342321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
343321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	ADC_L( ECX, ECX )
344321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	CMP_L( EBX, EBP )	/* carry = abs(S(2))*2 > abs(S(3))*2 */
345321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
346321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	ADC_L( ECX, ECX )
3470b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	MOV_L( SRC1, EBX )
348321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
349321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	ADD_L( EBX, EBX )	/* ebx = abs(S(1))*2 ; carry = sign of S(1) */
350321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
351321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	ADC_L( ECX, ECX )
352321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	CMP_L( EBX, EBP )	/* carry = abs(S(1))*2 > abs(S(3))*2 */
353321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
354321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	ADC_L( ECX, ECX )
3550b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	MOV_L( SRC0, EBX )
356321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
357321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	ADD_L( EBX, EBX )	/* ebx = abs(S(0))*2 ; carry = sign of S(0) */
358321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
359321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	ADC_L( ECX, ECX )
360321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	CMP_L( EBX, EBP )	/* carry = abs(S(0))*2 > abs(S(3))*2 */
361321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
362321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	ADC_L( ECX, ECX )
363321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
364321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell#ifdef ELFPIC
365321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_L( REGIND(ESP), EBP )	/* clip_table */
366321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
367321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_B( REGBI(EBP, ECX), CL )
368321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell#else
369321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_B( REGOFF(clip_table,ECX), CL )
370321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell#endif
371321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
372321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	OR_B( CL, AL )
373321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	AND_B( CL, AH )
374321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
375321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	TEST_B( CL, CL )
376321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_B( CL, REGIND(EDX) )
377321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
378321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	INC_L( EDX )
379321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	/* slot */
380321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
381321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	ADD_L( ARG_DEST, ESI )
382321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	CMP_L( EDX, EDI )
383321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
3840b2fa873c6da02f169a76d74d3bedd91236f8e28Brian Paul	JNZ( LLBL(ctp4_np_top) )
385321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
386321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_L( ARG_OR, ECX )
387321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_L( ARG_AND, EDX )
388321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
389321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_B( AL, REGIND(ECX) )
390321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_B( AH, REGIND(EDX) )
391321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
3920b2fa873c6da02f169a76d74d3bedd91236f8e28Brian PaulLLBL(ctp4_np_finish):
393321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
394321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	MOV_L( ARG_SOURCE, EAX )
395321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell#ifdef ELFPIC
396321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	POP_L( ESI )			/* discard ptr to clip_table */
397321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell#endif
398321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	POP_L( EBX )
399321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	POP_L( EBP )
400321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	POP_L( EDI )
401321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	POP_L( ESI )
402321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell
403321f67c4729adeebd7aa9ef9e22c95e709952851Keith Whitwell	RET
404fcdc6a7d2488defd66bc7e8398c6d8c9a6190a1aKristian Høgsberg
405fcdc6a7d2488defd66bc7e8398c6d8c9a6190a1aKristian Høgsberg#if defined (__ELF__) && defined (__linux__)
406fcdc6a7d2488defd66bc7e8398c6d8c9a6190a1aKristian Høgsberg	.section .note.GNU-stack,"",%progbits
407fcdc6a7d2488defd66bc7e8398c6d8c9a6190a1aKristian Høgsberg#endif
408