utils icon indicating copy to clipboard operation
utils copied to clipboard

cpufeatures: add compile time fallback for unsupported targets and target features

Open newpavlov opened this issue 4 months ago • 2 comments

The changes simplify the code a bit and add a cfg-based fallback for all targets. This allows users to use the crate even if runtime detection was not implemented for a given target or target feature combination.

It ties the list of target features supported by the crate to std. This should not be a concern since we generally use target feature names defined by std.

TODO: Update docs and check list of supported target features in __can_detect macros.

newpavlov avatar Aug 25 '25 04:08 newpavlov

@heiher I noticed that Loongarch features added in #955 differ from features supported by the is_loongarch_feature_detected! macro. Do you know why?

Additionally, rustc --target=loongarch64-unknown-linux-gnu --print=target-features prints the following list:

    crt-static           - Enables C Run-time Libraries to be statically linked.
    d                    - 'D' (Double-Precision Floating-Point).
    div32                - Assume div.w[u] and mod.w[u] can handle inputs that are not sign-extended.
    f                    - 'F' (Single-Precision Floating-Point).
    frecipe              - Support frecipe.{s/d} and frsqrte.{s/d} instructions..
    lam-bh               - Support amswap[_db].{b/h} and amadd[_db].{b/h} instructions..
    lamcas               - Support amcas[_db].{b/h/w/d}..
    lasx                 - 'LASX' (Loongson Advanced SIMD Extension).
    lbt                  - 'LBT' (Loongson Binary Translation Extension).
    ld-seq-sa            - Don't use load-load barrier (dbar 0x700)..
    lsx                  - 'LSX' (Loongson SIMD Extension).
    lvz                  - 'LVZ' (Loongson Virtualization Extension).
    relax                - Enable Linker relaxation.
    scq                  - Support sc.q instruction.
    ual                  - Allow memory accesses to be unaligned.

For example, there are no mentions of the crypto target feature.

I think we should change the module to follow std.

newpavlov avatar Aug 25 '25 07:08 newpavlov

@newpavlov You're right. The LoongArch target features in cpufeatures are indeed different from those used by rustc. In cpufeatures, they come from the Linux kernel's HWCAP set, but those don't map one-to-one with LLVM's compiler features. That's the root cause of the discrepancy. I agree we should align with std, and I'll update them accordingly.

EDIT:

#1206

heiher avatar Aug 25 '25 11:08 heiher