gpt4 book ai didi

c - 如何在 gcc 中使用编译指示(或其他方式)指定 -march=native

转载 作者:太空宇宙 更新时间:2023-11-04 02:29:25 28 4
gpt4 key购买 nike

我想为将在 gcc 中编译的 C 代码指定编译器选项。由于代码的部署方式,我需要在代码中执行此操作。这是目前似乎成功指定优化标志的代码。

#pragma GCC optimize ("-O3,-ffast-math")
typedef float v4sf __attribute__ ((vector_size (16)));
typedef union {
v4sf v;
float e[4];
} float4;
typedef struct {
float4 x;
float4 y;
} complex4;
static complex4 complex4_mul(complex4 a, complex4 b) {
return (complex4){a.x.v*b.x.v -a.y.v*b.y.v, a.y.v*b.x.v + a.x.v*b.y.v};
}
complex4 f4(complex4 x[], int n) {
v4sf one = {1,1,1,1};
complex4 p = {one,one};
for (int i = 0; i < n; i++) p = complex4_mul(p, x[i]);
return p;
}

However I would also like to specify -march=native. Is this possible somehow from within the code?

我确实尝试了 #pragma GCC optimize ("-O3,-ffast-math, -march=native"),但是 -march=native 部分刚刚出现被忽略。请参阅:https://godbolt.org/g/FjbRcV .

最佳答案

现在我明白了。据我所知,除了使用 #pragma GCC target

别无他法

例如:

#pragma GCC 目标(“arch=skylake-avx512”)

但它不接受native 作为参数。我已经把它添加到你的 godbolt 中了

https://godbolt.org/g/vm1ZBa

IMO 这是错误的方法,因为它们应该使用命令行参数和正确编写的 makefile 传递给编译器

关于c - 如何在 gcc 中使用编译指示(或其他方式)指定 -march=native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45908243/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com