1 /* 2 * Copyright 2019 The libgav1 Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef LIBGAV1_SRC_UTILS_CPU_H_ 18 #define LIBGAV1_SRC_UTILS_CPU_H_ 19 20 #include <cstdint> 21 22 namespace libgav1 { 23 24 #if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86)) 25 #define LIBGAV1_X86_MSVC 26 #endif 27 28 #if !defined(LIBGAV1_ENABLE_SSE4_1) 29 #if defined(__SSE4_1__) || defined(LIBGAV1_X86_MSVC) 30 #define LIBGAV1_ENABLE_SSE4_1 1 31 #else 32 #define LIBGAV1_ENABLE_SSE4_1 0 33 #endif 34 #endif // !defined(LIBGAV1_ENABLE_SSE4_1) 35 36 #undef LIBGAV1_X86_MSVC 37 38 #if !defined(LIBGAV1_ENABLE_NEON) 39 // TODO(jzern): add support for _M_ARM64. 40 #if defined(__ARM_NEON__) || defined(__aarch64__) || \ 41 (defined(_MSC_VER) && defined(_M_ARM)) 42 #define LIBGAV1_ENABLE_NEON 1 43 #else 44 #define LIBGAV1_ENABLE_NEON 0 45 #endif 46 #endif // !defined(LIBGAV1_ENABLE_NEON) 47 48 enum CpuFeatures : uint8_t { 49 kSSE2 = 1 << 0, 50 #define LIBGAV1_CPU_SSE2 (1 << 0) 51 kSSSE3 = 1 << 1, 52 #define LIBGAV1_CPU_SSSE3 (1 << 1) 53 kSSE4_1 = 1 << 2, 54 #define LIBGAV1_CPU_SSE4_1 (1 << 2) 55 kAVX = 1 << 3, 56 #define LIBGAV1_CPU_AVX (1 << 3) 57 kAVX2 = 1 << 4, 58 #define LIBGAV1_CPU_AVX2 (1 << 4) 59 kNEON = 1 << 5, 60 #define LIBGAV1_CPU_NEON (1 << 5) 61 }; 62 63 // Returns a bit-wise OR of CpuFeatures supported by this platform. 64 uint32_t GetCpuInfo(); 65 66 } // namespace libgav1 67 68 #endif // LIBGAV1_SRC_UTILS_CPU_H_ 69