1 /* libFLAC - Free Lossless Audio Codec library 2 * Copyright (C) 2001-2009 Josh Coalson 3 * Copyright (C) 2011-2016 Xiph.Org Foundation 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * - Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * - Neither the name of the Xiph.org Foundation nor the names of its 17 * contributors may be used to endorse or promote products derived from 18 * this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #ifndef FLAC__PRIVATE__CPU_H 34 #define FLAC__PRIVATE__CPU_H 35 36 #include "FLAC/ordinals.h" 37 38 #ifdef HAVE_CONFIG_H 39 #include <config.h> 40 #endif 41 42 #ifndef FLAC__CPU_X86_64 43 44 #if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64) 45 #define FLAC__CPU_X86_64 46 #endif 47 48 #endif 49 50 #ifndef FLAC__CPU_IA32 51 52 #if defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) ||defined( __i386) || defined(_M_IX86) 53 #define FLAC__CPU_IA32 54 #endif 55 56 #endif 57 58 #ifndef __has_attribute 59 #define __has_attribute(x) 0 60 #endif 61 62 #if FLAC__HAS_X86INTRIN 63 /* SSE intrinsics support by ICC/MSVC/GCC */ 64 #if defined __INTEL_COMPILER 65 #define FLAC__SSE_TARGET(x) 66 #define FLAC__SSE_SUPPORTED 1 67 #define FLAC__SSE2_SUPPORTED 1 68 #if (__INTEL_COMPILER >= 1000) /* Intel C++ Compiler 10.0 */ 69 #define FLAC__SSSE3_SUPPORTED 1 70 #define FLAC__SSE4_1_SUPPORTED 1 71 #endif 72 #if (__INTEL_COMPILER >= 1110) /* Intel C++ Compiler 11.1 */ 73 #define FLAC__AVX_SUPPORTED 1 74 #endif 75 #if (__INTEL_COMPILER >= 1300) /* Intel C++ Compiler 13.0 */ 76 #define FLAC__AVX2_SUPPORTED 1 77 #define FLAC__FMA_SUPPORTED 1 78 #endif 79 #elif defined __clang__ && __has_attribute(__target__) /* clang */ 80 #define FLAC__SSE_TARGET(x) __attribute__ ((__target__ (x))) 81 #if __has_builtin(__builtin_ia32_maxps) 82 #define FLAC__SSE_SUPPORTED 1 83 #endif 84 #if __has_builtin(__builtin_ia32_pmuludq128) 85 #define FLAC__SSE2_SUPPORTED 1 86 #endif 87 #if __has_builtin(__builtin_ia32_pabsd128) 88 #define FLAC__SSSE3_SUPPORTED 1 89 #endif 90 #if __has_builtin(__builtin_ia32_pmuldq128) 91 #define FLAC__SSE4_1_SUPPORTED 1 92 #endif 93 #if __has_builtin(__builtin_ia32_pabsd256) 94 #define FLAC__AVX2_SUPPORTED 1 95 #endif 96 #elif defined __GNUC__ && !defined __clang__ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)) /* GCC 4.9+ */ 97 #define FLAC__SSE_TARGET(x) __attribute__ ((__target__ (x))) 98 #define FLAC__SSE_SUPPORTED 1 99 #define FLAC__SSE2_SUPPORTED 1 100 #define FLAC__SSSE3_SUPPORTED 1 101 #define FLAC__SSE4_1_SUPPORTED 1 102 #ifdef FLAC__USE_AVX 103 #define FLAC__AVX_SUPPORTED 1 104 #define FLAC__AVX2_SUPPORTED 1 105 #define FLAC__FMA_SUPPORTED 1 106 #endif 107 #elif defined _MSC_VER 108 #define FLAC__SSE_TARGET(x) 109 #define FLAC__SSE_SUPPORTED 1 110 #define FLAC__SSE2_SUPPORTED 1 111 #if (_MSC_VER >= 1500) /* MS Visual Studio 2008 */ 112 #define FLAC__SSSE3_SUPPORTED 1 113 #define FLAC__SSE4_1_SUPPORTED 1 114 #endif 115 #if (_MSC_FULL_VER >= 160040219) /* MS Visual Studio 2010 SP1 */ 116 #define FLAC__AVX_SUPPORTED 1 117 #endif 118 #if (_MSC_VER >= 1700) /* MS Visual Studio 2012 */ 119 #define FLAC__AVX2_SUPPORTED 1 120 #define FLAC__FMA_SUPPORTED 1 121 #endif 122 #else 123 #define FLAC__SSE_TARGET(x) 124 #ifdef __SSE__ 125 #define FLAC__SSE_SUPPORTED 1 126 #endif 127 #ifdef __SSE2__ 128 #define FLAC__SSE2_SUPPORTED 1 129 #endif 130 #ifdef __SSSE3__ 131 #define FLAC__SSSE3_SUPPORTED 1 132 #endif 133 #ifdef __SSE4_1__ 134 #define FLAC__SSE4_1_SUPPORTED 1 135 #endif 136 #ifdef __AVX__ 137 #define FLAC__AVX_SUPPORTED 1 138 #endif 139 #ifdef __AVX2__ 140 #define FLAC__AVX2_SUPPORTED 1 141 #endif 142 #ifdef __FMA__ 143 #define FLAC__FMA_SUPPORTED 1 144 #endif 145 #endif /* compiler version */ 146 #endif /* intrinsics support */ 147 148 149 #ifndef FLAC__AVX_SUPPORTED 150 #define FLAC__AVX_SUPPORTED 0 151 #endif 152 153 typedef enum { 154 FLAC__CPUINFO_TYPE_IA32, 155 FLAC__CPUINFO_TYPE_X86_64, 156 FLAC__CPUINFO_TYPE_PPC, 157 FLAC__CPUINFO_TYPE_UNKNOWN 158 } FLAC__CPUInfo_Type; 159 160 typedef struct { 161 FLAC__bool intel; 162 163 FLAC__bool cmov; 164 FLAC__bool mmx; 165 FLAC__bool sse; 166 FLAC__bool sse2; 167 168 FLAC__bool sse3; 169 FLAC__bool ssse3; 170 FLAC__bool sse41; 171 FLAC__bool sse42; 172 FLAC__bool avx; 173 FLAC__bool avx2; 174 FLAC__bool fma; 175 } FLAC__CPUInfo_x86; 176 177 typedef struct { 178 FLAC__bool arch_3_00; 179 FLAC__bool arch_2_07; 180 } FLAC__CPUInfo_ppc; 181 182 typedef struct { 183 FLAC__bool use_asm; 184 FLAC__CPUInfo_Type type; 185 FLAC__CPUInfo_x86 x86; 186 FLAC__CPUInfo_ppc ppc; 187 } FLAC__CPUInfo; 188 189 void FLAC__cpu_info(FLAC__CPUInfo *info); 190 191 FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void); 192 193 void FLAC__cpu_info_asm_ia32(FLAC__uint32 level, FLAC__uint32 *eax, FLAC__uint32 *ebx, FLAC__uint32 *ecx, FLAC__uint32 *edx); 194 195 #endif 196