There’s a common feature in programming languages to compile code for a certain CPU target. This is present in C, Rust, Zig, Haskell, Pascal, and a lot more. Does Go support this at all?
I know gc was built on top of the Plan9 toolchain, not LLVM or GCC… So if there’s no way to target code for a certain CPU (or even tune) in gc, would it be possible in GCC’s frontend, gccgo?
GOARM
For GOARCH=arm, the ARM architecture for which to compile.
Valid values are 5, 6, 7.
GO386
For GOARCH=386, how to implement floating point instructions.
Valid values are sse2 (default), softfloat.
GOAMD64
For GOARCH=amd64, the microarchitecture level for which to compile.
Valid values are v1 (default), v2, v3, v4.
See https://golang.org/wiki/MinimumRequirements#amd64
GOMIPS
For GOARCH=mips{,le}, whether to use floating point instructions.
Valid values are hardfloat (default), softfloat.
GOMIPS64
For GOARCH=mips64{,le}, whether to use floating point instructions.
Valid values are hardfloat (default), softfloat.
GOPPC64
For GOARCH=ppc64{,le}, the target ISA (Instruction Set Architecture).
Valid values are power8 (default), power9.
GOWASM
For GOARCH=wasm, comma-separated list of experimental WebAssembly features to use.
Valid values are satconv, signext.
Thank you both!! I have a few follow up questions.
Will for example, setting GO(arch), ie, GOAMD64="v2" have any effects on an other architecture, for example PowerPC, compiling for itself?
As this seems the only way to optimize Go code for your hardware, are there any other ways to optimize Go code? (in general or for your hardware)
This is very unconventional compared to how I see other languages handle this, although it is a lot better than not being able to do this at all. Thanks again for your time.