编译带有AVX矢量警告的遗留GCC代码
Compiling legacy GCC code with AVX vector warnings
我一直在谷歌上搜索,但找不到任何有用的。
typedef int64_t v4si __attribute__ ((vector_size(32)));
//warning: AVX vector return without AVX enabled changes the ABI [-Wpsabi]
// so isn't AVX already automatically enabled?
// What does it mean "without AVX enabled"?
// What does it mean "changes the ABI"?
inline v4si v4si_gt0(v4si x_);
//warning: The ABI for passing parameters with 32-byte alignment has changed in GCC 4.6
//So why there's warning and what does it mean?
// Why only this parameter got warning?
// And all other v4si parameter/arguments got no warning?
void set_quota(v4si quota);
这不是遗留代码。__attribute__ ((vector_size(32)))
表示32字节向量,即256位,在x86上表示AVX。(GNU C向量扩展)
AVX不启用,除非您使用-mavx
(或包含它的-march
设置)。否则,编译器不允许生成使用AVX指令的代码,因为这些代码会在不支持AVX的旧cpu上触发非法指令错误。
所以编译器不能像常规调用约定那样在寄存器中传递或返回256b向量。它可能将它们视为与value传递的相同大小的结构体。
请参阅x86标签wiki中的ABI链接,或维基百科上的x86调用约定页面(大多没有提到向量寄存器)。
由于GNU C向量扩展语法与任何特定的硬件无关,使用32字节的向量仍然可以编译成正确的代码。它的性能很差,但即使编译器只能使用SSE指令,它仍然可以工作。(据我所知,gcc在生成处理超出目标机器支持范围的向量的代码方面做得非常糟糕。通过手动使用vector_size(16)
,您可以为具有16B向量的机器获得更好的代码。)
__attribute__ ((vector_size(32)))
并不意味着AVX特别,但AVX或其他256b向量指令集需要它编译成好的代码。
相关文章:
- GCC对可能有效的代码抛出init list生存期警告
- GCC 和 Clang 代码性能的巨大差异
- GCC 能否优化具有相同主体的函数的代码大小?
- GCC 编译器是否应该对涉及 [[fallthrough]] 属性的格式错误的C++代码进行诊断?
- 如何使用 gcc 通过命令行限制C++代码的内存使用量?
- MSVC对这段代码很满意,但GCC并不那么热衷
- 为什么这段代码无法使用 gcc 4.8.5 编译,而使用 clang 编译正常
- 为什么以下代码在在线 ide(gcc 7.2.0) 上有效,但在 ubuntu 上出现错误?
- Boost tread 代码在 VC++ 下编译,但不在 GCC 下编译:如何获得更好的调试信息
- gcc 可以使用较旧的第三方库编译 C++17 代码吗?
- 如何使用 gcc 内联汇编器代码访问成员变量
- 初始化不可移动对象数组:为什么这样的代码无法在 GCC 上编译?
- 是否可以使用 GCC 编译具有特定编译器标志的代码文件的一部分?
- variadic模板代码中的GCC VS MSVC编译误差
- Clang vs GCC:挥发性访问的不同代码
- 编译为C 与C的GCC代码生成的很大差异
- 在 Visual Studio 中编译 gcc 代码会导致错误 C3646:"__attribute__":未知的覆盖说明符
- 编译带有AVX矢量警告的遗留GCC代码
- c++ stl映射编译问题与GCC/代码块
- 需要连接std:string + WCHAR移动gcc代码到Visual c++ 2010