1 /*
2  * Copyright (c) 2003, 2007-14 Matteo Frigo
3  * Copyright (c) 2003, 2007-14 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 "kernel/ifftw.h"
23 
24 #if HAVE_NEON
25 
26 /* check for an environment where signals are known to work */
27 #if defined(unix) || defined(linux)
28   # include <signal.h>
29   # include <setjmp.h>
30 
31   static jmp_buf jb;
32 
sighandler(int x)33   static void sighandler(int x)
34   {
35        UNUSED(x);
36        longjmp(jb, 1);
37   }
38 
really_have_neon(void)39   static int really_have_neon(void)
40   {
41        void (*oldsig)(int);
42        oldsig = signal(SIGILL, sighandler);
43        if (setjmp(jb)) {
44 	    signal(SIGILL, oldsig);
45 	    return 0;
46        } else {
47 	    /* paranoia: encode the instruction in binary because the
48 	       assembler may not recognize it without -mfpu=neon */
49 	    /*asm volatile ("vand q0, q0, q0");*/
50 	    asm volatile (".long 0xf2000150");
51 	    signal(SIGILL, oldsig);
52 	    return 1;
53        }
54   }
55 
X(have_simd_neon)56   int X(have_simd_neon)(void)
57   {
58        static int init = 0, res;
59 
60        if (!init) {
61 	    res = really_have_neon();
62 	    init = 1;
63        }
64        return res;
65   }
66 
67 
68 #else
69 /* don't know how to autodetect NEON; assume it is present */
X(have_simd_neon)70   int X(have_simd_neon)(void)
71   {
72        return 1;
73   }
74 #endif
75 
76 #endif
77