Chromium Code Reviews| Index: base/cpu_unittest.cc |
| =================================================================== |
| --- base/cpu_unittest.cc (revision 0) |
| +++ base/cpu_unittest.cc (revision 0) |
| @@ -0,0 +1,91 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/cpu.h" |
| + |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +// Tests whether we can run extended instructions represented by the CPU |
| +// information. This test actually executes some extended instructions (such as |
| +// MMX, SSE, etc.) supported by the CPU and sees we can run them without |
| +// "undefined instructions" exceptions. That is, this test succeeds when this |
| +// test finishes without crashes. |
| +TEST(CPU, RunExtendedInstructions) { |
| +#if defined(ARCH_CPU_X86_FAMILY) |
| + // Retrieve the CPU information. |
| + base::CPU cpu; |
| + |
| +#if defined(OS_WIN) |
| + if (cpu.has_mmx()) { |
|
fbarchard
2011/02/22 17:48:03
mmx is required for chromium. You could just asse
Hironori Bono
2011/02/23 09:23:31
Done. I have replaced this code with ASSERT_TRUE()
|
| + // Run an MMX instruction. |
| + __asm emms; |
| + } |
| + |
| + if (cpu.has_sse()) { |
| + // Run an SSE instruction. |
| + __asm xorps xmm0, xmm0; |
| + } |
| + |
| + if (cpu.has_sse2()) { |
| + // Run an SSE 2 instruction. |
| + __asm psrldq xmm0, 0; |
| + } |
| + |
| + if (cpu.has_sse3()) { |
| + // Run an SSE 3 instruction. |
| + __asm addsubpd xmm0, xmm0; |
| + } |
| + |
| + if (cpu.has_ssse3()) { |
| + // Run a Supplimental SSE 3 instruction. |
| + __asm psignb xmm0, xmm0; |
| + } |
| + |
| + if (cpu.has_sse41()) { |
| + // Run an SSE 4.1 instruction. |
| + __asm pmuldq xmm0, xmm0; |
| + } |
| + |
| + if (cpu.has_sse42()) { |
| + // Run an SSE 4.2 instruction. |
| + __asm crc32 eax, eax; |
| + } |
| +#elif defined(OS_POSIX) |
| + if (cpu.has_mmx()) { |
| + // Run an MMX instruction. |
| + __asm__ __volatile__("emms\n" : : : "mm0"); |
| + } |
| + |
| + if (cpu.has_sse()) { |
| + // Run an SSE instruction. |
| + __asm__ __volatile__("xorps %%xmm0, %%xmm0\n" : : : "xmm0"); |
| + } |
| + |
| + if (cpu.has_sse2()) { |
| + // Run an SSE 2 instruction. |
| + __asm__ __volatile__("psrldq $0, %%xmm0\n" : : : "xmm0"); |
| + } |
| + |
| + if (cpu.has_sse3()) { |
| + // Run an SSE 3 instruction. |
| + __asm__ __volatile__("addsubpd %%xmm0, %%xmm0\n" : : : "xmm0"); |
| + } |
| + |
| + if (cpu.has_ssse3()) { |
| + // Run a Supplimental SSE 3 instruction. |
| + __asm__ __volatile__("psignb %%xmm0, %%xmm0\n" : : : "xmm0"); |
| + } |
| + |
| + if (cpu.has_sse41()) { |
| + // Run an SSE 4.1 instruction. |
| + __asm__ __volatile__("pmuldq %%xmm0, %%xmm0\n" : : : "xmm0"); |
| + } |
| + |
| + if (cpu.has_sse42()) { |
| + // Run an SSE 4.2 instruction. |
| + __asm__ __volatile__("crc32 %%eax, %%eax\n" : : : "eax"); |
| + } |
| +#endif |
| +#endif |
| +} |
| Property changes on: base\cpu_unittest.cc |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |