Module Name: src
Committed By: matt
Date: Sat Aug 24 00:51:48 UTC 2013
Modified Files:
src/lib/libc/quad: Makefile.inc floatdisf_ieee754.c
floatundisf_ieee754.c
Added Files:
src/lib/libc/quad: fixdfdi_ieee754.c fixsfdi_ieee754.c
fixunsdfdi_ieee754.c fixunssfdi_ieee754.c floatdidf_ieee754.c
floatundidf_ieee754.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/quad/Makefile.inc
cvs rdiff -u -r0 -r1.1 src/lib/libc/quad/fixdfdi_ieee754.c \
src/lib/libc/quad/fixsfdi_ieee754.c \
src/lib/libc/quad/fixunsdfdi_ieee754.c \
src/lib/libc/quad/fixunssfdi_ieee754.c \
src/lib/libc/quad/floatdidf_ieee754.c \
src/lib/libc/quad/floatundidf_ieee754.c
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/quad/floatdisf_ieee754.c \
src/lib/libc/quad/floatundisf_ieee754.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/quad/Makefile.inc
diff -u src/lib/libc/quad/Makefile.inc:1.16 src/lib/libc/quad/Makefile.inc:1.17
--- src/lib/libc/quad/Makefile.inc:1.16 Tue Apr 30 01:43:01 2013
+++ src/lib/libc/quad/Makefile.inc Sat Aug 24 00:51:48 2013
@@ -1,13 +1,15 @@
-# $NetBSD: Makefile.inc,v 1.16 2013/04/30 01:43:01 matt Exp $
+# $NetBSD: Makefile.inc,v 1.17 2013/08/24 00:51:48 matt Exp $
# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
# Quad support
SRCS.quad= cmpdi2.c ucmpdi2.c
SRCS.quad+= divdi3.c moddi3.c
+.if empty(LIBC_MACHINE_ARCH:Mearm*)
SRCS.quad+= fixdfdi.c fixsfdi.c
SRCS.quad+= fixunsdfdi.c fixunssfdi.c
SRCS.quad+= floatdidf.c floatdisf.c
-SRCS.quad+= floatundisf.c floatundidf.c
+SRCS.quad+= floatundidf.c floatundisf.c
+.endif
SRCS.quad+= muldi3.c
SRCS.quad+= negdi2.c
SRCS.quad+= qdivrem.c
@@ -17,8 +19,12 @@ SRCS.quad+= udivdi3.c umoddi3.c
SRCS.quad+= ashldi3.S ashrdi3.S lshrdi3.S
.elif (${MACHINE_ARCH} == "m68000")
SRCS.quad+= ashldi3.S lshrdi3.S
-.elif (!empty{LIBC_MACHINE_ARCH:Mearm*})
+.elif !empty(LIBC_MACHINE_ARCH:Mearm*)
SRCS.quad+= ashldi3.c ashrdi3.c lshrdi3.c lshldi3.c
+SRCS.quad+= floatdidf_ieee754.c floatdisf_ieee754.c
+SRCS.quad+= floatundidf_ieee754.c floatundisf_ieee754.c
+SRCS.quad+= fixdfdi_ieee754.c fixsfdi_ieee754.c
+SRCS.quad+= fixunsdfdi_ieee754.c fixunssfdi_ieee754.c
.else
SRCS.quad+= ashldi3.c ashrdi3.c lshrdi3.c
.endif
Index: src/lib/libc/quad/floatdisf_ieee754.c
diff -u src/lib/libc/quad/floatdisf_ieee754.c:1.1 src/lib/libc/quad/floatdisf_ieee754.c:1.2
--- src/lib/libc/quad/floatdisf_ieee754.c:1.1 Fri Aug 23 17:41:03 2013
+++ src/lib/libc/quad/floatdisf_ieee754.c Sat Aug 24 00:51:48 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: floatdisf_ieee754.c,v 1.1 2013/08/23 17:41:03 matt Exp $ */
+/* $NetBSD: floatdisf_ieee754.c,v 1.2 2013/08/24 00:51:48 matt Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: floatdisf_ieee754.c,v 1.1 2013/08/23 17:41:03 matt Exp $");
+__RCSID("$NetBSD: floatdisf_ieee754.c,v 1.2 2013/08/24 00:51:48 matt Exp $");
#endif /* LIBC_SCCS and not lint */
#if defined(SOFTFLOAT) || defined(__ARM_EABI__)
@@ -69,14 +69,15 @@ __floatdisf(quad_t x)
ux.sngu_frac = (u_quad_t)x >> (64 - SNG_FRACBITS);
#else
- union uu u = { .q = x };
+ union uu u = { .uq = x };
uint32_t frac;
+ u_int l;
if (u.ul[H] == 0) {
- u_int l = __builtin_clz(u.ul[L]);
+ l = __builtin_clz(u.ul[L]);
frac = u.ul[L] << (l + 1); /* clear implicit bit */
l += 32;
} else {
- u_int l = __builtin_clz(u.ul[H]);
+ l = __builtin_clz(u.ul[H]);
frac = u.ul[H] << (l + 1); /* clear implicit bit */
frac |= u.ul[L] >> (32 - (l + 1));
}
Index: src/lib/libc/quad/floatundisf_ieee754.c
diff -u src/lib/libc/quad/floatundisf_ieee754.c:1.1 src/lib/libc/quad/floatundisf_ieee754.c:1.2
--- src/lib/libc/quad/floatundisf_ieee754.c:1.1 Fri Aug 23 17:41:03 2013
+++ src/lib/libc/quad/floatundisf_ieee754.c Sat Aug 24 00:51:48 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: floatundisf_ieee754.c,v 1.1 2013/08/23 17:41:03 matt Exp $ */
+/* $NetBSD: floatundisf_ieee754.c,v 1.2 2013/08/24 00:51:48 matt Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: floatundisf_ieee754.c,v 1.1 2013/08/23 17:41:03 matt Exp $");
+__RCSID("$NetBSD: floatundisf_ieee754.c,v 1.2 2013/08/24 00:51:48 matt Exp $");
#endif /* LIBC_SCCS and not lint */
#if defined(SOFTFLOAT) || defined(__ARM_EABI__)
@@ -64,12 +64,13 @@ __floatundisf(u_quad_t x)
#else
union uu u = { .uq = x };
uint32_t frac;
+ u_int l;
if (u.ul[H] == 0) {
- u_int l = __builtin_clz(u.ul[L]);
+ l = __builtin_clz(u.ul[L]);
frac = u.ul[L] << (l + 1); /* clear implicit bit */
l += 32;
} else {
- u_int l = __builtin_clz(u.ul[H]);
+ l = __builtin_clz(u.ul[H]);
frac = u.ul[H] << (l + 1); /* clear implicit bit */
frac |= u.ul[L] >> (32 - (l + 1));
}
Added files:
Index: src/lib/libc/quad/fixdfdi_ieee754.c
diff -u /dev/null src/lib/libc/quad/fixdfdi_ieee754.c:1.1
--- /dev/null Sat Aug 24 00:51:48 2013
+++ src/lib/libc/quad/fixdfdi_ieee754.c Sat Aug 24 00:51:48 2013
@@ -0,0 +1,82 @@
+/* $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;
+}
Index: src/lib/libc/quad/fixsfdi_ieee754.c
diff -u /dev/null src/lib/libc/quad/fixsfdi_ieee754.c:1.1
--- /dev/null Sat Aug 24 00:51:48 2013
+++ src/lib/libc/quad/fixsfdi_ieee754.c Sat Aug 24 00:51:48 2013
@@ -0,0 +1,75 @@
+/* $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;
+}
Index: src/lib/libc/quad/fixunsdfdi_ieee754.c
diff -u /dev/null src/lib/libc/quad/fixunsdfdi_ieee754.c:1.1
--- /dev/null Sat Aug 24 00:51:48 2013
+++ src/lib/libc/quad/fixunsdfdi_ieee754.c Sat Aug 24 00:51:48 2013
@@ -0,0 +1,85 @@
+/* $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;
+}
Index: src/lib/libc/quad/fixunssfdi_ieee754.c
diff -u /dev/null src/lib/libc/quad/fixunssfdi_ieee754.c:1.1
--- /dev/null Sat Aug 24 00:51:48 2013
+++ src/lib/libc/quad/fixunssfdi_ieee754.c Sat Aug 24 00:51:48 2013
@@ -0,0 +1,77 @@
+/* $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;
+}
Index: src/lib/libc/quad/floatdidf_ieee754.c
diff -u /dev/null src/lib/libc/quad/floatdidf_ieee754.c:1.1
--- /dev/null Sat Aug 24 00:51:48 2013
+++ src/lib/libc/quad/floatdidf_ieee754.c Sat Aug 24 00:51:48 2013
@@ -0,0 +1,75 @@
+/* $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;
+}
Index: src/lib/libc/quad/floatundidf_ieee754.c
diff -u /dev/null src/lib/libc/quad/floatundidf_ieee754.c:1.1
--- /dev/null Sat Aug 24 00:51:48 2013
+++ src/lib/libc/quad/floatundidf_ieee754.c Sat Aug 24 00:51:48 2013
@@ -0,0 +1,69 @@
+/* $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;
+}