最快的整数类型的通用架构 [英] Fastest integer type for common architectures

查看:101
本文介绍了最快的整数类型的通用架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

stdint.h 头缺少 int_fastest_t uint_fastest_t 与对应的 {,U} int_fastX_t 类型。对于实例其中整数类型的宽度无所谓,一个人如何挑选可以使处理比特的最大数量用最少罚性能整数类型?例如,如果一个在缓冲用朴素方法搜索的第一组比特,环路如这可能被认为是:

The stdint.h header lacks an int_fastest_t and uint_fastest_t to correspond with the {,u}int_fastX_t types. For instances where the width of the integer type does not matter, how does one pick the integer type that allows processing the greatest quantity of bits with the least penalty to performance? For example, if one was searching for the first set bit in a buffer using a naive approach, a loop such as this might be considered:

// return the bit offset of the first 1 bit
size_t find_first_bit_set(void const *const buf)
{
    uint_fastest_t const *p = buf; // use the fastest type for comparison to zero
    for (; *p == 0; ++p); // inc p while no bits are set
    // return offset of first bit set
    return (p - buf) * sizeof(*p) * CHAR_BIT + ffsX(*p) - 1;
}

当然,使用字符将导致比 INT 更多的操作。但长长,可能会导致比使用 INT 32位系统上等等的开销更昂贵的操作。

Naturally, using char would result in more operations than int. But long long might result in more expensive operations than the overhead of using int on a 32 bit system and so on.

我目前的假设是为主流的架构,使用是最安全的赌注:它是32位在32位系统和64位在64位系统。

My current assumption is for the mainstream architectures, the use of long is the safest bet: It's 32 bit on 32 bit systems, and 64 bit on 64 bit systems.

推荐答案

对于所有现有的主流架构为present循环吞吐量最快的一类。

For all existing mainstream architectures long is the fastest type at present for loop throughput.

这篇关于最快的整数类型的通用架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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