Skip to content

x/sys/cpu: add support for ARM #33508

@jpap

Description

@jpap

It would be nice to have feature detection for ARM (32-bit) in x/sys/cpu.

Concretely, a new cpu.ARM struct that closely resembles the existing cpu.ARM64 struct, tailored to the ARM specific hardware capabilities. The following fields are proposed, which map directly to the {HWCAP, HWCAP2} auxiliary vector values on Linux and FreeBSD:

HasSWP      bool // SWP instruction support
HasHALF     bool // Half-word load and store support
HasTHUMB    bool // ARM Thumb instruction set
Has26BIT    bool // Address space limited to 26-bits
HasFASTMUL  bool // 32-bit operand, 64-bit result multiplication support
HasFPA      bool // Floating point arithmetic support
HasVFP      bool // Vector floating point support
HasEDSP     bool // DSP Extensions support
HasJAVA     bool // Java instruction set
HasIWMMXT   bool // Intel Wireless MMX technology support
HasCRUNCH   bool // MaverickCrunch context switching and handling
HasTHUMBEE  bool // Thumb EE instruction set
HasNEON     bool // NEON instruction set
HasVFPv3    bool // Vector floating point version 3 support
HasVFPv3D16 bool // Vector floating point version 3 D8-D15
HasTLS      bool // Thread local storage support
HasVFPv4    bool // Vector floating point version 4 support
HasIDIVA    bool // Integer divide instruction support in ARM mode
HasIDIVT    bool // Integer divide instruction support in Thumb mode
HasIDIV     bool // Integer divide instruction support in ARM and Thumb mode
HasVFPD32   bool // Vector floating point version 3 D15-D31
HasLPAE     bool // Large Physical Address Extensions
HasEVTSTRM  bool // Event stream support
HasAES      bool // AES hardware implementation
HasPMULL    bool // Polynomial multiplication instruction set
HasSHA1     bool // SHA1 hardware implementation
HasSHA2     bool // SHA2 hardware implementation
HasCRC32    bool // CRC32 hardware implementation

As I look around, I see code detecting CPU features based on the runtime.goarm value (which is set by the GOARM environment variable at link time), rather than a runtime check. This means that:

  1. As runtime.goarm is not const, the fast-path (e.g. using NEON) and slow-path fallback are being compiled into the binary, but only one path can ever be used. It would be nice if both paths can be used via run-time detection instead.
  2. Using the above, one cannot have a "universal binary" that is especially problematic on Android.

In one of my projects, I have resorted to parsing /proc/cpuinfo for run-time detection of NEON, which only works on Linux. I'd love to instead use the standard library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.NeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions