[gamecode] Add a 2d wedge product

While it could be emulated using a 3d cross-product, it was a hack and
required the use of a swizzle (or alias) to extract the scalar value.
This will make 2d PGA a little nicer when I get to modifying qfcc for it
This commit is contained in:
Bill Currie 2023-08-31 15:38:20 +09:00
parent a66fb80517
commit a416e9c060
3 changed files with 33 additions and 2 deletions

View file

@ -3,6 +3,7 @@ bitmap_txt = """
0 0001 mmss store
0 0010 mmss push
0 0011 mmss pop
0 0111 01t0 wedge2
0 1ccc ttss compare
0 0000 00nn
0 0000 0000 noop
@ -520,6 +521,18 @@ swizzle_formats = {
"swizzle_types": float_t,
},
}
wedge2_formats = {
"opcode": "OP_WEDGE_{wedge_type[t]}_2",
"mnemonic": "wedge.{wedge_type[t]}",
"opname": "wedge",
"format": "%Ga, %Gb, %gc",
"widths": "2, 2, 1",
"types": "{wedge_types[t]}",
"args": {
"wedge_type": ['F', 'D'],
"wedge_types": float_t,
},
}
return_formats = {
"opcode": "OP_RETURN",
"mnemonic": "return",
@ -619,6 +632,7 @@ group_map = {
"udivops": udivops_formats,
"vecops": vecops_formats,
"vecops2": vecops2_formats,
"wedge2": wedge2_formats,
"with": with_formats,
}

View file

@ -2291,6 +2291,21 @@ pr_exec_ruamoko (progs_t *pr, int exitdepth)
// 0 0110
// spare
// 0 0111
case OP_WEDGE_F_2:
{
auto a = OPA(vec2);
auto b = OPB(vec2);
OPC(float) = a[0] * b[1] - a[1] * b[0];
}
break;
// spare
case OP_WEDGE_D_2:
{
auto a = OPA(dvec2);
auto b = OPB(dvec2);
OPC(double) = a[0] * b[1] - a[1] * b[0];
}
break;
// spare
#define OP_cmp_1(OP, T, rt, cmp, ct) \

View file

@ -28,7 +28,7 @@ static pr_vec4_t float_globals_init[] = {
static pr_vec4_t float_globals_expect[] = {
{3, 4, 5, 12},
{63, 0, -33, 56},
{63, 16, -33, 56},
{1, 2, 3, 8},
{4, 5, 6, 8},
@ -54,6 +54,7 @@ static pr_vec4_t float_globals_expect[] = {
static dstatement_t float_vector_statements[] = {
{ OP(0, 0, 0, OP_CDOT_F), 0, 2, 4 },
{ OP(0, 0, 0, OP_WEDGE_F_2), 0, 2, 5 },
{ OP(0, 0, 0, OP_CMUL_F), 0, 2, 6 },
{ OP(0, 0, 0, OP_VDOT_F), 8, 12, 16 },
{ OP(0, 0, 0, OP_CROSS_F), 8, 12, 20 },
@ -102,7 +103,7 @@ static pr_dvec4_t double_globals_init[] = {
static pr_dvec4_t double_globals_expect[] = {
{3, 4, 5, 12},
{63, 0, -33, 56},
{63, 16, -33, 56},
{1, 2, 3, 8},
{4, 5, 6, 8},
@ -128,6 +129,7 @@ static pr_dvec4_t double_globals_expect[] = {
static dstatement_t double_vector_statements[] = {
{ OP(0, 0, 0, OP_CDOT_D), 0, 4, 8 },
{ OP(0, 0, 0, OP_WEDGE_D_2), 0, 4, 10 },
{ OP(0, 0, 0, OP_CMUL_D), 0, 4, 12 },
{ OP(0, 0, 0, OP_VDOT_D), 16, 24, 32 },
{ OP(0, 0, 0, OP_CROSS_D), 16, 24, 40 },