summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authorjca <jca@openbsd.org>2019-06-21 17:00:58 +0000
committerjca <jca@openbsd.org>2019-06-21 17:00:58 +0000
commitdcaa94fa8333d546e96b49f352c2dd028e96fd9d (patch)
treec0aca4c4265bdaf1ce92e8caf072166ba80c3a64 /lib/libc
parentTry harder to have a complete /bsd.upgrade on disk. (diff)
downloadwireguard-openbsd-dcaa94fa8333d546e96b49f352c2dd028e96fd9d.tar.xz
wireguard-openbsd-dcaa94fa8333d546e96b49f352c2dd028e96fd9d.zip
Fix conversions to long double on sparc64
Bug exposed by erratic sqlite3 behavior used in ports/devel/proj, as pointed out by landry@. Richard Hipps (SQLite) pointed at the culprit (_Qp_div), many thanks. Adapted from FreeBSD revision 146673 by Stephen Paskaluk and stefanf@FreeBSD. FreeBSD commit message: """ Fix long (and long long) to long double, unsigned to long double and unsigned long (and unsigned long long) to long double conversions. - Add a parameter that specifies the position of the sign bit to the _QP_TTOQ macro, previously it always looked at bit 31. Pass a negative number to disable sign inspection for unsigned types. This fixes _Qp_xtoq(), _Qp_uitoq() and _Qp_uxtoq(). - In the functions __fpu_itof() and __fpu_xtof(), look at the sign bit to decide whether we're doing a conversion from an unsigned type. If so, don't negate the mantissa if the integer exceeds the biggest signed number. """ ok deraadt@
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/arch/sparc64/fpu/fpu_explode.c6
-rw-r--r--lib/libc/arch/sparc64/fpu/fpu_qp.c18
2 files changed, 12 insertions, 12 deletions
diff --git a/lib/libc/arch/sparc64/fpu/fpu_explode.c b/lib/libc/arch/sparc64/fpu/fpu_explode.c
index e16eff95ecd..8ee93048645 100644
--- a/lib/libc/arch/sparc64/fpu/fpu_explode.c
+++ b/lib/libc/arch/sparc64/fpu/fpu_explode.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fpu_explode.c,v 1.9 2019/03/15 05:42:38 kevlo Exp $ */
+/* $OpenBSD: fpu_explode.c,v 1.10 2019/06/21 17:00:58 jca Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -99,7 +99,7 @@ __fpu_itof(fp, i)
* fpu_norm()'s handling of `supernormals'; see fpu_subr.c.
*/
fp->fp_exp = FP_LG;
- fp->fp_mant[0] = (int)i < 0 ? -i : i;
+ fp->fp_mant[0] = (fp->fp_sign && (int)i < 0) ? -i : i;
fp->fp_mant[1] = 0;
fp->fp_mant[2] = 0;
fp->fp_mant[3] = 0;
@@ -151,7 +151,7 @@ __fpu_xtof(fp, i)
* fpu_norm()'s handling of `supernormals'; see fpu_subr.c.
*/
fp->fp_exp = FP_LG2;
- i = ((int64_t)i < 0) ? -i : i;
+ i = (fp->fp_sign && (int64_t)i < 0) ? -i : i;
fp->fp_mant[0] = (i >> 32) & 0xffffffff;
fp->fp_mant[1] = (i >> 0) & 0xffffffff;
fp->fp_mant[2] = 0;
diff --git a/lib/libc/arch/sparc64/fpu/fpu_qp.c b/lib/libc/arch/sparc64/fpu/fpu_qp.c
index 8c7a088b007..c0821b2b487 100644
--- a/lib/libc/arch/sparc64/fpu/fpu_qp.c
+++ b/lib/libc/arch/sparc64/fpu/fpu_qp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fpu_qp.c,v 1.7 2019/03/15 05:42:38 kevlo Exp $ */
+/* $OpenBSD: fpu_qp.c,v 1.8 2019/06/21 17:00:58 jca Exp $ */
/*-
* Copyright (c) 2002 Jake Burkholder.
@@ -52,7 +52,7 @@ _Qp_ ## op(u_int *c, u_int *a, u_int *b) \
} \
DEF_STRONG(_Qp_ ## op);
-#define _QP_TTOQ(qname, fname, ntype, atype, signed, ...) \
+#define _QP_TTOQ(qname, fname, ntype, signpos, atype, ...) \
void _Qp_ ## qname ## toq(u_int *c, ntype n); \
PROTO_NORMAL(_Qp_ ## qname ## toq); \
void \
@@ -62,7 +62,7 @@ _Qp_ ## qname ## toq(u_int *c, ntype n) \
atype *a; \
__asm volatile("stx %%fsr, %0" : "=m" (fe.fe_fsr) :); \
a = (atype *)&n; \
- fe.fe_f1.fp_sign = signed ? a[0] >> 31 : 0; \
+ fe.fe_f1.fp_sign = (signpos >= 0) ? a[0] >> signpos : 0; \
fe.fe_f1.fp_sticky = 0; \
fe.fe_f1.fp_class = __fpu_ ## fname ## tof(&fe.fe_f1, __VA_ARGS__); \
c[0] = __fpu_ftoq(&fe, &fe.fe_f1, c); \
@@ -176,12 +176,12 @@ _QP_OP(div)
_QP_OP(mul)
_QP_OP(sub)
-_QP_TTOQ(d, d, double, u_int, 1, a[0], a[1])
-_QP_TTOQ(i, i, int, u_int, 1, a[0])
-_QP_TTOQ(s, s, float, u_int, 1, a[0])
-_QP_TTOQ(x, x, long, u_long, 1, a[0])
-_QP_TTOQ(ui, ui, u_int, u_int, 0, a[0])
-_QP_TTOQ(ux, ux, u_long, u_long, 0, a[0])
+_QP_TTOQ(d, d, double, 31, u_int, a[0], a[1])
+_QP_TTOQ(i, i, int, 31, u_int, a[0])
+_QP_TTOQ(s, s, float, 31, u_int, a[0])
+_QP_TTOQ(x, x, long, 63, u_long, a[0])
+_QP_TTOQ(ui, ui, u_int, -1, u_int, a[0])
+_QP_TTOQ(ux, ux, u_long, -1, u_long, a[0])
_QP_QTOT4(d, d, double, a)
_QP_QTOT3(i, i, int)