Modify this to suit:
1. You need to declare variables with global scope for proper linkage, so, for example:
Code:
/*globals*/
int *int_ptr __asm__ ( "int_ptr" );
float floatval __asm__( "floatval" );
2. Then in your FloatToInt fn, just doing it by assignment, ie.:
Code:
inline void FloatToInt(int *int_pointer, float f)
{
int_ptr=int_pointer;
floatval=f;
__asm__("fld floatval");
__asm__("mov edx, int_ptr");
__asm__("FRNDINT");
__asm__("fistp dword ptr [edx]");
}
You'll probably want to rewrite the fn so it doesn't take any parameters and make other changes to use the global variables directly - I just did it this way as proof of concept.
Used: gcc -o test.exe test.c -masm=intel (winxp, gcc 3.2.3)
Output:
10000000 sin and cos computed in 3781 ticks with standard math funcs
10000000 sin and cos computed in 1125 ticks with fast[cos/sin]
And change void main to int main in the original example, of course.
******************************
edit: Just noticed the name 'Linuxdude' so, for linux:
1. Remove conio.h, assert.h includes and getch(); in 'main' fn.
2. You need to declare variables with global scope for proper linkage, so, for example:
Code:
/*globals*/
/*with linux you don't need to use following syntax - normal declaration is sufficient*/
int *int_ptr __asm__ ( "int_ptr" );
float floatval __asm__( "floatval" );
3. Then in your FloatToInt fn, just doing it by assignment, ie.:
Code:
inline void FloatToInt(int *int_pointer, float f)
{
int_ptr=int_pointer;
floatval=f;
__asm__(".intel_syntax noprefix"); /*kills error: too many memory references for mov*/
__asm__("fld floatval");
__asm__("mov edx, int_ptr");
__asm__("FRNDINT");
__asm__("fistp dword ptr [edx]");
}
You'll probably want to rewrite the fn so it doesn't take any parameters and make other changes to use the global variables directly - I just did it this way as proof of concept.
Used(fedora, gcc 3.3.2): gcc -o test.exe test.c -masm=intel -lm
Output:
10000000 sin and cos computed in 4410000 ticks with standard math funcs
10000000 sin and cos computed in 3450000 ticks with fast[cos/sin]
(slower machine)