1848b8605Smrg 2848b8605Smrg/* 3848b8605Smrg * Mesa 3-D graphics library 4848b8605Smrg * 5848b8605Smrg * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. 6848b8605Smrg * 7848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 8848b8605Smrg * copy of this software and associated documentation files (the "Software"), 9848b8605Smrg * to deal in the Software without restriction, including without limitation 10848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the 12848b8605Smrg * Software is furnished to do so, subject to the following conditions: 13848b8605Smrg * 14848b8605Smrg * The above copyright notice and this permission notice shall be included 15848b8605Smrg * in all copies or substantial portions of the Software. 16848b8605Smrg * 17848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 21848b8605Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22848b8605Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23848b8605Smrg * OTHER DEALINGS IN THE SOFTWARE. 24848b8605Smrg */ 25848b8605Smrg 26848b8605Smrg#ifdef USE_SSE_ASM 27848b8605Smrg#include "assyntax.h" 28848b8605Smrg#include "matypes.h" 29848b8605Smrg#include "xform_args.h" 30848b8605Smrg 31848b8605Smrg SEG_TEXT 32848b8605Smrg 33848b8605Smrg#define FRAME_OFFSET 8 34848b8605Smrg 35848b8605Smrg#define SRC(i) REGOFF(i * 4, ESI) 36848b8605Smrg#define DST(i) REGOFF(i * 4, EDI) 37848b8605Smrg#define MAT(i) REGOFF(i * 4, EDX) 38848b8605Smrg 39848b8605Smrg#define SELECT(r0, r1, r2, r3) CONST( r0 * 64 + r1 * 16 + r2 * 4 + r3 ) 40848b8605Smrg 41848b8605Smrg 42848b8605SmrgALIGNTEXT16 43848b8605SmrgGLOBL GLNAME( _mesa_sse_transform_points4_general ) 44848b8605SmrgHIDDEN(_mesa_sse_transform_points4_general) 45848b8605SmrgGLNAME( _mesa_sse_transform_points4_general ): 46848b8605Smrg 47848b8605Smrg PUSH_L( ESI ) 48848b8605Smrg PUSH_L( EDI ) 49848b8605Smrg 50848b8605Smrg MOV_L( ARG_SOURCE, ESI ) 51848b8605Smrg MOV_L( ARG_DEST, EDI ) 52848b8605Smrg 53848b8605Smrg MOV_L( ARG_MATRIX, EDX ) 54848b8605Smrg MOV_L( REGOFF(V4F_COUNT, ESI), ECX ) 55848b8605Smrg 56848b8605Smrg TEST_L( ECX, ECX ) /* verify non-zero count */ 57848b8605Smrg JE( LLBL( sse_general_done ) ) 58848b8605Smrg 59848b8605Smrg MOV_L( REGOFF(V4F_STRIDE, ESI), EAX ) /* stride */ 60848b8605Smrg OR_L( CONST(VEC_SIZE_4), REGOFF(V4F_FLAGS, EDI) ) /* set dest flags */ 61848b8605Smrg 62848b8605Smrg MOV_L( ECX, REGOFF(V4F_COUNT, EDI) ) /* set dest count */ 63848b8605Smrg MOV_L( CONST(4), REGOFF(V4F_SIZE, EDI) )/* set dest size */ 64848b8605Smrg 65848b8605Smrg MOV_L( REGOFF(V4F_START, ESI), ESI ) /* ptr to first source vertex */ 66848b8605Smrg MOV_L( REGOFF(V4F_START, EDI), EDI ) /* ptr to first dest vertex */ 67848b8605Smrg 68848b8605Smrg PREFETCHT0( REGIND(ESI) ) 69848b8605Smrg 70848b8605Smrg MOVAPS( MAT(0), XMM4 ) /* m3 | m2 | m1 | m0 */ 71848b8605Smrg MOVAPS( MAT(4), XMM5 ) /* m7 | m6 | m5 | m4 */ 72848b8605Smrg MOVAPS( MAT(8), XMM6 ) /* m11 | m10 | m9 | m8 */ 73848b8605Smrg MOVAPS( MAT(12), XMM7 ) /* m15 | m14 | m13 | m12 */ 74848b8605Smrg 75848b8605SmrgALIGNTEXT16 76848b8605SmrgLLBL( sse_general_loop ): 77848b8605Smrg 78848b8605Smrg MOVSS( SRC(0), XMM0 ) /* ox */ 79848b8605Smrg SHUFPS( CONST(0x0), XMM0, XMM0 ) /* ox | ox | ox | ox */ 80848b8605Smrg MULPS( XMM4, XMM0 ) /* ox*m3 | ox*m2 | ox*m1 | ox*m0 */ 81848b8605Smrg 82848b8605Smrg MOVSS( SRC(1), XMM1 ) /* oy */ 83848b8605Smrg SHUFPS( CONST(0x0), XMM1, XMM1 ) /* oy | oy | oy | oy */ 84848b8605Smrg MULPS( XMM5, XMM1 ) /* oy*m7 | oy*m6 | oy*m5 | oy*m4 */ 85848b8605Smrg 86848b8605Smrg MOVSS( SRC(2), XMM2 ) /* oz */ 87848b8605Smrg SHUFPS( CONST(0x0), XMM2, XMM2 ) /* oz | oz | oz | oz */ 88848b8605Smrg MULPS( XMM6, XMM2 ) /* oz*m11 | oz*m10 | oz*m9 | oz*m8 */ 89848b8605Smrg 90848b8605Smrg MOVSS( SRC(3), XMM3 ) /* ow */ 91848b8605Smrg SHUFPS( CONST(0x0), XMM3, XMM3 ) /* ow | ow | ow | ow */ 92848b8605Smrg MULPS( XMM7, XMM3 ) /* ow*m15 | ow*m14 | ow*m13 | ow*m12 */ 93848b8605Smrg 94848b8605Smrg ADDPS( XMM1, XMM0 ) /* ox*m3+oy*m7 | ... */ 95848b8605Smrg ADDPS( XMM2, XMM0 ) /* ox*m3+oy*m7+oz*m11 | ... */ 96848b8605Smrg ADDPS( XMM3, XMM0 ) /* ox*m3+oy*m7+oz*m11+ow*m15 | ... */ 97848b8605Smrg MOVAPS( XMM0, DST(0) ) /* ->D(3) | ->D(2) | ->D(1) | ->D(0) */ 98848b8605Smrg 99848b8605Smrg ADD_L( CONST(16), EDI ) 100848b8605Smrg ADD_L( EAX, ESI ) 101848b8605Smrg 102848b8605Smrg DEC_L( ECX ) 103848b8605Smrg JNZ( LLBL( sse_general_loop ) ) 104848b8605Smrg 105848b8605SmrgLLBL( sse_general_done ): 106848b8605Smrg 107848b8605Smrg POP_L( EDI ) 108848b8605Smrg POP_L( ESI ) 109848b8605Smrg RET 110848b8605Smrg 111848b8605Smrg 112848b8605Smrg 113848b8605Smrg 114848b8605SmrgALIGNTEXT4 115848b8605SmrgGLOBL GLNAME( _mesa_sse_transform_points4_3d ) 116848b8605SmrgHIDDEN(_mesa_sse_transform_points4_3d) 117848b8605SmrgGLNAME( _mesa_sse_transform_points4_3d ): 118848b8605Smrg 119848b8605Smrg PUSH_L( ESI ) 120848b8605Smrg PUSH_L( EDI ) 121848b8605Smrg 122848b8605Smrg MOV_L( ARG_SOURCE, ESI ) /* ptr to source GLvector4f */ 123848b8605Smrg MOV_L( ARG_DEST, EDI ) /* ptr to dest GLvector4f */ 124848b8605Smrg 125848b8605Smrg MOV_L( ARG_MATRIX, EDX ) /* ptr to matrix */ 126848b8605Smrg MOV_L( REGOFF(V4F_COUNT, ESI), ECX ) /* source count */ 127848b8605Smrg 128848b8605Smrg TEST_L( ECX, ECX) 129848b8605Smrg JZ( LLBL(K_GTP43P3DR_finish) ) /* count was zero; go to finish */ 130848b8605Smrg 131848b8605Smrg MOV_L( REGOFF(V4F_STRIDE, ESI), EAX ) /* stride */ 132848b8605Smrg OR_L( CONST(VEC_SIZE_3), REGOFF(V4F_FLAGS, EDI) ) /* set dest flags */ 133848b8605Smrg 134848b8605Smrg MOV_L( ECX, REGOFF(V4F_COUNT, EDI) ) /* set dest count */ 135848b8605Smrg MOV_L( CONST(3), REGOFF(V4F_SIZE, EDI) )/* set dest size */ 136848b8605Smrg 137848b8605Smrg SHL_L( CONST(4), ECX ) /* count *= 16 */ 138848b8605Smrg MOV_L( REGOFF(V4F_START, ESI), ESI ) /* ptr to first source vertex */ 139848b8605Smrg 140848b8605Smrg MOV_L( REGOFF(V4F_START, EDI), EDI ) /* ptr to first dest vertex */ 141848b8605Smrg ADD_L( EDI, ECX ) /* count += dest ptr */ 142848b8605Smrg 143848b8605Smrg MOVAPS( MAT(0), XMM0 ) /* m3 | m2 | m1 | m0 */ 144848b8605Smrg MOVAPS( MAT(4), XMM1 ) /* m7 | m6 | m5 | m4 */ 145848b8605Smrg MOVAPS( MAT(8), XMM2 ) /* m11 | m10 | m9 | m8 */ 146848b8605Smrg MOVAPS( MAT(12), XMM3 ) /* m15 | m14 | m13 | m12 */ 147848b8605Smrg 148848b8605SmrgALIGNTEXT32 149848b8605SmrgLLBL( K_GTP43P3DR_top ): 150848b8605Smrg MOVSS( SRC(0), XMM4 ) /* ox */ 151848b8605Smrg SHUFPS( CONST(0x0), XMM4, XMM4 ) /* ox | ox | ox | ox */ 152848b8605Smrg MULPS( XMM0, XMM4 ) /* ox*m3 | ox*m2 | ox*m1 | ox*m0 */ 153848b8605Smrg 154848b8605Smrg MOVSS( SRC(1), XMM5 ) /* oy */ 155848b8605Smrg SHUFPS( CONST(0x0), XMM5, XMM5 ) /* oy | oy | oy | oy */ 156848b8605Smrg MULPS( XMM1, XMM5 ) /* oy*m7 | oy*m6 | oy*m5 | oy*m4 */ 157848b8605Smrg 158848b8605Smrg MOVSS( SRC(2), XMM6 ) /* oz */ 159848b8605Smrg SHUFPS( CONST(0x0), XMM6, XMM6 ) /* oz | oz | oz | oz */ 160848b8605Smrg MULPS( XMM2, XMM6 ) /* oz*m11 | oz*m10 | oz*m9 | oz*m8 */ 161848b8605Smrg 162848b8605Smrg MOVSS( SRC(3), XMM7 ) /* ow */ 163848b8605Smrg SHUFPS( CONST(0x0), XMM7, XMM7 ) /* ow | ow | ow | ow */ 164848b8605Smrg MULPS( XMM3, XMM7 ) /* ow*m15 | ow*m14 | ow*m13 | ow*m12 */ 165848b8605Smrg 166848b8605Smrg ADDPS( XMM5, XMM4 ) /* ox*m3+oy*m7 | ... */ 167848b8605Smrg ADDPS( XMM6, XMM4 ) /* ox*m3+oy*m7+oz*m11 | ... */ 168848b8605Smrg ADDPS( XMM7, XMM4 ) /* ox*m3+oy*m7+oz*m11+ow*m15 | ... */ 169848b8605Smrg MOVAPS( XMM4, DST(0) ) /* ->D(3) | ->D(2) | ->D(1) | ->D(0) */ 170848b8605Smrg 171848b8605Smrg MOVSS( SRC(3), XMM4 ) /* ow */ 172848b8605Smrg MOVSS( XMM4, DST(3) ) /* ->D(3) */ 173848b8605Smrg 174848b8605SmrgLLBL( K_GTP43P3DR_skip ): 175848b8605Smrg ADD_L( CONST(16), EDI ) 176848b8605Smrg ADD_L( EAX, ESI ) 177848b8605Smrg CMP_L( ECX, EDI ) 178848b8605Smrg JNE( LLBL(K_GTP43P3DR_top) ) 179848b8605Smrg 180848b8605SmrgLLBL( K_GTP43P3DR_finish ): 181848b8605Smrg POP_L( EDI ) 182848b8605Smrg POP_L( ESI ) 183848b8605Smrg RET 184848b8605Smrg 185848b8605Smrg 186848b8605SmrgALIGNTEXT16 187848b8605SmrgGLOBL GLNAME( _mesa_sse_transform_points4_identity ) 188848b8605SmrgHIDDEN(_mesa_sse_transform_points4_identity) 189848b8605SmrgGLNAME( _mesa_sse_transform_points4_identity ): 190848b8605Smrg 191848b8605Smrg PUSH_L( ESI ) 192848b8605Smrg PUSH_L( EDI ) 193848b8605Smrg 194848b8605Smrg MOV_L( ARG_SOURCE, ESI ) 195848b8605Smrg MOV_L( ARG_DEST, EDI ) 196848b8605Smrg 197848b8605Smrg MOV_L( ARG_MATRIX, EDX ) 198848b8605Smrg MOV_L( REGOFF(V4F_COUNT, ESI), ECX ) 199848b8605Smrg 200848b8605Smrg TEST_L( ECX, ECX ) /* verify non-zero count */ 201848b8605Smrg JE( LLBL( sse_identity_done ) ) 202848b8605Smrg 203848b8605Smrg MOV_L( REGOFF(V4F_STRIDE, ESI), EAX ) /* stride */ 204848b8605Smrg OR_L( CONST(VEC_SIZE_4), REGOFF(V4F_FLAGS, EDI) ) /* set dest flags */ 205848b8605Smrg 206848b8605Smrg MOV_L( ECX, REGOFF(V4F_COUNT, EDI) ) /* set dest count */ 207848b8605Smrg MOV_L( CONST(4), REGOFF(V4F_SIZE, EDI) )/* set dest size */ 208848b8605Smrg 209848b8605Smrg MOV_L( REGOFF(V4F_START, ESI), ESI ) /* ptr to first source vertex */ 210848b8605Smrg MOV_L( REGOFF(V4F_START, EDI), EDI ) /* ptr to first dest vertex */ 211848b8605Smrg 212848b8605SmrgALIGNTEXT16 213848b8605SmrgLLBL( sse_identity_loop ): 214848b8605Smrg 215848b8605Smrg PREFETCHNTA( REGOFF(32, ESI) ) 216848b8605Smrg 217848b8605Smrg MOVAPS( REGIND(ESI), XMM0 ) 218848b8605Smrg ADD_L( EAX, ESI ) 219848b8605Smrg 220848b8605Smrg MOVAPS( XMM0, REGIND(EDI) ) 221848b8605Smrg ADD_L( CONST(16), EDI ) 222848b8605Smrg 223848b8605Smrg DEC_L( ECX ) 224848b8605Smrg JNZ( LLBL( sse_identity_loop ) ) 225848b8605Smrg 226848b8605SmrgLLBL( sse_identity_done ): 227848b8605Smrg 228848b8605Smrg POP_L( EDI ) 229848b8605Smrg POP_L( ESI ) 230848b8605Smrg RET 231848b8605Smrg#endif 232848b8605Smrg 233848b8605Smrg#if defined (__ELF__) && defined (__linux__) 234848b8605Smrg .section .note.GNU-stack,"",%progbits 235848b8605Smrg#endif 236