Project

General

Profile

Actions

Feature #14378

open

Increase Fixnum range on Windows from 31 bits to 63 bits

Added by HfCloud (Xiangyu Shi) almost 7 years ago. Updated over 3 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:84940]
Tags:

Description

On windows, start an IRB of a 64-bits ruby, enter these code:

(1<<29).equal?(1<<29) 
#=>true

(1<<30).equal?(1<<30)
#=>false

So, it is that FIXNUM of the 64-bits ruby is a 32-bits data?
But my friend try these code on linux platform and all got true(it means FIXNUM is 64bits)
Then I opened ruby/ruby.h and found this:

#define RUBY_FIXNUM_MAX (LONG_MAX>>1)

The LONG_MAX of my compiler(msvc140, vs2017) is 2147483647, and the ruby which is installed by ruby-installer also have the same problem.

Actions #1

Updated by HfCloud (Xiangyu Shi) almost 7 years ago

  • Description updated (diff)
Actions #2

Updated by HfCloud (Xiangyu Shi) almost 7 years ago

  • Description updated (diff)

Updated by nobu (Nobuyoshi Nakada) almost 7 years ago

  • Description updated (diff)

HfCloud (Xiangyu Shi) wrote:

So, it is that FIXNUM of the 64-bits ruby is a 32-bits data?

Yes, we are using long for fixnums, and Windows is the so-called IL32LLP64 platform.
To "fix" this, or relax this limitation, we have to replace tons of long in the source code.

Updated by HfCloud (Xiangyu Shi) almost 7 years ago

I'm using vs2017 and embed ruby interpreter in my game engine. In certain situation I need to use Fixnum to pass values of pointers(64-bits pointers). So ruby will use big integer to pass the pointer's values, what may cause unsatisfying performance on runtime speed.

Updated by HfCloud (Xiangyu Shi) almost 7 years ago

nobu (Nobuyoshi Nakada) wrote:

To "fix" this, or relax this limitation, we have to replace tons of long in the source code.

Oh...I tried just now. The codes uses so large amount of '#define' to alias types' names, it makes the work more difficult.....
what I only want to say is 'why didn't use typedef?...' I found that Matz once said 'IL32LLP64 platform is not hackneyed' :(

Updated by Eregon (Benoit Daloze) almost 7 years ago

This is indeed very surprising that on a platform with 64-bit pointers, Fixnum are still only 30 bits.
+1 to making this more intuitive.
It creates a lot of weird edge cases in ruby/spec.

There are also places in the code where VALUE is used as a synonym of unsigned long (e.g.: rb_uint2inum(VALUE)) but those should just be replaced by "unsigned long".

Updated by spatulasnout (B Kelly) almost 7 years ago

wrote:

what I only want to say is 'why didn't use typedef?...'

In the 1980s, when the 'int' type was fluctuating between 16 bits and
32 bits, we learned to NEVER trust naked C types.

This defensive tactic may have been lost during the 90's and early 2000's
while 32-bit platforms had a lengthy run.

(Interesting to see the old problem re-emerge finally, 30 years later.)

Regards,

Bill

Updated by spatulasnout (B Kelly) almost 7 years ago

a mere data point:

(cygwin-64 ruby includes the full 64-bit Fixnum)

>> RUBY_VERSION
=> "2.2.5"
>> `uname -om`
=> "x86_64 Cygwin\n"
>> (1<<61).class
=> Fixnum
>> (1<<62).class
=> Bignum

Updated by jeremyevans0 (Jeremy Evans) over 3 years ago

  • Tracker changed from Bug to Feature
  • Subject changed from On windows, RUBY_FIXNUM_MAX of 64 bits ruby is 32 bits to Increase Fixnum range on Windows from 31 bits to 63 bits
  • ruby -v deleted (2.5.0)
  • Backport deleted (2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN)

This issue is still present in the master branch. However, the range of T_FIXNUM is an implementation detail, especially since Integer unification in Ruby 2.4, so I do not think this is a bug. I think we wouldn't be opposed to increasing the range of Fixnum on 64-bit Windows, but I consider that a feature request.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0