关于减少分支小姐prediciton [英] About reducing the branch miss prediciton

查看:311
本文介绍了关于减少分支小姐prediciton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到一个句子在文章转化成分支的数据依赖,以避免误predicted分支。 (第6页)

I saw a sentence in a paper "Transforming branches into data dependencies to avoid mispredicted branches." (Page 6)

我不知道如何改变分支code到数据依赖性。

I wonder how to change the code from branches into data dependencies.

这是纸: http://www.adms-conf.org/p1 -SCHLEGEL.pdf

更新:如何在二进制搜索转换分支

推荐答案

其基本思想(我presume)是改变这样的:

The basic idea (I would presume) would be to change something like:

if (a>b)
    return "A is greater than B";
else
    return "A is less than or equal to B";

static char const *strings[] = {
    "A is less than or equal to B", 
    "A is greater than B"
};

return strings[a>b];

编辑:至于在二进制搜索分支走,让我们考虑的正常的二进制搜索,这通常如下(至少隐约)像这样的基本理念:

As far as branches in a binary search go, let's consider the basic idea of the "normal" binary search, which typically looks (at least vaguely) like this:

while (left < right) {
    middle = (left + right)/2;
    if (search_for < array[middle])
        right = middle;
    else
        left = middle;
}

我们可以摆脱的分支在这里pretty的几乎相同的方式:

We could get rid of the branching here in pretty much the same way:

size_t &positions = {left, right};

while (left < right) {
    size_t middle = (left + right)/2;

    positions[search_for >= array[middle]] = middle;
}

[对于通用code使用左+(右 - 左)/ 2 ,而不是(左+右)/ 2 ]

这篇关于关于减少分支小姐prediciton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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