Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.3/simd-support/sse2.c @ 10:37bf6b4a2645
Add FFTW3
author | Chris Cannam |
---|---|
date | Wed, 20 Mar 2013 15:35:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
9:c0fb53affa76 | 10:37bf6b4a2645 |
---|---|
1 /* | |
2 * Copyright (c) 2003, 2007-11 Matteo Frigo | |
3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology | |
4 * | |
5 * This program is free software; you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License as published by | |
7 * the Free Software Foundation; either version 2 of the License, or | |
8 * (at your option) any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 * GNU General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU General Public License | |
16 * along with this program; if not, write to the Free Software | |
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
18 * | |
19 */ | |
20 | |
21 | |
22 #include "ifftw.h" | |
23 | |
24 #ifdef FFTW_SINGLE | |
25 # define DS(d,s) s /* single-precision option */ | |
26 #else | |
27 # define DS(d,s) d /* double-precision option */ | |
28 #endif | |
29 | |
30 #if HAVE_SSE2 | |
31 | |
32 # if defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64) | |
33 | |
34 int X(have_simd_sse2)(void) | |
35 { | |
36 return 1; | |
37 } | |
38 | |
39 # else /* !x86_64 */ | |
40 | |
41 # include <signal.h> | |
42 # include <setjmp.h> | |
43 # include "x86-cpuid.h" | |
44 | |
45 static jmp_buf jb; | |
46 | |
47 static void sighandler(int x) | |
48 { | |
49 UNUSED(x); | |
50 longjmp(jb, 1); | |
51 } | |
52 | |
53 static int sse2_works(void) | |
54 { | |
55 void (*oldsig)(int); | |
56 oldsig = signal(SIGILL, sighandler); | |
57 if (setjmp(jb)) { | |
58 signal(SIGILL, oldsig); | |
59 return 0; | |
60 } else { | |
61 # ifdef _MSC_VER | |
62 _asm { DS(xorpd,xorps) xmm0,xmm0 } | |
63 # else | |
64 /* asm volatile ("xorpd/s %xmm0, %xmm0"); */ | |
65 asm volatile(DS(".byte 0x66; .byte 0x0f; .byte 0x57; .byte 0xc0", | |
66 ".byte 0x0f; .byte 0x57; .byte 0xc0")); | |
67 # endif | |
68 signal(SIGILL, oldsig); | |
69 return 1; | |
70 } | |
71 } | |
72 | |
73 extern void X(check_alignment_of_sse2_pm)(void); | |
74 | |
75 int X(have_simd_sse2)(void) | |
76 { | |
77 static int init = 0, res; | |
78 | |
79 if (!init) { | |
80 res = !is_386() | |
81 && has_cpuid() | |
82 && (cpuid_edx(1) & (1 << DS(26,25))) | |
83 && sse2_works(); | |
84 init = 1; | |
85 X(check_alignment_of_sse2_pm)(); | |
86 } | |
87 return res; | |
88 } | |
89 | |
90 # endif | |
91 | |
92 #endif |