Currently, I am trying to create a VFPU (Vector Floating-Point Unit) function that returns the dot-product of two vectors. Since the output is a scalar, I want to store the value as a scalar; however, when I store the value in a scalar instead of an element in a vector, I get a consistent and wrong answer.
Here is my test.c file:
#include "callback.h"
#include <pspkernel.h>
#include <pspla.h>
PSP_MODULE_INFO("VtxGame", 0, 1, 0);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER | PSP_THREAD_ATTR_VFPU);
int main() {
pspDebugScreenInit();
setupCallbacks();
float v0[3] __attribute__((aligned(16))) = {1.0, 2.0, 3.0};
float v1[3] __attribute__((aligned(16))) = {4.0, 5.0, 6.0};
float v2[3] __attribute__((aligned(16))) = {0.0, 0.0, 0.0};
float s0 __attribute__((aligned(4))) = 0.0;
psplaVec3DotProduct(v0, v1, &s0); //(v0, v1, v2) when storing to v2
pspDebugScreenPrintf("Result Vector: ");
for(int i = 0; i < 3; i++) {
pspDebugScreenPrintf("%f ", v2[i]);
}
psplaVec3Magnitude(v0, &s0);
pspDebugScreenPrintf("nResult Scalar: %f", s0);
sceKernelSleepThread();
}
And here’s the assembly function:
.macro singleOpScalar op, w
lv.q r000, 0($a0)
lv.q r001, 0($a1)
op().w s002, r000, r001
sv.s s002, 0($a2)
.endm
...
.globl psplaVec3DotProduct
psplaVec3DotProduct:
singleOpScalar vdot, t
jr $ra
The program outputs Result Vector: 32.000000 0.000000 0.000000
when storing to v2, and Result Scalar: 3.741657
when storing to s0.