1 /* $Id: common_x86_asm.S,v 1.8 2002/03/07 21:40:08 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Check extended CPU capabilities. Now justs returns the raw CPUID
29 * feature information, allowing the higher level code to interpret the
32 * Written by Holger Waechtler <holger@akaflieg.extern.tu-berlin.de>
34 * Cleaned up and simplified by Gareth Hughes <gareth@valinux.com>
38 * NOTE: Avoid using spaces in between '(' ')' and arguments, especially
39 * with macros like CONST, LLBL that expand to CONCAT(...). Putting spaces
40 * in there will break the build on some platforms.
44 #include "common_x86_features.h"
47 /* Intel vendor string
49 #define GENU 0x756e6547 /* "Genu" */
50 #define INEI 0x49656e69 /* "ineI" */
51 #define NTEL 0x6c65746e /* "ntel" */
55 #define AUTH 0x68747541 /* "Auth" */
56 #define ENTI 0x69746e65 /* "enti" */
57 #define CAMD 0x444d4163 /* "cAMD" */
62 /* We might want to print out some useful messages.
64 GLNAME( found_intel ): STRING( "Genuine Intel processor found\n\0" )
65 GLNAME( found_amd ): STRING( "Authentic AMD processor found\n\0" )
68 GLNAME( sse_test_dummy ):
69 D_LONG 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000
76 GLOBL GLNAME( _mesa_identify_x86_cpu_features )
77 GLNAME( _mesa_identify_x86_cpu_features ):
81 /* Test for the CPUID command. If the ID Flag bit in EFLAGS
82 * (bit 21) is writable, the CPUID command is present.
87 XOR_L ( CONST(0x00200000), EAX )
93 /* Verify the ID Flag bit has been written.
96 JZ ( LLBL (cpuid_done) )
98 /* Get the CPU vendor info.
103 /* Test for Intel processors. We must look for the
104 * "GenuineIntel" string in EBX, ECX and EDX.
106 CMP_L ( CONST(GENU), EBX )
107 JNE ( LLBL(cpuid_amd) )
108 CMP_L ( CONST(INEI), EDX )
109 JNE ( LLBL(cpuid_amd) )
110 CMP_L ( CONST(NTEL), ECX )
111 JNE ( LLBL(cpuid_amd) )
113 /* We have an Intel processor, so we can get the feature
114 * information with an CPUID input value of 1.
116 MOV_L ( CONST(0x1), EAX )
119 JMP ( LLBL(cpuid_done) )
123 /* Test for AMD processors. We must look for the
124 * "AuthenticAMD" string in EBX, ECX and EDX.
126 CMP_L ( CONST(AUTH), EBX )
127 JNE ( LLBL(cpuid_other) )
128 CMP_L ( CONST(ENTI), EDX )
129 JNE ( LLBL(cpuid_other) )
130 CMP_L ( CONST(CAMD), ECX )
131 JNE ( LLBL(cpuid_other) )
133 /* We have an AMD processor, so we can get the feature
134 * information after we verify that the extended functions are
137 MOV_L ( CONST(0x80000000), EAX )
140 JZ ( LLBL (cpuid_failed) )
142 MOV_L ( CONST(0x80000001), EAX )
145 JMP ( LLBL (cpuid_done) )
149 /* Test for other processors here when required.
154 /* If we can't determine the feature information, we must
155 * return zero to indicate that no platform-specific
156 * optimizations can be used.
158 MOV_L ( CONST(0), EAX )
167 /* Execute an SSE instruction to see if the operating system correctly
168 * supports SSE. A signal handler for SIGILL should have been set
169 * before calling this function, otherwise this could kill the client
173 GLOBL GLNAME( _mesa_test_os_sse_support )
174 GLNAME( _mesa_test_os_sse_support ):
181 /* Perform an SSE divide-by-zero to see if the operating system
182 * correctly supports unmasked SIMD FPU exceptions. Signal handlers for
183 * SIGILL and SIGFPE should have been set before calling this function,
184 * otherwise this could kill the client application.
187 GLOBL GLNAME( _mesa_test_os_sse_exception_support )
188 GLNAME( _mesa_test_os_sse_exception_support ):
192 SUB_L ( CONST( 8 ), ESP )
194 /* Save the original MXCSR register value.
196 STMXCSR ( REGOFF( -4, EBP ) )
198 /* Unmask the divide-by-zero exception and perform one.
200 STMXCSR ( REGOFF( -8, EBP ) )
201 AND_L ( CONST( 0xfffffdff ), REGOFF( -8, EBP ) )
202 LDMXCSR ( REGOFF( -8, EBP ) )
205 MOVUPS ( GLNAME( sse_test_dummy ), XMM1 )
209 /* Restore the original MXCSR register value.
211 LDMXCSR ( REGOFF( -4, EBP ) )