From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Matt Wette Newsgroups: gmane.lisp.guile.bugs Subject: bug#25785: scm_c_make_polar broken on APPLE Date: Sat, 18 Feb 2017 09:37:54 -0800 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 (Mac OS X Mail 10.2 \(3259\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_A118C0A3-D324-47B9-9844-79DF6C0C3EB2" X-Trace: blaine.gmane.org 1487439557 11875 195.159.176.226 (18 Feb 2017 17:39:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 18 Feb 2017 17:39:17 +0000 (UTC) To: 25785@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Sat Feb 18 18:39:08 2017 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cf8yP-0002BS-Vb for guile-bugs@m.gmane.org; Sat, 18 Feb 2017 18:39:06 +0100 Original-Received: from localhost ([::1]:59339 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cf8yV-0001M6-PK for guile-bugs@m.gmane.org; Sat, 18 Feb 2017 12:39:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35378) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cf8yP-0001Lx-Kz for bug-guile@gnu.org; Sat, 18 Feb 2017 12:39:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cf8yM-0006Gh-Ga for bug-guile@gnu.org; Sat, 18 Feb 2017 12:39:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:47046) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cf8yM-0006Gb-CC for bug-guile@gnu.org; Sat, 18 Feb 2017 12:39:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cf8yM-00025j-3U for bug-guile@gnu.org; Sat, 18 Feb 2017 12:39:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Matt Wette Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sat, 18 Feb 2017 17:39:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 25785 X-GNU-PR-Package: guile X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-guile@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.14874394987981 (code B ref -1); Sat, 18 Feb 2017 17:39:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 18 Feb 2017 17:38:18 +0000 Original-Received: from localhost ([127.0.0.1]:45245 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cf8xe-00024f-BC for submit@debbugs.gnu.org; Sat, 18 Feb 2017 12:38:18 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:44269) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cf8xd-00024S-6K for submit@debbugs.gnu.org; Sat, 18 Feb 2017 12:38:17 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cf8xU-0005gp-LC for submit@debbugs.gnu.org; Sat, 18 Feb 2017 12:38:11 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:41467) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cf8xU-0005gj-Gt for submit@debbugs.gnu.org; Sat, 18 Feb 2017 12:38:08 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35225) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cf8xQ-0000x5-SH for bug-guile@gnu.org; Sat, 18 Feb 2017 12:38:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cf8xL-0005fC-Rb for bug-guile@gnu.org; Sat, 18 Feb 2017 12:38:04 -0500 Original-Received: from mail-pg0-x22c.google.com ([2607:f8b0:400e:c05::22c]:33694) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cf8xL-0005ez-Hz for bug-guile@gnu.org; Sat, 18 Feb 2017 12:37:59 -0500 Original-Received: by mail-pg0-x22c.google.com with SMTP id a123so1242612pgc.0 for ; Sat, 18 Feb 2017 09:37:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:mime-version:subject:message-id:date:to; bh=1V74h6NQiIj86KUQoZg9lkStqEvGamHRhPo5Co5slQ0=; b=N3wZAHbaV3u5rjLNqiR9FYlI1yLj8xvIdPcF/P4lRmhHLw+HNjT30dDrxxZAh+Otbr H1NIV6CgOc3KwA2fjWxFYvmdskA25emWDRWOvgrQ0nD6murR4s72cliL8gZgxz8rihKs RVrXqzYxIdXA3W5mMSR1yz8uMuM/mz1DLc6NCauVyunOcQfzavXTclc8PISDbP0Dhp6O p3AKiqrMTOuf2P9us/oKxQ4PSgCsiNCc/NN872xCvHF7GZuErLV4ZGyOz1pd7cl1pBFH TEURG5WYt8O2PvA4Na5aUV3mITXUPnWRERdudCKWiVRMMczvl7SF0M1HVK03hnr0s6St lBlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:message-id:date:to; bh=1V74h6NQiIj86KUQoZg9lkStqEvGamHRhPo5Co5slQ0=; b=DB0OQ1KvdEDzyJb5TomfOzxfYLEMr3GeoBCAK0FZFdlxLREXDGwAMVY99OXJ5tKfOQ 81ze3CiDOiALSXW+LlgVt93Q8E1oGQllMoEL4HWK+DapnaStzFUiLhnNEVpg8muuBLQH MZ4L2B400+0eoIUOOeCfL+WygfnJ23iy0HYIdXEQ39zQbNDed09zDx+bcLegiTsrWr35 8hJoRW3SLsqSTZXf4nl/pScD3HFrNvReQNLRkyhYOd/WOSJ820QCta5jkfE087CAs7rZ 9gX239HNa3nPLj/i8KPmMkQxOrUfHtSku8qzntJNbnptecklmJqQN+Ws207v8NoDBu+B M1Xg== X-Gm-Message-State: AMke39mI8o9nnvv7NBGqBFxIm+i7DAiHE+ww6RKlol+1WxZdNs76wlXQf7nEYzkXaBHTaQ== X-Received: by 10.84.241.138 with SMTP id b10mr19820313pll.32.1487439477944; Sat, 18 Feb 2017 09:37:57 -0800 (PST) Original-Received: from nautilus.championbroadband.com (216-165-246-244.championbroadband.com. [216.165.246.244]) by smtp.gmail.com with ESMTPSA id i15sm5244927pfj.0.2017.02.18.09.37.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Feb 2017 09:37:56 -0800 (PST) X-Mailer: Apple Mail (2.3259) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.org gmane.lisp.guile.bugs:8547 Archived-At: --Apple-Mail=_A118C0A3-D324-47B9-9844-79DF6C0C3EB2 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 numbers.c:scm_c_make_polar in guile-2.1.7 breaks on APPLE (macOS 10.12). Reason: APPLE does not have sincos(), and gcc will optimize sin/cos to = use cexp(), and cexp() does not preserve sign of zero. Patch includes (and attached) for guile-2.1.7. This uses macOS = __sincos(). Example: In scm_c_make_polar, =E2=80=9Cgcc -O2=E2=80=9D turns sin(), cos() into = cexp(), since cexp(i*x) =3D cos(x) + i*sin(x): gcc -O0 =3D> LM4339: movq -32(%rbp), %rax movd %rax, %xmm0 call _sin movd %xmm0, %rax movq %rax, -8(%rbp) LM4340: movq -32(%rbp), %rax movd %rax, %xmm0 call _cos movd %xmm0, %rax movq %rax, -16(%rbp) gcc -O2 =3D> pxor %xmm0, %xmm0 LVL2703: call _cexp I wrote a little C program to show that cexp() does not preserve the = zero-signed-ness: cos,sin: +1.000000 -0.000000 __sincos: +1.000000 -0.000000 cexp: +1.000000 +0.000000 The scm_c_make_polar will use sincos() if available, but macOS does not = have sincos(), it has __sincos(). #include #include #include #include extern double z, p, n; int main() { double complex c; double d, sine, cosine; d =3D z*n; printf(" cos,sin: %+f %+f\n", cos(d), sin(d)); __sincos(d, &sine, &cosine); printf("__sincos: %+f %+f\n", cosine, sine); c =3D cexp(CMPLX(0.0, d)); printf(" cexp: %+f %+f\n", creal(c), cimag(c)); } double z =3D 0.0, p =3D +1.0, n =3D -1.0; --- configure.ac.orig 2017-02-18 08:35:06.000000000 -0800 +++ configure.ac 2017-02-18 08:35:26.000000000 -0800 @@ -1152,8 +1152,9 @@ # asinh, acosh, atanh, trunc - C99 standard, generally not available = on # older systems # sincos - GLIBC extension +# __sincos - APPLE extension # -AC_CHECK_FUNCS(asinh acosh atanh copysign finite sincos trunc) +AC_CHECK_FUNCS(asinh acosh atanh copysign finite sincos __sincos trunc) =20 # C99 specifies isinf and isnan as macros. # HP-UX provides only macros, no functions. --- libguile/numbers.c.patch.labs 2017-02-18 08:31:21.000000000 = -0800 +++ libguile/numbers.c 2017-02-18 08:34:18.000000000 -0800 @@ -9109,6 +9109,8 @@ details. */ #if (defined HAVE_SINCOS) && (defined __GLIBC__) && (defined = _GNU_SOURCE) sincos (ang, &s, &c); +#elif (defined HAVE___SINCOS) + __sincos (ang, &s, &c); #else s =3D sin (ang); c =3D cos (ang); --Apple-Mail=_A118C0A3-D324-47B9-9844-79DF6C0C3EB2 Content-Type: multipart/mixed; boundary="Apple-Mail=_1F9A3EBB-9475-4C82-B9EF-39C4681D7900" --Apple-Mail=_1F9A3EBB-9475-4C82-B9EF-39C4681D7900 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 numbers.c:scm_c_make_polar in guile-2.1.7 breaks on APPLE = (macOS 10.12).

Reason:= APPLE does not have sincos(), and gcc will optimize sin/cos to use = cexp(), and cexp() does not preserve sign of zero.

Patch includes (and = attached) for guile-2.1.7.  This uses macOS __sincos().

Example:
In scm_c_make_polar, =E2=80=9Cgcc -O2=E2=80=9D =  turns sin(), cos() into cexp(), since cexp(i*x) =3D cos(x) + = i*sin(x):

gcc -O0 = =3D>
LM4339:
= movq = -32(%rbp), %rax
= movd = %rax, %xmm0
= call = _sin
= movd = %xmm0, %rax
= movq = %rax, -8(%rbp)
LM4340:
= movq = -32(%rbp), %rax
= movd = %rax, %xmm0
= call = _cos
= movd = %xmm0, %rax
= movq = %rax, -16(%rbp)

gcc -O2 =3D>
pxor %xmm0, %xmm0
LVL2703:
call _cexp

I wrote a little C = program to show that cexp() does not preserve the = zero-signed-ness:

 cos,sin: +1.000000 = -0.000000
__sincos: = +1.000000 -0.000000
    = cexp: +1.000000 +0.000000

The scm_c_make_polar will use = sincos() if available, but macOS does not have sincos(), it has = __sincos().

#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include = <complex.h>

extern double z, p, n;

int main() = {
  double complex c;
  = double d, sine, cosine;

  d =3D z*n;
  printf(" = cos,sin: %+f %+f\n", cos(d), sin(d));
  = __sincos(d, &sine, &cosine);
  = printf("__sincos: %+f %+f\n", cosine, sine);
  c =3D = cexp(CMPLX(0.0, d));
  = printf("    cexp: %+f %+f\n", creal(c), = cimag(c));
}

double z =3D 0.0, p =3D +1.0, n =3D = -1.0;


--- configure.ac.orig = 2017-02-18 08:35:06.000000000 -0800
+++ configure.ac 2017-02-18 08:35:26.000000000 = -0800
@@ -1152,8 +1152,9 = @@
 #   = asinh, acosh, atanh, trunc - C99 standard, generally not available = on
 #   =                     =          older systems
 #   sincos - GLIBC = extension
+#   __sincos - = APPLE extension
 #
-AC_CHECK_FUNCS(asinh acosh atanh copysign finite sincos = trunc)
+AC_CHECK_FUNCS(asinh = acosh atanh copysign finite sincos __sincos trunc)
 
 # C99 specifies isinf and isnan as = macros.
 # HP-UX = provides only macros, no functions.
--- libguile/numbers.c.patch.labs = 2017-02-18 08:31:21.000000000 -0800
+++ libguile/numbers.c 2017-02-18 08:34:18.000000000 = -0800
@@ -9109,6 +9109,8 = @@
      = details.  */
 #if= (defined HAVE_SINCOS) && (defined __GLIBC__) && = (defined _GNU_SOURCE)
  =  sincos (ang, &s, &c);
+#elif (defined HAVE___SINCOS)
+  __sincos (ang, &s, = &c);
 #else
  =  s =3D sin (ang);
  =  c =3D cos (ang);
= --Apple-Mail=_1F9A3EBB-9475-4C82-B9EF-39C4681D7900 Content-Disposition: attachment; filename=sincos.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="sincos.patch" Content-Transfer-Encoding: 7bit --- configure.ac.orig 2017-02-18 08:35:06.000000000 -0800 +++ configure.ac 2017-02-18 08:35:26.000000000 -0800 @@ -1152,8 +1152,9 @@ # asinh, acosh, atanh, trunc - C99 standard, generally not available on # older systems # sincos - GLIBC extension +# __sincos - APPLE extension # -AC_CHECK_FUNCS(asinh acosh atanh copysign finite sincos trunc) +AC_CHECK_FUNCS(asinh acosh atanh copysign finite sincos __sincos trunc) # C99 specifies isinf and isnan as macros. # HP-UX provides only macros, no functions. --- libguile/numbers.c.patch.labs 2017-02-18 08:31:21.000000000 -0800 +++ libguile/numbers.c 2017-02-18 08:34:18.000000000 -0800 @@ -9109,6 +9109,8 @@ details. */ #if (defined HAVE_SINCOS) && (defined __GLIBC__) && (defined _GNU_SOURCE) sincos (ang, &s, &c); +#elif (defined HAVE___SINCOS) + __sincos (ang, &s, &c); #else s = sin (ang); c = cos (ang); --Apple-Mail=_1F9A3EBB-9475-4C82-B9EF-39C4681D7900 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=us-ascii

--Apple-Mail=_1F9A3EBB-9475-4C82-B9EF-39C4681D7900-- --Apple-Mail=_A118C0A3-D324-47B9-9844-79DF6C0C3EB2--