C-Backend

Everything else that doesn't fall into one of the other PB categories.
loulou2522
Enthusiast
Enthusiast
Posts: 495
Joined: Tue Oct 14, 2014 12:09 pm

C-Backend

Post by loulou2522 »

Hi all,
It would be verypleased if someone can explain what is C-Backend ant the utility For purebasic.
THanks
User_Russian
Addict
Addict
Posts: 1443
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: C-Backend

Post by User_Russian »

Simply put it is a translator in the C language. https://www.purebasic.fr/blog/?p=480
Prior to version 6.00, a translator in the assembler language was used.
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: C-Backend

Post by BarryG »

A new way for your code to be compiled, using superior-performance code. See here -> https://www.purebasic.fr/blog/

As you'll see there, just using the C backend compiler (in Compiler Options) for the graphics test app increased its speed by 50%, without the developer changing a single line in his code. It's fantastic!

Others will explain it better than I, but that's a major improvement in itself.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: C-Backend

Post by davido »

@BarryG,
Thanks for the explanation.
DE AA EB
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: C-Backend

Post by infratec »

In PB the 'backend' is the part which translates the PB code to the language of the used tool to generate machine code.
Up to PB 5.73 the tool to generate the machine code is the fasm compiler. So the backend translates the PB code to fasm assembler.
A (f)asm-backend.

From PB 6.0 onwards it is possible to use a C-backend (at the moment a gcc-backend).
It tranlates the PB code to c code for the gcc compiler.

There are several advantages:

Since C is a highlevel language, the c compiler can optimize the generated machine code.
And since gcc is very 'old' and has a very large community, the optimizations are very good.
Fred does not need to do the optimze stuff by himself, like in the asm backend.

The used gcc is available on many architectures, not only x86 or x64.
So it is possible to use PB on a raspberry pi with linux as OS. The cpu is an arm derivate.
But it doesn't matter, since gcc does this part.

But there is also a (small) price to pay:
The generated machine code (executable) can get larger.
The compilation time is longer, since gcc is not a one parse compiler.
It needs more loops over the c code to generate the best optimized machine code.

Summary:
Fred has less work to maintenance the optimizations and don't need to take care of the underlaying CPU type,
as long as the OS is supported by PB.
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: C-Backend

Post by fsw »

infratec wrote: Mon Sep 27, 2021 9:14 pm The used gcc is available on many architectures, not only x86 or x64.
So it is possible to use PB on a raspberry pi with linux as OS. The cpu is an arm derivate.
Looking forward to compile my [in PB written] apps natively to a Apple M1 CPU :)

I am to provide the public with beneficial shocks.
Alfred Hitshock
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: C-Backend

Post by Fred »

My Mac Mini M1 should get home today :)
User avatar
useful
Enthusiast
Enthusiast
Posts: 367
Joined: Fri Jul 19, 2013 7:36 am

Re: C-Backend

Post by useful »

Fred wrote: Fri Oct 01, 2021 1:41 pm My Mac Mini M1 should get home today :)
I.e. the linux version, including the ARM version, will not be waiting in the near future? All the attention will be devoted to MAC?
Dawn will come inevitably.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: C-Backend

Post by infratec »

Apples M1 is ARM based :wink:

But if you read and understand the stuff above you should know now that the CPU doesn't matter as long there is gcc available for it
and the OS is an already supported one.
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: C-Backend

Post by fsw »

Fred wrote: Fri Oct 01, 2021 1:41 pm My Mac Mini M1 should get home today :)
Awesome 😎

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
minimy
Enthusiast
Enthusiast
Posts: 344
Joined: Mon Jul 08, 2013 8:43 pm

Re: C-Backend

Post by minimy »

Hello, i understand what PB can write code for ARM?
¿Can write app for android?
Sorry my ignorance..

Greetings and thanks for the great tool PB!!
If translation=Error: reply="Sorry, Im Spanish": Endif
User avatar
jacdelad
Addict
Addict
Posts: 1432
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: C-Backend

Post by jacdelad »

No(t yet). Maybe in the future, but that's not priority. And there's more to do than just switch the compiler.
I would pay an extra 80 bucks for PureBasic for Android. Like, the compiler as an extra, would be cool.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: C-Backend

Post by Caronte3D »

jacdelad wrote: Tue Oct 12, 2021 1:24 pm I would pay an extra 80 bucks for PureBasic for Android. Like, the compiler as an extra, would be cool.
Me too! :wink:
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: C-Backend

Post by Tenaja »

Caronte3D wrote: Tue Oct 12, 2021 5:58 pm
jacdelad wrote: Tue Oct 12, 2021 1:24 pm I would pay an extra 80 bucks for PureBasic for Android. Like, the compiler as an extra, would be cool.
Me too! :wink:
Ditto!
User avatar
the.weavster
Addict
Addict
Posts: 1537
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: C-Backend

Post by the.weavster »

jacdelad wrote: Tue Oct 12, 2021 1:24 pmI would pay an extra 80 bucks for PureBasic for Android. Like, the compiler as an extra, would be cool.
+1
Post Reply