Where can I get a Recent-Git-Build of FreeBASIC?

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
deltarho[1859]
Posts: 4281
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Where can I get a Recent-Git-Build of FreeBASIC?

Post by deltarho[1859] »

I think some research at gcc is needed
Knowing diddly-squat about compilers I am at a disadvantage when reading the changes to 6.4, 7.3 and 8.1. There is a lot to do with CPU architecture. Not being able to 'see the wood for the trees' it is impossible for me to filter out anything which may relate to our use of gcc with FreeBASIC.

If there is anything in the versions of gcc since 5.2 which do relate to our use with FreeBASIC and are beneficial then we will lose out by not adopting the later versions.

Given a 144.5KB 64 bit binary using gcc 5.2 and a 152.5KB 64 bit binary using gcc 8.1 with no real difference in performance and both seeming to behave without any issues is there then anything beneficial in the extra 8KB using gcc 8.1? I have no idea.
Provoni
Posts: 508
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Where can I get a Recent-Git-Build of FreeBASIC?

Post by Provoni »

deltarho[1859] wrote: Added: "Your implementation is slow." I may be wrong on that - I am getting some weird results in 64 bit.
On my Ivy Bridge CPU, using FreeBASIC 1.05 64-bit, and "-gen GCC -O max -Wc -march=native,-funroll-loops,-ffast-math", the implementation:

Code: Select all

ms_state=(214013*ms_state+2531011)and 2147483647
random_number=int(ms_state/2147483648*variable)
Is faster than PCG32II and the built in FreeBASIC random function.

Can anyone top it?
deltarho[1859]
Posts: 4281
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Where can I get a Recent-Git-Build of FreeBASIC?

Post by deltarho[1859] »

@Provoni

With "-gen gcc -Wc -O3" 32 bit 1.06 I am getting 10^7 computations done in 180ms, 55.5MHz
With "-gen GCC -O max -Wc -march=native,-funroll-loops,-ffast-math" 32 bit 1.06 I am getting 10^7 computations done in 25ms, 400MHz

That is over 7 times faster.

Your knowledge of the compiler switches is way beyond mine.

In 64 bit, with either of the two switches route, I cannot measure the time. I repeated the two statements 100 times in a loop within the 10^7 loop and am getting a time of zero.

This is not telling me that the time is immeasurable but is telling me that the 64 bit compilation, whilst apparently successful, is suspicious.

It is not going to be possible to top code which exits as soon as it has started.

Perhaps someone else can have a look at a 64 bit compilation to confirm my suspicions or, the more likely scenario, correct me.

Provoni, can you determine a MHz for the 64 bit compilation?

Added: With "-gen gcc -Wc -O1" 64 bit 1.06 I am getting 10^7 computations done in 3.4ms, 2978MHz. -O2 and above and I'm getting a time of zero.

More added: I have been trying to find your algorithm and found it here. It is the LCG used by Microsoft Visual/Quick C/C++. No doubt you have tried others in that list and, if so, 'topping' it isn't going to be easy. Of course, anyone wanting half decent random numbers should not use a LCG.
St_W
Posts: 1617
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Where can I get a Recent-Git-Build of FreeBASIC?

Post by St_W »

Also note that "fast-math" has some negative implications on floating-point calculation accuracy, so you probably do not want to enable it in various situations.
Provoni
Posts: 508
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Where can I get a Recent-Git-Build of FreeBASIC?

Post by Provoni »

deltarho[1859] wrote: In 64 bit, with either of the two switches route, I cannot measure the time. I repeated the two statements 100 times in a loop within the 10^7 loop and am getting a time of zero.
You have to record the random numbers somehow, like by adding them to a variable that is later on outputted to the user, or otherwise the compiler will optimize it away since it is interpreted that the piece of code serves no obvious function.
deltarho[1859] wrote: Provoni, can you determine a MHz for the 64 bit compilation?
What needs to be done? Can you give me a program?
deltarho[1859] wrote: More added: I have been trying to find your algorithm and found it here. It is the LCG used by Microsoft Visual/Quick C/C++. No doubt you have tried others in that list and, if so, 'topping' it isn't going to be easy. Of course, anyone wanting half decent random numbers should not use a LCG.
Yes that is the one. There are speed issues with FreeBASIC's rnd implementation and multi-threading. I have not tried any other values or algorithms. Trying other values is on my mental to do list.
deltarho[1859]
Posts: 4281
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Where can I get a Recent-Git-Build of FreeBASIC?

Post by deltarho[1859] »

I put Provoni's code into the graphics comparison above. An erroneous compilation would not give me a blue background but it did. In fact there were no yellow pixels left so this LCG is OK for 13,440,000 numbers.

The timings got for 564 1.06 were

Code: Select all

PCG 0.310
LCG 0.296
Inf 0.220
A percentage increase in random number generation does not translate into the same percentage increase for the graphics timings - it is much less. The reason being Pset is not cheap. So, to go from 0.310 to 0.296 means the LCG is belting along.

Added: "You have to record the random numbers somehow, like by adding them to a variable that is later on outputted to the user, or otherwise the compiler will optimize it away since it is interpreted that the piece of code serves no obvious function."

I had not thought of that. Of course, that is what I am doing, without realising it, with the graphics comparison.

Measuring MHz will now be problematic. Whatever we add to stop the compiler trashing the algorithm will need to be removed after use by some arithmetic.

Measuring MHz is handy but not necessary. We could do worse than my little graphics comparison and we get an indication of speed in less than half a second.
coderJeff
Site Admin
Posts: 4308
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Where can I get a Recent-Git-Build of FreeBASIC?

Post by coderJeff »

deltarho[1859] wrote:Perhaps someone else can have a look at a 64 bit compilation to confirm my suspicions or, the more likely scenario, correct me.
Assuming that you are using TIMER to measure time. Trying to measure short time intervals, I get varied results, all over the place, depending on 32/64bit and optimization (-O) level. with 64 bit -gen gcc - O 3, can see that the program completes, TIMER returns a different result each time, but the result is so small represented as a double, don't really see it. Which is leading to the wildly inaccurate statistics.

Code: Select all

dim t(0 to 5) as double
dim i(0 to 5) as longint
t(0) = timer
i(0) = 0
dim n as integer = 0
do
	t(n+1) = timer
	i(n+1) += 1
	if( t(n+1) <> t(n) ) then
		n += 1
	end if
loop until n > 5
for k as integer = 1 to 5
	print i(k),
	print t(k-1), 
	print t(k),
	print int(   (t(k) - t(k-1)) * 1000000 * 1000 )/1000 & "ms", 
	print int( 1/(t(k) - t(k-1)) / 1000000 * 1000 )/1000 & "MHz"
next
On the other hand, if I time out 10 seconds and count the iterations, I get results that can be compared between 32/64bit, -gen gas/gcc, etc. In particular in my test, -O 3 being approx 25% faster than -O 0.

Code: Select all

const duration = 10 '' seconds
dim count as longint
dim t0 as double = timer
dim t1 as double
print "Be patient for " & duration & " seconds..."
do
	t1 = timer
	if( t1-t0 ) >= duration then
		exit do
	end if
	count += 1 	
loop
print "iterations per second = " & count / duration & "Hz", 
print int(count / duration / 1000000 * 1000) / 1000 & "MHz"
deltarho[1859]
Posts: 4281
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Where can I get a Recent-Git-Build of FreeBASIC?

Post by deltarho[1859] »

coderJeff wrote:On the other hand, if I time out 10 seconds and count the iterations
Very crafty <smile>
deltarho[1859]
Posts: 4281
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Where can I get a Recent-Git-Build of FreeBASIC?

Post by deltarho[1859] »

Unfortunately there is a lot work going on in the loop resulting in a gross underestimate of the actual MHz.

My PCG32II in range mode runs at about 300MHz for 64 bit. The only thing in that test's loop is 'x = pcg.range(0,20)' for example.

A slight tweak to your code coderJeff

Code: Select all

t1 = t0 + duration
Do
  If Timer >= t1 Then Exit Loop
  count += 1
Loop

With an empty loop I get 68.71MHz
With PCG32II I get 58.66MHz
With Provoni I get 68.72MHz

In Provoni's case we get the compiler trashing the algorithm again.

It seems to me that the only way to test Provoni's LCG is to use a real world environment using it compared with other generators in the same environment and forget about MHz.
deltarho[1859]
Posts: 4281
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Where can I get a Recent-Git-Build of FreeBASIC?

Post by deltarho[1859] »

I have just had 864 go down. 532, 564 and 832 were fine using -gen gcc -Wc -O3. The 864 was OK for -gen gcc but as soon as I turned optimization on, at -O1, it failed.

Code: Select all

internal compiler error: output_operand: invalid use of register 'frame' } ^libbacktrace could not find executable to open
Fortunately, I am more than happy with the results that I am getting from 532.

With -gen gas I had time to prepare an evening mail.
St_W
Posts: 1617
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Where can I get a Recent-Git-Build of FreeBASIC?

Post by St_W »

Maybe you noticed that my nightly builds weren't updated recently. I just wanted to note that the problem is known (broken internet connection) and I'm on it (but it will probably take a while). I'll update this post when the issue is resolved. Sorry for any inconvenience this may cause.

update: build machine is up and working again
Last edited by St_W on Aug 26, 2018 16:42, edited 1 time in total.
deltarho[1859]
Posts: 4281
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Where can I get a Recent-Git-Build of FreeBASIC?

Post by deltarho[1859] »

I did. I thought that a 1.06 must be imminent. <smile>
dafhi
Posts: 1640
Joined: Jun 04, 2005 9:51

Re: Where can I get a Recent-Git-Build of FreeBASIC?

Post by dafhi »

Provoni - simple change makes your rng more random

Code: Select all

Sub ShowBits32( p as any ptr, Newline As boolean = true)
 
  '' use ScreenRes w,h, 32
 
  Dim As ulong  I, AryFG(3), AryBG(3)
  var           oldcol = color()
  AryFG(0) = RGB(200,200,200)
  AryFG(1) = RGB(255,0,0)
  AryFG(2) = RGB(0,255,0)
  AryFG(3) = RGB(0,96,255)
  AryBG(0) = RGB(100,100,100)
  AryBG(1) = RGB(127,0,0)
  AryBG(2) = RGB(0,127,0)
  AryBG(3) = RGB(0,0,127)
  dim as ulong ptr  v = p
  For I = 0 To 3
    Color AryFG(I), AryBG(I)
    print bin(*v shr (24 - i*8), 8);
  Next
  If Newline Then Print
  color oldcol
End Sub

sub ShowBits64(p as any ptr, Newline As boolean = true)
  showbits32 p+4, false
  ShowBits32 p, newline
END SUB


function prov_rng as ulong  '' https://www.freebasic.net/forum/viewtopic.php?f=17&t=19095&start=375#p248261
    static as ulong ms_state:  ms_state=214013*((ms_state+2531011)shr 1)'and -1 [Aug 15 update]
    return ms_state
End Function

screenres 800,600,32
for i as long = 1 to 50
  var l = prov_rng
  showbits64 @l
next
sleep
Last edited by dafhi on Aug 15, 2018 23:25, edited 1 time in total.
fxm
Moderator
Posts: 12066
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Where can I get a Recent-Git-Build of FreeBASIC?

Post by fxm »

St_W wrote:Maybe you noticed that my nightly builds weren't updated recently.
I had just realized this, with very recent updates to the documentation.
Provoni
Posts: 508
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Where can I get a Recent-Git-Build of FreeBASIC?

Post by Provoni »

dafhi wrote:Provoni - simple change makes your rng more random

Code: Select all

Sub ShowBits32( p as any ptr, Newline As boolean = true)
 
  '' use ScreenRes w,h, 32
 
  Dim As ulong  I, AryFG(3), AryBG(3)
  var           oldcol = color()
  AryFG(0) = RGB(200,200,200)
  AryFG(1) = RGB(255,0,0)
  AryFG(2) = RGB(0,255,0)
  AryFG(3) = RGB(0,96,255)
  AryBG(0) = RGB(100,100,100)
  AryBG(1) = RGB(127,0,0)
  AryBG(2) = RGB(0,127,0)
  AryBG(3) = RGB(0,0,127)
  dim as ulong ptr  v = p
  For I = 0 To 3
    Color AryFG(I), AryBG(I)
    print bin(*v shr (24 - i*8), 8);
  Next
  If Newline Then Print
  color oldcol
End Sub

sub ShowBits64(p as any ptr, Newline As boolean = true)
  showbits32 p+4, false
  ShowBits32 p, newline
END SUB


function prov_rng as ulong  '' https://www.freebasic.net/forum/viewtopic.php?f=17&t=19095&start=375#p248261
    static as ulong ms_state:  ms_state=214013*((ms_state+2531011)shr 1)and -1
    return ms_state
End Function

screenres 800,600,32
for i as long = 1 to 50
  var l = prov_rng
  showbits64 @l
next
sleep
Thank you!
Post Reply