mirror of
https://chromium.googlesource.com/libyuv/libyuv
synced 2026-10-29 02:17:13 +08:00
Implement RAWToRGB24Row_WASMSIMD and RAWToRGB24Row_Any_WASMSIMD in source/row_wasm.cc for RGB24ToRAW and RAWToRGB24 conversions: - Process 16 pixels (48 bytes) per loop iteration using three 128-bit loads, three byte-wise shuffles, and four 2-way blends. - Use wasm_i8x16_relaxed_swizzle when __wasm_relaxed_simd__ is enabled (compiling to a single vpshufb on x86 without bounds-checking overhead) and fall back to wasm_i8x16_swizzle for baseline SIMD128. - Add kCpuHasWASM (0x100) and kCpuHasWASMSIMD (0x101) CPU feature flags and enable -msimd128 in BUILD.bazel, BUILD.gn, and CMakeLists.txt for WebAssembly targets. Performance (RAWToRGB24_Opt, 1280x720, V8 d8): CPU WASM C SIMD128 Relaxed SIMD Spd Rlx Spd ------------------------------------------------------------------- AMD Zen 4 595.0 us 137.0 us 84.0 us 4.34x 7.08x AMD Zen 3 708.0 us 148.0 us 107.0 us 4.78x 6.62x AMD Zen 5 375.0 us 107.0 us 67.0 us 3.50x 5.60x ARM Neoverse-V2 638.0 us 118.0 us 116.0 us 5.41x 5.50x ARM Neoverse-N1 1046.0 us 294.0 us 294.0 us 3.56x 3.56x Intel Ice Lake 707.0 us 209.0 us 220.0 us 3.38x 3.21x Intel Haswell 1110.0 us 344.0 us 360.0 us 3.23x 3.08x Intel Emerald Rapids 519.0 us 207.0 us 208.0 us 2.51x 2.50x Intel Sapphire Rapids 551.0 us 220.0 us 255.0 us 2.50x 2.16x ARM Cortex-A53 14440.0 us 8660.0us 6920.0us 1.67x 2.09x Intel Granite Rapids 453.0 us 225.0 us 221.0 us 2.01x 2.05x Bug: 42271072 Test: libyuv_test --gunit_filter=*RAWToRGB24*:*RGB24ToRAW*:*Cpu* Change-Id: Id902668263a2ab70aa300eeeea18851490c917b5 Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8515581 Reviewed-by: richard winterton <rrwinterton@gmail.com> Commit-Queue: Frank Barchard <fbarchard@google.com>
590 lines
19 KiB
C++
590 lines
19 KiB
C++
/*
|
|
* Copyright 2011 The LibYuv 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 "../unit_test/unit_test.h"
|
|
|
|
#include <stdlib.h> // For getenv()
|
|
|
|
#include <cstring>
|
|
|
|
#ifdef LIBYUV_USE_ABSL_FLAGS
|
|
#include "absl/flags/flag.h"
|
|
#include "absl/flags/parse.h"
|
|
#endif
|
|
#include "libyuv/cpu_id.h"
|
|
|
|
unsigned int fastrand_seed = 0xfb;
|
|
|
|
#ifdef LIBYUV_USE_ABSL_FLAGS
|
|
ABSL_FLAG(int32_t, libyuv_width, 0, "width of test image.");
|
|
ABSL_FLAG(int32_t, libyuv_height, 0, "height of test image.");
|
|
ABSL_FLAG(int32_t, libyuv_repeat, 0, "number of times to repeat test.");
|
|
ABSL_FLAG(int32_t,
|
|
libyuv_flags,
|
|
0,
|
|
"cpu flags for reference code. 1 = C, -1 = SIMD");
|
|
ABSL_FLAG(int32_t,
|
|
libyuv_cpu_info,
|
|
0,
|
|
"cpu flags for benchmark code. 1 = C, -1 = SIMD");
|
|
#else
|
|
// Disable command line parameters if absl/flags disabled.
|
|
static const int32_t FLAGS_libyuv_width = 0;
|
|
static const int32_t FLAGS_libyuv_height = 0;
|
|
static const int32_t FLAGS_libyuv_repeat = 0;
|
|
static const int32_t FLAGS_libyuv_flags = 0;
|
|
static const int32_t FLAGS_libyuv_cpu_info = 0;
|
|
#endif
|
|
|
|
#ifdef LIBYUV_USE_ABSL_FLAGS
|
|
#define LIBYUV_GET_FLAG(f) absl::GetFlag(f)
|
|
#else
|
|
#define LIBYUV_GET_FLAG(f) f
|
|
#endif
|
|
|
|
// Test environment variable for disabling CPU features. Any non-zero value
|
|
// to disable. Zero ignored to make it easy to set the variable on/off.
|
|
#if !defined(__native_client__) && !defined(_M_ARM)
|
|
static bool TestEnv(const char* name) {
|
|
const char* var = getenv(name);
|
|
if (var) {
|
|
if (var[0] != '0') {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
#else // nacl does not support getenv().
|
|
static bool TestEnv(const char*) {
|
|
return false;
|
|
}
|
|
#endif
|
|
|
|
static int TestCpuEnv(int cpu_info) {
|
|
#if defined(__arm__) || defined(__aarch64__)
|
|
if (TestEnv("LIBYUV_DISABLE_NEON")) {
|
|
cpu_info &= ~libyuv::kCpuHasNEON;
|
|
}
|
|
#endif
|
|
#if defined(__aarch64__)
|
|
if (TestEnv("LIBYUV_DISABLE_NEON_DOTPROD")) {
|
|
cpu_info &= ~libyuv::kCpuHasNeonDotProd;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_NEON_I8MM")) {
|
|
cpu_info &= ~libyuv::kCpuHasNeonI8MM;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_SVE")) {
|
|
cpu_info &= ~libyuv::kCpuHasSVE;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_SVE2")) {
|
|
cpu_info &= ~libyuv::kCpuHasSVE2;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_SME")) {
|
|
cpu_info &= ~libyuv::kCpuHasSME;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_SME2")) {
|
|
cpu_info &= ~libyuv::kCpuHasSME2;
|
|
}
|
|
#endif
|
|
#if defined(__longarch__) && defined(__linux__)
|
|
if (TestEnv("LIBYUV_DISABLE_LSX")) {
|
|
cpu_info &= ~libyuv::kCpuHasLSX;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_LASX")) {
|
|
cpu_info &= ~libyuv::kCpuHasLASX;
|
|
}
|
|
#endif
|
|
#if defined(__riscv) && defined(__linux__)
|
|
if (TestEnv("LIBYUV_DISABLE_RVV")) {
|
|
cpu_info &= ~libyuv::kCpuHasRVV;
|
|
}
|
|
#endif
|
|
#if defined(__wasm__)
|
|
if (TestEnv("LIBYUV_DISABLE_WASM")) {
|
|
cpu_info &= ~libyuv::kCpuHasWASMSIMD;
|
|
}
|
|
#endif
|
|
#if !defined(__pnacl__) && !defined(__CLR_VER) && \
|
|
(defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || \
|
|
defined(_M_IX86))
|
|
if (TestEnv("LIBYUV_DISABLE_X86")) {
|
|
cpu_info &= ~libyuv::kCpuHasX86;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_SSE2")) {
|
|
cpu_info &= ~libyuv::kCpuHasSSE2;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_SSSE3")) {
|
|
cpu_info &= ~libyuv::kCpuHasSSSE3;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_SSE41")) {
|
|
cpu_info &= ~libyuv::kCpuHasSSE41;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_SSE42")) {
|
|
cpu_info &= ~libyuv::kCpuHasSSE42;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_AVX")) {
|
|
cpu_info &= ~libyuv::kCpuHasAVX;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_AVX2")) {
|
|
cpu_info &= ~libyuv::kCpuHasAVX2;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_ERMS")) {
|
|
cpu_info &= ~libyuv::kCpuHasERMS;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_FMA3")) {
|
|
cpu_info &= ~libyuv::kCpuHasFMA3;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_F16C")) {
|
|
cpu_info &= ~libyuv::kCpuHasF16C;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_AVX512BW")) {
|
|
cpu_info &= ~libyuv::kCpuHasAVX512BW;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_AVX512VL")) {
|
|
cpu_info &= ~libyuv::kCpuHasAVX512VL;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_AVX512VNNI")) {
|
|
cpu_info &= ~libyuv::kCpuHasAVX512VNNI;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_AVX512VBMI")) {
|
|
cpu_info &= ~libyuv::kCpuHasAVX512VBMI;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_AVX512VBMI2")) {
|
|
cpu_info &= ~libyuv::kCpuHasAVX512VBMI2;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_AVX512VBITALG")) {
|
|
cpu_info &= ~libyuv::kCpuHasAVX512VBITALG;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_AVX10")) {
|
|
cpu_info &= ~libyuv::kCpuHasAVX10;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_AVX10_2")) {
|
|
cpu_info &= ~libyuv::kCpuHasAVX10_2;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_AVXVNNI")) {
|
|
cpu_info &= ~libyuv::kCpuHasAVXVNNI;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_AVXVNNIINT8")) {
|
|
cpu_info &= ~libyuv::kCpuHasAVXVNNIINT8;
|
|
}
|
|
if (TestEnv("LIBYUV_DISABLE_AMXINT8")) {
|
|
cpu_info &= ~libyuv::kCpuHasAMXINT8;
|
|
}
|
|
#endif
|
|
if (TestEnv("LIBYUV_DISABLE_ASM")) {
|
|
cpu_info = libyuv::kCpuInitialized;
|
|
}
|
|
return cpu_info;
|
|
}
|
|
|
|
// For quicker unittests, default is 128 x 72. But when benchmarking,
|
|
// default to 720p. Allow size to specify.
|
|
// Set flags to -1 for benchmarking to avoid slower C code.
|
|
|
|
LibYUVConvertTest::LibYUVConvertTest()
|
|
: benchmark_iterations_(1),
|
|
benchmark_width_(128),
|
|
benchmark_height_(72),
|
|
disable_cpu_flags_(1),
|
|
benchmark_cpu_info_(-1) {
|
|
const char* repeat = getenv("LIBYUV_REPEAT");
|
|
if (repeat) {
|
|
benchmark_iterations_ = atoi(repeat); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) {
|
|
benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat);
|
|
}
|
|
if (benchmark_iterations_ > 1) {
|
|
benchmark_width_ = 1280;
|
|
benchmark_height_ = 720;
|
|
}
|
|
const char* width = getenv("LIBYUV_WIDTH");
|
|
if (width) {
|
|
benchmark_width_ = atoi(width); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) {
|
|
benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width);
|
|
}
|
|
const char* height = getenv("LIBYUV_HEIGHT");
|
|
if (height) {
|
|
benchmark_height_ = atoi(height); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) {
|
|
benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height);
|
|
}
|
|
const char* cpu_flags = getenv("LIBYUV_FLAGS");
|
|
if (cpu_flags) {
|
|
disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) {
|
|
disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags);
|
|
}
|
|
const char* cpu_info = getenv("LIBYUV_CPU_INFO");
|
|
if (cpu_info) {
|
|
benchmark_cpu_info_ = atoi(cpu_info); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) {
|
|
benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info);
|
|
}
|
|
disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
|
|
benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
|
|
libyuv::MaskCpuFlags(benchmark_cpu_info_);
|
|
benchmark_pixels_div1280_ =
|
|
static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
|
|
static_cast<double>(Abs(benchmark_height_)) *
|
|
static_cast<double>(benchmark_iterations_) +
|
|
1279.0) /
|
|
1280.0);
|
|
}
|
|
|
|
LibYUVColorTest::LibYUVColorTest()
|
|
: benchmark_iterations_(1),
|
|
benchmark_width_(128),
|
|
benchmark_height_(72),
|
|
disable_cpu_flags_(1),
|
|
benchmark_cpu_info_(-1) {
|
|
const char* repeat = getenv("LIBYUV_REPEAT");
|
|
if (repeat) {
|
|
benchmark_iterations_ = atoi(repeat); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) {
|
|
benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat);
|
|
}
|
|
if (benchmark_iterations_ > 1) {
|
|
benchmark_width_ = 1280;
|
|
benchmark_height_ = 720;
|
|
}
|
|
const char* width = getenv("LIBYUV_WIDTH");
|
|
if (width) {
|
|
benchmark_width_ = atoi(width); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) {
|
|
benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width);
|
|
}
|
|
const char* height = getenv("LIBYUV_HEIGHT");
|
|
if (height) {
|
|
benchmark_height_ = atoi(height); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) {
|
|
benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height);
|
|
}
|
|
const char* cpu_flags = getenv("LIBYUV_FLAGS");
|
|
if (cpu_flags) {
|
|
disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) {
|
|
disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags);
|
|
}
|
|
const char* cpu_info = getenv("LIBYUV_CPU_INFO");
|
|
if (cpu_info) {
|
|
benchmark_cpu_info_ = atoi(cpu_info); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) {
|
|
benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info);
|
|
}
|
|
disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
|
|
benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
|
|
libyuv::MaskCpuFlags(benchmark_cpu_info_);
|
|
benchmark_pixels_div1280_ =
|
|
static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
|
|
static_cast<double>(Abs(benchmark_height_)) *
|
|
static_cast<double>(benchmark_iterations_) +
|
|
1279.0) /
|
|
1280.0);
|
|
}
|
|
|
|
LibYUVScaleTest::LibYUVScaleTest()
|
|
: benchmark_iterations_(1),
|
|
benchmark_width_(128),
|
|
benchmark_height_(72),
|
|
disable_cpu_flags_(1),
|
|
benchmark_cpu_info_(-1) {
|
|
const char* repeat = getenv("LIBYUV_REPEAT");
|
|
if (repeat) {
|
|
benchmark_iterations_ = atoi(repeat); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) {
|
|
benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat);
|
|
}
|
|
if (benchmark_iterations_ > 1) {
|
|
benchmark_width_ = 1280;
|
|
benchmark_height_ = 720;
|
|
}
|
|
const char* width = getenv("LIBYUV_WIDTH");
|
|
if (width) {
|
|
benchmark_width_ = atoi(width); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) {
|
|
benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width);
|
|
}
|
|
const char* height = getenv("LIBYUV_HEIGHT");
|
|
if (height) {
|
|
benchmark_height_ = atoi(height); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) {
|
|
benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height);
|
|
}
|
|
const char* cpu_flags = getenv("LIBYUV_FLAGS");
|
|
if (cpu_flags) {
|
|
disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) {
|
|
disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags);
|
|
}
|
|
const char* cpu_info = getenv("LIBYUV_CPU_INFO");
|
|
if (cpu_info) {
|
|
benchmark_cpu_info_ = atoi(cpu_info); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) {
|
|
benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info);
|
|
}
|
|
disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
|
|
benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
|
|
libyuv::MaskCpuFlags(benchmark_cpu_info_);
|
|
benchmark_pixels_div1280_ =
|
|
static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
|
|
static_cast<double>(Abs(benchmark_height_)) *
|
|
static_cast<double>(benchmark_iterations_) +
|
|
1279.0) /
|
|
1280.0);
|
|
}
|
|
|
|
LibYUVRotateTest::LibYUVRotateTest()
|
|
: benchmark_iterations_(1),
|
|
benchmark_width_(128),
|
|
benchmark_height_(72),
|
|
disable_cpu_flags_(1),
|
|
benchmark_cpu_info_(-1) {
|
|
const char* repeat = getenv("LIBYUV_REPEAT");
|
|
if (repeat) {
|
|
benchmark_iterations_ = atoi(repeat); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) {
|
|
benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat);
|
|
}
|
|
if (benchmark_iterations_ > 1) {
|
|
benchmark_width_ = 1280;
|
|
benchmark_height_ = 720;
|
|
}
|
|
const char* width = getenv("LIBYUV_WIDTH");
|
|
if (width) {
|
|
benchmark_width_ = atoi(width); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) {
|
|
benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width);
|
|
}
|
|
const char* height = getenv("LIBYUV_HEIGHT");
|
|
if (height) {
|
|
benchmark_height_ = atoi(height); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) {
|
|
benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height);
|
|
}
|
|
const char* cpu_flags = getenv("LIBYUV_FLAGS");
|
|
if (cpu_flags) {
|
|
disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) {
|
|
disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags);
|
|
}
|
|
const char* cpu_info = getenv("LIBYUV_CPU_INFO");
|
|
if (cpu_info) {
|
|
benchmark_cpu_info_ = atoi(cpu_info); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) {
|
|
benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info);
|
|
}
|
|
disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
|
|
benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
|
|
libyuv::MaskCpuFlags(benchmark_cpu_info_);
|
|
benchmark_pixels_div1280_ =
|
|
static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
|
|
static_cast<double>(Abs(benchmark_height_)) *
|
|
static_cast<double>(benchmark_iterations_) +
|
|
1279.0) /
|
|
1280.0);
|
|
}
|
|
|
|
LibYUVPlanarTest::LibYUVPlanarTest()
|
|
: benchmark_iterations_(1),
|
|
benchmark_width_(128),
|
|
benchmark_height_(72),
|
|
disable_cpu_flags_(1),
|
|
benchmark_cpu_info_(-1) {
|
|
const char* repeat = getenv("LIBYUV_REPEAT");
|
|
if (repeat) {
|
|
benchmark_iterations_ = atoi(repeat); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) {
|
|
benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat);
|
|
}
|
|
if (benchmark_iterations_ > 1) {
|
|
benchmark_width_ = 1280;
|
|
benchmark_height_ = 720;
|
|
}
|
|
const char* width = getenv("LIBYUV_WIDTH");
|
|
if (width) {
|
|
benchmark_width_ = atoi(width); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) {
|
|
benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width);
|
|
}
|
|
const char* height = getenv("LIBYUV_HEIGHT");
|
|
if (height) {
|
|
benchmark_height_ = atoi(height); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) {
|
|
benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height);
|
|
}
|
|
const char* cpu_flags = getenv("LIBYUV_FLAGS");
|
|
if (cpu_flags) {
|
|
disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) {
|
|
disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags);
|
|
}
|
|
const char* cpu_info = getenv("LIBYUV_CPU_INFO");
|
|
if (cpu_info) {
|
|
benchmark_cpu_info_ = atoi(cpu_info); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) {
|
|
benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info);
|
|
}
|
|
disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
|
|
benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
|
|
libyuv::MaskCpuFlags(benchmark_cpu_info_);
|
|
benchmark_pixels_div1280_ =
|
|
static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
|
|
static_cast<double>(Abs(benchmark_height_)) *
|
|
static_cast<double>(benchmark_iterations_) +
|
|
1279.0) /
|
|
1280.0);
|
|
}
|
|
|
|
LibYUVBaseTest::LibYUVBaseTest()
|
|
: benchmark_iterations_(1),
|
|
benchmark_width_(128),
|
|
benchmark_height_(72),
|
|
disable_cpu_flags_(1),
|
|
benchmark_cpu_info_(-1) {
|
|
const char* repeat = getenv("LIBYUV_REPEAT");
|
|
if (repeat) {
|
|
benchmark_iterations_ = atoi(repeat); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) {
|
|
benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat);
|
|
}
|
|
if (benchmark_iterations_ > 1) {
|
|
benchmark_width_ = 1280;
|
|
benchmark_height_ = 720;
|
|
}
|
|
const char* width = getenv("LIBYUV_WIDTH");
|
|
if (width) {
|
|
benchmark_width_ = atoi(width); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) {
|
|
benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width);
|
|
}
|
|
const char* height = getenv("LIBYUV_HEIGHT");
|
|
if (height) {
|
|
benchmark_height_ = atoi(height); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) {
|
|
benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height);
|
|
}
|
|
const char* cpu_flags = getenv("LIBYUV_FLAGS");
|
|
if (cpu_flags) {
|
|
disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) {
|
|
disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags);
|
|
}
|
|
const char* cpu_info = getenv("LIBYUV_CPU_INFO");
|
|
if (cpu_info) {
|
|
benchmark_cpu_info_ = atoi(cpu_info); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) {
|
|
benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info);
|
|
}
|
|
disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
|
|
benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
|
|
libyuv::MaskCpuFlags(benchmark_cpu_info_);
|
|
benchmark_pixels_div1280_ =
|
|
static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
|
|
static_cast<double>(Abs(benchmark_height_)) *
|
|
static_cast<double>(benchmark_iterations_) +
|
|
1279.0) /
|
|
1280.0);
|
|
}
|
|
|
|
LibYUVCompareTest::LibYUVCompareTest()
|
|
: benchmark_iterations_(1),
|
|
benchmark_width_(128),
|
|
benchmark_height_(72),
|
|
disable_cpu_flags_(1),
|
|
benchmark_cpu_info_(-1) {
|
|
const char* repeat = getenv("LIBYUV_REPEAT");
|
|
if (repeat) {
|
|
benchmark_iterations_ = atoi(repeat); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_repeat)) {
|
|
benchmark_iterations_ = LIBYUV_GET_FLAG(FLAGS_libyuv_repeat);
|
|
}
|
|
if (benchmark_iterations_ > 1) {
|
|
benchmark_width_ = 1280;
|
|
benchmark_height_ = 720;
|
|
}
|
|
const char* width = getenv("LIBYUV_WIDTH");
|
|
if (width) {
|
|
benchmark_width_ = atoi(width); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_width)) {
|
|
benchmark_width_ = LIBYUV_GET_FLAG(FLAGS_libyuv_width);
|
|
}
|
|
const char* height = getenv("LIBYUV_HEIGHT");
|
|
if (height) {
|
|
benchmark_height_ = atoi(height); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_height)) {
|
|
benchmark_height_ = LIBYUV_GET_FLAG(FLAGS_libyuv_height);
|
|
}
|
|
const char* cpu_flags = getenv("LIBYUV_FLAGS");
|
|
if (cpu_flags) {
|
|
disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_flags)) {
|
|
disable_cpu_flags_ = LIBYUV_GET_FLAG(FLAGS_libyuv_flags);
|
|
}
|
|
const char* cpu_info = getenv("LIBYUV_CPU_INFO");
|
|
if (cpu_info) {
|
|
benchmark_cpu_info_ = atoi(cpu_info); // NOLINT
|
|
}
|
|
if (LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info)) {
|
|
benchmark_cpu_info_ = LIBYUV_GET_FLAG(FLAGS_libyuv_cpu_info);
|
|
}
|
|
disable_cpu_flags_ = TestCpuEnv(disable_cpu_flags_);
|
|
benchmark_cpu_info_ = TestCpuEnv(benchmark_cpu_info_);
|
|
libyuv::MaskCpuFlags(benchmark_cpu_info_);
|
|
benchmark_pixels_div1280_ =
|
|
static_cast<int>((static_cast<double>(Abs(benchmark_width_)) *
|
|
static_cast<double>(Abs(benchmark_height_)) *
|
|
static_cast<double>(benchmark_iterations_) +
|
|
1279.0) /
|
|
1280.0);
|
|
}
|
|
|
|
int main(int argc, char** argv) {
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
#ifdef LIBYUV_USE_ABSL_FLAGS
|
|
absl::ParseCommandLine(argc, argv);
|
|
#endif
|
|
return RUN_ALL_TESTS();
|
|
}
|