Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2012 The LibYuv Project Authors. All rights reserved. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license |
michael@0 | 5 | * that can be found in the LICENSE file in the root of the source |
michael@0 | 6 | * tree. An additional intellectual property rights grant can be found |
michael@0 | 7 | * in the file PATENTS. All contributing project authors may |
michael@0 | 8 | * be found in the AUTHORS file in the root of the source tree. |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #include <stdlib.h> |
michael@0 | 12 | #include <string.h> |
michael@0 | 13 | |
michael@0 | 14 | #include "libyuv/basic_types.h" |
michael@0 | 15 | #include "libyuv/cpu_id.h" |
michael@0 | 16 | #include "libyuv/version.h" |
michael@0 | 17 | #include "../unit_test/unit_test.h" |
michael@0 | 18 | |
michael@0 | 19 | namespace libyuv { |
michael@0 | 20 | |
michael@0 | 21 | TEST_F(libyuvTest, TestCpuHas) { |
michael@0 | 22 | int cpu_flags = TestCpuFlag(-1); |
michael@0 | 23 | printf("Cpu Flags %x\n", cpu_flags); |
michael@0 | 24 | int has_arm = TestCpuFlag(kCpuHasARM); |
michael@0 | 25 | printf("Has ARM %x\n", has_arm); |
michael@0 | 26 | int has_neon = TestCpuFlag(kCpuHasNEON); |
michael@0 | 27 | printf("Has NEON %x\n", has_neon); |
michael@0 | 28 | int has_x86 = TestCpuFlag(kCpuHasX86); |
michael@0 | 29 | printf("Has X86 %x\n", has_x86); |
michael@0 | 30 | int has_sse2 = TestCpuFlag(kCpuHasSSE2); |
michael@0 | 31 | printf("Has SSE2 %x\n", has_sse2); |
michael@0 | 32 | int has_ssse3 = TestCpuFlag(kCpuHasSSSE3); |
michael@0 | 33 | printf("Has SSSE3 %x\n", has_ssse3); |
michael@0 | 34 | int has_sse41 = TestCpuFlag(kCpuHasSSE41); |
michael@0 | 35 | printf("Has SSE4.1 %x\n", has_sse41); |
michael@0 | 36 | int has_sse42 = TestCpuFlag(kCpuHasSSE42); |
michael@0 | 37 | printf("Has SSE4.2 %x\n", has_sse42); |
michael@0 | 38 | int has_avx = TestCpuFlag(kCpuHasAVX); |
michael@0 | 39 | printf("Has AVX %x\n", has_avx); |
michael@0 | 40 | int has_avx2 = TestCpuFlag(kCpuHasAVX2); |
michael@0 | 41 | printf("Has AVX2 %x\n", has_avx2); |
michael@0 | 42 | int has_erms = TestCpuFlag(kCpuHasERMS); |
michael@0 | 43 | printf("Has ERMS %x\n", has_erms); |
michael@0 | 44 | int has_fma3 = TestCpuFlag(kCpuHasFMA3); |
michael@0 | 45 | printf("Has FMA3 %x\n", has_fma3); |
michael@0 | 46 | int has_mips = TestCpuFlag(kCpuHasMIPS); |
michael@0 | 47 | printf("Has MIPS %x\n", has_mips); |
michael@0 | 48 | int has_mips_dsp = TestCpuFlag(kCpuHasMIPS_DSP); |
michael@0 | 49 | printf("Has MIPS DSP %x\n", has_mips_dsp); |
michael@0 | 50 | int has_mips_dspr2 = TestCpuFlag(kCpuHasMIPS_DSPR2); |
michael@0 | 51 | printf("Has MIPS DSPR2 %x\n", has_mips_dspr2); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | #if defined(__i386__) || defined(__x86_64__) || \ |
michael@0 | 55 | defined(_M_IX86) || defined(_M_X64) |
michael@0 | 56 | TEST_F(libyuvTest, TestCpuId) { |
michael@0 | 57 | int has_x86 = TestCpuFlag(kCpuHasX86); |
michael@0 | 58 | if (has_x86) { |
michael@0 | 59 | uint32 cpu_info[4]; |
michael@0 | 60 | // Vendor ID: |
michael@0 | 61 | // AuthenticAMD AMD processor |
michael@0 | 62 | // CentaurHauls Centaur processor |
michael@0 | 63 | // CyrixInstead Cyrix processor |
michael@0 | 64 | // GenuineIntel Intel processor |
michael@0 | 65 | // GenuineTMx86 Transmeta processor |
michael@0 | 66 | // Geode by NSC National Semiconductor processor |
michael@0 | 67 | // NexGenDriven NexGen processor |
michael@0 | 68 | // RiseRiseRise Rise Technology processor |
michael@0 | 69 | // SiS SiS SiS SiS processor |
michael@0 | 70 | // UMC UMC UMC UMC processor |
michael@0 | 71 | CpuId(0, 0, cpu_info); |
michael@0 | 72 | cpu_info[0] = cpu_info[1]; // Reorder output |
michael@0 | 73 | cpu_info[1] = cpu_info[3]; |
michael@0 | 74 | cpu_info[3] = 0; |
michael@0 | 75 | printf("Cpu Vendor: %s %x %x %x\n", reinterpret_cast<char*>(&cpu_info[0]), |
michael@0 | 76 | cpu_info[0], cpu_info[1], cpu_info[2]); |
michael@0 | 77 | EXPECT_EQ(12, strlen(reinterpret_cast<char*>(&cpu_info[0]))); |
michael@0 | 78 | |
michael@0 | 79 | // CPU Family and Model |
michael@0 | 80 | // 3:0 - Stepping |
michael@0 | 81 | // 7:4 - Model |
michael@0 | 82 | // 11:8 - Family |
michael@0 | 83 | // 13:12 - Processor Type |
michael@0 | 84 | // 19:16 - Extended Model |
michael@0 | 85 | // 27:20 - Extended Family |
michael@0 | 86 | CpuId(1, 0, cpu_info); |
michael@0 | 87 | int family = ((cpu_info[0] >> 8) & 0x0f) | ((cpu_info[0] >> 16) & 0xff0); |
michael@0 | 88 | int model = ((cpu_info[0] >> 4) & 0x0f) | ((cpu_info[0] >> 12) & 0xf0); |
michael@0 | 89 | printf("Cpu Family %d (0x%x), Model %d (0x%x)\n", family, family, |
michael@0 | 90 | model, model); |
michael@0 | 91 | } |
michael@0 | 92 | } |
michael@0 | 93 | #endif |
michael@0 | 94 | |
michael@0 | 95 | TEST_F(libyuvTest, TestLinuxNeon) { |
michael@0 | 96 | int testdata = ArmCpuCaps("unit_test/testdata/arm_v7.txt"); |
michael@0 | 97 | if (testdata) { |
michael@0 | 98 | EXPECT_EQ(0, ArmCpuCaps("unit_test/testdata/arm_v7.txt")); |
michael@0 | 99 | EXPECT_EQ(kCpuHasNEON, ArmCpuCaps("unit_test/testdata/tegra3.txt")); |
michael@0 | 100 | } else { |
michael@0 | 101 | printf("WARNING: unable to load \"unit_test/testdata/arm_v7.txt\"\n"); |
michael@0 | 102 | } |
michael@0 | 103 | #if defined(__linux__) && defined(__ARM_NEON__) |
michael@0 | 104 | EXPECT_NE(0, ArmCpuCaps("/proc/cpuinfo")); |
michael@0 | 105 | #endif |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | } // namespace libyuv |