[Freebasic 32 vs 64]

General FreeBASIC programming questions.
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

[Freebasic 32 vs 64]

Post by Coolman »

Freebasic 32 bit generates code asm ...

Freebasic 64 bit generates code C ...

I did not know it. I only recently installed 64-bit freebasic ...

it is obvious that the assembler is and has always been faster than the C. which explains that 32 bit programs are much faster than 64 bit ...

for information.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: [Freebasic 32 vs 64]

Post by MrSwiss »

This is only partly correct (insufficient information):

FBC 32 can also output C code (which requires GCC 32 bit installation).
Default is: -gen GAS
FBC 64 is by default: -gen GCC (can do: code optimisations, which GAS can't).

GCC is used to output the assembly code, that is further processed by AS and LD.
Assembler & Linker e.t.c., from BinUtils (aka: -gen GAS).
This means: the same tools are used (in the end), independent of the code output
by FBC ... (GAS straight away, or GCC as inbetween step).

Your conclusions are therefore not very well reasoned.
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

Re: [Freebasic 32 vs 64]

Post by Coolman »

I know all that. by default freebasic 32 generates asm code while the 64-bit version generates only C code.

which explains that 32 bit programs are much faster than 64 bit ...

I hope it is more precise.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: [Freebasic 32 vs 64]

Post by MrSwiss »

Coolman wrote:I know all that.
If you write information for others to use, this doesn't matter at all.

Your conclusion is still based of funny assumptions ;-)
(bold print, doesn't change anything)
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

Re: [Freebasic 32 vs 64]

Post by Coolman »

MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: [Freebasic 32 vs 64]

Post by MrSwiss »

The test results you are referring to, are without any meaning ...
a) no testing code supplied
b) no testing conditions mentioned (graphics driver used)
(FBC 32 uses DirectX as graphics driver, which isn't available in FBC 64, using GDI, known to be slow)
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

Re: [Freebasic 32 vs 64]

Post by Coolman »

I use freebasic only for small programs and lazarus freepascal for big projects. the speed difference of the programs (32 vs 64) generated surprised me. that's all. the technical details are not important. I expect a 64 bit program to be faster than a 32 bit program. it's always the case with the other languages I use. this is not the case with freebasic for now. I will use the 32 bit version ...
St_W
Posts: 1619
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: [Freebasic 32 vs 64]

Post by St_W »

Coolman wrote:I know all that. by default freebasic 32 generates asm code while the 64-bit version generates only C code.
which explains that 32 bit programs are much faster than 64 bit ...
I hope it is more precise.
Maybe more precise, but your conclusion is still wrong. In general asm code is not faster than C code; maybe handwritten asm code, but not asm code generated by FB. And btw the C code is compiled to asm code as well during FreeBasic's internal build process, which you could've seen if you'd have taken a closer look.
However in most cases the opposite is true: C code is faster than than 32-bit asm code generated by FB, because the asm code that is generated from C code is heavily optimized by gcc while FB only supports some basic optimization techniques.
Coolman wrote:the technical details are not important. I expect a 64 bit program to be faster than a 32 bit program. it's always the case with the other languages I use.
Maybe you're using inadequate methods to measure "speed". In general a 64-bit application isn't faster than a 32-bit one, no matter whether you use FB, C, Pascal or any other programming language to generate native code. Technical details may be not important to you, but knowing them explains why you're wrong, so you may consider having a closer look into them.
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: [Freebasic 32 vs 64]

Post by marcov »

Coolman wrote:I know all that. by default freebasic 32 generates asm code while the 64-bit version generates only C code.
The 32-bit generates assembler from Basic. The 64-bit generates assembler from C.

Since C is faster that Basic that explains why 64-bits programs are so much faster than 32-bit.

In general 64-bit can be faster, because it is easier to optimize for with a compiler, provided some conditions are met:

- when the math is relatively simple (x64 often uses SSE fpu, which has slower non basic operations than x87, things like cos etc)
- when the data size is the same. If you blow up the datasize, you hit the cache, which has the same size in 32-bit as 64-bit mode.
- On *nix, the relative speed of 64-bit PIC vs 32-bit PIC comes on top of that.
- runtime libraries can assume sse2 (and in practice even sse3, since most kernels don't support the first generation AMD64 due to missing atomic primitives). This specially means that small moves can be inlined in a better way.

A lot of naive benchmarks and tests blame codegeneration while it is often other factors, like runtime helpers, 64-bit vs 80-bit fpu math etc.
Last edited by marcov on Jan 28, 2019 19:55, edited 1 time in total.
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: [Freebasic 32 vs 64]

Post by badidea »

marcov wrote:... that explains why 64-bits programs are so much faster than 32-bit
Coolman wrote:... which explains that 32 bit programs are much faster than 64 bit
:-)
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

Re: [Freebasic 32 vs 64]

Post by Coolman »

St_W wrote:
Coolman wrote:I know all that. by default freebasic 32 generates asm code while the 64-bit version generates only C code.
which explains that 32 bit programs are much faster than 64 bit ...
I hope it is more precise.
Maybe more precise, but your conclusion is still wrong. In general asm code is not faster than C code; maybe handwritten asm code, but not asm code generated by FB. And btw the C code is compiled to asm code as well during FreeBasic's internal build process, which you could've seen if you'd have taken a closer look.
However in most cases the opposite is true: C code is faster than than 32-bit asm code generated by FB, because the asm code that is generated from C code is heavily optimized by gcc while FB only supports some basic optimization techniques.
Coolman wrote:the technical details are not important. I expect a 64 bit program to be faster than a 32 bit program. it's always the case with the other languages I use.
Maybe you're using inadequate methods to measure "speed". In general a 64-bit application isn't faster than a 32-bit one, no matter whether you use FB, C, Pascal or any other programming language to generate native code. Technical details may be not important to you, but knowing them explains why you're wrong, so you may consider having a closer look into them.
well. it is true that using gcc optimization options in the example I cited the 32 bit program is faster. in that case. why not harmonize freebasic 32 and 64 so that it generates only C code with the default compilation enabled with the option -O2. it would be more logical. and it will optimize the c-generated code in both versions.

that said. i can assure you that 64 bit programs generated by lazarus freepascal are much faster than 32 bit ones.
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: [Freebasic 32 vs 64]

Post by marcov »

Coolman wrote: that said. i can assure you that 64 bit programs generated by lazarus freepascal are much faster than 32 bit ones.
On Windows or on Linux ?
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

Re: [Freebasic 32 vs 64]

Post by Coolman »

Windows
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: [Freebasic 32 vs 64]

Post by marcov »

Coolman wrote:Windows
Make sure you recompiled everything with -dTEST_WIN32_SEH and appropriate -Cf parameters.

By default win32 has a slower exception system than win64, but that is historic and will hopefully be fixed soon.
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

Re: [Freebasic 32 vs 64]

Post by Coolman »

marcov wrote:
Coolman wrote:Windows
Make sure you recompiled everything with -dTEST_WIN32_SEH and appropriate -Cf parameters.

By default win32 has a slower exception system than win64, but that is historic and will hopefully be fixed soon.
I did not know this setting, I use classic optimizations. you mean with this setting. 32 and 64 bit programs have an equal execution speed?
Post Reply