* New R5900 COP2 test case.
[deliverable/binutils-gdb.git] / sim / testsuite / sky / t-cop2b.c
1 /* Copyright (C) 1998 Cygnus Solutions */
2 /* COP2 function test, with non-expert inline assembly */
3
4
5
6 /* globals */
7
8 int num_ok = 0;
9 int num_errors = 0;
10 float data_array[128] __attribute__((aligned(16)));
11
12
13
14 /* macros */
15
16 #define TEST(x) do_test(x, #x, __LINE__)
17
18
19
20 /* prototypes */
21
22
23 void enable_cop2();
24 void test00();
25 void do_test(int ok, const char* test, int line);
26
27
28
29 /* Utility functions */
30
31 void
32 enable_cop2()
33 {
34 asm volatile (".set noat");
35 asm volatile ("mfc0 $1,$12; dli $2,0x40000000; or $1,$2,$2; mtc0 $1,$12"
36 : /* no outputs */
37 : /* no inputs */
38 : "$1", "$2" /* clobbered */);
39 asm volatile (".set at");
40 }
41
42
43 void
44 do_test(int ok, const char* test, int line)
45 {
46 static int test_num = 0;
47
48 printf("[%d @ %d] (%s): ", ++test_num, line, test);
49 if(ok)
50 {
51 num_ok ++;
52 printf("ok\n");
53 }
54 else
55 {
56 num_errors ++;
57 printf("ko\n");
58 }
59 }
60
61
62
63 /* Tests */
64
65
66 /* test00: test LQC2/SQC2 data non-corruption */
67 void test00()
68 {
69 volatile float* data = & data_array[0];
70 volatile float* data2 = & data_array[4];
71
72 /* stuff some initial values */
73 data[0] = -10.0;
74 data[1] = +10.0;
75 data[2] = -20.0;
76 data[3] = +20.0;
77
78 /* save values */
79 asm volatile ("lqc2 vf01,%0"
80 : /* no output */
81 : "m" (data[0]) /* input */
82 : "memory" /* clobbered */);
83
84 /* test no clobbering */
85 TEST(data[0] == -10.0f);
86 TEST(data[1] == +10.0f);
87 TEST(data[2] == -20.0f);
88 TEST(data[3] == +20.0f);
89
90 /* overwrite with VU constants */
91 asm volatile ("sqc2 vf00,%0"
92 : /* no outputs */
93 : "m" (data[0]) /* input */
94 : "memory" /* clobbered */);
95
96 /* test proper values */
97 TEST(data[0] == 0.0f);
98 TEST(data[1] == 0.5f);
99 TEST(data[2] == -1.0f);
100 TEST(data[3] == +1.0f);
101
102 /* read back original array values */
103 asm volatile ("sqc2 vf01,%0"
104 : /* no outputs */
105 : "m" (data2[0]) /* input */
106 : "memory" /* clobbered */);
107
108 /* printf("%f,%f,%f,%f\n", data2[0], data2[1], data2[2], data2[3]); */
109
110 /* test proper values */
111 TEST(data2[0] == -10.0f);
112 TEST(data2[1] == +10.0f);
113 TEST(data2[2] == -20.0f);
114 TEST(data2[3] == +20.0f);
115 }
116
117
118
119 /* Mainline */
120
121
122 int main()
123 {
124 enable_cop2();
125
126 /* tests */
127 test00();
128
129
130 /* summarize */
131 printf("%d ok, %d bad\n", num_ok, num_errors);
132 if(num_errors > 0)
133 exit(47);
134 else
135 exit(0);
136 }
This page took 0.035047 seconds and 4 git commands to generate.