GNU bug report logs - #25785
scm_c_make_polar broken on APPLE

Previous Next

Package: guile;

Reported by: Matt Wette <matt.wette <at> gmail.com>

Date: Sat, 18 Feb 2017 17:39:01 UTC

Severity: normal

Done: Andy Wingo <wingo <at> pobox.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 25785 in the body.
You can then email your comments to 25785 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#25785; Package guile. (Sat, 18 Feb 2017 17:39:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Matt Wette <matt.wette <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Sat, 18 Feb 2017 17:39:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Matt Wette <matt.wette <at> gmail.com>
To: bug-guile <at> gnu.org
Subject: scm_c_make_polar broken on APPLE
Date: Sat, 18 Feb 2017 09:37:54 -0800
[Message part 1 (text/plain, inline)]
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, “gcc -O2”  turns sin(), cos() into cexp(), since cexp(i*x) = cos(x) + i*sin(x):

gcc -O0 =>
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 =>
	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 = z*n;
  printf(" cos,sin: %+f %+f\n", cos(d), sin(d));
  __sincos(d, &sine, &cosine);
  printf("__sincos: %+f %+f\n", cosine, sine);
  c = cexp(CMPLX(0.0, d));
  printf("    cexp: %+f %+f\n", creal(c), cimag(c));
}

double z = 0.0, p = +1.0, n = -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 = sin (ang);
   c = cos (ang);


[Message part 2 (text/html, inline)]
[sincos.patch (application/octet-stream, attachment)]
[Message part 4 (text/html, inline)]

Information forwarded to bug-guile <at> gnu.org:
bug#25785; Package guile. (Sat, 18 Feb 2017 21:31:02 GMT) Full text and rfc822 format available.

Message #8 received at 25785 <at> debbugs.gnu.org (full text, mbox):

From: Matt Wette <matt.wette <at> gmail.com>
To: 25785 <at> debbugs.gnu.org
Subject: scm_c_make_polar broken
Date: Sat, 18 Feb 2017 13:30:33 -0800
[Message part 1 (text/plain, inline)]
So, I may have missed the update for config.h.in.   I am not sure this gets autogenerated or not.

--- config.h.in.orig	2017-02-18 13:27:19.000000000 -0800
+++ config.h.in	2017-02-18 13:27:45.000000000 -0800
@@ -2183,6 +2183,9 @@
 /* Define to 1 if you have the `sincos' function. */
 #undef HAVE_SINCOS
 
+/* Define to 1 if you have the `__sincos' function. */
+#undef HAVE___SINCOS
+
 /* Define to 1 if you have the `snprintf' function. */
 #undef HAVE_SNPRINTF
 

[Message part 2 (text/html, inline)]

Information forwarded to bug-guile <at> gnu.org:
bug#25785; Package guile. (Tue, 21 Feb 2017 21:11:01 GMT) Full text and rfc822 format available.

Message #11 received at 25785 <at> debbugs.gnu.org (full text, mbox):

From: Andy Wingo <wingo <at> pobox.com>
To: Matt Wette <matt.wette <at> gmail.com>
Cc: 25785 <at> debbugs.gnu.org
Subject: Re: bug#25785: scm_c_make_polar broken on APPLE
Date: Tue, 21 Feb 2017 22:10:09 +0100
On Sat 18 Feb 2017 18:37, Matt Wette <matt.wette <at> gmail.com> writes:

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

Thank you for this patch!  Applied.  The config.h.in is indeed
autogenerated (by autoheader, I think).

Andy




Reply sent to Andy Wingo <wingo <at> pobox.com>:
You have taken responsibility. (Tue, 21 Feb 2017 21:11:02 GMT) Full text and rfc822 format available.

Notification sent to Matt Wette <matt.wette <at> gmail.com>:
bug acknowledged by developer. (Tue, 21 Feb 2017 21:11:02 GMT) Full text and rfc822 format available.

Message #16 received at 25785-done <at> debbugs.gnu.org (full text, mbox):

From: Andy Wingo <wingo <at> pobox.com>
To: 25785-done <at> debbugs.gnu.org
Subject: Re: bug#25785: scm_c_make_polar broken on APPLE
Date: Tue, 21 Feb 2017 22:10:40 +0100
Thanks!




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 22 Mar 2017 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 89 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.