如何使用Apple GCC 4.2.1重载__m128 SSE类型的+,-,*,/,/=等运算符? [英] How to overload +, -, *, /, /=, etc operators for __m128 SSE type using Apple GCC 4.2.1?

查看:95
本文介绍了如何使用Apple GCC 4.2.1重载__m128 SSE类型的+,-,*,/,/=等运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要将游戏移植到 OS X ,该游戏使用 __ m128 类型的运算符重载:

I'm porting a game to OS X, which uses operators overloading for __m128 type like:

__forceinline __m128 operator - ( __m128 a, __m128 b )
{
    return _mm_sub_ps ( a, b );
}

__forceinline __m128 operator * ( __m128 a, __m128 b )
{
    return _mm_mul_ps ( a, b );
}

Apple GCC v4.2.1 给我以下错误:

错误:浮动向量 运算符-(float vector ,float vector )'必须具有类或枚举类型的参数

error: 'float vector operator-(float vector, float vector)' must have an argument of class or enumerated type

错误:浮动向量 运算符*(浮点 vector ,浮点 vector )'必须具有类或枚举类型的参数

error: 'float vector operator*(float vector, float vector)' must have an argument of class or enumerated type

我找到了链接,将这种错误描述为 GCC错误,已在v4.0中解决...

I have found a link, describing this kind of errors as a GCC bug, which was solved in v4.0...

现在我完全迷路了...请帮助我解决这个问题...

And now I'm completely lost... Please help me deal with this issue...

推荐答案

我正在使用g ++ 4.6.1,并且在类似情况下发现了相同的错误消息,当两个参数都是内置类型时就会发生这种情况:

i'm using g++ 4.6.1 and found same error message on a similar situation, it happens when both arguments are builtin types:

算法运算符+(const char * a,double b); 算法运算符+(double a,const char * b);

algo operator+(const char* a,double b); algo operator+(double a,const char* b);

我知道重新定义+(int,int)会很棘手,因为编译器依靠它来进行计算,thouse计算会在编译时而不是在运行时发生,因此您提供的代码在编译时不可用,并且稍后在运行时,数据已经计算完毕.

I understand it would be tricky to redefine +(int,int) because the compiler rely on that to do calculations, thouse calculations occour on compile time, not on runtime, so the code you provide is not available at compile time and Later at runtime the data is already calculated.

很遗憾,我们不能执行此操作,内置类型应允许使用,前提是类型不同(在我的情况下),并且在这种情况下编译器没有默认答案.

too bad we can't do this, it should be allowed for builtin types provided that types were diferent (wich is my case) and for that case the compiler has no default answer.

对于+(int,int)情况,由于上述原因,我认为它永远不会被允许.除非编译器接受某种类型的参数以将计算结果留给运行时(并且我还没有检查那种类型的参数).我认为类似的事情正在浮起.

for the case +(int,int) i think it would never be allowed because of the above explained. unless compilers accept some sort of parameters to leave that calc's to runtime (and i didnt check that kind of parameters yet). I think similar thing is happening to floats.

这篇关于如何使用Apple GCC 4.2.1重载__m128 SSE类型的+,-,*,/,/=等运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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