Created
January 26, 2022 10:43
-
-
Save badamczewski/7aeb58b67b600241431c73d2f7fd8d9b to your computer and use it in GitHub Desktop.
Nullable
This file contains hidden or 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
public int? A(int? x, int? y) { | |
int? sum = 0; | |
for(int i = 0; i < 1000; i++) | |
sum += x + y; | |
return sum.Value; | |
} | |
public int? B(int? x, int? y) { | |
int? sum = 0; | |
var h = x + y; | |
for(int i = 0; i < 1000; i++) | |
sum += h; | |
return sum.Value; | |
} | |
# C# 9.0 .NET: 6.0.0 | |
# Instruction Count: 49; Code Size: 148 | |
Nullable`1 A(Nullable`1, Nullable`1): | |
0440: sub rsp, 28h # stack.push_times(5) | |
0444: mov [rsp+38h], rdx # Memory[rsp+38h] = rdx | |
0449: mov [rsp+40h], r8 # Memory[rsp+40h] = r8 | |
# int? sum = 0; | |
044E: xor eax, eax # eax = 0 | |
0450: mov edx, 1 # edx = 1 | |
# for(int i = 0; i < 1000; i++) | |
0455: xor ecx, ecx # ecx = 0 | |
# sum += x + y; | |
┌──────────>0457: movzx r8d, byte ptr [rsp+38h] | |
│ 045D: mov r9d, [rsp+3Ch] # r9d = Memory[rsp+3Ch] | |
│ 0462: movzx r10d, byte ptr [rsp+40h] | |
│ 0468: mov r11d, [rsp+44h] # r11d = Memory[rsp+44h] | |
│ 046D: movzx r8d, r8b | |
│ 0471: movzx r10d, r10b | |
│ 0475: test r10d, r8d # if(r10d & r8d != 0) | |
│ ┌────◦0478: jne short 0482 ⇣ # goto 7FFBBA970482 | |
│ │ 047A: xor r8d, r8d # r8d = 0 | |
│ │ 047D: xor r10d, r10d # r10d = 0 | |
│ │ ┌──◦0480: jmp short 048E ⇣ # goto 7FFBBA97048E | |
│ └─┼──>0482: add r9d, r11d # r9d += r11d | |
│ │ 0485: mov r10d, r9d # r10d = r9d | |
│ │ 0488: mov r8d, 1 # r8d = 1 | |
│ └──>048E: movzx edx, dl | |
│ 0491: movzx r8d, r8b | |
│ 0495: test r8d, edx # if(r8d & edx != 0) | |
│ ┌──────◦0498: jne short 04A5 ⇣ # goto 7FFBBA9704A5 | |
│ │ 049A: xor r10d, r10d # r10d = 0 | |
│ │ 049D: movzx edx, r10b | |
│ │ 04A1: xor eax, eax # eax = 0 | |
│ │ ┌◦04A3: jmp short 04AD ⇣ # goto 7FFBBA9704AD | |
│ └─────┼>04A5: add eax, r10d # eax += r10d | |
│ │ 04A8: mov edx, 1 # edx = 1 | |
│ │ # for(int i = 0; i < 1000; i++) | |
│ └>04AD: inc ecx # ecx++ | |
│ # for(int i = 0; i < 1000; i++) | |
│ 04AF: cmp ecx, 3E8h # if(ecx < 1000) | |
└──────────◦04B5: jl short 0457 ⇡ # └> goto 7FFBBA970457 | |
# return sum.Value; | |
04B7: test dl, dl # if(dl & dl == 0) | |
┌────────◦04B9: je short 04CE ⇣ # goto 7FFBBA9704CE | |
│ 04BB: mov [rsp+24h], eax # Memory[rsp+24h] = eax | |
│ 04BF: mov byte ptr [rsp+20h], 1 # byte ptr [rsp+20h] = 1 | |
│ 04C4: mov rax, [rsp+20h] # rax = Memory[rsp+20h] | |
│ 04C9: add rsp, 28h # stack.pop_times(5) | |
│ 04CD: ret # return; | |
│ # return sum.Value; | |
└────────>04CE: call System.ThrowHelper.ThrowInvalidOperationException_InvalidOperation_NoValue() 44F8 ↷ | |
04D3: int 3 | |
# Instruction Count: 51; Code Size: 147 | |
Nullable`1 B(Nullable`1, Nullable`1): | |
0500: sub rsp, 28h # stack.push_times(5) | |
0504: mov [rsp+38h], rdx # Memory[rsp+38h] = rdx | |
0509: mov [rsp+40h], r8 # Memory[rsp+40h] = r8 | |
# int? sum = 0; | |
050E: xor eax, eax # eax = 0 | |
0510: mov edx, 1 # edx = 1 | |
# var h = x + y; | |
0515: movzx ecx, byte ptr [rsp+38h] | |
051A: mov r8d, [rsp+3Ch] # r8d = Memory[rsp+3Ch] | |
051F: movzx r9d, byte ptr [rsp+40h] | |
0525: mov r10d, [rsp+44h] # r10d = Memory[rsp+44h] | |
052A: movzx ecx, cl | |
052D: movzx r9d, r9b | |
0531: test r9d, ecx # if(r9d & ecx != 0) | |
┌──◦0534: jne short 053D ⇣ # goto 7FFBBA97053D | |
│ 0536: xor ecx, ecx # ecx = 0 | |
│ 0538: xor r9d, r9d # r9d = 0 | |
┌───┼──◦053B: jmp short 0546 ⇣ # goto 7FFBBA970546 | |
│ └──>053D: add r8d, r10d # r8d += r10d | |
│ 0540: mov r9d, r8d # r9d = r8d | |
│ 0543: movzx ecx, dl | |
│ # for(int i = 0; i < 1000; i++) | |
└──────>0546: xor r8d, r8d # r8d = 0 | |
0549: movzx ecx, cl | |
# sum += h; | |
┌──────────>054C: mov r10d, eax # r10d = eax | |
│ 054F: movzx edx, dl | |
│ 0552: test ecx, edx # if(ecx & edx != 0) | |
│ ┌────◦0554: jne short 0561 ⇣ # goto 7FFBBA970561 | |
│ │ 0556: xor r10d, r10d # r10d = 0 | |
│ │ 0559: movzx edx, r10b | |
│ │ 055D: xor eax, eax # eax = 0 | |
│ │ ┌◦055F: jmp short 056A ⇣ # goto 7FFBBA97056A | |
│ └───┼>0561: lea eax, [r10+r9] # eax = r10+r9 | |
│ │ 0565: mov edx, 1 # edx = 1 | |
│ │ # for(int i = 0; i < 1000; i++) | |
│ └>056A: inc r8d # r8d++ | |
│ # for(int i = 0; i < 1000; i++) | |
│ 056D: cmp r8d, 3E8h # if(r8d < 1000) | |
└──────────◦0574: jl short 054C ⇡ # └> goto 7FFBBA97054C | |
# return sum.Value; | |
0576: test dl, dl # if(dl & dl == 0) | |
┌────────◦0578: je short 058D ⇣ # goto 7FFBBA97058D | |
│ 057A: mov [rsp+24h], eax # Memory[rsp+24h] = eax | |
│ 057E: mov byte ptr [rsp+20h], 1 # byte ptr [rsp+20h] = 1 | |
│ 0583: mov rax, [rsp+20h] # rax = Memory[rsp+20h] | |
│ 0588: add rsp, 28h # stack.pop_times(5) | |
│ 058C: ret # return; | |
│ # return sum.Value; | |
└────────>058D: call System.ThrowHelper.ThrowInvalidOperationException_InvalidOperation_NoValue() 44F8 ↷ | |
0592: int 3 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment