gen -gcc overlooking something, help please.

General FreeBASIC programming questions.
akumadantai
Posts: 34
Joined: Apr 03, 2012 13:09

gen -gcc overlooking something, help please.

Postby akumadantai » Jul 04, 2013 19:50

Hello,
i have encountered a problem with the -gen gcc backend, in case of : "how do i set it up ?"
i have not used that since i posted the software 3d point rendering program a couple of months ago...

now i get a constant "CreateProcess: No such file or directory", error message...
currently i downloaded the GCC freebasic compiler from sourceforge, but i seem to remember that that was not enough...
dkl
Site Admin
Posts: 3206
Joined: Jul 28, 2005 14:45
Location: Germany

Re: gen -gcc overlooking something, help please.

Postby dkl » Jul 04, 2013 20:09

It needs gcc.exe at bin\win32\gcc.exe and cc1.exe at bin\libexec\gcc\i686-w64-mingw32\4.7.3\cc1.exe. These should be included in the FB-win32-gcc-4.7.3.zip package.

(of course, the cc1.exe path will be different for different versions of gcc.exe)
akumadantai
Posts: 34
Joined: Apr 03, 2012 13:09

Re: gen -gcc overlooking something, help please.

Postby akumadantai » Jul 04, 2013 20:24

thank you for the reply.
although i did not have this problem a long time ago, it now seems to fail...

according to my folders, everything is in place, and i already have the version you posted.
yet it still fails...

did it not need a different as, ar, and custom compiled FB... or is it present in all the current FB builds.
because that would explain a lot about what i might be forgetting.

Image
dkl
Site Admin
Posts: 3206
Joined: Jul 28, 2005 14:45
Location: Germany

Re: gen -gcc overlooking something, help please.

Postby dkl » Jul 04, 2013 20:41

Is it really the same gcc.exe? Could it be related to the "C:\Program Files" directory? Does it work when FB is installed in C:\ instead?
akumadantai
Posts: 34
Joined: Apr 03, 2012 13:09

Re: gen -gcc overlooking something, help please.

Postby akumadantai » Jul 04, 2013 20:50

Is it really the same gcc.exe? Could it be related to the "C:\Program Files" directory? Does it work when FB is installed in C:\ instead?


A : exactly the same gcc.exe (and now i even redownloaded it)
B : copy n paste the entire directory to a non user permision drive, and set up the paths in the ide
C : and no...

i will try and fiddle with it along the road... no need to break your head over it yet !
Jonge
Posts: 129
Joined: Jul 17, 2012 17:51
Location: Norway
Contact:

Re: gen -gcc overlooking something, help please.

Postby Jonge » Jul 05, 2013 10:06

-gen gcc dose not seem to be able to compile any source code containing inline ASM:

The example from the ASM block keyword:

Code: Select all

'' This is an example for the x86 architecture.
Function AddFive(ByVal num As Integer) As Integer
    Asm
        mov eax, [num]
        add eax, 5
        mov [Function], eax
    End Asm
End Function

Dim i As Integer = 4

Print "4 + 5 ="; AddFive(i)
Sleep


Output:

Code: Select all

D:\Dev\FreeBASIC-0.90.0\fbc -s console -gen gcc "FbTemp.bas"
FbTemp.c: In function 'ADDFIVE':
FbTemp.c:26:24: error: expected string literal before 'mov'
FbTemp.c:27:24: error: expected string literal before 'add'
FbTemp.c:28:24: error: expected string literal before 'mov'

Make done
fxm
Posts: 8972
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: gen -gcc overlooking something, help please.

Postby fxm » Jul 05, 2013 11:16

Obviously (IMHO):
'-gen gas' compiles directly in ASM.
'-gen gcc' compiles first in C.
Jonge
Posts: 129
Joined: Jul 17, 2012 17:51
Location: Norway
Contact:

Re: gen -gcc overlooking something, help please.

Postby Jonge » Jul 05, 2013 12:11

fxm wrote:Obviously (IMHO):
'-gen gcc' compiles first in C.

[deleted grumpy comment] GCC seems to have the possibility of using in line assembly code(do a google search).

I have not seen any where that inline Asm is not allowed when using -gen gcc. If so, the compiler should stop compilation and tell you that the ASM block is not supported when using -gen gcc.
Last edited by Jonge on Jul 05, 2013 14:50, edited 1 time in total.
TJF
Posts: 3467
Joined: Dec 06, 2009 22:27
Location: N47°, E15°

Re: gen -gcc overlooking something, help please.

Postby TJF » Jul 05, 2013 12:26

Jonge wrote:Off course.. Im not that stupid, GCC seems to have the possibility of using in line assembly code(do a google search).

I have not seen any where that inline Asm is not allowed when using -gen gcc. If so, the compiler should stop compilation and tell you that the ASM block is not supported when using -gen gcc.

GCC is able to handle inline assembler code. But fbc-0.90 doesn't emit propper code yet.

-gen gcc is much better since version 0.90, but it's still WIP (fbc-0.90 is still compiled with -gen gas).
dkl
Site Admin
Posts: 3206
Joined: Jul 28, 2005 14:45
Location: Germany

Re: gen -gcc overlooking something, help please.

Postby dkl » Jul 05, 2013 13:58

As of FB 0.90, -gen gcc expects inline asm to be in GCC's format, i.e. using AT&T syntax, enclosed in string literals, with the needed register/memory input/output constraints.

However there is an fbc -asm intel option that can be used together with -gen gcc, it's a first attempt at accepting normal FB inline asm and generate working GCC inline asm blocks for it. It passes -masm=intel to gcc in order to get it to generate Intel syntax asm in which FB inline asm can be embedded directly. There are two problems with it:
1) gcc's -masm=intel code generation is buggy.
2) -gen gcc generates gcc asm blocks with all possible constraints I could think of (all registers/memory/flags trashed), to match the FB behaviour, but I still cannot be sure it's enough (e.g. currently it only assumes xmmN registers to be trashed if -fpu sse was used, but inline asm could be using SSE without -fpu sse, so it's not 100% safe).
Jonge
Posts: 129
Joined: Jul 17, 2012 17:51
Location: Norway
Contact:

Re: gen -gcc overlooking something, help please.

Postby Jonge » Jul 05, 2013 15:00

Ok. This is not a problem for me, I was just trying out some code that had some parts with in line assembly code, to see any speed difference between GAS and GCC. I'll rewrite the asm parts to FB code. GCC compiled FB code will probably be faster then my simple/noob Assembly code =)
creek23
Posts: 260
Joined: Sep 09, 2007 1:57
Location: Philippines
Contact:

Re: gen -gcc overlooking something, help please.

Postby creek23 » Oct 02, 2013 10:45

dkl wrote:However there is an fbc -asm intel option that can be used together with -gen gcc


Hi dkl,

I tried using FBC -asm intel -gen gcc -R -m source SOURCE.BAS and I got a SOURCE.C but it's not compiling because of a GCC error:

Code: Select all

source.c: In function 'SCREENSYNC':
source.c:2084:87: error: memory input 1 is not directly addressable

I'm not sure I know what to do next. The generated code looks like this:

Code: Select all

2079: TMP$1 = vr$44;
2080: BUFSZ$1 = _ZN3OGL5TEXX$E * _ZN3OGL5TEXY$E;
2081: __asm__ __volatile__( "\tmov esi,[%0]    \n" : "=m" (TMP$1) : "m" (TMP$1) : "cc", "memory", "eax", "ebx", "ecx", "edx", "esp", "edi", "esi" );
2082: __asm__ __volatile__( "\tmov edi,[%0]\n" : "=m" (_ZN3OGL7BUFFER$E) : "m" (_ZN3OGL7BUFFER$E) : "cc", "memory", "eax", "ebx", "ecx", "edx", "esp", "edi", "esi" );
2083: __asm__ __volatile__( "\tadd edi,32\n" :  :  : "cc", "memory", "eax", "ebx", "ecx", "edx", "esp", "edi", "esi" );
2084: __asm__ __volatile__( "\tmov edx,offset %0      \n" : "=m" (_ZN3OGL5CORS$E) : "m" (_ZN3OGL5CORS$E) : "cc", "memory", "eax", "ebx", "ecx", "edx", "esp", "edi", "esi" );
2085: __asm__ __volatile__( "\tmov ecx,[%0]\n" : "=m" (BUFSZ$1) : "m" (BUFSZ$1) : "cc", "memory", "eax", "ebx", "ecx", "edx", "esp", "edi", "esi" );
2086: __asm__ __volatile__( "\tXor eax,eax\n" :  :  : "cc", "memory", "eax", "ebx", "ecx", "edx", "esp", "edi", "esi" );
2087: __asm__ __volatile__( "\t_8TO32_NEXTPIXEL_:\n" :  :  : "cc", "memory", "eax", "ebx", "ecx", "edx", "esp", "edi", "esi" );
2088: __asm__ __volatile__( "\tlodsb\n" :  :  : "cc", "memory", "eax", "ebx", "ecx", "edx", "esp", "edi", "esi" );
2089: __asm__ __volatile__( "\tmov ebx,[EDX+EAX*4]\n" :  :  : "cc", "memory", "eax", "ebx", "ecx", "edx", "esp", "edi", "esi" );
2090: __asm__ __volatile__( "\tmov [edi],ebx\n" :  :  : "cc", "memory", "eax", "ebx", "ecx", "edx", "esp", "edi", "esi" );

The error was on 2084.

SOURCE.C is actually my FB project, btw.

~creek23
dkl
Site Admin
Posts: 3206
Joined: Jul 28, 2005 14:45
Location: Germany

Re: gen -gcc overlooking something, help please.

Postby dkl » Oct 02, 2013 12:12

FB inline ASM and -gen gcc don't play well together usually, so it's not surprising to see a problem coming up there.

Could you post the FB source code corresponding to that source.c? And/or perhaps the full source.c. I wonder what _ZN3OGL5CORS$E really is, it looks like a global variable named ogl.cors (if I demangled that C++ name correctly), but if that's the case it should also just be a global variable in the generated C code and I wonder what problem gcc has with using it in inline ASM like that.
creek23
Posts: 260
Joined: Sep 09, 2007 1:57
Location: Philippines
Contact:

Re: gen -gcc overlooking something, help please.

Postby creek23 » Oct 02, 2013 18:04

Hi dkl,

Not sure how to send the source file over to you. Your email address is not displayed and this forum's email doesn't allow attaching files -- the generated C-source file is 2MB with over 57KLOC, so pasting it wouldn't make sense.

Anyway, I forgot to mention that _ZN3OGL5CORS$E is a static array of ints:

Code: Select all

static integer _ZN3OGL5CORS$E[256];


~creek23
dkl
Site Admin
Posts: 3206
Joined: Jul 28, 2005 14:45
Location: Germany

Re: gen -gcc overlooking something, help please.

Postby dkl » Oct 02, 2013 18:50

You can find my email in here, if you still want to send it, I could use for testing.

---

I've found that with MinGW GCC 4.7.3, the following code produces that error, but it's working with GCC 4.8.1 (both Linux and MinGW):

Code: Select all

static int __a[256];
int main( int argc, char** argv ) {
   __asm__ __volatile__( "\tmov eax, dword ptr %0\n" : "=m" (__a) : "m" (__a) : "cc", "memory", "eax", "ebx", "ecx", "edx", "esp", "edi", "esi" );
   return 0;
}


Using just a global variable instead of an array works with both versions of MinGW GCC. Using array[0] instead of just array also helps, and I think that's what fbc should be doing. I'm not sure whether GCC 4.8 now accepts the array directly on purpose, or whether that's a bug, but passing the array's first element should always work.

Return to “General”

Who is online

Users browsing this forum: No registered users and 6 guests