tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit d7f8a904ac59e2fa627cc799d990f8cbc8f3251d
parent 6ad9983264efd83c11086e83c26ec9c68f9f1ebd
Author: André Bargull <andre.bargull@gmail.com>
Date:   Fri, 17 Oct 2025 11:25:41 +0000

Bug 1992993 - Part 4: Add MIPSFlags to compute flags not-during startup. r=spidermonkey-reviewers,iain

Add `MIPSFlags` similar to `ARM64Flags`.

This avoids "Global variable has runtime initialisation" warnings.

Differential Revision: https://phabricator.services.mozilla.com/D267792

Diffstat:
Mjs/src/jit/JitContext.cpp | 5+++++
Mjs/src/jit/mips-shared/Architecture-mips-shared.cpp | 28++++++++++------------------
Mjs/src/jit/mips-shared/Architecture-mips-shared.h | 42+++++++++++++++++++++++++++++++-----------
3 files changed, 46 insertions(+), 29 deletions(-)

diff --git a/js/src/jit/JitContext.cpp b/js/src/jit/JitContext.cpp @@ -114,6 +114,11 @@ bool jit::InitializeJit() { ARM64Flags::Init(); #endif +#ifdef JS_CODEGEN_MIPS64 + // Compute flags. + MIPSFlags::Init(); +#endif + #ifndef JS_CODEGEN_NONE MOZ_ASSERT(js::jit::CPUFlagsHaveBeenComputed()); #endif diff --git a/js/src/jit/mips-shared/Architecture-mips-shared.cpp b/js/src/jit/mips-shared/Architecture-mips-shared.cpp @@ -55,26 +55,18 @@ static uint32_t get_mips_flags() { return flags; } -static bool check_fpu() { return mips_private::Flags & HWCAP_FPU; } - -static bool check_loongson() { return mips_private::Flags & HWCAP_LOONGSON; } - -static bool check_r2() { return mips_private::Flags & HWCAP_R2; } - -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(); -bool hasR2 = check_r2(); -} // namespace mips_private - -bool CPUFlagsHaveBeenComputed() { - // Flags were computed above. - return true; +void MIPSFlags::Init() { + MOZ_ASSERT(!IsInitialized()); + + flags = get_mips_flags(); + hasFPU = flags & HWCAP_FPU; + hasR2 = flags & HWCAP_R2; + isLoongson = flags & HWCAP_LOONGSON; + initialized = true; } +bool CPUFlagsHaveBeenComputed() { return MIPSFlags::IsInitialized(); } + Registers::Code Registers::FromName(const char* name) { for (size_t i = 0; i < Total; i++) { if (strcmp(GetName(i), name) == 0) { diff --git a/js/src/jit/mips-shared/Architecture-mips-shared.h b/js/src/jit/mips-shared/Architecture-mips-shared.h @@ -296,17 +296,37 @@ class FloatRegisterMIPSShared { } }; -namespace mips_private { -extern uint32_t Flags; -extern bool hasFPU; -extern bool isLoongson; -extern bool hasR2; -} // namespace mips_private - -inline uint32_t GetMIPSFlags() { return mips_private::Flags; } -inline bool hasFPU() { return mips_private::hasFPU; } -inline bool isLoongson() { return mips_private::isLoongson; } -inline bool hasR2() { return mips_private::hasR2; } +class MIPSFlags final { + static inline bool initialized = false; + + static inline uint32_t flags = 0; + static inline bool hasFPU = false; + static inline bool hasR2 = false; + static inline bool isLoongson = false; + + public: + MIPSFlags() = delete; + + // MIPSFlags::Init is called from the JitContext constructor to read the + // hardware flags. This method must only be called exactly once. + static void Init(); + + static bool IsInitialized() { return initialized; } + + static uint32_t GetFlags() { + MOZ_ASSERT(IsInitialized()); + return flags; + } + + static bool HasFPU() { return hasFPU; } + static bool HasR2() { return hasR2; } + static bool IsLoongson() { return isLoongson; } +}; + +inline uint32_t GetMIPSFlags() { return MIPSFlags::GetFlags(); } +inline bool hasFPU() { return MIPSFlags::HasFPU(); } +inline bool isLoongson() { return MIPSFlags::IsLoongson(); } +inline bool hasR2() { return MIPSFlags::HasR2(); } // MIPS doesn't have double registers that can NOT be treated as float32. inline bool hasUnaliasedDouble() { return false; }