这是什么'代表ret`是什么意思? [英] What does `rep ret` mean?

查看:361
本文介绍了这是什么'代表ret`是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我于Visual Studio 2008的测试一些code和注意到 security_cookie 。我能理解它的观点,但我不明白这个指令的目的是什么。

 代表RET / * REP避免AMD分支prediction罚款* /

当然,我能理解注释:)但是,这是什么preFIX exaclty在上下文中执行与 RET ,如果会发生什么ECX 是!= 0?显然,从环 ECX 计数,当我调试它,这是可以预料的被忽略。

在code,我发现这是在这里(编译器为安全注射):

 无效__declspec(裸体)__fastcall __security_check_cookie(UINT_PTR饼干)
{
    / *写在ASM为preserve x86版的所有暂存器* /
    __asm​​ {
        CMP ECX,__security_cookie
        JNE失败
        代表RET / * REP避免AMD分支prediction罚款* /
失败:
        JMP __report_gsfailure
    }
}


解决方案

有此指令命名的整个博客。与第一篇文章介绍了背后的原因: http://repzret.org/p/repzret/

基本上,有一个在AMD的分支predictor一个问题,当一个单字节 RET 后面紧跟一个条件转移作为code你报(和一些其他情况),而解决方法是添加代表 preFIX,这是由CPU忽略,但修复了predictor点球。

I was testing some code on Visual Studio 2008 and noticed security_cookie. I can understand the point of it, but I don't understand what the purpose of this instruction is.

    rep ret /* REP to avoid AMD branch prediction penalty */

Of course I can understand the comment :) but what is this prefix exaclty doing in context with the ret and what happens if ecx is != 0? Apparently the loop count from ecx is ignored when I debug it, which is to be expected.

The code where I found this was here (injected by the compiler for security):

void __declspec(naked) __fastcall __security_check_cookie(UINT_PTR cookie)
{
    /* x86 version written in asm to preserve all regs */
    __asm {
        cmp ecx, __security_cookie
        jne failure
        rep ret /* REP to avoid AMD branch prediction penalty */
failure:
        jmp __report_gsfailure
    }
}

解决方案

There's a whole blog named after this instruction. And the first post describes the reason behind it: http://repzret.org/p/repzret/

Basically, there was an issue in the AMD's branch predictor when a single-byte ret immediately followed a conditional jump as in the code you quoted (and a few other situations), and the workaround was to add the rep prefix, which is ignored by CPU but fixes the predictor penalty.

这篇关于这是什么'代表ret`是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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