FB 1.02 release

For other topics related to the FreeBASIC project or its community.
VANYA
Posts: 1370
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: FB 1.02 release

Postby VANYA » Apr 06, 2015 3:23

Thank you for the new version.

Address-of followed by pointer-arithmetic on variables (expressions such as @x+N) will now be turned into offsetted variable accesses, resulting in better generated code


I do not understand what that means? What added compared to the previous version? Please tell me an example.
fxm
Posts: 9820
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: FB 1.02 release

Postby fxm » Apr 06, 2015 7:07

Thanks for this new official version.

But why since fbc 1.00.0, the file as 'gcc-4.9.1-for-FB-win32-gengcc.zip' no longer explicitly appears on a SourceForge page?
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: FB 1.02 release

Postby MichaelW » Apr 06, 2015 8:41

Since the inline assembly changed for the 1.02.0 (04-05-2015) release, I decided to do a series of small tests for the Win64 version. I found no problems, thank you dkl for your efforts.

Code: Select all

#include "windows.bi"

''--------------------------------------------------------------------
'' -asm intel is now the default
''
'' There is still apparently no way to access a stack-based (local)
'' variable, but knowing the naming convention shared variables are
'' no problem.
''--------------------------------------------------------------------

dim shared as ulongint x = 123456789, y

asm
    mov     rax, X$
    mov     Y$, rax
end asm

print x, y

sleep

Code: Select all

#include "windows.bi"

''--------------------------------------------------------------------------------
'' -asm intel is now the default
''
'' Naked function without parameters.
''--------------------------------------------------------------------------------

function Rdrand64 naked() as ulongint
    ''------------------------------------------------------------------------------
    '' RDRAND instruction supported if, for CPUID function 1, bit 30 of ECX is set.
    '' This function returns a 64-bit hardware random number, or zero if RDRAND not
    '' supported.
    ''------------------------------------------------------------------------------
    asm
        mov     eax, 1
        cpuid
        xor     rax, rax
        bt      ecx, 30
        jnc     0f
        rdrand  rax
    0:
        ret
    end asm
end function

for i as integer = 1 to 20
    print Rdrand64()
next

sleep

Code: Select all

#include "windows.bi"

''------------------------------------------------------------------------------
'' -asm intel is now the default
''
'' Naked function with parameters.
''------------------------------------------------------------------------------

function Sum naked( byval p1 as longint, byval p2 as longint, _
                    byval p3 as longint, byval p4 as longint, _
                    byval p5 as longint, byval p6 as longint ) as longint
    ''---------------------------------------------------------------------
    '' Per the 64-bit Windows calling convention the first four integer
    '' parameters are passed in RCX, RDX, R8, and R9, and any further
    '' parameters are passed on the stack, in C (right to left) order.
    ''
    '' Contents of the stack on entry:
    ''
    '' [rsp+48] arg6
    '' [rsp+40] arg5
    '' [rsp+32] spill space for arg4   
    '' [rsp+24] spill space for arg3   
    '' [rsp+16] spill space for arg2
    '' [rsp+8]  spill space for arg1
    '' [rsp]    return address
    ''
    '' And 64-bit integer values are returned in RAX.
    ''---------------------------------------------------------------------
    asm
        mov     rax, rcx
        add     rax, rdx
        add     rax, r8
        add     rax, r9
        add     rax, [rsp+40]
        add     rax, [rsp+48]
        ret
    end asm
end function

print 1+2+3+4+5+6, Sum(1,2,3,4,5,6)

sleep

[code file=counter64.bas]
''=============================================================================
'' These two macros, which are coded to be compatible with -asm intel, now
'' the default for the 1.02.0 release of the Win64 compiler, provide a
'' convenient method of measuring the processor clock-cycle count for a
'' block of code. The macros must be called in pairs, and the block of code,
'' or a call to a procedure containing the block of code, must be placed
'' between the counter_begin and counter_end macro calls. The average per-
'' loop cycle count, corrected for the loop overhead, is returned in the
'' global variable counter_cycles.
''
'' I provided access to the process priority class and the thread priority to
'' make it possible to operate at the highest possible priority by using the
'' combination of REALTIME_PRIORITY_CLASS and THREAD_PRIORITY_TIME_CRITICAL.
'' On a multi-core system doing so appears to be reasonably safe, even if the
'' code being timed triggers an exception. But note the Microsoft warnings
'' about operating at such a high priority for more than a very brief interval.
''
'' The loops and the cycle-count calculations are done entirely in assembly to
'' avoid problems with compiler optimizations breaking the code.
''
'' Note that CPUID will alter the value of EBX/RBX, which is one of the callee-
'' save registers for Windows and Linux. I did not bother with preserving the
'' value because doing so would pollute the cycle count, and because these
'' macros are not intended for use under circumstances were the failure to
'' preserve the value would matter.
''=============================================================================

dim shared as integer counter_cycles
dim shared as long _loop_count_, _loop_counter_
dim shared as DWORD _process_priority_class_
dim shared as long _thread_priority_

#macro COUNTER_BEGIN( loop_count, process_priority, thread_priority )
_loop_count_ = loop_count
_process_priority_class_ = GetPriorityClass(GetCurrentProcess())
_thread_priority_ = GetThreadPriority(GetCurrentThread())
SetPriorityClass(GetCurrentProcess(), process_priority)
SetThreadPriority(GetCurrentThread(), thread_priority)
_loop_counter_ = _loop_count_
asm
xor eax, eax
cpuid
rdtsc
push rdx
push rax
xor eax, eax
cpuid
.balign 16
0:
sub DWORD PTR [_LOOP_COUNTER_$], 1
jnz 0b
xor eax, eax
cpuid
rdtsc
pop rcx
sub eax, ecx
pop rcx
sbb edx, ecx
push rdx
push rax
xor eax, eax
cpuid
rdtsc
push rdx
push rax
mov eax, _LOOP_COUNT_$
mov _LOOP_COUNTER_$, eax
xor eax, eax
cpuid
.balign 16
1:
end asm
#endmacro

#macro COUNTER_END
asm
sub DWORD PTR [_LOOP_COUNTER_$], 1
jnz 1b
xor eax, eax
cpuid
rdtsc
pop rcx
sub eax, ecx
pop rcx
sbb edx, ecx
pop rcx
sub eax, ecx
pop rcx
sbb edx, ecx
mov DWORD PTR [COUNTER_CYCLES$], eax
mov DWORD PTR [COUNTER_CYCLES$+4], edx
end asm
SetPriorityClass(GetCurrentProcess(),_process_priority_class_)
SetThreadPriority(GetCurrentThread(),_thread_priority_)
counter_cycles /= _loop_count_
#endmacro
[/code]

Code: Select all

#include "windows.bi"
#include "counter64.bas"

dim as double r1,r2,r3

sleep 5000

for i as integer = 1 to 3
    randomize ,1
    counter_begin(1000000,REALTIME_PRIORITY_CLASS,THREAD_PRIORITY_TIME_CRITICAL)   
        r1 = rnd
    counter_end   
    print counter_cycles;" cycles, rand"
    randomize ,2
    counter_begin(1000000,REALTIME_PRIORITY_CLASS,THREAD_PRIORITY_TIME_CRITICAL)   
        r2 = rnd
    counter_end   
    print counter_cycles;" cycles, fast"
    randomize ,3
    counter_begin(1000000,REALTIME_PRIORITY_CLASS,THREAD_PRIORITY_TIME_CRITICAL)   
        r3 = rnd
    counter_end   
    print counter_cycles;" cycles, mt"   
next

sleep
dkl
Site Admin
Posts: 3212
Joined: Jul 28, 2005 14:45
Location: Germany

Re: FB 1.02 release

Postby dkl » Apr 06, 2015 10:28

VANYA wrote:
Address-of followed by pointer-arithmetic on variables (expressions such as @x+N) will now be turned into offsetted variable accesses, resulting in better generated code


I do not understand what that means? What added compared to the previous version? Please tell me an example.


It's an improvement to code generation. Here's a small example:

Code: Select all

dim s as zstring * 100
print @s + 10


1.01.0 wrote:...
lea eax, [ebp-100]
add eax, 10
...


1.02.0 wrote:...
lea eax, [ebp-90]
...


@MichealW It should be possible to access local variables from inline ASM even with -gen gcc, at least this works for me under -gen gcc:

Code: Select all

dim as long a = 123, b
print a, b
asm
   mov eax, [a]
   mov [b], eax
end asm
print a, b
VANYA
Posts: 1370
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: FB 1.02 release

Postby VANYA » Apr 06, 2015 11:49

dkl!

Thank you for the response. Good improvement. Now I will test as follows headers, though already found a couple of bugs. Later I will create a new topic and everything that I can find will write
D.J.Peters
Posts: 8121
Joined: May 28, 2005 3:28
Contact:

Re: FB 1.02 release

Postby D.J.Peters » Apr 06, 2015 13:45

I testes all my FB stuff successfull with 1.02 32/64bit. (and I have ton's of stuff from the last ten years here)

In some OpenGL stuff I must only cast the glGetString() const ubyte ptr to zString ptr now.

Does the macros RGB and RGBA are changed too ?

I mean a pixel for 32/64-bit OS must be allways ULONG not UINTEGER as before.

@dkl again you have done a really good job for us all.

Thank you.

Joshy
VANYA
Posts: 1370
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: FB 1.02 release

Postby VANYA » Apr 06, 2015 18:00

Will not create a new topic, write it down here:

1) No definition REFIID
2) win\dshow.bi (files do not exist: #include once "strsafe.bi", #include once "windowsx.bi")
3) win\strmif.bi (not defines: IGraphBuilder_QueryInterface,IGraphBuilder_AddRef,...)
4) win\winuser.bi (not defines: wsprintf)

dkl, you create new headers? Like in the old definition of all the headlines were made, and in the new lot missing.
ike
Posts: 387
Joined: Jan 17, 2011 18:59

Re: FB 1.02 release

Postby ike » Apr 06, 2015 19:00

I tested some old IUP samples with new version

SCINTILLA did not work until I changed
this line:

extern "C" lib "iup_scintilla"

instead of:

extern "C"


IN THIS FILE
iup_scintilla.bi


ALSO changed

extern "C" lib "iupcontrols"
aloberoger
Posts: 495
Joined: Jan 13, 2009 19:23

Re: FB 1.02 release

Postby aloberoger » Apr 06, 2015 20:34

WANYA WROTE
Will not create a new topic, write it down here:
1) No definition REFIID
2) win\dshow.bi (files do not exist: #include once "strsafe.bi", #include once "windowsx.bi")
3) win\strmif.bi (not defines: IGraphBuilder_QueryInterface,IGraphBuilder_AddRef,...)
4) win\winuser.bi (not defines: wsprintf)


Yes REFIID does not exist we have in declaration riid as Const IDD const ptr instead
I thing IGraphBuilder_QueryInterface has been replaced by IGraphBuilder_QueryInterface_proxy

I have tested my old Com programs I haved this error:
D:\NEW COM 2014\FBCOM1\IExample1.bas(36) error 180: Invalid assignment/conversion, at parameter 1 of MEMCMP() in 'IF IsEqualIID( iid, @IID_IUnknown) Or IsEqualIID( iid, @IID_IDispatch) Then'
I have changed the declaration in "crt/mem.bi"
declare function memcmp (byval as Any ptr, byval as Any ptr, byval as size_t) as long
by
declare function memcmp (byval as Const Any ptr, byval as Const Any ptr, byval as size_t) as long

and things are ok now

In the others hand:
Line Input #ff, s is not been recognised
declare property Fontsize() as integer show an error

GPTR_ is now GPTR .....
fxm
Posts: 9820
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: FB 1.02 release

Postby fxm » Apr 07, 2015 9:27

fxm wrote:... why since fbc 1.00.0, the file as 'gcc-4.9.1-for-FB-win32-gengcc.zip' no longer explicitly appears on a SourceForge page?
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: FB 1.02 release

Postby MichaelW » Apr 07, 2015 10:07

dkl wrote:@MichealW It should be possible to access local variables from inline ASM even with -gen gcc, at least this works for me under -gen gcc:

Code: Select all

dim as long a = 123, b
print a, b
asm
   mov eax, [a]
   mov [b], eax
end asm
print a, b

Your example compiles to a 64-bit EXE with or without -gen gcc, and the same for a version that uses 64-bit registers and variables:

Code: Select all

dim as integer a = 123, b
print a, b
asm
    mov     rax, [a]
    mov     [b], rax
end asm
print a, b
sleep

So in my tests I was apparently doing something wrong, but I have not been able to backtrack and determine what it was.
dodicat
Posts: 6641
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: FB 1.02 release

Postby dodicat » Apr 07, 2015 13:24

Using disphelper:

My simple little Google page no longer works with fb 1.02.
The error is:
FreeBASIC-1.02.0-win32\inc\win\winerror.bi(3107) error 20: Type mismatch in '#if _WIN32_WINNT = &h0602'

This system:
Win Xp, 32 bit

code:

Code: Select all

 
#define UNICODE

#include once "disphelper/disphelper.bi"

   
var WebPage="http://www.google.com"
dim FBIE as any Ptr
dhInitialize(TRUE)
dhToggleExceptions(FALSE)
dhCreateObject("InternetExplorer.Application",0,@FBIE)
dhPutValue(FBIE, ".Visible = %b",1)
dhcallmethod(FBIE, ".Navigate %s",WebPage)
sleep
dhcallmethod(FBIE ,"quit")

end

 
 
D.J.Peters
Posts: 8121
Joined: May 28, 2005 3:28
Contact:

Re: FB 1.02 release

Postby D.J.Peters » Apr 07, 2015 20:46

Problem solved was my fault.

Joshy
Last edited by D.J.Peters on Apr 07, 2015 22:43, edited 1 time in total.
fxm
Posts: 9820
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: FB 1.02 release

Postby fxm » Apr 07, 2015 22:25

Code: Select all

function realVector3Read(byval pIn as FILE ptr) as realVector3
  dim as realVector3 v=any
'  dim as ubyte     l,r
  dim as zstring * 2 l,r
  dim as single f(2)=any
  ' read "(x,y,z)"
  fscanf( pIn, "%1s %g %g %g %1s",@l, @f(0), @f(1), @f(2),@r)
'  if l<>asc("(") or r<>asc(")") then
  if l[0]<>asc("(") or r[0]<>asc(")") then
    print "error: realVector3Read() !"
    beep:sleep:end
  end if
  for i as integer=0 to 2:v.xyz(i)=f(i):next
  return v
end function
IMHO, l and r must be zstring * 2, and not ubyte.
(one character plus the terminal null character)
Last edited by fxm on Apr 08, 2015 8:03, edited 1 time in total.
D.J.Peters
Posts: 8121
Joined: May 28, 2005 3:28
Contact:

Re: FB 1.02 release

Postby D.J.Peters » Apr 07, 2015 22:35

@fxm good find sometimes i'm blind.

I wonder me does it works
with
gen -gas
and
-gen gcc -O 3
-gen gcc -O 2

However thank you.

Joshy

Return to “Community Discussion”

Who is online

Users browsing this forum: jj2007 and 5 guests