50 #ifdef __cpp_lib_hardware_interference_size
51 l1_share_max = std::hardware_constructive_interference_size;
52 l1_apart_min = std::hardware_destructive_interference_size;
65 return (jlong) si.dwPageSize;
66 #elif defined(JAU_OS_TYPE_UNIX) && defined(_SC_PAGESIZE)
67 return sysconf(_SC_PAGESIZE);
73 return std::thread::hardware_concurrency();
79 GetSystemInfo(&sysinfo);
80 return static_cast<size_t>( sysinfo.dwNumberOfProcessors );
81 #elif defined(JAU_OS_TYPE_UNIX) && defined(_SC_NPROCESSORS_ONLN)
82 return static_cast<size_t>( sysconf(_SC_NPROCESSORS_ONLN) );
83 #elif defined(JAU_OS_TYPE_UNIX) && defined(HW_NCPU)
84 int mib[] { CTL_HW, HW_NCPU };
86 size_t len =
sizeof(numCPU);
87 if( sysctl(mib, 2, &numCPU, &len, NULL, 0) || 0 >= numCPU ) {
90 return static_cast<size_t>(numCPU);
100 GetSystemInfo(&sysinfo);
101 return static_cast<size_t>( sysinfo.dwNumberOfProcessors );
102 #elif defined(JAU_OS_TYPE_UNIX) && defined(_SC_NPROCESSORS_CONF)
103 return static_cast<size_t>( sysconf(_SC_NPROCESSORS_CONF) );
104 #elif defined(JAU_OS_TYPE_UNIX) && defined(HW_NCPU)
105 int mib[] { CTL_HW, HW_AVAILCPU };
107 size_t len =
sizeof(numCPU);
108 if( sysctl(mib, 2, &numCPU, &len, NULL, 0) || 0 >= numCPU ) {
111 return static_cast<size_t>(numCPU);
119static void append_bitstr(std::string& out, T mask, T bit,
const std::string& bitstr,
bool& comma) {
120 if( bit == ( mask & bit ) ) {
121 if( comma ) { out.append(
", "); }
122 out.append(bitstr); comma =
true;
128 #if defined(__EMSCRIPTEN__)
136 #elif defined(__aarch64__)
139 #elif defined(__arm__)
142 #elif defined(__x86_64__)
145 #elif defined(__ia64__)
148 #elif defined(__i386__)
150 return cpu_family_t::X86_32;
151 #elif defined(__powerpc__)
152 #if defined(__LP64__)
159 #elif defined(__sparc__)
160 #if defined(__LP64__)
167 #elif defined(__mips__)
168 #if defined(__LP64__)
175 #elif defined(__sh__)
176 #if defined(__LP64__)
184 return cpu_family_t::UNDEF;
189#if defined(__i386__) || defined(__x86_64__)
193#elif defined(__INTEL__)
194 #include <ia32intrin.h>
195#elif defined(__GNUC__) || defined(__clang__)
199static void invoke_cpuid(uint32_t
type, uint32_t out[4]) {
200#if defined(_MSC_VER) || defined(__INTEL__)
201 __cpuid((
int*)out,
type);
202#elif defined(__GNUC__) || defined(__clang__)
203 __get_cpuid(
type, out, out+1, out+2, out+3);
205 #warning "No x86 cpuid supported for this compiler"
206 ::bzero(out,
sizeof(uint32_t)*4);
210static void invoke_cpuid_sublevel(uint32_t
type, uint32_t level, uint32_t out[4]) {
212 __cpuidex((
int*)out,
type, level);
213#elif defined(__GNUC__) || defined(__clang__)
214 __cpuid_count(
type, level, out[0], out[1], out[2], out[3]);
216 #warning "No x86 cpuid sublevel supported for this compiler"
217 ::bzero(out,
sizeof(uint32_t)*4);
261jau::cpu::CpuInfo::CpuInfo() noexcept
264 has_l1_minmax(false), l1_share_max(0), l1_apart_min(0),
276 if( !details_only ) {
296 if( !details_only ) {
size_t pointer_bits
See pointer_bit_size()
std::string toString() const noexcept
size_t l1_apart_min
Minimum offset between two objects to avoid false sharing if has_l1_minmax, or zero.
size_t online_core_count() const noexcept
Returns maximum number of available/online cores, i.e.
cpu_family_t family
cpu_family_t derived from Architectures predefined compiler macros.
bool has_l1_minmax
True if successfully queried l1_share_max and l1_apart_min.
arm32_hwcap1_t arm32_hwcap1
arm32_hwcap1_t info if available, i.e.
bool has_arm32_hwcap
True if successfully queried arm32_hwcap1 and arm32_hwcap1 on cpu_family_t::arm32.
size_t page_size
Size of a page in bytes or zero if not available.
arm64_hwcap_t arm64_hwcap
arm64_hwcap_t info if available, i.e.
size_t l1_share_max
Maximum size of contiguous memory to promote true sharing if has_l1_minmax, or zero.
bool has_arm64_hwcap
True if successfully queried arm64_hwcap on cpu_family_t::arm64.
arm32_hwcap2_t arm32_hwcap2
arm32_hwcap2_t info if available, i.e.
static bool get_arm32_hwcap(arm32_hwcap1_t &hwcap1, arm32_hwcap2_t &hwcap2) noexcept
static size_t get_concurrent_thread_count() noexcept
static size_t get_sys_online_core_count() noexcept
static size_t get_sys_max_core_count() noexcept
static size_t get_page_size() noexcept
static cpu_family_t get_cpu_family() noexcept
Returns cpu_family derived from Architectures predefined compiler macros.
static bool get_arm64_hwcap(arm64_hwcap_t &hwcap) noexcept
static bool get_cache_line_size(size_t &l1_share_max, size_t &l1_apart_min) noexcept
endian_t
Endian identifier, indicating endianess of all scalar types.
std::string to_string(const endian_t v) noexcept
Return std::string representation of the given endian.
@ native
Identifier for native platform type, one of the above.
constexpr std::underlying_type_t< E > number(const E v) noexcept
constexpr void append_bitstr(std::string &out, E mask, E bit, const std::string &bitstr, bool &comma)
std::string format_string(const char *format,...)
Returns a string according to printf() formatting rules and variable number of arguments following th...
constexpr size_t pointer_bit_size() noexcept
Returns the compile time pointer architecture size in bits.
@ x86_64
AMD/Intel 64-bit.
@ wasm64
WebAssembly 64-bit.
@ superh32
Hitachi SuperH 32bit.
@ superh64
Hitachi SuperH 64bit.
@ wasm32
WebAssembly 32-bit.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.