2018-02-09 Sebastian Perta <sebastian.perta@renesas.com>
[official-gcc.git] / gcc / testsuite / gcc.target / sh / pr6526.c
blob7443b4d1e34973078a75c8c74849e3f8e89d00af
1 /* Check that the XF registers are not clobbered by an integer division
2 that is done using double precision FPU division. */
4 /* { dg-do run { target { default_single_fpu && has_xf_regs } } } */
5 /* { dg-options "-O1 -mdiv=call-fp" } */
7 #include <assert.h>
8 #include <stdlib.h>
10 extern void __set_fpscr (int);
12 void
13 write_xf0 (float* f)
15 __asm__ __volatile__ ("frchg; fmov.s @%0,fr0; frchg" : : "r" (f) : "memory");
18 void
19 read_xf0 (float* f)
21 __asm__ __volatile__ ("frchg; fmov.s fr0,@%0; frchg" : : "r" (f) : "memory");
24 int __attribute__ ((noinline))
25 test_00 (int a, int b)
27 return a / b;
30 unsigned int __attribute__ ((noinline))
31 test_01 (unsigned a, unsigned b)
33 return a / b;
36 int __attribute__ ((noinline))
37 test_02 (int x)
39 return x & 0;
42 int
43 main (void)
45 float test_value;
46 int r = 0;
48 /* Set FPSCR.FR to 1. */
49 __set_fpscr (0x200000);
51 test_value = 123;
52 write_xf0 (&test_value);
53 r += test_00 (40, 4);
54 read_xf0 (&test_value);
55 assert (test_value == 123);
57 test_value = 321;
58 write_xf0 (&test_value);
59 r += test_01 (50, 5);
60 read_xf0 (&test_value);
61 assert (test_value == 321);
63 return test_02 (r);