Created
February 9, 2015 23:32
-
-
Save rednaxelafx/29caf8a939884e0c9c42 to your computer and use it in GitHub Desktop.
Simple demo of autovectorization in Oracle JDK8u25 on Linux/x64 with AVX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java -XX:+UnlockDiagnosticVMOptions -XX:-TieredCompilation -XX:+PrintCompilation -XX:+PrintInlining -XX:CompileCommand=exclude,TestVec,main -XX:+PrintAssembly TestVec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Decoding compiled method 0x00007fbca906e5d0: | |
Code: | |
[Disassembling for mach='i386:x86-64'] | |
[Entry Point] | |
[Verified Entry Point] | |
[Constants] | |
# {method} {0x00007fbca37923d8} 'doTest' '([I[I)[I' in 'TestVec' | |
# parm0: rsi:rsi = '[I' | |
# parm1: rdx:rdx = '[I' | |
# [sp+0x40] (sp of caller) | |
0x00007fbca906e720: mov %eax,-0x14000(%rsp) | |
0x00007fbca906e727: push %rbp | |
0x00007fbca906e728: sub $0x30,%rsp ;*synchronization entry | |
; - TestVec::doTest@-1 (line 5) | |
0x00007fbca906e72c: mov %rsi,%r11 | |
0x00007fbca906e72f: mov 0xc(%rsi),%r8d ;*arraylength | |
; - TestVec::doTest@1 (line 5) | |
; implicit exception: dispatches to 0x00007fbca906e8d9 | |
0x00007fbca906e733: mov 0xc(%rdx),%ebp ;*arraylength | |
; - TestVec::doTest@3 (line 5) | |
; implicit exception: dispatches to 0x00007fbca906e8e9 | |
0x00007fbca906e736: cmp %ebp,%r8d | |
0x00007fbca906e739: je 0x00007fbca906e74d ;*if_icmpeq | |
; - TestVec::doTest@4 (line 5) | |
0x00007fbca906e73b: xor %r9d,%r9d ;*arraylength | |
; - TestVec::doTest@3 (line 5) | |
0x00007fbca906e73e: mov %r9,%rax | |
0x00007fbca906e741: add $0x30,%rsp | |
0x00007fbca906e745: pop %rbp | |
0x00007fbca906e746: test %eax,0xb2b48b4(%rip) # 0x00007fbcb4323000 | |
; {poll_return} | |
0x00007fbca906e74c: retq | |
0x00007fbca906e74d: cmp $0x40000,%r8d | |
0x00007fbca906e754: ja 0x00007fbca906e887 | |
0x00007fbca906e75a: movslq %r8d,%rcx | |
0x00007fbca906e75d: shl $0x2,%rcx | |
0x00007fbca906e761: add $0x17,%rcx | |
0x00007fbca906e765: mov %rcx,%r10 | |
0x00007fbca906e768: and $0xfffffffffffffff8,%r10 | |
0x00007fbca906e76c: mov 0x60(%r15),%r9 | |
0x00007fbca906e770: mov %r9,%rbx | |
0x00007fbca906e773: add %r10,%rbx | |
0x00007fbca906e776: cmp 0x70(%r15),%rbx | |
0x00007fbca906e77a: jae 0x00007fbca906e887 | |
0x00007fbca906e780: mov %rbx,0x60(%r15) | |
0x00007fbca906e784: mov %r9,%rdi | |
0x00007fbca906e787: add $0x10,%rdi | |
0x00007fbca906e78b: movq $0x1,(%r9) | |
0x00007fbca906e792: movl $0xb68,0x8(%r9) ; {metadata({type array int})} | |
0x00007fbca906e79a: mov %r8d,0xc(%r9) | |
0x00007fbca906e79e: shr $0x3,%rcx | |
0x00007fbca906e7a2: add $0xfffffffffffffffe,%rcx | |
0x00007fbca906e7a6: xor %rax,%rax | |
0x00007fbca906e7a9: rep stos %rax,%es:(%rdi) ;*newarray | |
; - TestVec::doTest@11 (line 6) | |
0x00007fbca906e7ac: test %r8d,%r8d | |
0x00007fbca906e7af: jle 0x00007fbca906e73e ;*if_icmpge | |
; - TestVec::doTest@19 (line 7) | |
0x00007fbca906e7b1: test %r8d,%r8d | |
0x00007fbca906e7b4: jbe 0x00007fbca906e8be | |
0x00007fbca906e7ba: mov %r8d,%ecx | |
0x00007fbca906e7bd: dec %ecx | |
0x00007fbca906e7bf: cmp %r8d,%ecx | |
0x00007fbca906e7c2: jae 0x00007fbca906e8be | |
0x00007fbca906e7c8: test %ebp,%ebp | |
0x00007fbca906e7ca: jbe 0x00007fbca906e8be | |
0x00007fbca906e7d0: cmp %ebp,%ecx | |
0x00007fbca906e7d2: jae 0x00007fbca906e8be | |
0x00007fbca906e7d8: mov %r9d,%r10d | |
0x00007fbca906e7db: shr $0x2,%r10d | |
0x00007fbca906e7df: and $0x3,%r10d | |
0x00007fbca906e7e3: xor %edi,%edi | |
0x00007fbca906e7e5: mov $0xffffffff,%ebx | |
0x00007fbca906e7ea: sub %r10d,%ebx | |
0x00007fbca906e7ed: and $0x3,%ebx | |
0x00007fbca906e7f0: inc %ebx | |
0x00007fbca906e7f2: cmp %r8d,%ebx | |
0x00007fbca906e7f5: cmovg %r8d,%ebx ;*aload_2 | |
; - TestVec::doTest@22 (line 8) | |
0x00007fbca906e7f9: mov 0x10(%rdx,%rdi,4),%esi | |
0x00007fbca906e7fd: imul 0x10(%r11,%rdi,4),%esi | |
0x00007fbca906e803: mov %esi,0x10(%r9,%rdi,4) ;*iastore | |
; - TestVec::doTest@31 (line 8) | |
0x00007fbca906e808: inc %edi ;*iinc | |
; - TestVec::doTest@32 (line 7) | |
0x00007fbca906e80a: cmp %ebx,%edi | |
0x00007fbca906e80c: jl 0x00007fbca906e7f9 ;*if_icmpge | |
; - TestVec::doTest@19 (line 7) | |
0x00007fbca906e80e: mov %r8d,%ebx | |
0x00007fbca906e811: add $0xfffffffffffffff9,%ebx | |
0x00007fbca906e814: mov $0x80000000,%esi | |
0x00007fbca906e819: cmp %ebx,%ecx | |
0x00007fbca906e81b: cmovl %esi,%ebx | |
0x00007fbca906e81e: cmp %ebx,%edi | |
0x00007fbca906e820: jge 0x00007fbca906e863 | |
0x00007fbca906e822: nopl 0x0(%rax) | |
0x00007fbca906e829: nopl 0x0(%rax) ;*aload_2 | |
; - TestVec::doTest@22 (line 8) | |
0x00007fbca906e830: vmovdqu 0x10(%rdx,%rdi,4),%xmm0 | |
0x00007fbca906e836: vpmulld 0x10(%r11,%rdi,4),%xmm0,%xmm0 | |
0x00007fbca906e83d: vmovdqu %xmm0,0x10(%r9,%rdi,4) | |
0x00007fbca906e844: movslq %edi,%r10 | |
0x00007fbca906e847: vmovdqu 0x20(%rdx,%r10,4),%xmm0 | |
0x00007fbca906e84e: vpmulld 0x20(%r11,%r10,4),%xmm0,%xmm0 | |
0x00007fbca906e855: vmovdqu %xmm0,0x20(%r9,%r10,4) ;*iastore | |
; - TestVec::doTest@31 (line 8) | |
0x00007fbca906e85c: add $0x8,%edi ;*iinc | |
; - TestVec::doTest@32 (line 7) | |
0x00007fbca906e85f: cmp %ebx,%edi | |
0x00007fbca906e861: jl 0x00007fbca906e830 ;*if_icmpge | |
; - TestVec::doTest@19 (line 7) | |
0x00007fbca906e863: cmp %r8d,%edi | |
0x00007fbca906e866: jge 0x00007fbca906e73e ;*aload_2 | |
; - TestVec::doTest@22 (line 8) | |
0x00007fbca906e86c: mov 0x10(%rdx,%rdi,4),%ecx | |
0x00007fbca906e870: imul 0x10(%r11,%rdi,4),%ecx | |
0x00007fbca906e876: mov %ecx,0x10(%r9,%rdi,4) ;*iastore | |
; - TestVec::doTest@31 (line 8) | |
0x00007fbca906e87b: inc %edi ;*iinc | |
; - TestVec::doTest@32 (line 7) | |
0x00007fbca906e87d: cmp %r8d,%edi | |
0x00007fbca906e880: jl 0x00007fbca906e86c ;*if_icmpge | |
; - TestVec::doTest@19 (line 7) | |
0x00007fbca906e882: jmpq 0x00007fbca906e73e | |
0x00007fbca906e887: mov %r8d,0x10(%rsp) | |
0x00007fbca906e88c: mov %rdx,0x8(%rsp) | |
0x00007fbca906e891: mov %rsi,(%rsp) | |
0x00007fbca906e895: mov $0x800000b68,%rsi ; {metadata({type array int})} | |
0x00007fbca906e89f: mov %r8d,%edx | |
0x00007fbca906e8a2: nop | |
0x00007fbca906e8a3: callq 0x00007fbca906bce0 ; OopMap{[0]=Oop [8]=Oop off=392} | |
;*newarray | |
; - TestVec::doTest@11 (line 6) | |
; {runtime_call} | |
0x00007fbca906e8a8: mov (%rsp),%r11 | |
0x00007fbca906e8ac: mov 0x8(%rsp),%rdx | |
0x00007fbca906e8b1: mov 0x10(%rsp),%r8d | |
0x00007fbca906e8b6: mov %rax,%r9 | |
0x00007fbca906e8b9: jmpq 0x00007fbca906e7ac | |
0x00007fbca906e8be: mov $0xffffff86,%esi | |
0x00007fbca906e8c3: mov %r11,%rbp | |
0x00007fbca906e8c6: mov %rdx,(%rsp) | |
0x00007fbca906e8ca: mov %r9,0x8(%rsp) | |
0x00007fbca906e8cf: callq 0x00007fbca9004ee0 ; OopMap{rbp=Oop [0]=Oop [8]=Oop off=436} | |
;*aload_2 | |
; - TestVec::doTest@22 (line 8) | |
; {runtime_call} | |
0x00007fbca906e8d4: callq 0x00007fbcb3a503b0 ;*aload_2 | |
; - TestVec::doTest@22 (line 8) | |
; {runtime_call} | |
0x00007fbca906e8d9: mov $0xfffffff6,%esi | |
0x00007fbca906e8de: nop | |
0x00007fbca906e8df: callq 0x00007fbca9004ee0 ; OopMap{off=452} | |
;*arraylength | |
; - TestVec::doTest@1 (line 5) | |
; {runtime_call} | |
0x00007fbca906e8e4: callq 0x00007fbcb3a503b0 ;*arraylength | |
; - TestVec::doTest@1 (line 5) | |
; {runtime_call} | |
0x00007fbca906e8e9: mov $0xfffffff6,%esi | |
0x00007fbca906e8ee: nop | |
0x00007fbca906e8ef: callq 0x00007fbca9004ee0 ; OopMap{off=468} | |
;*arraylength | |
; - TestVec::doTest@3 (line 5) | |
; {runtime_call} | |
0x00007fbca906e8f4: callq 0x00007fbcb3a503b0 ;*newarray | |
; - TestVec::doTest@11 (line 6) | |
; {runtime_call} | |
0x00007fbca906e8f9: mov %rax,%rsi | |
0x00007fbca906e8fc: add $0x30,%rsp | |
0x00007fbca906e900: pop %rbp | |
0x00007fbca906e901: jmpq 0x00007fbca906d1e0 ;*if_icmpge | |
; - TestVec::doTest@19 (line 7) | |
; {runtime_call} | |
0x00007fbca906e906: hlt | |
0x00007fbca906e907: hlt | |
0x00007fbca906e908: hlt | |
0x00007fbca906e909: hlt | |
0x00007fbca906e90a: hlt | |
0x00007fbca906e90b: hlt | |
0x00007fbca906e90c: hlt | |
0x00007fbca906e90d: hlt | |
0x00007fbca906e90e: hlt | |
0x00007fbca906e90f: hlt | |
0x00007fbca906e910: hlt | |
0x00007fbca906e911: hlt | |
0x00007fbca906e912: hlt | |
0x00007fbca906e913: hlt | |
0x00007fbca906e914: hlt | |
0x00007fbca906e915: hlt | |
0x00007fbca906e916: hlt | |
0x00007fbca906e917: hlt | |
0x00007fbca906e918: hlt | |
0x00007fbca906e919: hlt | |
0x00007fbca906e91a: hlt | |
0x00007fbca906e91b: hlt | |
0x00007fbca906e91c: hlt | |
0x00007fbca906e91d: hlt | |
0x00007fbca906e91e: hlt | |
0x00007fbca906e91f: hlt | |
[Exception Handler] | |
[Stub Code] | |
0x00007fbca906e920: jmpq 0x00007fbca906c2e0 ; {no_reloc} | |
[Deopt Handler Code] | |
0x00007fbca906e925: callq 0x00007fbca906e92a | |
0x00007fbca906e92a: subq $0x5,(%rsp) | |
0x00007fbca906e92f: jmpq 0x00007fbca9046d00 ; {runtime_call} | |
0x00007fbca906e934: hlt | |
0x00007fbca906e935: hlt | |
0x00007fbca906e936: hlt | |
0x00007fbca906e937: hlt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class TestVec { | |
public static int[] doTest(int[] xs, int[] ys) { | |
if (xs.length != ys.length) return null; | |
int[] zs = new int[xs.length]; | |
for (int i = 0; i < xs.length; i++) { | |
zs[i] = xs[i] * ys[i]; | |
} | |
return zs; | |
} | |
public static void main(String[] args) throws Exception { | |
int[] xs = new int[1000]; | |
int[] ys = new int[1000]; | |
Arrays.fill(xs, 123); | |
Arrays.fill(ys, 456); | |
for (int i = 0; i < 100000; i++) { | |
doTest(xs, ys); | |
} | |
System.in.read(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment