1/*
2 *  Copyright 2011 The LibYuv Project Authors. All rights reserved.
3 *
4 *  Use of this source code is governed by a BSD-style license
5 *  that can be found in the LICENSE file in the root of the source
6 *  tree. An additional intellectual property rights grant can be found
7 *  in the file PATENTS.  All contributing project authors may
8 *  be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef INCLUDE_LIBYUV_CPU_ID_H_  // NOLINT
12#define INCLUDE_LIBYUV_CPU_ID_H_
13
14#include "libyuv/basic_types.h"
15
16#ifdef __cplusplus
17namespace libyuv {
18extern "C" {
19#endif
20
21// Internal flag to indicate cpuid is initialized.
22static const int kCpuInitialized = 0x1;
23
24// These flags are only valid on ARM processors.
25static const int kCpuHasARM = 0x2;
26static const int kCpuHasNEON = 0x4;
27// 0x8 reserved for future ARM flag.
28
29// These flags are only valid on x86 processors.
30static const int kCpuHasX86 = 0x10;
31static const int kCpuHasSSE2 = 0x20;
32static const int kCpuHasSSSE3 = 0x40;
33static const int kCpuHasSSE41 = 0x80;
34static const int kCpuHasSSE42 = 0x100;
35static const int kCpuHasAVX = 0x200;
36static const int kCpuHasAVX2 = 0x400;
37
38// Internal function used to auto-init.
39LIBYUV_API
40int InitCpuFlags(void);
41
42// Internal function for parsing /proc/cpuinfo.
43LIBYUV_API
44int ArmCpuCaps(const char* cpuinfo_name);
45
46// Detect CPU has SSE2 etc.
47// Test_flag parameter should be one of kCpuHas constants above.
48// returns non-zero if instruction set is detected
49static __inline int TestCpuFlag(int test_flag) {
50  LIBYUV_API extern int cpu_info_;
51  return (cpu_info_ ? cpu_info_ : InitCpuFlags()) & test_flag;
52}
53
54// For testing, allow CPU flags to be disabled.
55// ie MaskCpuFlags(~kCpuHasSSSE3) to disable SSSE3.
56// MaskCpuFlags(-1) to enable all cpu specific optimizations.
57// MaskCpuFlags(0) to disable all cpu specific optimizations.
58LIBYUV_API
59void MaskCpuFlags(int enable_flags);
60
61// Low level cpuid for X86. Returns zeros on other CPUs.
62LIBYUV_API
63void CpuId(int cpu_info[4], int info_type);
64
65#ifdef __cplusplus
66}  // extern "C"
67}  // namespace libyuv
68#endif
69
70#endif  // INCLUDE_LIBYUV_CPU_ID_H_  NOLINT
71