Update copyright notices with scripts/update-copyrights.
[jlayton/glibc.git] / sysdeps / powerpc / fpu / s_float_bitwise.h
1 /* Bitwise manipulation over float. Function prototypes.
2    Copyright (C) 2011-2013 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4    Contributed by Adhemerval Zanella <azanella@br.ibm.com>, 2011
5
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    The GNU C Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, see
18    <http://www.gnu.org/licenses/>.  */
19
20 #ifndef _FLOAT_BITWISE_
21 #define _FLOAT_BITWISE_ 1
22
23 #include <math_private.h>
24
25 /* Returns (int)(num & 0x7FFFFFF0 == value) */
26 static inline
27 int __float_and_test28 (float num, float value)
28 {
29   float ret;
30 #ifdef _ARCH_PWR7
31   vector int mask = (vector int) {
32     0x7ffffffe, 0x00000000, 0x00000000, 0x0000000
33   };
34   __asm__ (
35   /* the 'f' constrain is use on mask because we just need
36    * to compare floats, not full vector */
37     "xxland %x0,%x1,%x2" : "=f" (ret) : "f" (num), "f" (mask)
38   );
39 #else
40   int32_t inum;
41   GET_FLOAT_WORD(inum, num);
42   inum = (inum & 0x7ffffff0);
43   SET_FLOAT_WORD(ret, inum);
44 #endif
45   return (ret == value);
46 }
47
48 /* Returns (int)(num & 0x7FFFFF00 == value) */
49 static inline
50 int __float_and_test24 (float num, float value)
51 {
52   float ret;
53 #ifdef _ARCH_PWR7
54   vector int mask = (vector int) {
55     0x7fffffe0, 0x00000000, 0x00000000, 0x0000000
56   };
57   __asm__ (
58     "xxland %x0,%x1,%x2" : "=f" (ret) : "f" (num), "f" (mask)
59   );
60 #else
61   int32_t inum;
62   GET_FLOAT_WORD(inum, num);
63   inum = (inum & 0x7fffff00);
64   SET_FLOAT_WORD(ret, inum);
65 #endif
66   return (ret == value);
67 }
68
69 /* Returns (float)(num & 0x7F800000) */
70 static inline
71 float __float_and8 (float num)
72 {
73   float ret;
74 #ifdef _ARCH_PWR7
75   vector int mask = (vector int) {
76     0x7ff00000, 0x00000000, 0x00000000, 0x00000000
77   };
78   __asm__ (
79     "xxland %x0,%x1,%x2" : "=f" (ret) : "f" (num), "f" (mask)
80   );
81 #else
82   int32_t inum;
83   GET_FLOAT_WORD(inum, num);
84   inum = (inum & 0x7f800000);
85   SET_FLOAT_WORD(ret, inum);
86 #endif
87   return ret;
88 }
89
90 /* Returns ((int32_t)(num & 0x7F800000) >> 23) */
91 static inline
92 int32_t __float_get_exp (float num)
93 {
94   int32_t inum;
95 #ifdef _ARCH_PWR7
96   float ret;
97   vector int mask = (vector int) {
98     0x7ff00000, 0x00000000, 0x00000000, 0x00000000
99   };
100   __asm__ (
101     "xxland %x0,%x1,%x2" : "=f" (ret) : "f" (num), "f" (mask)
102   );
103   GET_FLOAT_WORD(inum, ret);
104 #else
105   GET_FLOAT_WORD(inum, num);
106   inum = inum & 0x7f800000;
107 #endif
108   return inum >> 23;
109 }
110
111 #endif /* s_float_bitwise.h */