Turn off 512-bit vector ops (-mprefer-vector-width=256)?

Is there any way to prevent zig from producing AVX-512 512-bit instructions ?

(edit: Trying to make the question more specific since I know what I would do with gcc, but don’t know how to express it in zig. I want to keep the 256-bit and lower vector ops regardless of instruction set extension. Second best and I thought might be more supported was just turning off avx-512 entirely, but that is a very crude hammer.)

Yes, you can turn off the feature.

  1. Do you build from the command line? If yes, what is the command line?
  2. Do you build using build.zig? If yes, post you build.zig.
  3. When building, do you specify a target?

I don’t know the build system very well. I’ve read though parts of build.zig, (like I see the suggest vector size and preferred size pieces, but I dont know how to influence them).

1.yes, zig build --release=fast
2. just standard no changes
3. just the default – i want native (but it would be nice to know how to do something like -march and related

What I really want is to just turn of the 512-bit operations, but leave AVX-512 for 256 and lower. Basically I want -mprefer-vector-width=256 . A per function basis would be the best.

The problem with native is that is using the parameters of your processor that have avx512.
You can use the build command line option -Dcpu=-feature1-feature2 to remove feature1 and feature2, where features are: std.Target.x86.Feature.

1 Like

I see the prefered bit width tuple. Cant I set that? I still want AVX-512 just not the 5120-bit ops because they are so slow and downclock the CPU drastically.