Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / lib / filter / gr_cpu_x86.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2002 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_3dnow ()
89 {
90   unsigned int extended_fct_count = cpuid_eax (0x80000000);
91   if (extended_fct_count < 0x80000001)
92     return false;
93
94   unsigned int extended_features = cpuid_edx (0x80000001);
95   return (extended_features & (1 << 31)) != 0;
96 }
97
98 bool
99 gr_cpu::has_3dnowext ()
100 {
101   unsigned int extended_fct_count = cpuid_eax (0x80000000);
102   if (extended_fct_count < 0x80000001)
103     return false;
104
105   unsigned int extended_features = cpuid_edx (0x80000001);
106   return (extended_features & (1 << 30)) != 0;
107 }
108
109 bool
110 gr_cpu::has_altivec ()
111 {
112   return false;
113 }