cannam@95: /* cannam@95: * Copyright (c) 2003, 2007-11 Matteo Frigo cannam@95: * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology cannam@95: * cannam@95: * This program is free software; you can redistribute it and/or modify cannam@95: * it under the terms of the GNU General Public License as published by cannam@95: * the Free Software Foundation; either version 2 of the License, or cannam@95: * (at your option) any later version. cannam@95: * cannam@95: * This program is distributed in the hope that it will be useful, cannam@95: * but WITHOUT ANY WARRANTY; without even the implied warranty of cannam@95: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the cannam@95: * GNU General Public License for more details. cannam@95: * cannam@95: * You should have received a copy of the GNU General Public License cannam@95: * along with this program; if not, write to the Free Software cannam@95: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA cannam@95: * cannam@95: */ cannam@95: cannam@95: cannam@95: #include "ifftw.h" cannam@95: cannam@95: #if HAVE_ALTIVEC cannam@95: cannam@95: #if HAVE_SYS_SYSCTL_H cannam@95: # include cannam@95: #endif cannam@95: cannam@95: #if HAVE_SYS_SYSCTL_H && HAVE_SYSCTL && defined(CTL_HW) && defined(HW_VECTORUNIT) cannam@95: /* code for darwin */ cannam@95: static int really_have_altivec(void) cannam@95: { cannam@95: int mib[2], altivecp; cannam@95: size_t len; cannam@95: mib[0] = CTL_HW; cannam@95: mib[1] = HW_VECTORUNIT; cannam@95: len = sizeof(altivecp); cannam@95: sysctl(mib, 2, &altivecp, &len, NULL, 0); cannam@95: return altivecp; cannam@95: } cannam@95: #else /* GNU/Linux and other non-Darwin systems (!HAVE_SYS_SYSCTL_H etc.) */ cannam@95: cannam@95: #include cannam@95: #include cannam@95: cannam@95: static jmp_buf jb; cannam@95: cannam@95: static void sighandler(int x) cannam@95: { cannam@95: longjmp(jb, 1); cannam@95: } cannam@95: cannam@95: static int really_have_altivec(void) cannam@95: { cannam@95: void (*oldsig)(int); cannam@95: oldsig = signal(SIGILL, sighandler); cannam@95: if (setjmp(jb)) { cannam@95: signal(SIGILL, oldsig); cannam@95: return 0; cannam@95: } else { cannam@95: __asm__ __volatile__ (".long 0x10000484"); /* vor 0,0,0 */ cannam@95: signal(SIGILL, oldsig); cannam@95: return 1; cannam@95: } cannam@95: return 0; cannam@95: } cannam@95: #endif cannam@95: cannam@95: int X(have_simd_altivec)(void) cannam@95: { cannam@95: static int init = 0, res; cannam@95: if (!init) { cannam@95: res = really_have_altivec(); cannam@95: init = 1; cannam@95: } cannam@95: return res; cannam@95: } cannam@95: cannam@95: #endif