vendredi 31 juillet 2015

Compare float array as int array

I'm trying to write a deeply optimized Skeleton Animation library. My goal is to get 10000 characters onscreen at 60 fps on my i7. As I working on keyframe animation, I realized I need a binary search algorithm on the timeline to determine which two keyframe should i interpolate. I did this and found that using float to store keyframes is faster than using integer, because at the end i must calculate

(frameNumber-this->frameNumber[imin])/(this->frameNumber[imax]-this->frameNumber[imin])

The conversion from int to float spent some cycles. Then I discovered that in the asm there a a lot of fpu instructions. I'm worrying they might be slower than integer.

So here is the question. Can I convert an array of sorted floating point numbers to an int* and run a binary search on it?

That means:

void binary_search(float key,float* array,...)
{
    int key_integer=*(int*)&key;
    int* array_intege(int*)array;
    binary_search_for_integers(key_integer,array_integer,...);
}

Or my above conclusion are wrong? (Such as casting int to float is not so costy, or comparision between floating points is the same fast as integers?

Thanks a lot!

Aucun commentaire:

Enregistrer un commentaire