GOAMD64 build tags?

122 views
Skip to first unread message

Klaus Post

unread,
Feb 1, 2022, 7:34:22 AM2/1/22
to golang-nuts
Hi!

I looked through the source to see if `GOAMD64` version results in build tags being set, but I was unsure if that is the case.

It would be really helpful for assembly code that can be assumed to work without cpuid checks, avoiding a bit of branching.

For example adding goamd64_v1...goamd64_v4 tags depending on the version set at compile would be very helpful.

Apologies if I missed it already existing.

/Klaus

Ian Lance Taylor

unread,
Feb 1, 2022, 3:12:08 PM2/1/22
to Klaus Post, golang-nuts
Historically the go tool hasn't provided build tags for any of the
GO${GOARCH} environment variables. What it does do is define macros
that the assembler code can check using #ifdef. It will define
GOAMD64_vN where N is the value from the GOAMD64 environment variable
at build time. Perhaps that will be sufficient for your purposes.

Ian

Klaus Post

unread,
Feb 2, 2022, 4:07:26 AM2/2/22
to golang-nuts
Oh, so that is what that part of the code is doing.

That should be quite fine, and also reduces code duplication a lot, when I can convince avo to emit ifdefs. It seems to me like only the latest version is defined, which is a bit clunky, but doable.

Build tags would help pure Go alternate paths, but the define in assembly should be ok for now.

Thanks!



Ian
Reply all
Reply to author
Forward
0 new messages