[Freebasic 32 vs 64]

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

[Freebasic 32 vs 64]

Postby Coolman » Jan 28, 2019 16:31

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: 3137
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: [Freebasic 32 vs 64]

Postby MrSwiss » Jan 28, 2019 16:49

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: 208
Joined: Nov 05, 2010 15:09

Re: [Freebasic 32 vs 64]

Postby Coolman » Jan 28, 2019 17:07

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: 3137
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: [Freebasic 32 vs 64]

Postby MrSwiss » Jan 28, 2019 17:19

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: 208
Joined: Nov 05, 2010 15:09

Re: [Freebasic 32 vs 64]

Postby Coolman » Jan 28, 2019 17:29

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

Re: [Freebasic 32 vs 64]

Postby MrSwiss » Jan 28, 2019 17:56

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: 208
Joined: Nov 05, 2010 15:09

Re: [Freebasic 32 vs 64]

Postby Coolman » Jan 28, 2019 18:16

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: 1467
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: [Freebasic 32 vs 64]

Postby St_W » Jan 28, 2019 18:30

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: 2755
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: [Freebasic 32 vs 64]

Postby marcov » Jan 28, 2019 19:36

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: 1401
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: [Freebasic 32 vs 64]

Postby badidea » Jan 28, 2019 19:41

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: 208
Joined: Nov 05, 2010 15:09

Re: [Freebasic 32 vs 64]

Postby Coolman » Jan 28, 2019 19:50

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: 2755
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: [Freebasic 32 vs 64]

Postby marcov » Jan 28, 2019 19:53

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: 208
Joined: Nov 05, 2010 15:09

Re: [Freebasic 32 vs 64]

Postby Coolman » Jan 28, 2019 19:57

Windows
marcov
Posts: 2755
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: [Freebasic 32 vs 64]

Postby marcov » Jan 28, 2019 20:06

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: 208
Joined: Nov 05, 2010 15:09

Re: [Freebasic 32 vs 64]

Postby Coolman » Jan 28, 2019 20:14

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?

Return to “General”

Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest