Jump to content
  • Advertisement

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

Guest Anonymous Poster

#define START_TIMER(x)\
_asm cpuid\
_asm rdtsc\
_asm mov x, eax

#define STOP_TIMER(x)\
_asm rdtsc\
_asm sub eax, x\
_asm mov x, eax

#include <cstdlib>
#include <cstdio>

typedef unsigned timer_t;

float DivTest(const float* p, size_t nSize, float* pDiv)
{
float f = 0.f;
for(size_t n = 0; n != nSize; n += 4)
{
f += p[n] / pDiv[n];
f += p[n + 1] / pDiv[n + 1];
f += p[n + 2] / pDiv[n + 2];
f += p[n + 3] / pDiv[n + 3];

}
return f;
}

float MulTest(const float* p, size_t nSize, float* pMul)
{
float f = 0.f;
for(size_t n = 0; n != nSize; n += 4)
{
f += p[n] * pMul[n];
f += p[n + 1] * pMul[n + 1];
f += p[n + 2] * pMul[n + 2];
f += p[n + 3] * pMul[n + 3];
}
return f;

}

int main(void)
{
const int size = 2048;
float fValues[size];
float fMuls[size];
float fDivs[size];
for(int i = 0; i != size; ++i)
{
fValues = float(rand());
fDivs = float(1 + rand() % 4);
fMuls = 1.f / fDivs;
}

timer_t tDiv;
START_TIMER( tDiv);
float fDiv = DivTest( fValues, size, fDivs);
STOP_TIMER( tDiv);

timer_t tMul;
START_TIMER( tMul);
float fMul = MulTest( fValues, size, fMuls);
STOP_TIMER( tMul);

if( fDiv == fMul)
printf("div:%d cycles\nmul:%d cycles\n", tDiv / size, tMul / size);
else
fprintf( stderr, "error");
system("pause");
}

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Promit
I know strike works.

I want S to work!
We're trying to wear your fingers down by making you type extra letters. It's a cunning, dastardly plot.

Share this post


Link to post
Share on other sites
are you breaking the forums? or why is the formating broken? could also be the banner on the topright, but i dont think after refreshing 3 times that 3different banners are broken

edit: phew now its ok, you know that this site looks like sh*t without the coloring?
edit2: strange, the last post before my reply is a half day old, or more, but it was listed in active topics under the first 10 or so...


T2k

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!