Ignore:
Timestamp:
Apr 27, 2018, 5:01:14 PM (7 years ago)
Author:
Yusuke Suzuki
Message:

[JSC][ARM64][Linux] Add collectCPUFeatures using auxiliary vector
https://bugs.webkit.org/show_bug.cgi?id=185055

Reviewed by JF Bastien.

This patch is paving the way to emitting jscvt instruction if possible.
To do that, we need to determine jscvt instruction is supported in the
given CPU.

We add a function collectCPUFeatures, which is responsible to collect
CPU features if necessary. In Linux, we can use auxiliary vector to get
the information without parsing /proc/cpuinfo.

Currently, nobody calls this function. It is later called when we emit
jscvt instruction. To make it possible, we also need to add disassembler
support too.

  • assembler/AbstractMacroAssembler.h:
  • assembler/MacroAssemblerARM64.cpp:

(JSC::MacroAssemblerARM64::collectCPUFeatures):

  • assembler/MacroAssemblerARM64.h:
  • assembler/MacroAssemblerX86Common.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/assembler/MacroAssemblerARM64.cpp

    r230040 r231118  
    3131#include "ProbeContext.h"
    3232#include <wtf/InlineASM.h>
     33
     34#if OS(LINUX)
     35#include <asm/hwcap.h>
     36#include <sys/auxv.h>
     37#endif
    3338
    3439namespace JSC {
     
    527532#endif // ENABLE(MASM_PROBE)
    528533
     534void MacroAssemblerARM64::collectCPUFeatures()
     535{
     536    static std::once_flag onceKey;
     537    std::call_once(onceKey, [] {
     538#if OS(LINUX)
     539        // A register for describing ARM64 CPU features are only accessible in kernel mode.
     540        // Thus, some kernel support is necessary to collect CPU features. In Linux, the
     541        // kernel passes CPU feature flags in AT_HWCAP auxiliary vector which is passed
     542        // when the process starts. While this may pose a bit conservative information
     543        // (for example, the Linux kernel may add a flag for a feature after the feature
     544        // is shipped and implemented in some CPUs. In that case, even if the CPU has
     545        // that feature, the kernel does not tell it to users.), it is a stable approach.
     546        // https://www.kernel.org/doc/Documentation/arm64/elf_hwcaps.txt
     547        unsigned long hwcaps = getauxval(AT_HWCAP);
     548
     549#if !defined(HWCAP_JSCVT)
     550#define HWCAP_JSCVT (1 << 13)
     551#endif
     552
     553        s_jscvtCheckState = (hwcaps & HWCAP_JSCVT) ? CPUIDCheckState::Set : CPUIDCheckState::Clear;
     554#else
     555        s_jscvtCheckState = CPUIDCheckState::Clear;
     556#endif
     557    });
     558}
     559
     560MacroAssemblerARM64::CPUIDCheckState MacroAssemblerARM64::s_jscvtCheckState = CPUIDCheckState::NotChecked;
     561
    529562} // namespace JSC
    530563
Note: See TracChangeset for help on using the changeset viewer.