.net - CLR 中的原生浮点类型用法

标签 .net cil

我发现 CIL 编译器允许输入 native float .但是,CLR 不允许。有什么用吗?它的大小是多少?是否有相应的 .NET 类型?我试图将它实现为一个伪原始类型:

.class public sequential ansi serializable sealed beforefieldinit NativeFloat
  extends System.ValueType
{
  .field assembly native float m_value
}

但是,CLR 不支持这种类型。感谢您的帮助。

编辑:如果你有兴趣,它的 CorElementType 是 26 (0x1a, R)。

最佳答案

来自 CIL ECMA 规范,I.12.1.1 Native size: native int, native unsigned int, O and & :

The native-size types (native int, native unsigned int, O, and &) are a mechanism in the CLI for deferring the choice of a value’s size. These data types exist as CIL types; however, the CLI maps each to the native size for a specific processor. (For example, data type I would map to int32 on a Pentium processor, but to int64 on an IA64 processor.) So, the choice of size is deferred until JIT compilation or runtime, when the CLI has been initialized and the architecture is known. This implies that field and stack frame offsets are also not known at compile time.



现在,话虽如此,native float (与 native int 相反)在 ECMA 规范中没有被提及一次。我能找到的唯一证据是在一些开源 CIL 汇编器中,它们抛出异常,指出它们无法为 native float 生成操作码。 .

如果 Microsoft 的 CIL 编译器确实接受这种类型,我会想象这是 Microsoft 打算实现但最终没有放入 MSIL(CIL 的前身)的功能。此外,如果汇编器确实产生了一个操作码而不是错误消息,我可以想象(尽管再次,这是推测)可能存在 Microsoft 的 CLR 的变体(可能是 .NET Micro Framework 或特定版本的 Silverlight,或其他东西)支持操作码。

另请注意,在上面的规范中,提到了 CLI。 CLR 只是 Microsoft 对 CLI 的实现。

ECMA 规范确实提到了原生浮点类型,但它不是 native float :

F, a floating point value (float32, float64, or other representation supported by the underlying hardware)

关于.net - CLR 中的原生浮点类型用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13961205/

相关文章:

c# - JPEG 压缩无损编码器?

.net - KeyedCollection 是否有一般的具体实现?

c# - 从控制台读取 unicode

.net - MSIL 虚拟地址

.net - BCL 与 CLS 有何关系?

c# - 基于 XSD 的 .Net XML 序列化?

.net - System.ArgumentException 列 <ColumnName> 不属于表

c# - 尝试保存 Emitted 程序集时抛出 NotSupportedException

c# - 使用 Mono.Cecil 从 ByReferenceType 获取通用参数

c# - 如何使用 ILGenerator 设置 ".maxstack"