Efficient floating-point number handling for dynamically typed scripting languages

Shiro Kawai
{"title":"Efficient floating-point number handling for dynamically typed scripting languages","authors":"Shiro Kawai","doi":"10.1145/1408681.1408687","DOIUrl":null,"url":null,"abstract":"Typical implementations of dynamically typed languages treat floating-point numbers, or flonums, in a \"boxed\" form, since those numbers don't fit in a natural machine word if a few bits in the word are reserved for type tags. The naïve implementations allocate every instance of flonums in the heap, thus incur large overhead on numerically intensive computations. Compile-time type inference could eliminate boxing of some flonums, but it would be costly for highly dynamic scripting languages, in which a compiler runs every time a script is executed.\n We suggest two modified stack machine architectures that avoid heap allocations for most intermediate flonums, and can be relatively easily retrofitted to existing stack-based VMs. The basic idea is to have an arena for intermediate flonums that works as a part of extended stack or as a nursery. Like typical VMs, flonums are tagged pointers that point to native floating-point numbers, but when a new flonum is pushed onto the VM's stack, it actually points to a native floating-point number placed in the arena. Heap allocation only occurs when the flonum pointer needs to be moved to the heap. The two architectures differ in the strategies to manage the arena.\n We implemented and evaluated those strategies in a Scheme implementation\"Gauche.\" Both strategies showed 30%-140% speed up in numerical computation intensive benchmarks, eliminating 99.8% of heap-allocation of intermediate flonums, with little penalty in non-numerical benchmarks. Profiling showed the speed improvement came from the elimination of flonum allocation and garbage collection.","PeriodicalId":344101,"journal":{"name":"Dynamic Languages Symposium","volume":"66 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2008-07-08","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"2","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"Dynamic Languages Symposium","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1145/1408681.1408687","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 2

Abstract

Typical implementations of dynamically typed languages treat floating-point numbers, or flonums, in a "boxed" form, since those numbers don't fit in a natural machine word if a few bits in the word are reserved for type tags. The naïve implementations allocate every instance of flonums in the heap, thus incur large overhead on numerically intensive computations. Compile-time type inference could eliminate boxing of some flonums, but it would be costly for highly dynamic scripting languages, in which a compiler runs every time a script is executed. We suggest two modified stack machine architectures that avoid heap allocations for most intermediate flonums, and can be relatively easily retrofitted to existing stack-based VMs. The basic idea is to have an arena for intermediate flonums that works as a part of extended stack or as a nursery. Like typical VMs, flonums are tagged pointers that point to native floating-point numbers, but when a new flonum is pushed onto the VM's stack, it actually points to a native floating-point number placed in the arena. Heap allocation only occurs when the flonum pointer needs to be moved to the heap. The two architectures differ in the strategies to manage the arena. We implemented and evaluated those strategies in a Scheme implementation"Gauche." Both strategies showed 30%-140% speed up in numerical computation intensive benchmarks, eliminating 99.8% of heap-allocation of intermediate flonums, with little penalty in non-numerical benchmarks. Profiling showed the speed improvement came from the elimination of flonum allocation and garbage collection.
查看原文
分享 分享
微信好友 朋友圈 QQ好友 复制链接
本刊更多论文
动态类型脚本语言的高效浮点数处理
动态类型语言的典型实现将浮点数或flonums以“盒装”形式处理,因为如果单词中的一些位保留给类型标记,这些数字就不适合自然的机器单词。naïve实现在堆中分配每个flonums实例,因此在数字密集型计算上产生很大的开销。编译时类型推断可以消除一些flonums的装箱,但是对于高度动态的脚本语言来说,这将是代价高昂的,在这种语言中,每次执行脚本时都会运行编译器。我们建议采用两种改进的堆栈机器架构,它们可以避免大多数中间空间的堆分配,并且可以相对容易地改造到现有的基于堆栈的vm。基本的想法是为中间菌群提供一个舞台,作为扩展堆栈的一部分或作为苗圃。像典型的VM一样,flonum是指向本机浮点数的标记指针,但是当一个新的flonum被压入VM的堆栈时,它实际上指向放置在竞技场中的本机浮点数。堆分配仅在需要将浮动指针移动到堆时发生。这两种体系结构在管理竞技场的策略上有所不同。我们在Scheme实现“Gauche”中实现并评估了这些策略。这两种策略在数值计算密集型基准测试中都显示出30%-140%的速度提升,消除了99.8%的中间堆分配,在非数值基准测试中几乎没有损失。分析显示,速度的提高来自于消除了flonum分配和垃圾收集。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 去求助
来源期刊
自引率
0.00%
发文量
0
期刊最新文献
Optimizing MATLAB feval with dynamic techniques Whalesong: running racket in the browser All about the with statement in JavaScript: removing with statements in JavaScript applications Type refinement for static analysis of JavaScript TeJaS: retrofitting type systems for JavaScript
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
现在去查看 取消
×
提示
确定
0
微信
客服QQ
Book学术公众号 扫码关注我们
反馈
×
意见反馈
请填写您的意见或建议
请填写您的手机或邮箱
已复制链接
已复制链接
快去分享给好友吧!
我知道了
×
扫码分享
扫码分享
Book学术官方微信
Book学术文献互助
Book学术文献互助群
群 号:481959085
Book学术
文献互助 智能选刊 最新文献 互助须知 联系我们:info@booksci.cn
Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。
Copyright © 2023 Book学术 All rights reserved.
ghs 京公网安备 11010802042870号 京ICP备2023020795号-1