sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
main.c
1#include <stdio.h>
2#include <string.h>
3#include <math.h>
4#include <kernel.h>
5
6extern int kputs(char *s);
7
8typedef unsigned int u32;
9
10static volatile u32 in[16] = {
11 0x3f800000, /* 1.0 */
12 0x33c00000, /* 1.5 * 2^-24 */
13 0x3f8ccccd, /* 1.1 */
14 0x40400000, /* 3.0 */
15 0x00000000, /* 0.0 */
16 0x7f7fffff, /* FLT_MAX */
17 0x00800000, /* FLT_MIN */
18 0x00000001, /* smallest denormal */
19 0x40000000, /* 2.0 */
20 0xc0800000, /* -4.0 */
21 0x40200000, /* 2.5 */
22 0xc0200000, /* -2.5 */
23 0x4f32d05e, /* 3e9 */
24 0x7fc00000, /* quiet NaN bits */
25 0x7f800000, /* +Inf bits */
26 0x80000000, /* -0.0 */
27};
28
29static float f(int i)
30{
31 u32 b = in[i];
32 float v;
33
34 memcpy(&v, &b, sizeof(v));
35 return v;
36}
37
38static u32 bits(float v)
39{
40 u32 b;
41
42 memcpy(&b, &v, sizeof(b));
43 return b;
44}
45
46static char line[96];
47
48static void show(const char *name, u32 run, u32 folded)
49{
50 snprintf(line, sizeof(line), "fpu %-14s %08x %08x%s\n", name, run, folded, run == folded ? "" : " differ");
51 kputs(line);
52 printf("%s", line);
53}
54
55__attribute__((noinline)) static float fma_like(float a, float b, float c)
56{
57 return a * b + c;
58}
59
60int main(void)
61{
62 show("add_round", bits(f(0) + f(1)), bits(1.0f + 0x1.8p-24f));
63 show("mul_round", bits(f(2) * f(2)), bits(1.1f * 1.1f));
64 show("div_third", bits(f(0) / f(3)), bits(1.0f / 3.0f));
65 show("div_zero", bits(f(0) / f(4)), bits(1.0f / 0.0f));
66 show("zero_zero", bits(f(4) / f(4)), bits(0.0f / 0.0f));
67 show("overflow", bits(f(5) * f(8)), bits(0x1.fffffep127f * 2.0f));
68 show("underflow", bits(f(6) * 0.5f * f(0)), bits(0x1p-126f * 0.5f));
69 show("denorm_in", bits(f(7) + f(4)), bits(0x1p-149f + 0.0f));
70 show("sqrt2", bits(sqrtf(f(8))), bits(sqrtf(2.0f)));
71 show("sqrt_neg", bits(sqrtf(f(9))), bits(sqrtf(-4.0f)));
72 show("rsqrt3", bits(f(0) / sqrtf(f(3))), bits(1.0f / sqrtf(3.0f)));
73 show("cvt_2.5", (u32)(int)f(10), (u32)(int)2.5f);
74 show("cvt_-2.5", (u32)(int)f(11), (u32)(int)-2.5f);
75 show("cvt_3e9", (u32)(int)f(12), 0);
76 show("i2f_2^24+1", bits((float)(int)(in[0] >> 6 | 1)), bits((float)16646145));
77 show("fma_like", bits(fma_like(f(2), f(2), -f(0))), bits(1.1f * 1.1f - 1.0f));
78 show("nan_eq", f(13) == f(13), 1);
79 show("inf_plus_1", bits(f(14) + f(0)), 0);
80 show("neg_zero_abs", bits(fabsf(f(15))), bits(fabsf(-0.0f)));
81 show("neg_zero_add", bits(f(15) + f(4)), bits(-0.0f + 0.0f));
82 show("fmax", bits(fmaxf(f(9), f(8))), bits(fmaxf(-4.0f, 2.0f)));
83 show("fmin_nan", bits(fminf(f(13), f(8))), bits(fminf(__builtin_nanf(""), 2.0f)));
84 kputs("fpu-check: done\n");
85 printf("[ps2rig] exit=0\n");
86 SleepThread();
87 return 0;
88}