diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2d82e85 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +Build \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..cadd5cb --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,36 @@ +cmake_minimum_required(VERSION 3.10) +project(Fledasty C) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) + +set(LIB_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/Lib/Include") + +if(WIN32) + set (HALLOCY_LIB_PATH "${CMAKE_SOURCE_DIR}/Lib/Windows/Hallocy.lib") +elseif(UNIX) + set (HALLOCY_LIB_PATH "${CMAKE_SOURCE_DIR}/Lib/Linux/libHallocy.a") +endif() + +include_directories(${PROJECT_SOURCE_DIR}/Include) +include_directories(${LIB_INCLUDE_DIR}) +file(GLOB_RECURSE SRC_FILES "${PROJECT_SOURCE_DIR}/Src/*.c") + +add_library(Fledasty STATIC ${SRC_FILES}) +add_executable(FledastyTest ${PROJECT_SOURCE_DIR}/Tests/Main.c) + +target_link_libraries(Fledasty PRIVATE ${HALLOCY_LIB_PATH}) +target_include_directories(FledastyTest PRIVATE ${PROJECT_SOURCE_DIR}/Tests) +target_link_libraries(FledastyTest Fledasty) + +if (MSVC) + target_compile_options(Fledasty PRIVATE /W4 /Zl) +else() + target_compile_options(Fledasty PRIVATE -mavx512f -mavx512vl) + target_compile_options(FledastyTest PRIVATE -mavx512f -mavx512vl) + + target_compile_options(Fledasty PRIVATE -march=native) + target_compile_options(FledastyTest PRIVATE -march=native) + + target_compile_options(Fledasty PRIVATE -Wall -Wextra -pedantic) +endif() \ No newline at end of file diff --git a/Lib/Include/Hallocy/Core/Allocator.h b/Lib/Include/Hallocy/Core/Allocator.h new file mode 100644 index 0000000..0720216 --- /dev/null +++ b/Lib/Include/Hallocy/Core/Allocator.h @@ -0,0 +1,38 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * File: Allocator.h + * Description: + * This file contains the functions for allocating, freeing and managing memory. + * It includes functions to allocate, reallocate, free, copy, move and set memory. + * + * Author: Mineplay + * ----------------------------------------------------------------------------- + */ +#ifndef HALLOCY_ALLOCATOR +#define HALLOCY_ALLOCATOR + +#include +#include + +#include "../Utils/Error.h" + +void *hallocy_allocate(const size_t size, const bool zero_memory); + +static inline void *hallocy_malloc(const size_t size) { return hallocy_allocate(size, false); } +static inline void *hallocy_calloc(const size_t size, size_t count) { return hallocy_allocate(size * count, true); } +void *hallocy_realloc(void *memory_pointer, const size_t size); +HallocyError hallocy_free(void *pointer); + +#endif \ No newline at end of file diff --git a/Lib/Include/Hallocy/Core/Memory.h b/Lib/Include/Hallocy/Core/Memory.h new file mode 100644 index 0000000..e284e5a --- /dev/null +++ b/Lib/Include/Hallocy/Core/Memory.h @@ -0,0 +1,36 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * File: Memory.h + * Description: + * This file implements the functions for managing memory. It includes functions + * to copy, move, compare and set memory. + * + * Author: Mineplay + * ----------------------------------------------------------------------------- + */ +#ifndef HALLOCY_MEMORY +#define HALLOCY_MEMORY + +#include +#include + +#include "../Utils/Error.h" + +HallocyError hallocy_set_memory(void *destination, int value, const size_t size); +HallocyError hallocy_copy_memory(void *destination, void *source, const size_t size); +HallocyError hallocy_move_memory(void *destination, void *source, const size_t size); +bool hallocy_compare_memory(void *left_side, void *right_side, const size_t size); + +#endif \ No newline at end of file diff --git a/Lib/Include/Hallocy/Utils/Error.h b/Lib/Include/Hallocy/Utils/Error.h new file mode 100644 index 0000000..af2ced6 --- /dev/null +++ b/Lib/Include/Hallocy/Utils/Error.h @@ -0,0 +1,34 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * File: Error.h + * Description: + * This file contains the ErrorCode enum that defines the error codes for the + * library. + * + * Author: Mineplay + * ----------------------------------------------------------------------------- + */ +#ifndef HALLOCY_ERROR +#define HALLOCY_ERROR + +typedef enum { + HALLOCY_ERROR_NONE = 0, + HALLOCY_ERROR_INVALID_POINTER = 1, + HALLOCY_ERROR_OUT_OF_MEMORY = 2, + HALLOCY_ERROR_UNKNOWN = 3, + HALLOCY_ERROR_INVALID_PARAM = 4 +} HallocyError; + +#endif \ No newline at end of file diff --git a/Lib/Include/Hallocy/Utils/Simd.h b/Lib/Include/Hallocy/Utils/Simd.h new file mode 100644 index 0000000..abbda76 --- /dev/null +++ b/Lib/Include/Hallocy/Utils/Simd.h @@ -0,0 +1,55 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * File: Simd.h + * Description: + * This file implements the functions for detecting SIMD support and defines the + * enum for specifing the SIMD type. + * + * Author: Mineplay + * ----------------------------------------------------------------------------- + */ +#ifndef HALLOCY_SIMD +#define HALLOCY_SIMD + +#if defined(_MSC_VER) + #if defined(_M_ARM64) + #include + #else + #include + #endif +#else + #if defined(__aarch64__) + #include + #elif defined(__arm__) + #include + #else + #include + #endif +#endif + +typedef enum { + HALLOCY_SIMD_UNDEFINED = 0, + HALLOCY_SIMD_NONE = 1, + HALLOCY_SIMD_SSE = 2, + HALLOCY_SIMD_SSE2 = 3, + HALLOCY_SIMD_AVX = 4, + HALLOCY_SIMD_AVX2 = 5, + HALLOCY_SIMD_AVX512 = 6, + HALLOCY_SIMD_NEON = 7 +} HallocySimdType; + +HallocySimdType hallocy_is_simd_supported(); + +#endif \ No newline at end of file diff --git a/Lib/Linux/libHallocy.a b/Lib/Linux/libHallocy.a new file mode 100644 index 0000000..b0d7df1 Binary files /dev/null and b/Lib/Linux/libHallocy.a differ diff --git a/Lib/Windows/Hallocy.lib b/Lib/Windows/Hallocy.lib new file mode 100644 index 0000000..64fbcac Binary files /dev/null and b/Lib/Windows/Hallocy.lib differ diff --git a/Tests/Main.c b/Tests/Main.c new file mode 100644 index 0000000..cde1df7 --- /dev/null +++ b/Tests/Main.c @@ -0,0 +1,27 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * File: Main.c + * Description: + * Executes all tests. + * + * Author: Mineplay + * ----------------------------------------------------------------------------- + */ +#include + +int main() { + printf("Test\n"); + return 0; +} \ No newline at end of file