Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bit shift broken at 32 bits #6231

Closed
p6rt opened this issue May 9, 2017 · 6 comments
Closed

bit shift broken at 32 bits #6231

p6rt opened this issue May 9, 2017 · 6 comments
Labels

Comments

@p6rt
Copy link

p6rt commented May 9, 2017

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

Searchable as RT131278$

@p6rt
Copy link
Author

p6rt commented May 9, 2017

From curt@tilmes.org

<curt_> m​: my $i = -0x8000000000000000; say ($i div 2**12) == ($i +> 12) ??
'good' !! 'bad';
<camelia> rakudo-moar 6bb1b5​: OUTPUT​: «good␤»
<curt_> m​: my $i = -0x8000000000000000; say ($i div 2**37) == ($i +> 37) ??
'good' !! 'bad';
<camelia> rakudo-moar 6bb1b5​: OUTPUT​: «bad␤»
<curt_> m​: my $i = -0x8000000000000000; say ($i div 2**23) == ($i +> 23) ??
'good' !! 'bad';
<camelia> rakudo-moar 6bb1b5​: OUTPUT​: «good␤»
<curt_> m​: my $i = -0x8000000000000000; say ($i div 2**42) == ($i +> 42) ??
'good' !! 'bad';
<camelia> rakudo-moar 6bb1b5​: OUTPUT​: «bad␤»
<TimToady> loks like a bug
<TimToady> at the 32-bit boundary
<TimToady> m​: my $i = -0x8000000000000000; say ($i +> 31)
<camelia> rakudo-moar 6bb1b5​: OUTPUT​: «-4294967296␤»
<TimToady> m​: my $i = -0x8000000000000000; say ($i +> 32)
<camelia> rakudo-moar 6bb1b5​: OUTPUT​: «-1␤»
<TimToady> please report bug

@p6rt
Copy link
Author

p6rt commented May 10, 2017

From @zoffixznet

On Tue, 09 May 2017 09​:49​:37 -0700, curt@​tilmes.org wrote​:

<curt_> m​: my $i = -0x8000000000000000; say ($i div 2**12) == ($i +> 12) ??
'good' !! 'bad';
<camelia> rakudo-moar 6bb1b5​: OUTPUT​: «good␤»
<curt_> m​: my $i = -0x8000000000000000; say ($i div 2**37) == ($i +> 37) ??
'good' !! 'bad';
<camelia> rakudo-moar 6bb1b5​: OUTPUT​: «bad␤»
<curt_> m​: my $i = -0x8000000000000000; say ($i div 2**23) == ($i +> 23) ??
'good' !! 'bad';
<camelia> rakudo-moar 6bb1b5​: OUTPUT​: «good␤»
<curt_> m​: my $i = -0x8000000000000000; say ($i div 2**42) == ($i +> 42) ??
'good' !! 'bad';
<camelia> rakudo-moar 6bb1b5​: OUTPUT​: «bad␤»
<TimToady> loks like a bug
<TimToady> at the 32-bit boundary
<TimToady> m​: my $i = -0x8000000000000000; say ($i +> 31)
<camelia> rakudo-moar 6bb1b5​: OUTPUT​: «-4294967296␤»
<TimToady> m​: my $i = -0x8000000000000000; say ($i +> 32)
<camelia> rakudo-moar 6bb1b5​: OUTPUT​: «-1␤»
<TimToady> please report bug

Looking at the source code, this behaviour is due to a kludge to fix RT#​126942[^1],
according to which long bit shifts of negative integers should always produce -1

I'm not sure where the value of 32 bits came into play, other than it's the value
where RT#​126942's bug came around.

[1] https://rt-archive.perl.org/perl6/Ticket/Display.html?id=126942
[2] https://github.com/rakudo/rakudo/blob/6435933/src/core/Int.pm#L412

@p6rt
Copy link
Author

p6rt commented May 10, 2017

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented May 10, 2017

From @zoffixznet

Found where the problem was. Sent a PR[^1] to MoarVM to fix it and will commit Rakudo's patch and tests once that's merged.

[1] MoarVM/MoarVM#593

@p6rt
Copy link
Author

p6rt commented May 10, 2017

From @zoffixznet

Thanks for the report. This is now fixed.

Fix​:
  MoarVM/MoarVM@362277b79f
  Raku/nqp@9763728215
  rakudo/rakudo@66e8e72c02
  rakudo/rakudo@ef29bb9f41

Tests​:
  Raku/roast@02d1f9d0f6
  rakudo/rakudo@6409ee582e

@p6rt
Copy link
Author

p6rt commented May 10, 2017

@zoffixznet - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed May 10, 2017
@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant