Note that there are some explanatory texts on larger screens.

plurals
  1. POUse GCC generated assembler inside C++ Builder
    text
    copied!<p>I'm using C++builder for GUI application on Win32. Borland compiler optimization is very bad and does not know how to use SSE. I have a function that is 5 times faster when compiled with mingw gcc 4.7. I think about asking gcc to generate assembler code and then use this cod inside my C function because Borland compiler allows inline assembler.</p> <p>The function in C looks like this :</p> <pre><code>void Test_Fn(double *x, size_t n,double *AV, size_t *mA, size_t NT) { double s = 77.777; size_t m = mA[NT-3]; AV[2]=x[n-4]+m*s; } </code></pre> <p>I made the function code very simple in order to simplify my question. My real function contains many loops.</p> <p>The Borland C++ compiler generated this assembler code :</p> <pre><code> ; ; void Test_Fn(double *x, size_t n,double *AV, size_t *mA, size_t NT) ; @1: push ebp mov ebp,esp add esp,-16 push ebx ; ; { ; double s = 77.777; ; mov dword ptr [ebp-8],1580547965 mov dword ptr [ebp-4],1079210426 ; ; size_t m = mA[NT-3]; ; mov edx,dword ptr [ebp+20] mov ecx,dword ptr [ebp+24] mov eax,dword ptr [edx+4*ecx-12] ; ; AV[2]=x[n-4]+m*s; ; ?live16385@48: ; EAX = m xor edx,edx mov dword ptr [ebp-16],eax mov dword ptr [ebp-12],edx fild qword ptr [ebp-16] mov ecx,dword ptr [ebp+8] mov ebx,dword ptr [ebp+12] mov eax,dword ptr [ebp+16] fmul qword ptr [ebp-8] fadd qword ptr [ecx+8*ebx-32] fstp qword ptr [eax+16] ; ; } ; ?live16385@64: ; @2: pop ebx mov esp,ebp pop ebp ret </code></pre> <p>While the gcc generated assembler code is :</p> <pre><code> _Test_Fn: mov edx, DWORD PTR [esp+20] mov eax, DWORD PTR [esp+16] mov eax, DWORD PTR [eax-12+edx*4] mov edx, DWORD PTR [esp+8] add eax, -2147483648 cvtsi2sd xmm0, eax mov eax, DWORD PTR [esp+4] addsd xmm0, QWORD PTR LC0 mulsd xmm0, QWORD PTR LC1 addsd xmm0, QWORD PTR [eax-32+edx*8] mov eax, DWORD PTR [esp+12] movsd QWORD PTR [eax+16], xmm0 ret LC0: .long 0 .long 1105199104 .align 8 LC1: .long 1580547965 .long 1079210426 .align 8 </code></pre> <p>I like to get help about how the function arguments acces is done in gcc and Borland C++. My function in C++ for Borland would be something like :</p> <pre><code> void Test_Fn(double *x, size_t n,double *AV, size_t *mA, size_t NT) { __asm { put gcc generated assembler here } } </code></pre> <p>Borland starts using <code>ebp</code> register while gcc use <code>esp</code> register. Can I force one of the compilers to generate compatible code for accessing the arguments using some calling conventions like cdecl ou stdcall ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload