Archived

This topic is now archived and is closed to further replies.

Are there anything more?

This topic is 6388 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Just to see the most ridiculous function declaration I''ve ever made:
    
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).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
I just found my old routines. Here you are, so you can compare:

        
#ifndef FUNCIONES_Y_MACROS_DE_MATEMATICA_DE_COMA_FIJA
#define FUNCIONES_Y_MACROS_DE_MATEMATICA_DE_COMA_FIJA

typedef long int FixedPoint;

#pragma warning(disable: 4035)

__forceinline FixedPoint
FixedPointMul(FixedPoint a,FixedPoint b)
{
__asm
{
mov EAX,a;
mov EDX,b;
imul EDX;
shrd EAX,EDX,16;
}
}

__forceinline FixedPoint
FixedPointDiv(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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.


Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites