转自:http://webkit.sed.hu/node/17

Technical discussion part 2: constructing constants

Among other things, one interesting advantage of dynamically generated code is that constants can be embedded into the instruction stream. Think about it: there are several constants (usually pointers), which are unknown at compile time, but behave as constant once a value is assigned to them. Those constants can be embedded into the generated code, so several load-from-memory operations can be eliminated. WebKit JIT goes one step further: you can also rewrite constants which are not even known at JIT compilation time. Those constants typically hold cached values used by some fast cases.

On x86 based machines, these features are rather easy to implement, since instructions have a 32 bit immediate field, which is enough to hold any immediate value. On ARM, we only have an 8 bit immediate field, which can be rotated by an even number. Therefore, we sometimes need 4 instructions to create a 32 bit number. Fortunately, there is another way to access constants. The program counter (pc) is a regular register on ARM, which points to the instruction address plus 8. Using the pc, we can load constants that are at most 4 kbyte away from the current instruction. The constants are grouped together to form a constant pool and its entry is protected by a jump instruction. The constant pool is aligned to 32 bytes to aid caching. The drawback of this solution is that memory loads are expensive operations, especially when they cause cache misses.

[jump after the constant pool][constant 0][constant 1]...[constant n]
Constant pool

In our ARM JIT implementation, the constant generator was made as smart as possible. In other words, we tried to find the right balance between speed (a slow algorithm is not suitable for a JIT compiler) and efficiency (use the least number of instructions to generate a specific constant). Furthermore, those constants, which are not known at JIT compilation time, are placed into the constant pool as well.

Finally, let me share some technical details with you. We decided to use the following algorithm:

step 1: it detects whether the constant is an ARM constant (rotated 8 bit immediate value)
step 2: it detects whether the constant can be encoded by two data processing instructions
step 3: it bails out, the constant is simply pushed onto the constant pool

Since one of our primary concern is speed, we tried to avoid loops: our implementation does not need any loops if the constant itself is an ARM constant. If it is not an ARM constant, we employ a single loop to find an 8 zero bit sequence (if the the instruction can be encoded as two data processing instruction, it must have 8 continual zero bits somewhere). This 8 bits are rotated to the least significant byte (bit 0-7). The search iteration took at most 16 steps. No other loops are needed for our algorithm.

zaheer (not verified) - 11/13/2009 - 18:00

Hi Zoltan, Thanks for all this great information.. I have one question, is there a way to we can see the Javascript->Bytecode->MacroAssembler->JIT mapping (e.g in inspector), if not whats the alternative..

zoltan.herczeg - 11/17/2009 - 15:04

Hi Zaheer. Unfortunately there is no such thing in WebKit (at least I am not aware of such tool). You can get a ByteCode dump using the command line JavaScript execution tool (pass -d option to jsc).

SFX: constructing constants相关推荐

  1. Codeforces Beta Round #96 (Div. 1) D. Constants in the language of Shakespeare 贪心

    D. Constants in the language of Shakespeare Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codef ...

  2. 常量和指针(Pointers and Constants)

    常量和指针(Pointers and Constants) --const 修饰的指针解惑 一般遇到用const修饰的常量涉及到指针就会比较麻烦,容易把头搞晕,有个简单的技巧就是从右向左看,下面我举例 ...

  3. Codeforces Educational 38 C. Constructing Tests ( 数学公式推导+暴力)

    C. Constructing Tests time limit per test 1 second memory limit per test 256 megabytes input standar ...

  4. hdu1025 Constructing Roads In JGShining#39;s Kingdom(二分+dp)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1025 Problem ...

  5. 深入浅出OOP(五): C#访问修饰符(Public/Private/Protected/Internal/Sealed/Constants)

    访问修饰符(或者叫访问控制符)是面向对象语言的特性之一,用于对类.类成员函数.类成员变量进行访问控制.同时,访问控制符也是语法保留关键字,用于封装组件. Public, Private, Protec ...

  6. 八十五、store数据,actionCreators 与 constants 的拆分和redux-immutable的使用

    2020/11/22. 周日.今天又是奋斗的一天. @Author:Runsen 你是否将所有 JavaScript 脚本放在一个大文件中,并在所有页面上使用这个文件?如果是这样,你可能需要考虑使用代 ...

  7. HDU1102 Constructing Roads 最小生成树

    点击打开链接 Online Judge Online Exercise Online Teaching Online Contests Exercise Author F.A.Q Hand In Ha ...

  8. [C++] 用Xcode来写C++程序[3] Constants

    用Xcode来写C++程序[3] Constants 以下是一些基本数据的含义: 75 // int 75u // unsigned int 75l // long 75ul // unsigned ...

  9. 关于压缩工具 7z(7-zip) 如何创建自释放档案(选项 -sfx 的解读)

    文章目录 一.选项 -sfx 介绍 二.自释放安装模块 三.创建自释放档案(创建安装程序) (一)安装程序配置文件格式 (二)配置文件示例 四.创建自释放档案示例 (一)添加 *.txt 文件到自释放 ...

最新文章

  1. python画直方图代码-Python使用Plotly绘图工具,绘制直方图
  2. CPropertyPage::OnSetActive()和OnKillActive()函数:属性页切换时的处理函数
  3. 本田da屏怎么进wince系统_东风本田LIFE“来福酱”上市
  4. 关于echars中雷达图的一些配置
  5. 大数据WEB阶段(六)MySql详解(二)
  6. 【转】 Pro Android学习笔记(二九):用户界面和控制(17):include和merge
  7. 类成员函数可以返回该类的实例吗_关于类的理解
  8. CodeGear 出品 Delphi for PHP
  9. PHP+jQuery.photoClip.js支持手势的图片裁剪上传实例
  10. rtmp/rtsp直播播放器选择
  11. window.open用法详解
  12. 侯捷 C++ 课程系列视频 | 侯捷 STL 视频
  13. Xilinx ZCU106开发详解(Xilinx Zynq UltraScale+ MPSoC)
  14. iOS调试_Couldn't load project
  15. 自定义圆形、半圆形ProgressBar
  16. 基于Echarts实现可视化数据大屏分析大屏监控系统
  17. TextBoxes++
  18. Fiddler抓包6-打断点(bpu)
  19. CVBS/AHD 转USB
  20. ubuntu 安装谷歌输入法 亲测有效

热门文章

  1. Microsoft .NET Framework 3.5 sp1离线安装(DotNetFX35)
  2. react使用animate.css完成动画
  3. C语言逻辑左移指令shl怎么用,汇编语言SHL(左移)指令:将操作数逻辑左移一位...
  4. 一起来看流星雨剧情简介/剧情介绍/剧情分集介绍第三十六集
  5. 怎么样给小孩取名字?准爸妈为孩子起名字的另类姿势
  6. python adb开发-adb常见用法
  7. 使用obs时显示已从服务器,小鹅通OBS
  8. 黑马程序员mysql答案_干货|MySQL常见问题及答案汇总
  9. 安卓面试题你都会吗?
  10. 推荐九个数据可视化工具,快速生成可视化信息