cpuinfo.cpp 1.92 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
// [AsmJit]
// Complete x86/x64 JIT and Remote Assembler for C++.
//
// [License]
// Zlib - See LICENSE.md file in the package.

// [Export]
#define ASMJIT_EXPORTS

// [Dependencies - AsmJit]
#include "../base/cpuinfo.h"

13
#if defined(ASMJIT_ARCH_X86) || defined(ASMJIT_ARCH_X64)
14
15
16
#include "../x86/x86cpuinfo.h"
#else
// ?
17
#endif
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

// [Dependencies - Posix]
#if defined(ASMJIT_OS_POSIX)
# include <errno.h>
# include <sys/statvfs.h>
# include <sys/utsname.h>
# include <unistd.h>
#endif // ASMJIT_OS_POSIX

// [Api-Begin]
#include "../apibegin.h"

namespace asmjit {

// ============================================================================
// [asmjit::CpuInfo - DetectHwThreadsCount]
// ============================================================================

uint32_t CpuInfo::detectHwThreadsCount() {
#if defined(ASMJIT_OS_WINDOWS)
  SYSTEM_INFO info;
  ::GetSystemInfo(&info);
  return info.dwNumberOfProcessors;
#elif defined(ASMJIT_OS_POSIX) && defined(_SC_NPROCESSORS_ONLN)
  // It seems that sysconf returns the number of "logical" processors on both
  // mac and linux.  So we get the number of "online logical" processors.
  long res = ::sysconf(_SC_NPROCESSORS_ONLN);
  if (res == -1) return 1;

  return static_cast<uint32_t>(res);
#else
  return 1;
#endif
}

// ============================================================================
// [asmjit::CpuInfo - GetHost]
// ============================================================================

57
#if defined(ASMJIT_ARCH_X86) || defined(ASMJIT_ARCH_X64)
58
59
60
61
62
63
64
struct AutoX86CpuInfo : public X86CpuInfo {
  ASMJIT_INLINE AutoX86CpuInfo() : X86CpuInfo() {
    X86CpuUtil::detect(this);
  }
};
#else
#error "AsmJit - Unsupported CPU."
65
#endif
66
67

const CpuInfo* CpuInfo::getHost() {
68
#if defined(ASMJIT_ARCH_X86) || defined(ASMJIT_ARCH_X64)
69
70
71
  static AutoX86CpuInfo cpuInfo;
#else
#error "AsmJit - Unsupported CPU."
72
#endif
73
74
75
76
77
78
79
  return &cpuInfo;
}

} // asmjit namespace

// [Api-End]
#include "../apiend.h"