Skip to content

Commit

Permalink
Added ./example & improved Simd usage
Browse files Browse the repository at this point in the history
  • Loading branch information
WillisMedwell committed Feb 12, 2024
1 parent 6a7b188 commit f6d9d6e
Show file tree
Hide file tree
Showing 15 changed files with 648 additions and 1,898 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

- name: Build With GCC
run: |
cmake --preset gcc-ninja -DCMAKE_BUILD_TYPE=Release
cmake --preset gcc-ninja -DCMAKE_BUILD_TYPE=Release
cmake --build ./build/gcc-ninja --target UtilyTest --config Debug
cmake --build ./build/gcc-ninja --target UtilyBenchmark --config Release
Expand Down
21 changes: 11 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if(DEFINED EMSCRIPTEN)
message(STATUS "For Emscripten SIMD use flags: \"-msimd128 -mrelaxed-simd -msse -msse2 -msse3 -msse4.1\"")
elseif(NOT MSVC)
target_compile_options(Utily_Utily PRIVATE "-Wall" "-Wextra" "-Wpedantic" "-Wcast-align" "-Wcast-qual" "-Wctor-dtor-privacy" "-Wformat=2" "-Winit-self" "-Wmissing-declarations" "-Wmissing-include-dirs" "-Wold-style-cast" "-Woverloaded-virtual" "-Wredundant-decls" "-Wshadow" "-Wsign-conversion" "-Wsign-promo" "-Wstrict-overflow=5" "-Wundef" "-Wno-unused" "-Wconversion" "-Wsign-compare")
message(STATUS "For Native SIMD use flags: \"-mtune=native\"")
message(STATUS "For Native SIMD use flags: \"-march=native\"")
endif()

set_property(TARGET Utily_Utily PROPERTY EXPORT_NAME Utily)
Expand Down Expand Up @@ -57,12 +57,9 @@ if(BUILD_UTILY_TESTS)
set(CMAKE_EXECUTABLE_SUFFIX ".html")
elseif(NOT MSVC)
target_compile_options(UtilyTest PRIVATE "-Wall" "-Wextra" "-Wpedantic" "-Wcast-align" "-Wcast-qual" "-Wctor-dtor-privacy" "-Wformat=2" "-Winit-self" "-Wmissing-declarations" "-Wmissing-include-dirs" "-Wold-style-cast" "-Woverloaded-virtual" "-Wredundant-decls" "-Wshadow" "-Wsign-conversion" "-Wsign-promo" "-Wstrict-overflow=5" "-Wundef" "-Wno-unused" "-Wconversion" "-Wsign-compare")
# target_compile_options(UtilyTest PRIVATE -msse -msse2 -msse3 -msse4.1 -mavx512f -mavx512bw)
# target_link_options(UtilyTest PRIVATE -msse -msse2 -msse3 -msse4.1 -mavx512f -mavx512bw)
target_compile_options(UtilyTest PRIVATE -mtune=native)
target_link_options(UtilyTest PRIVATE -mtune=native)
target_compile_options(UtilyTest PRIVATE -march=native)
target_link_options(UtilyTest PRIVATE -march=native)


if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(UtilyTest PRIVATE -Wuseless-cast)
endif()
Expand Down Expand Up @@ -109,18 +106,22 @@ if(BUILD_UTILY_BENCHMARKS)
target_compile_options(UtilyBenchmark PRIVATE -msimd128 -mrelaxed-simd -msse -msse2 -msse3 -msse4.1)
elseif(NOT MSVC)
target_compile_options(UtilyBenchmark PRIVATE "-Wall" "-Wextra" "-Wpedantic" "-Wcast-align" "-Wcast-qual" "-Wctor-dtor-privacy" "-Wformat=2" "-Winit-self" "-Wmissing-declarations" "-Wmissing-include-dirs" "-Wold-style-cast" "-Woverloaded-virtual" "-Wredundant-decls" "-Wshadow" "-Wsign-conversion" "-Wsign-promo" "-Wstrict-overflow=5" "-Wswitch-default" "-Wundef" "-Wno-unused" "-Wconversion" "-Wsign-compare")
# target_compile_options(UtilyBenchmark PRIVATE -msse -msse2 -msse3 -msse4.1 -mavx512f -mavx512bw)
# target_link_options(UtilyBenchmark PRIVATE -msse -msse2 -msse3 -msse4.1 -mavx512f -mavx512bw)
target_compile_options(UtilyTest PRIVATE -mtune=native)
target_link_options(UtilyTest PRIVATE -mtune=native)
target_compile_options(UtilyBenchmark PRIVATE -march=native)
target_link_options(UtilyBenchmark PRIVATE -march=native)
target_compile_options(UtilyBenchmark PRIVATE
$<$<CONFIG:Release>:-O3 -DNDEBUG>
)

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(UtilyBenchmark PRIVATE -Wuseless-cast)
endif()
else()

endif()
target_link_libraries(UtilyBenchmark PRIVATE benchmark::benchmark benchmark::benchmark_main Utily::Utily)
endif()

# Example Setup
if(BUILD_UTILY_EXAMPLES)
add_subdirectory(example)
endif()
3 changes: 3 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"CMAKE_BUILD_TYPE": "Release",
"BUILD_UTILY_TESTS": "ON",
"BUILD_UTILY_BENCHMARKS": "ON",
"BUILD_UTILY_EXAMPLES": "ON",
"HAVE_STEADY_CLOCK": "0",
"HAVE_POSIX_REGEX": "0",
"HAVE_STD_REGEX": "0",
Expand All @@ -33,6 +34,7 @@
"cacheVariables": {
"BUILD_UTILY_TESTS": "ON",
"BUILD_UTILY_BENCHMARKS": "ON",
"BUILD_UTILY_EXAMPLES": "ON",
"HAVE_STEADY_CLOCK": "0",
"HAVE_POSIX_REGEX": "0",
"HAVE_STD_REGEX": "0",
Expand All @@ -52,6 +54,7 @@
"CMAKE_BUILD_TYPE": "Release",
"BUILD_UTILY_TESTS": "ON",
"BUILD_UTILY_BENCHMARKS": "ON",
"BUILD_UTILY_EXAMPLES": "ON",
"HAVE_STEADY_CLOCK": "0",
"HAVE_POSIX_REGEX": "0",
"HAVE_STD_REGEX": "0",
Expand Down
50 changes: 6 additions & 44 deletions benchmark/BenchSimd.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
#include "Utily/Utily.hpp"

#include "Utily/Simd128.hpp"
#include "Utily/Simd512.hpp"

#include <benchmark/benchmark.h>

#include <algorithm>
#include <array>
#include <numeric>
#include <ranges>

#ifndef EMSCRIPTEN
extern "C" {
#include "stringzilla.h"
}
#endif

#if 1

auto all_a(size_t max) -> std::string {
Expand Down Expand Up @@ -49,17 +46,6 @@ static void BM_Uty_find_char_512(benchmark::State& state) {
}
BENCHMARK(BM_Uty_find_char_512);

#ifndef EMSCRIPTEN
static void BM_Zil_find_char(benchmark::State& state) {
auto delim = 'z';
for (auto _ : state) {
volatile auto iter = sz_find_1char(LONG_STRING.data(), LONG_STRING.size(), &delim);
benchmark::DoNotOptimize(iter);
}
}
BENCHMARK(BM_Zil_find_char);
#endif

static void BM_Std_find_char(benchmark::State& state) {
for (auto _ : state) {
volatile auto iter = std::find(LONG_STRING.begin(), LONG_STRING.end(), 'z');
Expand All @@ -71,7 +57,9 @@ BENCHMARK(BM_Std_find_char);
static void BM_Uty_find_first_of_char(benchmark::State& state) {
const auto data = std::to_array({ 'z', 'o', 'n' });
for (auto _ : state) {
volatile auto iter = Utily::Simd128::Char::find_first_of(LONG_STRING.data(), LONG_STRING.size(), data.data(), data.size());
// Alternate, less performant version.
// volatile auto iter = Utily::Simd128::Char::find_first_of(LONG_STRING.data(), LONG_STRING.size(), data.data(), data.size());
volatile auto iter = Utily::Simd128::Char::find_first_of<3>(LONG_STRING.data(), LONG_STRING.size(), data.data());
benchmark::DoNotOptimize(iter);
}
}
Expand Down Expand Up @@ -112,21 +100,6 @@ static void BM_Uty_search_char_4letters_512(benchmark::State& state) {
}
BENCHMARK(BM_Uty_search_char_4letters_512);

#ifndef EMSCRIPTEN
static void BM_Zil_search_char_4letters(benchmark::State& state) {
std::string_view find = "stri";
for (auto _ : state) {
volatile auto iter = sz_find_substring(
LONG_STRING.data(),
LONG_STRING.size(),
find.data(),
find.size());
benchmark::DoNotOptimize(iter);
}
}
BENCHMARK(BM_Zil_search_char_4letters);
#endif

static void BM_Std_search_char_4letters(benchmark::State& state) {
std::string_view find = "stri";
for (auto _ : state) {
Expand All @@ -153,17 +126,6 @@ static void BM_Uty_search_char_8letters(benchmark::State& state) {
}
BENCHMARK(BM_Uty_search_char_8letters);

#ifndef EMSCRIPTEN
static void BM_Zil_search_char_8letters(benchmark::State& state) {
std::string_view find = "stringer";
for (auto _ : state) {
auto index = sz_find_substring(LONG_STRING.data(), LONG_STRING.size(), find.data(), find.size());
benchmark::DoNotOptimize(index);
}
}
BENCHMARK(BM_Zil_search_char_8letters);
#endif

static void BM_Std_search_char_8letters(benchmark::State& state) {
std::string_view find = "stringer";
for (auto _ : state) {
Expand Down
Loading

0 comments on commit f6d9d6e

Please sign in to comment.