Any way to prevent gc emitting AVX256 and AVX512 instructions for amd64?

331 views
Skip to first unread message

Amnon Baron Cohen

unread,
May 14, 2019, 5:17:46 AM5/14/19
to golang-nuts
I am trying to avoid running any AVX instructions in order to prevent Intel's dynamic frequency scaling 
reducing my CPU base frequency.

Thanks,
   Amnon

Amnon Baron Cohen

unread,
May 14, 2019, 5:42:56 AM5/14/19
to golang-nuts
apart from GOARCH=386 ?

Ian Lance Taylor

unread,
May 14, 2019, 9:30:32 AM5/14/19
to Amnon Baron Cohen, golang-nuts
On Tue, May 14, 2019 at 2:18 AM Amnon Baron Cohen <amn...@gmail.com> wrote:
>
> I am trying to avoid running any AVX instructions in order to prevent Intel's dynamic frequency scaling
> reducing my CPU base frequency.

You should be able to avoid AVX instructions at runtime by setting the
environment variable GODEBUG=cpu.avx=off. For the complete list of
available GODEBUG=cpu options available on amd64 see the options
variable in internal/cpu/cpu_x86.go.

Ian

Amnon Baron Cohen

unread,
May 14, 2019, 10:03:27 AM5/14/19
to golang-nuts
Thanks!

> go version
go version go1.12.5 linux/amd64
> GODEBUG=cpu.avx=off go build hello.go 
> objdump -d hello | grep '%ymm'
  4021bd: c5 fe 6f 16          vmovdqu (%rsi),%ymm2
  4021c1: c5 fe 6f 1f          vmovdqu (%rdi),%ymm3
  4021c5: c5 fe 6f 66 20        vmovdqu 0x20(%rsi),%ymm4

> GODEBUG=cpu.avx=off,cpu.avx2=off go build hello.go 
> objdump -d hello | grep '%ymm' |head
  4021bd: c5 fe 6f 16          vmovdqu (%rsi),%ymm2
  4021c1: c5 fe 6f 1f          vmovdqu (%rdi),%ymm3
  4021c5: c5 fe 6f 66 20        vmovdqu 0x20(%rsi),%ymm4
  4021ca: c5 fe 6f 6f 20        vmovdqu 0x20(%rdi),%ymm5

but the sledgehammer GOARCH=386 does work

> GOARCH=386 go build hello.go 
> objdump -d hello | grep '%ymm' 

I'll keep digging.

- Amnon

Ian Lance Taylor

unread,
May 14, 2019, 10:15:46 AM5/14/19
to Amnon Baron Cohen, golang-nuts
On Tue, May 14, 2019 at 7:03 AM Amnon Baron Cohen <amn...@gmail.com> wrote:

> > go version
> go version go1.12.5 linux/amd64
> > GODEBUG=cpu.avx=off go build hello.go
> > objdump -d hello | grep '%ymm'
> 4021bd: c5 fe 6f 16 vmovdqu (%rsi),%ymm2
> 4021c1: c5 fe 6f 1f vmovdqu (%rdi),%ymm3
> 4021c5: c5 fe 6f 66 20 vmovdqu 0x20(%rsi),%ymm4
>
> > GODEBUG=cpu.avx=off,cpu.avx2=off go build hello.go
> > objdump -d hello | grep '%ymm' |head
> 4021bd: c5 fe 6f 16 vmovdqu (%rsi),%ymm2
> 4021c1: c5 fe 6f 1f vmovdqu (%rdi),%ymm3
> 4021c5: c5 fe 6f 66 20 vmovdqu 0x20(%rsi),%ymm4
> 4021ca: c5 fe 6f 6f 20 vmovdqu 0x20(%rdi),%ymm5

Yes: GODEBUG=cpu.avx=off affects runtime execution. It does not
affect the compiler. You should set it when running the program. It
will override the CPU detection to say that AVX instructions are not
available on this processor.

There is no way to change what the compiler generates.

Ian

Amnon Baron Cohen

unread,
May 14, 2019, 10:37:44 AM5/14/19
to golang-nuts
OK.
Thanks for the explanation and pointers.

keith....@gmail.com

unread,
May 14, 2019, 8:07:45 PM5/14/19
to golang-nuts
By the way, these instructions are not generated by the compiler. They are part of the assembly in the stdlib (runtime or internal/bytealg, probably).
Reply all
Reply to author
Forward
0 new messages