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

[perl #128487] [Win32] signalling NaN is evasive on recent 32-bitperls

Thread Next
From:
Sisyphus
Date:
June 27, 2016 09:50
Subject:
[perl #128487] [Win32] signalling NaN is evasive on recent 32-bitperls
Message ID:
rt-4.0.18-10643-1467021028-570.128487-75-0@perl.org
# New Ticket Created by  "Sisyphus" 
# Please include the string:  [perl #128487]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=128487 >


Hi,

This report is a result of issues raised in
http://www.perlmonks.org/?node_id=1166429

It affects "MSWin32-x86-multi-thread-64int" builds of (at least) perl 
5.22.0, 5.24.0 and
5.25.2.
But "MSWin32-x64-multi-thread" builds of perl 5.22.0, 5.24.0 and 5.25.2 are 
*not* affected.

Both of those architectures have nvtype of 'double' and ivtype of 'long 
long' - and endianness is, of course, little-endian.

Example 1:
=========

C:\_32\pscrpt>type t1.pl
$snan = unpack 'd',  pack 'h16', scalar reverse '7ff0000000000001';
print scalar reverse unpack 'h16', pack 'd', $snan;

C:\_32\pscrpt>perl -lw t1.pl
7ff8000000000001

A signalling NaN has been requested, but we're informed that we got a quiet 
NaN.

Example 2: (needs 5.24.0 or later)
=========

C:\_32\pscrpt>type t1.pl
$snan = unpack 'd',  pack 'h16', scalar reverse '7ff0000000000001';
print "\$snan issignalling: ", issignaling($snan);

$snan2 = 0;

setpayloadsig($snan2, 15);
print "\$snan2 issignalling: ", issignaling($snan2);

print scalar reverse unpack 'h16', pack 'd', $snan2;

C:\_32\pscrpt>perl -MPOSIX=":nan_payload" -lw t1.pl
$snan issignalling: 0
$snan2 issignalling: 0
7ff800000000000f

Here we see that POSIX::issignaling also informs us that the signalling NaN 
we requested in Example 1 is a quiet NaN.
POSIX::issignaling further informs us that a NaN set using setpayloadsig is 
a quiet NaN, too - and unpack/pack agrees.

Example 3: (also needs 5.24.0 or later)
=========

C:\_32\pscrpt>type t1.pl
use Inline C => <<'EOC';

typedef union {
    double  d;
    long long i;
} BITS64;

double get_snan () {
  BITS64 x;

  x.i = 0x7ff0000000000001;

  return x.d;
}

EOC

$snan = get_snan();
print "\$snan issignalling: ", issignaling($snan);
print scalar reverse unpack 'h16', pack 'd', $snan;

C:\_32\pscrpt>perl -MPOSIX=":nan_payload" -lw t1.pl
$snan issignalling: 0
7ff8000000000001

Again we are told that $snan, which should be signalling, is quiet. (We can 
run this script on 5.22.0 if the issignaling call is removed - in which case 
we still get output of 7ff8000000000001.)

I think this issue can also affect other configurations of Windows perl  (eg 
"long double" builds and 32-bit builds where ivsize is 4) but I haven't 
checked on that properly.

Output of perl -V for 5.24.0 follows.

Cheers,
Rob

Summary of my perl5 (revision 5 version 24 subversion 0) configuration:

  Platform:
    osname=MSWin32, osvers=6.1, archname=MSWin32-x86-multi-thread-64int
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    useithreads=define, usemultiplicity=define
    use64bitint=define, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags 
=' -s -O2 -DWIN32  -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS 
 -DUSE_PERLIO -fwrapv -fno-strict-aliasing -mms-bitfields',
    optimize='-s -O2',
    cppflags='-DWIN32'
    ccversion='', gccversion='5.3.0', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678, 
doublekind=3
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12, 
longdblkind=3
    ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='long 
long', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='g++', ldflags 
='-s -L"c:\MinGW\perl524_64int\lib\CORE" -L"C:\_32\gcc-mingw-530\mingw32\lib"'
    libpth=C:\_32\gcc-mingw-530\mingw32\lib C:\_32\gcc-mingw-530\mingw32\lib 
C:\_32\gcc-mingw-530\mingw32\i686-w64-mingw32\lib 
C:\_32\msys_530\1.0\local\lib 
C:\_32\gcc-mingw-530\mingw32\lib\gcc\i686-w64-mingw32\5.3.0
    libs= -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 
 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion 
 -lodbc32 -lodbccp32 -lcomctl32
    perllibs= -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 
 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion 
 -lodbc32 -lodbccp32 -lcomctl32
    libc=, so=dll, useshrplib=true, libperl=libperl524.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', 
lddlflags='-mdll -s -L"c:\MinGW\perl524_64int\lib\CORE" -L"C:\_32\gcc-mingw-530\mingw32\lib"'


Characteristics of this binary (from libperl):
  Compile-time options: HAS_TIMES HAVE_INTERP_INTERN MULTIPLICITY
                        PERLIO_LAYERS PERL_COPY_ON_WRITE
                        PERL_DONT_CREATE_GVSV
                        PERL_HASH_FUNC_ONE_AT_A_TIME_HARD
                        PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS
                        PERL_MALLOC_WRAP PERL_PRESERVE_IVUV USE_64_BIT_INT
                        USE_ITHREADS USE_LARGE_FILES USE_LOCALE
                        USE_LOCALE_COLLATE USE_LOCALE_CTYPE
                        USE_LOCALE_NUMERIC USE_LOCALE_TIME USE_PERLIO
                        USE_PERL_ATOF
  Built under MSWin32
  Compiled at May  9 2016 22:40:05
  @INC:
    C:/MinGW/perl524_64int/site/lib
    C:/MinGW/perl524_64int/lib
    . 


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