/*****************************************************************************
 * $Id: transform_x86_sse.hh,v 1.1 2006/10/21 00:19:08 devel Exp $
 * @file
 * @author	Jim E. Brooks  http://www.jimbrooks.org
 *//*
 * LEGAL:	COPYRIGHT (C) 2004 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE (GPL).
 *****************************************************************************/

#ifndef TRANSFORM_X86_SSE_HH
#define TRANSFORM_X86_SSE_HH

#include <unistd.h>
#include <sys/times.h>
#include <time.h>

//------------------------------------------------------------------------------
// gfx (stripped-down)

typedef float fp;

struct EyeVertex
{
	EyeVertex( void ) { x = y = z = unused = 0.0; }
	fp x, y, z, unused;
};

struct WorldVertex
{
	WorldVertex( void ) { x = y = z = unused = 0.0; }
	fp x, y, z, unused;
};

enum { Xx, Xy, Xz, Xs,
       Yx, Yy, Yz, Ys,
       Zx, Zy, Zz, Zs,
       Ox, Oy, Oz, Os };

// Matrix.
fp m[16];

//------------------------------------------------------------------------------
// GNU gcc/g++

typedef float v4sf __attribute__ ((vector_size (4 * sizeof (float))));

/// FP4 is a vector type that underlies the fp4 union.
typedef v4sf FP4;

/// fp4 is union of FP4 and float[4].
union fp4
{
	FP4		v;
	float	f[4];
};

/// Cast a fp* to a pointer to a 4-element float vector and dereference it.
#define FP_FP4( fpPtr )	( *((FP4*)(fpPtr)) )

//------------------------------------------------------------------------------

void
PrintTimeDelta( struct tms& time1, struct tms& time2 )
{
	// POSIX.
	int clocksPerSec = sysconf( _SC_CLK_TCK );
	double secUserSys = double(time2.tms_utime+time2.tms_stime - time1.tms_utime + time1.tms_stime) / double(clocksPerSec);
	double secUser	  = double(time2.tms_utime                 - time1.tms_utime                ) / double(clocksPerSec);

	cout << "secs (user+sys) = " << secUserSys << endl;
	cout << "secs (user)     = " << secUser    << endl;
}

#endif // TRANSFORM_X86_SSE_HH
