2bit位字段对性能和缓存效率的影响? [英] 2bit bit-fields array effects on performance and cache efficiency?

查看:114
本文介绍了2bit位字段对性能和缓存效率的影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个2bit数组,我不关心节省内存,但我关心最小化缓存未命中和最大化缓存效率。使用bool数组将使用4倍的内存,这意味着对于缓存中的每个可用的数据块,将有3个未使用。所以技术上,如果我使用位字段,我可以得到3倍更好的缓存一致性。

I am in need of a 2bit array, I am not concerned with saving memory at all, but I am concerned with minimizing cache misses and maximizing cache efficiency. Using an array of bools will use 4 times more memory, which means for every usable chunk of data in the cache, there will be 3 that are not used. So technically, I can get 3 times better cache consistency if I use bitfields.

该计划是将它实现为一个字节数组,分为4个相等的位域,并使用div函数能够获得积分商和余数在单个时钟中,并使用那些访问正确的索引和右位字段。

The plan is to implement it as an array of bytes, divided into 4 equal bitfields, and use the div function to be able to get the integral quotient and remainder, possibly in a single clock, and use those to access the right index and right bitfield.

我需要的数组大约有10000个元素,因此它将使一个显着更密集打包数据,使用2个实际位将允许整个数组适合L1缓存,而使用字节数组这将是不可能的。

The array I needs is about 10000 elements long, so it will make for a significantly denser packed data, using 2 actual bits will allow for the entire array to fit in L1 cache, while using a byte array this will not be possible.

所以我的问题是,有人可以告诉我,如果这是一个好主意,在性能导向的任务,所以我知道如果值得出去和实现一个2bit数组?

So my question is whether someone can tell me if this is a good idea in a performance oriented task, so I know if it is worth to go forth and implement a 2bit array? And surely, the best way to know is profiling, but any information in advance may be useful and will be appreciated.

推荐答案

有了这个功能, 10000元素,在现代处理器上,它应该适合在内存中作为字节(10KB),所以我不会担心太多,除非你想要在一个非常微小的微处理器上运行一个缓存远小于典型的16-32KB L1缓存,现代CPU的。

With 10000 elements, on a modern processor, it should fit nicely in memory as bytes (10KB), so I wouldn't worry too much about it, unless you want this to run on some very tiny microprocessor with a cache that is much smaller than the typical 16-32KB L1 caches that modern CPU's have.

当然,您可能希望使用不同的解决方案来测试性能,如果您认为从性能角度来看这是代码的重要部分[您在开始优化之前已经做过的分析,对吗?]

Of course, you may well want to TEST the performance with different solutions, if you think this is an important part of your code from a performance perspective [as measured from your profiling that you've already done before you start optimising, right?].

这篇关于2bit位字段对性能和缓存效率的影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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