webrtc/net/dcsctp/packet/crc32c.cc
Victor Boivie a866228db1 dcsctp: Use third_party/crc32c for integrity check
CRC32c is used in SCTP for integrity checking, and the
third_party/crc32c library (https://github.com/google/crc32c) which has
been optimized for SSE42 and arm64 and has a much faster fallback
implementation for other architectures.

Running ./out/Release/dcsctp_benchmark
Run on (12 X 4500 MHz CPU s)
CPU Caches:
  L1 Data 32 KiB (x6)
  L1 Instruction 32 KiB (x6)
  L2 Unified 1024 KiB (x6)
  L3 Unified 8448 KiB (x1)
Load Average: 11.01, 17.53, 17.11
------------------------------------------------------------------------------
Benchmark                    Time             CPU   Iterations UserCounters...
------------------------------------------------------------------------------
BM_PumpData/1              676 ns          676 ns      1034087 bytes_per_second=1.41063M/s items_per_second=1.47916M/s
BM_PumpData/8              671 ns          671 ns      1041809 bytes_per_second=11.3643M/s items_per_second=1.48955M/s
BM_PumpData/128            725 ns          725 ns       967170 bytes_per_second=168.398M/s items_per_second=1.37952M/s
BM_PumpData/512            800 ns          800 ns       873854 bytes_per_second=610.125M/s items_per_second=1.24954M/s
BM_PumpData/1024           911 ns          911 ns       775785 bytes_per_second=1072.2M/s items_per_second=1097.93k/s
BM_PumpData/2048          1988 ns         1988 ns       352444 bytes_per_second=982.409M/s items_per_second=502.993k/s
BM_PumpData/4096          3893 ns         3893 ns       179999 bytes_per_second=1003.31M/s items_per_second=256.848k/s
BM_PumpData/8192          7477 ns         7477 ns        92790 bytes_per_second=1044.88M/s items_per_second=133.745k/s
BM_PumpData/65536        97156 ns        97153 ns         7089 bytes_per_second=643.318M/s items_per_second=10.2931k/s
BM_EchoServer/1            634 ns          634 ns      1130860 bytes_per_second=1.50512M/s items_per_second=1.57823M/s
BM_EchoServer/8            614 ns          614 ns      1136372 bytes_per_second=12.4286M/s items_per_second=1.62904M/s
BM_EchoServer/128          644 ns          644 ns      1073464 bytes_per_second=189.618M/s items_per_second=1.55335M/s
BM_EchoServer/512          734 ns          734 ns       949487 bytes_per_second=665.181M/s items_per_second=1.36229M/s
BM_EchoServer/1024         836 ns          836 ns       838010 bytes_per_second=1.14046G/s items_per_second=1.19586M/s
BM_EchoServer/2048        1939 ns         1939 ns       345067 bytes_per_second=1007.27M/s items_per_second=515.724k/s
BM_EchoServer/4096        3984 ns         3983 ns       176047 bytes_per_second=980.737M/s items_per_second=251.069k/s
BM_EchoServer/8192        7486 ns         7484 ns        95780 bytes_per_second=1043.85M/s items_per_second=133.613k/s
BM_EchoServer/65536      92360 ns        92346 ns         7821 bytes_per_second=676.805M/s items_per_second=10.8289k/s

No-Presubmit: True
Bug: webrtc:12614
Change-Id: Iff21035ee78b263ee0e4b0fe3d07eea24064b921
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/215002
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Victor Costan <pwnall@chromium.org>
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33842}
2021-04-27 10:12:44 +00:00

29 lines
953 B
C++

/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "net/dcsctp/packet/crc32c.h"
#include <cstdint>
#include "third_party/crc32c/src/include/crc32c/crc32c.h"
namespace dcsctp {
uint32_t GenerateCrc32C(rtc::ArrayView<const uint8_t> data) {
uint32_t crc32c = crc32c_value(data.data(), data.size());
// Byte swapping for little endian byte order:
uint8_t byte0 = crc32c;
uint8_t byte1 = crc32c >> 8;
uint8_t byte2 = crc32c >> 16;
uint8_t byte3 = crc32c >> 24;
crc32c = ((byte0 << 24) | (byte1 << 16) | (byte2 << 8) | byte3);
return crc32c;
}
} // namespace dcsctp