Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualNypyren

Posted 28 February 2013 - 02:57 PM

Here's some C# code and the JIT optimized x86 for it (Debug information, JIT optimizations not suppressed)
struct Vector3
{
	public float x;
	public float y;
	public float z;

	public Vector3(float x, float y, float z)
	{
		this.x = x;
		this.y = y;
		this.z = z;
	}
}

class Program
{
	static void Main(string[] args)
	{
		Vector3 a;
		a.x = 5;

		Console.WriteLine(a.x);
	}
}
Resulting x86:
// Frame setup
00000000  push        ebp 
00000001  mov         ebp,esp 
00000003  push        edi 
00000004  push        esi 
00000005  push        ebx 

// Local variable block allocation
00000006  sub         esp,3Ch

// register push
00000009  mov         esi,ecx

// memset the local variable stack memory to zero
0000000b  lea         edi,[ebp-48h] 
0000000e  mov         ecx,0Fh 
00000013  xor         eax,eax 
00000015  rep stos    dword ptr es:[edi] 

// register pop
00000017  mov         ecx,esi

// Not sure what this stuff is.  It doesn't seem like it's the vector constructor because the call is conditional.
00000019  mov         dword ptr [ebp-3Ch],ecx 
0000001c  cmp         dword ptr ds:[00760B00h],0 
00000023  je          0000002A 
00000025  call        64B54A82 
0000002a  nop 

			Vector3 a;
			a.x = 5;

// Moving the float32 form of 5.0f onto the stack slot containing a.x
0000002b  mov         dword ptr [ebp-48h],40A00000h 

			Console.WriteLine(a.x);
// Push 5.0f
00000032  push        dword ptr [ebp-48h] 

// Call Console.WriteLine(float)
00000035  call        641C5470 
0000003a  nop 
		}
0000003b  nop 

// Frame teardown
0000003c  lea         esp,[ebp-0Ch] 
0000003f  pop         ebx 
00000040  pop         esi 
00000041  pop         edi 
00000042  pop         ebp 
00000043  ret 

#3Nypyren

Posted 28 February 2013 - 02:57 PM

Here's some C# code and the JIT optimized x86 for it (Debug information, JIT optimizations not suppressed)
struct Vector3
{
	public float x;
	public float y;
	public float z;

	public Vector3(float x, float y, float z)
	{
		this.x = x;
		this.y = y;
		this.z = z;
	}
}

class Program
{
	static void Main(string[] args)
	{
		Vector3 a;
		a.x = 5;

		Console.WriteLine(a.x);
	}
}
Resulting x86:
// Frame setup
00000000  push        ebp 
00000001  mov         ebp,esp 
00000003  push        edi 
00000004  push        esi 
00000005  push        ebx 

// Local variable block allocation
00000006  sub         esp,3Ch

// register push
00000009  mov         esi,ecx

// memset the local variable stack memory to zero
0000000b  lea         edi,[ebp-48h] 
0000000e  mov         ecx,0Fh 
00000013  xor         eax,eax 
00000015  rep stos    dword ptr es:[edi] 

// register pop
00000017  mov         ecx,esi

// Not sure what this stuff is.  Possibly constructor?
00000019  mov         dword ptr [ebp-3Ch],ecx 
0000001c  cmp         dword ptr ds:[00760B00h],0 
00000023  je          0000002A 
00000025  call        64B54A82 
0000002a  nop 

			Vector3 a;
			a.x = 5;

// Moving the float32 form of 5.0f onto the stack slot containing a.x
0000002b  mov         dword ptr [ebp-48h],40A00000h 

			Console.WriteLine(a.x);
// Push 5.0f
00000032  push        dword ptr [ebp-48h] 

// Call Console.WriteLine(float)
00000035  call        641C5470 
0000003a  nop 
		}
0000003b  nop 

// Frame teardown
0000003c  lea         esp,[ebp-0Ch] 
0000003f  pop         ebx 
00000040  pop         esi 
00000041  pop         edi 
00000042  pop         ebp 
00000043  ret 

#2Nypyren

Posted 28 February 2013 - 02:51 PM

Here's some C# code and the JIT optimized x86 for it (Debug information, JIT optimizations not suppressed)
struct Vector3
{
	public float x;
	public float y;
	public float z;

	public Vector3(float x, float y, float z)
	{
		this.x = x;
		this.y = y;
		this.z = z;
	}
}

class Program
{
	static void Main(string[] args)
	{
		Vector3 a;
		a.x = 5;

		Console.WriteLine(a.x);
	}
}
Resulting x86:
// Frame setup
00000000  push        ebp 
00000001  mov         ebp,esp 
00000003  push        edi 
00000004  push        esi 
00000005  push        ebx 

// Local variable block allocation
00000006  sub         esp,3Ch

// register push
00000009  mov         esi,ecx

// memset the local variable stack memory to zero
0000000b  lea         edi,[ebp-48h] 
0000000e  mov         ecx,0Fh 
00000013  xor         eax,eax 
00000015  rep stos    dword ptr es:[edi] 

// register pop
00000017  mov         ecx,esi

// Not sure what this stuff is.
00000019  mov         dword ptr [ebp-3Ch],ecx 
0000001c  cmp         dword ptr ds:[00760B00h],0 
00000023  je          0000002A 
00000025  call        64B54A82 
0000002a  nop 

// Initializing vector.
// Notice the constructor code is not being called since the values on the stack are already zero.
			Vector3 a;
			a.x = 5;

// Moving the float32 form of 5.0f onto the stack slot containing a.x
0000002b  mov         dword ptr [ebp-48h],40A00000h 

			Console.WriteLine(a.x);
// Push 5.0f
00000032  push        dword ptr [ebp-48h] 

// Call Console.WriteLine(float)
00000035  call        641C5470 
0000003a  nop 
		}
0000003b  nop 

// Frame teardown
0000003c  lea         esp,[ebp-0Ch] 
0000003f  pop         ebx 
00000040  pop         esi 
00000041  pop         edi 
00000042  pop         ebp 
00000043  ret 

#1Nypyren

Posted 28 February 2013 - 02:50 PM

Here's some C# code and the JIT optimized x86 for it (Debug information, JIT optimizations not suppressed)
struct Vector3
{
	public float x;
	public float y;
	public float z;

	public Vector3(float x, float y, float z)
	{
		this.x = x;
		this.y = y;
		this.z = z;
	}
}

class Program
{
	static void Main(string[] args)
	{
		Vector3 a;
		a.x = 5;

		Console.WriteLine(a.x);
	}
}
Resulting x86:
// Frame setup
00000000  push        ebp 
00000001  mov         ebp,esp 
00000003  push        edi 
00000004  push        esi 
00000005  push        ebx 
// Local variable setup
00000006  sub         esp,3Ch

// register push
00000009  mov         esi,ecx

// memset the local variable stack memory to zero
0000000b  lea         edi,[ebp-48h] 
0000000e  mov         ecx,0Fh 
00000013  xor         eax,eax 
00000015  rep stos    dword ptr es:[edi] 

// register pop
00000017  mov         ecx,esi

// Not sure what this stuff is.
00000019  mov         dword ptr [ebp-3Ch],ecx 
0000001c  cmp         dword ptr ds:[00760B00h],0 
00000023  je          0000002A 
00000025  call        64B54A82 
0000002a  nop 

// Initializing vector.
// Notice the constructor code is not being called since the values on the stack are already zero.
			Vector3 a;
			a.x = 5;

// Moving the float32 form of 5.0f onto the stack slot containing a.x
0000002b  mov         dword ptr [ebp-48h],40A00000h 

			Console.WriteLine(a.x);
// Push 5.0f
00000032  push        dword ptr [ebp-48h] 

// Call Console.WriteLine(float)
00000035  call        641C5470 
0000003a  nop 
		}
0000003b  nop 

// Frame teardown
0000003c  lea         esp,[ebp-0Ch] 
0000003f  pop         ebx 
00000040  pop         esi 
00000041  pop         edi 
00000042  pop         ebp 
00000043  ret 

PARTNERS