draw: corrections to allow for different cliptest cases
[mesa.git] / src / gallium / auxiliary / util / u_sse.h
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /**
29 * @file
30 * SSE intrinsics portability header.
31 *
32 * Although the SSE intrinsics are support by all modern x86 and x86-64
33 * compilers, there are some intrisincs missing in some implementations
34 * (especially older MSVC versions). This header abstracts that away.
35 */
36
37 #ifndef U_SSE_H_
38 #define U_SSE_H_
39
40 #include "pipe/p_config.h"
41
42 #if defined(PIPE_ARCH_SSE)
43
44 #include <emmintrin.h>
45
46
47 /* MSVC before VC8 does not support the _mm_castxxx_yyy */
48 #if defined(_MSC_VER) && _MSC_VER < 1500
49
50 union __declspec(align(16)) m128_types {
51 __m128 m128;
52 __m128i m128i;
53 __m128d m128d;
54 };
55
56 static __inline __m128
57 _mm_castsi128_ps(__m128i a)
58 {
59 union m128_types u;
60 u.m128i = a;
61 return u.m128;
62 }
63
64 static __inline __m128i
65 _mm_castps_si128(__m128 a)
66 {
67 union m128_types u;
68 u.m128 = a;
69 return u.m128i;
70 }
71
72 #endif /* defined(_MSC_VER) && _MSC_VER < 1500 */
73
74
75 #if defined(PIPE_ARCH_SSSE3)
76
77 #include <tmmintrin.h>
78
79 #else /* !PIPE_ARCH_SSSE3 */
80
81 #include <emmintrin.h>
82
83 /**
84 * Describe _mm_shuffle_epi8() with gcc extended inline assembly, for cases
85 * where -mssse3 is not supported/enabled.
86 *
87 * MSVC will never get in here as its intrinsics support do not rely on
88 * compiler command line options.
89 */
90 static __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
91 _mm_shuffle_epi8(__m128i a, __m128i mask)
92 {
93 __m128i result;
94 __asm__("pshufb %1, %0"
95 : "=x" (result)
96 : "xm" (mask), "0" (a));
97 return result;
98 }
99
100 #endif /* !PIPE_ARCH_SSSE3 */
101
102
103 #endif /* PIPE_ARCH_X86 || PIPE_ARCH_X86_64 */
104
105 #endif /* U_SSE_H_ */