From 3758fceca935f3307e2301984399497388574a70 Mon Sep 17 00:00:00 2001 From: "dusan.milosavljevic@imgtec.com" Date: Thu, 9 Oct 2014 09:39:23 +0000 Subject: [PATCH] MIPS: Improve runtime detection and compatibility wrt arch. revisions. TEST= BUG= R=jkummerow@chromium.org, paul.lind@imgtec.com Review URL: https://codereview.chromium.org/618193005 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24486 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- build/toolchain.gypi | 24 +++++++++++++++--------- src/base/cpu.cc | 38 ++++++++++++++++++++++++++++---------- src/mips/constants-mips.h | 2 +- 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/build/toolchain.gypi b/build/toolchain.gypi index c3a9a1b..20c2c94 100644 --- a/build/toolchain.gypi +++ b/build/toolchain.gypi @@ -302,7 +302,7 @@ 'cflags': ['-mfp32'], }], ['mips_arch_variant=="r6"', { - 'cflags!': ['-mfp32'], + 'cflags!': ['-mfp32', '-mfpxx'], 'cflags': ['-mips32r6', '-Wa,-mips32r6'], 'ldflags': [ '-mips32r6', @@ -312,14 +312,17 @@ }], ['mips_arch_variant=="r2"', { 'cflags': ['-mips32r2', '-Wa,-mips32r2'], + 'ldflags': ['-mips32r2'], }], ['mips_arch_variant=="r1"', { - 'cflags!': ['-mfp64'], + 'cflags!': ['-mfp64', '-mfpxx'], 'cflags': ['-mips32', '-Wa,-mips32'], + 'ldflags': ['-mips32'], }], ['mips_arch_variant=="rx"', { - 'cflags!': ['-mfp64'], - 'cflags': ['-mips32', '-Wa,-mips32'], + 'cflags!': ['-mfp64', '-mfp32'], + 'cflags': ['-mips32', '-Wa,-mips32', '-mfpxx'], + 'ldflags': ['-mips32'], }], ], }], @@ -400,7 +403,7 @@ 'cflags': ['-mfp32'], }], ['mips_arch_variant=="r6"', { - 'cflags!': ['-mfp32'], + 'cflags!': ['-mfp32', '-mfpxx'], 'cflags': ['-mips32r6', '-Wa,-mips32r6'], 'ldflags': [ '-mips32r6', @@ -410,17 +413,20 @@ }], ['mips_arch_variant=="r2"', { 'cflags': ['-mips32r2', '-Wa,-mips32r2'], + 'ldflags': ['-mips32r2'], }], ['mips_arch_variant=="r1"', { - 'cflags!': ['-mfp64'], + 'cflags!': ['-mfp64', '-mfpxx'], 'cflags': ['-mips32', '-Wa,-mips32'], + 'ldflags': ['-mips32'], }], ['mips_arch_variant=="rx"', { - 'cflags!': ['-mfp64'], - 'cflags': ['-mips32', '-Wa,-mips32'], + 'cflags!': ['-mfp64', '-mfp32'], + 'cflags': ['-mips32', '-Wa,-mips32', '-mfpxx'], + 'ldflags': ['-mips32'], }], ['mips_arch_variant=="loongson"', { - 'cflags!': ['-mfp64'], + 'cflags!': ['-mfp64', '-mfp32', '-mfpxx'], 'cflags': ['-mips3', '-Wa,-mips3'], }], ], diff --git a/src/base/cpu.cc b/src/base/cpu.cc index 2ef6893..9d0715a 100644 --- a/src/base/cpu.cc +++ b/src/base/cpu.cc @@ -121,13 +121,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); } @@ -135,9 +140,22 @@ 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. + uint32_t result = 0; + __asm__ volatile( + "move $v0, $zero\n\t" + // Encoding for "addi $v0, $v0, 1" on non-r6, + // which is encoding for "bovc $v0, %v0, 1" on r6. + // Use machine code directly to avoid compilation errors with different + // toolchains and maintain compatibility. + ".word 0x20420001\n\t" + "sw $v0, %0\n\t" + : "=m"(result) + : + : "v0", "memory"); + // Result is 0 on r6 architectures, 1 on other architecture revisions. + // Fall-back to the least common denominator which is mips32 revision 1. + return result ? 1 : 6; } #endif diff --git a/src/mips/constants-mips.h b/src/mips/constants-mips.h index 5ead110..c2eb4ca 100644 --- a/src/mips/constants-mips.h +++ b/src/mips/constants-mips.h @@ -105,7 +105,7 @@ const uint32_t kHoleNanLower32Offset = 4; (kArchVariant == check) #else #define IsMipsArchVariant(check) \ - (CpuFeatures::IsSupported(check)) + (CpuFeatures::IsSupported(static_cast(check))) #endif -- 2.7.4