观察汇编代码,默认UseSuperWord是启用的,加了减号还是会生成SIMD指令,需再加上 -XX:UseSSE=0 -XX:UseAVX=0
完整版:
-XX:-UseSuperWord -XX:+PrintFlagsFinal -XX:+UnlockDiagnosticVMOptions -XX:+LogCompilation -XX:UseSSE=0 -XX:UseAVX=0 -XX:CompileCommand=print,*TestJava.*
另,生成SIMD指令需要循环100000次以上,如:
public static void apply(float[] a, float[] b, float s, int n){ for (int i = 0; i < n; i += 1) a[i] += b[i] * s; } public static void main4(String[] args) { final float s = 2.1f; final int n = 1024*100; final float[] a = new float[n]; final float[] b = new float[n]; apply(a, b, s, n); }
查看汇编代码,需要下载 hsdis-amd64.dll (64位机器) hsdis-i386.dll (32位机器)到C:\Program Files\Java\jdk1.8.0_162\jre\bin\server