Bug 1260694 - IonMonkey: MIPS: Inline get MIPS flags. r=huangwenjun06
authorHeiher <r@hev.cc>
Tue, 05 Apr 2016 11:03:38 +0800
changeset 347727 973bbaa2be7bae42ae7d96dee962fbcfb7ee65b3
parent 347726 a82738ebcf080050a3b919502a5f9c6c37f14576
child 347728 4ebc3275aa3d5b9d7dc222864b5a29a24582c9eb
push id14653
push userolivier@olivieryiptong.com
push dateTue, 05 Apr 2016 19:21:01 +0000
reviewershuangwenjun06
bugs1260694
milestone48.0a1
Bug 1260694 - IonMonkey: MIPS: Inline get MIPS flags. r=huangwenjun06 --- .../jit/mips-shared/Architecture-mips-shared.cpp | 24 +++++++++++++--------- js/src/jit/mips-shared/Architecture-mips-shared.h | 12 ++++++++--- 2 files changed, 23 insertions(+), 13 deletions(-)
js/src/jit/mips-shared/Architecture-mips-shared.cpp
js/src/jit/mips-shared/Architecture-mips-shared.h
--- a/js/src/jit/mips-shared/Architecture-mips-shared.cpp
+++ b/js/src/jit/mips-shared/Architecture-mips-shared.cpp
@@ -13,24 +13,21 @@
 
 #define HWCAP_MIPS (1 << 28)
 #define HWCAP_LOONGSON (1 << 27)
 #define HWCAP_FPU (1 << 0)
 
 namespace js {
 namespace jit {
 
-uint32_t GetMIPSFlags()
+static uint32_t
+get_mips_flags()
 {
-    static uint32_t flags = 0;
+    uint32_t flags = HWCAP_MIPS;
 
-    if (flags)
-        return flags;
-
-    flags |= HWCAP_MIPS;
 #if defined(JS_SIMULATOR_MIPS32) || defined(JS_SIMULATOR_MIPS64)
     flags |= HWCAP_FPU;
 #else
 # ifdef __linux__
     FILE* fp = fopen("/proc/cpuinfo", "r");
     if (!fp)
         return flags;
 
@@ -42,24 +39,31 @@ uint32_t GetMIPSFlags()
         flags |= HWCAP_FPU;
     if (strstr(buf, "Loongson"))
         flags |= HWCAP_LOONGSON;
 # endif
 #endif // JS_SIMULATOR_MIPS32 || JS_SIMULATOR_MIPS64
     return flags;
 }
 
-bool hasFPU()
+static bool check_fpu()
 {
-    return js::jit::GetMIPSFlags() & HWCAP_FPU;
+    return mips_private::Flags & HWCAP_FPU;
 }
 
-bool isLoongson()
+static bool check_loongson()
 {
-    return js::jit::GetMIPSFlags() & HWCAP_LOONGSON;
+    return mips_private::Flags & HWCAP_LOONGSON;
+}
+
+namespace mips_private {
+    // Cache a local copy so we only have to read /proc/cpuinfo once.
+    uint32_t Flags = get_mips_flags();
+    bool hasFPU = check_fpu();;
+    bool isLoongson = check_loongson();
 }
 
 Registers::Code
 Registers::FromName(const char* name)
 {
     for (size_t i = 0; i < Total; i++) {
         if (strcmp(GetName(i), name) == 0)
             return Code(i);
--- a/js/src/jit/mips-shared/Architecture-mips-shared.h
+++ b/js/src/jit/mips-shared/Architecture-mips-shared.h
@@ -303,19 +303,25 @@ class FloatRegisterMIPSShared
     static uint32_t FirstBit(SetType x) {
         return mozilla::CountTrailingZeroes64(x);
     }
     static uint32_t LastBit(SetType x) {
         return 63 - mozilla::CountLeadingZeroes64(x);
     }
 };
 
-uint32_t GetMIPSFlags();
-bool hasFPU();
-bool isLoongson();
+namespace mips_private {
+    extern uint32_t Flags;
+    extern bool hasFPU;
+    extern bool isLoongson;
+}
+
+inline uint32_t GetMIPSFlags() { return mips_private::Flags; }
+inline bool hasFPU() { return mips_private::hasFPU; }
+inline bool isLoongson() { return mips_private::isLoongson; }
 
 // MIPS doesn't have double registers that can NOT be treated as float32.
 inline bool
 hasUnaliasedDouble() {
     return false;
 }
 
 // On MIPS, fn-double aliases both fn-float32 and fn+1-float32, so if you need