预取双类成员需要强制转换为 char*? [英] Prefetching double class member requires casting to char*?

查看:71
本文介绍了预取双类成员需要强制转换为 char*?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类,我使用 _mm_prefetch() 来预请求包含类成员的缓存行,类型为 double:

class MyClass{双 getDouble(){返回 db;}//其他成员双dbl;//其他成员};

_mm_prefetch() 签名是:>

void _mm_prefetch (char const* p, int i)

但是当我这样做时:

_mm_prefetch((char*)(myOb.getDouble()), _MM_HINT_T0);

海湾合作委员会抱怨:

<块引用>

错误:从类型double"到类型char*"的无效转换

那么我如何预取这个类成员?

解决方案

如果您从链接到它的站点上阅读了 _mm_prefetch() 的描述:

void _mm_prefetch (char const* p, int i)

<块引用>

从内存中提取包含地址 p 的数据行到位置提示 i 指定的缓存层次结构中的某个位置.

所以你需要传递你想要的变量的地址.为此,您需要将类成员的引用地址或指向它的指针传递给函数.

最简单的解决方案是更改 getDouble() 以返回引用,然后您可以使用:

_mm_prefetch((char*)(&myOb.getDouble()), _MM_HINT_T0);

I have a class which I am using _mm_prefetch() to pre-request the cacheline containing a class member, of type double:

class MyClass{

    double getDouble(){
        return dbl;
    }

    //other members
    double dbl;
    //other members
};

_mm_prefetch() signature is:

void _mm_prefetch (char const* p, int i)

But when I do:

_mm_prefetch((char*)(myOb.getDouble()), _MM_HINT_T0);

GCC complains:

error: invalid cast from type 'double' to type 'char*'

So how do I prefetch this class member?

解决方案

If you read the description for _mm_prefetch() from the site you linked to it has :

void _mm_prefetch (char const* p, int i)

Fetch the line of data from memory that contains address p to a location in the cache heirarchy specified by the locality hint i.

So you need to pass the address of the variable that you want. In order for you to do that you need to pass to the function either the address of a reference to the class member or a pointer to it.

The simplest solution woul be to change getDouble() to return a reference and then you can use:

_mm_prefetch((char*)(&myOb.getDouble()), _MM_HINT_T0);

这篇关于预取双类成员需要强制转换为 char*?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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