为什么不能gcc或clang正确@encode SIMD矢量类型? [英] Why can't gcc or clang properly @encode SIMD vector types?

查看:370
本文介绍了为什么不能gcc或clang正确@encode SIMD矢量类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在使用向量类型和ObjC运行时做一些错误时,我遇到了一个非常令人困惑的问题。

  #import< Foundation / Foundation.h>对于任何SIMD向量类型, 

int main(){
typedef int int4 __attribute __((vector_size(16)));
typedef float float4 __attribute __((vector_size(16)));

NSLog(@Int4:%s,@encode(int4));
NSLog(@Float4:%s,@encode(float4));
}

使用GCC或clang运行,我得到以下输出:

 
2014-04-09 06:21:01.102 test [1707:507 ] Int4:
2014-04-09 06:21:01.103 test [1707:507] Float4:

我期望,这将是这样的:

 
2014-04-09 06:21:01.102 test [1707:507] Int4: ![16,16i]
2014-04-09 06:21:01.103 test [1707:507] Float4:![16,16f]

根据文档此处


向量     '!['后跟vector_size(组成向量的字节数),后跟逗号,后跟一个向量的对齐方式(以字节为单位),后面紧跟着']'后的元素类型


当试图从ObjC方法返回这些类型时,这变成了一个问题,而不是像! ,16i] @:用于以下方法的编码:

   - (int4)foo; 

我只得到字符串 @:这导致 NSMethodSignature NSInvocation 基本上废除他们的裤子和segfault。



有没有一些编译器选项,我可以启用恢复向量类型的正确编码?或者是这里唯一的解决方案是'不从ObjC方法返回向量'?



注意:返回该向量也没有帮助,因为指针到向量的编码只是 ^ ,然后贪婪匹配列表中的下一个参数,导致我的参数计数再次关闭。我想我可以把向量转换为 void * ,但那真的是一个丑陋的黑客。

解决方案

看起来这是一个已知问题,clang显然已经修改为在这种情况下显示警告: https://github.com/llvm-mirror/clang/commit/024d9c65e9d3887045c82be09e4f630f19da48b4


While doing some messing around with vector types and the ObjC runtime, I came across a very perplexing problem.

Neither clang or GCC will give the 'proper' type-encoding for any SIMD vector type, as far as I can tell.

#import <Foundation/Foundation.h>

int main() {
    typedef int int4 __attribute__((vector_size(16)));
    typedef float float4 __attribute__((vector_size(16)));

    NSLog(@"Int4: %s", @encode(int4));
    NSLog(@"Float4: %s", @encode(float4));
}

When compiled & run with either GCC or clang, I get the following output:

2014-04-09 06:21:01.102 test[1707:507] Int4:
2014-04-09 06:21:01.103 test[1707:507] Float4:

Instead of what I expect, which would be something like this:

2014-04-09 06:21:01.102 test[1707:507] Int4: ![16,16i]
2014-04-09 06:21:01.103 test[1707:507] Float4: ![16,16f]

As per the documentation here:

vectors      ‘![’ followed by the vector_size (the number of bytes composing the vector) followed by a comma, followed by the alignment (in bytes) of the vector, followed by the type of the elements followed by ‘]’

Which becomes a problem when attempting to return these types from an ObjC method, as instead of getting something logical like ![16,16i]@: for the encoding of the following method:

-(int4) foo;

I only get the string @:, which causes both NSMethodSignature and NSInvocation to essentially crap their pants, and segfault.

Is there some compiler option I can enable to restore the proper encoding of vector types? Or is the only solution here 'don't return vectors from an ObjC method'?

Note: Returning (or passing) a pointer to the vector doesn't help either, as the encoding for a pointer-to-vector is simply ^, which then greedily-matches the next argument in the list, causing my argument count to be off once again. I suppose I could cast the vector to a void *, but that really is an ugly hack at that point.

解决方案

Looks like this is a known issue, clang has apparently been modified to show a warning in this case: https://github.com/llvm-mirror/clang/commit/024d9c65e9d3887045c82be09e4f630f19da48b4

这篇关于为什么不能gcc或clang正确@encode SIMD矢量类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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