Nugget
Loading...
Searching...
No Matches
gte-op.c
Go to the documentation of this file.
1// OP: outer product / cross product
2// Uses rotation matrix diagonal (R11, R22, R33) as D vector
3// Result = D x IR
4
5CESTER_TEST(op_identity_diagonal, gte_tests,
7 cop2_put(9, 1000);
8 cop2_put(10, 2000);
9 cop2_put(11, 3000);
11 cop2_cmd(COP2_OP_CP(1, 0));
12 int32_t ir1, ir2, ir3;
13 cop2_get(9, ir1);
14 cop2_get(10, ir2);
15 cop2_get(11, ir3);
16 // D=(1,1,1), IR=(1000,2000,3000)
17 // cross = (1*3000-1*2000, 1*1000-1*3000, 1*2000-1*1000) = (1000,-2000,1000)
21)
22
23CESTER_TEST(op_unshifted, gte_tests,
25 cop2_put(9, 10);
26 cop2_put(10, 20);
27 cop2_put(11, 30);
29 cop2_cmd(COP2_OP_CP(0, 0)); // sf=0
30 int32_t mac1, mac2, mac3;
34 // sf=0: no shift. D=(0x1000,0x1000,0x1000), IR=(10,20,30)
35 // MAC1 = R22*IR3 - R33*IR2 = 0x1000*30 - 0x1000*20 = 4096*(30-20) = 40960
39)
40
41// OP with asymmetric diagonal
42CESTER_TEST(op_asymmetric, gte_tests,
43 cop2_putc(0, 0x00000800); // R11=0x800 (0.5)
44 cop2_putc(1, 0x00000000);
45 cop2_putc(2, 0x00001000); // R22=0x1000 (1.0)
46 cop2_putc(3, 0x00000000);
47 cop2_putc(4, 0x2000); // R33=0x2000 (2.0)
48 cop2_put(9, 100);
49 cop2_put(10, 200);
50 cop2_put(11, 300);
52 cop2_cmd(COP2_OP_CP(1, 0));
53 int32_t ir1, ir2, ir3;
54 cop2_get(9, ir1);
55 cop2_get(10, ir2);
56 cop2_get(11, ir3);
57 // D=(0.5, 1.0, 2.0), IR=(100,200,300)
58 // cross.x = D.y*IR.z - D.z*IR.y = 1.0*300 - 2.0*200 = 300 - 400 = -100
59 // cross.y = D.z*IR.x - D.x*IR.z = 2.0*100 - 0.5*300 = 200 - 150 = 50
60 // cross.z = D.x*IR.y - D.y*IR.x = 0.5*200 - 1.0*100 = 100 - 100 = 0
64)
65
66// OP with overflow - large values that exceed 44-bit accumulator
67CESTER_TEST(op_overflow_flag, gte_tests,
68 cop2_putc(0, 0x00007fff); // R11=0x7fff
69 cop2_putc(2, 0x00007fff); // R22=0x7fff
70 cop2_putc(4, 0x7fff); // R33=0x7fff
71 cop2_put(9, 0x7fff);
72 cop2_put(10, 0x7fff);
73 cop2_put(11, 0x7fff);
75 cop2_cmd(COP2_OP_CP(0, 0)); // sf=0, no shift -> large products
77 flag = gte_read_flag();
78 ramsyscall_printf("OP overflow: FLAG=0x%08x\n", flag);
79 // With sf=0: MAC = 0x7fff*0x7fff - 0x7fff*0x7fff = 0 for all
80 // Actually this produces zero cross product since all components are equal
82)
#define COP2_OP_CP(sf, lm)
Definition cop2.h:136
#define cop2_cmd(op)
Definition cop2.h:175
#define cop2_put(reg, val)
Definition cop2.h:182
#define cop2_putc(reg, val)
Definition cop2.h:196
#define cop2_get(reg, dest)
Definition cop2.h:189
uint32_t ir1
Definition gte-edgecase.c:108
ramsyscall_printf("OP overflow: FLAG=0x%08x\n", flag)
int32_t mac1
Definition gte-op.c:30
gte_set_identity_rotation()
gte_tests
Definition gte-op.c:23
uint32_t flag
Definition gte-op.c:76
cester_assert_uint_eq(0x00000000, flag)
int32_t mac2
Definition gte-op.c:30
cester_assert_int_eq(40960, mac1)
gte_clear_flag()
int32_t mac3
Definition gte-op.c:30
CESTER_TEST(op_identity_diagonal, gte_tests, gte_set_identity_rotation();cop2_put(9, 1000);cop2_put(10, 2000);cop2_put(11, 3000);gte_clear_flag();cop2_cmd(COP2_OP_CP(1, 0));int32_t ir1, ir2, ir3;cop2_get(9, ir1);cop2_get(10, ir2);cop2_get(11, ir3);cester_assert_int_eq(1000, ir1);cester_assert_int_eq(-2000, ir2);cester_assert_int_eq(1000, ir3);) CESTER_TEST(op_unshifted
uint32_t ir3
Definition gte-precision.c:320
uint32_t ir2
Definition gte-sqr.c:24
void uint32_t(classId, spec)