~diresu/blender/blender-command-port

« back to all changes in this revision

Viewing changes to extern/fftw/simd/sse.c

  • Committer: theeth
  • Date: 2008-10-14 16:52:04 UTC
  • Revision ID: vcs-imports@canonical.com-20081014165204-r32w2gm6s0osvdhn
copy back trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2003, 2006 Matteo Frigo
 
3
 * Copyright (c) 2003, 2006 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 *
 
19
 */
 
20
 
 
21
/* $Id: sse.c,v 1.16 2006-02-08 03:01:36 athena Exp $ */
 
22
 
 
23
#include "ifftw.h"
 
24
#include "simd.h"
 
25
 
 
26
#if HAVE_SSE
 
27
 
 
28
# if defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64)
 
29
 
 
30
  int RIGHT_CPU(void)
 
31
  {
 
32
       return 1;
 
33
  }
 
34
 
 
35
# else /* !x86_64 */
 
36
 
 
37
# include <signal.h>
 
38
# include <setjmp.h>
 
39
# include "x86-cpuid.h"
 
40
 
 
41
  static jmp_buf jb;
 
42
 
 
43
  static void sighandler(int x)
 
44
  {
 
45
       UNUSED(x);
 
46
       longjmp(jb, 1);
 
47
  }
 
48
 
 
49
  static int sse_works(void)
 
50
  {
 
51
       void (*oldsig)(int);
 
52
       oldsig = signal(SIGILL, sighandler);
 
53
       if (setjmp(jb)) {
 
54
            signal(SIGILL, oldsig);
 
55
            return 0;
 
56
       } else {
 
57
#        ifdef _MSC_VER
 
58
            _asm { xorps xmm0,xmm0 }
 
59
#        else
 
60
            /* asm volatile ("xorps %xmm0, %xmm0"); */
 
61
            asm volatile (".byte 0x0f; .byte 0x57; .byte 0xc0");
 
62
#        endif
 
63
            signal(SIGILL, oldsig);
 
64
            return 1;
 
65
       }
 
66
  }
 
67
 
 
68
  int RIGHT_CPU(void)
 
69
  {
 
70
       static int init = 0, res;
 
71
       extern void X(check_alignment_of_sse_mpmp)(void);
 
72
 
 
73
       if (!init) {
 
74
            res =   !is_386() 
 
75
                 && has_cpuid()
 
76
                 && (cpuid_edx(1) & (1 << 25)) 
 
77
                 && sse_works();
 
78
            init = 1;
 
79
            X(check_alignment_of_sse_mpmp)();
 
80
       }
 
81
       return res;
 
82
  }
 
83
# endif /* x86_64 */
 
84
 
 
85
#endif /* HAVE_SSE */