Create a gist now

Instantly share code, notes, and snippets.

Partially Interruptible version (compared to the Fully Interruptible one)

public static long TestMethod()
{
    long counter = 0;
    for (int i = 0; i < 1000 * 1000; i++)
    {
        for (int j = 0; j < 2000; j++)
        {
            if (i % 10 == 0)
                counter++;
			Console.WriteLine("Inside Inner Loop, counter = {0:N0}", counter);
        }
		Console.WriteLine("After Inner Loop, counter = {0:N0}", counter);
    }
    Console.WriteLine("Thread loop exited cleanly, counter = {0:N0}", counter);
    return counter;
}

Compiling 32 ConsoleApplication.Program::TestMethod, IL size = 96, hsh=0xe6099ccc

; Assembly listing for method ConsoleApplication.Program:TestMethod():long
; Emitting BLENDED_CODE for X64 CPU with AVX
; optimized code
; rsp based frame
; partially interruptible
; Final local variable assignments
;
;  V00 loc0         [V00,T05] (  7,  39  )    long  ->  rsi        
;  V01 loc1         [V01,T06] (  6,  33  )     int  ->  rdi        
;  V02 loc2         [V02,T04] (  4,  52  )     int  ->  rbx        
;  V03 tmp0         [V03,T00] (  9, 126  )     ref  ->  rax        
;  V04 tmp1         [V04,T01] (  3,  96  )     int  ->  rcx        
;  V05 tmp2         [V05,T02] (  2,  64  )     ref  ->  rcx        
;  V06 tmp3         [V06,T03] (  2,  64  )     ref  ->  rdx        
;  V07 tmp4         [V07,T08] (  2,  16  )     ref  ->  rcx        
;  V08 tmp5         [V08,T09] (  2,  16  )     ref  ->  rdx        
;  V09 tmp6         [V09,T10] (  2,   4  )     ref  ->  rcx        
;  V10 tmp7         [V10,T11] (  2,   4  )     ref  ->  rdx        
;  V11 OutArgs      [V11    ] (  1,   1  )  lclBlk (32) [rsp+0x00]  
;  V12 cse0         [V12,T07] (  2,  20  )     int  ->  rbp        
;
; Lcl frame size = 40

G_M25395_IG01:
000000 57                   push     rdi
000001 56                   push     rsi
000002 55                   push     rbp
000003 53                   push     rbx
000004 4883EC28             sub      rsp, 40

G_M25395_IG02:
000008 33F6                 xor      rsi, rsi
00000A 33FF                 xor      edi, edi

G_M25395_IG03:
00000C 33DB                 xor      ebx, ebx
00000E B867666666           mov      eax, 0x66666667
000013 F7EF                 imul     edx:eax, edi
000015 8BC2                 mov      eax, edx
000017 8BE8                 mov      ebp, eax
000019 C1FD02               sar      ebp, 2

G_M25395_IG04:
00001C 8BCD                 mov      ecx, ebp
00001E 8BC1                 mov      eax, ecx
000020 C1E81F               shr      eax, 31
000023 03C8                 add      ecx, eax
000025 8D0C89               lea      ecx, [rcx+4*rcx]
000028 D1E1                 shl      ecx, 1
00002A 8BC7                 mov      eax, edi
00002C 2BC1                 sub      eax, ecx
00002E 85C0                 test     eax, eax
000030 7503                 jne      SHORT G_M25395_IG05
000032 48FFC6               inc      rsi

G_M25395_IG05:
000035 48B920F8DBD0FE070000 mov      rcx, 0x7FED0DBF820
00003F E8FCC0ED5E           call     CORINFO_HELP_NEWFAST
000044 488B0C2580309312     mov      rcx, gword ptr [12933080H]      'Inside Inner Loop, counter = {0:N0}'
00004C 48897008             mov      qword ptr [rax+8], rsi
000050 488BD0               mov      rdx, rax
000053 E808D1FFFF           call     System.Console:WriteLine(ref,ref)
000058 FFC3                 inc      ebx
00005A 81FBD0070000         cmp      ebx, 0x7D0
000060 7CBA                 jl       SHORT G_M25395_IG04

G_M25395_IG06:
000062 48B920F8DBD0FE070000 mov      rcx, 0x7FED0DBF820
00006C E8CFC0ED5E           call     CORINFO_HELP_NEWFAST
000071 488B0C2588309312     mov      rcx, gword ptr [12933088H]      'After Inner Loop, counter = {0:N0}'
000079 48897008             mov      qword ptr [rax+8], rsi
00007D 488BD0               mov      rdx, rax
000080 E8DBD0FFFF           call     System.Console:WriteLine(ref,ref)
000085 FFC7                 inc      edi
000087 81FF40420F00         cmp      edi, 0xF4240
00008D 0F8C79FFFFFF         jl       G_M25395_IG03

G_M25395_IG07:
000093 48B920F8DBD0FE070000 mov      rcx, 0x7FED0DBF820
00009D E89EC0ED5E           call     CORINFO_HELP_NEWFAST
0000A2 488B0C2590309312     mov      rcx, gword ptr [12933090H]      '
Thread loop exited cleanly, counter = {0:N0}'
0000AA 48897008             mov      qword ptr [rax+8], rsi
0000AE 488BD0               mov      rdx, rax
0000B1 E8AAD0FFFF           call     System.Console:WriteLine(ref,ref)
0000B6 488BC6               mov      rax, rsi

G_M25395_IG08:
0000B9 4883C428             add      rsp, 40
0000BD 5B                   pop      rbx
0000BE 5D                   pop      rbp
0000BF 5E                   pop      rsi
0000C0 5F                   pop      rdi
0000C1 C3                   ret      

; Total bytes of code 194, prolog size 8 for method ConsoleApplication.Program:TestMethod():long
; ============================================================
Set code length to 194.
Set Outgoing stack arg area size to 32.
Defining 6 call sites:
    Offset 0x3f, size 5.
    Offset 0x53, size 5.
    Offset 0x6c, size 5.
    Offset 0x80, size 5.
    Offset 0x9d, size 5.
    Offset 0xb1, size 5.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment