Sat Aug 24 00:51:48 2013 UTC ()
Add IEEE 754 versions of
fixdfdi.c fixsfdi.c fixunsdfdi.c fixunssfdi.c
floatdidf.c floatdisf.c floatundidf.c floatundisf.c
These don't FP so are well suited to softfloat implementation.
(matt)
diff -r1.16 -r1.17 src/lib/libc/quad/Makefile.inc
diff -r0 -r1.1 src/lib/libc/quad/fixdfdi_ieee754.c
diff -r0 -r1.1 src/lib/libc/quad/fixsfdi_ieee754.c
diff -r0 -r1.1 src/lib/libc/quad/fixunsdfdi_ieee754.c
diff -r0 -r1.1 src/lib/libc/quad/fixunssfdi_ieee754.c
diff -r0 -r1.1 src/lib/libc/quad/floatdidf_ieee754.c
diff -r0 -r1.1 src/lib/libc/quad/floatundidf_ieee754.c
diff -r1.1 -r1.2 src/lib/libc/quad/floatdisf_ieee754.c
diff -r1.1 -r1.2 src/lib/libc/quad/floatundisf_ieee754.c
--- src/lib/libc/quad/Makefile.inc 2013/04/30 01:43:01 1.16
+++ src/lib/libc/quad/Makefile.inc 2013/08/24 00:51:48 1.17
| @@ -1,31 +1,37 @@ | | | @@ -1,31 +1,37 @@ |
1 | # $NetBSD: Makefile.inc,v 1.16 2013/04/30 01:43:01 matt Exp $ | | 1 | # $NetBSD: Makefile.inc,v 1.17 2013/08/24 00:51:48 matt Exp $ |
2 | # @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 | | 2 | # @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 |
3 | | | 3 | |
4 | # Quad support | | 4 | # Quad support |
5 | SRCS.quad= cmpdi2.c ucmpdi2.c | | 5 | SRCS.quad= cmpdi2.c ucmpdi2.c |
6 | SRCS.quad+= divdi3.c moddi3.c | | 6 | SRCS.quad+= divdi3.c moddi3.c |
| | | 7 | .if empty(LIBC_MACHINE_ARCH:Mearm*) |
7 | SRCS.quad+= fixdfdi.c fixsfdi.c | | 8 | SRCS.quad+= fixdfdi.c fixsfdi.c |
8 | SRCS.quad+= fixunsdfdi.c fixunssfdi.c | | 9 | SRCS.quad+= fixunsdfdi.c fixunssfdi.c |
9 | SRCS.quad+= floatdidf.c floatdisf.c | | 10 | SRCS.quad+= floatdidf.c floatdisf.c |
10 | SRCS.quad+= floatundisf.c floatundidf.c | | 11 | SRCS.quad+= floatundidf.c floatundisf.c |
| | | 12 | .endif |
11 | SRCS.quad+= muldi3.c | | 13 | SRCS.quad+= muldi3.c |
12 | SRCS.quad+= negdi2.c | | 14 | SRCS.quad+= negdi2.c |
13 | SRCS.quad+= qdivrem.c | | 15 | SRCS.quad+= qdivrem.c |
14 | SRCS.quad+= udivdi3.c umoddi3.c | | 16 | SRCS.quad+= udivdi3.c umoddi3.c |
15 | | | 17 | |
16 | .if (${MACHINE_ARCH} == "m68k") | | 18 | .if (${MACHINE_ARCH} == "m68k") |
17 | SRCS.quad+= ashldi3.S ashrdi3.S lshrdi3.S | | 19 | SRCS.quad+= ashldi3.S ashrdi3.S lshrdi3.S |
18 | .elif (${MACHINE_ARCH} == "m68000") | | 20 | .elif (${MACHINE_ARCH} == "m68000") |
19 | SRCS.quad+= ashldi3.S lshrdi3.S | | 21 | SRCS.quad+= ashldi3.S lshrdi3.S |
20 | .elif (!empty{LIBC_MACHINE_ARCH:Mearm*}) | | 22 | .elif !empty(LIBC_MACHINE_ARCH:Mearm*) |
21 | SRCS.quad+= ashldi3.c ashrdi3.c lshrdi3.c lshldi3.c | | 23 | SRCS.quad+= ashldi3.c ashrdi3.c lshrdi3.c lshldi3.c |
| | | 24 | SRCS.quad+= floatdidf_ieee754.c floatdisf_ieee754.c |
| | | 25 | SRCS.quad+= floatundidf_ieee754.c floatundisf_ieee754.c |
| | | 26 | SRCS.quad+= fixdfdi_ieee754.c fixsfdi_ieee754.c |
| | | 27 | SRCS.quad+= fixunsdfdi_ieee754.c fixunssfdi_ieee754.c |
22 | .else | | 28 | .else |
23 | SRCS.quad+= ashldi3.c ashrdi3.c lshrdi3.c | | 29 | SRCS.quad+= ashldi3.c ashrdi3.c lshrdi3.c |
24 | .endif | | 30 | .endif |
25 | | | 31 | |
26 | # XXX as far as I can tell, these are never used and can be removed | | 32 | # XXX as far as I can tell, these are never used and can be removed |
27 | SRCS.quad+= adddi3.c anddi3.c iordi3.c notdi2.c subdi3.c xordi3.c | | 33 | SRCS.quad+= adddi3.c anddi3.c iordi3.c notdi2.c subdi3.c xordi3.c |
28 | | | 34 | |
29 | SRCS+= ${SRCS.quad} | | 35 | SRCS+= ${SRCS.quad} |
30 | | | 36 | |
31 | .PATH: ${ARCHDIR}/quad ${.CURDIR}/quad | | 37 | .PATH: ${ARCHDIR}/quad ${.CURDIR}/quad |
/* $NetBSD: fixdfdi_ieee754.c,v 1.1 2013/08/24 00:51:48 matt Exp $ */
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: fixdfdi_ieee754.c,v 1.1 2013/08/24 00:51:48 matt Exp $");
#endif /* LIBC_SCCS and not lint */
#if defined(SOFTFLOAT) || defined(__ARM_EABI__)
#include "softfloat/softfloat-for-gcc.h"
#endif
#include "quad.h"
#include <limits.h>
#include <stdbool.h>
#include <machine/ieee.h>
/*
* Convert double to signed quad.
* Not sure what to do with negative numbers---for now, anything out
* of range becomes UQUAD_MAX.
*/
quad_t
__fixdfdi(double x)
{
const union ieee_double_u ux = { .dblu_d = x };
signed int exp = ux.dblu_exp - DBL_EXP_BIAS;
const bool neg = ux.dblu_sign;
quad_t r;
if (exp >= 62)
return neg ? QUAD_MIN : QUAD_MAX;
r = 1 << DBL_FRACHBITS; /* implicit bit */
r |= ux.dblu_frach;
exp -= DBL_FRACHBITS;
if (exp < 0) {
r >>= -exp;
} else if (exp > 0) {
r <<= DBL_FRACLBITS;
r |= ux.dblu_fracl;
exp -= DBL_FRACLBITS;
if (exp < 0) {
r >>= -exp;
} else if (exp > 0) {
r <<= exp;
}
}
return neg ? -r : r;
}
/* $NetBSD: fixsfdi_ieee754.c,v 1.1 2013/08/24 00:51:48 matt Exp $ */
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: fixsfdi_ieee754.c,v 1.1 2013/08/24 00:51:48 matt Exp $");
#endif /* LIBC_SCCS and not lint */
#if defined(SOFTFLOAT) || defined(__ARM_EABI__)
#include "softfloat/softfloat-for-gcc.h"
#endif
#include "quad.h"
#include <limits.h>
#include <stdbool.h>
#include <machine/ieee.h>
/*
* Convert float to signed quad.
*/
quad_t
__fixsfdi(float x)
{
const union ieee_single_u ux = { .sngu_f = x };
signed int exp = ux.sngu_exp - SNG_EXP_BIAS;
const bool neg = ux.sngu_sign;
quad_t r;
if (exp < 0)
return 0;
if (exp > 62)
return neg ? QUAD_MIN : QUAD_MAX;
r = 1 << SNG_FRACBITS; /* implicit bit */
r |= ux.sngu_frac;
exp -= SNG_FRACBITS;
if (exp < 0) {
r >>= -exp;
} else if (exp > 0) {
r <<= exp;
}
return neg ? -r : r;
}
/* $NetBSD: fixunsdfdi_ieee754.c,v 1.1 2013/08/24 00:51:48 matt Exp $ */
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: fixunsdfdi_ieee754.c,v 1.1 2013/08/24 00:51:48 matt Exp $");
#endif /* LIBC_SCCS and not lint */
#if defined(SOFTFLOAT) || defined(__ARM_EABI__)
#include "softfloat/softfloat-for-gcc.h"
#endif
#include "quad.h"
#include <limits.h>
#include <machine/ieee.h>
/*
* Convert double to unsigned quad.
* Not sure what to do with negative numbers---for now, anything out
* of range becomes UQUAD_MAX.
*/
u_quad_t
__fixunsdfdi(double x)
{
const union ieee_double_u ux = { .dblu_d = x };
signed int exp = ux.dblu_exp - DBL_EXP_BIAS;
u_quad_t r;
if (ux.dblu_sign)
return UQUAD_MAX;
if (exp > 63)
return UQUAD_MAX;
if (exp < 0)
return 0;
r = 1 << DBL_FRACHBITS; /* implicit bit */
r |= ux.dblu_frach;
exp -= DBL_FRACHBITS;
if (exp == 0)
return r;
if (exp < 0)
return r >> -exp;
r <<= DBL_FRACLBITS;
r |= ux.dblu_fracl;
exp -= DBL_FRACLBITS;
if (exp == 0)
return r;
if (exp < 0)
return r >> -exp;
return r << exp;
}
/* $NetBSD: fixunssfdi_ieee754.c,v 1.1 2013/08/24 00:51:48 matt Exp $ */
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: fixunssfdi_ieee754.c,v 1.1 2013/08/24 00:51:48 matt Exp $");
#endif /* LIBC_SCCS and not lint */
#if defined(SOFTFLOAT) || defined(__ARM_EABI__)
#include "softfloat/softfloat-for-gcc.h"
#endif
#include "quad.h"
#include <limits.h>
#include <machine/ieee.h>
/*
* Convert float to unsigned quad.
* Not sure what to do with negative numbers---for now, anything out
* of range becomes UQUAD_MAX.
*/
u_quad_t
__fixunssfdi(float x)
{
const union ieee_single_u ux = { .sngu_f = x };
signed int exp = ux.sngu_exp - SNG_EXP_BIAS;
u_quad_t r;
if (ux.sngu_sign)
return UQUAD_MAX;
if (exp > 63)
return UQUAD_MAX;
if (exp < 0)
return 0;
r = 1 << SNG_FRACBITS; /* implicit bit */
r |= ux.sngu_frac;
exp -= SNG_FRACBITS;
if (exp == 0)
return r;
if (exp < 0)
return r >> -exp;
return r << exp;
}
/* $NetBSD: floatdidf_ieee754.c,v 1.1 2013/08/24 00:51:48 matt Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: floatdidf_ieee754.c,v 1.1 2013/08/24 00:51:48 matt Exp $");
#endif /* LIBC_SCCS and not lint */
#if defined(SOFTFLOAT) || defined(__ARM_EABI__)
#include "softfloat/softfloat-for-gcc.h"
#endif
#include <limits.h>
#include <machine/ieee.h>
#include "quad.h"
double __floatdidf(quad_t);
/*
* Convert signed quad to double.
*/
double
__floatdidf(quad_t x)
{
union ieee_double_u ux = { .dblu_d = 0.0 };
if (x == 0)
return 0.0;
if (x == 1)
return 1.0;
if (x < 0) {
if (x == QUAD_MIN)
return -0x1.0p63;
ux.dblu_sign = 1;
x = -x;
}
u_int l = __builtin_clzll(x);
x <<= (l + 1); /* clear implicit bit */
x >>= 64 - (DBL_FRACHBITS + DBL_FRACLBITS);
union uu u = { .uq = x };
ux.dblu_frach = u.ul[H];
ux.dblu_fracl = u.ul[L];
ux.dblu_exp = DBL_EXP_BIAS + 63 - l;
return ux.dblu_d;
}
/* $NetBSD: floatundidf_ieee754.c,v 1.1 2013/08/24 00:51:48 matt Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: floatundidf_ieee754.c,v 1.1 2013/08/24 00:51:48 matt Exp $");
#endif /* LIBC_SCCS and not lint */
#if defined(SOFTFLOAT) || defined(__ARM_EABI__)
#include "softfloat/softfloat-for-gcc.h"
#endif
#include <limits.h>
#include <machine/ieee.h>
#include "quad.h"
/*
* Convert unsigned quad to double.
*/
double
__floatundidf(u_quad_t x)
{
union ieee_double_u ux = { .dblu_d = 0.0 };
if (x == 0)
return 0.0;
if (x == 1)
return 1.0;
u_int l = __builtin_clzll(x);
x <<= (l + 1); /* clear implicit bit */
if (x == 0)
return 0x1.0p31;
x >>= 64 - (DBL_FRACHBITS + DBL_FRACLBITS);
union uu u = { .uq = x };
ux.dblu_frach = u.ul[H];
ux.dblu_fracl = u.ul[L];
ux.dblu_exp = DBL_EXP_BIAS + 63 - l;
return ux.dblu_d;
}
--- src/lib/libc/quad/floatdisf_ieee754.c 2013/08/23 17:41:03 1.1
+++ src/lib/libc/quad/floatdisf_ieee754.c 2013/08/24 00:51:48 1.2
| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: floatdisf_ieee754.c,v 1.1 2013/08/23 17:41:03 matt Exp $ */ | | 1 | /* $NetBSD: floatdisf_ieee754.c,v 1.2 2013/08/24 00:51:48 matt Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2013 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2013 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Matt Thomas of 3am Software Foundry. | | 8 | * by Matt Thomas of 3am Software Foundry. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -21,27 +21,27 @@ | | | @@ -21,27 +21,27 @@ |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | #if defined(LIBC_SCCS) && !defined(lint) | | 33 | #if defined(LIBC_SCCS) && !defined(lint) |
34 | __RCSID("$NetBSD: floatdisf_ieee754.c,v 1.1 2013/08/23 17:41:03 matt Exp $"); | | 34 | __RCSID("$NetBSD: floatdisf_ieee754.c,v 1.2 2013/08/24 00:51:48 matt Exp $"); |
35 | #endif /* LIBC_SCCS and not lint */ | | 35 | #endif /* LIBC_SCCS and not lint */ |
36 | | | 36 | |
37 | #if defined(SOFTFLOAT) || defined(__ARM_EABI__) | | 37 | #if defined(SOFTFLOAT) || defined(__ARM_EABI__) |
38 | #include "softfloat/softfloat-for-gcc.h" | | 38 | #include "softfloat/softfloat-for-gcc.h" |
39 | #endif | | 39 | #endif |
40 | | | 40 | |
41 | #include <limits.h> | | 41 | #include <limits.h> |
42 | #include <machine/ieee.h> | | 42 | #include <machine/ieee.h> |
43 | #include "quad.h" | | 43 | #include "quad.h" |
44 | | | 44 | |
45 | float __floatdisf(quad_t); | | 45 | float __floatdisf(quad_t); |
46 | | | 46 | |
47 | /* | | 47 | /* |
| @@ -59,31 +59,32 @@ __floatdisf(quad_t x) | | | @@ -59,31 +59,32 @@ __floatdisf(quad_t x) |
59 | | | 59 | |
60 | if (x < 0) { | | 60 | if (x < 0) { |
61 | if (x == QUAD_MIN) | | 61 | if (x == QUAD_MIN) |
62 | return -0x1.0p63; | | 62 | return -0x1.0p63; |
63 | ux.sngu_sign = 1; | | 63 | ux.sngu_sign = 1; |
64 | x = -x; | | 64 | x = -x; |
65 | } | | 65 | } |
66 | #if defined(_LP64) || defined(__mips_n32) | | 66 | #if defined(_LP64) || defined(__mips_n32) |
67 | u_int l = __builtin_clzll(x); | | 67 | u_int l = __builtin_clzll(x); |
68 | x <<= (l + 1); /* clear implicit bit */ | | 68 | x <<= (l + 1); /* clear implicit bit */ |
69 | | | 69 | |
70 | ux.sngu_frac = (u_quad_t)x >> (64 - SNG_FRACBITS); | | 70 | ux.sngu_frac = (u_quad_t)x >> (64 - SNG_FRACBITS); |
71 | #else | | 71 | #else |
72 | union uu u = { .q = x }; | | 72 | union uu u = { .uq = x }; |
73 | uint32_t frac; | | 73 | uint32_t frac; |
| | | 74 | u_int l; |
74 | if (u.ul[H] == 0) { | | 75 | if (u.ul[H] == 0) { |
75 | u_int l = __builtin_clz(u.ul[L]); | | 76 | l = __builtin_clz(u.ul[L]); |
76 | frac = u.ul[L] << (l + 1); /* clear implicit bit */ | | 77 | frac = u.ul[L] << (l + 1); /* clear implicit bit */ |
77 | l += 32; | | 78 | l += 32; |
78 | } else { | | 79 | } else { |
79 | u_int l = __builtin_clz(u.ul[H]); | | 80 | l = __builtin_clz(u.ul[H]); |
80 | frac = u.ul[H] << (l + 1); /* clear implicit bit */ | | 81 | frac = u.ul[H] << (l + 1); /* clear implicit bit */ |
81 | frac |= u.ul[L] >> (32 - (l + 1)); | | 82 | frac |= u.ul[L] >> (32 - (l + 1)); |
82 | } | | 83 | } |
83 | | | 84 | |
84 | ux.sngu_frac = frac >> (32 - SNG_FRACBITS); | | 85 | ux.sngu_frac = frac >> (32 - SNG_FRACBITS); |
85 | #endif | | 86 | #endif |
86 | ux.sngu_exp = SNG_EXP_BIAS + 63 - l; | | 87 | ux.sngu_exp = SNG_EXP_BIAS + 63 - l; |
87 | | | 88 | |
88 | return ux.sngu_f; | | 89 | return ux.sngu_f; |
89 | } | | 90 | } |
--- src/lib/libc/quad/floatundisf_ieee754.c 2013/08/23 17:41:03 1.1
+++ src/lib/libc/quad/floatundisf_ieee754.c 2013/08/24 00:51:48 1.2
| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: floatundisf_ieee754.c,v 1.1 2013/08/23 17:41:03 matt Exp $ */ | | 1 | /* $NetBSD: floatundisf_ieee754.c,v 1.2 2013/08/24 00:51:48 matt Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2013 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2013 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Matt Thomas of 3am Software Foundry. | | 8 | * by Matt Thomas of 3am Software Foundry. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -21,27 +21,27 @@ | | | @@ -21,27 +21,27 @@ |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | #if defined(LIBC_SCCS) && !defined(lint) | | 33 | #if defined(LIBC_SCCS) && !defined(lint) |
34 | __RCSID("$NetBSD: floatundisf_ieee754.c,v 1.1 2013/08/23 17:41:03 matt Exp $"); | | 34 | __RCSID("$NetBSD: floatundisf_ieee754.c,v 1.2 2013/08/24 00:51:48 matt Exp $"); |
35 | #endif /* LIBC_SCCS and not lint */ | | 35 | #endif /* LIBC_SCCS and not lint */ |
36 | | | 36 | |
37 | #if defined(SOFTFLOAT) || defined(__ARM_EABI__) | | 37 | #if defined(SOFTFLOAT) || defined(__ARM_EABI__) |
38 | #include "softfloat/softfloat-for-gcc.h" | | 38 | #include "softfloat/softfloat-for-gcc.h" |
39 | #endif | | 39 | #endif |
40 | | | 40 | |
41 | #include <machine/ieee.h> | | 41 | #include <machine/ieee.h> |
42 | #include "quad.h" | | 42 | #include "quad.h" |
43 | | | 43 | |
44 | float __floatundisf(u_quad_t); | | 44 | float __floatundisf(u_quad_t); |
45 | | | 45 | |
46 | /* | | 46 | /* |
47 | * Convert unsigned quad to float. | | 47 | * Convert unsigned quad to float. |
| @@ -54,29 +54,30 @@ __floatundisf(u_quad_t x) | | | @@ -54,29 +54,30 @@ __floatundisf(u_quad_t x) |
54 | if (x == 0) | | 54 | if (x == 0) |
55 | return 0.0; | | 55 | return 0.0; |
56 | if (x == 1) | | 56 | if (x == 1) |
57 | return 1.0; | | 57 | return 1.0; |
58 | | | 58 | |
59 | #if defined(_LP64) || defined(__mips_n32) | | 59 | #if defined(_LP64) || defined(__mips_n32) |
60 | u_int l = __builtin_clzll(x); | | 60 | u_int l = __builtin_clzll(x); |
61 | x <<= (l + 1); /* clear implicit bit */ | | 61 | x <<= (l + 1); /* clear implicit bit */ |
62 | | | 62 | |
63 | ux.sngu_frac = x >> (64 - SNG_FRACBITS); | | 63 | ux.sngu_frac = x >> (64 - SNG_FRACBITS); |
64 | #else | | 64 | #else |
65 | union uu u = { .uq = x }; | | 65 | union uu u = { .uq = x }; |
66 | uint32_t frac; | | 66 | uint32_t frac; |
| | | 67 | u_int l; |
67 | if (u.ul[H] == 0) { | | 68 | if (u.ul[H] == 0) { |
68 | u_int l = __builtin_clz(u.ul[L]); | | 69 | l = __builtin_clz(u.ul[L]); |
69 | frac = u.ul[L] << (l + 1); /* clear implicit bit */ | | 70 | frac = u.ul[L] << (l + 1); /* clear implicit bit */ |
70 | l += 32; | | 71 | l += 32; |
71 | } else { | | 72 | } else { |
72 | u_int l = __builtin_clz(u.ul[H]); | | 73 | l = __builtin_clz(u.ul[H]); |
73 | frac = u.ul[H] << (l + 1); /* clear implicit bit */ | | 74 | frac = u.ul[H] << (l + 1); /* clear implicit bit */ |
74 | frac |= u.ul[L] >> (32 - (l + 1)); | | 75 | frac |= u.ul[L] >> (32 - (l + 1)); |
75 | } | | 76 | } |
76 | | | 77 | |
77 | ux.sngu_frac = frac >> (32 - SNG_FRACBITS); | | 78 | ux.sngu_frac = frac >> (32 - SNG_FRACBITS); |
78 | #endif | | 79 | #endif |
79 | ux.sngu_exp = SNG_EXP_BIAS + 63 - l; | | 80 | ux.sngu_exp = SNG_EXP_BIAS + 63 - l; |
80 | | | 81 | |
81 | return ux.sngu_f; | | 82 | return ux.sngu_f; |
82 | } | | 83 | } |