Why does Roslyn emit conv.r8 after conv.r.un instruction for casting to float? #49101
-
Hi all! I can't figure out why Roslyn emits |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
It looks like that |
Beta Was this translation helpful? Give feedback.
-
The short answer is that CLI does not support storing unsigned integers on the evaluation stack so you have to clarify whether a given integer is signed or not using specific instructions. (Note: Page number and section references are based on the Microsoft-specific variant of ECMA-335. I don't have a super good reason for using it specifically, but I thought I should point it out. This version isn't officially published anymore as far as I'm aware, but you can find it via The Wayback Machine.) Partition I §12.3.2.1 The Evaluation Stack (pg 88) describes the evaluation stack, and specifically it lists what can be represented on the stack:
It's a pretty short list. Two things to note here: The first thing to note is the lack of unsigned types. The standard clarifies this after this list:
The other thing to notice is this
Basically So with that knowledge, let's look at the way those instructions are defined. Both are defined in Partiion III §3.27 Both have a stack transition of
The final thing to know is how "convert" is defined in this context. The behavior of converting between values of different types is defined in Partition III §1.5 Table 8: Conversion Operations. A particular thing to note is the conversion between So with all of that, your IL can be read as:
If you want to think of it this way: |
Beta Was this translation helpful? Give feedback.
It looks like that
conv.r.un
behaves like a prefix, not a full instruction. It specifies the source to be unsigned integer, but doesn't specify the destination size. Onlyr8
means double.