A couple of years ago, working with OpenWatcom for Windows, I was
able to wrote the inline assembly code shown below. I spent a while
reading and by trail an error I made it work.
I was trying to test the efficiency of the "inner_product()" function
in C++.
Now I am working in Linux and I would like to compile it with g++.
Is the inline assembly of g++ similar?
Can some of this code be reused in g++?
I like to thank all of you in advance for your comments.
Edgar Black
+++++++++++++++++++++++++++++++++++++++++++++++++
double dot_product(double *array1, double *array1End, double *array2)
{
double result;
const unsigned int n = array1End-array1;
_asm {
fldz
mov ecx, n
cmp ecx,0
jz finish
mov esi,array1
mov edi,array2
more:
fld qword ptr [esi]
fmul qword ptr [edi]
faddp st(1),st(0)
add esi,8
add edi,8
loop more
finish:
fstp qword ptr result
} // end asm //
return (result);
} // end of dot_product//
+++++++++++++++++++++++++++++++++++++++++++++++++
> Hi all,
>
> A couple of years ago, working with OpenWatcom for Windows, I was
> able to wrote the inline assembly code shown below. I spent a while
> reading and by trail an error I made it work.
>
> I was trying to test the efficiency of the "inner_product()" function
> in C++.
>
> Now I am working in Linux and I would like to compile it with g++.
>
> Is the inline assembly of g++ similar?
> Can some of this code be reused in g++?
inline assembler of gcc is different. For example all register are
prefixed by "%". All constants are prefixed by "$".
See: http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html
Here a simple example
#include <iostream>
int function(void)
{
int result;
asm(
"mov $0x2, %%eax\n\t"
"mov $3, %%ebx\n\t"
"add %%ebx, %%eax\n\t"
"mov %%eax, %0\n\t"
: "=r"(result)
:
: "%eax", "%ebx"
);
return result;
}
int main(void)
{
std::cout << function() << std::endl;
return 0;
}
Viele Grᅵᅵe
Sebastian Waschik