godot/thirdparty/embree/common/sys/sysinfo.cpp

// Copyright 2009-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#if defined(__INTEL_LLVM_COMPILER)
// prevents "'__thiscall' calling convention is not supported for this target" warning from TBB
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wignored-attributes"
#endif

#include "sysinfo.h"
#include "intrinsics.h"
#include "estring.h"
#include "ref.h"
#if defined(__FREEBSD__)
#include <sys/cpuset.h>
#include <pthread_np.h>
typedef cpuset_t cpu_set_t;
#endif

////////////////////////////////////////////////////////////////////////////////
/// All Platforms
////////////////////////////////////////////////////////////////////////////////

namespace embree
{
  NullTy null;
  
  std::string getPlatformName() 
  {}

  std::string getCompilerName()
  {}

  std::string getCPUVendor()
  {}

  CPU getCPUModel() 
  {}

  std::string stringOfCPUModel(CPU model)
  {}

#if defined(__X86_ASM__)
  /* constants to access destination registers of CPUID instruction */
  static const int EAX =;
  static const int EBX =;
  static const int ECX =;
  static const int EDX =;

  /* cpuid[eax=1].ecx */
  static const int CPU_FEATURE_BIT_SSE3   =;
  static const int CPU_FEATURE_BIT_SSSE3  =;
  static const int CPU_FEATURE_BIT_FMA3   =;
  static const int CPU_FEATURE_BIT_SSE4_1 =;
  static const int CPU_FEATURE_BIT_SSE4_2 =;
  //static const int CPU_FEATURE_BIT_MOVBE  = 1 << 22;
  static const int CPU_FEATURE_BIT_POPCNT =;
  //static const int CPU_FEATURE_BIT_XSAVE  = 1 << 26;
  static const int CPU_FEATURE_BIT_OXSAVE =;
  static const int CPU_FEATURE_BIT_AVX    =;
  static const int CPU_FEATURE_BIT_F16C   =;
  static const int CPU_FEATURE_BIT_RDRAND =;

  /* cpuid[eax=1].edx */
  static const int CPU_FEATURE_BIT_SSE  =;
  static const int CPU_FEATURE_BIT_SSE2 =;

  /* cpuid[eax=0x80000001].ecx */
  static const int CPU_FEATURE_BIT_LZCNT =;

  /* cpuid[eax=7,ecx=0].ebx */
  static const int CPU_FEATURE_BIT_BMI1    =;
  static const int CPU_FEATURE_BIT_AVX2    =;
  static const int CPU_FEATURE_BIT_BMI2    =;
  static const int CPU_FEATURE_BIT_AVX512F =;     // AVX512F  (foundation)
  static const int CPU_FEATURE_BIT_AVX512DQ =;    // AVX512DQ (doubleword and quadword instructions)
  static const int CPU_FEATURE_BIT_AVX512PF =;    // AVX512PF (prefetch gather/scatter instructions)
  static const int CPU_FEATURE_BIT_AVX512ER =;    // AVX512ER (exponential and reciprocal instructions)
  static const int CPU_FEATURE_BIT_AVX512CD =;    // AVX512CD (conflict detection instructions)
  static const int CPU_FEATURE_BIT_AVX512BW =;    // AVX512BW (byte and word instructions)
  static const int CPU_FEATURE_BIT_AVX512VL =;    // AVX512VL (vector length extensions)
  static const int CPU_FEATURE_BIT_AVX512IFMA =;  // AVX512IFMA (integer fused multiple-add instructions)
  
  /* cpuid[eax=7,ecx=0].ecx */
  static const int CPU_FEATURE_BIT_AVX512VBMI =;   // AVX512VBMI (vector bit manipulation instructions)
#endif

#if defined(__X86_ASM__)
  __noinline int64_t get_xcr0() 
  {}
#endif

  int getCPUFeatures()
  {}

  std::string stringOfCPUFeatures(int features)
  {}
  
  std::string stringOfISA (int isa)
  {}

  bool hasISA(int features, int isa) {}
  
  std::string supportedTargetList (int features)
  {}
}

////////////////////////////////////////////////////////////////////////////////
/// Windows Platform
////////////////////////////////////////////////////////////////////////////////

#if defined(__WIN32__)

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <psapi.h>

namespace embree
{
  std::string getExecutableFileName() {
    char filename[1024];
    if (!GetModuleFileName(nullptr, filename, sizeof(filename)))
      return std::string();
    return std::string(filename);
  }

  unsigned int getNumberOfLogicalThreads() 
  {
    static int nThreads = -1;
    if (nThreads != -1) return nThreads;

    typedef WORD (WINAPI *GetActiveProcessorGroupCountFunc)();
    typedef DWORD (WINAPI *GetActiveProcessorCountFunc)(WORD);
    HMODULE hlib = LoadLibrary("Kernel32");
    GetActiveProcessorGroupCountFunc pGetActiveProcessorGroupCount = (GetActiveProcessorGroupCountFunc)GetProcAddress(hlib, "GetActiveProcessorGroupCount");
    GetActiveProcessorCountFunc      pGetActiveProcessorCount      = (GetActiveProcessorCountFunc)     GetProcAddress(hlib, "GetActiveProcessorCount");

    if (pGetActiveProcessorGroupCount && pGetActiveProcessorCount) 
    {
      int groups = pGetActiveProcessorGroupCount();
      int totalProcessors = 0;
      for (int i = 0; i < groups; i++) 
        totalProcessors += pGetActiveProcessorCount(i);
      nThreads = totalProcessors;
    }
    else
    {
      SYSTEM_INFO sysinfo;
      GetSystemInfo(&sysinfo);
      nThreads = sysinfo.dwNumberOfProcessors;
    }
    assert(nThreads);
    return nThreads;
  }

  int getTerminalWidth() 
  {
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    if (handle == INVALID_HANDLE_VALUE) return 80;
    CONSOLE_SCREEN_BUFFER_INFO info;
    memset(&info,0,sizeof(info));
    GetConsoleScreenBufferInfo(handle, &info);
    return info.dwSize.X;
  }

  double getSeconds() 
  {
    LARGE_INTEGER freq, val;
    QueryPerformanceFrequency(&freq);
    QueryPerformanceCounter(&val);
    return (double)val.QuadPart / (double)freq.QuadPart;
  }

  void sleepSeconds(double t) {
    Sleep(DWORD(1000.0*t));
  }

  size_t getVirtualMemoryBytes()
  {
    PROCESS_MEMORY_COUNTERS info;
    GetProcessMemoryInfo( GetCurrentProcess( ), &info, sizeof(info) );
    return (size_t)info.QuotaPeakPagedPoolUsage;
  }

  size_t getResidentMemoryBytes()
  {
    PROCESS_MEMORY_COUNTERS info;
    GetProcessMemoryInfo( GetCurrentProcess( ), &info, sizeof(info) );
    return (size_t)info.WorkingSetSize;
  }
}
#endif

////////////////////////////////////////////////////////////////////////////////
/// Linux Platform
////////////////////////////////////////////////////////////////////////////////

#if defined(__LINUX__)

#include <stdio.h>
#include <unistd.h>

namespace embree
{
  std::string getExecutableFileName() 
  {}

  size_t getVirtualMemoryBytes()
  {}

  size_t getResidentMemoryBytes()
  {}
}

#endif

////////////////////////////////////////////////////////////////////////////////
/// FreeBSD Platform
////////////////////////////////////////////////////////////////////////////////

#if defined (__FreeBSD__)

#include <sys/sysctl.h>

namespace embree
{
  std::string getExecutableFileName()
  {
    const int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
    char buf[4096];
    memset(buf,0,sizeof(buf));
    size_t len = sizeof(buf)-1;
    if (sysctl(mib, 4, buf, &len, 0x0, 0) == -1)
      return std::string();
    return std::string(buf);
  }

  size_t getVirtualMemoryBytes() {
    return 0;
  }
   
  size_t getResidentMemoryBytes() {
    return 0;
  }
}

#endif

////////////////////////////////////////////////////////////////////////////////
/// Mac OS X Platform
////////////////////////////////////////////////////////////////////////////////

#if defined(__MACOSX__)

#include <mach-o/dyld.h>

namespace embree
{
  std::string getExecutableFileName()
  {
    char buf[4096];
    uint32_t size = sizeof(buf);
    if (_NSGetExecutablePath(buf, &size) != 0)
      return std::string();
    return std::string(buf);
  }

  size_t getVirtualMemoryBytes() {
    return 0;
  }
   
  size_t getResidentMemoryBytes() {
    return 0;
  }
}

#endif

////////////////////////////////////////////////////////////////////////////////
/// Unix Platform
////////////////////////////////////////////////////////////////////////////////

#if defined(__UNIX__)

#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <pthread.h>

#if defined(__EMSCRIPTEN__)
#include <emscripten.h>

// -- GODOT start --
extern "C" {
extern int godot_js_os_hw_concurrency_get();
}
// -- GODOT end --
#endif

namespace embree
{
  unsigned int getNumberOfLogicalThreads() 
  {}

  int getTerminalWidth() 
  {}

  double getSeconds() {}

  void sleepSeconds(double t) {}
}
#endif

#if defined(__INTEL_LLVM_COMPILER)
#pragma clang diagnostic pop
#endif