Skip to content

Instantly share code, notes, and snippets.

@MrSmith33
Created April 13, 2018 16:34
Show Gist options
  • Save MrSmith33/f2e36deef54997f7ee6d88544f6bf03d to your computer and use it in GitHub Desktop.
Save MrSmith33/f2e36deef54997f7ee6d88544f6bf03d to your computer and use it in GitHub Desktop.
Release vs Debug build
i32 sign(i32 number)
{
i32 result;
if (number < 0) result = 0-1;
else if (number > 0) result = 1;
else result = 0;
return result;
}
// Release
//-------------------------------------------------------------
// Generated from binary IR
function i32 $sign () {
| @start:0 instr[0..3]
1| %0 = i32 o_param uses [ i1 %1 i1 %2]
2| %1 = i1 o_icmp l i32 %0, i64 0 uses [ instr.3]
3| branch i1 %1 @then_1, @else_1
| @then_1:1 instr[4..5] in[@start]
5| jmp @blk_2
| @else_1:2 instr[6..8] in[@start]
7| %2 = i1 o_icmp g i32 %0, i64 0 uses [ instr.8]
8| branch i1 %2 @then_2, @else_2
| @then_2:3 instr[9..10] in[@else_1]
10| jmp @blk_1
| @else_2:4 instr[11..12] in[@else_1]
12| jmp @blk_1
| @blk_1:5 instr[13..14] in[@then_2, @else_2]
13| %4 = i32 phi.1(i64 1 @3, i64 0 @4) uses [ i32 %3]
14| jmp @blk_2
| @blk_2:6 instr[15..16] in[@then_1, @blk_1]
15| %3 = i32 phi.0(i32 -1 @1, i32 %4 @5) uses [ instr.16]
16| return i32 %3
}
// Code
83 F9 00 0F 8C 05 00 00 00 E9 0A 00 00 00 B8 FF
FF FF FF E9 1D 00 00 00 83 F9 00 0F 8F 05 00 00
00 E9 0A 00 00 00 B8 01 00 00 00 E9 05 00 00 00
B8 00 00 00 00 C3
0: 83 f9 00 cmp ecx,0x0
3: 0f 8c 05 00 00 00 jl 0xe
9: e9 0a 00 00 00 jmp 0x18
e: b8 ff ff ff ff mov eax,0xffffffff
13: e9 1d 00 00 00 jmp 0x35
18: 83 f9 00 cmp ecx,0x0
1b: 0f 8f 05 00 00 00 jg 0x26
21: e9 0a 00 00 00 jmp 0x30
26: b8 01 00 00 00 mov eax,0x1
2b: e9 05 00 00 00 jmp 0x35
30: b8 00 00 00 00 mov eax,0x0
35: c3 ret
// Debug
//-------------------------------------------------------------
// Generated from binary IR
function i32 $sign () {
| @start:0 instr[0..5]
1| %0 = i32 o_param
2| o_store i32 0, stack(1)
3| %1 = i32 o_load stack(0) uses [ i1 %2]
4| %2 = i1 o_icmp l i32 %1, i64 0 uses [ instr.5]
5| branch i1 %2 @then_1, @else_1
| @then_1:1 instr[6..8] in[@start]
7| o_store i32 -1, stack(1)
8| jmp @blk_2
| @else_1:2 instr[9..12] in[@start]
10| %3 = i32 o_load stack(0) uses [ i1 %4]
11| %4 = i1 o_icmp g i32 %3, i64 0 uses [ instr.12]
12| branch i1 %4 @then_2, @else_2
| @then_2:3 instr[13..15] in[@else_1]
14| o_store i64 1, stack(1)
15| jmp @blk_1
| @else_2:4 instr[16..18] in[@else_1]
17| o_store i64 0, stack(1)
18| jmp @blk_1
| @blk_1:5 instr[19..20] in[@then_2, @else_2]
20| jmp @blk_2
| @blk_2:6 instr[21..23] in[@then_1, @blk_1]
22| %5 = i32 o_load stack(1) uses [ instr.23]
23| return i32 %5
}
// Code
48 89 4C 24 08 48 83 EC 08 C7 44 24 00 00 00 00
00 8B 44 24 10 83 F8 00 0F 8C 05 00 00 00 E9 0D
00 00 00 C7 44 24 00 FF FF FF FF E9 27 00 00 00
8B 44 24 10 83 F8 00 0F 8F 05 00 00 00 E9 0D 00
00 00 C7 44 24 00 01 00 00 00 E9 08 00 00 00 C7
44 24 00 00 00 00 00 8B 44 24 00 48 83 C4 08 C3
0: 48 89 4c 24 08 mov QWORD PTR [rsp+0x8],rcx
5: 48 83 ec 08 sub rsp,0x8
9: c7 44 24 00 00 00 00 00 mov DWORD PTR [rsp+0x0],0x0
11: 8b 44 24 10 mov eax,DWORD PTR [rsp+0x10]
15: 83 f8 00 cmp eax,0x0
18: 0f 8c 05 00 00 00 jl 0x23
1e: e9 0d 00 00 00 jmp 0x30
23: c7 44 24 00 ff ff ff ff mov DWORD PTR [rsp+0x0],0xffffffff
2b: e9 27 00 00 00 jmp 0x57
30: 8b 44 24 10 mov eax,DWORD PTR [rsp+0x10]
34: 83 f8 00 cmp eax,0x0
37: 0f 8f 05 00 00 00 jg 0x42
3d: e9 0d 00 00 00 jmp 0x4f
42: c7 44 24 00 01 00 00 00 mov DWORD PTR [rsp+0x0],0x1
4a: e9 08 00 00 00 jmp 0x57
4f: c7 44 24 00 00 00 00 00 mov DWORD PTR [rsp+0x0],0x0
57: 8b 44 24 00 mov eax,DWORD PTR [rsp+0x0]
5b: 48 83 c4 08 add rsp,0x8
5f: c3 ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment