g++ -Ofast
程序
#include <Eigen/Eigen>
#include <iostream>
#include <cstdlib>
#include <ctime>
template <typename T>
T symdet(T a) {
Eigen::Matrix<T, 3, 3> X;
X(0, 0) = a;
X(1, 1) = 2 * a;
X(2, 2) = 3 * a;
X(0, 1) = X(1, 0) = 4 * a;
X(0, 2) = X(2, 0) = 5 * a;
X(1, 2) = X(2, 1) = 6 * a;
return X.determinant();
}
int main() {
srand (static_cast <unsigned> (time(0)));
float a = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
std::cout << symdet(a) << "\n";
}
答案 0 :(得分:0)
可能它可以,因为它无论如何都不使用矢量化操作。 我安装了编译器资源管理器的本地实例:https://github.com/mattgodbolt/compiler-explorer
C ++代码:
#include <Eigen/Eigen>
float symdet(float a, float b, float c, float d, float e, float f) {
Eigen::Matrix<float, 3, 3> X;
X(0, 0) = a;
X(1, 1) = b;
X(2, 2) = c;
X(0, 1) = X(1, 0) = d;
X(0, 2) = X(2, 0) = e;
X(1, 2) = X(2, 1) = f;
return X.determinant();
}
汇编(g ++ - 7 -Ofast -I):
symdet(float, float, float, float, float, float):
movaps xmm6, xmm1
mulss xmm1, xmm4
movaps xmm7, xmm5
mulss xmm6, xmm2
mulss xmm7, xmm5
mulss xmm2, xmm3
subss xmm6, xmm7
mulss xmm0, xmm6
movaps xmm6, xmm4
mulss xmm6, xmm5
subss xmm2, xmm6
mulss xmm2, xmm3
mulss xmm3, xmm5
subss xmm0, xmm2
subss xmm3, xmm1
mulss xmm4, xmm3
addss xmm0, xmm4
ret
ss操作是标量,仅适用于1个浮点值,而不是向量运算。
只有6个输入值xmm[0 - 5]
,xmm[6, 7]
包含中间词。