BRL-CAD
simd.c
Go to the documentation of this file.
1 /* S I M D . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2010-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 
21 #include "common.h"
22 #include "bu/simd.h"
23 
24 int
26 {
27 #if defined(__GNUC__) && defined(__SSE__)
28  int c=0, d=0;
29 # ifdef __i386__
30  __asm__ volatile("pushl %%ebx;cpuid;popl %%ebx;":"=c"(c),"=d"(d):"a"(0x1));
31 # else
32  int b=0;
33  __asm__ volatile("cpuid":"=b"(b),"=c"(c),"=d"(d):"a"(0x1));
34 # endif
35  if (c & 0x100000)
36  return BU_SIMD_SSE4_2;
37  if (c & 0x080000)
38  return BU_SIMD_SSE4_1;
39  if (c & 0x1)
40  return BU_SIMD_SSE3;
41  if (d & 0x1<<26)
42  return BU_SIMD_SSE2;
43  if (d & 0x1<<25)
44  return BU_SIMD_SSE;
45  if (d & 0x1<<24)
46  return BU_SIMD_MMX;
47 #endif
48  return BU_SIMD_NONE;
49 }
50 
51 int
53 {
54  int l;
55 
56  if (level == 4)
57  return 0;
58 
59  l = bu_simd_level();
60 
61  return l >= level;
62 }
63 
64 
65 /*
66  * Local Variables:
67  * mode: C
68  * tab-width: 8
69  * indent-tabs-mode: t
70  * c-file-style: "stroustrup"
71  * End:
72  * ex: shiftwidth=4 tabstop=8
73  */
#define BU_SIMD_SSE4_2
Definition: simd.h:40
#define BU_SIMD_SSE2
Definition: simd.h:44
Header file for the BRL-CAD common definitions.
#define BU_SIMD_SSE4_1
Definition: simd.h:41
#define BU_SIMD_SSE
Definition: simd.h:45
int bu_simd_level()
Definition: simd.c:25
#define BU_SIMD_SSE3
Definition: simd.h:42
#define BU_SIMD_NONE
Definition: simd.h:47
int bu_simd_supported(int level)
Definition: simd.c:52
#define BU_SIMD_MMX
Definition: simd.h:46