From 2230d4c662fdb390131cff7b818dae5fe719c5fa Mon Sep 17 00:00:00 2001 From: iris Date: Mon, 18 May 2026 23:13:35 +0200 Subject: [PATCH] dhjkfhsdf --- external/ircolib/README.md | 7 -- external/ircolib/file.hpp | 43 --------- external/ircolib/floats.hpp | 106 --------------------- external/ircolib/log.hpp | 16 ---- external/ircolib/mem_access.hpp | 159 -------------------------------- external/ircolib/types.hpp | 37 -------- 6 files changed, 368 deletions(-) delete mode 100644 external/ircolib/README.md delete mode 100644 external/ircolib/file.hpp delete mode 100644 external/ircolib/floats.hpp delete mode 100644 external/ircolib/log.hpp delete mode 100644 external/ircolib/mem_access.hpp delete mode 100644 external/ircolib/types.hpp diff --git a/external/ircolib/README.md b/external/ircolib/README.md deleted file mode 100644 index d5db4a5..0000000 --- a/external/ircolib/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# ircolib - -Collections of useful functions I started copy-pasting in various projects and thus decided to gather all in one place. - -## Flags - -To enable SIMD for `floats.hpp`, add a `#define SIMD_SUPPORT` before `#include "floats.hpp"`. \ No newline at end of file diff --git a/external/ircolib/file.hpp b/external/ircolib/file.hpp deleted file mode 100644 index ebfb463..0000000 --- a/external/ircolib/file.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once -#include -#include -#include -#include - -namespace fs = std::filesystem; - -namespace ircolib { -static inline std::vector read_file_binary(const std::string &path) { - std::ifstream file(path, std::ios::binary); - return {std::istreambuf_iterator{file}, {}}; -} - -static inline void write_file_binary(const std::vector &data, const std::string &path) { - std::ofstream file(path, std::ios::binary); - std::copy(data.begin(), data.end(), std::ostreambuf_iterator{file}); -} - -static inline void write_file_binary(const u8 *data, const size_t size, const std::string &path) { - FILE *out = fopen(path.c_str(), "wb"); - fwrite(data, size, 1, out); - fclose(out); -} - -template -static inline void write_file_binary(const std::array &data, const std::string &path) { - std::ofstream file(path, std::ios::binary); - std::copy(data.begin(), data.end(), std::ostreambuf_iterator{file}); -} - -static inline size_t next_pow2(size_t num) { - // Taken from "Bit Twiddling Hacks" by Sean Anderson: - // https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 - --num; - num |= num >> 1; - num |= num >> 2; - num |= num >> 4; - num |= num >> 8; - num |= num >> 16; - return num + 1; -} -} // namespace ircolib diff --git a/external/ircolib/floats.hpp b/external/ircolib/floats.hpp deleted file mode 100644 index 24868bc..0000000 --- a/external/ircolib/floats.hpp +++ /dev/null @@ -1,106 +0,0 @@ -#pragma once -#include -#include - -namespace ircolib { -static inline auto round_ceil(float f) { -#ifdef SIMD_SUPPORT - __m128 t = _mm_set_ss(f); - t = _mm_round_ss(t, t, _MM_FROUND_TO_POS_INF); - return _mm_cvtss_f32(t); -#else - return ceilf(f); -#endif -} - -static inline auto round_ceil(double f) { -#ifdef SIMD_SUPPORT - __m128d t = _mm_set_sd(f); - t = _mm_round_sd(t, t, _MM_FROUND_TO_POS_INF); - return _mm_cvtsd_f64(t); -#else - return ceil(f); -#endif -} - -static inline auto round_nearest(float f) { -#ifdef SIMD_SUPPORT - __m128 t = _mm_set_ss(f); - t = _mm_round_ss(t, t, _MM_FROUND_TO_NEAREST_INT); - return _mm_cvtss_f32(t); -#else - return roundf(f); -#endif -} - -static inline auto round_nearest(double f) { -#ifdef SIMD_SUPPORT - __m128d t = _mm_set_sd(f); - t = _mm_round_sd(t, t, _MM_FROUND_TO_NEAREST_INT); - return _mm_cvtsd_f64(t); -#else - return round(f); -#endif -} - -static inline auto round_current(float f) { -#ifdef SIMD_SUPPORT - auto t = _mm_set_ss(f); - t = _mm_round_ss(t, t, _MM_FROUND_CUR_DIRECTION); - return _mm_cvtss_f32(t); -#else - return rint(f); -#endif -} - -static inline auto round_current(double f) { -#ifdef SIMD_SUPPORT - auto t = _mm_set_sd(f); - t = _mm_round_sd(t, t, _MM_FROUND_CUR_DIRECTION); - return _mm_cvtsd_f64(t); -#else - return rint(f); -#endif -} - - -static inline auto round_floor(float f) { -#ifdef SIMD_SUPPORT - __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); -#endif -} - -static inline auto round_floor(double f) { -#ifdef SIMD_SUPPORT - __m128d t = _mm_set_sd(f); - t = _mm_round_sd(t, t, _MM_FROUND_TO_NEG_INF); - return _mm_cvtsd_f64(t); -#else - return floor(f); -#endif -} - -static inline auto round_trunc(float f) { -#ifdef SIMD_SUPPORT - __m128 t = _mm_set_ss(f); - t = _mm_round_ss(t, t, _MM_FROUND_TO_ZERO); - return _mm_cvtss_f32(t); -#else - return trunc(f); -#endif -} - -static inline auto round_trunc(double f) { -#ifdef SIMD_SUPPORT - __m128d t = _mm_set_sd(f); - t = _mm_round_sd(t, t, _MM_FROUND_TO_ZERO); - return _mm_cvtsd_f64(t); -#else - return trunc(f); -#endif -} -} // namespace ircolib diff --git a/external/ircolib/log.hpp b/external/ircolib/log.hpp deleted file mode 100644 index 0f4ab06..0000000 --- a/external/ircolib/log.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once -#include - -namespace ircolib { -template -void panic(std::format_string fmt, Args &&...args) { - std::print("[FATAL] "); - std::println(fmt, std::forward(args)...); - exit(1); -} -template -void warn(std::format_string fmt, Args &&...args) { - std::print("[WARN] "); - std::println(fmt, std::forward(args)...); -} -} // namespace ircolib diff --git a/external/ircolib/mem_access.hpp b/external/ircolib/mem_access.hpp deleted file mode 100644 index bb83b77..0000000 --- a/external/ircolib/mem_access.hpp +++ /dev/null @@ -1,159 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include - -namespace ircolib { -static inline std::vector integral_to_buffer(const std::integral auto &val) { - std::vector ret{}; - ret.resize(sizeof(val)); - - memcpy(ret.data(), &val, sizeof(val)); - - return ret; -} - -static inline auto integral_to_slice(const std::integral auto &val) -> std::array { - std::array ret{}; - - memcpy(ret.data(), &val, sizeof(val)); - - return ret; -} - -static inline constexpr bool is_inside_range(const std::integral auto &addr, const std::integral auto &start, - const std::integral auto &end) { - return addr >= start && addr <= end; -} - -template -static constexpr inline T read_access(const u8 *data, const u32 index); -template -static constexpr inline T read_access(const std::vector &data, const u32 index); -template -static constexpr inline T read_access(const std::array &data, const u32 index); - -template -static constexpr inline void write_access(u8 *data, const u32 index, const T val); -template -static constexpr inline void write_access(std::vector &data, const u32 index, const T val); -template -static constexpr inline void write_access(std::array &data, const u32 index, const T val); - -template <> -constexpr inline u64 read_access(const u8 *data, const u32 index) { - u32 hi = *reinterpret_cast(&data[index + 0]); - u32 lo = *reinterpret_cast(&data[index + 4]); - const auto &result = static_cast(hi) << 32 | static_cast(lo); - return result; -} - -template -static constexpr inline T read_access(const u8 *data, const u32 index) { - return *reinterpret_cast(&data[index]); -} - -template <> -constexpr inline u64 read_access(const std::vector &data, const u32 index) { - u32 hi = *reinterpret_cast(&data[index + 0]); - u32 lo = *reinterpret_cast(&data[index + 4]); - return (static_cast(hi) << 32) | static_cast(lo); -} - -template -static constexpr inline T read_access(const std::vector &data, const u32 index) { - return *reinterpret_cast(&data[index]); -} - -template -constexpr inline u64 read_access(const std::array &data, const u32 index) { - u32 hi = *reinterpret_cast(&data[index + 0]); - u32 lo = *reinterpret_cast(&data[index + 4]); - return static_cast(hi) << 32 | static_cast(lo); -} - -template -static constexpr inline T read_access(const std::array &data, const u32 index) { - return *reinterpret_cast(&data[index]); -} - -template -constexpr inline void write_access(std::array &data, const u32 index, const u64 val) { - const u32 hi = val >> 32; - const u32 lo = val; - - *reinterpret_cast(&data[index + 0]) = hi; - *reinterpret_cast(&data[index + 4]) = lo; -} - -template -static constexpr inline void write_access(std::array &data, const u32 index, const T val) { - *reinterpret_cast(&data[index]) = val; -} - -template <> -constexpr inline void write_access(std::vector &data, const u32 index, const u64 val) { - const u32 hi = val >> 32; - const u32 lo = val; - - *reinterpret_cast(&data[index + 0]) = hi; - *reinterpret_cast(&data[index + 4]) = lo; -} - -template -static constexpr inline void write_access(std::vector &data, const u32 index, const T val) { - *reinterpret_cast(&data[index]) = val; -} - -template <> -constexpr inline void write_access(u8 *data, const u32 index, const u64 val) { - const u32 hi = val >> 32; - const u32 lo = val; - - *reinterpret_cast(&data[index + 0]) = hi; - *reinterpret_cast(&data[index + 4]) = lo; -} - -template -static constexpr inline void write_access(u8 *data, const u32 index, const T val) { - *reinterpret_cast(&data[index]) = val; -} - -template -static constexpr inline void swap_buffer(std::vector &data) { - for (size_t i = 0; i < data.size(); i += sizeof(T)) { - const T original = *reinterpret_cast(&data[i]); - *reinterpret_cast(&data[i]) = std::byteswap(original); - } -} - -template -static constexpr inline void swap_buffer(std::array &data) { - for (size_t i = 0; i < data.size(); i += sizeof(T)) { - const T original = *reinterpret_cast(&data[i]); - *reinterpret_cast(&data[i]) = std::byteswap(original); - } -} - -template -static constexpr inline void swap_buffer(u8 *data, size_t size) { - for (size_t i = 0; i < size; i += sizeof(T)) { - const T original = *reinterpret_cast(&data[i]); - *reinterpret_cast(&data[i]) = std::byteswap(original); - } -} - -#ifdef _WIN32 -inline void *aligned_alloc(const size_t alignment, const size_t size) { return _aligned_malloc(size, alignment); } - -inline void aligned_free(void *ptr) { _aligned_free(ptr); } -#else -inline void *aligned_alloc(const size_t alignment, const size_t size) { return std::aligned_alloc(alignment, size); } - -inline void aligned_free(void *ptr) { std::free(ptr); } -#endif -} // namespace ircolib diff --git a/external/ircolib/types.hpp b/external/ircolib/types.hpp deleted file mode 100644 index 396a74c..0000000 --- a/external/ircolib/types.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once -#include - -namespace ircolib { -using u8 = uint8_t; -using u16 = uint16_t; -using u32 = uint32_t; -using u64 = uint64_t; -using s8 = int8_t; -using s16 = int16_t; -using s32 = int32_t; -using s64 = int64_t; - -template -static constexpr bool is_bit_set(const T &val) { - return val & (1 << bit); -} - -template -static constexpr void set_bit(T &val) { - val |= 1 << bit; -} - -template -inline bool is_bit_set(const T &val, const std::size_t &bit) { - return val & (1 << bit); -} - -template -inline void set_bit(T &val, const std::size_t &bit) { - val |= 1 << bit; -} -} // namespace ircolib - -constexpr ircolib::u32 operator""_kib(const unsigned long long v) { return v * 1024; } -constexpr ircolib::u32 operator""_mib(const unsigned long long v) { return v * 1024 * 1024; } -constexpr ircolib::u32 operator""_gib(const unsigned long long v) { return v * 1024 * 1024 * 1024; }