plotter: require double buffering
[debian/gnuradio] / gnuradio-core / src / lib / filter / gr_cpu.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2002,2008 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #include <gr_cpu.h>
24
25 /*
26  * execute CPUID instruction, return EAX, EBX, ECX and EDX values in result
27  */
28 extern "C" {
29 void cpuid_x86 (unsigned int op, unsigned int result[4]);
30 };
31
32 /*
33  * CPUID functions returning a single datum
34  */
35
36 static inline unsigned int cpuid_eax(unsigned int op)
37 {
38   unsigned int  regs[4];
39   cpuid_x86 (op, regs);
40   return regs[0];
41 }
42
43 static inline unsigned int cpuid_ebx(unsigned int op)
44 {
45   unsigned int  regs[4];
46   cpuid_x86 (op, regs);
47   return regs[1];
48 }
49
50 static inline unsigned int cpuid_ecx(unsigned int op)
51 {
52   unsigned int  regs[4];
53   cpuid_x86 (op, regs);
54   return regs[2];
55 }
56
57 static inline unsigned int cpuid_edx(unsigned int op)
58 {
59   unsigned int  regs[4];
60   cpuid_x86 (op, regs);
61   return regs[3];
62 }
63
64 // ----------------------------------------------------------------
65
66 bool
67 gr_cpu::has_mmx ()
68 {
69   unsigned int edx = cpuid_edx (1);     // standard features
70   return (edx & (1 << 23)) != 0;
71 }
72
73 bool
74 gr_cpu::has_sse ()
75 {
76   unsigned int edx = cpuid_edx (1);     // standard features
77   return (edx & (1 << 25)) != 0;
78 }
79
80 bool
81 gr_cpu::has_sse2 ()
82 {
83   unsigned int edx = cpuid_edx (1);     // standard features
84   return (edx & (1 << 26)) != 0;
85 }
86
87 bool
88 gr_cpu::has_sse3 ()
89 {
90   unsigned int ecx = cpuid_ecx (1);     // standard features
91   return (ecx & (1 << 0)) != 0;
92 }
93
94 bool
95 gr_cpu::has_ssse3 ()
96 {
97   unsigned int ecx = cpuid_ecx (1);     // standard features
98   return (ecx & (1 << 9)) != 0;
99 }
100
101 bool
102 gr_cpu::has_sse4_1 ()
103 {
104   unsigned int ecx = cpuid_ecx (1);     // standard features
105   return (ecx & (1 << 19)) != 0;
106 }
107
108 bool
109 gr_cpu::has_sse4_2 ()
110 {
111   unsigned int ecx = cpuid_ecx (1);     // standard features
112   return (ecx & (1 << 20)) != 0;
113 }
114
115
116 bool
117 gr_cpu::has_3dnow ()
118 {
119   unsigned int extended_fct_count = cpuid_eax (0x80000000);
120   if (extended_fct_count < 0x80000001)
121     return false;
122
123   unsigned int extended_features = cpuid_edx (0x80000001);
124   return (extended_features & (1 << 31)) != 0;
125 }
126
127 bool
128 gr_cpu::has_3dnowext ()
129 {
130   unsigned int extended_fct_count = cpuid_eax (0x80000000);
131   if (extended_fct_count < 0x80000001)
132     return false;
133
134   unsigned int extended_features = cpuid_edx (0x80000001);
135   return (extended_features & (1 << 30)) != 0;
136 }