2011-09-08 04:10:26 +02:00
|
|
|
/* Bitwise manipulation over float. Function prototypes.
|
2016-01-04 17:05:18 +01:00
|
|
|
Copyright (C) 2011-2016 Free Software Foundation, Inc.
|
2011-09-08 04:10:26 +02:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
Contributed by Adhemerval Zanella <azanella@br.ibm.com>, 2011
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-10 00:18:22 +01:00
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
2011-09-08 04:10:26 +02:00
|
|
|
|
|
|
|
#ifndef _FLOAT_BITWISE_
|
|
|
|
#define _FLOAT_BITWISE_ 1
|
|
|
|
|
2012-03-09 20:29:16 +01:00
|
|
|
#include <math_private.h>
|
2011-09-08 04:10:26 +02:00
|
|
|
|
|
|
|
/* Returns (int)(num & 0x7FFFFFF0 == value) */
|
2013-08-17 10:59:43 +02:00
|
|
|
static inline int
|
|
|
|
__float_and_test28 (float num, float value)
|
2011-09-08 04:10:26 +02:00
|
|
|
{
|
|
|
|
float ret;
|
|
|
|
#ifdef _ARCH_PWR7
|
2013-08-17 10:59:43 +02:00
|
|
|
union {
|
|
|
|
int i;
|
|
|
|
float f;
|
|
|
|
} mask = { .i = 0x7ffffff0 };
|
2011-09-08 04:10:26 +02:00
|
|
|
__asm__ (
|
2013-08-17 10:59:43 +02:00
|
|
|
/* the 'f' constraint is used on mask because we just need
|
2011-09-08 04:10:26 +02:00
|
|
|
* to compare floats, not full vector */
|
2013-08-17 10:59:43 +02:00
|
|
|
"xxland %x0,%x1,%x2" : "=f" (ret) : "f" (num), "f" (mask.f)
|
2011-09-08 04:10:26 +02:00
|
|
|
);
|
|
|
|
#else
|
|
|
|
int32_t inum;
|
|
|
|
GET_FLOAT_WORD(inum, num);
|
|
|
|
inum = (inum & 0x7ffffff0);
|
|
|
|
SET_FLOAT_WORD(ret, inum);
|
|
|
|
#endif
|
|
|
|
return (ret == value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns (int)(num & 0x7FFFFF00 == value) */
|
2013-08-17 10:59:43 +02:00
|
|
|
static inline int
|
|
|
|
__float_and_test24 (float num, float value)
|
2011-09-08 04:10:26 +02:00
|
|
|
{
|
|
|
|
float ret;
|
|
|
|
#ifdef _ARCH_PWR7
|
2013-08-17 10:59:43 +02:00
|
|
|
union {
|
|
|
|
int i;
|
|
|
|
float f;
|
|
|
|
} mask = { .i = 0x7fffff00 };
|
2011-09-08 04:10:26 +02:00
|
|
|
__asm__ (
|
2013-08-17 10:59:43 +02:00
|
|
|
"xxland %x0,%x1,%x2" : "=f" (ret) : "f" (num), "f" (mask.f)
|
2011-09-08 04:10:26 +02:00
|
|
|
);
|
|
|
|
#else
|
|
|
|
int32_t inum;
|
|
|
|
GET_FLOAT_WORD(inum, num);
|
|
|
|
inum = (inum & 0x7fffff00);
|
|
|
|
SET_FLOAT_WORD(ret, inum);
|
|
|
|
#endif
|
|
|
|
return (ret == value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns (float)(num & 0x7F800000) */
|
2013-08-17 10:59:43 +02:00
|
|
|
static inline float
|
|
|
|
__float_and8 (float num)
|
2011-09-08 04:10:26 +02:00
|
|
|
{
|
|
|
|
float ret;
|
|
|
|
#ifdef _ARCH_PWR7
|
2013-08-17 10:59:43 +02:00
|
|
|
union {
|
|
|
|
int i;
|
|
|
|
float f;
|
|
|
|
} mask = { .i = 0x7f800000 };
|
2011-09-08 04:10:26 +02:00
|
|
|
__asm__ (
|
2013-08-17 10:59:43 +02:00
|
|
|
"xxland %x0,%x1,%x2" : "=f" (ret) : "f" (num), "f" (mask.f)
|
2011-09-08 04:10:26 +02:00
|
|
|
);
|
|
|
|
#else
|
|
|
|
int32_t inum;
|
|
|
|
GET_FLOAT_WORD(inum, num);
|
|
|
|
inum = (inum & 0x7f800000);
|
|
|
|
SET_FLOAT_WORD(ret, inum);
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns ((int32_t)(num & 0x7F800000) >> 23) */
|
2013-08-17 10:59:43 +02:00
|
|
|
static inline int32_t
|
|
|
|
__float_get_exp (float num)
|
2011-09-08 04:10:26 +02:00
|
|
|
{
|
|
|
|
int32_t inum;
|
|
|
|
#ifdef _ARCH_PWR7
|
|
|
|
float ret;
|
2013-08-17 10:59:43 +02:00
|
|
|
union {
|
|
|
|
int i;
|
|
|
|
float f;
|
|
|
|
} mask = { .i = 0x7f800000 };
|
2011-09-08 04:10:26 +02:00
|
|
|
__asm__ (
|
2013-08-17 10:59:43 +02:00
|
|
|
"xxland %x0,%x1,%x2" : "=f" (ret) : "f" (num), "f" (mask.f)
|
2011-09-08 04:10:26 +02:00
|
|
|
);
|
|
|
|
GET_FLOAT_WORD(inum, ret);
|
|
|
|
#else
|
|
|
|
GET_FLOAT_WORD(inum, num);
|
|
|
|
inum = inum & 0x7f800000;
|
|
|
|
#endif
|
|
|
|
return inum >> 23;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* s_float_bitwise.h */
|