|
From: <axl...@us...> - 2010-04-27 18:20:49
|
Revision: 705
http://hgengine.svn.sourceforge.net/hgengine/?rev=705&view=rev
Author: axlecrusher
Date: 2010-04-27 18:20:41 +0000 (Tue, 27 Apr 2010)
Log Message:
-----------
visual studio and GCC Alignment
Modified Paths:
--------------
Mercury2/src/MQuaternion.h
Mercury2/src/MercuryMath.h
Mercury2/src/MercuryMatrix.cpp
Mercury2/src/MercuryMatrix.h
Mercury2/src/MercuryUtil.h
Modified: Mercury2/src/MQuaternion.h
===================================================================
--- Mercury2/src/MQuaternion.h 2010-04-27 18:16:51 UTC (rev 704)
+++ Mercury2/src/MQuaternion.h 2010-04-27 18:20:41 UTC (rev 705)
@@ -7,7 +7,7 @@
class MercuryMatrix;
///Mathematical Quaternion (Used for Rotation)
-class MQuaternion {
+VC_ALIGN(16) class MQuaternion {
public:
enum WXYZ { QW = 0, QX, QY, QZ };
@@ -81,7 +81,7 @@
//Also, for most operations, it appeared to go slower. All the moving in and out of these variables
//is disadvantagious.
float m_wxyz[4];
-} M_ALIGN(32);
+} CC_ALIGN(16);
///Produce a matrix out of a rotation x, then y then z (how Mercury does it)
void AngleMatrix (const MercuryVector & angles, MercuryMatrix & mat );
Modified: Mercury2/src/MercuryMath.h
===================================================================
--- Mercury2/src/MercuryMath.h 2010-04-27 18:16:51 UTC (rev 704)
+++ Mercury2/src/MercuryMath.h 2010-04-27 18:20:41 UTC (rev 705)
@@ -1,5 +1,5 @@
#ifndef _MERCURYMATH_H
-#define _MERCURYMATH_H
+#define _MERCURYMATH_H
#include <math.h>
#ifdef HGENGINE
@@ -8,13 +8,21 @@
#endif
#endif
+#if defined(__GNUC__)
+#define VC_ALIGN(n)
+#define CC_ALIGN(n) __attribute__((aligned(n)))
+#else
+#define VC_ALIGN(n) __declspec(align(n))
+#define CC_ALIGN(n)
+#endif
+
#ifdef USE_SSE
#include <xmmintrin.h>
#define PREFETCH(a,sel) _mm_prefetch(a,sel); //prefetch a cache line (64 bytes)
#else
#define PREFETCH(a,sel) ; //prefetch a cache line (64 bytes)
#endif
-class FloatRow
+VC_ALIGN(16) class FloatRow
{
public:
inline operator float*() { return (float*)&m_floats; }
@@ -27,9 +35,10 @@
inline operator __m128&() { return m_floats; }
inline operator const __m128&() const { return m_floats; }
- __m128 m_floats __attribute__((aligned(16)));
+// __m128 m_floats __attribute__((aligned(16)));
+ __m128 m_floats;
#endif
-};
+} CC_ALIGN(16);
#ifdef WIN32
#include <limits>
@@ -99,7 +108,7 @@
//http://graphics.stanford.edu/~seander/bithacks.html
#define SetBit(x,mask,t) ((x & ~mask) | (-t & mask)) /*superscalar CPU version*/
-#define GetBit(x,mask) (x & mask)
+#define GetBit(x,mask) ((x & mask)>0)
//void Float2FloatRow(const float* f, FloatRow& r);
//void FloatRow2Float(const FloatRow& fr, float* f);
Modified: Mercury2/src/MercuryMatrix.cpp
===================================================================
--- Mercury2/src/MercuryMatrix.cpp 2010-04-27 18:16:51 UTC (rev 704)
+++ Mercury2/src/MercuryMatrix.cpp 2010-04-27 18:20:41 UTC (rev 705)
@@ -1,7 +1,7 @@
#include "MercuryMatrix.h"
#include <MercuryLog.h>
-float base_matrix_identity[16] = {
+VC_ALIGN(16) float base_matrix_identity[16] CC_ALIGN(16) = {
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
@@ -18,7 +18,8 @@
Copy16f(m_matrix[0], base_matrix_identity );
#endif
*/
- *this = Identity();
+// *this = Identity();
+ LoadIdentity();
}
const MercuryMatrix& MercuryMatrix::operator=(const MercuryMatrix& m)
@@ -61,6 +62,11 @@
return IdentityMatrix;
}
+void MercuryMatrix::LoadIdentity()
+{
+ Copy16f(m_matrix, base_matrix_identity );
+}
+
void MercuryMatrix::Translate(float x, float y, float z)
{
MercuryMatrix m;
Modified: Mercury2/src/MercuryMatrix.h
===================================================================
--- Mercury2/src/MercuryMatrix.h 2010-04-27 18:16:51 UTC (rev 704)
+++ Mercury2/src/MercuryMatrix.h 2010-04-27 18:20:41 UTC (rev 705)
@@ -8,7 +8,7 @@
#include <MQuaternion.h>
///General Purpose 4x4 row-major matrix
-class MercuryMatrix
+ VC_ALIGN(16) class MercuryMatrix
{
private:
///[row][column] (The internal matrix)
@@ -52,14 +52,10 @@
void Zero();
static const MercuryMatrix& Identity();
+ void LoadIdentity();
void Print() const;
-}
-#if !defined( WIN32 ) || defined( _MSC_VER )
-M_ALIGN(64);
-#else
-M_ALIGN(16);
-#endif
+} CC_ALIGN(16);
//namespace MercuryMath
//{
Modified: Mercury2/src/MercuryUtil.h
===================================================================
--- Mercury2/src/MercuryUtil.h 2010-04-27 18:16:51 UTC (rev 704)
+++ Mercury2/src/MercuryUtil.h 2010-04-27 18:20:41 UTC (rev 705)
@@ -19,12 +19,6 @@
void* mmemalign(size_t align, size_t size, void*& mem);
bool isAligned(size_t align, const void* mem);
-#if defined(__GNUC__)
-#define M_ALIGN(n) __attribute__((aligned(n)))
-#else
-#define M_ALIGN(n)
-#endif
-
///Make a string all upper case
MString ToUpper(const MString & s);
@@ -96,10 +90,10 @@
///Open up filename: sFileName and dump it into a new buffer; you must delete the return value when done.
///The return value is -1 if there was an issue, otherwise it is valid.
long FileToString( const MString & sFileName, char * & data );
-
-///Take a string and write it to the hard drive as a file. True indicates everything is okay.
-bool StringToFile( const MString & sFileName, const MString & data );
+///Take a string and write it to the hard drive as a file. True indicates everything is okay.
+bool StringToFile( const MString & sFileName, const MString & data );
+
/* These two functions are very different */
/// nextPow2 will go to the NEXT power of 2 even if x is already a power of 2.
inline int nextPow2(int x) { int num = 1; while(num <= x) num <<= 1; return num; }
@@ -135,20 +129,20 @@
MString ConvertToUnformatted( const MString & cf );
///millisecond sleep
-void msleep(uint32_t msec);
-
-///Utility linear function, in = [0..1] out = [0..1]; respectively, if slice >= 1
-float FLinear( float in, float slice = 1. );
-
-///Utility exponential function, in = [0..1] out = [0..1]; respectively; regardless of pow. If pow == 1, would be identical to linear.
-float FExponential( float in, float powx = 1. );
-
-///Utility step function; out = 0 when in < stepplace; out = 1 when in >= stepplace
-float FStep( float in, float stepplace = 1. );
-
-///Utility sigmoid function; in = [0..1] out = [0..1]; speed is the slope of change in the middle.
-float FSigmoid( float in, float fspeed = 1. );
+void msleep(uint32_t msec);
+///Utility linear function, in = [0..1] out = [0..1]; respectively, if slice >= 1
+float FLinear( float in, float slice = 1. );
+
+///Utility exponential function, in = [0..1] out = [0..1]; respectively; regardless of pow. If pow == 1, would be identical to linear.
+float FExponential( float in, float powx = 1. );
+
+///Utility step function; out = 0 when in < stepplace; out = 1 when in >= stepplace
+float FStep( float in, float stepplace = 1. );
+
+///Utility sigmoid function; in = [0..1] out = [0..1]; speed is the slope of change in the middle.
+float FSigmoid( float in, float fspeed = 1. );
+
#endif
/* Copyright (c) 2009, Joshua Allen and Charles Lohr
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|