doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Simd.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #ifndef __MATH_SIMD_H__
30 #define __MATH_SIMD_H__
31 
32 /*
33 ===============================================================================
34 
35  Single Instruction Multiple Data (SIMD)
36 
37  For optimal use data should be aligned on a 16 byte boundary.
38  All idSIMDProcessor routines are thread safe.
39 
40 ===============================================================================
41 */
42 
43 class idSIMD {
44 public:
45  static void Init( void );
46  static void InitProcessor( const char *module, bool forceGeneric );
47  static void Shutdown( void );
48  static void Test_f( const class idCmdArgs &args );
49 };
50 
51 
52 /*
53 ===============================================================================
54 
55  virtual base class for different SIMD processors
56 
57 ===============================================================================
58 */
59 
60 #ifdef _WIN32
61 #define VPCALL __fastcall
62 #else
63 #define VPCALL
64 #endif
65 
66 class idVec2;
67 class idVec3;
68 class idVec4;
69 class idVec5;
70 class idVec6;
71 class idVecX;
72 class idMat2;
73 class idMat3;
74 class idMat4;
75 class idMat5;
76 class idMat6;
77 class idMatX;
78 class idPlane;
79 class idDrawVert;
80 class idJointQuat;
81 class idJointMat;
82 struct dominantTri_s;
83 
84 const int MIXBUFFER_SAMPLES = 4096;
85 
86 typedef enum {
93 } speakerLabel;
94 
95 
97 public:
99 
101 
102  virtual const char * VPCALL GetName( void ) const = 0;
103 
104  virtual void VPCALL Add( float *dst, const float constant, const float *src, const int count ) = 0;
105  virtual void VPCALL Add( float *dst, const float *src0, const float *src1, const int count ) = 0;
106  virtual void VPCALL Sub( float *dst, const float constant, const float *src, const int count ) = 0;
107  virtual void VPCALL Sub( float *dst, const float *src0, const float *src1, const int count ) = 0;
108  virtual void VPCALL Mul( float *dst, const float constant, const float *src, const int count ) = 0;
109  virtual void VPCALL Mul( float *dst, const float *src0, const float *src1, const int count ) = 0;
110  virtual void VPCALL Div( float *dst, const float constant, const float *src, const int count ) = 0;
111  virtual void VPCALL Div( float *dst, const float *src0, const float *src1, const int count ) = 0;
112  virtual void VPCALL MulAdd( float *dst, const float constant, const float *src, const int count ) = 0;
113  virtual void VPCALL MulAdd( float *dst, const float *src0, const float *src1, const int count ) = 0;
114  virtual void VPCALL MulSub( float *dst, const float constant, const float *src, const int count ) = 0;
115  virtual void VPCALL MulSub( float *dst, const float *src0, const float *src1, const int count ) = 0;
116 
117  virtual void VPCALL Dot( float *dst, const idVec3 &constant, const idVec3 *src, const int count ) = 0;
118  virtual void VPCALL Dot( float *dst, const idVec3 &constant, const idPlane *src, const int count ) = 0;
119  virtual void VPCALL Dot( float *dst, const idVec3 &constant, const idDrawVert *src, const int count ) = 0;
120  virtual void VPCALL Dot( float *dst, const idPlane &constant,const idVec3 *src, const int count ) = 0;
121  virtual void VPCALL Dot( float *dst, const idPlane &constant,const idPlane *src, const int count ) = 0;
122  virtual void VPCALL Dot( float *dst, const idPlane &constant,const idDrawVert *src, const int count ) = 0;
123  virtual void VPCALL Dot( float *dst, const idVec3 *src0, const idVec3 *src1, const int count ) = 0;
124  virtual void VPCALL Dot( float &dot, const float *src1, const float *src2, const int count ) = 0;
125 
126  virtual void VPCALL CmpGT( byte *dst, const float *src0, const float constant, const int count ) = 0;
127  virtual void VPCALL CmpGT( byte *dst, const byte bitNum, const float *src0, const float constant, const int count ) = 0;
128  virtual void VPCALL CmpGE( byte *dst, const float *src0, const float constant, const int count ) = 0;
129  virtual void VPCALL CmpGE( byte *dst, const byte bitNum, const float *src0, const float constant, const int count ) = 0;
130  virtual void VPCALL CmpLT( byte *dst, const float *src0, const float constant, const int count ) = 0;
131  virtual void VPCALL CmpLT( byte *dst, const byte bitNum, const float *src0, const float constant, const int count ) = 0;
132  virtual void VPCALL CmpLE( byte *dst, const float *src0, const float constant, const int count ) = 0;
133  virtual void VPCALL CmpLE( byte *dst, const byte bitNum, const float *src0, const float constant, const int count ) = 0;
134 
135  virtual void VPCALL MinMax( float &min, float &max, const float *src, const int count ) = 0;
136  virtual void VPCALL MinMax( idVec2 &min, idVec2 &max, const idVec2 *src, const int count ) = 0;
137  virtual void VPCALL MinMax( idVec3 &min, idVec3 &max, const idVec3 *src, const int count ) = 0;
138  virtual void VPCALL MinMax( idVec3 &min, idVec3 &max, const idDrawVert *src, const int count ) = 0;
139  virtual void VPCALL MinMax( idVec3 &min, idVec3 &max, const idDrawVert *src, const int *indexes, const int count ) = 0;
140 
141  virtual void VPCALL Clamp( float *dst, const float *src, const float min, const float max, const int count ) = 0;
142  virtual void VPCALL ClampMin( float *dst, const float *src, const float min, const int count ) = 0;
143  virtual void VPCALL ClampMax( float *dst, const float *src, const float max, const int count ) = 0;
144 
145  virtual void VPCALL Memcpy( void *dst, const void *src, const int count ) = 0;
146  virtual void VPCALL Memset( void *dst, const int val, const int count ) = 0;
147 
148  // these assume 16 byte aligned and 16 byte padded memory
149  virtual void VPCALL Zero16( float *dst, const int count ) = 0;
150  virtual void VPCALL Negate16( float *dst, const int count ) = 0;
151  virtual void VPCALL Copy16( float *dst, const float *src, const int count ) = 0;
152  virtual void VPCALL Add16( float *dst, const float *src1, const float *src2, const int count ) = 0;
153  virtual void VPCALL Sub16( float *dst, const float *src1, const float *src2, const int count ) = 0;
154  virtual void VPCALL Mul16( float *dst, const float *src1, const float constant, const int count ) = 0;
155  virtual void VPCALL AddAssign16( float *dst, const float *src, const int count ) = 0;
156  virtual void VPCALL SubAssign16( float *dst, const float *src, const int count ) = 0;
157  virtual void VPCALL MulAssign16( float *dst, const float constant, const int count ) = 0;
158 
159  // idMatX operations
160  virtual void VPCALL MatX_MultiplyVecX( idVecX &dst, const idMatX &mat, const idVecX &vec ) = 0;
161  virtual void VPCALL MatX_MultiplyAddVecX( idVecX &dst, const idMatX &mat, const idVecX &vec ) = 0;
162  virtual void VPCALL MatX_MultiplySubVecX( idVecX &dst, const idMatX &mat, const idVecX &vec ) = 0;
163  virtual void VPCALL MatX_TransposeMultiplyVecX( idVecX &dst, const idMatX &mat, const idVecX &vec ) = 0;
164  virtual void VPCALL MatX_TransposeMultiplyAddVecX( idVecX &dst, const idMatX &mat, const idVecX &vec ) = 0;
165  virtual void VPCALL MatX_TransposeMultiplySubVecX( idVecX &dst, const idMatX &mat, const idVecX &vec ) = 0;
166  virtual void VPCALL MatX_MultiplyMatX( idMatX &dst, const idMatX &m1, const idMatX &m2 ) = 0;
167  virtual void VPCALL MatX_TransposeMultiplyMatX( idMatX &dst, const idMatX &m1, const idMatX &m2 ) = 0;
168  virtual void VPCALL MatX_LowerTriangularSolve( const idMatX &L, float *x, const float *b, const int n, int skip = 0 ) = 0;
169  virtual void VPCALL MatX_LowerTriangularSolveTranspose( const idMatX &L, float *x, const float *b, const int n ) = 0;
170  virtual bool VPCALL MatX_LDLTFactor( idMatX &mat, idVecX &invDiag, const int n ) = 0;
171 
172  // rendering
173  virtual void VPCALL BlendJoints( idJointQuat *joints, const idJointQuat *blendJoints, const float lerp, const int *index, const int numJoints ) = 0;
174  virtual void VPCALL ConvertJointQuatsToJointMats( idJointMat *jointMats, const idJointQuat *jointQuats, const int numJoints ) = 0;
175  virtual void VPCALL ConvertJointMatsToJointQuats( idJointQuat *jointQuats, const idJointMat *jointMats, const int numJoints ) = 0;
176  virtual void VPCALL TransformJoints( idJointMat *jointMats, const int *parents, const int firstJoint, const int lastJoint ) = 0;
177  virtual void VPCALL UntransformJoints( idJointMat *jointMats, const int *parents, const int firstJoint, const int lastJoint ) = 0;
178  virtual void VPCALL TransformVerts( idDrawVert *verts, const int numVerts, const idJointMat *joints, const idVec4 *weights, const int *index, const int numWeights ) = 0;
179  virtual void VPCALL TracePointCull( byte *cullBits, byte &totalOr, const float radius, const idPlane *planes, const idDrawVert *verts, const int numVerts ) = 0;
180  virtual void VPCALL DecalPointCull( byte *cullBits, const idPlane *planes, const idDrawVert *verts, const int numVerts ) = 0;
181  virtual void VPCALL OverlayPointCull( byte *cullBits, idVec2 *texCoords, const idPlane *planes, const idDrawVert *verts, const int numVerts ) = 0;
182  virtual void VPCALL DeriveTriPlanes( idPlane *planes, const idDrawVert *verts, const int numVerts, const int *indexes, const int numIndexes ) = 0;
183  virtual void VPCALL DeriveTangents( idPlane *planes, idDrawVert *verts, const int numVerts, const int *indexes, const int numIndexes ) = 0;
184  virtual void VPCALL DeriveUnsmoothedTangents( idDrawVert *verts, const dominantTri_s *dominantTris, const int numVerts ) = 0;
185  virtual void VPCALL NormalizeTangents( idDrawVert *verts, const int numVerts ) = 0;
186  virtual void VPCALL CreateTextureSpaceLightVectors( idVec3 *lightVectors, const idVec3 &lightOrigin, const idDrawVert *verts, const int numVerts, const int *indexes, const int numIndexes ) = 0;
187  virtual void VPCALL CreateSpecularTextureCoords( idVec4 *texCoords, const idVec3 &lightOrigin, const idVec3 &viewOrigin, const idDrawVert *verts, const int numVerts, const int *indexes, const int numIndexes ) = 0;
188  virtual int VPCALL CreateShadowCache( idVec4 *vertexCache, int *vertRemap, const idVec3 &lightOrigin, const idDrawVert *verts, const int numVerts ) = 0;
189  virtual int VPCALL CreateVertexProgramShadowCache( idVec4 *vertexCache, const idDrawVert *verts, const int numVerts ) = 0;
190 
191  // sound mixing
192  virtual void VPCALL UpSamplePCMTo44kHz( float *dest, const short *pcm, const int numSamples, const int kHz, const int numChannels ) = 0;
193  virtual void VPCALL UpSampleOGGTo44kHz( float *dest, const float * const *ogg, const int numSamples, const int kHz, const int numChannels ) = 0;
194  virtual void VPCALL MixSoundTwoSpeakerMono( float *mixBuffer, const float *samples, const int numSamples, const float lastV[2], const float currentV[2] ) = 0;
195  virtual void VPCALL MixSoundTwoSpeakerStereo( float *mixBuffer, const float *samples, const int numSamples, const float lastV[2], const float currentV[2] ) = 0;
196  virtual void VPCALL MixSoundSixSpeakerMono( float *mixBuffer, const float *samples, const int numSamples, const float lastV[6], const float currentV[6] ) = 0;
197  virtual void VPCALL MixSoundSixSpeakerStereo( float *mixBuffer, const float *samples, const int numSamples, const float lastV[6], const float currentV[6] ) = 0;
198  virtual void VPCALL MixedSoundToSamples( short *samples, const float *mixBuffer, const int numSamples ) = 0;
199 };
200 
201 // pointer to SIMD processor
203 
204 #endif /* !__MATH_SIMD_H__ */
virtual void VPCALL ConvertJointQuatsToJointMats(idJointMat *jointMats, const idJointQuat *jointQuats, const int numJoints)=0
#define min(a, b)
virtual void VPCALL MatX_TransposeMultiplyAddVecX(idVecX &dst, const idMatX &mat, const idVecX &vec)=0
virtual void VPCALL Sub16(float *dst, const float *src1, const float *src2, const int count)=0
virtual void VPCALL SubAssign16(float *dst, const float *src, const int count)=0
const GLbyte * weights
Definition: glext.h:3273
virtual void VPCALL Sub(float *dst, const float constant, const float *src, const int count)=0
virtual void VPCALL UpSamplePCMTo44kHz(float *dest, const short *pcm, const int numSamples, const int kHz, const int numChannels)=0
virtual void VPCALL DeriveTangents(idPlane *planes, idDrawVert *verts, const int numVerts, const int *indexes, const int numIndexes)=0
const int MIXBUFFER_SAMPLES
Definition: Simd.h:84
static void Test_f(const class idCmdArgs &args)
Definition: Simd.cpp:4102
virtual void VPCALL MatX_TransposeMultiplyMatX(idMatX &dst, const idMatX &m1, const idMatX &m2)=0
virtual const char *VPCALL GetName(void) const =0
Definition: Simd.h:43
speakerLabel
Definition: Simd.h:86
virtual void VPCALL CreateTextureSpaceLightVectors(idVec3 *lightVectors, const idVec3 &lightOrigin, const idDrawVert *verts, const int numVerts, const int *indexes, const int numIndexes)=0
GLenum GLsizei n
Definition: glext.h:3705
virtual void VPCALL Div(float *dst, const float constant, const float *src, const int count)=0
virtual void VPCALL Clamp(float *dst, const float *src, const float min, const float max, const int count)=0
virtual void VPCALL CmpGE(byte *dst, const float *src0, const float constant, const int count)=0
virtual void VPCALL MixSoundTwoSpeakerMono(float *mixBuffer, const float *samples, const int numSamples, const float lastV[2], const float currentV[2])=0
virtual void VPCALL MatX_MultiplyMatX(idMatX &dst, const idMatX &m1, const idMatX &m2)=0
Definition: Vector.h:316
virtual void VPCALL OverlayPointCull(byte *cullBits, idVec2 *texCoords, const idPlane *planes, const idDrawVert *verts, const int numVerts)=0
idSIMDProcessor(void)
Definition: Simd.h:98
virtual void VPCALL Memset(void *dst, const int val, const int count)=0
GLuint src
Definition: glext.h:5390
GLenum GLint x
Definition: glext.h:2849
virtual void VPCALL MatX_LowerTriangularSolveTranspose(const idMatX &L, float *x, const float *b, const int n)=0
virtual void VPCALL MatX_TransposeMultiplyVecX(idVecX &dst, const idMatX &mat, const idVecX &vec)=0
virtual void VPCALL Zero16(float *dst, const int count)=0
virtual void VPCALL ConvertJointMatsToJointQuats(idJointQuat *jointQuats, const idJointMat *jointMats, const int numJoints)=0
static void Shutdown(void)
Definition: Simd.cpp:118
virtual void VPCALL CmpLE(byte *dst, const float *src0, const float constant, const int count)=0
GLuint dst
Definition: glext.h:5285
virtual void VPCALL CreateSpecularTextureCoords(idVec4 *texCoords, const idVec3 &lightOrigin, const idVec3 &viewOrigin, const idDrawVert *verts, const int numVerts, const int *indexes, const int numIndexes)=0
GLuint GLuint GLsizei count
Definition: glext.h:2845
virtual void VPCALL MinMax(float &min, float &max, const float *src, const int count)=0
Definition: Vector.h:52
virtual void VPCALL CmpLT(byte *dst, const float *src0, const float constant, const int count)=0
GLuint index
Definition: glext.h:3476
Definition: Vector.h:808
virtual void VPCALL AddAssign16(float *dst, const float *src, const int count)=0
virtual void VPCALL MatX_MultiplySubVecX(idVecX &dst, const idMatX &mat, const idVecX &vec)=0
virtual void VPCALL BlendJoints(idJointQuat *joints, const idJointQuat *blendJoints, const float lerp, const int *index, const int numJoints)=0
virtual void VPCALL TransformVerts(idDrawVert *verts, const int numVerts, const idJointMat *joints, const idVec4 *weights, const int *index, const int numWeights)=0
virtual void VPCALL MatX_MultiplyVecX(idVecX &dst, const idMatX &mat, const idVecX &vec)=0
virtual void VPCALL UpSampleOGGTo44kHz(float *dest, const float *const *ogg, const int numSamples, const int kHz, const int numChannels)=0
virtual void VPCALL MulAdd(float *dst, const float constant, const float *src, const int count)=0
virtual void VPCALL DeriveTriPlanes(idPlane *planes, const idDrawVert *verts, const int numVerts, const int *indexes, const int numIndexes)=0
virtual void VPCALL Add(float *dst, const float constant, const float *src, const int count)=0
cpuid_t
Definition: sys_public.h:142
virtual void VPCALL MixSoundSixSpeakerStereo(float *mixBuffer, const float *samples, const int numSamples, const float lastV[6], const float currentV[6])=0
virtual void VPCALL MixSoundSixSpeakerMono(float *mixBuffer, const float *samples, const int numSamples, const float lastV[6], const float currentV[6])=0
virtual void VPCALL MatX_LowerTriangularSolve(const idMatX &L, float *x, const float *b, const int n, int skip=0)=0
virtual void VPCALL MulAssign16(float *dst, const float constant, const int count)=0
virtual void VPCALL Mul16(float *dst, const float *src1, const float constant, const int count)=0
Definition: Plane.h:71
virtual void VPCALL Dot(float *dst, const idVec3 &constant, const idVec3 *src, const int count)=0
Definition: eax4.h:1413
virtual void VPCALL MixSoundTwoSpeakerStereo(float *mixBuffer, const float *samples, const int numSamples, const float lastV[2], const float currentV[2])=0
static void InitProcessor(const char *module, bool forceGeneric)
Definition: Simd.cpp:63
idSIMDProcessor * SIMDProcessor
Definition: Simd.cpp:43
virtual void VPCALL Mul(float *dst, const float constant, const float *src, const int count)=0
virtual void VPCALL Add16(float *dst, const float *src1, const float *src2, const int count)=0
virtual void VPCALL Copy16(float *dst, const float *src, const int count)=0
static void Init(void)
Definition: Simd.cpp:51
virtual void VPCALL MatX_TransposeMultiplySubVecX(idVecX &dst, const idMatX &mat, const idVecX &vec)=0
virtual bool VPCALL MatX_LDLTFactor(idMatX &mat, idVecX &invDiag, const int n)=0
virtual void VPCALL DeriveUnsmoothedTangents(idDrawVert *verts, const dominantTri_s *dominantTris, const int numVerts)=0
virtual void VPCALL Memcpy(void *dst, const void *src, const int count)=0
virtual void VPCALL UntransformJoints(idJointMat *jointMats, const int *parents, const int firstJoint, const int lastJoint)=0
GLubyte GLubyte b
Definition: glext.h:4662
virtual void VPCALL TransformJoints(idJointMat *jointMats, const int *parents, const int firstJoint, const int lastJoint)=0
virtual void VPCALL TracePointCull(byte *cullBits, byte &totalOr, const float radius, const idPlane *planes, const idDrawVert *verts, const int numVerts)=0
Definition: Matrix.h:333
virtual void VPCALL MatX_MultiplyAddVecX(idVecX &dst, const idMatX &mat, const idVecX &vec)=0
virtual void VPCALL MulSub(float *dst, const float constant, const float *src, const int count)=0
unsigned char byte
Definition: Lib.h:75
virtual void VPCALL NormalizeTangents(idDrawVert *verts, const int numVerts)=0
virtual void VPCALL MixedSoundToSamples(short *samples, const float *mixBuffer, const int numSamples)=0
idVertexCache vertexCache
Definition: VertexCache.cpp:41
virtual void VPCALL CmpGT(byte *dst, const float *src0, const float constant, const int count)=0
#define VPCALL
Definition: Simd.h:63
float dot(float a[], float b[])
Definition: Model_lwo.cpp:3883
#define max(x, y)
Definition: os.h:70
Definition: Matrix.h:55
virtual void VPCALL Negate16(float *dst, const int count)=0
virtual void VPCALL ClampMin(float *dst, const float *src, const float min, const int count)=0
Definition: Matrix.h:764
cpuid_t cpuid
Definition: Simd.h:100
virtual void VPCALL ClampMax(float *dst, const float *src, const float max, const int count)=0
virtual void VPCALL DecalPointCull(byte *cullBits, const idPlane *planes, const idDrawVert *verts, const int numVerts)=0
virtual int VPCALL CreateShadowCache(idVec4 *vertexCache, int *vertRemap, const idVec3 &lightOrigin, const idDrawVert *verts, const int numVerts)=0
virtual int VPCALL CreateVertexProgramShadowCache(idVec4 *vertexCache, const idDrawVert *verts, const int numVerts)=0