Skip to content

Instantly share code, notes, and snippets.

@Ono-Sendai
Last active May 22, 2018 15:00
Show Gist options
  • Save Ono-Sendai/b3220a02216b82a560260fcf036cc515 to your computer and use it in GitHub Desktop.
Save Ono-Sendai/b3220a02216b82a560260fcf036cc515 to your computer and use it in GitHub Desktop.
=====================================================Optimised IR=========================================================
; ModuleID = 'WinterModule'
target datalayout = "e-p:64:64:64-S128-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-f128:128:128-v64:64:64-v128:128:128-a0:0:6$
%vec2 = type { <2 x float> }
; Function Attrs: nounwind
declare void @print_vec2_(%vec2* noalias sret, %vec2* noalias readonly) #0
; Function Attrs: nounwind
define i1 @main_opaque_(i32* nocapture readnone %env) #0 {
entry:
%res1 = alloca %vec2, align 8
%res = alloca %vec2, align 8
%0 = getelementptr inbounds %vec2* %res1, i64 0, i32 0
store <2 x float> <float 1.000000e+00, float 2.000000e+00>, <2 x float>* %0, align 8
call void @print_vec2_(%vec2* %res, %vec2* %res1)
%res.idx = getelementptr %vec2* %res, i64 0, i32 0
%res.idx.val = load <2 x float>* %res.idx, align 8
%1 = fcmp oeq <2 x float> %res.idx.val, <float 1.000000e+00, float 2.000000e+00>
%2 = extractelement <2 x i1> %1, i32 0
%3 = extractelement <2 x i1> %1, i32 1
%4 = and i1 %2, %3
ret i1 %4
}
attributes #0 = { nounwind }
============================================== Assembly with annotations ===================================================
.file "WinterModule"
.section .rodata.cst16,"aM",@progbits,16
.align 16
.LCPI0_0:
.long 1065353216 # float 1
.long 1073741824 # float 2
.zero 4
.zero 4
.text
.globl main_opaque_
.align 16, 0x90
.type main_opaque_,@function
main_opaque_: # @main_opaque_
# BB#0: # %entry
subq $40, %rsp ### Add 40 bytes to stack
movabsq $.LCPI0_0, %rax ### Move LCPI0_0 pointer to rax
vmovaps (%rax), %xmm0 ### Load 16 bytes from *LCPI0_0, store in xmm0
vmovaps %xmm0, (%rsp) # 16-byte Spill ### Store xmm0 contents on stack at rsp
vmovq %xmm0, 32(%rsp) ### Move quadword (8 bytes, floats 1 and 2?) to RSP + 32
movabsq $print_vec2_, %rax ### load print_vec2_ addr into rax
leaq 24(%rsp), %rdi ### Load RSP + 24 (float 1?) into rdi
leaq 32(%rsp), %rsi ### Load RSP + 32 (float 2?) into rsi
callq *%rax ### Call print_vec2_
vmovq 24(%rsp), %xmm0 ### Load float 1 and 2 into xmm0, clear high quadword
vcmpeqps (%rsp), %xmm0, %xmm0 # 16-byte Folded Reload ### compare floats 1 and 2 and xmm0, store result in xmm0
vpmovzxdq %xmm0, %xmm0 ### zero extend to 64-byte integers in xmm0
vpextrq $1, %xmm0, %rax ### Get quadword offset 1, store in rax
cltq ### sign extend rax???
vmovq %rax, %xmm1 ### Move quadword to xmm1
vmovq %xmm0, %rax ### Move xmm0 to rax
cltq
vmovq %rax, %xmm0
vpunpcklqdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0]
vpextrb $0, %xmm0, %ecx
vpextrb $8, %xmm0, %eax
andl %ecx, %eax
# kill: AL<def> AL<kill> EAX<kill>
addq $40, %rsp ### restore stack pointer
ret
================================================== Called C++ code =================================================================
static void print_vec2(Vec2f* ret, Vec2f* x)
{
conPrint(toString(*x));
*ret = *x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment