Skip to content

Commit

Permalink
Merge pull request #568 from ckormanyos/bench_crypt_hasher
Browse files Browse the repository at this point in the history
Bench crypt hasher
  • Loading branch information
ckormanyos authored Oct 26, 2024
2 parents f5ea4d8 + 2897d9e commit a54a398
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 13 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/real-time-cpp-benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ jobs:
- name: clone-cppalliance-decimal
run: |
git clone -b develop --depth 1 https://github.com/cppalliance/decimal.git ../cppalliance-decimal-root
- name: clone-cppalliance-crypt
run: |
git clone -b develop --depth 1 https://github.com/cppalliance/crypt.git ../cppalliance-crypt-root
working-directory: ./
- name: benchmark_gcc-clang
run: ./target/build/test_app_benchmarks.sh ${{ matrix.compiler }} ${{ matrix.standard }}
Expand Down Expand Up @@ -104,7 +107,7 @@ jobs:
strategy:
fail-fast: false
matrix:
standard: [ c++14, c++17, c++2a ]
standard: [ c++14, c++20 ]
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -125,6 +128,9 @@ jobs:
- name: clone-cppalliance-decimal
run: |
git clone -b develop --depth 1 https://github.com/cppalliance/decimal.git ../cppalliance-decimal-root
- name: clone-cppalliance-crypt
run: |
git clone -b develop --depth 1 https://github.com/cppalliance/crypt.git ../cppalliance-crypt-root
working-directory: ./
- name: benchmark_builds-stm32f446
run: ./target/build/test_app_benchmarks_stm32f446.sh ${{ matrix.standard }}
Expand Down
1 change: 1 addition & 0 deletions ref_app/ref_app.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\app\benchmark\app_benchmark.cpp" />
<ClCompile Include="src\app\benchmark\app_benchmark_boost_crypt_hasher.cpp" />
<ClCompile Include="src\app\benchmark\app_benchmark_boost_math_cbrt_tgamma.cpp" />
<ClCompile Include="src\app\benchmark\app_benchmark_boost_math_cyl_bessel_j.cpp" />
<ClCompile Include="src\app\benchmark\app_benchmark_boost_multiprecision_cbrt.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions ref_app/ref_app.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,9 @@
<ClCompile Include="src\mcal\rpi_pico2_rp2350\mcal_cpu_rp2350.cpp">
<Filter>src\mcal\rpi_pico2_rp2350</Filter>
</ClCompile>
<ClCompile Include="src\app\benchmark\app_benchmark_boost_crypt_hasher.cpp">
<Filter>src\app\benchmark</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\math\calculus\derivative.h">
Expand Down
4 changes: 4 additions & 0 deletions ref_app/src/app/benchmark/app_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ auto app::benchmark::task_func() -> void

const bool result_is_ok = app::benchmark::run_non_std_decimal();

#elif (defined(APP_BENCHMARK_TYPE) && (APP_BENCHMARK_TYPE == APP_BENCHMARK_TYPE_BOOST_CRYPT_HASHER))

const bool result_is_ok = app::benchmark::run_boost_crypt_hasher();

#endif

// Set the benchmark port pin level to low.
Expand Down
4 changes: 4 additions & 0 deletions ref_app/src/app/benchmark/app_benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#define APP_BENCHMARK_TYPE_ECC_GENERIC_ECC 20
#define APP_BENCHMARK_TYPE_NON_STD_DECIMAL 21
#define APP_BENCHMARK_TYPE_PI_AGM_100 22
#define APP_BENCHMARK_TYPE_BOOST_CRYPT_HASHER 23

//#define APP_BENCHMARK_TYPE APP_BENCHMARK_TYPE_NONE
//#define APP_BENCHMARK_TYPE APP_BENCHMARK_TYPE_COMPLEX
Expand All @@ -55,6 +56,7 @@
//#define APP_BENCHMARK_TYPE APP_BENCHMARK_TYPE_ECC_GENERIC_ECC
//#define APP_BENCHMARK_TYPE APP_BENCHMARK_TYPE_NON_STD_DECIMAL
//#define APP_BENCHMARK_TYPE APP_BENCHMARK_TYPE_PI_AGM_100
//#define APP_BENCHMARK_TYPE APP_BENCHMARK_TYPE_BOOST_CRYPT_HASHER

#if !defined(APP_BENCHMARK_TYPE)
#define APP_BENCHMARK_TYPE APP_BENCHMARK_TYPE_NONE
Expand Down Expand Up @@ -106,6 +108,8 @@
auto run_ecc_generic_ecc() -> bool;
#elif (defined(APP_BENCHMARK_TYPE) && (APP_BENCHMARK_TYPE == APP_BENCHMARK_TYPE_NON_STD_DECIMAL))
auto run_non_std_decimal() -> bool;
#elif (defined(APP_BENCHMARK_TYPE) && (APP_BENCHMARK_TYPE == APP_BENCHMARK_TYPE_BOOST_CRYPT_HASHER))
auto run_boost_crypt_hasher() -> bool;
#else
#error APP_BENCHMARK_TYPE is undefined.
#endif
Expand Down
117 changes: 117 additions & 0 deletions ref_app/src/app/benchmark/app_benchmark_boost_crypt_hasher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2024.
// Distributed under the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#include <cstdint>

#include <app/benchmark/app_benchmark.h>

#if (defined(APP_BENCHMARK_TYPE) && (APP_BENCHMARK_TYPE == APP_BENCHMARK_TYPE_BOOST_CRYPT_HASHER))

#if !defined(BOOST_CRYPT_STANDALONE)
#define BOOST_CRYPT_STANDALONE
#endif

#if !defined(BOOST_CRYPT_DISABLE_IOSTREAM)
#define BOOST_CRYPT_DISABLE_IOSTREAM
#endif

#if !defined(BOOST_CRYPT_NO_EXCEPTIONS)
#define BOOST_CRYPT_NO_EXCEPTIONS
#endif

#include <boost/crypt/hash/sha512.hpp>

auto app::benchmark::run_boost_crypt_hasher() -> bool
{
// "abc"
const std::array<std::uint8_t, 3U> message =
{{
0x61U, 0x62U, 0x63U
}};

using local_hasher_type = boost::crypt::sha512_hasher;
using local_result_type = typename local_hasher_type::return_type;

constexpr local_result_type control =
{{
0xDDU, 0xAFU, 0x35U, 0xA1U, 0x93U, 0x61U, 0x7AU, 0xBAU,
0xCCU, 0x41U, 0x73U, 0x49U, 0xAEU, 0x20U, 0x41U, 0x31U,
0x12U, 0xE6U, 0xFAU, 0x4EU, 0x89U, 0xA9U, 0x7EU, 0xA2U,
0x0AU, 0x9EU, 0xEEU, 0xE6U, 0x4BU, 0x55U, 0xD3U, 0x9AU,
0x21U, 0x92U, 0x99U, 0x2AU, 0x27U, 0x4FU, 0xC1U, 0xA8U,
0x36U, 0xBAU, 0x3CU, 0x23U, 0xA3U, 0xFEU, 0xEBU, 0xBDU,
0x45U, 0x4DU, 0x44U, 0x23U, 0x64U, 0x3CU, 0xE8U, 0x0EU,
0x2AU, 0x9AU, 0xC9U, 0x4FU, 0xA5U, 0x4CU, 0xA4U, 0x9FU,
}};

local_hasher_type my_hasher { };

my_hasher.init();

my_hasher.process_bytes(message.data(), message.size());

const local_result_type result { my_hasher.get_digest() };

const bool result_is_ok { result == control };

return result_is_ok;
}

#if defined(APP_BENCHMARK_STANDALONE_MAIN)
constexpr auto app_benchmark_standalone_foodcafe = static_cast<std::uint32_t>(UINT32_C(0xF00DCAFE));

extern "C"
{
extern volatile std::uint32_t app_benchmark_standalone_result;

auto app_benchmark_run_standalone (void) -> bool;
auto app_benchmark_get_standalone_result(void) -> bool;

auto app_benchmark_run_standalone(void) -> bool
{
auto result_is_ok = true;

for(unsigned i = 0U; i < 64U; ++i)
{
result_is_ok &= app::benchmark::run_boost_crypt_hasher();
}

app_benchmark_standalone_result =
static_cast<std::uint32_t>
(
result_is_ok ? app_benchmark_standalone_foodcafe : static_cast<std::uint32_t>(UINT32_C(0xFFFFFFFF))
);

return result_is_ok;
}

auto app_benchmark_get_standalone_result(void) -> bool
{
volatile auto result_is_ok =
(app_benchmark_standalone_result == static_cast<std::uint32_t>(UINT32_C(0xF00DCAFE)));

return result_is_ok;
}
}

int main()
{
auto result_is_ok = true;

result_is_ok = (::app_benchmark_run_standalone () && result_is_ok);
result_is_ok = (::app_benchmark_get_standalone_result() && result_is_ok);

return (result_is_ok ? 0 : -1);
}

extern "C"
{
volatile std::uint32_t app_benchmark_standalone_result;
}
#endif // APP_BENCHMARK_STANDALONE_MAIN

#endif // APP_BENCHMARK_TYPE_CRC
19 changes: 11 additions & 8 deletions ref_app/src/mcal/mcal_gpt_arm_sys_tick.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
)
);

const auto sys_tick_value = my_sys_tick_value;
const value_type sys_tick_value { my_sys_tick_value };

// Do the second read of the sys-tick counter and the sys-tick
// value. Handle reverse counting for sys-tick counter, which is
Expand All @@ -143,13 +143,16 @@

// Perform the consistency check.

const auto sys_tick_consistent_value =
static_cast<std::uint64_t>
(
((sys_tick_counter_2 >= sys_tick_counter_1)
? static_cast<std::uint64_t>(static_cast<std::uint64_t>( sys_tick_value) | sys_tick_counter_1)
: static_cast<std::uint64_t>(static_cast<std::uint64_t>(my_sys_tick_value) | sys_tick_counter_2))
);
const std::uint64_t
sys_tick_consistent_value
{
static_cast<std::uint64_t>
(
((sys_tick_counter_2 >= sys_tick_counter_1)
? static_cast<std::uint64_t>(static_cast<std::uint64_t>( sys_tick_value) | sys_tick_counter_1)
: static_cast<std::uint64_t>(static_cast<std::uint64_t>(my_sys_tick_value) | sys_tick_counter_2))
)
};

// Perform scaling and include a rounding correction.
return
Expand Down
1 change: 1 addition & 0 deletions ref_app/target/app/make/app_files.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# ------------------------------------------------------------------------------

FILES_CPP = $(PATH_APP)/app/benchmark/app_benchmark \
$(PATH_APP)/app/benchmark/app_benchmark_boost_crypt_hasher \
$(PATH_APP)/app/benchmark/app_benchmark_boost_math_cbrt_tgamma \
$(PATH_APP)/app/benchmark/app_benchmark_boost_math_cyl_bessel_j \
$(PATH_APP)/app/benchmark/app_benchmark_boost_multiprecision_cbrt \
Expand Down
9 changes: 7 additions & 2 deletions ref_app/target/build/test_app_benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ if [[ "$GCC" == "g++" ]]; then
$GCC -std=$STD -Wall -Werror -O2 -m64 -I./src/mcal/host -I./src -DAPP_BENCHMARK_TYPE=APP_BENCHMARK_TYPE_ECC_GENERIC_ECC -DAPP_BENCHMARK_STANDALONE_MAIN ./src/app/benchmark/app_benchmark_ecc_generic_ecc.cpp -o ./bin/app_benchmark_ecc_generic_ecc.exe
fi
$GCC -std=$STD -Wall -O2 -m64 -I./src/mcal/host -I./src -I../../cppalliance-decimal-root/include -I../../boost-root -DAPP_BENCHMARK_TYPE=APP_BENCHMARK_TYPE_NON_STD_DECIMAL -DAPP_BENCHMARK_STANDALONE_MAIN ./src/app/benchmark/app_benchmark_non_std_decimal.cpp -o ./bin/app_benchmark_non_std_decimal.exe
$GCC -std=$STD -Wall -O2 -m64 -I./src/mcal/host -I./src -I../../cppalliance-crypt-root/include -I../../boost-root -DAPP_BENCHMARK_TYPE=APP_BENCHMARK_TYPE_BOOST_CRYPT_HASHER -DAPP_BENCHMARK_STANDALONE_MAIN ./src/app/benchmark/app_benchmark_boost_crypt_hasher.cpp -o ./bin/app_benchmark_boost_crypt_hasher.exe

./bin/app_benchmark_complex.exe
result_var_complex=$?
Expand Down Expand Up @@ -113,6 +114,9 @@ fi
./bin/app_benchmark_non_std_decimal.exe
result_var_non_std_decimal=$?

./bin/app_benchmark_boost_crypt_hasher.exe
result_var_boost_crypt_hasher=$?

echo "result_var_complex : " "$result_var_complex"
echo "result_var_crc : " "$result_var_crc"
echo "result_var_fast_math : " "$result_var_fast_math"
Expand All @@ -136,11 +140,12 @@ if [[ "$GCC" == "g++" ]]; then
echo "result_var_ecc_generic_ecc : " "$result_var_ecc_generic_ecc"
fi
echo "result_var_non_std_decimal : " "$result_var_non_std_decimal"
echo "result_var_boost_crypt_hasher : " "$result_var_boost_crypt_hasher"

if [[ "$GCC" == "g++" ]]; then
result_total=$((result_var_complex+result_var_crc+result_var_fast_math+result_var_filter+result_var_fixed_point+result_var_float+result_var_hash+result_var_none+result_var_pi_agm+result_var_pi_spigot+result_var_pi_spigot_single+$result_var_soft_double_h2f1+result_var_trapezoid_integral+result_var_wide_decimal+result_var_wide_integer+result_var_boost_math_cbrt_tgamma+result_var_boost_math_cyl_bessel_j+result_var_boost_multiprecision_cbrt+result_var_hash_sha256+result_var_ecc_generic_ecc+result_var_non_std_decimal))
result_total=$((result_var_complex+result_var_crc+result_var_fast_math+result_var_filter+result_var_fixed_point+result_var_float+result_var_hash+result_var_none+result_var_pi_agm+result_var_pi_spigot+result_var_pi_spigot_single+$result_var_soft_double_h2f1+result_var_trapezoid_integral+result_var_wide_decimal+result_var_wide_integer+result_var_boost_math_cbrt_tgamma+result_var_boost_math_cyl_bessel_j+result_var_boost_multiprecision_cbrt+result_var_hash_sha256+result_var_ecc_generic_ecc+result_var_non_std_decimal+result_ls_boost_crypt_hasher))
else
result_total=$((result_var_complex+result_var_crc+result_var_fast_math+result_var_filter+result_var_fixed_point+result_var_float+result_var_hash+result_var_none+result_var_pi_agm+result_var_pi_spigot+result_var_pi_spigot_single+$result_var_soft_double_h2f1+result_var_trapezoid_integral+result_var_wide_decimal+result_var_wide_integer+result_var_boost_math_cbrt_tgamma+result_var_boost_math_cyl_bessel_j+result_var_boost_multiprecision_cbrt+result_var_hash_sha256+result_var_non_std_decimal))
result_total=$((result_var_complex+result_var_crc+result_var_fast_math+result_var_filter+result_var_fixed_point+result_var_float+result_var_hash+result_var_none+result_var_pi_agm+result_var_pi_spigot+result_var_pi_spigot_single+$result_var_soft_double_h2f1+result_var_trapezoid_integral+result_var_wide_decimal+result_var_wide_integer+result_var_boost_math_cbrt_tgamma+result_var_boost_math_cyl_bessel_j+result_var_boost_multiprecision_cbrt+result_var_hash_sha256+result_var_non_std_decimal+result_ls_boost_crypt_hasher))
fi

echo "result_total : " "$result_total"
Expand Down
Loading

0 comments on commit a54a398

Please sign in to comment.