How can I check whether my Perl installation is 32 or 64 bit?
Asked Answered
P

6

11

On Windows, how can I check whether my Perl installation is 32 or 64 bit?

Pardoes answered 2/10, 2014 at 20:4 Comment(3)
why do you want to know? as the 2 answers reflect, 32 or 64 bit could mean more than one thing; it's not clear what you are actually asking.Zymometer
Came here looking for answer to the same question. In my case I have binary modules for both archs and need to load right one dynamically.Frisky
Just explanation for log(~0 +1)/log(2): ~0 +1 produces the max int and log(N)/log(2) gets the base-2 log of N. See perldoc perlop and perldoc -f log.Jessy
O
25

If you want to check if it uses 32-bit integers or 64-bit integers, use the following:

perl -V:ivsize      # use Config; say $Config{ivsize}
  • If the returned value is 4, your Perl uses 32-bit integers.
  • If the returned value is 8, your Perl uses 64-bit integers.

See also: Answer to "What is the perl equivalent of MAX_INT?"


If you want to check if it uses 32-bit pointers or 64-bit pointers, use the following:

perl -V:ptrsize     # use Config; say $Config{ptrsize}
  • If the returned value is 4, your Perl can address 4 GiB of RAM.
  • If the returned value is 8, your Perl can address "unlimited" RAM.

If you want to check if it's a 32-bit program or a 64-bit program, use the following:

perl -V:archname    # use Config; say $Config{archname}
  • If the returned value includes x86_64, it's a 64-bit process.
  • If the returned value includes x86 (but not x86_64), it's a 32-bit process.

This value is also included in the output of perl -v.


Note: You shouldn't be checking use64bitint or use64bitall as these indicate what parameters were passed to Configure rather than provide information about what is actually being used.

Olag answered 3/10, 2014 at 3:18 Comment(0)
R
18

I'm reading the question to ask if Perl is compiled 64 bit, not if Windows or the CPU is.

Perl can be configured to use varying degrees of 64 bit-ness. You can look this up using the Config module.

To check if Perl is compiled to use 64 bit integers, you can look at the use64bitint entry in Config.

use Config;
print $Config{use64bitint};

define indicates yes.

There is also...

  • use64bitall meaning perl will be compiled to use all the 64 bit-ness it can, including 64 bit pointers allowing you to access more than 2 gigs of memory.
  • ivsize indicating how many bytes Perl will use to store an integer, 8 indicates 64 bit.
  • ptrsize is how many bits Perl will use to store pointers which allows you to use more than 2 gigs of memory per process, 8 indicates 64 bit.

Common Config variables and their values can be seen in perl -V (note the capital V). Their definitions can be found with perldoc Config.

Note, you can compile Perl to use 64 bit integers regardless of whether your operating system or CPU is 32 or 64 bit. On a 32 bit CPU, Perl will use a type other than "integer" to store numbers, probably "long integer".

Roselba answered 2/10, 2014 at 20:13 Comment(0)
M
3

log(~0 +1)/log(2) works because :

  • ~0 is "bitwise not zero" -> UINT_MAX
  • UINT_MAX is either 2^32-1 or 2^64-1, depending on the architecture (or compile options)
  • log(2^32)/log(2) = 32 and log(2^64)/log(2) = 64, by design.

So basically this command order perl to say how many bits have its UINT_MAX.

$ perl -e "print log(~0 +1)/log(2)" 32 $ perl -V:archname archname='MSWin32-x86-multi-thread';

Mandelbaum answered 19/3, 2018 at 16:57 Comment(0)
I
1

Just check the version/build:

perl -v

And I got:

This is perl, v5.8.8 built for msys-64int

Copyright 1987-2006, Larry Wall

...
Indignation answered 2/10, 2014 at 20:6 Comment(1)
The 64int in perl -v's output does NOT indicate a 64-bit program. While perl -v would normally tell you if it's a 32-bit or 64-bit process (by including x86 or x86_64), you showed that it doesn't work (it doesn't tell you either way) for msys.Olag
F
0

Please consider the less computationally expensive:

$is32bit = ~0==0xFFFFFFFF ? 1:0;
Fortuitous answered 4/2 at 20:50 Comment(1)
Thank you for your interest in contributing to the Stack Overflow community. This question already has a few answers—including a couple that have been validated by the community. Are you certain your approach hasn’t been given previously? If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient. Can you kindly edit your answer to offer an explanation?Paraclete
S
-4

Just use

log(~0 +1)/log(2) 

....

Slade answered 4/1, 2015 at 7:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.