Chromium Code Reviews| Index: src/base/cpu.cc |
| diff --git a/src/base/cpu.cc b/src/base/cpu.cc |
| index fbfbcf683b74e3014257cfe749e96eabdf2203cf..0a737a66d488e090e611f40440f64e001708123b 100644 |
| --- a/src/base/cpu.cc |
| +++ b/src/base/cpu.cc |
| @@ -119,13 +119,18 @@ static uint32_t ReadELFHWCaps() { |
| int __detect_fp64_mode(void) { |
| double result = 0; |
| // Bit representation of (double)1 is 0x3FF0000000000000. |
| - asm( |
| - "lui $t0, 0x3FF0\n\t" |
| - "ldc1 $f0, %0\n\t" |
| - "mtc1 $t0, $f1\n\t" |
| - "sdc1 $f0, %0\n\t" |
| - : "+m" (result) |
| - : : "t0", "$f0", "$f1", "memory"); |
| + __asm__ volatile( |
| + ".set push\n\t" |
| + ".set noreorder\n\t" |
| + ".set oddspreg\n\t" |
| + "lui $t0, 0x3FF0\n\t" |
| + "ldc1 $f0, %0\n\t" |
| + "mtc1 $t0, $f1\n\t" |
| + "sdc1 $f0, %0\n\t" |
| + ".set pop\n\t" |
| + : "+m"(result) |
| + : |
| + : "t0", "$f0", "$f1", "memory"); |
| return !(result == 1); |
| } |
| @@ -133,9 +138,33 @@ int __detect_fp64_mode(void) { |
| int __detect_mips_arch_revision(void) { |
| // TODO(dusmil): Do the specific syscall as soon as it is implemented in mips |
| - // kernel. Currently fail-back to the least common denominator which is |
| - // mips32 revision 1. |
| - return 1; |
| + // kernel. |
| + // Detect r6 architectures through QNaN representation. |
| + // The r6 variant uses IEEE2008 QNaN representation which is 7ff8xxxxxxxxxxxx, |
| + // the same encoding for QNaN on x86, ARM. |
| + // Non r6 variants uses 7ff7fxxxxxxxxxxx for QNaN which is SNaN on x86, ARM. |
| + double result = 0; |
| + uint64_t check, mask = 0x8000000000000LLU; |
| + union { |
| + double d; |
| + uint64_t ull; |
| + } conv; |
| + |
| + __asm__ volatile( |
| + ".set push\n\t" |
| + ".set noreorder\n\t" |
| + "ldc1 $f0, %0\n\t" |
| + "div.d $f0, $f0, $f0\n\t" |
| + "sdc1 $f0, %0\n\t" |
| + ".set pop\n\t" |
| + : "+m"(result) |
| + : |
| + : "$f0", "memory"); |
| + conv.d = result; |
| + // Check bit 50 of NaN value. |
| + // Fail-back to the least common denominator which is mips32 revision 1. |
|
paul.l...
2014/10/02 16:26:47
nit: this should probably be "fall-back"
dusmil.imgtec
2014/10/02 17:02:09
Done.
|
| + check = conv.ull & mask; |
| + return check ? 6 : 1; |
| } |
| #endif |