diff --git a/.idea/modules.xml b/.idea/modules.xml index 74258af..3c731f4 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,6 +2,7 @@ + diff --git a/CMakeLists.txt b/CMakeLists.txt index b045622..e0fae0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.5) include(cmake/color.cmake) -set(BLT_VERSION 0.16.0) +set(BLT_VERSION 0.16.1) set(BLT_TEST_VERSION 0.0.1) set(BLT_TARGET BLT) diff --git a/include/blt/math/fixed_point.h b/include/blt/math/fixed_point.h index 113756d..5961f1b 100644 --- a/include/blt/math/fixed_point.h +++ b/include/blt/math/fixed_point.h @@ -19,9 +19,71 @@ #ifndef BLT_FIXED_POINT_H #define BLT_FIXED_POINT_H +#include +#include + namespace blt { - + struct fp64 + { + private: + u64 v = 0; + + fp64() = default; + + explicit fp64(u64 v): v(v) + {} + + public: + static fp64 from_u64(u64 ui) + { + fp64 fp; + fp.v = ui << 32; + return fp; + } + + static fp64 from_i64(i64 si) + { + u64 ui = static_cast(si); + fp64 fp; + fp.v = ui << 32; + return fp; + } + + BLT_ATTRIB_NO_INLINE friend fp64 operator+(fp64 left, fp64 right) + { + return fp64(left.v + right.v); + } + + BLT_ATTRIB_NO_INLINE friend fp64 operator-(fp64 left, fp64 right) + { + return fp64(left.v - right.v); + } + + BLT_ATTRIB_NO_INLINE friend fp64 operator*(fp64 left, fp64 right) + { + auto lhs = static_cast<__int128>(left.v); + auto rhs = static_cast<__int128>(right.v); + return fp64(static_cast((lhs * rhs) >> 32)); + } + + BLT_ATTRIB_NO_INLINE friend fp64 operator/(fp64 left, fp64 right) + { + auto lhs = static_cast<__int128>(left.v); + auto rhs = static_cast<__int128>(right.v); + return fp64(static_cast((lhs / rhs) << 32)); + } + + [[nodiscard]] u64 as_u64() const + { + return v >> 32; + } + + [[nodiscard]] i64 as_i64() const + { + return static_cast(v >> 32); + } + }; } #endif //BLT_FIXED_POINT_H diff --git a/libraries/parallel-hashmap b/libraries/parallel-hashmap index 946ebad..7ef2e73 160000 --- a/libraries/parallel-hashmap +++ b/libraries/parallel-hashmap @@ -1 +1 @@ -Subproject commit 946ebad67a21212d11a0dd4deb7cdedc297d47bc +Subproject commit 7ef2e733416953b222851f9a360d7fc72d068ee5 diff --git a/tests/include/blt_tests.h b/tests/include/blt_tests.h index a199749..b5efd9c 100644 --- a/tests/include/blt_tests.h +++ b/tests/include/blt_tests.h @@ -37,6 +37,7 @@ namespace blt::test } void vector_run(); + void allocator(); void fixed_point(); } diff --git a/tests/src/allocator_tests.cpp b/tests/src/allocator_tests.cpp new file mode 100644 index 0000000..9a3444b --- /dev/null +++ b/tests/src/allocator_tests.cpp @@ -0,0 +1,26 @@ +/* + * + * Copyright (C) 2024 Brett Terpstra + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include + +namespace blt::test +{ + void allocator() + { + + } +} \ No newline at end of file diff --git a/tests/src/main.cpp b/tests/src/main.cpp index 97fbf9b..6389b36 100644 --- a/tests/src/main.cpp +++ b/tests/src/main.cpp @@ -85,6 +85,8 @@ int main(int argc, const char** argv) parser.addArgument(blt::arg_builder("--utility").setHelp("Run tests on utility functions").setAction(blt::arg_action_t::STORE_TRUE).build()); parser.addArgument(blt::arg_builder("--data").setHelp("Run tests on data functions").setAction(blt::arg_action_t::STORE_TRUE).build()); parser.addArgument(blt::arg_builder("--vector").setHelp("Run tests for the vectors").setAction(blt::arg_action_t::STORE_TRUE).build()); + parser.addArgument(blt::arg_builder("--fixed_point").setHelp("Run tests for the vectors").setAction(blt::arg_action_t::STORE_TRUE).build()); + parser.addArgument(blt::arg_builder("--allocator").setHelp("Run tests for the vectors").setAction(blt::arg_action_t::STORE_TRUE).build()); auto args = parser.parse_args(argc, argv); @@ -110,6 +112,9 @@ int main(int argc, const char** argv) if (args.contains("--fixed_point")) blt::test::fixed_point(); + if (args.contains("--allocator")) + blt::test::allocator(); + if (args.contains("--nbt")) { auto v = blt::arg_parse::get(args["nbt"]); diff --git a/tests/src/math_tests.cpp b/tests/src/math_tests.cpp index db5fa0a..b8ad067 100644 --- a/tests/src/math_tests.cpp +++ b/tests/src/math_tests.cpp @@ -16,13 +16,23 @@ * along with this program. If not, see . */ #include +#include +#include +#include namespace blt::test { - void fixed_point() { - + fp64 uv = fp64::from_u64(32); + fp64 iv = fp64::from_i64(16); + + std::cout << uv.as_i64() << " : " << uv.as_u64() << std::endl; + std::cout << iv.as_i64() << " : " << iv.as_u64() << std::endl; + + std::cout << (uv * iv).as_i64() << std::endl; + std::cout << (uv * iv).as_u64() << std::endl; + std::cout << (uv / iv).as_i64() << std::endl; + std::cout << (uv / iv).as_u64() << std::endl; } - } \ No newline at end of file