1// ======================================================================== //
2// Copyright 2009-2019 Intel Corporation //
3// //
4// Licensed under the Apache License, Version 2.0 (the "License"); //
5// you may not use this file except in compliance with the License. //
6// You may obtain a copy of the License at //
7// //
8// http://www.apache.org/licenses/LICENSE-2.0 //
9// //
10// Unless required by applicable law or agreed to in writing, software //
11// distributed under the License is distributed on an "AS IS" BASIS, //
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
13// See the License for the specific language governing permissions and //
14// limitations under the License. //
15// ======================================================================== //
16
17#include "platform.h"
18
19namespace oidn {
20
21 // ----------------------------------------------------------------------------
22 // Common functions
23 // ----------------------------------------------------------------------------
24
25 void* alignedMalloc(size_t size, size_t alignment)
26 {
27 if (size == 0)
28 return nullptr;
29
30 assert((alignment & (alignment-1)) == 0);
31 void* ptr = _mm_malloc(size, alignment);
32
33 if (ptr == nullptr)
34 throw std::bad_alloc();
35
36 return ptr;
37 }
38
39 void alignedFree(void* ptr)
40 {
41 if (ptr)
42 _mm_free(ptr);
43 }
44
45 // ----------------------------------------------------------------------------
46 // System information
47 // ----------------------------------------------------------------------------
48
49 std::string getPlatformName()
50 {
51 std::string name;
52
53 #if defined(__linux__)
54 name = "Linux";
55 #elif defined(__FreeBSD__)
56 name = "FreeBSD";
57 #elif defined(__CYGWIN__)
58 name = "Cygwin";
59 #elif defined(_WIN32)
60 name = "Windows";
61 #elif defined(__APPLE__)
62 name = "macOS";
63 #elif defined(__unix__)
64 name = "Unix";
65 #else
66 return "Unknown";
67 #endif
68
69 #if defined(__x86_64__) || defined(_M_X64) || defined(__ia64__) || defined(__aarch64__)
70 name += " (64-bit)";
71 #else
72 name += " (32-bit)";
73 #endif
74
75 return name;
76 }
77
78 std::string getCompilerName()
79 {
80 #if defined(__INTEL_COMPILER)
81 int mayor = __INTEL_COMPILER / 100 % 100;
82 int minor = __INTEL_COMPILER % 100;
83 std::string version = "Intel Compiler ";
84 version += toString(mayor);
85 version += "." + toString(minor);
86 #if defined(__INTEL_COMPILER_UPDATE)
87 version += "." + toString(__INTEL_COMPILER_UPDATE);
88 #endif
89 return version;
90 #elif defined(__clang__)
91 return "Clang " __clang_version__;
92 #elif defined(__GNUC__)
93 return "GCC " __VERSION__;
94 #elif defined(_MSC_VER)
95 std::string version = toString(_MSC_FULL_VER);
96 version.insert(4, ".");
97 version.insert(9, ".");
98 version.insert(2, ".");
99 return "Visual C++ Compiler " + version;
100 #else
101 return "Unknown";
102 #endif
103 }
104
105 std::string getBuildName()
106 {
107 #if defined(NDEBUG)
108 return "Release";
109 #else
110 return "Debug";
111 #endif
112 }
113
114} // namespace oidn
115