“ ceq”与“ ceq”之间的区别在于MSIL命令和对象。 [英] Difference between the "ceq" MSIL command and object.InternalEquals

查看:101
本文介绍了“ ceq”与“ ceq”之间的区别在于MSIL命令和对象。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ILDASM和Reflector中进行了挖掘,发现:

I was digging around in ILDASM and Reflector as found that:


  1. ==已编译为 ceq MSIL命令

  2. object.Equals保持不变

  3. object.Equals调用
    object.InternalEquals

This question showed me how to find out how InternalEquals might be implemented i.e. in .cpp class (or whatever, somewhere in the CLR).

我的问题是:

ceq变成什么? .cpp类中的另一个方法?即它们是完全不同的代码吗?因此,尽管==和Equals的默认行为看起来是相同的,但是代码是不同的?

What does ceq become? Another method in a different .cpp class? I.e. they are completely different peices of code? So although the default behaviour of == and Equals appears to be the same, it is different code?

推荐答案

==运算符并不总是会转换为ceq。类型可以使用operator ==()重载。例如,System.Decimal会这样做,由于所有运算符的实现都是非竞争性的,因此它会使所有运算符过载,并且抖动对类型没有特别的了解(编译器知道)。

The == operator doesn't always get translated to ceq. A type can overload it with operator==(). System.Decimal does this for example, it overloads all of the operators since their implementation is untrivial and the jitter doesn't have special knowledge of the type (the compiler does).

您将使用Reflector作为Decimal.op_Equality()方法找到它。这将导致您进入FCallCompare,该方法是使用MethodImplOptions.InternalCall归属的方法。这些方法很特殊,抖动对它们有秘密的了解。您可以通过Rotor中的clr / src / vm / ecall.cpp源代码文件找到其实现。它包含一个所有内部调用函数的表,抖动通过方法名称查找表条目。然后将表中提供的相应C ++函数的地址编译为调用指令。请注意,自Rotor发布以来,函数名称已更改,请搜索FCallAdd,它是表中的下一个条目。这将带您进入COMDecimal :: Compare。

You'll find it back with Reflector as the Decimal.op_Equality() method. Which leads you to FCallCompare, a method that's attributed with MethodImplOptions.InternalCall. These kind of methods are special, the jitter has secret knowledge of them. You can find their implementation through the clr/src/vm/ecall.cpp source code file in Rotor. It contains a table of all internal call functions, the jitter looks up the table entry by the method name. Then compiles the address of the corresponding C++ function as provided in the table into the call instruction. Beware that the function name was changed since the Rotor release, search for FCallAdd, it it the next entry in the table. Which takes you to COMDecimal::Compare. Which takes you to the comdecimal.cpp source code file.

x86和x64抖动知道如何将ceq操作码直接转换为机器代码而不需要帮助函数,它会带您到comdecimal.cpp源代码文件。内联生成本机指令。实际生成的代码取决于要比较的值的类型。而目标,x64抖动使用SSE指令,x86使用FPU指令比较浮点值。当然,其他抖动也会以不同的方式实现它们。

The x86 and x64 jitters know how to convert the ceq opcode to machine code directly without needing a helper function, it generates the native machine instructions inline. Actual generated code depends on the type of the values being compared. And the target, the x64 jitter uses SSE instructions, the x86 uses FPU instructions to compare floating point values. Other jitters will implement them differently yet of course.

像Object.InternalEquals()这样的辅助函数也是内部方法,就像FCallCompare一样。您将使用相同的策略来查找实现。

A helper function like Object.InternalEquals() is also an internal method, just like FCallCompare. You'd use the same strategy to find the implementation.

这篇关于“ ceq”与“ ceq”之间的区别在于MSIL命令和对象。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆