如何使用 Apple GCC 4.2.1 重载 __m128 SSE 类型的 +、-、*、/、/= 等运算符?
我正在将游戏移植到 OS X,它使用 __m128 类型的运算符重载,例如:
__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 为我提供以下内容错误:
错误:'浮点矢量 运算符-(浮点向量,浮点 向量)'必须具有类或枚举类型的参数
错误:'浮点矢量 运算符*(浮点向量,浮点 向量)'必须具有类或枚举类型的参数
我发现了链接,将这种错误描述为GCC bug,在v4.0中已解决...
现在我完全迷失了...请帮助我处理这个问题...
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 );
}
And Apple GCC v4.2.1 gives me the following errors:
error: 'float vector
operator-(float vector, float
vector)' must have an argument of class or enumerated typeerror: 'float vector
operator*(float vector, float
vector)' must have an argument of class or enumerated type
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在使用 g++ 4.6.1 并在类似情况下发现相同的错误消息,当两个参数都是内置类型时会发生这种情况:
algo operator+(const char* a,double b);
算法运算符+(double a,const char* b);
我知道重新定义 +(int,int) 会很棘手,因为编译器依赖它来进行计算,这些计算发生在编译时,而不是运行时,因此您提供的代码在编译时和稍后在运行时不可用数据已经计算出来了。
太糟糕了,我们不能这样做,如果类型不同(这是我的情况),则应该允许内置类型,并且对于这种情况,编译器没有默认答案。
对于 +(int,int) 的情况,我认为由于上述解释,它永远不会被允许。除非编译器接受某种参数以将该计算留给运行时(而且我还没有检查这种参数)。我认为类似的事情也发生在花车上。
i'm using g++ 4.6.1 and found same error message on a similar situation, it happens when both arguments are builtin types:
algo operator+(const char* a,double b);
algo operator+(double a,const char* b);
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.
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.