Nugget
Loading...
Searching...
No Matches
gte-sqr.c
Go to the documentation of this file.
1// SQR: square of IR vector
2
3CESTER_TEST(sqr_shifted, gte_tests,
4 cop2_put(9, 0x1000); // 1.0
5 cop2_put(10, 0x0800); // 0.5
6 cop2_put(11, 0x2000); // 2.0
8 cop2_cmd(COP2_SQR(1, 0));
10 cop2_get(9, ir1);
11 cop2_get(10, ir2);
12 cop2_get(11, ir3);
13 cester_assert_uint_eq(0x1000, ir1); // 1.0^2 = 1.0
14 cester_assert_uint_eq(0x0400, ir2); // 0.5^2 = 0.25
15 cester_assert_uint_eq(0x4000, ir3); // 2.0^2 = 4.0 (no saturation, lm=0)
16)
17
18CESTER_TEST(sqr_unshifted, gte_tests,
19 cop2_put(9, 4);
20 cop2_put(10, 5);
21 cop2_put(11, 6);
31)
32
33// SQR sets MAC1-3 as well
34CESTER_TEST(sqr_mac_output, gte_tests,
35 cop2_put(9, 100);
36 cop2_put(10, 200);
37 cop2_put(11, 300);
39 cop2_cmd(COP2_SQR(0, 0));
40 int32_t mac1, mac2, mac3;
41 cop2_get(25, mac1);
42 cop2_get(26, mac2);
43 cop2_get(27, mac3);
47)
48
49// SQR with IR saturation (shifted, result > 0x7fff with lm=0)
50CESTER_TEST(sqr_saturation_shifted, gte_tests,
51 cop2_put(9, 0x4000); // 4.0 in 4.12; 4^2 = 16, >>12 = 0x4000 (fits)
52 cop2_put(10, 0x5a82); // ~5.656 (sqrt(32)); 32 >>12 = 0x8000 = saturates
53 cop2_put(11, 0x7fff); // max positive; 0x7fff^2 >>12 = huge, saturates
58 cop2_get(9, ir1);
59 cop2_get(10, ir2);
60 cop2_get(11, ir3);
61 flag = gte_read_flag();
62 ramsyscall_printf("SQR sat: IR1=0x%04x IR2=0x%04x IR3=0x%04x FLAG=0x%08x\n",
63 ir1 & 0xffff, ir2 & 0xffff, ir3 & 0xffff, flag);
64 cester_assert_uint_eq(0x7fff, ir1 & 0xffff);
65 cester_assert_uint_eq(0x7fff, ir2 & 0xffff);
66 cester_assert_uint_eq(0x7fff, ir3 & 0xffff);
68)
69
70// SQR with negative input (result should still be positive: square)
71CESTER_TEST(sqr_negative_input, gte_tests,
72 cop2_put(9, 0xfffffff6); // -10 (sign-extended)
73 cop2_put(10, 0xffffffce); // -50
74 cop2_put(11, 0xffffff9c); // -100
76 cop2_cmd(COP2_SQR(0, 0));
77 int32_t mac1, mac2, mac3;
78 cop2_get(25, mac1);
79 cop2_get(26, mac2);
80 cop2_get(27, mac3);
81 // Squares of negative numbers are positive
82 // But GTE multiplies IR*IR where IR is 16-bit signed
83 // -10 * -10 = 100, -50 * -50 = 2500, -100 * -100 = 10000
84 ramsyscall_printf("SQR neg: MAC1=%d MAC2=%d MAC3=%d\n", mac1, mac2, mac3);
88)
#define cop2_cmd(op)
Definition cop2.h:175
#define cop2_put(reg, val)
Definition cop2.h:182
#define COP2_SQR(sf, lm)
Definition cop2.h:161
#define cop2_get(reg, dest)
Definition cop2.h:189
cester_assert_int_eq(0, hi)
int32_t mac1
Definition gte-depthcue.c:116
int32_t mac2
Definition gte-depthcue.c:116
int32_t mac3
Definition gte-depthcue.c:116
cester_assert_uint_eq(16, ir1)
uint32_t ir1
Definition gte-sqr.c:24
uint32_t ir2
Definition gte-sqr.c:24
gte_tests
Definition gte-sqr.c:18
uint32_t flag
Definition gte-sqr.c:57
ramsyscall_printf("SQR sat: IR1=0x%04x IR2=0x%04x IR3=0x%04x FLAG=0x%08x\n", ir1 &0xffff, ir2 &0xffff, ir3 &0xffff, flag)
gte_clear_flag()
CESTER_TEST(sqr_shifted, gte_tests, cop2_put(9, 0x1000);cop2_put(10, 0x0800);cop2_put(11, 0x2000);gte_clear_flag();cop2_cmd(COP2_SQR(1, 0));uint32_t ir1, ir2, ir3;cop2_get(9, ir1);cop2_get(10, ir2);cop2_get(11, ir3);cester_assert_uint_eq(0x1000, ir1);cester_assert_uint_eq(0x0400, ir2);cester_assert_uint_eq(0x4000, ir3);) CESTER_TEST(sqr_unshifted
uint32_t ir3
Definition gte-sqr.c:24
void uint32_t(classId, spec)