与Yeppp一起表演!比本机实现慢
Performance with Yeppp! is slower than native implementation
嗨,我正在尝试使用Yeppp提高代码中向量代数的性能!然而,库的性能实际上越来越差。。。这里有一段Vector类代码:
#include "Vector3.h"
#include <cmath>
#include "yepCore.h"
Vector3::Vector3()
{
//ctor
}
Vector3::~Vector3()
{
//dtor
}
Vector3::Vector3(float X, float Y, float Z)
{
x = X;
y = Y;
z = Z;
}
float& Vector3::operator[](int idx)
{
return (&x)[idx];
}
Vector3& Vector3::normalize()
{
#if USE_YEPPP
float inf;
yepCore_SumSquares_V32f_S32f(&x, &inf, 3);
yepCore_Multiply_IV32fS32f_IV32f(&x, 1.0f / sqrt(inf), 3);
#else
float inf = 1.0f / sqrt((x * x) + (y * y) + (z * z));
x *= inf;
y *= inf;
z *= inf;
#endif
return *this;
}
Vector3 Vector3::cross(Vector3& rh)
{
return Vector3 (
(y * rh.z) - (z * rh.y),
(z * rh.x) - (x * rh.z),
(x * rh.y) - (y * rh.x)
);
}
float Vector3::dot(Vector3& rh)
{
#if USE_YEPPP
float ret = 0;
yepCore_DotProduct_V32fV32f_S32f(&x, &rh.x, &ret, 3);
return ret;
#else
return x*rh.x+y*rh.y+z*rh.z;
#endif
}
Vector3 Vector3::operator*(float scalar)
{
#if USE_YEPPP
Vector3 ret;
yepCore_Multiply_V32fS32f_V32f(&x, scalar, &ret.x , 3);
return ret;
#else
return Vector3(x*scalar, y*scalar,z*scalar);
#endif
}
Vector3 Vector3::operator+(Vector3 rh)
{
#if USE_YEPPP
Vector3 ret;
yepCore_Add_V32fV32f_V32f(&x, &rh.x, &ret.x, 3);
return ret;
#else
return Vector3(x+rh.x, y+rh.y, z+rh.z);
#endif
}
Vector3 Vector3::operator-(Vector3 rh)
{
#if USE_YEPPP
Vector3 ret;
yepCore_Subtract_V32fV32f_V32f(&x, &rh.x, &ret.x, 3);
return ret;
#else
return Vector3(x-rh.x, y-rh.y, z-rh.z);
#endif
}
Vector3 operator*(float s, const Vector3& v)
{
#if USE_YEPPP
Vector3 ret;
yepCore_Multiply_V32fS32f_V32f(&v.x, s, &ret.x , 3);
return ret;
#else
return Vector3(s*v.x,s*v.y,s*v.z);
#endif
}
我正在使用g++编译器。编译器选项:g++-Wall-fexceptions-fPIC-Wl,--无需-std=c++11-pthread-ggdb链接器选项:g++-共享-lpthread-lyeppp-ldl
你知道我做错了什么吗?
Yeppp!针对处理100+个元素的阵列进行了优化。
由于使用SIMD的能力有限以及函数调用、动态调度和参数检查的开销,它在小型阵列(如示例中的长度为3的阵列)上效率不高。
相关文章:
- 从C++本机插件更新Vector3数组
- GCC本机矩阵运算库
- VC++本机单元测试,找不到调试符号
- 在这种情况下,java对象是否可以调用本机函数
- PC中的程序和PHONE中的本机描述应用程序之间的数据连接
- 为什么导入Mixed native/CLR lib.dll的本机C++应用程序没有在Mixed lib.dll中的外部变
- 无法将标准库导入本机 android 项目中的头文件
- 使用本机 JNI 静态方法实现C++ Java 运行时错误
- 如何在本机 c++ jni 中实现 java 类型数组
- 对于第二个本机函数,显示不舒适的LinkError:未针对.stringfromjni2()找到实现
- C++ vs iOS / Android的本机实现
- 如何在V8中为C 本机对象实现属性枚举器
- 如何实现C#使用本机C 的com的接口
- Android NDK OpenCV - 找不到本机的实现
- 使用本机lib(仅限C,没有C++),并且找不到实现
- 使用本机windows API实现win32线程安全队列
- 如何为在 .props 文件中声明的非本机 VC 编译器 (GCC) 实现 MSBUILD 文件跟踪功能 (跟踪器.ex
- 与Yeppp一起表演!比本机实现慢
- 如何查看Java类的本机实现
- 使用C++在android中理解和实现本机绑定器