From 90faeb231f932c6da091103969778b8121baf641 Mon Sep 17 00:00:00 2001 From: Crow-bar Date: Thu, 5 May 2022 21:50:14 +0300 Subject: [PATCH] optimization: aligned memory access, vfpu math --- common/xash3d_types.h | 10 ++ public/matrixlib.c | 212 +++++++++++++++++++++++++--------------- public/xash3d_mathlib.c | 89 ++++------------- ref_gu/gu_frustum.c | 3 +- ref_gu/gu_rmath.c | 23 +++++ 5 files changed, 186 insertions(+), 151 deletions(-) diff --git a/common/xash3d_types.h b/common/xash3d_types.h index e6c9824c..ac29ea29 100644 --- a/common/xash3d_types.h +++ b/common/xash3d_types.h @@ -14,12 +14,22 @@ typedef int sound_t; typedef float vec_t; typedef vec_t vec2_t[2]; typedef vec_t vec3_t[3]; +#if XASH_PSP +typedef vec_t vec4_t[4] __attribute__( ( aligned( 16 ) ) ); +typedef vec_t quat_t[4] __attribute__( ( aligned( 16 ) ) ); +#else typedef vec_t vec4_t[4]; typedef vec_t quat_t[4]; +#endif typedef byte rgba_t[4]; // unsigned byte colorpack typedef byte rgb_t[3]; // unsigned byte colorpack +#if XASH_PSP +typedef vec_t matrix3x4[3][4] __attribute__( ( aligned( 16 ) ) ); +typedef vec_t matrix4x4[4][4] __attribute__( ( aligned( 16 ) ) ); +#else typedef vec_t matrix3x4[3][4]; typedef vec_t matrix4x4[4][4]; +#endif #undef true #undef false diff --git a/public/matrixlib.c b/public/matrixlib.c index 49f710f0..f56a68fb 100644 --- a/public/matrixlib.c +++ b/public/matrixlib.c @@ -39,9 +39,9 @@ void Matrix3x4_VectorTransform( const matrix3x4 in, const float v[3], float out[ __asm__ ( ".set push\n" // save assembler option ".set noreorder\n" // suppress reordering - "ulv.q C100, 0 + %1\n" // C100 = in[0] - "ulv.q C110, 16 + %1\n" // C110 = in[1] - "ulv.q C120, 32 + %1\n" // C120 = in[2] + "lv.q C100, 0 + %1\n" // C100 = in[0] + "lv.q C110, 16 + %1\n" // C110 = in[1] + "lv.q C120, 32 + %1\n" // C120 = in[2] "lv.s S130, 0 + %2\n" // S130 = v[0] "lv.s S131, 4 + %2\n" // S131 = v[1] "lv.s S132, 8 + %2\n" // S132 = v[2] @@ -68,16 +68,20 @@ void Matrix3x4_VectorITransform( const matrix3x4 in, const float v[3], float out __asm__ ( ".set push\n" // save assembler option ".set noreorder\n" // suppress reordering - "ulv.q C100, 0 + %1\n" // C100 = in[0] - "ulv.q C110, 16 + %1\n" // C110 = in[1] - "ulv.q C120, 32 + %1\n" // C120 = in[2] + "lv.q C100, 0 + %1\n" // C100 = in[0] + "lv.q C110, 16 + %1\n" // C110 = in[1] + "lv.q C120, 32 + %1\n" // C120 = in[2] "lv.s S130, 0 + %2\n" // S130 = v[0] "lv.s S131, 4 + %2\n" // S131 = v[1] "lv.s S132, 8 + %2\n" // S132 = v[2] "vsub.t C130, C130, R103\n" // C130 = v - in[][3] +#if 1 + "vtfm3.t C000, E100, C130\n" // C000 = E100 * C130 +#else "vdot.t S000, C130, R100\n" // S000 = dir[0] * in[0][0] + dir[1] * in[1][0] + dir[2] * in[2][0] "vdot.t S001, C130, R101\n" // S001 = dir[0] * in[0][1] + dir[1] * in[1][1] + dir[2] * in[2][1] "vdot.t S002, C130, R102\n" // S002 = dir[0] * in[0][2] + dir[1] * in[1][2] + dir[2] * in[2][2] +#endif "sv.s S000, 0 + %0\n" // out[0] = S000 "sv.s S001, 4 + %0\n" // out[1] = S001 "sv.s S002, 8 + %0\n" // out[2] = S002 @@ -104,14 +108,14 @@ void Matrix3x4_VectorRotate( const matrix3x4 in, const float v[3], float out[3] __asm__ ( ".set push\n" // save assembler option ".set noreorder\n" // suppress reordering - "ulv.q C100, 0 + %1\n" // C100 = in[0] - "ulv.q C110, 16 + %1\n" // C110 = in[1] - "ulv.q C120, 32 + %1\n" // C120 = in[2] + "lv.q C100, 0 + %1\n" // C100 = in[0] + "lv.q C110, 16 + %1\n" // C110 = in[1] + "lv.q C120, 32 + %1\n" // C120 = in[2] "lv.s S130, 0 + %2\n" // S130 = v[0] "lv.s S131, 4 + %2\n" // S131 = v[1] "lv.s S132, 8 + %2\n" // S132 = v[2] -#if 0 - "vtfm3.t C000, M100, C130\n" // c000 = M100 * C130 +#if 1 + "vtfm3.t C000, M100, C130\n" // C000 = M100 * C130 #else "vdot.t S000, C130, C100\n" // S000 = v[0] * in[0][0] + v[1] * in[0][1] + v[2] * in[0][2] "vdot.t S001, C130, C110\n" // S001 = v[0] * in[1][0] + v[1] * in[1][1] + v[2] * in[1][2] @@ -138,14 +142,14 @@ void Matrix3x4_VectorIRotate( const matrix3x4 in, const float v[3], float out[3] __asm__ ( ".set push\n" // save assembler option ".set noreorder\n" // suppress reordering - "ulv.q C100, 0 + %1\n" // C100 = in[0] - "ulv.q C110, 16 + %1\n" // C110 = in[1] - "ulv.q C120, 32 + %1\n" // C120 = in[2] + "lv.q C100, 0 + %1\n" // C100 = in[0] + "lv.q C110, 16 + %1\n" // C110 = in[1] + "lv.q C120, 32 + %1\n" // C120 = in[2] "lv.s S130, 0 + %2\n" // S130 = v[0] "lv.s S131, 4 + %2\n" // S131 = v[1] "lv.s S132, 8 + %2\n" // S132 = v[2] -#if 0 - "vtfm3.t C000, E100, C130\n" // c000 = E100 * C130 +#if 1 + "vtfm3.t C000, E100, C130\n" // C000 = E100 * C130 #else "vdot.t S000, C130, R100\n" // S000 = v[0] * in[0][0] + v[1] * in[1][0] + v[2] * in[2][0] "vdot.t S001, C130, R101\n" // S001 = v[0] * in[0][1] + v[1] * in[1][1] + v[2] * in[2][1] @@ -167,6 +171,27 @@ void Matrix3x4_VectorIRotate( const matrix3x4 in, const float v[3], float out[3] void Matrix3x4_ConcatTransforms( matrix3x4 out, const matrix3x4 in1, const matrix3x4 in2 ) { +#if XASH_PSP + __asm__ ( + ".set push\n" // save assembler option + ".set noreorder\n" // suppress reordering + "lv.q C100, 0 + %1\n" // C100 = in1[0] + "lv.q C110, 16 + %1\n" // C110 = in1[1] + "lv.q C120, 32 + %1\n" // C120 = in1[2] + "vzero.q C130\n" // C130 = [0, 0, 0, 0] + "lv.q C200, 0 + %2\n" // C100 = in2[0] + "lv.q C210, 16 + %2\n" // C110 = in2[1] + "lv.q C220, 32 + %2\n" // C120 = in2[2] + "vidt.q C230\n" // C230 = [0, 0, 0, 1] + "vmmul.q E000, E100, E200\n" // E000 = E100 * E200 + "sv.q C000, 0 + %0\n" // out[0] = C000 + "sv.q C010, 16 + %0\n" // out[1] = C010 + "sv.q C020, 32 + %0\n" // out[2] = C020 + ".set pop\n" // restore assembler option + : "=m"( *out ) + : "m"( *in1 ), "m"( *in2 ) + ); +#else out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] + in1[0][2] * in2[2][0]; out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] + in1[0][2] * in2[2][1]; out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] + in1[0][2] * in2[2][2]; @@ -179,6 +204,7 @@ void Matrix3x4_ConcatTransforms( matrix3x4 out, const matrix3x4 in1, const matri out[2][1] = in1[2][0] * in2[0][1] + in1[2][1] * in2[1][1] + in1[2][2] * in2[2][1]; out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] + in1[2][2] * in2[2][2]; out[2][3] = in1[2][0] * in2[0][3] + in1[2][1] * in2[1][3] + in1[2][2] * in2[2][3] + in1[2][3]; +#endif } void Matrix3x4_SetOrigin( matrix3x4 out, float x, float y, float z ) @@ -221,7 +247,7 @@ void Matrix3x4_FromOriginQuat( matrix3x4 out, const vec4_t quaternion, const vec __asm__ ( ".set push\n" // save assembler option ".set noreorder\n" // suppress reordering - "ulv.q C130, %1\n" // C130 = quaternion + "lv.q C130, %1\n" // C130 = quaternion "lv.s S003, 0 + %2\n" // S003 = out[0][3] = origin[0] "lv.s S013, 4 + %2\n" // S013 = out[1][3] = origin[1] "lv.s S023, 8 + %2\n" // S023 = out[2][3] = origin[2] @@ -233,9 +259,9 @@ void Matrix3x4_FromOriginQuat( matrix3x4 out, const vec4_t quaternion, const vec "vmov.q C220, C130[ Y, -X, W, Z]\n" // C220 = ( y, -x, w, z) "vmov.q C230, C130[-X, -Y, -Z, W]\n" // C230 = (-x, -y, -z, w) "vmmul.q E000, E100, E200\n" // E000 = E100 * E200 - "usv.q C000, 0 + %0\n" // out[0] = C000 - "usv.q C010, 16 + %0\n" // out[1] = C010 - "usv.q C020, 32 + %0\n" // out[2] = C020 + "sv.q C000, 0 + %0\n" // out[0] = C000 + "sv.q C010, 16 + %0\n" // out[1] = C010 + "sv.q C020, 32 + %0\n" // out[2] = C020 ".set pop\n" // restore assembler option : "=m"( *out ) : "m"( *quaternion ), "m"( *origin ) @@ -306,9 +332,9 @@ void Matrix3x4_CreateFromEntity( matrix3x4 out, const vec3_t angles, const vec3_ /**/ "vmscl.t E000, E000, S130\n" // E000 = E000 * S103 = out(3) * scale /**/ - "usv.q C000, 0 + %0\n" // out[0] = C000 - "usv.q C010, 16 + %0\n" // out[1] = C010 - "usv.q C020, 32 + %0\n" // out[2] = C020 + "sv.q C000, 0 + %0\n" // out[0] = C000 + "sv.q C010, 16 + %0\n" // out[1] = C010 + "sv.q C020, 32 + %0\n" // out[2] = C020 ".set pop\n" // restore assembler option : "=m"( *out ) : "m"( *angles ), "m"( *origin ), "m"( scale ) @@ -347,9 +373,9 @@ void Matrix3x4_CreateFromEntity( matrix3x4 out, const vec3_t angles, const vec3_ /**/ "vmscl.t E000, E000, S130\n" // E000 = E000 * S103 = out(3) * scale /**/ - "usv.q C000, 0 + %0\n" // out[0] = C000 - "usv.q C010, 16 + %0\n" // out[1] = C010 - "usv.q C020, 32 + %0\n" // out[2] = C020 + "sv.q C000, 0 + %0\n" // out[0] = C000 + "sv.q C010, 16 + %0\n" // out[1] = C010 + "sv.q C020, 32 + %0\n" // out[2] = C020 ".set pop\n" // restore assembler option : "=m"( *out ) : "m"( *angles ), "m"( *origin ), "m"( scale ) @@ -382,9 +408,9 @@ void Matrix3x4_CreateFromEntity( matrix3x4 out, const vec3_t angles, const vec3_ /**/ "vmscl.t E000, E000, S130\n" // E000 = E000 * S103 = out(3) * scale /**/ - "usv.q C000, 0 + %0\n" // out[0] = C000 - "usv.q C010, 16 + %0\n" // out[1] = C010 - "usv.q C020, 32 + %0\n" // out[2] = C020 + "sv.q C000, 0 + %0\n" // out[0] = C000 + "sv.q C010, 16 + %0\n" // out[1] = C010 + "sv.q C020, 32 + %0\n" // out[2] = C020 ".set pop\n" // restore assembler option : "=m"( *out ) : "m"( *angles ), "m"( *origin ), "m"( scale ) @@ -407,9 +433,9 @@ void Matrix3x4_CreateFromEntity( matrix3x4 out, const vec3_t angles, const vec3_ "vmov.s S011, S130\n" // S011 = S130 = out[1][1] = scale "vmov.s S022, S130\n" // S022 = S130 = out[2][2] = scale /**/ - "usv.q C000, 0 + %0\n" // out[0] = C000 - "usv.q C010, 16 + %0\n" // out[1] = C010 - "usv.q C020, 32 + %0\n" // out[2] = C020 + "sv.q C000, 0 + %0\n" // out[0] = C000 + "sv.q C010, 16 + %0\n" // out[1] = C010 + "sv.q C020, 32 + %0\n" // out[2] = C020 ".set pop\n" // restore assembler option : "=m"( *out ) : "m"( *origin ), "m"( scale ) @@ -502,9 +528,9 @@ void Matrix3x4_TransformPositivePlane( const matrix3x4 in, const vec3_t normal, __asm__ ( ".set push\n" // save assembler option ".set noreorder\n" // suppress reordering - "ulv.q C100, 0 + %2\n" // C100 = in[0] - "ulv.q C110, 16 + %2\n" // C110 = in[1] - "ulv.q C120, 32 + %2\n" // C120 = in[2] + "lv.q C100, 0 + %2\n" // C100 = in[0] + "lv.q C110, 16 + %2\n" // C110 = in[1] + "lv.q C120, 32 + %2\n" // C120 = in[2] "lv.s S200, 0 + %3\n" // S200 = normal[0] "lv.s S201, 4 + %3\n" // S201 = normal[1] "lv.s S202, 8 + %3\n" // S202 = normal[2] @@ -624,9 +650,9 @@ void Matrix4x4_VectorTransform( const matrix4x4 in, const float v[3], float out[ __asm__ ( ".set push\n" // save assembler option ".set noreorder\n" // suppress reordering - "ulv.q C100, 0 + %1\n" // C100 = in[0] - "ulv.q C110, 16 + %1\n" // C110 = in[1] - "ulv.q C120, 32 + %1\n" // C120 = in[2] + "lv.q C100, 0 + %1\n" // C100 = in[0] + "lv.q C110, 16 + %1\n" // C110 = in[1] + "lv.q C120, 32 + %1\n" // C120 = in[2] "lv.s S130, 0 + %2\n" // S130 = v[0] "lv.s S131, 4 + %2\n" // S131 = v[1] "lv.s S132, 8 + %2\n" // S132 = v[2] @@ -653,16 +679,20 @@ void Matrix4x4_VectorITransform( const matrix4x4 in, const float v[3], float out __asm__ ( ".set push\n" // save assembler option ".set noreorder\n" // suppress reordering - "ulv.q C100, 0 + %1\n" // C100 = in[0] - "ulv.q C110, 16 + %1\n" // C110 = in[1] - "ulv.q C120, 32 + %1\n" // C120 = in[2] + "lv.q C100, 0 + %1\n" // C100 = in[0] + "lv.q C110, 16 + %1\n" // C110 = in[1] + "lv.q C120, 32 + %1\n" // C120 = in[2] "lv.s S130, 0 + %2\n" // S130 = v[0] "lv.s S131, 4 + %2\n" // S131 = v[1] "lv.s S132, 8 + %2\n" // S132 = v[2] - "vsub.t C200, C130, R103\n" // C130 = v - in[][3] - "vdot.t S000, C200, R100\n" // S000 = dir[0] * in[0][0] + dir[1] * in[1][0] + dir[2] * in[2][0] - "vdot.t S001, C200, R101\n" // S001 = dir[0] * in[0][1] + dir[1] * in[1][1] + dir[2] * in[2][1] - "vdot.t S002, C200, R102\n" // S002 = dir[0] * in[0][2] + dir[1] * in[1][2] + dir[2] * in[2][2] + "vsub.t C130, C130, R103\n" // C130 = v - in[][3] +#if 1 + "vtfm3.t C000, E100, C130\n" // C000 = E100 * C130 +#else + "vdot.t S000, C130, R100\n" // S000 = dir[0] * in[0][0] + dir[1] * in[1][0] + dir[2] * in[2][0] + "vdot.t S001, C130, R101\n" // S001 = dir[0] * in[0][1] + dir[1] * in[1][1] + dir[2] * in[2][1] + "vdot.t S002, C130, R102\n" // S002 = dir[0] * in[0][2] + dir[1] * in[1][2] + dir[2] * in[2][2] +#endif "sv.s S000, 0 + %0\n" // out[0] = S000 "sv.s S001, 4 + %0\n" // out[1] = S001 "sv.s S002, 8 + %0\n" // out[2] = S002 @@ -689,14 +719,14 @@ void Matrix4x4_VectorRotate( const matrix4x4 in, const float v[3], float out[3] __asm__ ( ".set push\n" // save assembler option ".set noreorder\n" // suppress reordering - "ulv.q C100, 0 + %1\n" // C100 = in[0] - "ulv.q C110, 16 + %1\n" // C110 = in[1] - "ulv.q C120, 32 + %1\n" // C120 = in[2] + "lv.q C100, 0 + %1\n" // C100 = in[0] + "lv.q C110, 16 + %1\n" // C110 = in[1] + "lv.q C120, 32 + %1\n" // C120 = in[2] "lv.s S130, 0 + %2\n" // S130 = v[0] "lv.s S131, 4 + %2\n" // S131 = v[1] "lv.s S132, 8 + %2\n" // S132 = v[2] -#if 0 - "vtfm3.t C000, M100, C130\n" // c000 = M100 * C130 +#if 1 + "vtfm3.t C000, M100, C130\n" // C000 = M100 * C130 #else "vdot.t S000, C130, C100\n" // S000 = v[0] * in[0][0] + v[1] * in[0][1] + v[2] * in[0][2] "vdot.t S001, C130, C110\n" // S001 = v[0] * in[1][0] + v[1] * in[1][1] + v[2] * in[1][2] @@ -722,14 +752,14 @@ void Matrix4x4_VectorIRotate( const matrix4x4 in, const float v[3], float out[3] __asm__ ( ".set push\n" // save assembler option ".set noreorder\n" // suppress reordering - "ulv.q C100, 0 + %1\n" // C100 = in[0] - "ulv.q C110, 16 + %1\n" // C110 = in[1] - "ulv.q C120, 32 + %1\n" // C120 = in[2] + "lv.q C100, 0 + %1\n" // C100 = in[0] + "lv.q C110, 16 + %1\n" // C110 = in[1] + "lv.q C120, 32 + %1\n" // C120 = in[2] "lv.s S130, 0 + %2\n" // S130 = v[0] "lv.s S131, 4 + %2\n" // S131 = v[1] "lv.s S132, 8 + %2\n" // S132 = v[2] -#if 0 - "vtfm3.t C000, E100, C130\n" // c000 = E100 * C130 +#if 1 + "vtfm3.t C000, E100, C130\n" // C000 = E100 * C130 #else "vdot.t S000, C130, R100\n" // S000 = v[0] * in[0][0] + v[1] * in[1][0] + v[2] * in[2][0] "vdot.t S001, C130, R101\n" // S001 = v[0] * in[0][1] + v[1] * in[1][1] + v[2] * in[2][1] @@ -752,6 +782,27 @@ void Matrix4x4_VectorIRotate( const matrix4x4 in, const float v[3], float out[3] void Matrix4x4_ConcatTransforms( matrix4x4 out, const matrix4x4 in1, const matrix4x4 in2 ) { +#if XASH_PSP + __asm__ ( + ".set push\n" // save assembler option + ".set noreorder\n" // suppress reordering + "lv.q C100, 0 + %1\n" // C100 = in1[0] + "lv.q C110, 16 + %1\n" // C110 = in1[1] + "lv.q C120, 32 + %1\n" // C120 = in1[2] + "vzero.q C130\n" // C130 = [0, 0, 0, 0] + "lv.q C200, 0 + %2\n" // C100 = in2[0] + "lv.q C210, 16 + %2\n" // C110 = in2[1] + "lv.q C220, 32 + %2\n" // C120 = in2[2] + "vidt.q C230\n" // C230 = [0, 0, 0, 1] + "vmmul.q E000, E100, E200\n" // E000 = E100 * E200 + "sv.q C000, 0 + %0\n" // out[0] = C000 + "sv.q C010, 16 + %0\n" // out[1] = C010 + "sv.q C020, 32 + %0\n" // out[2] = C020 + ".set pop\n" // restore assembler option + : "=m"( *out ) + : "m"( *in1 ), "m"( *in2 ) + ); +#else out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] + in1[0][2] * in2[2][0]; out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] + in1[0][2] * in2[2][1]; out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] + in1[0][2] * in2[2][2]; @@ -764,6 +815,7 @@ void Matrix4x4_ConcatTransforms( matrix4x4 out, const matrix4x4 in1, const matri out[2][1] = in1[2][0] * in2[0][1] + in1[2][1] * in2[1][1] + in1[2][2] * in2[2][1]; out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] + in1[2][2] * in2[2][2]; out[2][3] = in1[2][0] * in2[0][3] + in1[2][1] * in2[1][3] + in1[2][2] * in2[2][3] + in1[2][3]; +#endif } void Matrix4x4_SetOrigin( matrix4x4 out, float x, float y, float z ) @@ -818,7 +870,7 @@ void Matrix4x4_CreateFromEntity( matrix4x4 out, const vec3_t angles, const vec3_ "lv.s S130, %3\n" // S130 = scale /**/ "vfim.s S120, 0.0111111111111111\n" // S121 = 0.0111111111111111 const ( 2 / 180 ) - "vscl.t C100, C100, S120\n" // C100 = C100 * S120 = angles * ( 2 / 180 ) + "vscl.t C100, C100, S120\n" // C100 = C100 * S120 = angles * ( 2 / 180 ) /**/ "vsin.t C110, C100\n" // C110 = sin( C100 ) P Y R "vcos.t C120, C100\n" // C120 = cos( C100 ) P Y R @@ -849,10 +901,10 @@ void Matrix4x4_CreateFromEntity( matrix4x4 out, const vec3_t angles, const vec3_ "vmscl.t E000, E000, S130\n" // E000 = E000 * S103 = out(3) * scale "vidt.q C030\n" // C030 = [0.0f, 0.0f, 0.0f, 1.0f] /**/ - "usv.q C000, 0 + %0\n" // out[0] = C000 - "usv.q C010, 16 + %0\n" // out[1] = C010 - "usv.q C020, 32 + %0\n" // out[2] = C020 - "usv.q C030, 48 + %0\n" // out[3] = C030 + "sv.q C000, 0 + %0\n" // out[0] = C000 + "sv.q C010, 16 + %0\n" // out[1] = C010 + "sv.q C020, 32 + %0\n" // out[2] = C020 + "sv.q C030, 48 + %0\n" // out[3] = C030 ".set pop\n" // restore assembler option : "=m"( *out ) : "m"( *angles ), "m"( *origin ), "m"( scale ) @@ -871,7 +923,7 @@ void Matrix4x4_CreateFromEntity( matrix4x4 out, const vec3_t angles, const vec3_ "lv.s S130, %3\n" // S130 = scale /**/ "vfim.s S120, 0.0111111111111111\n" // S121 = 0.0111111111111111 const ( 2 / 180 ) - "vscl.p C100, C100, S120\n" // C100 = C100 * S120 = angles * ( 2 / 180 ) + "vscl.p C100, C100, S120\n" // C100 = C100 * S120 = angles * ( 2 / 180 ) /**/ "vsin.p C110, C100\n" // C110 = sin( C100 ) P Y "vcos.p C120, C100\n" // C120 = cos( C100 ) P Y @@ -892,10 +944,10 @@ void Matrix4x4_CreateFromEntity( matrix4x4 out, const vec3_t angles, const vec3_ "vmscl.t E000, E000, S130\n" // E000 = E000 * S103 = out(3) * scale "vidt.q C030\n" // C030 = [0.0f, 0.0f, 0.0f, 1.0f] /**/ - "usv.q C000, 0 + %0\n" // out[0] = C000 - "usv.q C010, 16 + %0\n" // out[1] = C010 - "usv.q C020, 32 + %0\n" // out[2] = C020 - "usv.q C030, 48 + %0\n" // out[3] = C030 + "sv.q C000, 0 + %0\n" // out[0] = C000 + "sv.q C010, 16 + %0\n" // out[1] = C010 + "sv.q C020, 32 + %0\n" // out[2] = C020 + "sv.q C030, 48 + %0\n" // out[3] = C030 ".set pop\n" // restore assembler option : "=m"( *out ) : "m"( *angles ), "m"( *origin ), "m"( scale ) @@ -913,7 +965,7 @@ void Matrix4x4_CreateFromEntity( matrix4x4 out, const vec3_t angles, const vec3_ "lv.s S130, %3\n" // S130 = scale /**/ "vfim.s S120, 0.0111111111111111\n" // S121 = 0.0111111111111111 const ( 2 / 180 ) - "vmul.s S101, S101, S120\n" // S101 = S101 * S120 = angles[YAW] * ( 2 / 180 ) + "vmul.s S101, S101, S120\n" // S101 = S101 * S120 = angles[YAW] * ( 2 / 180 ) /**/ "vsin.s S111, S101\n" // S111 = sin( S101 ) Y "vcos.s S121, S101\n" // S121 = cos( S101 ) Y @@ -929,10 +981,10 @@ void Matrix4x4_CreateFromEntity( matrix4x4 out, const vec3_t angles, const vec3_ "vmscl.t E000, E000, S130\n" // E000 = E000 * S103 = out(3) * scale "vidt.q C030\n" // C030 = [0.0f, 0.0f, 0.0f, 1.0f] /**/ - "usv.q C000, 0 + %0\n" // out[0] = C000 - "usv.q C010, 16 + %0\n" // out[1] = C010 - "usv.q C020, 32 + %0\n" // out[2] = C020 - "usv.q C030, 48 + %0\n" // out[3] = C030 + "sv.q C000, 0 + %0\n" // out[0] = C000 + "sv.q C010, 16 + %0\n" // out[1] = C010 + "sv.q C020, 32 + %0\n" // out[2] = C020 + "sv.q C030, 48 + %0\n" // out[3] = C030 ".set pop\n" // restore assembler option : "=m"( *out ) : "m"( *angles ), "m"( *origin ), "m"( scale ) @@ -956,10 +1008,10 @@ void Matrix4x4_CreateFromEntity( matrix4x4 out, const vec3_t angles, const vec3_ "vmov.s S011, S130\n" // S011 = S130 = out[1][1] = scale "vmov.s S022, S130\n" // S022 = S130 = out[2][2] = scale /**/ - "usv.q C000, 0 + %0\n" // out[0] = C000 - "usv.q C010, 16 + %0\n" // out[1] = C010 - "usv.q C020, 32 + %0\n" // out[2] = C020 - "usv.q C030, 48 + %0\n" // out[3] = C030 + "sv.q C000, 0 + %0\n" // out[0] = C000 + "sv.q C010, 16 + %0\n" // out[1] = C010 + "sv.q C020, 32 + %0\n" // out[2] = C020 + "sv.q C030, 48 + %0\n" // out[3] = C030 ".set pop\n" // restore assembler option : "=m"( *out ) : "m"( *origin ), "m"( scale ) @@ -1091,9 +1143,9 @@ void Matrix4x4_TransformPositivePlane( const matrix4x4 in, const vec3_t normal, __asm__ ( ".set push\n" // save assembler option ".set noreorder\n" // suppress reordering - "ulv.q C100, 0 + %2\n" // C100 = in[0] - "ulv.q C110, 16 + %2\n" // C110 = in[1] - "ulv.q C120, 32 + %2\n" // C120 = in[2] + "lv.q C100, 0 + %2\n" // C100 = in[0] + "lv.q C110, 16 + %2\n" // C110 = in[1] + "lv.q C120, 32 + %2\n" // C120 = in[2] "lv.s S200, 0 + %3\n" // S200 = normal[0] "lv.s S201, 4 + %3\n" // S201 = normal[1] "lv.s S202, 8 + %3\n" // S202 = normal[2] @@ -1131,9 +1183,9 @@ void Matrix4x4_TransformStandardPlane( const matrix4x4 in, const vec3_t normal, __asm__ ( ".set push\n" // save assembler option ".set noreorder\n" // suppress reordering - "ulv.q C100, 0 + %2\n" // C100 = in[0] - "ulv.q C110, 16 + %2\n" // C110 = in[1] - "ulv.q C120, 32 + %2\n" // C120 = in[2] + "lv.q C100, 0 + %2\n" // C100 = in[0] + "lv.q C110, 16 + %2\n" // C110 = in[1] + "lv.q C120, 32 + %2\n" // C120 = in[2] "lv.s S200, 0 + %3\n" // S200 = normal[0] "lv.s S201, 4 + %3\n" // S201 = normal[1] "lv.s S202, 8 + %3\n" // S202 = normal[2] diff --git a/public/xash3d_mathlib.c b/public/xash3d_mathlib.c index e465f4a5..d3ba9c57 100644 --- a/public/xash3d_mathlib.c +++ b/public/xash3d_mathlib.c @@ -312,11 +312,11 @@ float rsqrt( float number ) ".set push\n" // save assembler option ".set noreorder\n" // suppress reordering "lv.s S000, %1\n" // S000 = number - "vzero.s S001\n" // S111 = 0 + "vzero.s S001\n" // S100 = 0 "vcmp.s EZ, S000\n" // CC[0] = ( S000 == 0.0f ) "vrsq.s S000, S000\n" // S000 = 1.0 / sqrt( S000 ) "vcmovt.s S000, S001, 0\n" // if ( CC[0] ) S000 = S001 - "sv.s S000, %0\n" // result = S001 + "sv.s S000, %0\n" // result = S000 ".set pop\n" // restore assembler option : "=m"( result ) : "m"( number ) @@ -940,144 +940,93 @@ int BoxOnPlaneSide( const vec3_t emins, const vec3_t emaxs, const mplane_t *p ) "addiu $8, $8, 1\n" // $8 = $8 + 1 ( delay slot ) "beq %[signbits], $8, 7f\n" // jump to 7 "nop\n" // ( delay slot ) - "j 8f\n" // jump to SetSides + "j 9f\n" // jump to SetSides "nop\n" // ( delay slot ) "0:\n" -/* - dist1 = p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2]; - dist2 = p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2]; -*/ "lv.s S010, 0 + %[emaxs]\n" // S010 = emaxs[0] "lv.s S011, 4 + %[emaxs]\n" // S011 = emaxs[1] "lv.s S012, 8 + %[emaxs]\n" // S012 = emaxs[2] "lv.s S020, 0 + %[emins]\n" // S020 = emins[0] "lv.s S021, 4 + %[emins]\n" // S021 = emins[1] "lv.s S022, 8 + %[emins]\n" // S022 = emins[2] - "vdot.t S030, C000, C010\n" // S030 = C000 * C010 - "vdot.t S031, C000, C020\n" // S030 = C000 * C020 - "j 8f\n" // jump to SetSides + "j 8f\n" // jump to DotProduct "nop\n" // ( delay slot ) "1:\n" -/* - dist1 = p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2]; - dist2 = p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2]; -*/ "lv.s S010, 0 + %[emins]\n" // S010 = emins[0] "lv.s S011, 4 + %[emaxs]\n" // S011 = emaxs[1] "lv.s S012, 8 + %[emaxs]\n" // S012 = emaxs[2] "lv.s S020, 0 + %[emaxs]\n" // S020 = emaxs[0] "lv.s S021, 4 + %[emins]\n" // S021 = emins[1] "lv.s S022, 8 + %[emins]\n" // S022 = emins[2] - "vdot.t S030, C000, C010\n" // S030 = C000 * C010 - "vdot.t S031, C000, C020\n" // S030 = C000 * C020 - "j 8f\n" // jump to SetSides + "j 8f\n" // jump to DotProduct "nop\n" // ( delay slot ) "2:\n" -/* - dist1 = p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2]; - dist2 = p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2]; -*/ "lv.s S010, 0 + %[emaxs]\n" // S010 = emaxs[0] "lv.s S011, 4 + %[emins]\n" // S011 = emins[1] "lv.s S012, 8 + %[emaxs]\n" // S012 = emaxs[2] "lv.s S020, 0 + %[emins]\n" // S020 = emins[0] "lv.s S021, 4 + %[emaxs]\n" // S021 = emaxs[1] "lv.s S022, 8 + %[emins]\n" // S022 = emins[2] - "vdot.t S030, C000, C010\n" // S030 = C000 * C010 - "vdot.t S031, C000, C020\n" // S030 = C000 * C020 - "j 8f\n" // jump to SetSides + "j 8f\n" // jump to DotProduct "nop\n" // ( delay slot ) "3:\n" -/* - dist1 = p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2]; - dist2 = p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2]; -*/ "lv.s S010, 0 + %[emins]\n" // S010 = emins[0] "lv.s S011, 4 + %[emins]\n" // S011 = emins[1] "lv.s S012, 8 + %[emaxs]\n" // S012 = emaxs[2] "lv.s S020, 0 + %[emaxs]\n" // S020 = emaxs[0] "lv.s S021, 4 + %[emaxs]\n" // S021 = emaxs[1] "lv.s S022, 8 + %[emins]\n" // S022 = emins[2] - "vdot.t S030, C000, C010\n" // S030 = C000 * C010 - "vdot.t S031, C000, C020\n" // S030 = C000 * C020 - "j 8f\n" // jump to SetSides + "j 8f\n" // jump to DotProduct "nop\n" // ( delay slot ) "4:\n" -/* - dist1 = p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2]; - dist2 = p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2]; -*/ "lv.s S010, 0 + %[emaxs]\n" // S010 = emaxs[0] "lv.s S011, 4 + %[emaxs]\n" // S011 = emaxs[1] "lv.s S012, 8 + %[emins]\n" // S012 = emins[2] "lv.s S020, 0 + %[emins]\n" // S020 = emins[0] "lv.s S021, 4 + %[emins]\n" // S021 = emins[1] "lv.s S022, 8 + %[emaxs]\n" // S022 = emaxs[2] - "vdot.t S030, C000, C010\n" // S030 = C000 * C010 - "vdot.t S031, C000, C020\n" // S030 = C000 * C020 - "j 8f\n" // jump to SetSides + "j 8f\n" // jump to DotProduct "nop\n" // ( delay slot ) "5:\n" -/* - dist1 = p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2]; - dist2 = p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2]; -*/ "lv.s S010, 0 + %[emins]\n" // S010 = emins[0] "lv.s S011, 4 + %[emaxs]\n" // S011 = emaxs[1] "lv.s S012, 8 + %[emins]\n" // S012 = emins[2] "lv.s S020, 0 + %[emaxs]\n" // S020 = emaxs[0] "lv.s S021, 4 + %[emins]\n" // S021 = emins[1] "lv.s S022, 8 + %[emaxs]\n" // S022 = emaxs[2] - "vdot.t S030, C000, C010\n" // S030 = C000 * C010 - "vdot.t S031, C000, C020\n" // S030 = C000 * C020 - "j 8f\n" // jump to SetSides + "j 8f\n" // jump to DotProduct "nop\n" // ( delay slot ) "6:\n" -/* - dist1 = p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2]; - dist2 = p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2]; -*/ "lv.s S010, 0 + %[emaxs]\n" // S010 = emaxs[0] "lv.s S011, 4 + %[emins]\n" // S011 = emins[1] "lv.s S012, 8 + %[emins]\n" // S012 = emins[2] "lv.s S020, 0 + %[emins]\n" // S020 = emins[0] "lv.s S021, 4 + %[emaxs]\n" // S021 = emaxs[1] "lv.s S022, 8 + %[emaxs]\n" // S022 = emaxs[2] - "vdot.t S030, C000, C010\n" // S030 = C000 * C010 - "vdot.t S031, C000, C020\n" // S030 = C000 * C020 - "j 8f\n" // jump to SetSides + "j 8f\n" // jump to DotProduct "nop\n" // ( delay slot ) "7:\n" -/* - dist1 = p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2]; - dist2 = p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2]; -*/ "lv.s S010, 0 + %[emins]\n" // S010 = emins[0] "lv.s S011, 4 + %[emins]\n" // S011 = emins[1] "lv.s S012, 8 + %[emins]\n" // S012 = emins[2] "lv.s S020, 0 + %[emaxs]\n" // S020 = emaxs[0] "lv.s S021, 4 + %[emaxs]\n" // S021 = emaxs[1] "lv.s S022, 8 + %[emaxs]\n" // S022 = emaxs[2] + "8:\n" // DotProduct "vdot.t S030, C000, C010\n" // S030 = C000 * C010 - "vdot.t S031, C000, C020\n" // S030 = C000 * C020 - "8:\n" // SetSides -/* - if( dist1 >= p->dist ) - sides = 1; - if( dist2 < p->dist ) - sides |= 2; -*/ + "vdot.t S031, C000, C020\n" // S031 = C000 * C020 + "9:\n" // SetSides "addiu %[sides], $0, 0\n" // sides = 0 "vcmp.s LT, S030, S032\n" // S030 < S032 - "bvt 0, 9f\n" // if ( CC[0] == 1 ) jump to 9 - "nop\n" // ( delay slot ) - "addiu %[sides], %[sides], 1\n"// sides = 1 - "9:\n" - "vcmp.s GE, S031, S032\n" // S031 >= S032 "bvt 0, 10f\n" // if ( CC[0] == 1 ) jump to 10 "nop\n" // ( delay slot ) - "addiu %[sides], %[sides], 2\n"// sides = sides + 2 + "addiu %[sides], %[sides], 1\n"// sides = 1 "10:\n" + "vcmp.s GE, S031, S032\n" // S031 >= S032 + "bvt 0, 11f\n" // if ( CC[0] == 1 ) jump to 11 + "nop\n" // ( delay slot ) + "addiu %[sides], %[sides], 2\n"// sides = sides + 2 + "11:\n" ".set pop\n" // restore assembler option : [sides] "=r" ( sides ) : [normal] "m" ( p->normal ), diff --git a/ref_gu/gu_frustum.c b/ref_gu/gu_frustum.c index a52a8fb1..35c97c69 100644 --- a/ref_gu/gu_frustum.c +++ b/ref_gu/gu_frustum.c @@ -235,11 +235,12 @@ void GL_FrustumComputeBounds( gl_frustum_t *out, vec3_t mins, vec3_t maxs ) void GL_FrustumDrawDebug( gl_frustum_t *out ) { +/* vec3_t bbox[8]; int i; GL_FrustumComputeCorners( out, bbox ); -/* + // g-cont. frustum must be yellow :-) pglColor4f( 1.0f, 1.0f, 0.0f, 1.0f ); pglDisable( GL_TEXTURE_2D ); diff --git a/ref_gu/gu_rmath.c b/ref_gu/gu_rmath.c index c3a3db24..78b91e3e 100644 --- a/ref_gu/gu_rmath.c +++ b/ref_gu/gu_rmath.c @@ -25,6 +25,28 @@ GNU General Public License for more details. */ void Matrix4x4_Concat( matrix4x4 out, const matrix4x4 in1, const matrix4x4 in2 ) { +#if 1 + __asm__ ( + ".set push\n" // save assembler option + ".set noreorder\n" // suppress reordering + "lv.q C100, 0 + %1\n" // C100 = in1[0] + "lv.q C110, 16 + %1\n" // C110 = in1[1] + "lv.q C120, 32 + %1\n" // C120 = in1[2] + "lv.q C130, 48 + %1\n" // C130 = in1[3] + "lv.q C200, 0 + %2\n" // C200 = in2[0] + "lv.q C210, 16 + %2\n" // C210 = in2[1] + "lv.q C220, 32 + %2\n" // C220 = in2[2] + "lv.q C230, 48 + %2\n" // C230 = in2[3] + "vmmul.q E000, E100, E200\n" // E000 = E100 * E200 + "sv.q C000, 0 + %0\n" // out[0] = C000 + "sv.q C010, 16 + %0\n" // out[1] = C010 + "sv.q C020, 32 + %0\n" // out[2] = C020 + "sv.q C030, 48 + %0\n" // out[3] = C030 + ".set pop\n" // restore assembler option + : "=m"( *out ) + : "m"( *in1 ), "m"( *in2 ) + ); +#else out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] + in1[0][2] * in2[2][0] + in1[0][3] * in2[3][0]; out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] + in1[0][2] * in2[2][1] + in1[0][3] * in2[3][1]; out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] + in1[0][2] * in2[2][2] + in1[0][3] * in2[3][2]; @@ -41,6 +63,7 @@ void Matrix4x4_Concat( matrix4x4 out, const matrix4x4 in1, const matrix4x4 in2 ) out[3][1] = in1[3][0] * in2[0][1] + in1[3][1] * in2[1][1] + in1[3][2] * in2[2][1] + in1[3][3] * in2[3][1]; out[3][2] = in1[3][0] * in2[0][2] + in1[3][1] * in2[1][2] + in1[3][2] * in2[2][2] + in1[3][3] * in2[3][2]; out[3][3] = in1[3][0] * in2[0][3] + in1[3][1] * in2[1][3] + in1[3][2] * in2[2][3] + in1[3][3] * in2[3][3]; +#endif } /*