123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542 |
- /*
- * 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_GFLAGS
- #include "gflags/gflags.h"
- #endif
- #ifdef LIBYUV_USE_BASE_FLAGS
- #include "base/commandlineflags.h"
- #endif
- #include "libyuv/cpu_id.h"
- unsigned int fastrand_seed = 0xfb;
- #ifdef LIBYUV_USE_GFLAGS
- DEFINE_int32(libyuv_width, 0, "width of test image.");
- DEFINE_int32(libyuv_height, 0, "height of test image.");
- DEFINE_int32(libyuv_repeat, 0, "number of times to repeat test.");
- DEFINE_int32(libyuv_flags, 0, "cpu flags for reference code. 1 = C, -1 = SIMD");
- DEFINE_int32(libyuv_cpu_info,
- 0,
- "cpu flags for benchmark code. 1 = C, -1 = SIMD");
- #else
- // Disable command line parameters if gflags 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
- // 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 LIBYUV_BOOL TestEnv(const char* name) {
- const char* var = getenv(name);
- if (var) {
- if (var[0] != '0') {
- return LIBYUV_TRUE;
- }
- }
- return LIBYUV_FALSE;
- }
- #else // nacl does not support getenv().
- static LIBYUV_BOOL TestEnv(const char*) {
- return LIBYUV_FALSE;
- }
- #endif
- int TestCpuEnv(int cpu_info) {
- #if defined(__arm__) || defined(__aarch64__)
- if (TestEnv("LIBYUV_DISABLE_NEON")) {
- cpu_info &= ~libyuv::kCpuHasNEON;
- }
- #endif
- #if defined(__mips__) && defined(__linux__)
- if (TestEnv("LIBYUV_DISABLE_MSA")) {
- cpu_info &= ~libyuv::kCpuHasMSA;
- }
- if (TestEnv("LIBYUV_DISABLE_MMI")) {
- cpu_info &= ~libyuv::kCpuHasMMI;
- }
- #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_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_AVX512VPOPCNTDQ")) {
- cpu_info &= ~libyuv::kCpuHasAVX512VPOPCNTDQ;
- }
- if (TestEnv("LIBYUV_DISABLE_GFNI")) {
- cpu_info &= ~libyuv::kCpuHasGFNI;
- }
- #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 (FLAGS_libyuv_repeat) {
- benchmark_iterations_ = 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 (FLAGS_libyuv_width) {
- benchmark_width_ = FLAGS_libyuv_width;
- }
- const char* height = getenv("LIBYUV_HEIGHT");
- if (height) {
- benchmark_height_ = atoi(height); // NOLINT
- }
- if (FLAGS_libyuv_height) {
- benchmark_height_ = FLAGS_libyuv_height;
- }
- const char* cpu_flags = getenv("LIBYUV_FLAGS");
- if (cpu_flags) {
- disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
- }
- if (FLAGS_libyuv_flags) {
- disable_cpu_flags_ = FLAGS_libyuv_flags;
- }
- const char* cpu_info = getenv("LIBYUV_CPU_INFO");
- if (cpu_info) {
- benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT
- }
- if (FLAGS_libyuv_cpu_info) {
- benchmark_cpu_info_ = 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 (FLAGS_libyuv_repeat) {
- benchmark_iterations_ = 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 (FLAGS_libyuv_width) {
- benchmark_width_ = FLAGS_libyuv_width;
- }
- const char* height = getenv("LIBYUV_HEIGHT");
- if (height) {
- benchmark_height_ = atoi(height); // NOLINT
- }
- if (FLAGS_libyuv_height) {
- benchmark_height_ = FLAGS_libyuv_height;
- }
- const char* cpu_flags = getenv("LIBYUV_FLAGS");
- if (cpu_flags) {
- disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
- }
- if (FLAGS_libyuv_flags) {
- disable_cpu_flags_ = FLAGS_libyuv_flags;
- }
- const char* cpu_info = getenv("LIBYUV_CPU_INFO");
- if (cpu_info) {
- benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT
- }
- if (FLAGS_libyuv_cpu_info) {
- benchmark_cpu_info_ = 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 (FLAGS_libyuv_repeat) {
- benchmark_iterations_ = 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 (FLAGS_libyuv_width) {
- benchmark_width_ = FLAGS_libyuv_width;
- }
- const char* height = getenv("LIBYUV_HEIGHT");
- if (height) {
- benchmark_height_ = atoi(height); // NOLINT
- }
- if (FLAGS_libyuv_height) {
- benchmark_height_ = FLAGS_libyuv_height;
- }
- const char* cpu_flags = getenv("LIBYUV_FLAGS");
- if (cpu_flags) {
- disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
- }
- if (FLAGS_libyuv_flags) {
- disable_cpu_flags_ = FLAGS_libyuv_flags;
- }
- const char* cpu_info = getenv("LIBYUV_CPU_INFO");
- if (cpu_info) {
- benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT
- }
- if (FLAGS_libyuv_cpu_info) {
- benchmark_cpu_info_ = 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 (FLAGS_libyuv_repeat) {
- benchmark_iterations_ = 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 (FLAGS_libyuv_width) {
- benchmark_width_ = FLAGS_libyuv_width;
- }
- const char* height = getenv("LIBYUV_HEIGHT");
- if (height) {
- benchmark_height_ = atoi(height); // NOLINT
- }
- if (FLAGS_libyuv_height) {
- benchmark_height_ = FLAGS_libyuv_height;
- }
- const char* cpu_flags = getenv("LIBYUV_FLAGS");
- if (cpu_flags) {
- disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
- }
- if (FLAGS_libyuv_flags) {
- disable_cpu_flags_ = FLAGS_libyuv_flags;
- }
- const char* cpu_info = getenv("LIBYUV_CPU_INFO");
- if (cpu_info) {
- benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT
- }
- if (FLAGS_libyuv_cpu_info) {
- benchmark_cpu_info_ = 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 (FLAGS_libyuv_repeat) {
- benchmark_iterations_ = 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 (FLAGS_libyuv_width) {
- benchmark_width_ = FLAGS_libyuv_width;
- }
- const char* height = getenv("LIBYUV_HEIGHT");
- if (height) {
- benchmark_height_ = atoi(height); // NOLINT
- }
- if (FLAGS_libyuv_height) {
- benchmark_height_ = FLAGS_libyuv_height;
- }
- const char* cpu_flags = getenv("LIBYUV_FLAGS");
- if (cpu_flags) {
- disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
- }
- if (FLAGS_libyuv_flags) {
- disable_cpu_flags_ = FLAGS_libyuv_flags;
- }
- const char* cpu_info = getenv("LIBYUV_CPU_INFO");
- if (cpu_info) {
- benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT
- }
- if (FLAGS_libyuv_cpu_info) {
- benchmark_cpu_info_ = 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 (FLAGS_libyuv_repeat) {
- benchmark_iterations_ = 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 (FLAGS_libyuv_width) {
- benchmark_width_ = FLAGS_libyuv_width;
- }
- const char* height = getenv("LIBYUV_HEIGHT");
- if (height) {
- benchmark_height_ = atoi(height); // NOLINT
- }
- if (FLAGS_libyuv_height) {
- benchmark_height_ = FLAGS_libyuv_height;
- }
- const char* cpu_flags = getenv("LIBYUV_FLAGS");
- if (cpu_flags) {
- disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
- }
- if (FLAGS_libyuv_flags) {
- disable_cpu_flags_ = FLAGS_libyuv_flags;
- }
- const char* cpu_info = getenv("LIBYUV_CPU_INFO");
- if (cpu_info) {
- benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT
- }
- if (FLAGS_libyuv_cpu_info) {
- benchmark_cpu_info_ = 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 (FLAGS_libyuv_repeat) {
- benchmark_iterations_ = 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 (FLAGS_libyuv_width) {
- benchmark_width_ = FLAGS_libyuv_width;
- }
- const char* height = getenv("LIBYUV_HEIGHT");
- if (height) {
- benchmark_height_ = atoi(height); // NOLINT
- }
- if (FLAGS_libyuv_height) {
- benchmark_height_ = FLAGS_libyuv_height;
- }
- const char* cpu_flags = getenv("LIBYUV_FLAGS");
- if (cpu_flags) {
- disable_cpu_flags_ = atoi(cpu_flags); // NOLINT
- }
- if (FLAGS_libyuv_flags) {
- disable_cpu_flags_ = FLAGS_libyuv_flags;
- }
- const char* cpu_info = getenv("LIBYUV_CPU_INFO");
- if (cpu_info) {
- benchmark_cpu_info_ = atoi(cpu_flags); // NOLINT
- }
- if (FLAGS_libyuv_cpu_info) {
- benchmark_cpu_info_ = 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_GFLAGS
- // AllowCommandLineParsing allows us to ignore flags passed on to us by
- // Chromium build bots without having to explicitly disable them.
- google::AllowCommandLineReparsing();
- google::ParseCommandLineFlags(&argc, &argv, true);
- #endif
- return RUN_ALL_TESTS();
- }
|