6 ms·
You wrote this on your repo > Extending short => int is more expensive than short => ushort => uint => int Can you explain why
by belinder 3y ago
You wrote this on your repo
> Extending short => int is more expensive than short => ushort => uint => int
Can you explain why
- ygra 3y agoOne results in MOVSX, the other in MOVZX [1]. The difference thus is sign/zero extension when moving to the larger register. However, they seem to perform pretty much identical if I'm reading Agner Fog's instruction tables correctly. [1] https://sharplab.io/#v2:C4LghgzgtgPgAgJgIwFgBQcDMACR2DC2A3utmbjnEgGzYCWAdsNgLIAUEAFgPYBOzEAJTYAvAD5sEANylyWXDXpNWCDj36Th47G0bBBbAK56Dhrn32SZaAL5A=== https://sharplab.io/#v2:C4LghgzgtgPgAgJgIwFgBQcDMACR2DC2A3ut... EDIT: Ah, the other reply notes that this is likely only visible in a method that also does calculations and thus keeps those values in registers.
- anonymoushn 3y agoif the value starts out in a register, short => int is a sign-extend instruction. short -> ushort -> int is 0 instructions.
- buybackoff 3y agoThe sibling comments said it sooner and better