Jump to content
  • Advertisement
Sign in to follow this  
Dirk Gregorius

SinCos assembler function

This topic is 4952 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

I came across a a simple SinCos() function in one of an example from Intel's math library ( AMath library ):
void _sincosf( float x, float* s, float* c )
{
	__asm
	{
		fld	dword ptr x
		mov	eax, s
		mov	edx, c
		fsincos
		fstp	dword ptr [edx]
		fstp	dword ptr [eax]
	}
}


1. On which processors does this run? 2. Can I pass references instead of pointees? I tried to pass float& instead of float* and the mov instruction seems to work in both debug and relase mode. But I am not quite sure if this allowed and might fail under some circumstances. -Dirk BTW: I am looking for an inverse square root function as well. This function is about 50% faster then calling sinf() and cosf() independently and there are no differences in the results.

Share this post


Link to post
Share on other sites
Advertisement
Your code needs a 486 prosessor to run.

This should work too: (I haven't tested)


void _sincosf( float x, float* s, float* c )
// eax contains address of s
// edx contains address of c
// x is passed over the stack
{
__asm
{
fld x
fsincos
fstp dword ptr [edx]
fstp dword ptr [eax]
}
}




but this works for sure: (Delphi code)


procedure SinCosS(const Theta: Single; var Sin, Cos: Single); register;
// EAX contains address of Sin
// EDX contains address of Cos
// Theta is passed over the stack
asm
FLD Theta
FSINCOS
FSTP DWORD PTR [EDX] // cosine
FSTP DWORD PTR [EAX] // sine
end;


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!