123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/*
223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Mesa 3-D graphics library
323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *
427558a160a9fe91745728d7626995cd88f8fe339Brian Paul * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *
623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * copy of this software and associated documentation files (the "Software"),
823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * to deal in the Software without restriction, including without limitation
923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * and/or sell copies of the Software, and to permit persons to whom the
1123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Software is furnished to do so, subject to the following conditions:
1223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *
1323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * The above copyright notice and this permission notice shall be included
1423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * in all copies or substantial portions of the Software.
1523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *
1623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
193d8d5b298a268b119d840bc9bae0ee9e0c9244a9Kenneth Graunke * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
203d8d5b298a268b119d840bc9bae0ee9e0c9244a9Kenneth Graunke * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
213d8d5b298a268b119d840bc9bae0ee9e0c9244a9Kenneth Graunke * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
223d8d5b298a268b119d840bc9bae0ee9e0c9244a9Kenneth Graunke * OTHER DEALINGS IN THE SOFTWARE.
2323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */
2423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
2523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
2623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/*
2723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Matrix/vertex/vector transformation stuff
2823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *
2923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *
3023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * NOTES:
3123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * 1. 4x4 transformation matrices are stored in memory in column major order.
3223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * 2. Points/vertices are to be thought of as column vectors.
3323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * 3. Transformation of a point p by a matrix M is: p' = M * p
3423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */
3523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
36a2b366b92cecc5045293528aa0bb8b1f0678bbccBrian Paul#include "c99_math.h"
37c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian Paul#include "main/glheader.h"
38c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian Paul#include "main/macros.h"
3923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
40cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#include "m_eval.h"
4123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "m_matrix.h"
425a9026c65d260dc185e072163999f5d810015108Brian Paul#include "m_translate.h"
4323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "m_xform.h"
4423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
4523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
4681a22ef53953d950052c7bd5a282e96107a25f24Brian Paul#ifdef DEBUG_MATH
47fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughes#include "m_debug.h"
4823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#endif
4923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
5023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#ifdef USE_X86_ASM
515f3439916b74ed792ad12d1e614a2a5bc0a94b3aBrian Paul#include "x86/common_x86_asm.h"
5223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#endif
5323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
5442fa81275c67d7d1ad8d255120af0ffeeb46b963Brian Paul#ifdef USE_X86_64_ASM
5542fa81275c67d7d1ad8d255120af0ffeeb46b963Brian Paul#include "x86-64/x86-64.h"
5642fa81275c67d7d1ad8d255120af0ffeeb46b963Brian Paul#endif
5742fa81275c67d7d1ad8d255120af0ffeeb46b963Brian Paul
587943b349d696f8030f0d2f836ad42a762f4c6026Brian Paul#ifdef USE_SPARC_ASM
595f3439916b74ed792ad12d1e614a2a5bc0a94b3aBrian Paul#include "sparc/sparc.h"
607943b349d696f8030f0d2f836ad42a762f4c6026Brian Paul#endif
617943b349d696f8030f0d2f836ad42a762f4c6026Brian Paul
62188f2949eaf181f4aab041a6dad26fa76e746eeeBrian Paulclip_func _mesa_clip_tab[5];
63188f2949eaf181f4aab041a6dad26fa76e746eeeBrian Paulclip_func _mesa_clip_np_tab[5];
645e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughesdotprod_func _mesa_dotprod_tab[5];
655e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughesvec_copy_func _mesa_copy_tab[0x10];
665e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughesnormal_func _mesa_normal_tab[0xf];
675e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughestransform_func *_mesa_transform_tab[5];
6823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
6923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
7023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/* Raw data format used for:
7123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *    - Object-to-eye transform prior to culling, although this too
7223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *      could be culled under some circumstances.
7323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *    - Eye-to-clip transform (via the function above).
7423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *    - Cliptesting
7523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell *    - And everything else too, if culling happens to be disabled.
765e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes *
775e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes * GH: It's used for everything now, as clipping/culling is done
785e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes *     elsewhere (most often by the driver itself).
7923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */
805e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes#define TAG(x) x
815e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes#define TAG2(x,y) x##y
825e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes#define STRIDE_LOOP for ( i = 0 ; i < count ; i++, STRIDE_F(from, stride) )
835e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes#define LOOP for ( i = 0 ; i < n ; i++ )
8423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define ARGS
8523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "m_xform_tmp.h"
8623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "m_clip_tmp.h"
8723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "m_norm_tmp.h"
8823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "m_dotprod_tmp.h"
8923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "m_copy_tmp.h"
9023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#undef TAG
9123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#undef TAG2
9223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#undef LOOP
9323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#undef ARGS
9423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
9523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
9623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/*
9723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * This is called only once.  It initializes several tables with pointers
9823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * to optimized transformation functions.  This is where we can test for
99462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihane * AMD 3Dnow! capability, Intel SSE, etc. and hook in the right code.
10023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */
101fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughesvoid
10223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell_math_init_transformation( void )
10323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell{
1045e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes   init_c_transformations();
1055e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes   init_c_norm_transform();
1065e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes   init_c_cliptest();
1075e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes   init_copy0();
1085e23af22f708a66695c0e44e599c26f02d8d4dcdGareth Hughes   init_dotprod();
10923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
11081a22ef53953d950052c7bd5a282e96107a25f24Brian Paul#ifdef DEBUG_MATH
111fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughes   _math_test_all_transform_functions( "default" );
112fe69cb4b9bff800b6078ea7da5ea18bab05678d8Gareth Hughes   _math_test_all_normal_transform_functions( "default" );
113e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes   _math_test_all_cliptest_functions( "default" );
11423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#endif
11523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell
1168eaffa2a1c807f2f966f7f48c705c91fdd3b9ab5Brian Paul#ifdef USE_X86_ASM
11708836341788a9f9d638d9dc8328510ccd18ddeb5Brian Paul   _mesa_init_all_x86_transform_asm();
118447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick#elif defined( USE_SPARC_ASM )
1197943b349d696f8030f0d2f836ad42a762f4c6026Brian Paul   _mesa_init_all_sparc_transform_asm();
12042fa81275c67d7d1ad8d255120af0ffeeb46b963Brian Paul#elif defined( USE_X86_64_ASM )
12142fa81275c67d7d1ad8d255120af0ffeeb46b963Brian Paul   _mesa_init_all_x86_64_transform_asm();
1227943b349d696f8030f0d2f836ad42a762f4c6026Brian Paul#endif
12323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell}
124