Gas64 (no more use of gcc, only gas) WDS / LNX

User projects written in or related to FreeBASIC.
SARG
Posts: 1157
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) :-)

Postby SARG » Jan 29, 2020 21:38

paul doe wrote:Indeed, it's just gcc64 that does this. Naturally, none of the other x64 ASM keywords work

Sure the syntax is always correct lea rax, rax[rip] but obviously a wrong address....

As written in a previous post all the assembly 'words' could casue issue.
paul doe
Posts: 1312
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Gas64 (no more use of gcc, only gas) :-)

Postby paul doe » Jan 29, 2020 21:41

SARG wrote:I was writing when you posted.
Gas32 and gcc32 no problem unless I missed something.

The issue comes from --> lea rax, QWORD[rip]
The syntax is correct in assembly. However the address gets by lea (load address) is wrong. It's the adress in the middle of the instruction not the proc adress...... For this reason there is loop on the print command.

Currently without changing the proc name no way.

Yes, the solution is indeed simple (at least from the FreeBasic code side). However, it is a nasty problem to trip over (and better left well documented). Thank you for looking at the issue in depth.
SARG
Posts: 1157
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) :-)

Postby SARG » Jan 29, 2020 21:51

paul doe wrote:Yes, the solution is indeed simple (at least from the FreeBasic code side). However, it is a nasty problem to trip over (and better left well documented). Thank you for looking at the issue in depth.

You are welcome.

I was facing the same problem (with gas64) some months ago when someone wanted to use register names as variable names. I have had to add a underscore to every name. I guess I'll redo that.
Maybe further upstream to fix also this issue in gcc64. Need to exchange with codejeff.
jj2007
Posts: 1718
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Gas64 (no more use of gcc, only gas) :-)

Postby jj2007 » Feb 01, 2020 10:47

SARG wrote:The issue comes from --> lea rax, QWORD[rip]
The syntax is correct in assembly. However the address gets by lea (load address) is wrong. It's the adress in the middle of the instruction not the proc adress...
Which assembler are you using? MASM can't handle this, but with UAsm,
lea rax, QWORD[rip] chokes but
lea rax, [rip] works fine, and yields the address after the instruction - which is what you want to know anyway.
SARG
Posts: 1157
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) :-)

Postby SARG » Feb 01, 2020 11:14

jj2007 wrote:
SARG wrote:The issue comes from --> lea rax, QWORD[rip]
The syntax is correct in assembly. However the address gets by lea (load address) is wrong. It's the adress in the middle of the instruction not the proc adress...
Which assembler are you using? MASM can't handle this, but with UAsm,
lea rax, QWORD[rip] chokes but
lea rax, [rip] works fine, and yields the address after the instruction - which is what you want to know anyway.

Sorry, you missed something :-)
The problem is that the it should be lea rax, myfunction[rip] to get the address of myfunction and not lea rax, [rip].
When you use qword (or other assembly word) as function name the assembler can not correctly translate it even if the syntax is ok......
jj2007
Posts: 1718
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Gas64 (no more use of gcc, only gas) :-)

Postby jj2007 » Feb 04, 2020 3:00

Oh, now I got it: You used "qword" as a function name... yep, that won't work ;-)
nov79
Posts: 47
Joined: Feb 23, 2020 15:31

Re: Gas64 (no more use of gcc, only gas) :-)

Postby nov79 » Mar 03, 2020 17:10

What is the current state of this? If you no longer depends on gcc, why don't support llvm-as too? This way you could run on FreeBSD without the need to install gcc.
SARG
Posts: 1157
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) :-)

Postby SARG » Mar 05, 2020 17:11

Hi all,

nov79 wrote:What is the current state of this? If you no longer depends on gcc, why don't support llvm-as too? This way you could run on FreeBSD without the need to install gcc.

1.5 years ago, after a small exchange with dkl about 64bit emitter, I began to 'hack' the existing llvm module. However as I was facing some issues (clang, compiler understanding) and LLVM asm is very close to pure asm (at least compared to C) I changed my mind and I wrote the 64bit asm emitter.
Currently my compiler/emitter skill is far better maybe I could exhume my previous work and restart that project....


Only now Linux version is available, not fully tested but should not have a lot of bugs (I hope).
For better readability I recoded all the calling system. It's a complicated (if not the most) part of this module.

Provided (only 64bit exes) :
- fbc 1.07 windows
- fbc 1.08 windows (needs daily build by St_W)
- fbc 1.07 linux
- fbc 1.08 linux to come
- 9 bas/bi new or changed files. Github not yet updated.

http://users.freebasic-portal.de/sarg/fbc64_gas64.zip

Install the fbc64_gas64(.exe) in the same folder than fbc(.exe). Use it and report any issue.

if someone is interested I could also provide 2 simple scripts (bat or sh files) used for compiling all the modules and getting the exes.
Xusinboy Bekchanov
Posts: 254
Joined: Jul 26, 2018 18:28

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Postby Xusinboy Bekchanov » Mar 05, 2020 18:38

Thanks for the great work done.

I have a problem in Linux when starting a compiled application with this content:

Code: Select all

ReDim Construction(23) As Integer


gdb:
Reading symbols from /media/1...(no debugging symbols found)...done


And stopped with error:
Aborting due to runtime error 4 (out f memory) at line 1 of 1.bas::()


For some reason, the Linux version compiles several times longer than gcc.
SARG
Posts: 1157
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Postby SARG » Mar 06, 2020 11:11

Xusinboy Bekchanov wrote:Thanks for the great work done.

You are welcome. Thank you for reporting.

I have a problem in Linux when starting a compiled application with this content:

Code: Select all

ReDim Construction(23) As Integer

And stopped with error:
Aborting due to runtime error 4 (out f memory) at line 1 of 1.bas::()

I suspect MY handling of linux variadic functions. Redim is variadic as the dimension number is variable. I guess something goes wrong when external (lib) variadic functions are called. On the other hand your own functions work fine (tested).

I'll quickly fixed this issue, sorry coderjeff I didn't follow your advice....
Meanwhile it works if you can avoid that kind of functions (it should be hard/impossible).

gdb:
Reading symbols from /media/1...(no debugging symbols found)...done

For now no debugging data is included even if option -g is set.

For some reason, the Linux version compiles several times longer than gcc.

Do you get same slowness with the wds version ?
There is no difference between lnx and wds versions except for handling calling functions.
Xusinboy Bekchanov
Posts: 254
Joined: Jul 26, 2018 18:28

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Postby Xusinboy Bekchanov » Mar 06, 2020 15:30

SARG wrote:
For some reason, the Linux version compiles several times longer than gcc.

Do you get same slowness with the wds version ?
There is no difference between lnx and wds versions except for handling calling functions.

Windows version is normal. Today I checked again. Linux version 2 times faster compiled than the gcc version.
robert
Posts: 125
Joined: Aug 06, 2019 18:45

Re: Gas64 (no more use of gcc, only gas) :-)

Postby robert » Mar 07, 2020 1:44

SARG wrote:Hi all,
if someone is interested I could also provide 2 simple scripts (bat or sh files) used for compiling all the modules and getting the exes.


Hi SARG:

I am interested in recompiling on Fedora to get rid of the ospeed warning. Please post the scripts or include them in your next update.

Thank you. Great work!
nov79
Posts: 47
Joined: Feb 23, 2020 15:31

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Postby nov79 » Mar 07, 2020 14:52

fbc64_gas64 worked well with my small programs.
D.J.Peters
Posts: 8188
Joined: May 28, 2005 3:28
Contact:

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Postby D.J.Peters » Mar 07, 2020 20:43

Hello SARG looks like you are more familiar with 64-bit ASM on Windows and Linux as I'm.

Can you look at the comemnts and may be fix it if I made an mistake ?

And one more question on 64-bit (if you don't have to return a floating point) it's OK using the old FPU assembler commands also ?

I would translate my software OpenGL shader stuff to assembler
but I will wait that someone can confirm my current knowledge of 64-bit inline assembler.

Thank you.

Josh

Code: Select all

' ##################
' # x86 32-bit ASM #
' ##################
' all args on stack
' return integer in: eax
' return floating point in: st0

' ##################
' # Windows x86_64 #
' ##################
' first 4 integer or pointer args in:
' rcx,  rdx,  r8,   r9

' first 4 floating point args in:
' xmm0, xmm1, xmm2, xmm3

' none volatile
' rbp, rbx, rsi, rsp, rdi, r12, r13, r14, r15

' return integer in: rax
' return floating point in: xmm0

' ################
' # Linux x86_64 #
' ################
' first 6 integer or pointer args in:
' rdi, rsi, rdx, rcx, r8, r9

' first 8 floating point args in:
' xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7

' return integer in: rax
' return floating point in: xmm0

' none volatile
' rbp, rbx, rsp, r12, r13, r14, r15

#if (__FB_ASM__ = "att") or _
    defined(__FB_DOS__) or _
    defined(__FB_ARM__) or _
    defined(__FB_ARCH64__) or _
    defined(__FB_DARWIN__) 
 #define ASM_OFF
 #undef naked
 #define naked
#else
 #ifndef __FB_64BIT__
  #define ASM_32
 #elseif defined(__FB_WIN32__)
  #define ASM_64_WIN
 #else
  #define ASM_64_LIN
 #endif
#endif

sub sub_min naked cdecl(byref result as single, byval x as single, byval y as single)
#if defined(ASM_OFF)
  result = iif(x<y,x,y)
#else
 asm
 #if defined(ASM_32)
  mov   eax ,dword ptr [esp+ 4]  ' @result
  movss xmm0,dword ptr [esp+ 8]  ' x
  movss xmm1,dword ptr [esp+12]  ' y
  minss xmm0,xmm1                ' xmm0 = min(x,y)
  movss dword ptr [eax],xmm0     '*result = xmm0
 #elseif defined(ASM_64_WIN) 
  minss xmm1,xmm2                ' xmm1 = min(x,y)
  movss dword ptr [rcx],xmm1     '*result=xmm1
 #elseif defined(ASM_64_LIN) 
  minss xmm0,xmm1                ' xmm0=min(x,y)
  movss dword ptr [rdi],xmm0     '*result=xmm0
 #else
  #error 666: unknow inline assembler mode !
 #endif
  ret
 end asm
#endif
end sub

function func_min naked cdecl(byval x as single, byval y as single) as single
#if defined(ASM_OFF)
  return iif(x<y,x,y)
#else
 asm
 #if defined(ASM_32)
  sub esp,4                     ' dim as single temp=any
  movss xmm0,dword ptr [esp+ 8] ' x
  movss xmm1,dword ptr [esp+12] ' y
  minss xmm0,xmm1               ' xmm0 = min(x,y)
  movss dword ptr [esp],xmm0    ' *tmp = xmm0
  fld   dword ptr [esp]         ' return tmp
  add esp,4
 #elseif defined(ASM_64_WIN) or defined(ASM_64_LIN)
  minss xmm0, xmm1                ' xmm0 = min(x,y)
 #else
  #error 666: unknow inline assembler mode !
 #endif
  ret
 end asm
#endif
end function
'
' main
'
dim as single result
sub_min(result,6.0f,5.2f)
print "sub_min(result,6.0f,5.2f) = " & result
print "func_min(2.2f,1.7f) = " & func_min(2.2f,1.7f)
sleep

SARG
Posts: 1157
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Postby SARG » Mar 08, 2020 0:37

Hi all,
Thank you for your feedback. The issue on variadic functions is almost fixed. Redim should work, it stays the cva_xx commands to be finished. No release for now.

Xusinboy Bekchanov wrote:Windows version is normal. Today I checked again. Linux version 2 times faster compiled than the gcc version.
Not sure to understand , compilation with fbc64_gas64 (linux) is twice faster than with gcc ? The inverse of your previous post.

robert wrote:I am interested in recompiling on Fedora to get rid of the ospeed warning. Please post the scripts or include them in your next update.
Put the 2 scripts with the source code files. Name the first one whatever you want (eg compil.sh) and the second one link.sh.
Then execute compil.sh. link.sh is called automatically. Scripts at the end of the post.

Notes :
- if you don't have ir_gas64.bas remove the related line in the first script and ir_gas64.o at the end of the second.
- no error checking, watch carefully the execution.
- The exe is named fbc_new rename it if necessary and copy where fbc is located.


D.J.Peters wrote:Can you look at the comemnts and may be fix it if I made an mistake ?
Everything seems good.
For Windows it just lacks a subtle precision on the dispatch of arguments in the registers however a big difference from Linux.
But no problem in the provided code you respect the rule.

And one more question on 64-bit (if you don't have to return a floating point) it's OK using the old FPU assembler commands also ?
I guess that yes but I never use them. Why do that ?


nov79 wrote:fbc64_gas64 worked well with my small programs.
Linux, Windows or both ?

Code: Select all

fbc  -d disable_objinfo -t 2048    -c   parser-quirk-array.bas
fbc  -d disable_objinfo -t 2048    -c   parser-decl-def.bas
fbc  -d disable_objinfo -t 2048    -c   parser-quirk-casting.bas
fbc  -d disable_objinfo -t 2048    -c   parser-quirk-console.bas
fbc  -d disable_objinfo -t 2048    -c   parser-quirk-data.bas
fbc  -d disable_objinfo -t 2048    -c   parser-quirk-error.bas
fbc  -d disable_objinfo -t 2048    -c   parser-quirk-file.bas
fbc  -d disable_objinfo -t 2048    -c   parser-quirk-goto-return.bas
fbc  -d disable_objinfo -t 2048    -c   parser-quirk-iif.bas
fbc  -d disable_objinfo -t 2048    -c   parser-quirk-math.bas
fbc  -d disable_objinfo -t 2048    -c   parser-quirk-on.bas
fbc  -d disable_objinfo -t 2048    -c   parser-quirk-peekpoke.bas
fbc  -d disable_objinfo -t 2048    -c   parser-quirk-string.bas
fbc  -d disable_objinfo -t 2048    -c   parser-quirk-vafirst.bas
fbc  -d disable_objinfo -t 2048    -c   parser-quirk-mem.bas
fbc  -d disable_objinfo -t 2048    -c   parser-quirk.bas
fbc  -d disable_objinfo -t 2048    -c   parser-quirk-gfx.bas
fbc  -d disable_objinfo -t 2048    -c   parser-expr-atom.bas
fbc  -d disable_objinfo -t 2048    -c   parser-expr-binary.bas
fbc  -d disable_objinfo -t 2048    -c   parser-expr-constant.bas
fbc  -d disable_objinfo -t 2048    -c   parser-expr-function.bas
fbc  -d disable_objinfo -t 2048    -c   parser-expr-unary.bas
fbc  -d disable_objinfo -t 2048    -c   parser-expr-variable.bas
fbc  -d disable_objinfo -t 2048    -c   reg.bas
fbc  -d disable_objinfo -t 2048    -c   rtl.bas
fbc  -d disable_objinfo -t 2048    -c   rtl-array.bas
fbc  -d disable_objinfo -t 2048    -c   rtl-console.bas
fbc  -d disable_objinfo -t 2048    -c   rtl-data.bas
fbc  -d disable_objinfo -t 2048    -c   rtl-error.bas
fbc  -d disable_objinfo -t 2048    -c   rtl-file.bas
fbc  -d disable_objinfo -t 2048    -c   rtl-gfx.bas
fbc  -d disable_objinfo -t 2048    -c   rtl-gosub.bas
fbc  -d disable_objinfo -t 2048    -c   rtl-macro.bas
fbc  -d disable_objinfo -t 2048    -c   rtl-math.bas
fbc  -d disable_objinfo -t 2048    -c   rtl-mem.bas
fbc  -d disable_objinfo -t 2048    -c   rtl-print.bas
fbc  -d disable_objinfo -t 2048    -c   rtl-profile.bas
fbc  -d disable_objinfo -t 2048    -c   rtl-string.bas
fbc  -d disable_objinfo -t 2048    -c   rtl-system.bas
fbc  -d disable_objinfo -t 2048    -c   symb.bas
fbc  -d disable_objinfo -t 2048    -c   symb-const.bas
fbc  -d disable_objinfo -t 2048    -c   symb-data.bas
fbc  -d disable_objinfo -t 2048    -c   symb-define.bas
fbc  -d disable_objinfo -t 2048    -c   symb-enum.bas
fbc  -d disable_objinfo -t 2048    -c   symb-keyword.bas
fbc  -d disable_objinfo -t 2048    -c   symb-label.bas
fbc  -d disable_objinfo -t 2048    -c   symb-proc.bas
fbc  -d disable_objinfo -t 2048    -c   symb-scope.bas
fbc  -d disable_objinfo -t 2048    -c   symb-struct.bas
fbc  -d disable_objinfo -t 2048    -c   symb-typedef.bas
fbc  -d disable_objinfo -t 2048    -c   symb-var.bas
fbc  -d disable_objinfo -t 2048    -c   symb-namespace.bas
fbc  -d disable_objinfo -t 2048    -c   symb-mangling.bas
fbc  -d disable_objinfo -t 2048    -c   symb-comp.bas
fbc  -d disable_objinfo -t 2048    -c parser-quirk-thread.bas
fbc  -d disable_objinfo -t 2048    -c rtl-oop.bas
fbc  -d disable_objinfo -t 2048    -c rtl-system-thread.bas
fbc  -d disable_objinfo -t 2048    -c ir-llvm.bas
fbc -v  -d disable_objinfo -t 2048    -c ir-gas64.bas

./link.sh


Code: Select all

fbc -Wl -s -d DISABLE_OBJINFO -d ENABLE_STANDALONE -t 2048 -v -x fbc_new fbc.o ast.o ast-gosub.o ast-node-addr.o ast-node-assign.o ast-node-bop.o ast-node-mem.o ast-node-branch.o ast-node-check.o ast-node-const.o ast-node-conv.o ast-node-data.o ast-node-decl.o ast-node-call.o ast-node-arg.o ast-node-idx.o ast-node-iif.o ast-node-misc.o ast-node-ptr.o ast-node-scope.o ast-node-uop.o ast-node-var.o ast-node-typeini.o ast-optimize.o ast-node-proc.o ast-helper.o ast-misc.o ast-vectorize.o dstr.o edbg_stab.o emit.o emit_x86.o emit_SSE.o fb.o fb-main.o error.o hlp.o hlp-str.o ir.o ir-tac.o  ir-hlc.o hash.o flist.o list.o stack.o pool.o lex.o lex-utf.o pp.o pp-cond.o pp-define.o pp-pragma.o  parser-assignment.o parser-comment.o parser-decl-const.o  parser-decl-enum.o parser-decl-option.o parser-decl-proc-params.o parser-decl-proc.o parser-decl-struct.o  parser-decl-symb-init.o parser-decl-symbtype.o parser-decl-typedef.o parser-decl-var.o parser-decl.o parser-identifier.o parser-inlineasm.o parser-label.o  parser-proccall-args.o parser-proccall.o parser-statement.o parser-toplevel.o parser-compound.o parser-compound-do.o parser-compound-for.o parser-compound-if.o parser-compound-scope.o parser-compound-select.o parser-compound-namespace.o parser-compound-select-const.o parser-compound-while.o parser-compound-extern.o  parser-compound-with.o parser-proc.o parser-quirk-array.o parser-decl-def.o parser-quirk-casting.o parser-quirk-console.o parser-quirk-data.o parser-quirk-error.o parser-quirk-file.o parser-quirk-goto-return.o parser-quirk-iif.o parser-quirk-math.o parser-quirk-on.o parser-quirk-peekpoke.o parser-quirk-string.o parser-quirk-vafirst.o parser-quirk-mem.o parser-quirk.o parser-quirk-gfx.o parser-expr-atom.o parser-expr-binary.o parser-expr-constant.o parser-expr-function.o parser-expr-unary.o parser-expr-variable.o reg.o rtl.o rtl-array.o rtl-console.o rtl-data.o rtl-error.o rtl-file.o rtl-gfx.o rtl-gosub.o rtl-macro.o rtl-math.o rtl-mem.o rtl-print.o rtl-profile.o rtl-string.o rtl-system.o symb.o  symb-const.o symb-data.o  symb-define.o symb-enum.o symb-keyword.o symb-label.o symb-proc.o symb-scope.o symb-struct.o symb-typedef.o symb-var.o symb-namespace.o  symb-mangling.o symb-comp.o parser-quirk-thread.o rtl-oop.o rtl-system-thread.o ir-llvm.o objinfo.o ast-node-macro.o ir-gas64.o

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 7 guests