develooper Front page | perl.perl5.porters | Postings from November 2016

Issue with -DDEBUGGING and 128-bit types.

Thread Next
From:
sisyphus1
Date:
November 22, 2016 07:45
Subject:
Issue with -DDEBUGGING and 128-bit types.
Message ID:
87E91752EF054AA68768CC219B170769@OwnerPC311012
Hi,
Thanks to Dan Collins' cpan-testing for alerting me to this.
The 3 modules affected are Math::Float128, Math::Complex_C::Q and
Math::Decimal128; the platform is linux. (Ubuntu-16.04 for me - Debian for
Dan IIRC)
Each of these modules handles a 128-bit arithmetic type - __float128 for the 
first
two, and _Decimal128 for the last.

Links to those FAIL reports (which indicate the problem exists at least for
5.24.0, 5.25.5, 5.25.6 and 5.25.7) are given below my sig.

Basically, I've struck an alignment problem for perls built on linux with 
the following config_args:
-Dusedevel -DDEBUGGING -Dusethreads -Dprefix=/whatever -Uversiononly -des

Add a -Duselongdouble or -Dusequadmath to perl's configuration and the
problem goes away.
Remove the -DDEBUGGING and the problem goes away.

Here's an Inline::C demo of the issue:

###################################
use warnings;
use strict;

use Inline C => Config =>
  USING => 'ParseRegExp',
  LIBS => '-lquadmath -lm',
  BUILD_NOISY => 1;

use Inline C => <<'EOC';

#include <quadmath.h>

SV * UnityLD(void) {
     long double * f;
     SV * obj_ref, * obj;

     Newx(f, 1, long double);
     if(f == NULL) croak("Failed to allocate memory in UnityLD function");

     obj_ref = newSV(0);
     obj = newSVrv(obj_ref, NULL);

     *f = 1.0L;

     sv_setiv(obj, INT2PTR(IV,f));
     SvREADONLY_on(obj);
     return obj_ref;
}

SV * UnityF128(void) {
     __float128 * f;
     SV * obj_ref, * obj;

     Newx(f, 1, __float128);
     if(f == NULL) croak("Failed to allocate memory in UnityF128 function");

     obj_ref = newSV(0);
     obj = newSVrv(obj_ref, NULL);

     *f = 1.0Q;

     sv_setiv(obj, INT2PTR(IV,f));
     SvREADONLY_on(obj);
     return obj_ref;
}

EOC

print "ok 0\n";
my $x = UnityLD();
print "ok 1\n";
my $y = UnityF128();
print "ok 2\n";
###################################

UnityLD() returns an object that encapsulates an extended precision long 
double with a value of
1.0. It can be called without any problem - though what happens if the 'long 
double' is the full quad type is untested.
UnityF128() uses the same approach to return an object that encapsulates a
__float128 with a value of 1.0. It segfaults whenn called on the DEBUGGING, 
nvtype=double builds of perl.

As an alternative to not defining DEBUGGING or defining
usequadmath/uselongdouble, I can also fix the problem by inserting the
follow typedef:

typedef __float128 float128 __attribute__ ((aligned(8)));

(Of course, I then also need to replace the occurrences of "__float128" in
the code with "float128".)

Similarly, for Math::Decimal128 I can do something like:

typedef _Decimal128 D128 __attribute__ ((aligned(8)));

Are these -DDEBUGGING builds of perl behaving as they ought ?
FAIK this is part and parcel of what needs to happen when a perl whose 
nvtype is double is built for DEBUGGING ... just wondering ...

Cheers,
Rob

###################################
Math-Complex_C-Q-0.05:
- x86_64-linux-thread-multi / 5.24.0:
  - FAIL
http://www.cpantesters.org/cpan/report/1895b4b0-9529-11e6-9d8c-fd3fe822d6a9

- x86_64-linux-thread-multi / 5.25.5:
  - FAIL
http://www.cpantesters.org/cpan/report/1486a94c-9529-11e6-9d8c-fd3fe822d6a9

- x86_64-linux-thread-multi / 5.25.6:
  - FAIL
http://www.cpantesters.org/cpan/report/13a08d4a-9529-11e6-9d8c-fd3fe822d6a9

- x86_64-linux-thread-multi / 5.25.7:
  - FAIL
http://www.cpantesters.org/cpan/report/d2b8ee30-a653-11e6-932a-f4415c96acb4
###################################
Math-Decimal128-0.07:
- x86_64-linux-thread-multi / 5.24.0:
  - FAIL
http://www.cpantesters.org/cpan/report/1e379302-9529-11e6-9d8c-fd3fe822d6a9

- x86_64-linux-thread-multi / 5.25.5:
  - FAIL
http://www.cpantesters.org/cpan/report/1b868460-9529-11e6-9d8c-fd3fe822d6a9

- x86_64-linux-thread-multi / 5.25.6:
  - FAIL
http://www.cpantesters.org/cpan/report/1aa382aa-9529-11e6-9d8c-fd3fe822d6a9

- x86_64-linux-thread-multi / 5.25.7:
  - FAIL
http://www.cpantesters.org/cpan/report/d62ad5e2-a653-11e6-932a-f4415c96acb4
###################################
Math-Float128-0.11:
- x86_64-linux-thread-multi / 5.24.0:
  - FAIL
http://www.cpantesters.org/cpan/report/26cfa8a6-9529-11e6-9d8c-fd3fe822d6a9

- x86_64-linux-thread-multi / 5.25.5:
  - FAIL
http://www.cpantesters.org/cpan/report/22065540-9529-11e6-9d8c-fd3fe822d6a9

- x86_64-linux-thread-multi / 5.25.6:
  - FAIL
http://www.cpantesters.org/cpan/report/23126596-9529-11e6-9d8c-fd3fe822d6a9

- x86_64-linux-thread-multi / 5.25.7:
  - FAIL
http://www.cpantesters.org/cpan/report/dd8e2488-a653-11e6-932a-f4415c96acb4


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About