Update copyright dates with scripts/update-copyrights.
[glibc.git] / sysdeps / mips / tst-mode-switch-3.c
blob9bc08f7327c06d4d5badf8d2c11c72f6a25a4014
1 /* Copyright (C) 2014-2015 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
18 #include <errno.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <unistd.h>
23 #include <setjmp.h>
24 #include <sys/prctl.h>
26 #if __mips_fpr != 0 || _MIPS_SPFPSET != 16
27 # error This test requires -mfpxx -mno-odd-spreg
28 #endif
30 /* This test verifies that mode changes between a setjmp and longjmp do
31 not corrupt the state of callee-saved registers. */
33 static int mode[6] =
36 PR_FP_MODE_FR,
37 PR_FP_MODE_FR | PR_FP_MODE_FRE,
38 PR_FP_MODE_FR,
40 PR_FP_MODE_FR | PR_FP_MODE_FRE
42 static jmp_buf env;
43 float check1 = 2.0;
44 double check2 = 3.0;
46 int
47 main (void)
49 int i;
50 int result = 0;
52 for (i = 0 ; i < 7 ; i++)
54 int retval;
55 register float test1 __asm ("$f20");
56 register double test2 __asm ("$f22");
58 /* Hide what we are doing to $f20 and $f22 from the compiler. */
59 __asm __volatile ("l.s %0,%2\n"
60 "l.d %1,%3\n"
61 : "=f" (test1), "=f" (test2)
62 : "m" (check1), "m" (check2));
64 retval = setjmp (env);
66 /* Make sure the compiler knows we want to access the variables
67 via the named registers again. */
68 __asm __volatile ("" : : "f" (test1), "f" (test2));
70 if (test1 != check1 || test2 != check2)
72 printf ("Corrupt register detected: $20 %f = %f, $22 %f = %f\n",
73 test1, check1, test2, check2);
74 result = 1;
77 if (retval == 0)
79 if (prctl (PR_SET_FP_MODE, mode[i % 6]) != 0
80 && errno != ENOTSUP)
82 printf ("prctl PR_SET_FP_MODE failed: %m");
83 exit (1);
85 longjmp (env, 0);
89 return result;