clang-format the src/System directory
Bug: b/144825072
Change-Id: Ifc469786ac5fa2a8ed00e95069e1a2839e320e96
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/39657
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/System/Build.hpp b/src/System/Build.hpp
index 85dc018..788ece7 100644
--- a/src/System/Build.hpp
+++ b/src/System/Build.hpp
@@ -18,22 +18,22 @@
// Define MEMORY_SANITIZER_ENABLED to 1 if the project was build with the memory
// sanitizer enabled (-fsanitize=memory).
#if defined(__SANITIZE_MEMORY__)
-#define MEMORY_SANITIZER_ENABLED 1
-#else // defined(__SANITIZE_MEMORY__)
-#if defined(__clang__)
-#if __has_feature(memory_sanitizer)
-#define MEMORY_SANITIZER_ENABLED 1
-#endif // __has_feature(memory_sanitizer)
-#endif // defined(__clang__)
-#endif // defined(__SANITIZE_MEMORY__)
+# define MEMORY_SANITIZER_ENABLED 1
+#else // defined(__SANITIZE_MEMORY__)
+# if defined(__clang__)
+# if __has_feature(memory_sanitizer)
+# define MEMORY_SANITIZER_ENABLED 1
+# endif // __has_feature(memory_sanitizer)
+# endif // defined(__clang__)
+#endif // defined(__SANITIZE_MEMORY__)
// MEMORY_SANITIZER_ONLY(X) resolves to X if MEMORY_SANITIZER_ENABLED is defined
// to a non-zero value, otherwise MEMORY_SANITIZER_ONLY() is stripped by the
// preprocessor.
#if MEMORY_SANITIZER_ENABLED
-#define MEMORY_SANITIZER_ONLY(x) x
+# define MEMORY_SANITIZER_ONLY(x) x
#else
-#define MEMORY_SANITIZER_ONLY(x)
-#endif // MEMORY_SANITIZER_ENABLED
+# define MEMORY_SANITIZER_ONLY(x)
+#endif // MEMORY_SANITIZER_ENABLED
-#endif // Build_hpp
+#endif // Build_hpp
diff --git a/src/System/CPUID.cpp b/src/System/CPUID.cpp
index 3c62828..698fe887 100644
--- a/src/System/CPUID.cpp
+++ b/src/System/CPUID.cpp
@@ -15,16 +15,16 @@
#include "CPUID.hpp"
#if defined(_WIN32)
- #ifndef WIN32_LEAN_AND_MEAN
- #define WIN32_LEAN_AND_MEAN
- #endif
- #include <windows.h>
- #include <intrin.h>
- #include <float.h>
+# ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+# endif
+# include <windows.h>
+# include <intrin.h>
+# include <float.h>
#else
- #include <unistd.h>
- #include <sched.h>
- #include <sys/types.h>
+# include <unistd.h>
+# include <sched.h>
+# include <sys/types.h>
#endif
namespace sw {
@@ -164,18 +164,20 @@
static void cpuid(int registers[4], int info)
{
- #if defined(__i386__) || defined(__x86_64__)
- #if defined(_WIN32)
- __cpuid(registers, info);
- #else
- __asm volatile("cpuid": "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]): "a" (info));
- #endif
- #else
- registers[0] = 0;
- registers[1] = 0;
- registers[2] = 0;
- registers[3] = 0;
- #endif
+#if defined(__i386__) || defined(__x86_64__)
+# if defined(_WIN32)
+ __cpuid(registers, info);
+# else
+ __asm volatile("cpuid"
+ : "=a"(registers[0]), "=b"(registers[1]), "=c"(registers[2]), "=d"(registers[3])
+ : "a"(info));
+# endif
+#else
+ registers[0] = 0;
+ registers[1] = 0;
+ registers[2] = 0;
+ registers[3] = 0;
+#endif
}
bool CPUID::detectMMX()
@@ -231,55 +233,55 @@
{
int cores = 0;
- #if defined(_WIN32)
- DWORD_PTR processAffinityMask = 1;
- DWORD_PTR systemAffinityMask = 1;
+#if defined(_WIN32)
+ DWORD_PTR processAffinityMask = 1;
+ DWORD_PTR systemAffinityMask = 1;
- GetProcessAffinityMask(GetCurrentProcess(), &processAffinityMask, &systemAffinityMask);
+ GetProcessAffinityMask(GetCurrentProcess(), &processAffinityMask, &systemAffinityMask);
- while(systemAffinityMask)
+ while(systemAffinityMask)
+ {
+ if(systemAffinityMask & 1)
{
- if(systemAffinityMask & 1)
- {
- cores++;
- }
-
- systemAffinityMask >>= 1;
+ cores++;
}
- #else
- cores = sysconf(_SC_NPROCESSORS_ONLN);
- #endif
- if(cores < 1) cores = 1;
+ systemAffinityMask >>= 1;
+ }
+#else
+ cores = sysconf(_SC_NPROCESSORS_ONLN);
+#endif
+
+ if(cores < 1) cores = 1;
if(cores > 16) cores = 16;
- return cores; // FIXME: Number of physical cores
+ return cores; // FIXME: Number of physical cores
}
int CPUID::detectAffinity()
{
int cores = 0;
- #if defined(_WIN32)
- DWORD_PTR processAffinityMask = 1;
- DWORD_PTR systemAffinityMask = 1;
+#if defined(_WIN32)
+ DWORD_PTR processAffinityMask = 1;
+ DWORD_PTR systemAffinityMask = 1;
- GetProcessAffinityMask(GetCurrentProcess(), &processAffinityMask, &systemAffinityMask);
+ GetProcessAffinityMask(GetCurrentProcess(), &processAffinityMask, &systemAffinityMask);
- while(processAffinityMask)
+ while(processAffinityMask)
+ {
+ if(processAffinityMask & 1)
{
- if(processAffinityMask & 1)
- {
- cores++;
- }
-
- processAffinityMask >>= 1;
+ cores++;
}
- #else
- return detectCoreCount(); // FIXME: Assumes no affinity limitation
- #endif
- if(cores < 1) cores = 1;
+ processAffinityMask >>= 1;
+ }
+#else
+ return detectCoreCount(); // FIXME: Assumes no affinity limitation
+#endif
+
+ if(cores < 1) cores = 1;
if(cores > 16) cores = 16;
return cores;
@@ -287,11 +289,11 @@
void CPUID::setFlushToZero(bool enable)
{
- #if defined(_MSC_VER)
- _controlfp(enable ? _DN_FLUSH : _DN_SAVE, _MCW_DN);
- #else
- // Unimplemented
- #endif
+#if defined(_MSC_VER)
+ _controlfp(enable ? _DN_FLUSH : _DN_SAVE, _MCW_DN);
+#else
+ // Unimplemented
+#endif
}
void CPUID::setDenormalsAreZero(bool enable)
diff --git a/src/System/CPUID.hpp b/src/System/CPUID.hpp
index 5fbb89f..407af16 100644
--- a/src/System/CPUID.hpp
+++ b/src/System/CPUID.hpp
@@ -18,11 +18,11 @@
namespace sw {
#if !defined(__i386__) && defined(_M_IX86)
- #define __i386__ 1
+# define __i386__ 1
#endif
-#if !defined(__x86_64__) && (defined(_M_AMD64) || defined (_M_X64))
- #define __x86_64__ 1
+#if !defined(__x86_64__) && (defined(_M_AMD64) || defined(_M_X64))
+# define __x86_64__ 1
#endif
class CPUID
@@ -30,7 +30,7 @@
public:
static bool supportsMMX();
static bool supportsCMOV();
- static bool supportsMMX2(); // MMX instructions added by SSE: pshufw, pmulhuw, pmovmskb, pavgw/b, pextrw, pinsrw, pmaxsw/ub, etc.
+ static bool supportsMMX2(); // MMX instructions added by SSE: pshufw, pmulhuw, pmovmskb, pavgw/b, pextrw, pinsrw, pmaxsw/ub, etc.
static bool supportsSSE();
static bool supportsSSE2();
static bool supportsSSE3();
@@ -47,8 +47,8 @@
static void setEnableSSSE3(bool enable);
static void setEnableSSE4_1(bool enable);
- static void setFlushToZero(bool enable); // Denormal results are written as zero
- static void setDenormalsAreZero(bool enable); // Denormal inputs are read as zero
+ static void setFlushToZero(bool enable); // Denormal results are written as zero
+ static void setDenormalsAreZero(bool enable); // Denormal inputs are read as zero
private:
static bool MMX;
@@ -98,7 +98,7 @@
inline bool CPUID::supportsMMX2()
{
- return supportsSSE(); // Coincides with 64-bit integer vector instructions supported by SSE
+ return supportsSSE(); // Coincides with 64-bit integer vector instructions supported by SSE
}
inline bool CPUID::supportsSSE()
@@ -138,4 +138,4 @@
} // namespace sw
-#endif // sw_CPUID_hpp
+#endif // sw_CPUID_hpp
diff --git a/src/System/Configurator.cpp b/src/System/Configurator.cpp
index e544383..410fb29 100644
--- a/src/System/Configurator.cpp
+++ b/src/System/Configurator.cpp
@@ -14,17 +14,17 @@
#include "Configurator.hpp"
-#include <iostream>
#include <fstream>
+#include <iostream>
using namespace std;
-#include <stdio.h>
-#include <stdarg.h>
#include <ctype.h>
+#include <stdarg.h>
+#include <stdio.h>
#if defined(__unix__)
-#include <unistd.h>
+# include <unistd.h>
#endif
namespace sw {
@@ -42,12 +42,12 @@
bool Configurator::readFile()
{
- #if defined(__unix__)
- if(access(path.c_str(), R_OK) != 0)
- {
- return false;
- }
- #endif
+#if defined(__unix__)
+ if(access(path.c_str(), R_OK) != 0)
+ {
+ return false;
+ }
+#endif
fstream file(path.c_str(), ios::in);
if(file.fail()) return false;
@@ -66,7 +66,7 @@
if(!isprint(line[0]))
{
- // printf("Failing on char %d\n", line[0]);
+ // printf("Failing on char %d\n", line[0]);
file.close();
return false;
}
@@ -77,7 +77,7 @@
{
switch(line[pLeft])
{
- case '[':
+ case '[':
{
string::size_type pRight = line.find_last_of("]");
@@ -88,17 +88,17 @@
}
}
break;
- case '=':
+ case '=':
{
string valueName = line.substr(0, pLeft);
string value = line.substr(pLeft + 1);
addValue(keyName, valueName, value);
}
break;
- case ';':
- case '#':
- // Ignore comments
- break;
+ case ';':
+ case '#':
+ // Ignore comments
+ break;
}
}
}
@@ -116,17 +116,18 @@
void Configurator::writeFile(std::string title)
{
- #if defined(__unix__)
- if(access(path.c_str(), W_OK) != 0)
- {
- return;
- }
- #endif
+#if defined(__unix__)
+ if(access(path.c_str(), W_OK) != 0)
+ {
+ return;
+ }
+#endif
fstream file(path.c_str(), ios::out);
if(file.fail()) return;
- file << "; " << title << endl << endl;
+ file << "; " << title << endl
+ << endl;
for(unsigned int keyID = 0; keyID < sections.size(); keyID++)
{
@@ -237,18 +238,18 @@
}
unsigned int Configurator::getFormatted(string keyName, string valueName, char *format,
- void *v1, void *v2, void *v3, void *v4,
- void *v5, void *v6, void *v7, void *v8,
- void *v9, void *v10, void *v11, void *v12,
- void *v13, void *v14, void *v15, void *v16)
+ void *v1, void *v2, void *v3, void *v4,
+ void *v5, void *v6, void *v7, void *v8,
+ void *v9, void *v10, void *v11, void *v12,
+ void *v13, void *v14, void *v15, void *v16)
{
string value = getValue(keyName, valueName);
if(!value.length()) return false;
unsigned int nVals = sscanf(value.c_str(), format,
- v1, v2, v3, v4, v5, v6, v7, v8,
- v9, v10, v11, v12, v13, v14, v15, v16);
+ v1, v2, v3, v4, v5, v6, v7, v8,
+ v9, v10, v11, v12, v13, v14, v15, v16);
return nVals;
}
diff --git a/src/System/Configurator.hpp b/src/System/Configurator.hpp
index 9a27a39..1cd8f7c 100644
--- a/src/System/Configurator.hpp
+++ b/src/System/Configurator.hpp
@@ -64,4 +64,4 @@
} // namespace sw
-#endif // sw_Configurator_hpp
+#endif // sw_Configurator_hpp
diff --git a/src/System/Debug.cpp b/src/System/Debug.cpp
index dd66d56..5fafc90 100644
--- a/src/System/Debug.cpp
+++ b/src/System/Debug.cpp
@@ -14,8 +14,8 @@
#include "Debug.hpp"
-#include <stdio.h>
#include <stdarg.h>
+#include <stdio.h>
namespace sw {
diff --git a/src/System/Debug.hpp b/src/System/Debug.hpp
index d26623c..5c62d7b 100644
--- a/src/System/Debug.hpp
+++ b/src/System/Debug.hpp
@@ -16,44 +16,50 @@
#define Debug_hpp
#if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) && !defined(ANDROID_NDK_BUILD)
-#include "DebugAndroid.hpp"
+# include "DebugAndroid.hpp"
#else
-#include <assert.h>
-#include <stdio.h>
+# include <assert.h>
+# include <stdio.h>
-#undef min
-#undef max
+# undef min
+# undef max
namespace sw {
void trace(const char *format, ...);
inline void trace() {}
-}
+} // namespace sw
-#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
- #define TRACE(format, ...) sw::trace("[0x%0.8X]%s(" format ")\n", this, __FUNCTION__, ##__VA_ARGS__)
-#else
- #define TRACE(...) ((void)0)
-#endif
+# if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
+# define TRACE(format, ...) sw::trace("[0x%0.8X]%s(" format ")\n", this, __FUNCTION__, ##__VA_ARGS__)
+# else
+# define TRACE(...) ((void)0)
+# endif
-#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
- #define UNIMPLEMENTED(...) do { \
- sw::trace("\t! Unimplemented: %s(%d): ", __FUNCTION__, __LINE__); \
- sw::trace(__VA_ARGS__); \
- sw::trace("\n"); \
- ASSERT(false); \
- } while(0)
-#else
- #define UNIMPLEMENTED(...) ((void)0)
-#endif
+# if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
+# define UNIMPLEMENTED(...) \
+ do \
+ { \
+ sw::trace("\t! Unimplemented: %s(%d): ", __FUNCTION__, __LINE__); \
+ sw::trace(__VA_ARGS__); \
+ sw::trace("\n"); \
+ ASSERT(false); \
+ } while(0)
+# else
+# define UNIMPLEMENTED(...) ((void)0)
+# endif
-#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
- #define ASSERT(expression) {if(!(expression)) sw::trace("\t! Assert failed in %s(%d): " #expression "\n", __FUNCTION__, __LINE__); assert(expression);}
-#else
- #define ASSERT assert
-#endif
+# if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
+# define ASSERT(expression) \
+ { \
+ if(!(expression)) sw::trace("\t! Assert failed in %s(%d): " #expression "\n", __FUNCTION__, __LINE__); \
+ assert(expression); \
+ }
+# else
+# define ASSERT assert
+# endif
-#endif // !__ANDROID__
-#endif // Debug_hpp
+#endif // !__ANDROID__
+#endif // Debug_hpp
diff --git a/src/System/DebugAndroid.cpp b/src/System/DebugAndroid.cpp
index 2a6569c..5194cc3 100644
--- a/src/System/DebugAndroid.cpp
+++ b/src/System/DebugAndroid.cpp
@@ -14,16 +14,16 @@
#include "DebugAndroid.hpp"
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
#include <cutils/properties.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
void AndroidEnterDebugger()
{
ALOGE(__FUNCTION__);
#ifndef NDEBUG
- static volatile int * const makefault = nullptr;
+ static volatile int *const makefault = nullptr;
char value[PROPERTY_VALUE_MAX];
property_get("debug.db.uid", value, "-1");
int debug_uid = atoi(value);
@@ -31,7 +31,8 @@
{
ALOGE("Waiting for debugger: gdbserver :${PORT} --attach %u. Look for thread %u", getpid(), gettid());
volatile int waiting = 1;
- while(waiting) {
+ while(waiting)
+ {
sleep(1);
}
}
diff --git a/src/System/DebugAndroid.hpp b/src/System/DebugAndroid.hpp
index bb7451e..a8cbc9f 100644
--- a/src/System/DebugAndroid.hpp
+++ b/src/System/DebugAndroid.hpp
@@ -16,11 +16,11 @@
#define DebugAndroid_hpp
#if ANDROID_PLATFORM_SDK_VERSION < 27
-#include <cutils/log.h>
+# include <cutils/log.h>
#elif ANDROID_PLATFORM_SDK_VERSION >= 27
-#include <log/log.h>
+# include <log/log.h>
#else
-#error "ANDROID_PLATFORM_SDK_VERSION is not defined"
+# error "ANDROID_PLATFORM_SDK_VERSION is not defined"
#endif
#include <cassert>
@@ -48,52 +48,61 @@
*/
void AndroidEnterDebugger();
-#define ASSERT(E) do { \
- if(!(E)) { \
- ALOGE("badness: assertion_failed %s in %s at %s:%d", #E, \
- __FUNCTION__, __FILE__, __LINE__); \
- AndroidEnterDebugger(); \
- } \
+#define ASSERT(E) \
+ do \
+ { \
+ if(!(E)) \
+ { \
+ ALOGE("badness: assertion_failed %s in %s at %s:%d", #E, \
+ __FUNCTION__, __FILE__, __LINE__); \
+ AndroidEnterDebugger(); \
+ } \
} while(0)
#undef assert
#define assert(E) ASSERT(E)
-#define ERR(format, ...) \
- do { \
+#define ERR(format, ...) \
+ do \
+ { \
ALOGE("badness: err %s %s:%d (" format ")", __FUNCTION__, __FILE__, \
- __LINE__, ##__VA_ARGS__); \
- AndroidEnterDebugger(); \
+ __LINE__, ##__VA_ARGS__); \
+ AndroidEnterDebugger(); \
} while(0)
-#define FIXME(format, ...) \
- do { \
+#define FIXME(format, ...) \
+ do \
+ { \
ALOGE("badness: fixme %s %s:%d (" format ")", __FUNCTION__, __FILE__, \
- __LINE__, ##__VA_ARGS__); \
- AndroidEnterDebugger(); \
+ __LINE__, ##__VA_ARGS__); \
+ AndroidEnterDebugger(); \
} while(0)
// TODO: Handle __VA_ARGS__ (can be empty)
-#define UNIMPLEMENTED(...) do { \
- ALOGE("badness: unimplemented: %s %s:%d", \
- __FUNCTION__, __FILE__, __LINE__); \
- AndroidEnterDebugger(); \
+#define UNIMPLEMENTED(...) \
+ do \
+ { \
+ ALOGE("badness: unimplemented: %s %s:%d", \
+ __FUNCTION__, __FILE__, __LINE__); \
+ AndroidEnterDebugger(); \
} while(0)
-#define UNREACHABLE(value) do { \
+#define UNREACHABLE(value) \
+ do \
+ { \
ALOGE("badness: unreachable case reached: %s %s:%d. %s: %d", \
- __FUNCTION__, __FILE__, __LINE__, #value, value); \
- AndroidEnterDebugger(); \
+ __FUNCTION__, __FILE__, __LINE__, #value, value); \
+ AndroidEnterDebugger(); \
} while(0)
#ifndef NDEBUG
- #define TRACE(format, ...) \
+# define TRACE(format, ...) \
ALOGV("%s %s:%d (" format ")", __FUNCTION__, __FILE__, \
- __LINE__, ##__VA_ARGS__)
+ __LINE__, ##__VA_ARGS__)
#else
- #define TRACE(...) ((void)0)
+# define TRACE(...) ((void)0)
#endif
void trace(const char *format, ...);
-#endif // DebugAndroid_hpp
+#endif // DebugAndroid_hpp
diff --git a/src/System/GrallocAndroid.cpp b/src/System/GrallocAndroid.cpp
index 7b1b4ee..83a60a6 100644
--- a/src/System/GrallocAndroid.cpp
+++ b/src/System/GrallocAndroid.cpp
@@ -16,7 +16,7 @@
#include "Debug.hpp"
#ifdef HAVE_GRALLOC1
-#include <sync/sync.h>
+# include <sync/sync.h>
#endif
GrallocModule *GrallocModule::getInstance()
@@ -33,19 +33,19 @@
m_major_version = (module->module_api_version >> 8) & 0xff;
switch(m_major_version)
{
- case 0:
- m_module = reinterpret_cast<const gralloc_module_t*>(module);
- break;
- case 1:
+ case 0:
+ m_module = reinterpret_cast<const gralloc_module_t *>(module);
+ break;
+ case 1:
#ifdef HAVE_GRALLOC1
- gralloc1_open(module, &m_gralloc1_device);
- m_gralloc1_lock = (GRALLOC1_PFN_LOCK) m_gralloc1_device->getFunction(m_gralloc1_device, GRALLOC1_FUNCTION_LOCK);
- m_gralloc1_unlock = (GRALLOC1_PFN_UNLOCK)m_gralloc1_device->getFunction(m_gralloc1_device, GRALLOC1_FUNCTION_UNLOCK);
- break;
+ gralloc1_open(module, &m_gralloc1_device);
+ m_gralloc1_lock = (GRALLOC1_PFN_LOCK)m_gralloc1_device->getFunction(m_gralloc1_device, GRALLOC1_FUNCTION_LOCK);
+ m_gralloc1_unlock = (GRALLOC1_PFN_UNLOCK)m_gralloc1_device->getFunction(m_gralloc1_device, GRALLOC1_FUNCTION_UNLOCK);
+ break;
#endif
- default:
- TRACE("unknown gralloc major version (%d)", m_major_version);
- break;
+ default:
+ TRACE("unknown gralloc major version (%d)", m_major_version);
+ break;
}
}
@@ -53,11 +53,11 @@
{
switch(m_major_version)
{
- case 0:
+ case 0:
{
return m_module->lock(m_module, handle, usage, left, top, width, height, vaddr);
}
- case 1:
+ case 1:
#ifdef HAVE_GRALLOC1
{
gralloc1_rect_t outRect{};
@@ -68,7 +68,7 @@
return m_gralloc1_lock(m_gralloc1_device, handle, usage, usage, &outRect, vaddr, -1);
}
#endif
- default:
+ default:
{
TRACE("no gralloc module to lock");
return -1;
@@ -80,11 +80,11 @@
{
switch(m_major_version)
{
- case 0:
+ case 0:
{
return m_module->unlock(m_module, handle);
}
- case 1:
+ case 1:
#ifdef HAVE_GRALLOC1
{
int32_t fenceFd = -1;
@@ -97,7 +97,7 @@
return error;
}
#endif
- default:
+ default:
{
TRACE("no gralloc module to unlock");
return -1;
diff --git a/src/System/GrallocAndroid.hpp b/src/System/GrallocAndroid.hpp
index fe0b15a..09a361d 100644
--- a/src/System/GrallocAndroid.hpp
+++ b/src/System/GrallocAndroid.hpp
@@ -18,10 +18,10 @@
#include <hardware/gralloc.h>
#ifdef HAVE_GRALLOC1
-#include <hardware/gralloc1.h>
+# include <hardware/gralloc1.h>
#endif
-#include <unistd.h> // for close()
+#include <unistd.h> // for close()
class GrallocModule
{
diff --git a/src/System/Half.cpp b/src/System/Half.cpp
index 4f8f7cd..ea66920 100644
--- a/src/System/Half.cpp
+++ b/src/System/Half.cpp
@@ -18,15 +18,15 @@
half::half(float fp32)
{
- unsigned int fp32i = *(unsigned int*)&fp32;
+ unsigned int fp32i = *(unsigned int *)&fp32;
unsigned int sign = (fp32i & 0x80000000) >> 16;
unsigned int abs = fp32i & 0x7FFFFFFF;
- if(abs > 0x47FFEFFF) // Infinity
+ if(abs > 0x47FFEFFF) // Infinity
{
fp16i = sign | 0x7FFF;
}
- else if(abs < 0x38800000) // Denormal
+ else if(abs < 0x38800000) // Denormal
{
unsigned int mantissa = (abs & 0x007FFFFF) | 0x00800000;
int e = 113 - (abs >> 23);
@@ -54,7 +54,7 @@
int s = (fp16i >> 15) & 0x00000001;
int e = (fp16i >> 10) & 0x0000001F;
- int m = fp16i & 0x000003FF;
+ int m = fp16i & 0x000003FF;
if(e == 0)
{
@@ -62,14 +62,14 @@
{
fp32i = s << 31;
- return (float&)fp32i;
+ return (float &)fp32i;
}
else
{
while(!(m & 0x00000400))
{
m <<= 1;
- e -= 1;
+ e -= 1;
}
e += 1;
@@ -82,7 +82,7 @@
fp32i = (s << 31) | (e << 23) | m;
- return (float&)fp32i;
+ return (float &)fp32i;
}
half &half::operator=(half h)
@@ -92,7 +92,6 @@
return *this;
}
-
half &half::operator=(float f)
{
*this = half(f);
diff --git a/src/System/Half.hpp b/src/System/Half.hpp
index 2831ca2..6f73b4d 100644
--- a/src/System/Half.hpp
+++ b/src/System/Half.hpp
@@ -58,7 +58,8 @@
unsigned int E : 5;
public:
- RGB9E5(float rgb[3]) : RGB9E5(rgb[0], rgb[1], rgb[2])
+ RGB9E5(float rgb[3])
+ : RGB9E5(rgb[0], rgb[1], rgb[2])
{
}
@@ -76,14 +77,14 @@
constexpr int g_sharedexp_maxexponent = 31;
constexpr float g_sharedexp_max =
- ((static_cast<float>(1 << g_sharedexp_mantissabits) - 1) /
- static_cast<float>(1 << g_sharedexp_mantissabits)) *
- static_cast<float>(1 << (g_sharedexp_maxexponent - g_sharedexp_bias));
+ ((static_cast<float>(1 << g_sharedexp_mantissabits) - 1) /
+ static_cast<float>(1 << g_sharedexp_mantissabits)) *
+ static_cast<float>(1 << (g_sharedexp_maxexponent - g_sharedexp_bias));
// Clamp components to valid range. NaN becomes 0.
- const float red_c = std::min(!(r > 0) ? 0 : r, g_sharedexp_max);
+ const float red_c = std::min(!(r > 0) ? 0 : r, g_sharedexp_max);
const float green_c = std::min(!(g > 0) ? 0 : g, g_sharedexp_max);
- const float blue_c = std::min(!(b > 0) ? 0 : b, g_sharedexp_max);
+ const float blue_c = std::min(!(b > 0) ? 0 : b, g_sharedexp_max);
// We're reducing the mantissa to 9 bits, so we must round up if the next
// bit is 1. In other words add 0.5 to the new mantissa's position and
@@ -111,12 +112,12 @@
operator unsigned int() const
{
- return *reinterpret_cast<const unsigned int*>(this);
+ return *reinterpret_cast<const unsigned int *>(this);
}
void toRGB16F(half rgb[3]) const
{
- constexpr int offset = 24; // Exponent bias (15) + number of mantissa bits per component (9) = 24
+ constexpr int offset = 24; // Exponent bias (15) + number of mantissa bits per component (9) = 24
const float factor = (1u << E) * (1.0f / (1 << offset));
rgb[0] = half(R * factor);
@@ -133,12 +134,12 @@
static inline half float11ToFloat16(unsigned short fp11)
{
- return shortAsHalf(fp11 << 4); // Sign bit 0
+ return shortAsHalf(fp11 << 4); // Sign bit 0
}
static inline half float10ToFloat16(unsigned short fp10)
{
- return shortAsHalf(fp10 << 5); // Sign bit 0
+ return shortAsHalf(fp10 << 5); // Sign bit 0
}
inline unsigned short float32ToFloat11(float fp32)
@@ -159,7 +160,7 @@
const unsigned int float32Maxfloat11 = 0x477E0000;
const unsigned int float32Minfloat11 = 0x38800000;
- const unsigned int float32Bits = *reinterpret_cast<unsigned int*>(&fp32);
+ const unsigned int float32Bits = *reinterpret_cast<unsigned int *>(&fp32);
const bool float32Sign = (float32Bits & float32SignMask) == float32SignMask;
unsigned int float32Val = float32Bits & float32ValueMask;
@@ -170,8 +171,8 @@
if((float32Val & float32MantissaMask) != 0)
{
return float11ExponentMask |
- (((float32Val >> 17) | (float32Val >> 11) | (float32Val >> 6) | (float32Val)) &
- float11MantissaMask);
+ (((float32Val >> 17) | (float32Val >> 11) | (float32Val >> 6) | (float32Val)) &
+ float11MantissaMask);
}
else if(float32Sign)
{
@@ -200,9 +201,9 @@
// The number is too small to be represented as a normalized float11
// Convert it to a denormalized value.
const unsigned int shift = (float32ExponentBias - float11ExponentBias) -
- (float32Val >> float32ExponentFirstBit);
+ (float32Val >> float32ExponentFirstBit);
float32Val =
- ((1 << float32ExponentFirstBit) | (float32Val & float32MantissaMask)) >> shift;
+ ((1 << float32ExponentFirstBit) | (float32Val & float32MantissaMask)) >> shift;
}
else
{
@@ -232,7 +233,7 @@
const unsigned int float32Maxfloat10 = 0x477C0000;
const unsigned int float32Minfloat10 = 0x38800000;
- const unsigned int float32Bits = *reinterpret_cast<unsigned int*>(&fp32);
+ const unsigned int float32Bits = *reinterpret_cast<unsigned int *>(&fp32);
const bool float32Sign = (float32Bits & float32SignMask) == float32SignMask;
unsigned int float32Val = float32Bits & float32ValueMask;
@@ -243,8 +244,8 @@
if((float32Val & float32MantissaMask) != 0)
{
return float10ExponentMask |
- (((float32Val >> 18) | (float32Val >> 13) | (float32Val >> 3) | (float32Val)) &
- float10MantissaMask);
+ (((float32Val >> 18) | (float32Val >> 13) | (float32Val >> 3) | (float32Val)) &
+ float10MantissaMask);
}
else if(float32Sign)
{
@@ -273,9 +274,9 @@
// The number is too small to be represented as a normalized float11
// Convert it to a denormalized value.
const unsigned int shift = (float32ExponentBias - float10ExponentBias) -
- (float32Val >> float32ExponentFirstBit);
+ (float32Val >> float32ExponentFirstBit);
float32Val =
- ((1 << float32ExponentFirstBit) | (float32Val & float32MantissaMask)) >> shift;
+ ((1 << float32ExponentFirstBit) | (float32Val & float32MantissaMask)) >> shift;
}
else
{
@@ -297,7 +298,7 @@
operator unsigned int() const
{
- return *reinterpret_cast<const unsigned int*>(this);
+ return *reinterpret_cast<const unsigned int *>(this);
}
void toRGB16F(half rgb[3]) const
@@ -310,4 +311,4 @@
} // namespace sw
-#endif // sw_Half_hpp
+#endif // sw_Half_hpp
diff --git a/src/System/Linux/MemFd.cpp b/src/System/Linux/MemFd.cpp
index 268e678..1319d11 100644
--- a/src/System/Linux/MemFd.cpp
+++ b/src/System/Linux/MemFd.cpp
@@ -22,19 +22,19 @@
#include <unistd.h>
#ifndef MFD_CLOEXEC
-#define MFD_CLOEXEC 0x0001U
+# define MFD_CLOEXEC 0x0001U
#endif
#if __aarch64__
-#define __NR_memfd_create 279
+# define __NR_memfd_create 279
#elif __arm__
-#define __NR_memfd_create 279
+# define __NR_memfd_create 279
#elif __powerpc64__
-#define __NR_memfd_create 360
+# define __NR_memfd_create 360
#elif __i386__
-#define __NR_memfd_create 356
+# define __NR_memfd_create 356
#elif __x86_64__
-#define __NR_memfd_create 319
+# define __NR_memfd_create 319
#endif /* __NR_memfd_create__ */
LinuxMemFd::~LinuxMemFd()
@@ -59,7 +59,7 @@
return ::fcntl(fd_, F_DUPFD_CLOEXEC, 0);
}
-bool LinuxMemFd::allocate(const char* name, size_t size)
+bool LinuxMemFd::allocate(const char *name, size_t size)
{
close();
@@ -93,7 +93,8 @@
// WARNING: Never retry on close() failure, even with EINTR, see
// https://lwn.net/Articles/576478/ for example.
int ret = ::close(fd_);
- if(ret < 0) {
+ if(ret < 0)
+ {
TRACE("LinuxMemFd::close() failed with: %s", strerror(errno));
assert(false);
}
@@ -101,14 +102,14 @@
}
}
-void* LinuxMemFd::mapReadWrite(size_t offset, size_t size)
+void *LinuxMemFd::mapReadWrite(size_t offset, size_t size)
{
- void* addr = ::mmap(nullptr, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd_,
- static_cast<off_t>(offset));
+ void *addr = ::mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_,
+ static_cast<off_t>(offset));
return (addr == MAP_FAILED) ? nullptr : addr;
}
-bool LinuxMemFd::unmap(void* addr, size_t size)
+bool LinuxMemFd::unmap(void *addr, size_t size)
{
return ::munmap(addr, size) == 0;
}
diff --git a/src/System/Linux/MemFd.hpp b/src/System/Linux/MemFd.hpp
index 209d642..e70af17 100644
--- a/src/System/Linux/MemFd.hpp
+++ b/src/System/Linux/MemFd.hpp
@@ -22,11 +22,14 @@
// supported by the Linux kernel since 3.17 (good enough for Android and desktop
// Linux).
-class LinuxMemFd {
+class LinuxMemFd
+{
public:
LinuxMemFd() = default;
- LinuxMemFd(const char* name, size_t size) : LinuxMemFd() {
+ LinuxMemFd(const char *name, size_t size)
+ : LinuxMemFd()
+ {
allocate(name, size);
}
@@ -45,19 +48,19 @@
int exportFd() const;
// Implement memfd_create() through direct syscalls if possible.
- // On success, return true and sets |fd| accordingly. On failure, return
- // false and sets errno.
- bool allocate(const char* name, size_t size);
+ // On success, return true and sets |fd| accordingly. On failure, return
+ // false and sets errno.
+ bool allocate(const char *name, size_t size);
- // Map a segment of |size| bytes from |offset| from the region.
+ // Map a segment of |size| bytes from |offset| from the region.
// Both |offset| and |size| should be page-aligned. Returns nullptr/errno
// on failure.
- void* mapReadWrite(size_t offset, size_t size);
+ void *mapReadWrite(size_t offset, size_t size);
// Unmap a region segment starting at |addr| of |size| bytes.
// Both |addr| and |size| should be page-aligned. Returns true on success
// or false/errno on failure.
- bool unmap(void* addr, size_t size);
+ bool unmap(void *addr, size_t size);
void close();
diff --git a/src/System/Math.hpp b/src/System/Math.hpp
index f45f933..4071059 100644
--- a/src/System/Math.hpp
+++ b/src/System/Math.hpp
@@ -21,7 +21,7 @@
#include <cmath>
#if defined(_MSC_VER)
- #include <intrin.h>
+# include <intrin.h>
#endif
namespace sw {
@@ -67,7 +67,7 @@
return min(min(a, b), min(c, d));
}
-template <typename destType, typename sourceType>
+template<typename destType, typename sourceType>
destType bit_cast(const sourceType &source)
{
union
@@ -82,7 +82,7 @@
inline int iround(float x)
{
return (int)floor(x + 0.5f);
-// return _mm_cvtss_si32(_mm_load_ss(&x)); // FIXME: Demands SSE support
+ // return _mm_cvtss_si32(_mm_load_ss(&x)); // FIXME: Demands SSE support
}
inline int ifloor(float x)
@@ -100,52 +100,52 @@
return (x + 0xF) >> 4;
}
-#define BITS(x) ( \
-!!((x) & 0x80000000) + \
-!!((x) & 0xC0000000) + \
-!!((x) & 0xE0000000) + \
-!!((x) & 0xF0000000) + \
-!!((x) & 0xF8000000) + \
-!!((x) & 0xFC000000) + \
-!!((x) & 0xFE000000) + \
-!!((x) & 0xFF000000) + \
-!!((x) & 0xFF800000) + \
-!!((x) & 0xFFC00000) + \
-!!((x) & 0xFFE00000) + \
-!!((x) & 0xFFF00000) + \
-!!((x) & 0xFFF80000) + \
-!!((x) & 0xFFFC0000) + \
-!!((x) & 0xFFFE0000) + \
-!!((x) & 0xFFFF0000) + \
-!!((x) & 0xFFFF8000) + \
-!!((x) & 0xFFFFC000) + \
-!!((x) & 0xFFFFE000) + \
-!!((x) & 0xFFFFF000) + \
-!!((x) & 0xFFFFF800) + \
-!!((x) & 0xFFFFFC00) + \
-!!((x) & 0xFFFFFE00) + \
-!!((x) & 0xFFFFFF00) + \
-!!((x) & 0xFFFFFF80) + \
-!!((x) & 0xFFFFFFC0) + \
-!!((x) & 0xFFFFFFE0) + \
-!!((x) & 0xFFFFFFF0) + \
-!!((x) & 0xFFFFFFF8) + \
-!!((x) & 0xFFFFFFFC) + \
-!!((x) & 0xFFFFFFFE) + \
-!!((x) & 0xFFFFFFFF))
+#define BITS(x) ( \
+ !!((x)&0x80000000) + \
+ !!((x)&0xC0000000) + \
+ !!((x)&0xE0000000) + \
+ !!((x)&0xF0000000) + \
+ !!((x)&0xF8000000) + \
+ !!((x)&0xFC000000) + \
+ !!((x)&0xFE000000) + \
+ !!((x)&0xFF000000) + \
+ !!((x)&0xFF800000) + \
+ !!((x)&0xFFC00000) + \
+ !!((x)&0xFFE00000) + \
+ !!((x)&0xFFF00000) + \
+ !!((x)&0xFFF80000) + \
+ !!((x)&0xFFFC0000) + \
+ !!((x)&0xFFFE0000) + \
+ !!((x)&0xFFFF0000) + \
+ !!((x)&0xFFFF8000) + \
+ !!((x)&0xFFFFC000) + \
+ !!((x)&0xFFFFE000) + \
+ !!((x)&0xFFFFF000) + \
+ !!((x)&0xFFFFF800) + \
+ !!((x)&0xFFFFFC00) + \
+ !!((x)&0xFFFFFE00) + \
+ !!((x)&0xFFFFFF00) + \
+ !!((x)&0xFFFFFF80) + \
+ !!((x)&0xFFFFFFC0) + \
+ !!((x)&0xFFFFFFE0) + \
+ !!((x)&0xFFFFFFF0) + \
+ !!((x)&0xFFFFFFF8) + \
+ !!((x)&0xFFFFFFFC) + \
+ !!((x)&0xFFFFFFFE) + \
+ !!((x)&0xFFFFFFFF))
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define MIN(x, y) ((x) < (y) ? (x) : (y))
inline unsigned long log2i(int x)
{
- #if defined(_MSC_VER)
- unsigned long y;
- _BitScanReverse(&y, x);
- return y;
- #else
- return 31 - __builtin_clz(x);
- #endif
+#if defined(_MSC_VER)
+ unsigned long y;
+ _BitScanReverse(&y, x);
+ return y;
+#else
+ return 31 - __builtin_clz(x);
+#endif
}
inline bool isPow2(int x)
@@ -331,11 +331,11 @@
{
if(c <= 0.04045f)
{
- return c * 0.07739938f; // 1.0f / 12.92f;
+ return c * 0.07739938f; // 1.0f / 12.92f;
}
else
{
- return powf((c + 0.055f) * 0.9478673f, 2.4f); // 1.0f / 1.055f
+ return powf((c + 0.055f) * 0.9478673f, 2.4f); // 1.0f / 1.055f
}
}
@@ -347,13 +347,13 @@
}
else
{
- return 1.055f * powf(c, 0.4166667f) - 0.055f; // 1.0f / 2.4f
+ return 1.055f * powf(c, 0.4166667f) - 0.055f; // 1.0f / 2.4f
}
}
unsigned char sRGB8toLinear8(unsigned char value);
-uint64_t FNV_1a(const unsigned char *data, int size); // Fowler-Noll-Vo hash function
+uint64_t FNV_1a(const unsigned char *data, int size); // Fowler-Noll-Vo hash function
// Round up to the next multiple of alignment
template<typename T>
@@ -374,10 +374,11 @@
}
// Convert floating value v to fixed point with p digits after the decimal point
-constexpr int toFixedPoint(float v, int p) {
+constexpr int toFixedPoint(float v, int p)
+{
return static_cast<int>(v * (1 << p));
}
} // namespace sw
-#endif // sw_Math_hpp
+#endif // sw_Math_hpp
diff --git a/src/System/Memory.cpp b/src/System/Memory.cpp
index 0ed36e0..723db3c 100644
--- a/src/System/Memory.cpp
+++ b/src/System/Memory.cpp
@@ -14,30 +14,30 @@
#include "Memory.hpp"
-#include "Types.hpp"
#include "Debug.hpp"
+#include "Types.hpp"
#if defined(_WIN32)
- #ifndef WIN32_LEAN_AND_MEAN
- #define WIN32_LEAN_AND_MEAN
- #endif
- #include <windows.h>
- #include <intrin.h>
+# ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+# endif
+# include <windows.h>
+# include <intrin.h>
#else
- #include <errno.h>
- #include <sys/mman.h>
- #include <stdlib.h>
- #include <unistd.h>
+# include <errno.h>
+# include <sys/mman.h>
+# include <stdlib.h>
+# include <unistd.h>
#endif
-#include <cstring>
#include <cstdlib>
+#include <cstring>
#undef allocate
#undef deallocate
-#if(defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined (_M_X64)) && !defined(__x86__)
-#define __x86__
+#if(defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64)) && !defined(__x86__)
+# define __x86__
#endif
namespace sw {
@@ -46,45 +46,45 @@
struct Allocation
{
-// size_t bytes;
+ // size_t bytes;
unsigned char *block;
};
void *allocateRaw(size_t bytes, size_t alignment)
{
- ASSERT((alignment & (alignment - 1)) == 0); // Power of 2 alignment.
+ ASSERT((alignment & (alignment - 1)) == 0); // Power of 2 alignment.
- #if defined(LINUX_ENABLE_NAMED_MMAP)
- if(alignment < sizeof(void*))
+#if defined(LINUX_ENABLE_NAMED_MMAP)
+ if(alignment < sizeof(void *))
+ {
+ return malloc(bytes);
+ }
+ else
+ {
+ void *allocation;
+ int result = posix_memalign(&allocation, alignment, bytes);
+ if(result != 0)
{
- return malloc(bytes);
+ errno = result;
+ allocation = nullptr;
}
- else
- {
- void *allocation;
- int result = posix_memalign(&allocation, alignment, bytes);
- if(result != 0)
- {
- errno = result;
- allocation = nullptr;
- }
- return allocation;
- }
- #else
- unsigned char *block = (unsigned char*)malloc(bytes + sizeof(Allocation) + alignment);
- unsigned char *aligned = nullptr;
+ return allocation;
+ }
+#else
+ unsigned char *block = (unsigned char *)malloc(bytes + sizeof(Allocation) + alignment);
+ unsigned char *aligned = nullptr;
- if(block)
- {
- aligned = (unsigned char*)((uintptr_t)(block + sizeof(Allocation) + alignment - 1) & -(intptr_t)alignment);
- Allocation *allocation = (Allocation*)(aligned - sizeof(Allocation));
+ if(block)
+ {
+ aligned = (unsigned char *)((uintptr_t)(block + sizeof(Allocation) + alignment - 1) & -(intptr_t)alignment);
+ Allocation *allocation = (Allocation *)(aligned - sizeof(Allocation));
// allocation->bytes = bytes;
- allocation->block = block;
- }
+ allocation->block = block;
+ }
- return aligned;
- #endif
+ return aligned;
+#endif
}
} // anonymous namespace
@@ -95,13 +95,13 @@
if(pageSize == 0)
{
- #if defined(_WIN32)
- SYSTEM_INFO systemInfo;
- GetSystemInfo(&systemInfo);
- pageSize = systemInfo.dwPageSize;
- #else
- pageSize = sysconf(_SC_PAGESIZE);
- #endif
+#if defined(_WIN32)
+ SYSTEM_INFO systemInfo;
+ GetSystemInfo(&systemInfo);
+ pageSize = systemInfo.dwPageSize;
+#else
+ pageSize = sysconf(_SC_PAGESIZE);
+#endif
}
return pageSize;
@@ -121,45 +121,51 @@
void deallocate(void *memory)
{
- #if defined(LINUX_ENABLE_NAMED_MMAP)
- free(memory);
- #else
- if(memory)
- {
- unsigned char *aligned = (unsigned char*)memory;
- Allocation *allocation = (Allocation*)(aligned - sizeof(Allocation));
+#if defined(LINUX_ENABLE_NAMED_MMAP)
+ free(memory);
+#else
+ if(memory)
+ {
+ unsigned char *aligned = (unsigned char *)memory;
+ Allocation *allocation = (Allocation *)(aligned - sizeof(Allocation));
- free(allocation->block);
- }
- #endif
+ free(allocation->block);
+ }
+#endif
}
void clear(uint16_t *memory, uint16_t element, size_t count)
{
- #if defined(_MSC_VER) && defined(__x86__) && !defined(MEMORY_SANITIZER)
- __stosw(memory, element, count);
- #elif defined(__GNUC__) && defined(__x86__) && !defined(MEMORY_SANITIZER)
- __asm__ __volatile__("rep stosw" : "+D"(memory), "+c"(count) : "a"(element) : "memory");
- #else
- for(size_t i = 0; i < count; i++)
- {
- memory[i] = element;
- }
- #endif
+#if defined(_MSC_VER) && defined(__x86__) && !defined(MEMORY_SANITIZER)
+ __stosw(memory, element, count);
+#elif defined(__GNUC__) && defined(__x86__) && !defined(MEMORY_SANITIZER)
+ __asm__ __volatile__("rep stosw"
+ : "+D"(memory), "+c"(count)
+ : "a"(element)
+ : "memory");
+#else
+ for(size_t i = 0; i < count; i++)
+ {
+ memory[i] = element;
+ }
+#endif
}
void clear(uint32_t *memory, uint32_t element, size_t count)
{
- #if defined(_MSC_VER) && defined(__x86__) && !defined(MEMORY_SANITIZER)
- __stosd((unsigned long*)memory, element, count);
- #elif defined(__GNUC__) && defined(__x86__) && !defined(MEMORY_SANITIZER)
- __asm__ __volatile__("rep stosl" : "+D"(memory), "+c"(count) : "a"(element) : "memory");
- #else
- for(size_t i = 0; i < count; i++)
- {
- memory[i] = element;
- }
- #endif
+#if defined(_MSC_VER) && defined(__x86__) && !defined(MEMORY_SANITIZER)
+ __stosd((unsigned long *)memory, element, count);
+#elif defined(__GNUC__) && defined(__x86__) && !defined(MEMORY_SANITIZER)
+ __asm__ __volatile__("rep stosl"
+ : "+D"(memory), "+c"(count)
+ : "a"(element)
+ : "memory");
+#else
+ for(size_t i = 0; i < count; i++)
+ {
+ memory[i] = element;
+ }
+#endif
}
} // namespace sw
diff --git a/src/System/Memory.hpp b/src/System/Memory.hpp
index d1e7871..eff959b 100644
--- a/src/System/Memory.hpp
+++ b/src/System/Memory.hpp
@@ -30,4 +30,4 @@
} // namespace sw
-#endif // Memory_hpp
+#endif // Memory_hpp
diff --git a/src/System/SharedLibrary.hpp b/src/System/SharedLibrary.hpp
index 8a8c3a1..e3b1e16 100644
--- a/src/System/SharedLibrary.hpp
+++ b/src/System/SharedLibrary.hpp
@@ -16,9 +16,9 @@
#define SharedLibrary_hpp
#if defined(_WIN32)
- #include <Windows.h>
+# include <Windows.h>
#else
- #include <dlfcn.h>
+# include <dlfcn.h>
#endif
#include <string>
@@ -67,105 +67,105 @@
}
#if defined(_WIN32)
- inline void *loadLibrary(const char *path)
+inline void *loadLibrary(const char *path)
+{
+ return (void *)LoadLibrary(path);
+}
+
+inline void *getLibraryHandle(const char *path)
+{
+ HMODULE module = NULL;
+ GetModuleHandleEx(0, path, &module);
+ return (void *)module;
+}
+
+inline void freeLibrary(void *library)
+{
+ FreeLibrary((HMODULE)library);
+}
+
+inline void *getProcAddress(void *library, const char *name)
+{
+ return (void *)GetProcAddress((HMODULE)library, name);
+}
+
+inline std::string getModuleDirectory()
+{
+ static int dummy_symbol = 0;
+
+ HMODULE module = NULL;
+ GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCTSTR)&dummy_symbol, &module);
+
+ char filename[1024];
+ if(module && (GetModuleFileName(module, filename, sizeof(filename)) != 0))
{
- return (void*)LoadLibrary(path);
+ std::string directory(filename);
+ return directory.substr(0, directory.find_last_of("\\/") + 1).c_str();
}
-
- inline void *getLibraryHandle(const char *path)
+ else
{
- HMODULE module = NULL;
- GetModuleHandleEx(0, path, &module);
- return (void*)module;
+ return "";
}
-
- inline void freeLibrary(void *library)
- {
- FreeLibrary((HMODULE)library);
- }
-
- inline void *getProcAddress(void *library, const char *name)
- {
- return (void*)GetProcAddress((HMODULE)library, name);
- }
-
- inline std::string getModuleDirectory()
- {
- static int dummy_symbol = 0;
-
- HMODULE module = NULL;
- GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCTSTR)&dummy_symbol, &module);
-
- char filename[1024];
- if(module && (GetModuleFileName(module, filename, sizeof(filename)) != 0))
- {
- std::string directory(filename);
- return directory.substr(0, directory.find_last_of("\\/") + 1).c_str();
- }
- else
- {
- return "";
- }
- }
+}
#else
- inline void *loadLibrary(const char *path)
+inline void *loadLibrary(const char *path)
+{
+ return dlopen(path, RTLD_LAZY | RTLD_LOCAL);
+}
+
+inline void *getLibraryHandle(const char *path)
+{
+# ifdef __ANDROID__
+ // bionic doesn't support RTLD_NOLOAD before L
+ return dlopen(path, RTLD_NOW | RTLD_LOCAL);
+# else
+ void *resident = dlopen(path, RTLD_LAZY | RTLD_NOLOAD | RTLD_LOCAL);
+
+ if(resident)
{
- return dlopen(path, RTLD_LAZY | RTLD_LOCAL);
+ return dlopen(path, RTLD_LAZY | RTLD_LOCAL); // Increment reference count
}
- inline void *getLibraryHandle(const char *path)
+ return nullptr;
+# endif
+}
+
+inline void freeLibrary(void *library)
+{
+ if(library)
{
- #ifdef __ANDROID__
- // bionic doesn't support RTLD_NOLOAD before L
- return dlopen(path, RTLD_NOW | RTLD_LOCAL);
- #else
- void *resident = dlopen(path, RTLD_LAZY | RTLD_NOLOAD | RTLD_LOCAL);
+ dlclose(library);
+ }
+}
- if(resident)
- {
- return dlopen(path, RTLD_LAZY | RTLD_LOCAL); // Increment reference count
- }
+inline void *getProcAddress(void *library, const char *name)
+{
+ void *symbol = dlsym(library, name);
- return nullptr;
- #endif
+ if(!symbol)
+ {
+ const char *reason = dlerror(); // Silence the error
+ (void)reason;
}
- inline void freeLibrary(void *library)
+ return symbol;
+}
+
+inline std::string getModuleDirectory()
+{
+ static int dummy_symbol = 0;
+
+ Dl_info dl_info;
+ if(dladdr(&dummy_symbol, &dl_info) != 0)
{
- if(library)
- {
- dlclose(library);
- }
+ std::string directory(dl_info.dli_fname);
+ return directory.substr(0, directory.find_last_of("\\/") + 1).c_str();
}
-
- inline void *getProcAddress(void *library, const char *name)
+ else
{
- void *symbol = dlsym(library, name);
-
- if(!symbol)
- {
- const char *reason = dlerror(); // Silence the error
- (void)reason;
- }
-
- return symbol;
+ return "";
}
-
- inline std::string getModuleDirectory()
- {
- static int dummy_symbol = 0;
-
- Dl_info dl_info;
- if(dladdr(&dummy_symbol, &dl_info) != 0)
- {
- std::string directory(dl_info.dli_fname);
- return directory.substr(0, directory.find_last_of("\\/") + 1).c_str();
- }
- else
- {
- return "";
- }
- }
+}
#endif
-#endif // SharedLibrary_hpp
+#endif // SharedLibrary_hpp
diff --git a/src/System/Socket.cpp b/src/System/Socket.cpp
index 1989a94..dd2944b 100644
--- a/src/System/Socket.cpp
+++ b/src/System/Socket.cpp
@@ -15,27 +15,28 @@
#include "Socket.hpp"
#if defined(_WIN32)
- #include <ws2tcpip.h>
+# include <ws2tcpip.h>
#else
- #include <unistd.h>
- #include <netdb.h>
- #include <netinet/in.h>
- #include <sys/select.h>
+# include <unistd.h>
+# include <netdb.h>
+# include <netinet/in.h>
+# include <sys/select.h>
#endif
namespace sw {
-Socket::Socket(SOCKET socket) : socket(socket)
+Socket::Socket(SOCKET socket)
+ : socket(socket)
{
}
Socket::Socket(const char *address, const char *port)
{
- #if defined(_WIN32)
- socket = INVALID_SOCKET;
- #else
- socket = -1;
- #endif
+#if defined(_WIN32)
+ socket = INVALID_SOCKET;
+#else
+ socket = -1;
+#endif
addrinfo hints = {};
hints.ai_family = AF_INET;
@@ -55,11 +56,11 @@
Socket::~Socket()
{
- #if defined(_WIN32)
- closesocket(socket);
- #else
- close(socket);
- #endif
+#if defined(_WIN32)
+ closesocket(socket);
+#else
+ close(socket);
+#endif
}
void Socket::listen(int backlog)
@@ -73,7 +74,7 @@
FD_ZERO(&sockets);
FD_SET(socket, &sockets);
- timeval timeout = {us / 1000000, us % 1000000};
+ timeval timeout = { us / 1000000, us % 1000000 };
return ::select(FD_SETSIZE, &sockets, 0, 0, &timeout) >= 1;
}
@@ -95,17 +96,17 @@
void Socket::startup()
{
- #if defined(_WIN32)
- WSADATA winsockData;
- WSAStartup(MAKEWORD(2, 2), &winsockData);
- #endif
+#if defined(_WIN32)
+ WSADATA winsockData;
+ WSAStartup(MAKEWORD(2, 2), &winsockData);
+#endif
}
void Socket::cleanup()
{
- #if defined(_WIN32)
- WSACleanup();
- #endif
+#if defined(_WIN32)
+ WSACleanup();
+#endif
}
} // namespace sw
diff --git a/src/System/Socket.hpp b/src/System/Socket.hpp
index efb5062..29f7d6f 100644
--- a/src/System/Socket.hpp
+++ b/src/System/Socket.hpp
@@ -16,10 +16,10 @@
#define sw_Socket_hpp
#if defined(_WIN32)
- #include <winsock2.h>
+# include <winsock2.h>
#else
- #include <sys/socket.h>
- typedef int SOCKET;
+# include <sys/socket.h>
+typedef int SOCKET;
#endif
namespace sw {
@@ -45,6 +45,6 @@
SOCKET socket;
};
-}
+} // namespace sw
-#endif // sw_Socket_hpp
+#endif // sw_Socket_hpp
diff --git a/src/System/Synchronization.hpp b/src/System/Synchronization.hpp
index e1b9e1f..0a5068d 100644
--- a/src/System/Synchronization.hpp
+++ b/src/System/Synchronization.hpp
@@ -42,7 +42,11 @@
// a corresponding call to start().
virtual void finish() = 0;
// complete() is a helper for calling start() followed by finish().
- inline void complete() { start(); finish(); }
+ inline void complete()
+ {
+ start();
+ finish();
+ }
protected:
virtual ~TaskEvents() = default;
@@ -89,8 +93,8 @@
// wait() blocks until all the tasks have been finished or the timeout
// has been reached, returning true if all tasks have been completed, or
// false if the timeout has been reached.
- template <class CLOCK, class DURATION>
- bool wait(const std::chrono::time_point<CLOCK, DURATION>& timeout)
+ template<class CLOCK, class DURATION>
+ bool wait(const std::chrono::time_point<CLOCK, DURATION> &timeout)
{
std::unique_lock<std::mutex> lock(mutex);
return condition.wait_until(lock, timeout, [this] { return count_ == 0; });
@@ -111,14 +115,14 @@
void finish() override { done(); }
private:
- int32_t count_ = 0; // guarded by mutex
+ int32_t count_ = 0; // guarded by mutex
std::mutex mutex;
std::condition_variable condition;
};
// Chan is a thread-safe FIFO queue of type T.
// Chan takes its name after Golang's chan.
-template <typename T>
+template<typename T>
class Chan
{
public:
@@ -148,10 +152,11 @@
std::condition_variable added;
};
-template <typename T>
-Chan<T>::Chan() {}
+template<typename T>
+Chan<T>::Chan()
+{}
-template <typename T>
+template<typename T>
T Chan<T>::take()
{
std::unique_lock<std::mutex> lock(mutex);
@@ -162,7 +167,7 @@
return out;
}
-template <typename T>
+template<typename T>
std::pair<T, bool> Chan<T>::tryTake()
{
std::unique_lock<std::mutex> lock(mutex);
@@ -175,7 +180,7 @@
return std::make_pair(out, true);
}
-template <typename T>
+template<typename T>
void Chan<T>::put(const T &item)
{
std::unique_lock<std::mutex> lock(mutex);
@@ -183,7 +188,7 @@
added.notify_one();
}
-template <typename T>
+template<typename T>
size_t Chan<T>::count()
{
std::unique_lock<std::mutex> lock(mutex);
@@ -192,4 +197,4 @@
} // namespace sw
-#endif // sw_Synchronization_hpp
+#endif // sw_Synchronization_hpp
diff --git a/src/System/Timer.cpp b/src/System/Timer.cpp
index 7bd7ba5..79e48ca 100644
--- a/src/System/Timer.cpp
+++ b/src/System/Timer.cpp
@@ -15,24 +15,24 @@
#include "Timer.hpp"
#if !defined(__i386__) && defined(_M_IX86)
- #define __i386__ 1
+# define __i386__ 1
#endif
-#if !defined(__x86_64__) && (defined(_M_AMD64) || defined (_M_X64))
- #define __x86_64__ 1
+#if !defined(__x86_64__) && (defined(_M_AMD64) || defined(_M_X64))
+# define __x86_64__ 1
#endif
#if defined(_WIN32)
- #ifndef WIN32_LEAN_AND_MEAN
- #define WIN32_LEAN_AND_MEAN
- #endif
- #include <windows.h>
- #include <intrin.h>
+# ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+# endif
+# include <windows.h>
+# include <intrin.h>
#else
- #include <sys/time.h>
- #if defined(__i386__) || defined(__x86_64__)
- #include <x86intrin.h>
- #endif
+# include <sys/time.h>
+# if defined(__i386__) || defined(__x86_64__)
+# include <x86intrin.h>
+# endif
#endif
namespace sw {
@@ -47,54 +47,55 @@
double Timer::seconds()
{
- #if defined(_WIN32)
- return (double)counter() / (double)frequency();
- #else
- timeval t;
- gettimeofday(&t, 0);
- return (double)t.tv_sec + (double)t.tv_usec * 1.0e-6;
- #endif
+#if defined(_WIN32)
+ return (double)counter() / (double)frequency();
+#else
+ timeval t;
+ gettimeofday(&t, 0);
+ return (double)t.tv_sec + (double)t.tv_usec * 1.0e-6;
+#endif
}
int64_t Timer::ticks()
{
- #if defined(_WIN32)
- #if defined(_M_ARM64)
- return _ReadStatusReg(ARM64_PMCCNTR_EL0);
- #else
- return __rdtsc();
- #endif
- #elif defined(__i386__) || defined(__x86_64__)
- int64_t tsc;
- __asm volatile("rdtsc": "=A" (tsc));
- return tsc;
- #else
- return 0;
- #endif
+#if defined(_WIN32)
+# if defined(_M_ARM64)
+ return _ReadStatusReg(ARM64_PMCCNTR_EL0);
+# else
+ return __rdtsc();
+# endif
+#elif defined(__i386__) || defined(__x86_64__)
+ int64_t tsc;
+ __asm volatile("rdtsc"
+ : "=A"(tsc));
+ return tsc;
+#else
+ return 0;
+#endif
}
int64_t Timer::counter()
{
- #if defined(_WIN32)
- int64_t counter;
- QueryPerformanceCounter((LARGE_INTEGER*)&counter);
- return counter;
- #else
- timeval t;
- gettimeofday(&t, 0);
- return t.tv_sec * 1000000 + t.tv_usec;
- #endif
+#if defined(_WIN32)
+ int64_t counter;
+ QueryPerformanceCounter((LARGE_INTEGER *)&counter);
+ return counter;
+#else
+ timeval t;
+ gettimeofday(&t, 0);
+ return t.tv_sec * 1000000 + t.tv_usec;
+#endif
}
int64_t Timer::frequency()
{
- #if defined(_WIN32)
- int64_t frequency;
- QueryPerformanceFrequency((LARGE_INTEGER*)&frequency);
- return frequency;
- #else
- return 1000000; // gettimeofday uses microsecond resolution
- #endif
+#if defined(_WIN32)
+ int64_t frequency;
+ QueryPerformanceFrequency((LARGE_INTEGER *)&frequency);
+ return frequency;
+#else
+ return 1000000; // gettimeofday uses microsecond resolution
+#endif
}
} // namespace sw
diff --git a/src/System/Timer.hpp b/src/System/Timer.hpp
index a2f687b..64ef770 100644
--- a/src/System/Timer.hpp
+++ b/src/System/Timer.hpp
@@ -35,4 +35,4 @@
} // namespace sw
-#endif // sw_Timer_hpp
+#endif // sw_Timer_hpp
diff --git a/src/System/Types.hpp b/src/System/Types.hpp
index df28db5..d99205b 100644
--- a/src/System/Types.hpp
+++ b/src/System/Types.hpp
@@ -21,25 +21,30 @@
// GCC warns against bitfields not fitting the entire range of an enum with a fixed underlying type of unsigned int, which gets promoted to an error with -Werror and cannot be suppressed.
// However, GCC already defaults to using unsigned int as the underlying type of an unscoped enum without a fixed underlying type. So we can just omit it.
#if defined(__GNUC__) && !defined(__clang__)
-namespace {enum E {}; static_assert(!std::numeric_limits<std::underlying_type<E>::type>::is_signed, "expected unscoped enum whose underlying type is not fixed to be unsigned");}
-#define ENUM_UNDERLYING_TYPE_UNSIGNED_INT
+namespace {
+enum E
+{
+};
+static_assert(!std::numeric_limits<std::underlying_type<E>::type>::is_signed, "expected unscoped enum whose underlying type is not fixed to be unsigned");
+} // namespace
+# define ENUM_UNDERLYING_TYPE_UNSIGNED_INT
#else
-#define ENUM_UNDERLYING_TYPE_UNSIGNED_INT : unsigned int
+# define ENUM_UNDERLYING_TYPE_UNSIGNED_INT : unsigned int
#endif
#if defined(_MSC_VER)
- typedef signed __int8 int8_t;
- typedef signed __int16 int16_t;
- typedef signed __int32 int32_t;
- typedef signed __int64 int64_t;
- typedef unsigned __int8 uint8_t;
- typedef unsigned __int16 uint16_t;
- typedef unsigned __int32 uint32_t;
- typedef unsigned __int64 uint64_t;
- #define ALIGN(bytes, type) __declspec(align(bytes)) type
+typedef signed __int8 int8_t;
+typedef signed __int16 int16_t;
+typedef signed __int32 int32_t;
+typedef signed __int64 int64_t;
+typedef unsigned __int8 uint8_t;
+typedef unsigned __int16 uint16_t;
+typedef unsigned __int32 uint32_t;
+typedef unsigned __int64 uint64_t;
+# define ALIGN(bytes, type) __declspec(align(bytes)) type
#else
- #include <stdint.h>
- #define ALIGN(bytes, type) type __attribute__((aligned(bytes)))
+# include <stdint.h>
+# define ALIGN(bytes, type) type __attribute__((aligned(bytes)))
#endif
namespace sw {
@@ -51,7 +56,7 @@
typedef ALIGN(1, int8_t) sbyte;
template<typename T, int N>
-struct alignas(sizeof(T)* N) vec
+struct alignas(sizeof(T) * N) vec
{
vec() = default;
@@ -63,9 +68,9 @@
}
}
- template<typename ... ARGS>
- constexpr vec(T arg0, ARGS ... args)
- : v{ arg0, args... }
+ template<typename... ARGS>
+ constexpr vec(T arg0, ARGS... args)
+ : v{ arg0, args... }
{
}
@@ -91,12 +96,18 @@
vec() = default;
constexpr explicit vec(T replicate)
- : x(replicate), y(replicate), z(replicate), w(replicate)
+ : x(replicate)
+ , y(replicate)
+ , z(replicate)
+ , w(replicate)
{
}
constexpr vec(T x, T y, T z, T w)
- : x(x), y(y), z(z), w(w)
+ : x(x)
+ , y(y)
+ , z(z)
+ , w(w)
{
}
@@ -128,7 +139,7 @@
};
template<typename T, int N>
-bool operator==(const vec<T, N>& a, const vec<T, N>& b)
+bool operator==(const vec<T, N> &a, const vec<T, N> &b)
{
for(int i = 0; i < N; i++)
{
@@ -142,15 +153,19 @@
}
template<typename T, int N>
-bool operator!=(const vec<T, N>& a, const vec<T, N>& b)
+bool operator!=(const vec<T, N> &a, const vec<T, N> &b)
{
return !(a == b);
}
-template<typename T> using vec2 = vec<T, 2>;
-template<typename T> using vec4 = vec<T, 4>;
-template<typename T> using vec8 = vec<T, 8>;
-template<typename T> using vec16 = vec<T, 16>;
+template<typename T>
+using vec2 = vec<T, 2>;
+template<typename T>
+using vec4 = vec<T, 4>;
+template<typename T>
+using vec8 = vec<T, 8>;
+template<typename T>
+using vec16 = vec<T, 16>;
using int2 = vec2<int>;
using uint2 = vec2<unsigned int>;
@@ -186,8 +201,8 @@
return vector(f, f, f, f);
}
-#define OFFSET(s,m) (int)(size_t)&reinterpret_cast<const volatile char&>((((s*)0)->m))
+#define OFFSET(s, m) (int)(size_t) & reinterpret_cast<const volatile char &>((((s *)0)->m))
} // namespace sw
-#endif // sw_Types_hpp
+#endif // sw_Types_hpp