1
2 /*
3 * Mesa 3-D graphics library
4 *
5 * Copyright (C) 1999-2003 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 /*
27 * x86-64 optimizations shamelessy converted from x86/sse/3dnow assembly by
28 * Mikko Tiihonen
29 */
30
31 #ifdef USE_X86_64_ASM
32
33 #include "main/glheader.h"
34 #include "main/context.h"
35 #include "math/m_xform.h"
36 #include "tnl/t_context.h"
37 #include "x86-64.h"
38 #include "../x86/x86_xform.h"
39
40 #ifdef DEBUG
41 #include "math/m_debug.h"
42 #endif
43
44 extern void _mesa_x86_64_cpuid(unsigned int *regs);
45
46 DECLARE_XFORM_GROUP( x86_64, 4 )
47 DECLARE_XFORM_GROUP( 3dnow, 4 )
48
49 #else
50 /* just to silence warning below */
51 #include "x86-64.h"
52 #endif
53
54 /*
55 extern void _mesa_x86_64_transform_points4_general( XFORM_ARGS );
56 extern void _mesa_x86_64_transform_points4_identity( XFORM_ARGS );
57 extern void _mesa_x86_64_transform_points4_perspective( XFORM_ARGS );
58 extern void _mesa_x86_64_transform_points4_3d( XFORM_ARGS );
59 extern void _mesa_x86_64_transform_points4_3d_no_rot( XFORM_ARGS );
60 extern void _mesa_x86_64_transform_points4_2d_no_rot( XFORM_ARGS );
61 extern void _mesa_x86_64_transform_points4_2d( XFORM_ARGS );
62 */
63
64 #ifdef USE_X86_64_ASM
message(const char * msg)65 static void message( const char *msg )
66 {
67 if (getenv("MESA_DEBUG")) {
68 _mesa_debug( NULL, "%s", msg );
69 }
70 }
71 #endif
72
73
_mesa_init_all_x86_64_transform_asm(void)74 void _mesa_init_all_x86_64_transform_asm(void)
75 {
76 #ifdef USE_X86_64_ASM
77 unsigned int regs[4];
78
79 if ( getenv( "MESA_NO_ASM" ) ) {
80 return;
81 }
82
83 message("Initializing x86-64 optimizations\n");
84
85
86 _mesa_transform_tab[4][MATRIX_GENERAL] =
87 _mesa_x86_64_transform_points4_general;
88 _mesa_transform_tab[4][MATRIX_IDENTITY] =
89 _mesa_x86_64_transform_points4_identity;
90 _mesa_transform_tab[4][MATRIX_3D] =
91 _mesa_x86_64_transform_points4_3d;
92
93 regs[0] = 0x80000001;
94 regs[1] = 0x00000000;
95 regs[2] = 0x00000000;
96 regs[3] = 0x00000000;
97 _mesa_x86_64_cpuid(regs);
98 if (regs[3] & (1U << 31)) {
99 message("3Dnow! detected\n");
100 _mesa_transform_tab[4][MATRIX_3D_NO_ROT] =
101 _mesa_3dnow_transform_points4_3d_no_rot;
102 _mesa_transform_tab[4][MATRIX_PERSPECTIVE] =
103 _mesa_3dnow_transform_points4_perspective;
104 _mesa_transform_tab[4][MATRIX_2D_NO_ROT] =
105 _mesa_3dnow_transform_points4_2d_no_rot;
106 _mesa_transform_tab[4][MATRIX_2D] =
107 _mesa_3dnow_transform_points4_2d;
108
109 }
110
111
112 #ifdef DEBUG_MATH
113 _math_test_all_transform_functions("x86_64");
114 _math_test_all_cliptest_functions("x86_64");
115 _math_test_all_normal_transform_functions("x86_64");
116 #endif
117
118 #endif
119 }
120