Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.85k stars 527 forks source link

Weird conversion issue with List::Util::sum on Linux/AMD 850MHz #6786

Closed p5pRT closed 20 years ago

p5pRT commented 20 years ago

Migrated from rt.perl.org#24012 (status was 'resolved')

Searchable as RT24012$

p5pRT commented 20 years ago

From martyn@chrome.sixears.co.uk

Created by martyn@chrome.sixears.co.uk

List​::Util​::sum returns questionable results when negative literals are provided on my Gentoo Linux AMD K6 800MHz box. It does not occur on my 1.6GHz Athlon\, no my Intel P-II Mobile. This occurs with 5.8.0 and 5.8.1-RC4​:

[martyn​:0]$ perl -MList​::Util=sum -le 'print sum -1' 4294967295 [martyn​:0]$ perl -MList​::Util=sum -le 'print sum -1\, 2' 4294967297

this only occurs with literal values

[martyn​:0]$ perl -MList​::Util=sum -le 'print sum 0.0\, -12.0' -12 [martyn​:0]$ perl -MList​::Util=sum -le 'print sum "0"\, "-12"' -12 [martyn​:0]$ perl -MList​::Util=sum -le 'print sum 0+0\, -12+0' 4294967284 [martyn​:0]$ perl -MList​::Util=sum -le 'print sum 0*1\, -12*1' 4294967284 [martyn​:0]$ perl -MList​::Util=sum -le 'print sum @​ARGV' 0 -12 -12 [martyn​:0]$ perl -MList​::Util=sum -le 'print sum -1\, 2' 4294967297

As the last line shows\, only one of the values has to be negative\, not necessarily the result.

It appears to be a signage issue​:

[martyn​:1]$ perl -le 'printf "%x\n"\, $_ for @​ARGV' -- -12 4294967284 fffffff4 fffffff4

Beyond that\, as this is an XS issue\, I cannot delve. :-(

Perl Info ``` Flags: category=utilities severity=medium Site configuration information for perl v5.8.0: Configured by martyn at Thu Jun 5 17:17:35 GMT 2003. Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration: Platform: osname=linux, osvers=2.5.69, archname=i686-linux-thread-multi uname='linux chrome 2.5.69 #5 sat may 31 17:05:40 gmt 2003 i686 amd athlon(tm) xp 1600+ authenticamd gnulinux ' config_args='-Dprefix=/export/home/martyn/opt/perl-5.8.0 -Dusethreades -Duseithreads -des' hint=recommended, useposix=true, d_sigaction=define usethreads=define use5005threads=undef useithreads=define usemultiplicity=define useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O3', cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing' ccversion='', gccversion='3.2.2', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lpthread -lc -lcrypt -lutil perllibs=-lnsl -ldl -lm -lpthread -lc -lcrypt -lutil libc=/lib/libc-2.3.1.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.3.1' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic' cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib' Locally applied patches: @INC for perl v5.8.0: /export/home/martyn/opt/perl-5.8.0/lib/5.8.0/i686-linux-thread-multi /export/home/martyn/opt/perl-5.8.0/lib/5.8.0 /export/home/martyn/opt/perl-5.8.0/lib/site_perl/5.8.0/i686-linux-thread-multi /export/home/martyn/opt/perl-5.8.0/lib/site_perl/5.8.0 /export/home/martyn/opt/perl-5.8.0/lib/site_perl . Environment for perl v5.8.0: HOME=/home/martyn LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH=/opt/blackdown-jdk-1.4.1/lib:/home/martyn/lib:/export/home/martyn/exec/lib:/usr/local/lib LOGDIR (unset) PATH=/opt/blackdown-jdk-1.4.1/bin:/home/martyn/bin:/export/home/martyn/exec/bin:/usr/local/bin:/bin:/usr/bin:/usr/i686-pc-linux-gnu/gcc-bin/3.2:/opt/Acrobat5:/usr/X11R6/bin:/opt/blackdown-jdk-1.4.1/jre/bin:/usr/qt/3/bin:/usr/kde/3.1/bin:/usr/qt/2/bin PERL_BADLANG (unset) SHELL=/bin/bash ```
p5pRT commented 20 years ago

From @gbarr

On 23 Sep 2003\, at 18​:29\, martyn@​chrome.sixears.co.uk (via RT) wrote​:

List​::Util​::sum returns questionable results when negative literals are provided on my Gentoo Linux AMD K6 800MHz box. It does not occur on my 1.6GHz Athlon\, no my Intel P-II Mobile. This occurs with 5.8.0 and 5.8.1-RC4​:

[martyn​:0]$ perl -MList​::Util=sum -le 'print sum -1' 4294967295

That is very odd

What do you get from

perl -MDevel​::Peek -le 'Dump(-1)'

Graham.

p5pRT commented 20 years ago

From @iabyn

On Tue\, Sep 23\, 2003 at 05​:29​:06PM -0000\, martyn@​chrome.sixears.co.uk (via RT) wrote​:

[martyn​:0]$ perl -MList​::Util=sum -le 'print sum -1' 4294967295

Various comments​:

For me\, this doesn't happen in 5.8.0\, but happens in bleed. Change occured between 18020 and 18113.

When debugging\, the problem occurs in Util.xs around this line​:

  RETVAL = slu_sv_value(sv);

At this point\, sv is

  SV = IV(0x818afc0) at 0x8189a2c   REFCNT = 1   FLAGS = (IOK\,READONLY\,pIOK)   IV = -1

slu_sv_value() is defined as​:

define slu_sv_value(sv) (NV)(SvIOK(sv) ? SvIOK_UV(sv) ? SvUVX(sv) : SvIVX(sv) : SvNV(sv))

typeof(IV) is (long int)\, and typeof(RETVAL) is double.

Single-stepping at the machine instruction level shows that the IOK test succeeds and the SvIOK_UV test fails\, yet at the end of the assignment\, RETVAL is 4294967295\, not -1.

So I'm very confused.

-- Technology is dominated by two types of people​: those who understand what they do not manage\, and those who manage what they do not understand.

p5pRT commented 20 years ago

From @andk

On Wed\, 24 Sep 2003 00​:12​:50 +0100\, Dave Mitchell \davem@​fdgroup\.com said​:

  > RETVAL = slu_sv_value(sv);

That was introduced in patch 18076 and blame analysis indeed shows on my Athlon​:

----Program---- use List​::Util qw(sum); print sum -1;

----Output of .../prT8St3/perl-5.8.0@​18075/bin/perl---- -1 ----EOF ($?='0')---- ----Output of .../pfZsvXT/perl-5.8.0@​18076/bin/perl---- 1.84467440737096e+19 ----EOF ($?='0')----

-- andreas

p5pRT commented 20 years ago

From @gbarr

On 24 Sep 2003\, at 9​:33\, Martyn J. Pearce wrote​:

On Tue\, Sep 23\, 2003 at 09​:58​:43PM +0100\, Graham Barr wrote​:

On 23 Sep 2003\, at 18​:29\, martyn@​chrome.sixears.co.uk (via RT) wrote​:

List​::Util​::sum returns questionable results when negative literals are provided on my Gentoo Linux AMD K6 800MHz box. It does not occur on my 1.6GHz Athlon\, no my Intel P-II Mobile. This occurs with 5.8.0 and 5.8.1-RC4​:

I don't have time to test this fully today or do a release\, I have to run in 5 mins. But try this patch. If there are no reported problems then I will release tomorrow\, or maybe late tonight\, when I am back.

Inline Patch ```diff --- Util.xs.orig Wed Sep 24 08:35:19 2003 +++ Util.xs Wed Sep 24 08:34:29 2003 @@ -47,9 +47,9 @@ #endif #ifdef SVf_IVisUV -# define slu_sv_value(sv) (NV)(SvIOK(sv) ? SvIOK_UV(sv) ? SvUVX(sv) : ```

SvIVX(sv) : SvNV(sv)) +# define slu_sv_value(sv) (SvIOK(sv)) ? (SvIOK_UV(sv)) ? (NV)(SvUVX(sv)) : (NV)(SvIVX(sv)) : (SvNV(sv))   #else -# define slu_sv_value(sv) (NV)(SvIOK(sv) ? SvIVX(sv) : SvNV(sv)) +# define slu_sv_value(sv) (SvIOK(sv)) ? (NV)(SvIVX(sv)) : SvNV(sv)   #endif

Graham.

p5pRT commented 20 years ago

From fluffy@sixears.co.uk

On Tue\, Sep 23\, 2003 at 09​:58​:43PM +0100\, Graham Barr wrote​:

On 23 Sep 2003\, at 18​:29\, martyn@​chrome.sixears.co.uk (via RT) wrote​:

List​::Util​::sum returns questionable results when negative literals are provided on my Gentoo Linux AMD K6 800MHz box. It does not occur on my 1.6GHz Athlon\, no my Intel P-II Mobile. This occurs with 5.8.0 and 5.8.1-RC4​:

[martyn​:0]$ perl -MList​::Util=sum -le 'print sum -1' 4294967295

That is very odd

What do you get from

perl -MDevel​::Peek -le 'Dump(-1)'

Apologies for the delay​: I'm on UK time\, and wrote the mail at the end of the day...

[martyn​:0]$ perl -MDevel​::Peek -le 'Dump(-1)']

SV = IV(0x8141c14) at 0x81338cc   REFCNT = 1   FLAGS = (IOK\,READONLY\,pIOK)   IV = -1

HTH\, Mx.

p5pRT commented 20 years ago

From fluffy@sixears.co.uk

On Wed\, Sep 24\, 2003 at 09​:55​:21AM +0100\, Graham Barr wrote​:

I don't have time to test this fully today or do a release\, I have to run in 5 mins. But try this patch. If there are no reported problems then I will release tomorrow\, or maybe late tonight\, when I am back.

Applied against 5.8.1-RC4\, this does the trick. Thank you very much for the quick response.

Mx.

p5pRT commented 20 years ago

From @nwc10

On Wed\, Sep 24\, 2003 at 09​:55​:21AM +0100\, Graham Barr wrote​:

I don't have time to test this fully today or do a release\, I have to run in 5 mins. But try this patch. If there are no reported problems then I will release tomorrow\, or maybe late tonight\, when I am back.

--- Util.xs.orig Wed Sep 24 08​:35​:19 2003 +++ Util.xs Wed Sep 24 08​:34​:29 2003 @​@​ -47\,9 +47\,9 @​@​ #endif

#ifdef SVf_IVisUV -# define slu_sv_value(sv) (NV)(SvIOK(sv) ? SvIOK_UV(sv) ? SvUVX(sv) : SvIVX(sv) : SvNV(sv)) +# define slu_sv_value(sv) (SvIOK(sv)) ? (SvIOK_UV(sv)) ? (NV)(SvUVX(sv)) : (NV)(SvIVX(sv)) : (SvNV(sv)) #else -# define slu_sv_value(sv) (NV)(SvIOK(sv) ? SvIVX(sv) : SvNV(sv)) +# define slu_sv_value(sv) (SvIOK(sv)) ? (NV)(SvIVX(sv)) : SvNV(sv) #endif

What goes wrong with using the direct output of SvNV(sv)? Certainly by 5.8.0 it should give identical results to

(SvIOK(sv)) ? (SvIOK_UV(sv)) ? (NV)(SvUVX(sv)) : (NV)(SvIVX(sv)) : (SvNV(sv))

Nicholas Clark

p5pRT commented 20 years ago

@iabyn - Status changed from 'new' to 'resolved'