ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
33.72k stars 2.48k forks source link

implement self-hosted CPU model and features detection #4591

Open andrewrk opened 4 years ago

andrewrk commented 4 years ago

Currently we rely on LLVM to do this:

https://github.com/ziglang/zig/blob/48cef8d5be24c40b4c845f6b07c78abd6c3d1b0d/lib/std/zig/system.zig#L790-L793

https://github.com/ziglang/zig/blob/48cef8d5be24c40b4c845f6b07c78abd6c3d1b0d/src-self-hosted/stage2.zig#L1156-L1167

The LLVM functions we are currently calling probably have some helpful code to look at when doing this implementation.

LLVM getHostCPUFeatures

andrewrk commented 4 years ago

Thanks to @alichay the x86 and x86-64 parts of this are complete!

alichay commented 4 years ago

Does it make sense to have the arch-avr label? While that's a valid target, of course, I can't see a situation where it makes sense for the compiler to run natively on it.

andrewrk commented 2 years ago

This is implemented for a few variants. The next step in this issue is to enumerate what exactly is still missing, extract issues for each one, then close this issue.

matu3ba commented 9 months ago

To be filled eventually (by me/others) the tier 1 support matrix:

          | freestanding | Linux | Darwin  | Windows  | Wasi
--------- | -----------  | ------| ------- | -------- | ----
x86_64    |     ?        |   ?   |    ?    |    ?     |  ?
x86       |     ?        |   ?   |    ?    |    ?     |  ?
aarch64   |     ?        |   ?   |    ?    |    ?     |  ?
arm       |     ?        |   ?   |    ?    |    ?     |  ?
mips64    |     ?        |   ?   |    ?    |    ?     |  ?
mips      |     ?        |   ?   |    ?    |    ?     |  ?
risc64    |     ?        |   ?   |    ?    |    ?     |  ?
powerpc32 |     ?        |   ?   |    ?    |    ?     |  ?
powerpc64 |     ?        |   ?   |    ?    |    ?     |  ?
wasm32    |     ?        |   ?   |    ?    |    ?     |  ?
matu3ba commented 9 months ago

Here you go @andrewrk

Comparing tier 1 targets

          | freestanding | Linux | macOS   | Windows  | Wasi
--------- | -----------  | ------| ------- | -------- | ----
x86_64    |     ✓        |   ✓   |    ✓    |    ✓     | N/A
x86       |     ✓        |   ✓   |    ✓    |    ✓     | N/A
aarch64   |     ✗        |   ✓   |    ✓    |    ✓     | N/A
arm       |     ✗        |   ✓   |   N/A   |    ✗     | N/A
mips      |     ✗        |   ✗   |   N/A   |   N/A    | N/A
risc64    |     ✗        |   ✗   |   N/A   |   N/A    | N/A
powerpc32 |     ✗        |   ✓   |   N/A   |   N/A    | N/A
powerpc64 |     ✗        |   ✓   |   N/A   |   N/A    | N/A
wasm32    |     ✗        |   ✗   |   N/A   |   N/A    |  ✓

(not sure if wasm32 standard even has the concept of feature detection via SIMD yet) Why:

Looking at detectNativeCpuAndFeatures in lib\std\zig\system\NativeTargetInfo.zig .x86_64, .x86 handled at first

lib\std\zig\system\windows.zig .aarch64, .aarch64_be, .aarch64_32

lib\std\zig\system\linux.zig .arm, .armeb, .thumb, .thumbeb, .aarch64, .aarch64_be, .aarch64_32 .sparc64 .powerpc, .powerpcle, .powerpc64, .powerpc64le

lib\std\zig\system\darwin\macos.zig .aarch64, .aarch64_be, .aarch64_32 => {

andrewrk commented 1 month ago

cc @alexrp this issue may be of interest to you.