Consider:
using System.Runtime.CompilerServices;
class Program
{
static void Main()
{
Mod(123);
Cast(123);
And(123);
}
[MethodImpl(MethodImplOptions.NoInlining)] static byte Cast(uint i) => (byte)(i);
[MethodImpl(MethodImplOptions.NoInlining)] static byte And(uint i) => (byte)(i & 0xFF);
[MethodImpl(MethodImplOptions.NoInlining)] static byte Mod(uint i) => (byte)(i % 256);
}
For Cast and And I get:
0FB6C1 movzx rax, cl
C3 ret
but for Mod I get:
81E1FF000000 and ecx, 255
0FB6C1 movzx rax, cl
C3 ret
Is there a reason that extra and instruction needs to exist?
category:cq
theme:basic-cq
skill-level:intermediate
cost:medium