Skip to content

Commit

Permalink
Enable the use of [SU]Int32Size and EnumSize templates for AArch64 (#…
Browse files Browse the repository at this point in the history
…11102)

Hi,

When benchmarking proto_benchmark from fleetbench on an AArch64 target we found that clang is able to vectorize these functions and they offer better performance than the scalar alternative.

I ran //src/google/protobuf:arena_unittest on aarch64-none-linux-gnu. Should I run any other tests? Also protobuf used to have its own set of benchmarks, but I can't find these when I query all targets with bazel. Let me know if you'd like me to run anything else, I couldn't find instructions on what the full test run is.

Closes #11102

COPYBARA_INTEGRATE_REVIEW=#11102 from avieira-arm:main 5552410
PiperOrigin-RevId: 532779004
  • Loading branch information
avieira-arm authored and copybara-github committed May 17, 2023
1 parent 1010f91 commit e285d3e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/google/protobuf/wire_format_lite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ static size_t VarintSize(const T* data, const int n) {
} else if (SignExtended) {
msb_sum += x >> 31;
}
// clang is so smart that it produces optimal SSE sequence unrolling
// clang is so smart that it produces optimal SIMD sequence unrolling
// the loop 8 ints at a time. With a sequence of 4
// cmpres = cmpgt x, sizeclass ( -1 or 0)
// sum = sum - cmpres
Expand Down Expand Up @@ -712,7 +712,7 @@ static size_t VarintSize64(const T* data, const int n) {
// and other platforms are untested, in those cases using the optimized
// varint size routine for each element is faster.
// Hence we enable it only for clang
#if defined(__SSE__) && defined(__clang__)
#if (defined(__SSE__) || defined(__aarch64__)) && defined(__clang__)
size_t WireFormatLite::Int32Size(const RepeatedField<int32_t>& value) {
return VarintSize<false, true>(value.data(), value.size());
}
Expand All @@ -730,7 +730,7 @@ size_t WireFormatLite::EnumSize(const RepeatedField<int>& value) {
return VarintSize<false, true>(value.data(), value.size());
}

#else // !(defined(__SSE4_1__) && defined(__clang__))
#else // !((defined(__SSE__) || defined(__aarch64__) && defined(__clang__))

size_t WireFormatLite::Int32Size(const RepeatedField<int32_t>& value) {
size_t out = 0;
Expand Down

0 comments on commit e285d3e

Please sign in to comment.