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
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.
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.
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/>. */
20 #ifndef _FLOAT_BITWISE_
21 #define _FLOAT_BITWISE_ 1
23 #include <math_private.h>
25 /* Returns (int)(num & 0x7FFFFFF0 == value) */
27 int __float_and_test28 (float num, float value)
31 vector int mask = (vector int) {
32 0x7ffffffe, 0x00000000, 0x00000000, 0x0000000
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)
41 GET_FLOAT_WORD(inum, num);
42 inum = (inum & 0x7ffffff0);
43 SET_FLOAT_WORD(ret, inum);
45 return (ret == value);
48 /* Returns (int)(num & 0x7FFFFF00 == value) */
50 int __float_and_test24 (float num, float value)
54 vector int mask = (vector int) {
55 0x7fffffe0, 0x00000000, 0x00000000, 0x0000000
58 "xxland %x0,%x1,%x2" : "=f" (ret) : "f" (num), "f" (mask)
62 GET_FLOAT_WORD(inum, num);
63 inum = (inum & 0x7fffff00);
64 SET_FLOAT_WORD(ret, inum);
66 return (ret == value);
69 /* Returns (float)(num & 0x7F800000) */
71 float __float_and8 (float num)
75 vector int mask = (vector int) {
76 0x7ff00000, 0x00000000, 0x00000000, 0x00000000
79 "xxland %x0,%x1,%x2" : "=f" (ret) : "f" (num), "f" (mask)
83 GET_FLOAT_WORD(inum, num);
84 inum = (inum & 0x7f800000);
85 SET_FLOAT_WORD(ret, inum);
90 /* Returns ((int32_t)(num & 0x7F800000) >> 23) */
92 int32_t __float_get_exp (float num)
97 vector int mask = (vector int) {
98 0x7ff00000, 0x00000000, 0x00000000, 0x00000000
101 "xxland %x0,%x1,%x2" : "=f" (ret) : "f" (num), "f" (mask)
103 GET_FLOAT_WORD(inum, ret);
105 GET_FLOAT_WORD(inum, num);
106 inum = inum & 0x7f800000;
111 #endif /* s_float_bitwise.h */