Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ add_benchmark(sample src/sample.cpp)
add_benchmark(search src/search.cpp)
add_benchmark(search_n src/search_n.cpp)
add_benchmark(shuffle src/shuffle.cpp)
add_benchmark(signed128_mul src/signed128_mul.cpp)
add_benchmark(std_copy src/std_copy.cpp)
add_benchmark(sv_equal src/sv_equal.cpp)
add_benchmark(swap_ranges src/swap_ranges.cpp)
Expand Down
75 changes: 75 additions & 0 deletions benchmarks/src/signed128_mul.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <benchmark/benchmark.h>

#include <__msvc_int128.hpp>
#include <array>
#include <cstdint>
#include <random>
#include <utility>
#include <vector>

using namespace std;

_NODISCARD constexpr _Signed128 old_mul128(_Signed128 _Left, _Signed128 _Right) {
bool _negative = false;
_Left._Strip_negative(_negative);
_Right._Strip_negative(_negative);
_Signed128 _Result{_Base128::_Multiply(_Left, _Right)};
if (_negative) {
_Result = -_Result;
}
return _Result;
}

vector<pair<_Signed128, _Signed128>> init_test_set() {
vector<pair<_Signed128, _Signed128>> vec(1'000'000);
mt19937_64 mt64{};
for (auto& [val1, val2] : vec) {
val1._Word[0] = mt64();
val1._Word[1] = mt64();
val2._Word[0] = mt64();
val2._Word[1] = mt64();
}
return vec;
}

void bm_signed128_mul(benchmark::State& state) {
const auto vec = init_test_set();

auto it = vec.begin();
_Signed128 res = 0;

for (auto _ : state) {
res = it->first * it->second;

benchmark::DoNotOptimize(res);
++it;
if (it == vec.end()) {
it = vec.begin();
}
}
}

void bm_signed128_oldmul(benchmark::State& state) {
const auto vec = init_test_set();

auto it = vec.begin();
_Signed128 res = 0;

for (auto _ : state) {
res = old_mul128(it->first, it->second);

benchmark::DoNotOptimize(res);
++it;
if (it == vec.end()) {
it = vec.begin();
}
}
}

BENCHMARK(bm_signed128_mul);
BENCHMARK(bm_signed128_oldmul);

BENCHMARK_MAIN();
9 changes: 1 addition & 8 deletions stl/inc/__msvc_int128.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1370,14 +1370,7 @@ struct _Signed128 : _Base128 {
}

_NODISCARD friend constexpr _Signed128 operator*(_Signed128 _Left, _Signed128 _Right) noexcept {
bool _Negative = false;
_Left._Strip_negative(_Negative);
_Right._Strip_negative(_Negative);
_Signed128 _Result{_Base128::_Multiply(_Left, _Right)};
if (_Negative) {
_Result = -_Result;
}
return _Result;
return _Signed128{_Base128::_Multiply(_Left, _Right)};
}

_TEMPLATE_CLASS_INTEGRAL(_Ty)
Expand Down