标签的地址(MSVC) [英] Address of labels (MSVC)

查看:150
本文介绍了标签的地址(MSVC)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在编写针对字节code为高层次的编译语言,有点分析和优化后,人们清楚地看到目前国内最大的性能开销,我们使用跳转到switch语句在字节级code的情况。

We are writing a byte-code for a high-level compiled language, and after a bit of profiling and optimization, it became clear that the current largest performance overhead is the switch statement we're using to jump to the byte-code cases.

我们调查拉出每个案件标签的地址,并针对字节$ C $的流中存储C本身,而不是指令ID就是我们通常开关。如果我们这样做,我们可以跳过跳转表,并直接跳转到当前指令执行code的位置。这部作品在飞驰GCC,但是,MSVC似乎不支持的功能是这样的。

We investigated pulling out the address of each case label and storing it in the stream of byte-code itself, rather than the instruction ID that we usually switch on. If we do that, we can skip the jump table, and directly jump to the location of code of the currently executing instruction. This works fantastically in GCC, however, MSVC doesn't seem to support a feature like this.

我们尝试使用内联汇编抢标签的地址(并跳转到他们),但是和它的工作原理,使用内联汇编导致的MSVC优化避免全功能。

We attempted to use inline assembly to grab the address of the labels (and to jump to them), and it works, however, using inline assembly causes the entire function to be avoided by the MSVC optimizer.

有没有办法,让优化器仍然在code运行?不幸的是,我们不能提取内嵌汇编成比标签是在做数据之外的其它功能,因为没有办法引用标签,即使内联汇编另一个函数。任何想法或意见?你输入多少AP preciated,谢谢!

Is there a way to allow the optimizer to still run over the code? Unfortunately, we can't extract the inline assembly into another function other than the one that the labels were made in, since there's no way to reference a label for another function even in inline assembly. Any thoughts or ideas? Your input is much appreciated, thanks!

推荐答案

在MSVC这样做的唯一方法是使用内联汇编(这基本上坏蛋,你用于基于x64):

The only way of doing this in MSVC is by using inline assembly (which basically buggers you for x64):

int _tmain(int argc, _TCHAR* argv[])
{
case_1:
    void* p;
    __asm{ mov [p],offset case_1 }
    printf("0x%p\n",p);
    return 0;
}

如果你打算做这样的事情,那么最好的办法是写汇编整个跨preTER然后链接,在通过连接器的主要二进制文件(这是LuaJIT做的,这是主要的原因,VM是如此瞬息万变,当其没有运行JIT'ed code即是)。

If you plan on doing something like this, then the best way would be to write the whole interpreter in assembly then link that in to the main binary via the linker (this is what LuaJIT did, and it is the main reason the VM is so blindingly fast, when its not running JIT'ed code that is).

LuaJIT是开源的的,所以如果你走这条路,你可能会选择从它的一些技巧。或者你可能要考虑的第四源(其创作者开发href=\"http://en.wikipedia.org/wiki/Threaded_$c$c\"> 你的原则,试图不是的坏事,它适用于所有主要平台)。

LuaJIT is open-source, so you might pick up some tips from it if you go that route. Alternatively you might want to look into the source of forth (whose creator developed the principle you're trying to use), if there is an MSVC build you can see how they accomplished it, else you're stuck with GCC (which isn't a bad thing, it works on all major platforms).

这篇关于标签的地址(MSVC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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