开发者

How to overload +, -, *, /, /=, etc operators for __m128 SSE type using Apple GCC 4.2.1?

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

__开发者_如何学JAVAforceinline __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 type

error: '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...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜