Fix silly mistake in vfpu_sincos. Add unittest.

This commit is contained in:
Henrik Rydgard committed 2014-06-15 11:51:30 +02:00
1 parent 0879d76503
commit e6f55bfef0
2 files changed
+39 -5

No files matched your search

+5 -3
View File
@@ -19,6 +19,8 @@
#include <cmath>
#include "Core/MIPS/MIPS.h"
#define _VD (op & 0x7F)
#define _VS ((op>>8) & 0x7F)
#define _VT ((op>>16) & 0x7F)
@@ -32,19 +34,19 @@ inline int Xpose(int v) {
#endif
inline float vfpu_sin(float angle) {
angle -= floorf(angle * 4.0f) * 0.25f;
angle -= floorf(angle * 0.25f) * 4.f;
angle *= (float)M_PI_2;
return sinf(angle);
}
inline float vfpu_cos(float angle) {
angle -= floorf(angle * 4.0f) * 0.25f;
angle -= floorf(angle * 0.25f) * 4.f;
angle *= (float)M_PI_2;
return cosf(angle);
}
inline void vfpu_sincos(float angle, float &sine, float &cosine) {
angle -= floorf(angle * 4.0f) * 0.25f;
angle -= floorf(angle * 0.25f) * 4.f;
angle *= (float)M_PI_2;
sine = sinf(angle);
cosine = cosf(angle);
+34 -2
View File
@@ -37,10 +37,12 @@
#include "math/math_util.h"
#include "util/text/parsers.h"
#include "Core/Config.h"
#include "Core/MIPS/MIPSVFPUUtils.h"
#define EXPECT_TRUE(a) if (!(a)) { printf("%s:%i: Test Fail\n", __FUNCTION__, __LINE__); return false; }
#define EXPECT_FALSE(a) if ((a)) { printf("%s:%i: Test Fail\n", __FUNCTION__, __LINE__); return false; }
#define EXPECT_EQ_FLOAT(a, b) if ((a) != (b)) { printf("%s:" __LINE__ ": Test Fail\n%f\nvs\n%f\n", __FUNCTION__, a, b); return false; }
#define EXPECT_EQ_FLOAT(a, b) if ((a) != (b)) { printf("%s:%i: Test Fail\n%f\nvs\n%f\n", __FUNCTION__, __LINE__, a, b); return false; }
#define EXPECT_APPROX_EQ_FLOAT(a, b) if (fabsf((a)-(b))>0.00001f) { printf("%s:%i: Test Fail\n%f\nvs\n%f\n", __FUNCTION__, __LINE__, a, b); /*return false;*/ }
#define EXPECT_EQ_STR(a, b) if (a != b) { printf("%s: Test Fail\n%s\nvs\n%s\n", __FUNCTION__, a.c_str(), b.c_str()); return false; }
#define RET(a) if (!(a)) { return false; }
@@ -385,6 +387,35 @@ bool TestParsers() {
return true;
}
bool TestVFPUSinCos() {
float sine, cosine;
vfpu_sincos(0.0f, sine, cosine);
EXPECT_EQ_FLOAT(sine, 0.0f);
EXPECT_EQ_FLOAT(cosine, 1.0f);
vfpu_sincos(1.0f, sine, cosine);
EXPECT_APPROX_EQ_FLOAT(sine, 1.0f);
EXPECT_APPROX_EQ_FLOAT(cosine, 0.0f);
vfpu_sincos(2.0f, sine, cosine);
EXPECT_APPROX_EQ_FLOAT(sine, 0.0f);
EXPECT_APPROX_EQ_FLOAT(cosine, -1.0f);
vfpu_sincos(3.0f, sine, cosine);
EXPECT_APPROX_EQ_FLOAT(sine, -1.0f);
EXPECT_APPROX_EQ_FLOAT(cosine, 0.0f);
vfpu_sincos(4.0f, sine, cosine);
EXPECT_EQ_FLOAT(sine, 0.0f);
EXPECT_EQ_FLOAT(cosine, 1.0f);
vfpu_sincos(5.0f, sine, cosine);
EXPECT_APPROX_EQ_FLOAT(sine, 1.0f);
EXPECT_APPROX_EQ_FLOAT(cosine, 0.0f);
for (float angle = -10.0f; angle < 10.0f; angle++) {
vfpu_sincos(angle, sine, cosine);
EXPECT_APPROX_EQ_FLOAT(sine, sinf(angle * M_PI_2));
EXPECT_APPROX_EQ_FLOAT(cosine, cosf(angle * M_PI_2));
}
return true;
}
int main(int argc, const char *argv[]) {
cpu_info.bNEON = true;
cpu_info.bVFP = true;
@@ -393,7 +424,8 @@ int main(int argc, const char *argv[]) {
g_Config.bEnableLogging = true;
//TestAsin();
//TestSinCos();
TestArmEmitter();
//TestArmEmitter();
TestVFPUSinCos();
//TestMathUtil();
//TestParsers();
return 0;