media/libyuv/unit_test/cpu_test.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libyuv/unit_test/cpu_test.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,108 @@
     1.4 +/*
     1.5 + *  Copyright 2012 The LibYuv Project Authors. All rights reserved.
     1.6 + *
     1.7 + *  Use of this source code is governed by a BSD-style license
     1.8 + *  that can be found in the LICENSE file in the root of the source
     1.9 + *  tree. An additional intellectual property rights grant can be found
    1.10 + *  in the file PATENTS. All contributing project authors may
    1.11 + *  be found in the AUTHORS file in the root of the source tree.
    1.12 + */
    1.13 +
    1.14 +#include <stdlib.h>
    1.15 +#include <string.h>
    1.16 +
    1.17 +#include "libyuv/basic_types.h"
    1.18 +#include "libyuv/cpu_id.h"
    1.19 +#include "libyuv/version.h"
    1.20 +#include "../unit_test/unit_test.h"
    1.21 +
    1.22 +namespace libyuv {
    1.23 +
    1.24 +TEST_F(libyuvTest, TestCpuHas) {
    1.25 +  int cpu_flags = TestCpuFlag(-1);
    1.26 +  printf("Cpu Flags %x\n", cpu_flags);
    1.27 +  int has_arm = TestCpuFlag(kCpuHasARM);
    1.28 +  printf("Has ARM %x\n", has_arm);
    1.29 +  int has_neon = TestCpuFlag(kCpuHasNEON);
    1.30 +  printf("Has NEON %x\n", has_neon);
    1.31 +  int has_x86 = TestCpuFlag(kCpuHasX86);
    1.32 +  printf("Has X86 %x\n", has_x86);
    1.33 +  int has_sse2 = TestCpuFlag(kCpuHasSSE2);
    1.34 +  printf("Has SSE2 %x\n", has_sse2);
    1.35 +  int has_ssse3 = TestCpuFlag(kCpuHasSSSE3);
    1.36 +  printf("Has SSSE3 %x\n", has_ssse3);
    1.37 +  int has_sse41 = TestCpuFlag(kCpuHasSSE41);
    1.38 +  printf("Has SSE4.1 %x\n", has_sse41);
    1.39 +  int has_sse42 = TestCpuFlag(kCpuHasSSE42);
    1.40 +  printf("Has SSE4.2 %x\n", has_sse42);
    1.41 +  int has_avx = TestCpuFlag(kCpuHasAVX);
    1.42 +  printf("Has AVX %x\n", has_avx);
    1.43 +  int has_avx2 = TestCpuFlag(kCpuHasAVX2);
    1.44 +  printf("Has AVX2 %x\n", has_avx2);
    1.45 +  int has_erms = TestCpuFlag(kCpuHasERMS);
    1.46 +  printf("Has ERMS %x\n", has_erms);
    1.47 +  int has_fma3 = TestCpuFlag(kCpuHasFMA3);
    1.48 +  printf("Has FMA3 %x\n", has_fma3);
    1.49 +  int has_mips = TestCpuFlag(kCpuHasMIPS);
    1.50 +  printf("Has MIPS %x\n", has_mips);
    1.51 +  int has_mips_dsp = TestCpuFlag(kCpuHasMIPS_DSP);
    1.52 +  printf("Has MIPS DSP %x\n", has_mips_dsp);
    1.53 +  int has_mips_dspr2 = TestCpuFlag(kCpuHasMIPS_DSPR2);
    1.54 +  printf("Has MIPS DSPR2 %x\n", has_mips_dspr2);
    1.55 +}
    1.56 +
    1.57 +#if defined(__i386__) || defined(__x86_64__) || \
    1.58 +    defined(_M_IX86) || defined(_M_X64)
    1.59 +TEST_F(libyuvTest, TestCpuId) {
    1.60 +  int has_x86 = TestCpuFlag(kCpuHasX86);
    1.61 +  if (has_x86) {
    1.62 +    uint32 cpu_info[4];
    1.63 +    // Vendor ID:
    1.64 +    // AuthenticAMD AMD processor
    1.65 +    // CentaurHauls Centaur processor
    1.66 +    // CyrixInstead Cyrix processor
    1.67 +    // GenuineIntel Intel processor
    1.68 +    // GenuineTMx86 Transmeta processor
    1.69 +    // Geode by NSC National Semiconductor processor
    1.70 +    // NexGenDriven NexGen processor
    1.71 +    // RiseRiseRise Rise Technology processor
    1.72 +    // SiS SiS SiS  SiS processor
    1.73 +    // UMC UMC UMC  UMC processor
    1.74 +    CpuId(0, 0, cpu_info);
    1.75 +    cpu_info[0] = cpu_info[1];  // Reorder output
    1.76 +    cpu_info[1] = cpu_info[3];
    1.77 +    cpu_info[3] = 0;
    1.78 +    printf("Cpu Vendor: %s %x %x %x\n", reinterpret_cast<char*>(&cpu_info[0]),
    1.79 +           cpu_info[0], cpu_info[1], cpu_info[2]);
    1.80 +    EXPECT_EQ(12, strlen(reinterpret_cast<char*>(&cpu_info[0])));
    1.81 +
    1.82 +    // CPU Family and Model
    1.83 +    // 3:0 - Stepping
    1.84 +    // 7:4 - Model
    1.85 +    // 11:8 - Family
    1.86 +    // 13:12 - Processor Type
    1.87 +    // 19:16 - Extended Model
    1.88 +    // 27:20 - Extended Family
    1.89 +    CpuId(1, 0, cpu_info);
    1.90 +    int family = ((cpu_info[0] >> 8) & 0x0f) | ((cpu_info[0] >> 16) & 0xff0);
    1.91 +    int model = ((cpu_info[0] >> 4) & 0x0f) | ((cpu_info[0] >> 12) & 0xf0);
    1.92 +    printf("Cpu Family %d (0x%x), Model %d (0x%x)\n", family, family,
    1.93 +           model, model);
    1.94 +  }
    1.95 +}
    1.96 +#endif
    1.97 +
    1.98 +TEST_F(libyuvTest, TestLinuxNeon) {
    1.99 +  int testdata = ArmCpuCaps("unit_test/testdata/arm_v7.txt");
   1.100 +  if (testdata) {
   1.101 +    EXPECT_EQ(0, ArmCpuCaps("unit_test/testdata/arm_v7.txt"));
   1.102 +    EXPECT_EQ(kCpuHasNEON, ArmCpuCaps("unit_test/testdata/tegra3.txt"));
   1.103 +  } else {
   1.104 +    printf("WARNING: unable to load \"unit_test/testdata/arm_v7.txt\"\n");
   1.105 +  }
   1.106 +#if defined(__linux__) && defined(__ARM_NEON__)
   1.107 +  EXPECT_NE(0, ArmCpuCaps("/proc/cpuinfo"));
   1.108 +#endif
   1.109 +}
   1.110 +
   1.111 +}  // namespace libyuv

mercurial