如何使用 Apple GCC 4.2.1 重载 __m128 SSE 类型的 +、-、*、/、/= 等运算符?

发布于 2024-11-02 05:21:23 字数 762 浏览 1 评论 0原文

我正在将游戏移植到 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 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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

川水往事 2024-11-09 05:21:23

我正在使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文