ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6086
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: RPI4: Why is everything still 32-bit?

Mon Sep 23, 2019 8:29 pm

dickon wrote: IIRC, the point of Raspbian was to recompile debian/armhf with an armv7 target, because vanilla Debian is only armv6
Almost. Debian had armel (armv6 soft-float) and armhf (armv7 hard-float). Raspbian is an armv6 hard-float rebuild to get the most out of the original pi 1 (which was armv6).
dickon wrote: Personally, I expect a 64b 'Raspbian' to be more or less a vanilla debian/aarch64 with an additional repo for a Pi-specific desktop and Pi-specific packages (like omxplayer).
That would be my vote, but there are a few different approaches being discussed.

dickon
Posts: 571
Joined: Sun Dec 09, 2012 3:54 pm
Location: Home, just outside Reading

Re: RPI4: Why is everything still 32-bit?

Mon Sep 23, 2019 8:41 pm

ShiftPlusOne wrote:
Mon Sep 23, 2019 8:29 pm
dickon wrote: IIRC, the point of Raspbian was to recompile debian/armhf with an armv7 target, because vanilla Debian is only armv6
Almost. Debian had armel (armv6 soft-float) and armhf (armv7 hard-float). Raspbian is an armv6 hard-float rebuild to get the most out of the original pi 1 (which was armv6).
It's been such very long time since I've needed to worry about this that clearly I've forgotten the details :-)
dickon wrote: Personally, I expect a 64b 'Raspbian' to be more or less a vanilla debian/aarch64 with an additional repo for a Pi-specific desktop and Pi-specific packages (like omxplayer).
That would be my vote, but there are a few different approaches being discussed.
It's the logical way of doing it if you ask me. I appreciate there may be some very good reasons not to, however. My point was that it was a recompile (and now minor fork) of a very popular project, and the recompile aspect of that goes away with the move to 64b. It'll be interesting, no matter what.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6086
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: RPI4: Why is everything still 32-bit?

Mon Sep 23, 2019 8:55 pm

dickon wrote: My point was that it was a recompile (and now minor fork) of a very popular project, and the recompile aspect of that goes away with the move to 64b. It'll be interesting, no matter what.
Sounds about right. From my (guy who does packaging) point of view, the annoying bits of that approach will be that a lot of packages were written with the assumption that they'll only run on armhf. So flags the rules/makefile may pass the same set of flags for all targets when it should actually have different sets based on what we're building for. Some packages have hand-written assembly which will need to be re-written.

Getting all of that sorted would involve checking each package with arch-dependant debs, rebuilding and testing. Most will just work, some (like chromium) would be trickier.

sal55
Posts: 63
Joined: Sat Sep 21, 2019 7:15 pm

Re: RPI4: Why is everything still 32-bit?

Mon Sep 23, 2019 9:07 pm

hippy wrote:
Mon Sep 23, 2019 8:11 pm
Whether 32-bit or 64-bit a simple looping "n = n + 1" compiles to something like -

Code: Select all

      ld  r0, #n
Loop: ld  r1, @r0
      add r1, #1
      st  r1, @r0
      b   Loop
So ignoring differences in clock speeds, that 32-bit overflows sooner than 64-bit, that pointers are bigger; where exactly is the gain in being "64-bit" over "32-bit" ?
This is the code generated by gcc-O0 on RPI1 when n is 32 bits (loop removed):

Code: Select all

    ldr r3, [fp, #-8]
    add r3, r3, #1
    str r3, [fp,#-8]
And this is it when n is 64 bits:

Code: Select all

    ldrd r2, [fp, #-12]
    adds r2, r2, #1
    adc r3, #0
    strd r2, [fp, #-12]
(ldrd/strd load or store 2 registers.) It uses 2 registers rather than 1 above. It uses 4 instructions rather than 3. Optimisation will mitigate some differences, but it does put extra pressure on registers, code density, cache and execution time (and possibly power consumption). The 64-bit code for ARM64 (this from gcc on Gentoo on RPi4) is:

Code: Select all

    ldr x0, [sp,8]
    add x0, x0, 1
    std x0, [sp, 8]
It again uses 1 register and 3 instructions just like the 32-bit version; you get the advantages of 64 bits - much bigger range and less likely overflows - with no extra cost! (Well, 'n' takes 8 bytes rather than 4, but in my example n was on the stack frame).

If you don't think you will ever need 64 bits for anything (other than arbitrary precision libraries, cryptography etc) then compare this when 'kwd' is an integer containing packed ASCII:

Code: Select all

    if kwd = 'proc'       # 32 bits: up to 4 characters in one int
    if kwd = 'function'   # 64 bits: up to 8 characters in one int
So where does the gain in being "64-bit" over "32-bit" actually come from ?
If you only ever use 32-bit operations, and none of your code includes 32-bit ops trying to do a 64-bit job so could be revised, then probably you will see no difference. Or it may even be slower because wider pointers take more bandwidth.

The advantage is the luxury of being able to use a wider numeric type, one that can count beyond 2**32 (large file sizes, large array/string sizes, bitarrays above 256MB which need 33+ bits to index, and a wider pointer type that can deal with total memory (including virtual memory) beyond 4GB.
Last edited by sal55 on Mon Sep 23, 2019 10:53 pm, edited 1 time in total.

dickon
Posts: 571
Joined: Sun Dec 09, 2012 3:54 pm
Location: Home, just outside Reading

Re: RPI4: Why is everything still 32-bit?

Mon Sep 23, 2019 9:21 pm

sal55 wrote:
Mon Sep 23, 2019 9:07 pm

Code: Select all

    if kwd = 'proc'       # 32 bits: up to 4 characters in one int
    if kwd = 'function'   # 64 bits: up to 8 characters in one int
Please don't do that in C. It isn't portable. Byte sex is still a thing.

hippy
Posts: 6299
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: RPI4: Why is everything still 32-bit?

Mon Sep 23, 2019 9:53 pm

sal55 wrote:
Mon Sep 23, 2019 9:07 pm
The advantage is the luxury of being able to use a wider numeric type, one that can count beyond 2**32 (large file sizes, large array/string sizes, bitarrays above 256MB which need 33+ bits to index, and a wider pointer type that can deal with total memory (including virtual memory) beyond 4GB.
That was my thinking; an advantage, but not one which most people would need, not most Pi users anyway. Where people do occasionally do such things, it's only a minor part of what they are doing, that any overhead from concatenated bytes to make up the requisite size variable is mostly an irrelevancy.

Of course there are things like cryptography which 'everyone's code', an OS or apps they commonly use, may rely on which would benefit, and then give an overall improvement but that's hard to quantify.

sal55
Posts: 63
Joined: Sat Sep 21, 2019 7:15 pm

Re: RPI4: Why is everything still 32-bit?

Mon Sep 23, 2019 10:02 pm

dickon wrote:
Mon Sep 23, 2019 9:21 pm
sal55 wrote:
Mon Sep 23, 2019 9:07 pm

Code: Select all

    if kwd = 'proc'       # 32 bits: up to 4 characters in one int
    if kwd = 'function'   # 64 bits: up to 8 characters in one int
Please don't do that in C. It isn't portable. Byte sex is still a thing.
This isn't C. And is intended for internal use, although it can be made portable by stipulating the ordering of the characters. (Better not mention that my language allows such constants up to 128 bits or 16 characters...)

dickon
Posts: 571
Joined: Sun Dec 09, 2012 3:54 pm
Location: Home, just outside Reading

Re: RPI4: Why is everything still 32-bit?

Mon Sep 23, 2019 10:05 pm

sal55 wrote:
Mon Sep 23, 2019 10:02 pm
dickon wrote:
Mon Sep 23, 2019 9:21 pm
sal55 wrote:
Mon Sep 23, 2019 9:07 pm

Code: Select all

    if kwd = 'proc'       # 32 bits: up to 4 characters in one int
    if kwd = 'function'   # 64 bits: up to 8 characters in one int
Please don't do that in C. It isn't portable. Byte sex is still a thing.
This isn't C. And is intended for internal use, although it can be made portable by stipulating the ordering of the characters. (Better not mention that my language allows such constants up to 128 bits or 16 characters...)
I know. But you're encoraging it.

User avatar
Fidelius
Posts: 460
Joined: Wed Jan 01, 2014 8:40 pm
Location: Germany

Re: RPI4: Why is everything still 32-bit?

Tue Sep 24, 2019 9:14 am

I'm running a standard Raspbian on a Pi4 and it works so well already in 32bit.

I've used and still use the older Pis (Pi1, Pi2, Pi3) but clearly the Pi4 is the best of them: not only because it's the most powerful Pi model but also because Debian based Raspbian 10 is so mature and works so well with the new Pi4 hardware, that basically I encounter no issues what-so-ever anymore on the Pi4. It just runs and runs like I'm used to on the "big" Linux machines, and we use our Pi4 as a full desktop machine by the way. (With 4 GB – it's my one and only treat…)

Really great work here on the hardware and software side! (I'm saying this as a Pi user and as a veteran software developer – in particular after looking at the bad posts of some poster here in the thread.)


So where's the connection to the thread's name? Here: With immense interest I read the other thread about an up-coming 64bit kernel for the 64bit Pi machines. So in the near future our good "old" Pis will run faster "just" by upgrading "some software" (kernel). With Linux such chances come true.

And then in the future we will even get a full 64bit Raspbian, which will make things faster again. (On my Amd/Intel machines, upgrading a 32bit Ubuntu to 64bit Ubuntu increased performance by 20-30% for many developer tasks, but not for all of course).

So, why do we Pi users not just lean back, enjoy a great Pi4 with a great 32bit Raspbian OS, and look forward to the 64bit kernel, and then looking forward to a full 64bit system? It only takes justified patience and then, when the time is ripe, it takes us some key presses on the software side. A lookout which delights.

And to all you Pi hardware and software developers out there: A heartfelt thanks from my entire family, and please keep up your good 32bit and 64bit work!

sal55
Posts: 63
Joined: Sat Sep 21, 2019 7:15 pm

Re: RPI4: Why is everything still 32-bit?

Tue Sep 24, 2019 11:00 am

dickon wrote:
Mon Sep 23, 2019 10:05 pm
sal55 wrote:
Mon Sep 23, 2019 10:02 pm
This isn't C.
I know. But you're encoraging it.
I'm sorry but C is 't the only language out there, even though it is highly dominant (mainly by being around for so long, and being such an integral part of Unix). IMO it is a mess. Other languages which do things in different and better and more useful ways should be encouraged.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 24195
Joined: Sat Jul 30, 2011 7:41 pm

Re: RPI4: Why is everything still 32-bit?

Tue Sep 24, 2019 11:19 am

sal55 wrote:
Tue Sep 24, 2019 11:00 am
dickon wrote:
Mon Sep 23, 2019 10:05 pm
sal55 wrote:
Mon Sep 23, 2019 10:02 pm
This isn't C.
I know. But you're encoraging it.
I'm sorry but C is 't the only language out there, even though it is highly dominant (mainly by being around for so long, and being such an integral part of Unix). IMO it is a mess. Other languages which do things in different and better and more useful ways should be encouraged.
I'd not say it was a mess. It's just a language, which is used to implement the entire Linux kernel, very successfully. And it's still around because it works, it's fast, and of course there is a lot of legacy code.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

Heater
Posts: 13938
Joined: Tue Jul 17, 2012 3:02 pm

Re: RPI4: Why is everything still 32-bit?

Tue Sep 24, 2019 1:22 pm

sal55,
Other languages which do things in different and better and more useful ways should be encouraged.
Quite so, we have a huge number of programming languages to choose from now a days. Too many for anyone to get familiar with. Other languages are indeed discussed and encourage here:

https://www.raspberrypi.org/forums/viewforum.php?f=14

And we often discuss, contrast and comapare languages available for the Pi here:
https://www.raspberrypi.org/forums/view ... 0b9c7ed289

For example in a recent very long discussion we looked at all these, and more:
https://www.raspberrypi.org/forums/view ... 5#p1517879

If you have a new language then perhaps you would like to take part in that discussion and present example code for the recent anagram finding problem.

C is a work of art. It meets it's design aims admirably. It is perhaps the minimal high level language required to implement Unix in a hardware independent way. To this day few languages can be used to do what you can do with C, perhaps Pascal, Ada, and Rust. It's debatable if they can do it better.

Of course squeezing multiple chars into 32 bits and then referring to them as an integer would be a messy thing to do in any language. We have type systems for a reason. Of course strings now a days are not ASCII but Unicode so that is all moot.
Memory in C++ is a leaky abstraction .

W. H. Heydt
Posts: 11118
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: RPI4: Why is everything still 32-bit?

Tue Sep 24, 2019 1:51 pm

sal55 wrote:
Tue Sep 24, 2019 11:00 am
I'm sorry but C is 't the only language out there, even though it is highly dominant (mainly by being around for so long, and being such an integral part of Unix). IMO it is a mess. Other languages which do things in different and better and more useful ways should be encouraged.
If the age of the language were the controlling factor, the touchstone for code structure would be FORTRAN, with a dash of COBOL.

sal55
Posts: 63
Joined: Sat Sep 21, 2019 7:15 pm

Re: RPI4: Why is everything still 32-bit?

Tue Sep 24, 2019 2:16 pm

Heater wrote:
Tue Sep 24, 2019 1:22 pm
If you have a new language then perhaps you would like to take part in that discussion and present example code for the recent anagram finding problem.
Thanks for those links, look like interesting threads to read through!
C is a work of art. It meets it's design aims admirably. It is perhaps the minimal high level language required to implement Unix in a hardware independent way. To this day few languages can be used to do what you can do with C, perhaps Pascal, Ada, and Rust. It's debatable if they can do it better.
My own systems language started life in 1981 (for a home-made 8-bit Z80 system), with a syntax modelled on Algol68. I didn't meet C until a dozen years later, but decided I didn't like it.

I've expounded on this at length in other forums, so let's say here that C is perverse, especially in its type system.

(For example, 'char* is incompatible with both 'unsigned char*' and 'signed char*' even though it must be one or the other! 'int32_t' may or may not be compatiable with 'int', and may or may not be compatible with 'long', but 'long' is always incompaible with 'int' even if they are the same size! You become very familiar with this when trying to use C libraries from your own language (and most important libraries seem to use C APIs.))
Of course squeezing multiple chars into 32 bits and then referring to them as an integer would be a messy thing to do in any language. We have type systems for a reason. Of course strings now a days are not ASCII but Unicode so that is all moot.
While this is about being able to efficiently compare short strings, it is just another way to write integer constants. You can do 0x4241 or 16961 for the bit-pattern 100'0010'0100'0001, so why not 'AB'?

(When the language makes 'A' the least significant as is common for strings. But also because, if you were to index the bytes in an int X (as my language allows), then X[0] corresponds to 'A', and X[1] to 'B', as you would expect, independently of h/w byte order.)

Sorry, this has drifted a long way off-topic!
Last edited by sal55 on Tue Sep 24, 2019 2:17 pm, edited 1 time in total.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 24195
Joined: Sat Jul 30, 2011 7:41 pm

Re: RPI4: Why is everything still 32-bit?

Tue Sep 24, 2019 2:16 pm

Keep on topic please.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

Heater
Posts: 13938
Joined: Tue Jul 17, 2012 3:02 pm

Re: RPI4: Why is everything still 32-bit?

Tue Sep 24, 2019 2:48 pm

C as a lot of "gotchas". Oddly none of the ones you pointed out are among the ones I would have listed first. I'm not even sure they would be on my list!

We love to chew on programming language features and design decisions but let's do so in those other threads. Or new ones I guess.
Memory in C++ is a leaky abstraction .

User avatar
PeterO
Posts: 5164
Joined: Sun Jul 22, 2012 4:14 pm

Re: RPI4: Why is everything still 32-bit?

Tue Sep 24, 2019 3:07 pm

W. H. Heydt wrote:
Tue Sep 24, 2019 1:51 pm
sal55 wrote:
Tue Sep 24, 2019 11:00 am
I'm sorry but C is 't the only language out there, even though it is highly dominant (mainly by being around for so long, and being such an integral part of Unix). IMO it is a mess. Other languages which do things in different and better and more useful ways should be encouraged.
If the age of the language were the controlling factor, the touchstone for code structure would be FORTRAN, with a dash of COBOL.
And a portion of ALGOL on the side :-)
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

pica200
Posts: 153
Joined: Tue Aug 06, 2019 10:27 am

Re: RPI4: Why is everything still 32-bit?

Tue Sep 24, 2019 3:45 pm

C is here to stay. Barely any of the other languages matches its performance and simplicity and at the same time it's very close to the metal. The type system of C is in fact pretty weak compared to many of the more modern languages and nothing stops you from type casting. The primitive types are indeed confusing which is why stdint.h exists.

My 2 cents for the language war above.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 24195
Joined: Sat Jul 30, 2011 7:41 pm

Re: RPI4: Why is everything still 32-bit?

Tue Sep 24, 2019 4:16 pm

Did everyone miss the "Please keep on topic" post above? Will soon start deleting, so you've got to ask yourself one question. Do I feel lucky? Well, do ya, punk?
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

ejolson
Posts: 3839
Joined: Tue Mar 18, 2014 11:47 am

Re: RPI4: Why is everything still 32-bit?

Tue Sep 24, 2019 4:28 pm

sal55 wrote:
Sat Sep 21, 2019 7:30 pm
I just bought a 64-bit RPI4 to supercede my RPI1 from 2012 or so. I wanted to port my 64-bit language tools to it.
Back to the original topic of porting 64-bit language tools to the Pi.

It seems reasonable to me to run 32-bit Raspbian with the 64-bit kernel and set up a chroot environment with 64-bit Debian userland as already suggested. After this, it may be possible to package your tools to include the necessary 64-bit libraries needed to run directly on Raspbian without the chroot. This would lead to a fully 64-bit version of your programming tools that easily run on Raspbian with only a simple kernel change.

The advantage in doing this is that you would be the first; however, that would also be the disadvantage.

sal55
Posts: 63
Joined: Sat Sep 21, 2019 7:15 pm

Re: RPI4: Why is everything still 32-bit?

Tue Sep 24, 2019 7:05 pm

ejolson wrote:
Tue Sep 24, 2019 4:28 pm
It seems reasonable to me to run 32-bit Raspbian with the 64-bit kernel and set up a chroot environment with 64-bit Debian userland as already suggested. After this, it may be possible to package your tools to include the necessary 64-bit libraries needed to run directly on Raspbian without the chroot. This would lead to a fully 64-bit version of your programming tools that easily run on Raspbian with only a simple kernel change.

The advantage in doing this is that you would be the first; however, that would also be the disadvantage.
The trouble is I know next to nothing about Linux, except the absolute basics. I also stay clear of most of the cumbersome, baggage-laden toolchains (makefile, autoconf etc). So I need a ready-to-use 64-bit C compiler to build the output of my programs, and the ability to run the results. (Part of what I do is to do produce the simplest possible self-contained tools.)

Enough works at the moment with the 64-bit Gentoo on RPi4 to run its 64-bit gcc to do some testing (with most work done on the PC, or on a VirtualBox Linux, but eventually I want to do actual development on the Pi).

The benchmark I posted yesterday suggested that the same program ran 50% faster compiled for 64-bit RPi4, compared with 32-bit RPi4. (These are programs based around a 64-bit integer type.)

I've just done another test program (a C compiler as it happens), which also ran 50% faster on 64-bit RPi4 (175Klps compared with 110Klps, for C to asm).

That is a similar speed-up to what I noticed 15-20 years ago when switching from a 16-bit compiler to full 32-bit, using x86.

jcyr
Posts: 505
Joined: Sun Apr 23, 2017 1:31 pm
Location: Atlanta

Re: RPI4: Why is everything still 32-bit?

Tue Sep 24, 2019 7:20 pm

sal55 wrote:
Tue Sep 24, 2019 7:05 pm
The benchmark I posted yesterday suggested that the same program ran 50% faster compiled for 64-bit RPi4, compared with 32-bit RPi4. (These are programs based around a 64-bit integer type.)

I've just done another test program (a C compiler as it happens), which also ran 50% faster on 64-bit RPi4 (175Klps compared with 110Klps, for C to asm).

That is a similar speed-up to what I noticed 15-20 years ago when switching from a 16-bit compiler to full 32-bit, using x86.
It is hardly surprising that the armv6 binaries imposed by the RPF's one size fits all objective are less performant that something compiled for and running in native armv8. After all, wasn't that the whole point of armv8?
It's um...uh...well it's kinda like...and it's got a bit of...

User avatar
RaTTuS
Posts: 10506
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: RPI4: Why is everything still 32-bit?

Tue Sep 24, 2019 7:37 pm

How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

ejolson
Posts: 3839
Joined: Tue Mar 18, 2014 11:47 am

Re: RPI4: Why is everything still 32-bit?

Tue Sep 24, 2019 7:57 pm

RaTTuS wrote:
Tue Sep 24, 2019 7:37 pm
why has no-one posted https://www.raspberrypi.org/forums/view ... p?t=250730 yet ?
Somewhere that thread was mentioned in this thread. That 64-bit kernel is good, but you also need a 64-bit user land to do any software development of 64-bit programs. The proposed solution is to use a Debian 64-bit chroot environment for software development and then statically link or include the necessary libraries when deploying the resulting project directly on Raspbian.

Note that the language tools mentioned in the original post apparently use a C compiler as the backend code generator. Thus, it is probably best to retain the chroot for use when compiling and work only on getting the final 64-bit binaries produced by those custom language tools to run directly on Raspbian.
Last edited by ejolson on Tue Sep 24, 2019 9:33 pm, edited 4 times in total.

jcyr
Posts: 505
Joined: Sun Apr 23, 2017 1:31 pm
Location: Atlanta

Re: RPI4: Why is everything still 32-bit?

Tue Sep 24, 2019 7:59 pm

RaTTuS wrote:
Tue Sep 24, 2019 7:37 pm
why has no-one posted https://www.raspberrypi.org/forums/view ... p?t=250730 yet ?
Waiting for a formal/official release.
It's um...uh...well it's kinda like...and it's got a bit of...

Return to “General discussion”