none/tests/fdleak_cmsg_supp.supp: Add suppressions for older glibc
[valgrind.git] / none / tests / mips32 / change_fp_mode.c
blobb40b6e28c175404fc61a9e359735abdedba2a754
1 #if defined(__mips_hard_float)
3 #include <elf.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <sys/prctl.h>
8 #if !defined(PR_SET_FP_MODE)
9 # define PR_SET_FP_MODE 45
10 #endif
12 #if !defined(PR_GET_FP_MODE)
13 # define PR_GET_FP_MODE 46
14 #endif
16 /* Determine FP mode based on sdc1 behavior
17 returns 1 if FR = 1 mode is detected. */
19 static int get_fp_mode(void) {
20 unsigned long long result = 0;
21 __asm__ volatile(
22 ".set push\n\t"
23 ".set noreorder\n\t"
24 ".set oddspreg\n\t"
25 "lui $t0, 0x3FF0\n\t"
26 "ldc1 $f0, %0\n\t"
27 "mtc1 $t0, $f1\n\t"
28 "sdc1 $f0, %0\n\t"
29 ".set pop\n\t"
30 : "+m"(result)
32 : "t0", "$f0", "$f1", "memory");
34 return (result != 0x3FF0000000000000ull);
37 static void fatal_error(const char* msg) {
38 fprintf(stderr, "Error: %s\n", msg);
39 exit(1);
42 static void test(int* fr_prctl, int* fr_detected) {
43 *fr_prctl = prctl(PR_GET_FP_MODE);
44 *fr_detected = get_fp_mode();
46 if (*fr_prctl < 0) {
47 fatal_error("prctl(PR_GET_FP_MODE) fails.");
50 printf("fr_prctl: %d, fr_detected: %d\n", *fr_prctl, *fr_detected);
51 #if (__mips_isa_rev >= 6)
52 if ((*fr_prctl != *fr_detected) && ((*fr_prctl != 3) || (*fr_detected != 0))) {
53 fatal_error("fr_prctl != fr_detected");
55 #else
56 if (*fr_prctl != *fr_detected) {
57 fatal_error("fr_prctl != fr_detected");
59 #endif
62 int main() {
63 int fr_prctl, fr_detected;
65 test(&fr_prctl, &fr_detected);
67 /* FP64 */
68 if (fr_prctl == 1) {
70 #if (__mips_isa_rev >= 6)
72 unsigned int w;
73 unsigned long long l;
75 /* Change mode to FRE */
76 if (prctl(PR_SET_FP_MODE, 3) != 0) {
77 fatal_error("prctl(PR_SET_FP_MODE, 3) fails.");
80 printf("Write to odd, read from even... ");
82 w = 0x12345678;
83 l = 0xAAAAAAAABBBBBBBB;
85 __asm__ volatile (
86 "ldc1 $f0, 0(%1) \n\t"
87 "mtc1 %0, $f1 \n\t"
88 "sdc1 $f0, 0(%1) \n\t"
89 : : "r" (w), "r" (&l) : "memory", "$f0", "$f1"
92 if (l == 0x12345678BBBBBBBBull) printf("OK\n");
93 else printf ("Error: l = %llX\n", l);
95 printf("Write to even, read from odd... ");
97 w = 0xAAAAAAAA;
98 l = 0x12345678AAAAAAAA;
100 __asm__ volatile (
101 "ldc1 $f0, 0(%1) \n\t"
102 "mfc1 %0, $f1 \n\t"
103 : "+r" (w) : "r" (&l) : "$f0", "$f1"
106 if (w == 0x12345678ul) printf("OK\n");
107 else printf ("Error: w = %X\n", w);
109 printf("Write to low part, check high part... ");
111 w = 0xBBBBBBBB;
112 l = 0x12345678AAAAAAAA;
114 __asm__ volatile (
115 "ldc1 $f0, 0(%1) \n\t"
116 "mtc1 %0, $f0 \n\t"
117 "sdc1 $f0, 0(%1) \n\t"
118 : : "r" (w), "r" (&l) : "memory", "$f0"
121 if (l == 0x12345678BBBBBBBBull) printf("OK\n");
122 else printf ("Error: l = %llX\n", l);
124 #else
125 /* Change mode to FP32 */
126 if (prctl(PR_SET_FP_MODE, 0) != 0) {
127 fatal_error("prctl(PR_SET_FP_MODE, 0) fails.");
129 #endif
130 test(&fr_prctl, &fr_detected);
132 /* Change back FP mode */
133 if (prctl(PR_SET_FP_MODE, 1) != 0) {
134 fatal_error("prctl(PR_SET_FP_MODE, 1) fails.");
137 test(&fr_prctl, &fr_detected);
140 return 0;
142 #else
143 int main() {
144 return 0;
146 #endif