-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMItenet-performancePerformance related issuePerformance related issue
Milestone
Description
Description
I have code ported from C that contains passing arguments by pointers, I noticed that if I replace them with passing by reference, it can improve codegeneration.
Code:
using System;
public unsafe class C {
public unsafe struct BIT_DStream_t
{
public nuint bitContainer;
public uint bitsConsumed;
public sbyte* ptr;
public sbyte* start;
public sbyte* limitPtr;
}
public unsafe struct seqState_t
{
public BIT_DStream_t DStream;
}
public void Add(BIT_DStream_t* x)
{
x->bitContainer++;
x->bitsConsumed++;
}
public void Add(ref BIT_DStream_t x)
{
x.bitContainer++;
x.bitsConsumed++;
}
public nuint Test1()
{
var x = new seqState_t();
for (var i = 0; i < 100; i++)
{
Add(&x.DStream);
}
return x.DStream.bitContainer;
}
public nuint Test2()
{
var x = new seqState_t();
for (var i = 0; i < 100; i++)
{
Add(ref x.DStream);
}
return x.DStream.bitContainer;
}
}Test1:
; Method TestConsole8.C:Test1():ulong:this (FullOpts)
G_M000_IG01:
sub rsp, 120
xor eax, eax
mov qword ptr [rsp+0x08], rax
vxorps xmm4, xmm4, xmm4
mov rax, -96
vmovdqa xmmword ptr [rsp+rax+0x70], xmm4
vmovdqa xmmword ptr [rsp+rax+0x80], xmm4
vmovdqa xmmword ptr [rsp+rax+0x90], xmm4
add rax, 48
jne SHORT -5 instr
mov qword ptr [rsp+0x70], rax
G_M000_IG02:
xor eax, eax
align [2 bytes for IG03]
G_M000_IG03:
lea rcx, bword ptr [rsp+0x08]
inc qword ptr [rcx]
add rcx, 8
inc dword ptr [rcx]
inc eax
cmp eax, 100
jl SHORT G_M000_IG03
G_M000_IG04:
mov rax, qword ptr [rsp+0x08]
G_M000_IG05:
add rsp, 120
ret
; Total bytes of code: 95Test2:
; Method TestConsole8.C:Test2():ulong:this (FullOpts)
G_M000_IG01:
G_M000_IG02:
xor eax, eax
xor ecx, ecx
xor edx, edx
align [0 bytes for IG03]
G_M000_IG03:
inc rax
inc ecx
inc edx
cmp edx, 100
jl SHORT G_M000_IG03
G_M000_IG04:
ret
; Total bytes of code: 19Configuration
.NET 8.0.202
Metadata
Metadata
Assignees
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMItenet-performancePerformance related issuePerformance related issue