1 #if defined(__mips_hard_float)
8 #if !defined(PR_SET_FP_MODE)
9 # define PR_SET_FP_MODE 45
12 #if !defined(PR_GET_FP_MODE)
13 # define PR_GET_FP_MODE 46
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;
32 : "t0", "$f0", "$f1", "memory");
34 return (result
!= 0x3FF0000000000000ull
);
37 static void fatal_error(const char* msg
) {
38 fprintf(stderr
, "Error: %s\n", msg
);
42 static void test(int* fr_prctl
, int* fr_detected
) {
43 *fr_prctl
= prctl(PR_GET_FP_MODE
);
44 *fr_detected
= get_fp_mode();
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");
56 if (*fr_prctl
!= *fr_detected
) {
57 fatal_error("fr_prctl != fr_detected");
63 int fr_prctl
, fr_detected
;
65 test(&fr_prctl
, &fr_detected
);
70 #if (__mips_isa_rev >= 6)
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... ");
83 l
= 0xAAAAAAAABBBBBBBB;
86 "ldc1 $f0, 0(%1) \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... ");
98 l
= 0x12345678AAAAAAAA;
101 "ldc1 $f0, 0(%1) \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... ");
112 l
= 0x12345678AAAAAAAA;
115 "ldc1 $f0, 0(%1) \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
);
125 /* Change mode to FP32 */
126 if (prctl(PR_SET_FP_MODE
, 0) != 0) {
127 fatal_error("prctl(PR_SET_FP_MODE, 0) fails.");
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
);