Xenomai  3.0.8
fptest.h
1 /*
2  * Copyright (C) 2006 Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>.
3  *
4  * This 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 of the License, or (at your option) any later version.
8  *
9  * This 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.
13 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18 #ifndef _COBALT_POWERPC_ASM_UAPI_FPTEST_H
19 #define _COBALT_POWERPC_ASM_UAPI_FPTEST_H
20 
21 #ifndef __NO_FPRS__ /* i.e. has FPU, not SPE */
22 
23 static inline void fp_regs_set(int features, unsigned int val)
24 {
25  unsigned long long fpval = val;
26 
27  __asm__ __volatile__("lfd 0, %0\n"
28  " fmr 1, 0\n"
29  " fmr 2, 0\n"
30  " fmr 3, 0\n"
31  " fmr 4, 0\n"
32  " fmr 5, 0\n"
33  " fmr 6, 0\n"
34  " fmr 7, 0\n"
35  " fmr 8, 0\n"
36  " fmr 9, 0\n"
37  " fmr 10, 0\n"
38  " fmr 11, 0\n"
39  " fmr 12, 0\n"
40  " fmr 13, 0\n"
41  " fmr 14, 0\n"
42  " fmr 15, 0\n"
43  " fmr 16, 0\n"
44  " fmr 17, 0\n"
45  " fmr 18, 0\n"
46  " fmr 19, 0\n"
47  " fmr 20, 0\n"
48  " fmr 21, 0\n"
49  " fmr 22, 0\n"
50  " fmr 23, 0\n"
51  " fmr 24, 0\n"
52  " fmr 25, 0\n"
53  " fmr 26, 0\n"
54  " fmr 27, 0\n"
55  " fmr 28, 0\n"
56  " fmr 29, 0\n"
57  " fmr 30, 0\n"
58  " fmr 31, 0\n"::"m"(fpval));
59 }
60 
61 #define FPTEST_REGVAL(n) { \
62  unsigned long long t; \
63  __asm__ __volatile__(" stfd " #n ", %0" : "=m" (t)); \
64  e[n] = (unsigned)t; \
65  }
66 
67 static inline unsigned int fp_regs_check(int features, unsigned int val,
68  int (*report)(const char *fmt, ...))
69 {
70  unsigned int i, result = val;
71  unsigned int e[32];
72 
73  FPTEST_REGVAL(0);
74  FPTEST_REGVAL(1);
75  FPTEST_REGVAL(2);
76  FPTEST_REGVAL(3);
77  FPTEST_REGVAL(4);
78  FPTEST_REGVAL(5);
79  FPTEST_REGVAL(6);
80  FPTEST_REGVAL(7);
81  FPTEST_REGVAL(8);
82  FPTEST_REGVAL(9);
83  FPTEST_REGVAL(10);
84  FPTEST_REGVAL(11);
85  FPTEST_REGVAL(12);
86  FPTEST_REGVAL(13);
87  FPTEST_REGVAL(14);
88  FPTEST_REGVAL(15);
89  FPTEST_REGVAL(16);
90  FPTEST_REGVAL(17);
91  FPTEST_REGVAL(18);
92  FPTEST_REGVAL(19);
93  FPTEST_REGVAL(20);
94  FPTEST_REGVAL(21);
95  FPTEST_REGVAL(22);
96  FPTEST_REGVAL(23);
97  FPTEST_REGVAL(24);
98  FPTEST_REGVAL(25);
99  FPTEST_REGVAL(26);
100  FPTEST_REGVAL(27);
101  FPTEST_REGVAL(28);
102  FPTEST_REGVAL(29);
103  FPTEST_REGVAL(30);
104  FPTEST_REGVAL(31);
105 
106  for (i = 0; i < 32; i++)
107  if (e[i] != val) {
108  report("r%d: %u != %u\n", i, e[i], val);
109  result = e[i];
110  }
111 
112  return result;
113 }
114 
115 #else /* __NO_FPRS__ */
116 
117 static inline void fp_regs_set(int features, unsigned int val) { }
118 
119 static inline unsigned int fp_regs_check(int features, unsigned int val,
120  int (*report)(const char *fmt, ...))
121 {
122  return val;
123 }
124 
125 #endif /* __NO_FPRS__ */
126 
127 #endif /* !_COBALT_POWERPC_ASM_UAPI_FPTEST_H */