~mmach/netext73/mesa-haswell

« back to all changes in this revision

Viewing changes to src/util/u_cpu_detect.h

  • Committer: mmach
  • Date: 2022-09-22 19:56:13 UTC
  • Revision ID: netbit73@gmail.com-20220922195613-wtik9mmy20tmor0i
2022-09-22 21:17:09

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**************************************************************************
2
 
 *
3
 
 * Copyright 2008 Dennis Smit
4
 
 * All Rights Reserved.
5
 
 *
6
 
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 
 * copy of this software and associated documentation files (the "Software"),
8
 
 * to deal in the Software without restriction, including without limitation
9
 
 * on the rights to use, copy, modify, merge, publish, distribute, sub
10
 
 * license, and/or sell copies of the Software, and to permit persons to whom
11
 
 * the Software is furnished to do so, subject to the following conditions:
12
 
 *
13
 
 * The above copyright notice and this permission notice (including the next
14
 
 * paragraph) shall be included in all copies or substantial portions of the
15
 
 * Software.
16
 
 *
17
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
20
 
 * AUTHORS, COPYRIGHT HOLDERS, AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
21
 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22
 
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23
 
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24
 
 *
25
 
 ***************************************************************************/
26
 
 
27
 
/**
28
 
 * @file
29
 
 * CPU feature detection.
30
 
 *
31
 
 * @author Dennis Smit
32
 
 * @author Based on the work of Eric Anholt <anholt@FreeBSD.org>
33
 
 */
34
 
 
35
 
#ifndef _UTIL_CPU_DETECT_H
36
 
#define _UTIL_CPU_DETECT_H
37
 
 
38
 
#include <stdbool.h>
39
 
 
40
 
#include "pipe/p_config.h"
41
 
#include "util/u_thread.h"
42
 
 
43
 
 
44
 
#ifdef  __cplusplus
45
 
extern "C" {
46
 
#endif
47
 
 
48
 
enum cpu_family {
49
 
   CPU_UNKNOWN,
50
 
 
51
 
   CPU_AMD_ZEN1_ZEN2,
52
 
   CPU_AMD_ZEN_HYGON,
53
 
   CPU_AMD_ZEN3,
54
 
   CPU_AMD_ZEN_NEXT,
55
 
   CPU_AMD_LAST,
56
 
 
57
 
   CPU_S390X,
58
 
};
59
 
 
60
 
typedef uint32_t util_affinity_mask[UTIL_MAX_CPUS / 32];
61
 
 
62
 
struct util_cpu_caps_t {
63
 
   /**
64
 
    * Number of CPUs available to the process.
65
 
    *
66
 
    * This will be less than or equal to \c max_cpus.  This is the number of
67
 
    * CPUs that are online and available to the process.
68
 
    */
69
 
   int16_t nr_cpus;
70
 
 
71
 
   /**
72
 
    * Maximum number of CPUs that can be online in the system.
73
 
    *
74
 
    * This will be greater than or equal to \c nr_cpus.  This is the number of
75
 
    * CPUs installed in the system.  \c nr_cpus will be less if some CPUs are
76
 
    * offline.
77
 
    */
78
 
   int16_t max_cpus;
79
 
 
80
 
   enum cpu_family family;
81
 
 
82
 
   /* Feature flags */
83
 
   int x86_cpu_type;
84
 
   unsigned cacheline;
85
 
 
86
 
   unsigned has_intel:1;
87
 
   unsigned has_tsc:1;
88
 
   unsigned has_mmx:1;
89
 
   unsigned has_mmx2:1;
90
 
   unsigned has_sse:1;
91
 
   unsigned has_sse2:1;
92
 
   unsigned has_sse3:1;
93
 
   unsigned has_ssse3:1;
94
 
   unsigned has_sse4_1:1;
95
 
   unsigned has_sse4_2:1;
96
 
   unsigned has_popcnt:1;
97
 
   unsigned has_avx:1;
98
 
   unsigned has_avx2:1;
99
 
   unsigned has_f16c:1;
100
 
   unsigned has_fma:1;
101
 
   unsigned has_3dnow:1;
102
 
   unsigned has_3dnow_ext:1;
103
 
   unsigned has_xop:1;
104
 
   unsigned has_altivec:1;
105
 
   unsigned has_vsx:1;
106
 
   unsigned has_daz:1;
107
 
   unsigned has_neon:1;
108
 
   unsigned has_msa:1;
109
 
 
110
 
   unsigned has_avx512f:1;
111
 
   unsigned has_avx512dq:1;
112
 
   unsigned has_avx512ifma:1;
113
 
   unsigned has_avx512pf:1;
114
 
   unsigned has_avx512er:1;
115
 
   unsigned has_avx512cd:1;
116
 
   unsigned has_avx512bw:1;
117
 
   unsigned has_avx512vl:1;
118
 
   unsigned has_avx512vbmi:1;
119
 
 
120
 
   unsigned num_L3_caches;
121
 
   unsigned num_cpu_mask_bits;
122
 
 
123
 
   uint16_t cpu_to_L3[UTIL_MAX_CPUS];
124
 
   /* Affinity masks for each L3 cache. */
125
 
   util_affinity_mask *L3_affinity_mask;
126
 
};
127
 
 
128
 
#define U_CPU_INVALID_L3 0xffff
129
 
 
130
 
static inline const struct util_cpu_caps_t *
131
 
util_get_cpu_caps(void)
132
 
{
133
 
        extern struct util_cpu_caps_t util_cpu_caps;
134
 
 
135
 
        /* If you hit this assert, it means that something is using the
136
 
         * cpu-caps without having first called util_cpu_detect()
137
 
         */
138
 
        assert(util_cpu_caps.nr_cpus >= 1);
139
 
 
140
 
        return &util_cpu_caps;
141
 
}
142
 
 
143
 
void util_cpu_detect(void);
144
 
 
145
 
 
146
 
#ifdef  __cplusplus
147
 
}
148
 
#endif
149
 
 
150
 
 
151
 
#endif /* _UTIL_CPU_DETECT_H */