commit c40034376174ed953760a0a47c3993e022e8e74f Author: Karutoh Date: Fri May 9 16:21:15 2025 -0700 First commit. diff --git a/.gitea/workflows/BuildRelease.yaml b/.gitea/workflows/BuildRelease.yaml new file mode 100644 index 0000000..da45028 --- /dev/null +++ b/.gitea/workflows/BuildRelease.yaml @@ -0,0 +1,107 @@ +name: Build & Release +run-name: ${{ gitea.actor }} is testing out Gitea Actions +on: + push: + tags: + - "v*" + +jobs: + Windows-AMD64-Build: + runs-on: windows-x86_64 + defaults: + run: + shell: powershell + steps: + - name: Check out repository code + uses: actions/checkout@v3 + + - name: Building/Compiling Project + run: | + cd ${{ gitea.workspace }} + mkdir build + cd build + cmake -A x64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake" .. + cmake --build . --config Release + + - name: Zipping Binaries + run: | + cd ${{ gitea.workspace }} + tar -a -c -f avx-windows-amd64.zip build/Release/AVX.exe "$env:USERPROFILE\EHS\bin\EHS_Dyn.dll" + + - uses: https://github.com/actions/setup-go@v4 + with: + go-version: '>=1.20.1' + + - name: Use Go Action + id: use-go-action + uses: https://gitea.com/actions/release-action@main + with: + files: |- + avx-windows-amd64.zip + api_key: '${{secrets.RELEASE_TOKEN}}' + pre_release: false + + Linux-AMD64-Build: + runs-on: linux-x86_64 + steps: + - name: Check out repository code + uses: actions/checkout@v3 + + - name: Installing Dependencies + run: | + sudo pacman -S --noconfirm doxygen zip alsa-lib libxcb xcb-util-cursor pipewire + + - name: Building/Compiling Project + run: | + cd ${{ gitea.workspace }} + cmake -DCMAKE_BUILD_TYPE=Release -DLINUX_WINDOW_SYSTEM:STRING=XCB . + cmake --build . --config Release + cmake --install . + + - name: Zipping Binaries + run: zip -r avx-linux-amd64.zip AVX + + - uses: https://github.com/actions/setup-go@v4 + with: + go-version: '>=1.20.1' + + - name: Use Go Action + id: use-go-action + uses: https://gitea.com/actions/release-action@main + with: + files: |- + avx-linux-amd64.zip + api_key: '${{secrets.RELEASE_TOKEN}}' + pre_release: false + + Linux-AARCH64-Build: + runs-on: linux-aarch64 + steps: + - name: Check out repository code + uses: actions/checkout@v3 + + - name: Installing Dependencies + run: sudo apt install -y doxygen zip libasound2-dev libxcb1-dev libxcb-xinput-dev libxcb-cursor-dev libpipewire-0.3-dev + + - name: Building/Compiling/Installing Project + run: | + cd ${{ gitea.workspace }} + cmake -DCMAKE_BUILD_TYPE=Release -DLINUX_WINDOW_SYSTEM:STRING=XCB . + cmake --build . --config Release + cmake --install . + + - name: Zipping Binaries + run: zip -r avx-linux-aarch64.zip AVX + + - uses: https://github.com/actions/setup-go@v4 + with: + go-version: '>=1.20.1' + + - name: Use Go Action + id: use-go-action + uses: https://gitea.com/actions/release-action@main + with: + files: |- + avx-linux-aarch64.zip + api_key: '${{secrets.RELEASE_TOKEN}}' + pre_release: false \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ebe792b --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +*.obj +*.cpp.obj +*.lib +*.exe +*.a +*.ninja_deps +*.ninja_log +*.ninja +*.cmake +*.log +/.idea/ +/cmake-build-release/ +/cmake-build-debug/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e78a8fc --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,49 @@ +cmake_minimum_required(VERSION 3.18.4) +project(AVX C CXX) + +if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows") + set(IS_OS_WINDOWS TRUE) + set(USER_HOME_DIRECTORY $ENV{USERPROFILE}) + message("Building for the Windows operating system.") +elseif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux") + set(IS_OS_LINUX TRUE) + set(USER_HOME_DIRECTORY $ENV{HOME}) + add_compile_options(-Wno-stringop-overflow) + message("Building for the Linux operating system.") +elseif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin") + set(IS_OS_MAC TRUE) + set(USER_HOME_DIRECTORY $ENV{HOME}) + message("Building for the Mac operating system.") +endif () + +if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") + message("Building for AMD64 architecture.") + set(IS_ARCH_AMD64 TRUE) +elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ARM64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64") + message("Building for ARM64 architecture.") + set(IS_ARCH_ARM64 TRUE) +endif () + +set(CMAKE_CXX_STANDARD 20) + +add_executable(AVX main.cpp) + +target_include_directories(AVX PUBLIC "${PROJECT_SOURCE_DIR}/include") + +if (IS_OS_LINUX) + add_compile_definitions(LWE_WS_XCB) + + target_link_directories(AVX PUBLIC "${USER_HOME_DIRECTORY}/.local/lib") + target_link_directories(AVX PUBLIC "${USER_HOME_DIRECTORY}/.local/bin") + target_include_directories(AVX PUBLIC "${USER_HOME_DIRECTORY}/.local/include") + + target_link_libraries(AVX PUBLIC xcb xcb-cursor xcb-xfixes xcb-xinput z asound EHS_Dyn) +elseif (IS_OS_WINDOWS) + target_compile_definitions(AVX PRIVATE EHS_LIB_EXPORT) + + target_link_directories(AVX PUBLIC "${USER_HOME_DIRECTORY}/EHS/lib") + target_link_directories(AVX PUBLIC "${USER_HOME_DIRECTORY}/EHS/bin") + target_include_directories(AVX PUBLIC "${USER_HOME_DIRECTORY}/EHS/include") + + target_link_libraries(AVX PUBLIC EHS_Dyn) +endif() \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..6245847 --- /dev/null +++ b/main.cpp @@ -0,0 +1,255 @@ +#include +#include +#include +#include +#include +#include + +bool Compare_AVX512(const void* const a, const void* const b, const ehs::UInt_64 size) +{ + ehs::Byte* aBytes = (ehs::Byte*)a; + ehs::Byte* bBytes = (ehs::Byte*)b; + ehs::UInt_64 remainder = size; + ehs::UInt_64 i = 0; + + while (i < size) + { + if (remainder >= 64) + { + if (!ehs::AVX512::CompareUnaligned((ehs::UInt_64*)&aBytes[i], (ehs::UInt_64*)&bBytes[i])) + return false; + + i += 64; + } + else if (remainder >= 32) + { + if (!ehs::AVX2::CompareUnaligned((ehs::UInt_64*)&aBytes[i], (ehs::UInt_64*)&bBytes[i])) + return false; + + i += 32; + } + else if (remainder >= sizeof(ehs::UInt_64)) + { + if (*(ehs::UInt_64*)&aBytes[i] != *(ehs::UInt_64*)&bBytes[i]) + return false; + + i += sizeof(ehs::UInt_64); + } + else if (remainder >= sizeof(ehs::UInt_32)) + { + if (*(ehs::UInt_32*)&aBytes[i] != *(ehs::UInt_32*)&bBytes[i]) + return false; + + i += sizeof(ehs::UInt_32); + } + else if (remainder >= sizeof(ehs::UInt_16)) + { + if (*(ehs::UInt_16*)&aBytes[i] != *(ehs::UInt_16*)&bBytes[i]) + return false; + + i += sizeof(ehs::UInt_16); + } + else + { + if (aBytes[i] != bBytes[i]) + return false; + + i += sizeof(ehs::Byte); + } + + remainder = size - i; + } + + return true; +} + +bool Compare_AVX2(const void* const a, const void* const b, const ehs::UInt_64 size) +{ + ehs::Byte* aBytes = (ehs::Byte*)a; + ehs::Byte* bBytes = (ehs::Byte*)b; + ehs::UInt_64 remainder = size; + ehs::UInt_64 i = 0; + + while (i < size) + { + if (remainder >= 32) + { + if (!ehs::AVX2::CompareUnaligned((ehs::UInt_64*)&aBytes[i], (ehs::UInt_64*)&bBytes[i])) + return false; + + i += 32; + } + else if (remainder >= sizeof(ehs::UInt_64)) + { + if (*(ehs::UInt_64*)&aBytes[i] != *(ehs::UInt_64*)&bBytes[i]) + return false; + + i += sizeof(ehs::UInt_64); + } + else if (remainder >= sizeof(ehs::UInt_32)) + { + if (*(ehs::UInt_32*)&aBytes[i] != *(ehs::UInt_32*)&bBytes[i]) + return false; + + i += sizeof(ehs::UInt_32); + } + else if (remainder >= sizeof(ehs::UInt_16)) + { + if (*(ehs::UInt_16*)&aBytes[i] != *(ehs::UInt_16*)&bBytes[i]) + return false; + + i += sizeof(ehs::UInt_16); + } + else + { + if (aBytes[i] != bBytes[i]) + return false; + + i += sizeof(ehs::Byte); + } + + remainder = size - i; + } + + return true; +} + +bool Compare(const void* const a, const void* const b, const ehs::UInt_64 size) +{ + ehs::Byte* aBytes = (ehs::Byte*)a; + ehs::Byte* bBytes = (ehs::Byte*)b; + ehs::UInt_64 remainder = size; + ehs::UInt_64 i = 0; + + while (i < size) + { + if (remainder >= sizeof(ehs::UInt_64)) + { + if (*(ehs::UInt_64*)&aBytes[i] != *(ehs::UInt_64*)&bBytes[i]) + return false; + + i += sizeof(ehs::UInt_64); + } + else if (remainder >= sizeof(ehs::UInt_32)) + { + if (*(ehs::UInt_32*)&aBytes[i] != *(ehs::UInt_32*)&bBytes[i]) + return false; + + i += sizeof(ehs::UInt_32); + } + else if (remainder >= sizeof(ehs::UInt_16)) + { + if (*(ehs::UInt_16*)&aBytes[i] != *(ehs::UInt_16*)&bBytes[i]) + return false; + + i += sizeof(ehs::UInt_16); + } + else + { + if (aBytes[i] != bBytes[i]) + return false; + + i += sizeof(ehs::Byte); + } + + remainder = size - i; + } + + return true; +} + +int main() +{ + ehs::Initialize("AVX", "Release", {1, 0, 0}); + ehs::Log::EnableImmediateMode(true); + + ehs::Console::Write_8("File Path:"); + ehs::Str_8 filePath = ehs::Console::Read_8(); + + ehs::File file(filePath, ehs::Mode::READ, ehs::Disposition::OPEN); + + ehs::Console::Write_8("\nFile Size: " + ehs::Str_8::FromNum(file.Size() / 1024 / 1024) + "MB\n"); + + ehs::Console::Write_8("Reading file..."); + + const ehs::Array data1 = file.ReadArray(file.Size()); + + ehs::Console::Write_8("Copying file data..."); + const ehs::Array data2 = data1; + file.Release(); + + ehs::Console::Write_8("Calculating TSC Frequency...\n"); + ehs::UInt_64 freq = ehs::CPU::GetTSC_Freq(); + ehs::UInt_64 start; + ehs::UInt_64 end; + + ehs::Console::Write_8("Control"); + + start = ehs::CPU::GetTSC(); + + const bool resultControl = Compare(data1, data2, data1.Size()); + + end = ehs::CPU::GetTSC(); + + ehs::Console::Write_8("Result: ", false); + if (resultControl) + ehs::Console::Write_8("Equal"); + else + ehs::Console::Write_8("Not Equal"); + + ehs::Console::Write_8("Start: " + ehs::Str_8::FromNum(start)); + ehs::Console::Write_8("End: " + ehs::Str_8::FromNum(end)); + ehs::Console::Write_8("Elapsed Time: " + ehs::Str_8::FromNum((double)(end - start) / (double)freq) + "s\n"); + + ehs::Console::Write_8("AVX2"); + if (ehs::CPU::hasAVX2) + { + start = ehs::CPU::GetTSC(); + + const bool resultAVX2 = Compare_AVX2(data1, data2, data1.Size()); + + end = ehs::CPU::GetTSC(); + + ehs::Console::Write_8("Result: ", false); + if (resultAVX2) + ehs::Console::Write_8("Equal"); + else + ehs::Console::Write_8("Not Equal"); + + ehs::Console::Write_8("Start: " + ehs::Str_8::FromNum(start)); + ehs::Console::Write_8("End: " + ehs::Str_8::FromNum(end)); + ehs::Console::Write_8("Elapsed Time: " + ehs::Str_8::FromNum((double)(end - start) / (double)freq) + "s\n"); + } + else + { + ehs::Console::Write_8("Not Supported\n"); + } + + ehs::Console::Write_8("AVX-512"); + if (ehs::CPU::hasAVX512F) + { + start = ehs::CPU::GetTSC(); + + const bool resultAVX512 = Compare_AVX512(data1, data2, data1.Size()); + + end = ehs::CPU::GetTSC(); + + ehs::Console::Write_8("Result: ", false); + if (resultAVX512) + ehs::Console::Write_8("Equal"); + else + ehs::Console::Write_8("Not Equal"); + + ehs::Console::Write_8("Start: " + ehs::Str_8::FromNum(start)); + ehs::Console::Write_8("End: " + ehs::Str_8::FromNum(end)); + ehs::Console::Write_8("Elapsed Time: " + ehs::Str_8::FromNum((double)(end - start) / (double)freq) + "s\n"); + } + else + { + ehs::Console::Write_8("Not Supported\n"); + } + + ehs::Uninitialize(); + + return 0; +} \ No newline at end of file