1 2/* 3 * Mesa 3-D graphics library 4 * 5 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a 8 * copy of this software and associated documentation files (the "Software"), 9 * to deal in the Software without restriction, including without limitation 10 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 * and/or sell copies of the Software, and to permit persons to whom the 12 * Software is furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included 15 * in all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 * OTHER DEALINGS IN THE SOFTWARE. 24 */ 25 26/** TODO: 27 * - insert PREFETCH instructions to avoid cache-misses ! 28 * - some more optimizations are possible... 29 * - for 40-50% more performance in the SSE-functions, the 30 * data (trans-matrix, src_vert, dst_vert) needs to be 16byte aligned ! 31 */ 32 33#ifdef USE_SSE_ASM 34#include "assyntax.h" 35#include "matypes.h" 36#include "norm_args.h" 37 38 SEG_TEXT 39 40#define M(i) REGOFF(i * 4, EDX) 41#define S(i) REGOFF(i * 4, ESI) 42#define D(i) REGOFF(i * 4, EDI) 43#define STRIDE REGOFF(12, ESI) 44 45 46ALIGNTEXT16 47GLOBL GLNAME(_mesa_sse_transform_rescale_normals_no_rot) 48HIDDEN(_mesa_sse_transform_rescale_normals_no_rot) 49GLNAME(_mesa_sse_transform_rescale_normals_no_rot): 50 51#define FRAME_OFFSET 8 52 PUSH_L ( ESI ) 53 PUSH_L ( EDI ) 54 55 MOV_L ( ARG_IN, ESI ) /* ptr to source GLvector3f */ 56 MOV_L ( ARG_DEST, EDI ) /* ptr to dest GLvector3f */ 57 58 MOV_L ( ARG_MAT, EDX ) /* ptr to matrix */ 59 MOV_L ( REGOFF(MATRIX_INV, EDX), EDX) /* matrix->inv */ 60 61 MOV_L ( REGOFF(V4F_COUNT, ESI), ECX ) /* source count */ 62 63 TEST_L ( ECX, ECX ) 64 JZ( LLBL(K_G3TRNNRR_finish) ) /* count was zero; go to finish */ 65 66 MOV_L ( STRIDE, EAX ) /* stride */ 67 MOV_L ( ECX, REGOFF(V4F_COUNT, EDI) ) /* set dest-count */ 68 69 IMUL_L( CONST(16), ECX ) /* count *= 16 */ 70 MOV_L( REGOFF(V4F_START, ESI), ESI ) /* ptr to first source vertex */ 71 72 MOV_L( REGOFF(V4F_START, EDI), EDI ) /* ptr to first dest vertex */ 73 ADD_L( EDI, ECX ) /* count += dest ptr */ 74 75ALIGNTEXT32 76 MOVSS ( M(0), XMM1 ) /* m0 */ 77 MOVSS ( M(5), XMM2 ) /* m5 */ 78 UNPCKLPS( XMM2, XMM1 ) /* m5 | m0 */ 79 MOVSS ( ARG_SCALE, XMM0 ) /* scale */ 80 SHUFPS ( CONST(0x0), XMM0, XMM0 ) /* scale | scale */ 81 MULPS ( XMM0, XMM1 ) /* m5*scale | m0*scale */ 82 MULSS ( M(10), XMM0 ) /* m10*scale */ 83 84ALIGNTEXT32 85LLBL(K_G3TRNNRR_top): 86 MOVLPS ( S(0), XMM2 ) /* uy | ux */ 87 MULPS ( XMM1, XMM2 ) /* uy*m5*scale | ux*m0*scale */ 88 MOVLPS ( XMM2, D(0) ) /* ->D(1) | D(0) */ 89 90 MOVSS ( S(2), XMM2 ) /* uz */ 91 MULSS ( XMM0, XMM2 ) /* uz*m10*scale */ 92 MOVSS ( XMM2, D(2) ) /* ->D(2) */ 93 94LLBL(K_G3TRNNRR_skip): 95 ADD_L ( CONST(16), EDI ) 96 ADD_L ( EAX, ESI ) 97 CMP_L ( ECX, EDI ) 98 JNE ( LLBL(K_G3TRNNRR_top) ) 99 100LLBL(K_G3TRNNRR_finish): 101 POP_L ( EDI ) 102 POP_L ( ESI ) 103 RET 104#undef FRAME_OFFSET 105 106 107 108ALIGNTEXT16 109GLOBL GLNAME(_mesa_sse_transform_rescale_normals) 110HIDDEN(_mesa_sse_transform_rescale_normals) 111GLNAME(_mesa_sse_transform_rescale_normals): 112 113#define FRAME_OFFSET 8 114 PUSH_L ( ESI ) 115 PUSH_L ( EDI ) 116 117 MOV_L ( ARG_IN, ESI ) /* ptr to source GLvector3f */ 118 MOV_L ( ARG_DEST, EDI ) /* ptr to dest GLvector3f */ 119 120 MOV_L ( ARG_MAT, EDX ) /* ptr to matrix */ 121 MOV_L ( REGOFF(MATRIX_INV, EDX), EDX) /* matrix->inv */ 122 123 MOV_L ( REGOFF(V4F_COUNT, ESI), ECX ) /* source count */ 124 125 TEST_L ( ECX, ECX ) 126 JZ( LLBL(K_G3TRNR_finish) ) /* count was zero; go to finish */ 127 128 MOV_L ( STRIDE, EAX ) /* stride */ 129 MOV_L ( ECX, REGOFF(V4F_COUNT, EDI) ) /* set dest-count */ 130 131 IMUL_L( CONST(16), ECX ) /* count *= 16 */ 132 MOV_L( REGOFF(V4F_START, ESI), ESI ) /* ptr to first source vertex */ 133 134 MOV_L( REGOFF(V4F_START, EDI), EDI ) /* ptr to first dest vertex */ 135 ADD_L( EDI, ECX ) /* count += dest ptr */ 136 137ALIGNTEXT32 138 MOVSS ( M(0), XMM0 ) /* m0 */ 139 MOVSS ( M(4), XMM1 ) /* m4 */ 140 UNPCKLPS( XMM1, XMM0 ) /* m4 | m0 */ 141 142 MOVSS ( ARG_SCALE, XMM4 ) /* scale */ 143 SHUFPS ( CONST(0x0), XMM4, XMM4 ) /* scale | scale */ 144 145 MULPS ( XMM4, XMM0 ) /* m4*scale | m0*scale */ 146 MOVSS ( M(1), XMM1 ) /* m1 */ 147 MOVSS ( M(5), XMM2 ) /* m5 */ 148 UNPCKLPS( XMM2, XMM1 ) /* m5 | m1 */ 149 MULPS ( XMM4, XMM1 ) /* m5*scale | m1*scale */ 150 MOVSS ( M(2), XMM2 ) /* m2 */ 151 MOVSS ( M(6), XMM3 ) /* m6 */ 152 UNPCKLPS( XMM3, XMM2 ) /* m6 | m2 */ 153 MULPS ( XMM4, XMM2 ) /* m6*scale | m2*scale */ 154 155 MOVSS ( M(8), XMM6 ) /* m8 */ 156 MULSS ( ARG_SCALE, XMM6 ) /* m8*scale */ 157 MOVSS ( M(9), XMM7 ) /* m9 */ 158 MULSS ( ARG_SCALE, XMM7 ) /* m9*scale */ 159 160ALIGNTEXT32 161LLBL(K_G3TRNR_top): 162 MOVSS ( S(0), XMM3 ) /* ux */ 163 SHUFPS ( CONST(0x0), XMM3, XMM3 ) /* ux | ux */ 164 MULPS ( XMM0, XMM3 ) /* ux*m4 | ux*m0 */ 165 MOVSS ( S(1), XMM4 ) /* uy */ 166 SHUFPS ( CONST(0x0), XMM4, XMM4 ) /* uy | uy */ 167 MULPS ( XMM1, XMM4 ) /* uy*m5 | uy*m1 */ 168 MOVSS ( S(2), XMM5 ) /* uz */ 169 SHUFPS ( CONST(0x0), XMM5, XMM5 ) /* uz | uz */ 170 MULPS ( XMM2, XMM5 ) /* uz*m6 | uz*m2 */ 171 172 ADDPS ( XMM4, XMM3 ) 173 ADDPS ( XMM5, XMM3 ) 174 MOVLPS ( XMM3, D(0) ) 175 176 MOVSS ( M(10), XMM3 ) /* m10 */ 177 MULSS ( ARG_SCALE, XMM3 ) /* m10*scale */ 178 MULSS ( S(2), XMM3 ) /* m10*scale*uz */ 179 MOVSS ( S(1), XMM4 ) /* uy */ 180 MULSS ( XMM7, XMM4 ) /* uy*m9*scale */ 181 MOVSS ( S(0), XMM5 ) /* ux */ 182 MULSS ( XMM6, XMM5 ) /* ux*m8*scale */ 183 184 ADDSS ( XMM4, XMM3 ) 185 ADDSS ( XMM5, XMM3 ) 186 MOVSS ( XMM3, D(2) ) 187 188LLBL(K_G3TRNR_skip): 189 ADD_L ( CONST(16), EDI ) 190 ADD_L ( EAX, ESI ) 191 CMP_L ( ECX, EDI ) 192 JNE ( LLBL(K_G3TRNR_top) ) 193 194LLBL(K_G3TRNR_finish): 195 POP_L ( EDI ) 196 POP_L ( ESI ) 197 RET 198#undef FRAME_OFFSET 199 200 201ALIGNTEXT16 202GLOBL GLNAME(_mesa_sse_transform_normals_no_rot) 203HIDDEN(_mesa_sse_transform_normals_no_rot) 204GLNAME(_mesa_sse_transform_normals_no_rot): 205 206#define FRAME_OFFSET 8 207 PUSH_L ( ESI ) 208 PUSH_L ( EDI ) 209 210 MOV_L ( ARG_IN, ESI ) /* ptr to source GLvector3f */ 211 MOV_L ( ARG_DEST, EDI ) /* ptr to dest GLvector3f */ 212 213 MOV_L ( ARG_MAT, EDX ) /* ptr to matrix */ 214 MOV_L ( REGOFF(MATRIX_INV, EDX), EDX) /* matrix->inv */ 215 216 MOV_L ( REGOFF(V4F_COUNT, ESI), ECX ) /* source count */ 217 218 TEST_L ( ECX, ECX ) 219 JZ( LLBL(K_G3TNNRR_finish) ) /* count was zero; go to finish */ 220 221 MOV_L ( STRIDE, EAX ) /* stride */ 222 MOV_L ( ECX, REGOFF(V4F_COUNT, EDI) ) /* set dest-count */ 223 224 IMUL_L( CONST(16), ECX ) /* count *= 16 */ 225 MOV_L( REGOFF(V4F_START, ESI), ESI ) /* ptr to first source vertex */ 226 227 MOV_L( REGOFF(V4F_START, EDI), EDI ) /* ptr to first dest vertex */ 228 ADD_L( EDI, ECX ) /* count += dest ptr */ 229 230ALIGNTEXT32 231 MOVSS( M(0), XMM0 ) /* m0 */ 232 MOVSS( M(5), XMM1 ) /* m5 */ 233 UNPCKLPS( XMM1, XMM0 ) /* m5 | m0 */ 234 MOVSS( M(10), XMM1 ) /* m10 */ 235 236ALIGNTEXT32 237LLBL(K_G3TNNRR_top): 238 MOVLPS( S(0), XMM2 ) /* uy | ux */ 239 MULPS( XMM0, XMM2 ) /* uy*m5 | ux*m0 */ 240 MOVLPS( XMM2, D(0) ) 241 242 MOVSS( S(2), XMM2 ) /* uz */ 243 MULSS( XMM1, XMM2 ) /* uz*m10 */ 244 MOVSS( XMM2, D(2) ) 245 246LLBL(K_G3TNNRR_skip): 247 ADD_L ( CONST(16), EDI ) 248 ADD_L ( EAX, ESI ) 249 CMP_L ( ECX, EDI ) 250 JNE ( LLBL(K_G3TNNRR_top) ) 251 252LLBL(K_G3TNNRR_finish): 253 POP_L ( EDI ) 254 POP_L ( ESI ) 255 RET 256#undef FRAME_OFFSET 257#endif 258 259#if defined (__ELF__) && defined (__linux__) 260 .section .note.GNU-stack,"",%progbits 261#endif 262