OpenTTD Source 20260218-master-g2123fca5ea
cpu.cpp File Reference

OS/CPU/compiler dependent CPU specific calls. More...

#include "stdafx.h"
#include "core/bitmath_func.hpp"
#include "safeguards.h"

Go to the source code of this file.

Typedefs

using CPUIDArray = std::array<int, 4>
 Container for CPUID information.

Functions

static CPUIDArray CPUID (int type)
 Get the CPUID information from the CPU.
bool HasCPUIDFlag (uint type, uint index, uint bit)
 Check whether the current CPU has the given flag.

Detailed Description

OS/CPU/compiler dependent CPU specific calls.

Definition in file cpu.cpp.

Typedef Documentation

◆ CPUIDArray

using CPUIDArray = std::array<int, 4>

Container for CPUID information.

Definition at line 16 of file cpu.cpp.

Function Documentation

◆ CPUID()

CPUIDArray CPUID ( int type)
static

Get the CPUID information from the CPU.

Definitions for CPU detection:

MSVC offers cpu information while gcc only implements in gcc 4.8 __builtin_cpu_supports and friends http://msdn.microsoft.com/library/vstudio/hskdteyh%28v=vs.100%29.aspx http://gcc.gnu.org/onlinedocs/gcc/X86-Built-in-Functions.html

Other platforms/architectures don't have CPUID, so zero the info and then most (if not all) of the features are set as if they do not exist.

Parameters
typeThe information this instruction should retrieve.
Returns
The retrieved info. All zeros on architectures without CPUID.

Definition at line 33 of file cpu.cpp.

Referenced by HasCPUIDFlag().

◆ HasCPUIDFlag()

bool HasCPUIDFlag ( uint type,
uint index,
uint bit )

Check whether the current CPU has the given flag.

Parameters
typeThe type to be passing to cpuid (usually 1).
indexThe index in the returned info array.
bitThe bit index that needs to be set.
Returns
The value of the bit, or false when there is no CPUID or the type is not available.

Definition at line 80 of file cpu.cpp.

References CPUID(), and HasBit().