// Liquid3D - Moteur 3D C++ NDS par Morukutsu
// Surcouche de l'ulibrary de Brunni
// Version alpha 1

#include "L3DTypes.h"

namespace L3D
{
	void v_fnormalizef32(int32* a)
	{
	   int32 m;
	   m = sqrtf32(dotf32(a,a));
	   // get reciprocal, not using divf32() DIV_32_32 is half the clks: numerator = 1
	   REG_DIVCNT = DIV_32_32;
	   while (REG_DIVCNT & DIV_BUSY) ;
	   REG_DIV_NUMER_L = 4096 << 12;
	   REG_DIV_DENOM_L = m;
	   while (REG_DIVCNT & DIV_BUSY) ;
	   m = REG_DIV_RESULT_L;
	   // multiply reciprocal instead of 3 divides
	   a[0] = mulf32(a[0],m);
	   a[1] = mulf32(a[1],m);
	   a[2] = mulf32(a[2],m);
	}
	void v2_fnormalizef32(int32* a)
	{
	   int32 m;
	   m = sqrtf32(dotf32(a,a));
	   // get reciprocal, not using divf32() DIV_32_32 is half the clks: numerator = 1
	   REG_DIVCNT = DIV_32_32;
	   while (REG_DIVCNT & DIV_BUSY) ;
	   REG_DIV_NUMER_L = 4096 << 12;
	   REG_DIV_DENOM_L = m;
	   while (REG_DIVCNT & DIV_BUSY) ;
	   m = REG_DIV_RESULT_L;
	   // multiply reciprocal instead of 3 divides
	   a[0] = mulf32(a[0],m);
	   a[1] = mulf32(a[1],m);
	}
};