I've been trying to learn how to use the PlayStation Portable's (PSP) vector floating-point unit (vfpu), and I decided the first thing to write for it would be a simple matrix multiplication function that multiplies 2 4x4 matrices. However, the program will instead hang up and then the PSP will shut off.
Here are the two main files: main.c
#include <pspdebug.h>
#include <pspdisplay.h>
#include "../include/callbacks.h"
#include "../include/matrixmul.h"
PSP_MODULE_INFO("vfputest", PSP_MODULE_USER, 1, 0);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER | PSP_THREAD_ATTR_VFPU);
int main(int argc, char** argv){
float m0[] = {5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8};
float m1[] = {5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8};
float m2[16] = {};
matrixmul4x4(m0, m1, m2);
setupCallbacks();
pspDebugScreenInit();
for(int i = 0; i < 16; i++){
pspDebugScreenPrintf("m2[%d]: %f\n", i, m2[i]);
}
sceKernelSleepThread();
return 0;
}
matrixmul.s
.globl matrixmul4x4
# $a0 = mat0 address
# $a1 = mat1 address
# $a2 = result address
matrixmul4x4:
.macro lm4 mnum adr
lv.q r\mnum\()00, 0(\adr\())
lv.q r\mnum\()01, 16(\adr\())
lv.q r\mnum\()02, 32(\adr\())
lv.q r\mnum\()03, 48(\adr\())
.endm
.macro sm4 mnum adr
sv.q r\mnum\()00, 0(\adr\())
sv.q r\mnum\()01, 16(\adr\())
sv.q r\mnum\()02, 32(\adr\())
sv.q r\mnum\()02, 48(\adr\())
.endm
lm4 0, $a0 # load mat0
lm4 1, $a1 # load mat1
vmmul.q m200, m000, m100 # multiply matrices
sm4 2, $a2 # store result
jr $ra
There is a third file, callbacks.c, but all that does at the moment is enable the PSP's home button functionality.
Finally there's my CMakeLists.txt
cmake_minimum_required(VERSION 3.27.3)
project(psp-vfputhing)
add_executable(vfputhing
src/main.c
src/callbacks.c
)
target_include_directories(vfputhing PRIVATE include)
target_link_directories(vfputhing PRIVATE src)
if(PLATFORM_PSP)
create_pbp_file(
TARGET vfputhing
TITLE "Dingus Console"
ICON_PATH NULL
PREVIEW_PATH NULL
BUILD_PRX
)
target_link_libraries(vfputhing matrixmul pspdebug pspdisplay pspge pspgu pspgum)
endif()
My first attempt at compilation gave me a linker error, telling me there was an undefined reference to matrixmul4x4. I then tried packaging it into a library, which made the linker error go away, but the PSP will crash any time the function is called. What I expected from this function was for it to place the values of the result matrix into the result array and then for the array to be printed out.