Run clangformat everywhere
This commit is contained in:
@@ -3,18 +3,18 @@
|
||||
#include <log.hpp>
|
||||
|
||||
namespace Util {
|
||||
FORCE_INLINE std::vector<u8> ReadFileBinary(const std::string& path) {
|
||||
FORCE_INLINE std::vector<u8> ReadFileBinary(const std::string &path) {
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
return {std::istreambuf_iterator{file}, {}};
|
||||
}
|
||||
|
||||
FORCE_INLINE void WriteFileBinary(const std::vector<u8>& data, const std::string& path) {
|
||||
FORCE_INLINE void WriteFileBinary(const std::vector<u8> &data, const std::string &path) {
|
||||
std::ofstream file(path, std::ios::binary);
|
||||
std::copy(data.begin(), data.end(), std::ostreambuf_iterator{file});
|
||||
}
|
||||
|
||||
template <size_t Size>
|
||||
FORCE_INLINE void WriteFileBinary(const std::array<u8, Size>& data, const std::string& path) {
|
||||
FORCE_INLINE void WriteFileBinary(const std::array<u8, Size> &data, const std::string &path) {
|
||||
std::ofstream file(path, std::ios::binary);
|
||||
std::copy(data.begin(), data.end(), std::ostreambuf_iterator{file});
|
||||
}
|
||||
@@ -30,4 +30,4 @@ FORCE_INLINE size_t NextPow2(size_t num) {
|
||||
num |= num >> 16;
|
||||
return num + 1;
|
||||
}
|
||||
}
|
||||
} // namespace Util
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include <common.hpp>
|
||||
#include <cmath>
|
||||
#include <common.hpp>
|
||||
#include <immintrin.h>
|
||||
|
||||
namespace Util {
|
||||
@@ -52,7 +52,7 @@ static inline T roundNearest(double f) {
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
static inline T roundCurrent(float f) {
|
||||
#ifdef SIMD_SUPPORT
|
||||
auto t = _mm_set_ss(f);
|
||||
@@ -63,7 +63,7 @@ static inline T roundCurrent(float f) {
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
static inline T roundCurrent(double f) {
|
||||
#ifdef SIMD_SUPPORT
|
||||
auto t = _mm_set_sd(f);
|
||||
@@ -78,11 +78,11 @@ static inline T roundCurrent(double f) {
|
||||
template <typename T>
|
||||
static inline T roundFloor(float f) {
|
||||
#ifdef SIMD_SUPPORT
|
||||
__m128 t = _mm_set_ss(f);
|
||||
__m128 t = _mm_set_ss(f);
|
||||
t = _mm_round_ss(t, t, _MM_FROUND_TO_NEG_INF);
|
||||
return _mm_cvtss_f32(t);
|
||||
#else
|
||||
return floor(f);
|
||||
return floor(f);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -118,4 +118,4 @@ static inline T roundTrunc(double f) {
|
||||
return trunc(f);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} // namespace Util
|
||||
|
||||
@@ -1,113 +1,113 @@
|
||||
#pragma once
|
||||
#include <common.hpp>
|
||||
#include <cstring>
|
||||
#include <portable_endian_bswap.h>
|
||||
#include <log.hpp>
|
||||
#include <functional>
|
||||
#include <log.hpp>
|
||||
#include <portable_endian_bswap.h>
|
||||
|
||||
namespace Util {
|
||||
template<typename T>
|
||||
static FORCE_INLINE T ReadAccess(const u8* data, u32 index) {
|
||||
template <typename T>
|
||||
static FORCE_INLINE T ReadAccess(const u8 *data, u32 index) {
|
||||
if constexpr (sizeof(T) == 8) {
|
||||
u32 hi = *reinterpret_cast<const u32*>(&data[index + 0]);
|
||||
u32 lo = *reinterpret_cast<const u32*>(&data[index + 4]);
|
||||
u32 hi = *reinterpret_cast<const u32 *>(&data[index + 0]);
|
||||
u32 lo = *reinterpret_cast<const u32 *>(&data[index + 4]);
|
||||
T result = ((T)hi << 32) | (T)lo;
|
||||
return result;
|
||||
} else {
|
||||
return *reinterpret_cast<const T*>(&data[index]);
|
||||
return *reinterpret_cast<const T *>(&data[index]);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static FORCE_INLINE T ReadAccess(const std::vector<u8>& data, u32 index) {
|
||||
template <typename T>
|
||||
static FORCE_INLINE T ReadAccess(const std::vector<u8> &data, u32 index) {
|
||||
if constexpr (sizeof(T) == 8) {
|
||||
u32 hi = *reinterpret_cast<const u32*>(&data[index + 0]);
|
||||
u32 lo = *reinterpret_cast<const u32*>(&data[index + 4]);
|
||||
u32 hi = *reinterpret_cast<const u32 *>(&data[index + 0]);
|
||||
u32 lo = *reinterpret_cast<const u32 *>(&data[index + 4]);
|
||||
T result = ((T)hi << 32) | (T)lo;
|
||||
return result;
|
||||
} else {
|
||||
return *reinterpret_cast<const T*>(&data[index]);
|
||||
return *reinterpret_cast<const T *>(&data[index]);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, size_t Size>
|
||||
static FORCE_INLINE T ReadAccess(const std::array<u8, Size>& data, u32 index) {
|
||||
template <typename T, size_t Size>
|
||||
static FORCE_INLINE T ReadAccess(const std::array<u8, Size> &data, u32 index) {
|
||||
if constexpr (sizeof(T) == 8) {
|
||||
u32 hi = *reinterpret_cast<const u32*>(&data[index + 0]);
|
||||
u32 lo = *reinterpret_cast<const u32*>(&data[index + 4]);
|
||||
u32 hi = *reinterpret_cast<const u32 *>(&data[index + 0]);
|
||||
u32 lo = *reinterpret_cast<const u32 *>(&data[index + 4]);
|
||||
T result = ((T)hi << 32) | (T)lo;
|
||||
return result;
|
||||
} else {
|
||||
return *reinterpret_cast<const T*>(&data[index]);
|
||||
return *reinterpret_cast<const T *>(&data[index]);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, size_t Size>
|
||||
static FORCE_INLINE void WriteAccess(std::array<u8, Size>& data, u32 index, T val) {
|
||||
template <typename T, size_t Size>
|
||||
static FORCE_INLINE void WriteAccess(std::array<u8, Size> &data, u32 index, T val) {
|
||||
if constexpr (sizeof(T) == 8) {
|
||||
u32 hi = val >> 32;
|
||||
u32 lo = val;
|
||||
|
||||
*reinterpret_cast<u32*>(&data[index + 0]) = hi;
|
||||
*reinterpret_cast<u32*>(&data[index + 4]) = lo;
|
||||
*reinterpret_cast<u32 *>(&data[index + 0]) = hi;
|
||||
*reinterpret_cast<u32 *>(&data[index + 4]) = lo;
|
||||
} else {
|
||||
*reinterpret_cast<T*>(&data[index]) = val;
|
||||
*reinterpret_cast<T *>(&data[index]) = val;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static FORCE_INLINE void WriteAccess(std::vector<u8>& data, u32 index, T val) {
|
||||
template <typename T>
|
||||
static FORCE_INLINE void WriteAccess(std::vector<u8> &data, u32 index, T val) {
|
||||
if constexpr (sizeof(T) == 8) {
|
||||
u32 hi = val >> 32;
|
||||
u32 lo = val;
|
||||
|
||||
*reinterpret_cast<u32*>(&data[index + 0]) = hi;
|
||||
*reinterpret_cast<u32*>(&data[index + 4]) = lo;
|
||||
*reinterpret_cast<u32 *>(&data[index + 0]) = hi;
|
||||
*reinterpret_cast<u32 *>(&data[index + 4]) = lo;
|
||||
} else {
|
||||
*reinterpret_cast<T*>(&data[index]) = val;
|
||||
*reinterpret_cast<T *>(&data[index]) = val;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
static FORCE_INLINE void WriteAccess(u8 *data, u32 index, T val) {
|
||||
if constexpr (sizeof(T) == 8) {
|
||||
u32 hi = val >> 32;
|
||||
u32 lo = val;
|
||||
|
||||
*reinterpret_cast<u32*>(&data[index + 0]) = hi;
|
||||
*reinterpret_cast<u32*>(&data[index + 4]) = lo;
|
||||
*reinterpret_cast<u32 *>(&data[index + 0]) = hi;
|
||||
*reinterpret_cast<u32 *>(&data[index + 4]) = lo;
|
||||
} else {
|
||||
*reinterpret_cast<T*>(&data[index]) = val;
|
||||
*reinterpret_cast<T *>(&data[index]) = val;
|
||||
}
|
||||
}
|
||||
|
||||
FORCE_INLINE void SwapBuffer32(std::vector<u8> &data) {
|
||||
for (size_t i = 0; i < data.size(); i += 4) {
|
||||
u32 original = *(u32 *) &data[i];
|
||||
*(u32 *) &data[i] = bswap_32(original);
|
||||
u32 original = *(u32 *)&data[i];
|
||||
*(u32 *)&data[i] = bswap_32(original);
|
||||
}
|
||||
}
|
||||
|
||||
FORCE_INLINE void SwapBuffer16(std::vector<u8> &data) {
|
||||
for (size_t i = 0; i < data.size(); i += 2) {
|
||||
u16 original = *(u16 *) &data[i];
|
||||
*(u16 *) &data[i] = bswap_16(original);
|
||||
u16 original = *(u16 *)&data[i];
|
||||
*(u16 *)&data[i] = bswap_16(original);
|
||||
}
|
||||
}
|
||||
|
||||
template <size_t Size>
|
||||
FORCE_INLINE void SwapBuffer32(std::array<u8, Size> &data) {
|
||||
for (size_t i = 0; i < Size; i += 4) {
|
||||
u32 original = *(u32 *) &data[i];
|
||||
*(u32 *) &data[i] = bswap_32(original);
|
||||
u32 original = *(u32 *)&data[i];
|
||||
*(u32 *)&data[i] = bswap_32(original);
|
||||
}
|
||||
}
|
||||
|
||||
template <size_t Size>
|
||||
FORCE_INLINE void SwapBuffer16(std::array<u8, Size> &data) {
|
||||
for (size_t i = 0; i < Size; i += 2) {
|
||||
u16 original = *(u16 *) &data[i];
|
||||
*(u16 *) &data[i] = bswap_16(original);
|
||||
u16 original = *(u16 *)&data[i];
|
||||
*(u16 *)&data[i] = bswap_16(original);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,27 +134,19 @@ FORCE_INLINE u32 crc32(u32 crc, const u8 *buf, size_t len) {
|
||||
|
||||
crc = ~crc;
|
||||
for (int i = 0; i < len; i++) {
|
||||
octet = buf[i]; /* Cast to unsigned octet. */
|
||||
octet = buf[i]; /* Cast to unsigned octet. */
|
||||
crc = (crc >> 8) ^ table[(crc & 0xff) ^ octet];
|
||||
}
|
||||
return ~crc;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
FORCE_INLINE void* aligned_alloc(size_t alignment, size_t size) {
|
||||
return _aligned_malloc(size, alignment);
|
||||
}
|
||||
FORCE_INLINE void *aligned_alloc(size_t alignment, size_t size) { return _aligned_malloc(size, alignment); }
|
||||
|
||||
FORCE_INLINE void aligned_free(void* ptr) {
|
||||
_aligned_free(ptr);
|
||||
}
|
||||
FORCE_INLINE void aligned_free(void *ptr) { _aligned_free(ptr); }
|
||||
#else
|
||||
FORCE_INLINE void* aligned_alloc(size_t alignment, size_t size) {
|
||||
return std::aligned_alloc(alignment, size);
|
||||
}
|
||||
FORCE_INLINE void *aligned_alloc(size_t alignment, size_t size) { return std::aligned_alloc(alignment, size); }
|
||||
|
||||
FORCE_INLINE void aligned_free(void* ptr) {
|
||||
std::free(ptr);
|
||||
}
|
||||
FORCE_INLINE void aligned_free(void *ptr) { std::free(ptr); }
|
||||
#endif
|
||||
}
|
||||
} // namespace Util
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
#pragma once
|
||||
#include <common.hpp>
|
||||
#include <fmt/format.h>
|
||||
#include <fmt/color.h>
|
||||
#include <fmt/format.h>
|
||||
#include <string>
|
||||
#if !defined(NDEBUG) && !defined(_WIN32)
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
namespace Util {
|
||||
enum LogLevel : u8 {
|
||||
Trace, Debug, Warn, Info, Error, Always
|
||||
};
|
||||
enum LogLevel : u8 { Trace, Debug, Warn, Info, Error, Always };
|
||||
|
||||
#ifndef NDEBUG
|
||||
static constexpr auto globalLogLevel = Debug;
|
||||
@@ -18,23 +16,23 @@ static constexpr auto globalLogLevel = Debug;
|
||||
static constexpr auto globalLogLevel = Info;
|
||||
#endif
|
||||
|
||||
template <LogLevel messageType = Info, typename ...Args>
|
||||
constexpr void print(const std::string& fmt, Args... args) {
|
||||
if constexpr(messageType >= globalLogLevel) {
|
||||
template <LogLevel messageType = Info, typename... Args>
|
||||
constexpr void print(const std::string &fmt, Args... args) {
|
||||
if constexpr (messageType >= globalLogLevel) {
|
||||
#ifndef _WIN32
|
||||
if constexpr(messageType == Error) {
|
||||
if constexpr (messageType == Error) {
|
||||
fmt::print(fmt::emphasis::bold | fg(fmt::color::red), fmt, args...);
|
||||
} else if constexpr(messageType == Warn) {
|
||||
} else if constexpr (messageType == Warn) {
|
||||
fmt::print(fg(fmt::color::yellow), fmt, args...);
|
||||
} else if constexpr(messageType == Info || messageType == Trace || messageType == Always) {
|
||||
} else if constexpr (messageType == Info || messageType == Trace || messageType == Always) {
|
||||
fmt::print(fmt, args...);
|
||||
} else if constexpr(messageType == Debug) {
|
||||
} else if constexpr (messageType == Debug) {
|
||||
#ifndef NDEBUG
|
||||
fmt::print(fmt, args...);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
if constexpr(messageType == Debug) {
|
||||
if constexpr (messageType == Debug) {
|
||||
#ifndef NDEBUG
|
||||
fmt::print(fmt, args...);
|
||||
#endif
|
||||
@@ -45,61 +43,61 @@ constexpr void print(const std::string& fmt, Args... args) {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
constexpr void panic(const std::string& fmt, Args... args) {
|
||||
template <typename... Args>
|
||||
constexpr void panic(const std::string &fmt, Args... args) {
|
||||
print<Error>("[FATAL] " + fmt + "\n", args...);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
constexpr void error(const std::string& fmt, Args... args) {
|
||||
template <typename... Args>
|
||||
constexpr void error(const std::string &fmt, Args... args) {
|
||||
print<Error>("[ERROR] " + fmt + "\n", args...);
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
constexpr void warn(const std::string& fmt, Args... args) {
|
||||
template <typename... Args>
|
||||
constexpr void warn(const std::string &fmt, Args... args) {
|
||||
print<Warn>("[WARN] " + fmt + "\n", args...);
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
constexpr void info(const std::string& fmt, Args... args) {
|
||||
template <typename... Args>
|
||||
constexpr void info(const std::string &fmt, Args... args) {
|
||||
print("[INFO] " + fmt + "\n", args...);
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
constexpr void debug(const std::string& fmt, Args... args) {
|
||||
template <typename... Args>
|
||||
constexpr void debug(const std::string &fmt, Args... args) {
|
||||
print<Debug>("[DEBUG] " + fmt + "\n", args...);
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
constexpr void trace(const std::string& fmt, Args... args) {
|
||||
template <typename... Args>
|
||||
constexpr void trace(const std::string &fmt, Args... args) {
|
||||
print<Trace>("[TRACE] " + fmt + "\n", args...);
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
constexpr void always(const std::string& fmt, Args... args) {
|
||||
template <typename... Args>
|
||||
constexpr void always(const std::string &fmt, Args... args) {
|
||||
print<Always>(fmt + "\n", args...);
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
constexpr void panic_trace(const std::string& fmt, Args... args) {
|
||||
template <typename... Args>
|
||||
constexpr void panic_trace(const std::string &fmt, Args... args) {
|
||||
#if !defined(NDEBUG) && !defined(_WIN32)
|
||||
Dl_info info;
|
||||
auto tmp = fmt::format(fmt + '\n', args...);
|
||||
tmp += "Called by:\n";
|
||||
if(dladdr(__builtin_return_address(0), &info))
|
||||
if (dladdr(__builtin_return_address(0), &info))
|
||||
tmp += fmt::format("\t-> {}\n", info.dli_sname);
|
||||
if(dladdr(__builtin_return_address(1), &info))
|
||||
if (dladdr(__builtin_return_address(1), &info))
|
||||
tmp += fmt::format("\t-> {}\n", info.dli_sname);
|
||||
if(dladdr(__builtin_return_address(2), &info))
|
||||
if (dladdr(__builtin_return_address(2), &info))
|
||||
tmp += fmt::format("\t-> {}\n", info.dli_sname);
|
||||
if(dladdr(__builtin_return_address(3), &info))
|
||||
if (dladdr(__builtin_return_address(3), &info))
|
||||
tmp += fmt::format("\t-> {}\n", info.dli_sname);
|
||||
if(dladdr(__builtin_return_address(4), &info))
|
||||
if (dladdr(__builtin_return_address(4), &info))
|
||||
tmp += fmt::format("\t-> {}\n", info.dli_sname);
|
||||
if(dladdr(__builtin_return_address(5), &info))
|
||||
if (dladdr(__builtin_return_address(5), &info))
|
||||
tmp += fmt::format("\t-> {}\n", info.dli_sname);
|
||||
if(dladdr(__builtin_return_address(6), &info))
|
||||
if (dladdr(__builtin_return_address(6), &info))
|
||||
tmp += fmt::format("\t-> {}\n", info.dli_sname);
|
||||
|
||||
print<Error>("[FATAL TRACE] " + tmp);
|
||||
@@ -108,4 +106,4 @@ constexpr void panic_trace(const std::string& fmt, Args... args) {
|
||||
panic(fmt, args...);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} // namespace Util
|
||||
|
||||
Reference in New Issue
Block a user