KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
When adding an int32 to a 64-bit native int , does the CLR sign-extend or zero-extend the 32-bit integer? And most importantly: based on what information does it make this choice? I am writing a .NET compiler and have read the ECMA specification throughly, but could not find an answer. The CLI supports only a subset of these types in its operations upon values stored on its evaluation stack: int32 , int64 , and native int . -- ECMA 335 , Section I 12.1: Supported data types Since the values on the evaluation stack have no information on their signedness, instructions for which the signedness of the operands matter have two variants: one for signed and one for unsigned integers. The add , sub and mul instructions (those that don't check for overflow) don't need to care about the signedness of the operands as long as the operands are the same size, and therefore have only a single variant. However, the operands are not always the same size... ECMA 335 , Section III 1.5: Operand type table states that an int32 and a native int can be added, subtracted, multiplied and divided. The result is again a native int . On a 64-bit system, a native int is 64 bits wide. ldc.i4.0 // Load int32 0 conv.i // Convert to (64-bit) native int ldc.i4.m1 // Load int32 -1 add // Add native int 0 and int32 0xFFFFFFFF together So what would be the result here? Note that, according to the specification, the runtime does not need to track the exact types or the si
Tags (comma-separated)
Save Edits
Cancel