一句话:提出 self-tagging:用可逆按位变换将浮点值与类型信息叠加在单字中,避免堆分配且性能影响小。
动态语言需在运行时对象携带类型信息,使 IEEE754 浮点数难以高效表示;tagged pointers 需堆分配所有 float,NaN/NuN-boxing 增加类型检查开销。提出 self-tagging:用可逆按位变换把浮点数映射为含类型信息的标记值,将值与类型叠加在单个机器字中;因只能覆盖部分浮点表示,它利用浮点数的非均匀分布避免常见浮点堆分配。作者在两种 Scheme 编译器和四种微架构上评估,并与现有三种编码比较。实验表明,该方法几乎消除所有浮点数堆分配,浮点密集基准性能良好,对其他基准影响可忽略。
Dynamic and polymorphic languages attach information, such as types, to run time objects, and therefore adapt the memory layout of values to include space for this information. This makes it difficult to efficiently implement IEEE754 floating-point numbers as this format does not leave an easily accessible space to store type information. The three main floating-point number encodings in use today, tagged pointers, NaN-boxing, and NuN-boxing, have drawbacks. Tagged pointers entail a heap allocation of all float objects, and NaN/NuN-boxing puts additional run time costs on type checks and the handling of other objects. This paper introduces self-tagging, a new approach to object tagging that uses an invertible bitwise transformation to map floating-point numbers to tagged values that contain the correct type information at the correct position in their bit pattern, superimposing both their value and type information in a single machine word. Such a transformation can only map a subset of all floats to correctly typed tagged values, hence self-tagging takes advantage of the non-uniform distribution of floating point numbers used in practice to avoid heap allocation of the most frequently encountered floats. Variants of self-tagging were implemented in two distinct Scheme compilers and evaluated on four microar¬chitectures to assess their performance and compare them to tagged pointers, NaN-boxing, and NuN-boxing. Experiments demonstrate that, in practice, the approach eliminates heap allocation of nearly all floating-point numbers and provides good execution speed of float-intensive benchmarks in Scheme with a negligible performance impact on other benchmarks, making it an attractive alternative to tagged pointers, alongside NaN-boxing and NuN-boxing.