inline __fastcall __declspec( naked ) long FixedMul(
long register num1,
long register num2)
{
_asm
{
push edx;
mov eax, [num1];
mov edx, [num2];
imul edx;
add eax, 0x8000;
adc edx, 0;
shrd eax,edx,16;
pop edx;
ret;
}
}
I''m using VC++. Do you think it''s the fastest I can get from a function? Are those things useless for an inline function (I mean "naked", "__fastcall" and the register parameters.
How can I know in which register a register variable is put?
Again, thanks for answering my stupid questions...
Programming is:
A.The art of debugging a blank sheet of paper (or an empty file).B.A pastime similar to banging one's head against a wall, but with fewer opportunities for reward.C.The most fun you can have with your clothes on (although clothes are not mandatory).
Are there anything more?
Just to see the most ridiculous function declaration I''ve ever made:
Now I know what I'm made of, and I'm afraid of it...
I think that's pretty fast.
Just one thing: don´t put this function in a lib, just put it in a header and "include" it whenever you want to use it, because if you don't do this way, there will be no inlining. The compiler must know the source code of an asm function in order to inline it (at lest VC++ 6.0)
(i'm quite sure of this, because some time ago i made some functions for fixed math, and that was the only way i found to make them to be inlined)
BTW, yes, those things are usseles in an inline function.
And in VC++ you can't pass parameters to user defined functions in registers. (I remember that with Watcom C++ you could)
Edited by - Danielillo on June 16, 2000 6:59:37 PM
Edited by - Danielillo on June 16, 2000 7:00:19 PM
Edited by - Danielillo on June 16, 2000 7:07:04 PM
Just one thing: don´t put this function in a lib, just put it in a header and "include" it whenever you want to use it, because if you don't do this way, there will be no inlining. The compiler must know the source code of an asm function in order to inline it (at lest VC++ 6.0)
(i'm quite sure of this, because some time ago i made some functions for fixed math, and that was the only way i found to make them to be inlined)
BTW, yes, those things are usseles in an inline function.
And in VC++ you can't pass parameters to user defined functions in registers. (I remember that with Watcom C++ you could)
Edited by - Danielillo on June 16, 2000 6:59:37 PM
Edited by - Danielillo on June 16, 2000 7:00:19 PM
Edited by - Danielillo on June 16, 2000 7:07:04 PM
I just found my old routines. Here you are, so you can compare:
Edited by - Danielillo on June 16, 2000 7:22:38 PM
#ifndef FUNCIONES_Y_MACROS_DE_MATEMATICA_DE_COMA_FIJA#define FUNCIONES_Y_MACROS_DE_MATEMATICA_DE_COMA_FIJAtypedef long int FixedPoint; #pragma warning(disable: 4035)__forceinline FixedPointFixedPointMul(FixedPoint a,FixedPoint b){ __asm { mov EAX,a; mov EDX,b; imul EDX; shrd EAX,EDX,16; }}__forceinline FixedPointFixedPointDiv(FixedPoint a,FixedPoint b ){ __asm { mov EDX,a; mov EBX,b; xor EAX,EAX; shrd EAX,EDX,16; sar EDX, 16; idiv EBX; }}#pragma warning(default: 4035)#define IntToFixedPoint(x) ((FixedPoint)(x)<<16)#define FixedPointToInt(x) ((int)(x)>>16)#define RoundFixedPoint(x) (((int)(x)+32767)>>16)#define TruncateFixedPoint(x) ((int) ((x)>>16))#define FloatToFixedPoint(x) (FixedPoint)((x)*65536.0)#define FixedPointToFloat(x) ((x)/65536.0)#endif
Edited by - Danielillo on June 16, 2000 7:22:38 PM
Gracias Danelillo.
Voy a intentarlo... pero hago una "classe" (???) de FixedPoint y no puedo utilisar eses definicion, y por que esos son funcion llamadas muchas veces necessito el metodo el mas rapido.
Gracias otra vez.
Programming is: A.The art of debugging a blank sheet of paper (or an empty file).B.A pastime similar to banging one's head against a wall, but with fewer opportunities for reward.C.The most fun you can have with your clothes on (although clothes are not mandatory).
Voy a intentarlo... pero hago una "classe" (???) de FixedPoint y no puedo utilisar eses definicion, y por que esos son funcion llamadas muchas veces necessito el metodo el mas rapido.
Gracias otra vez.
Programming is: A.The art of debugging a blank sheet of paper (or an empty file).B.A pastime similar to banging one's head against a wall, but with fewer opportunities for reward.C.The most fun you can have with your clothes on (although clothes are not mandatory).
Now I know what I'm made of, and I'm afraid of it...
I don''t quite undertand what you intended to mean:
Are you making a FixedPoint Class? I think a class is not fast enough for your needs.
Or you just mean that my source code is a class, and you don''t want to use one? No, it isn''t. They are just two old c functions and some macros. I just put the definition and the implementation in the header file, just to make the compiler inline them.
This is the fastest method i found. Just copy and paste it, give it a try (make program tha do a lot of calcs and profile the functions), and tell me about it.
You''re welcome
Where did you learn Spanish??? Yours It''s pretty good, so keep learning it.
Are you making a FixedPoint Class? I think a class is not fast enough for your needs.
Or you just mean that my source code is a class, and you don''t want to use one? No, it isn''t. They are just two old c functions and some macros. I just put the definition and the implementation in the header file, just to make the compiler inline them.
This is the fastest method i found. Just copy and paste it, give it a try (make program tha do a lot of calcs and profile the functions), and tell me about it.
You''re welcome
Where did you learn Spanish??? Yours It''s pretty good, so keep learning it.
Thanks I''m still trying to learn it but it is difficult to find ppl out on the internet willing to help me out.
I''ve spent a whole month in spain for the year 2k and I''m planning to go back there some day (maybe next year).
Where are you from in Madrid?
BTW, I know what a class is . I know C++, templates and most of the concepts in it...
What I really want is a class because I have started my whole engine with floats (I know this is stupid), and now I don''t want to change "a=b*c" for "a=FixedMul(b,c);". I think it would be a real waste of time...
So I want to make a class with overloaded operators and then I just change the float variables for FixedPoint ones without changing every call.
Programming is: A.The art of debugging a blank sheet of paper (or an empty file).B.A pastime similar to banging one's head against a wall, but with fewer opportunities for reward.C.The most fun you can have with your clothes on (although clothes are not mandatory).
I''ve spent a whole month in spain for the year 2k and I''m planning to go back there some day (maybe next year).
Where are you from in Madrid?
BTW, I know what a class is . I know C++, templates and most of the concepts in it...
What I really want is a class because I have started my whole engine with floats (I know this is stupid), and now I don''t want to change "a=b*c" for "a=FixedMul(b,c);". I think it would be a real waste of time...
So I want to make a class with overloaded operators and then I just change the float variables for FixedPoint ones without changing every call.
Programming is: A.The art of debugging a blank sheet of paper (or an empty file).B.A pastime similar to banging one's head against a wall, but with fewer opportunities for reward.C.The most fun you can have with your clothes on (although clothes are not mandatory).
Now I know what I'm made of, and I'm afraid of it...
Oh and I know how fast FPs are... I used them when particing under dos (under TPascal) a real while ago...
And I think I will still gain speed by using a FP class instead of standard float call.
Programming is: A.The art of debugging a blank sheet of paper (or an empty file).B.A pastime similar to banging one's head against a wall, but with fewer opportunities for reward.C.The most fun you can have with your clothes on (although clothes are not mandatory).
And I think I will still gain speed by using a FP class instead of standard float call.
Programming is: A.The art of debugging a blank sheet of paper (or an empty file).B.A pastime similar to banging one's head against a wall, but with fewer opportunities for reward.C.The most fun you can have with your clothes on (although clothes are not mandatory).
Now I know what I'm made of, and I'm afraid of it...
Oh, that makes much more sense. To make a fast class, just declare all your important member functions with __forceinline, and place the code for them on the header file of the class. In order to avoid an annoying warning message that VC is always spitting at you, use the pragma directive, just as above. I think that will be as fast as c functions, and you will benefit from operator overloading.
Hope it helps!
No te preocupes por tu español, en solo un mes es bastante dificil dominarlo. Yo llevo casi 16 años estudiando inglés y todavía no lo controlo. He estado en Canada dos veces, en dos veranos distintos durante un mes cada una de las veces, en Toronto, aprendiendo inglés; teneis un pais muy bonito, y una gente maravillosa.
Por cierto, vivo justo en el centro de la ciudad, en Plaza de España. Es un bonito lugar para vivir, y ademas tienes todo bastante cerca.
Hasta luego, espero que nos "veamos" pronto
Hope it helps!
No te preocupes por tu español, en solo un mes es bastante dificil dominarlo. Yo llevo casi 16 años estudiando inglés y todavía no lo controlo. He estado en Canada dos veces, en dos veranos distintos durante un mes cada una de las veces, en Toronto, aprendiendo inglés; teneis un pais muy bonito, y una gente maravillosa.
Por cierto, vivo justo en el centro de la ciudad, en Plaza de España. Es un bonito lugar para vivir, y ademas tienes todo bastante cerca.
Hasta luego, espero que nos "veamos" pronto
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement