iPhone 3GS 또는 Pandora에 액세스 할 수있는 사람이 방금 쓴 다음 어셈블리 루틴을 테스트 할 수 있습니까?ARMv7 + NEON 용 빠른 사인/코사인 : 테스터를 찾고 있습니다 ...
NEON 벡터 FPU에서 사인과 코사인을 정말 빠르게 계산한다고 가정합니다. 나는 그것이 잘 컴파일된다는 것을 알고 있지만 적절한 하드웨어가 없으면 그것을 테스트 할 수 없다. 몇 개의 사인과 코사인을 계산하고 그 결과를 sinf()와 cosf()의 결과와 비교할 수 있다면 정말 도움이 될 것입니다.
감사합니다.
#include <math.h>
/// Computes the sine and cosine of two angles
/// in: angles = Two angles, expressed in radians, in the [-PI,PI] range.
/// out: results = vector containing [sin(angles[0]),cos(angles[0]),sin(angles[1]),cos(angles[1])]
static inline void vsincos(const float angles[2], float results[4]) {
static const float constants[] = {
/* q1 */ 0, M_PI_2, 0, M_PI_2,
/* q2 */ M_PI, M_PI, M_PI, M_PI,
/* q3 */ 4.f/M_PI, 4.f/M_PI, 4.f/M_PI, 4.f/M_PI,
/* q4 */ -4.f/(M_PI*M_PI), -4.f/(M_PI*M_PI), -4.f/(M_PI*M_PI), -4.f/(M_PI*M_PI),
/* q5 */ 2.f, 2.f, 2.f, 2.f,
/* q6 */ .225f, .225f, .225f, .225f
};
asm volatile(
// Load q0 with [angle1,angle1,angle2,angle2]
"vldmia %1, { d3 }\n\t"
"vdup.f32 d0, d3[0]\n\t"
"vdup.f32 d1, d3[1]\n\t"
// Load q1-q6 with constants
"vldmia %2, { q1-q6 }\n\t"
// Cos(x) = Sin(x+PI/2), so
// q0 = [angle1, angle1+PI/2, angle2, angle2+PI/2]
"vadd.f32 q0,q0,q1\n\t"
// if angle1+PI/2>PI, substract 2*PI
// q0-=(q0>PI)?2*PI:0
"vcge.f32 q1,q0,q2\n\t"
"vand.f32 q1,q1,q2\n\t"
"vmls.f32 q0,q1,q5\n\t"
// q0=(4/PI)*q0 - q0*abs(q0)*4/(PI*PI)
"vabs.f32 q1,q0\n\t"
"vmul.f32 q1,q0,q1\n\t"
"vmul.f32 q0,q0,q3\n\t"
"vmul.f32 q1,q1,q4\n\t"
"vadd.f32 q0,q0,q1\n\t"
// q0+=.225*(q0*abs(q0) - q0)
"vabs.f32 q1,q0\n\t"
"vmul.f32 q1,q0,q1\n\t"
"vsub.f32 q1,q0\n\t"
"vmla.f32 q0,q1,q6\n\t"
"vstmia %0, { q0 }\n\t"
:: "r"(results), "r"(angles), "r"(constants)
: "memory","cc","q0","q1","q2","q3","q4","q5","q6"
);
}
그냥 호기심을 - 어떤 알고리즘 죄를 빨리 계산하고 계신가요? – gahooa
테스트 프로그램을 추가하면 비글 보드에서 실행할 수 있습니다. 같은 CPU. –
@ gahooa : http://www.devmaster.net/forums/showthread.php?t=5784 에있는 Nicolas Capens에 의해 설명 된 방법과 cos (x) = sin (x + 90 °) – jcayzac