PageRenderTime 28ms CodeModel.GetById 19ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llmath/llv4math.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 141 lines | 42 code | 33 blank | 66 comment | 3 complexity | 8efa25a98abd70ad61a122ad3127e954 MD5 | raw file
  1/** 
  2 * @file llv4math.h
  3 * @brief LLV4* class header file - vector processor enabled math
  4 *
  5 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library 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 GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef	LL_LLV4MATH_H
 28#define	LL_LLV4MATH_H
 29
 30// *NOTE: We do not support SSE acceleration on Windows builds.
 31// Our minimum specification for the viewer includes 1 GHz Athlon processors,
 32// which covers the Athlon Thunderbird series that does not support SSE.
 33//
 34// Our header files include statements like this
 35//   const F32 HAVOK_TIMESTEP = 1.f / 45.f;
 36// This creates "globals" that are included in each .obj file.  If a single
 37// .cpp file has SSE code generation turned on (eg, llviewerjointmesh_sse.cpp)
 38// these globals will be initialized using SSE instructions.  This causes SL
 39// to crash before main() on processors without SSE.  Untangling all these 
 40// headers/variables is too much work for the small performance gains of 
 41// vectorization.
 42//
 43// Therefore we only support vectorization on builds where the everything is 
 44// built with SSE or Altivec.  See https://jira.secondlife.com/browse/VWR-1610
 45// and https://jira.lindenlab.com/browse/SL-47720 for details.
 46//
 47// Sorry the code is such a mess. JC
 48
 49//-----------------------------------------------------------------------------
 50//-----------------------------------------------------------------------------
 51// LLV4MATH - GNUC
 52//-----------------------------------------------------------------------------
 53//-----------------------------------------------------------------------------
 54
 55#if LL_GNUC && __GNUC__ >= 4 && __SSE__
 56
 57#define			LL_VECTORIZE					1
 58
 59#if LL_DARWIN
 60
 61#include <Accelerate/Accelerate.h>
 62#include <xmmintrin.h>
 63typedef vFloat	V4F32;
 64
 65#else
 66
 67#include <xmmintrin.h>
 68typedef float	V4F32							__attribute__((vector_size(16)));
 69
 70#endif
 71
 72#endif
 73#if LL_GNUC
 74
 75#define			LL_LLV4MATH_ALIGN_PREFIX
 76#define			LL_LLV4MATH_ALIGN_POSTFIX		__attribute__((aligned(16)))
 77
 78#endif
 79
 80//-----------------------------------------------------------------------------
 81//-----------------------------------------------------------------------------
 82// LLV4MATH - MSVC
 83//-----------------------------------------------------------------------------
 84//-----------------------------------------------------------------------------
 85
 86// Only vectorize if the entire Windows build uses SSE.
 87// _M_IX86_FP is set when SSE code generation is turned on, and I have
 88// confirmed this in VS2003, VS2003 SP1, and VS2005. JC
 89#if LL_MSVC && _M_IX86_FP
 90
 91#define			LL_VECTORIZE					1
 92
 93#include <xmmintrin.h>
 94
 95typedef __m128	V4F32;
 96
 97#endif
 98#if LL_MSVC
 99
100#define			LL_LLV4MATH_ALIGN_PREFIX		__declspec(align(16))
101#define			LL_LLV4MATH_ALIGN_POSTFIX
102
103#endif
104
105//-----------------------------------------------------------------------------
106//-----------------------------------------------------------------------------
107// LLV4MATH - default - no vectorization
108//-----------------------------------------------------------------------------
109//-----------------------------------------------------------------------------
110
111#if !LL_VECTORIZE
112
113#define			LL_VECTORIZE					0
114
115struct			V4F32							{ F32 __pad__[4]; };
116
117inline F32 llv4lerp(F32 a, F32 b, F32 w)		{ return ( b - a ) * w + a; }
118
119#endif
120
121#ifndef			LL_LLV4MATH_ALIGN_PREFIX
122#	define			LL_LLV4MATH_ALIGN_PREFIX
123#endif
124#ifndef			LL_LLV4MATH_ALIGN_POSTFIX
125#	define			LL_LLV4MATH_ALIGN_POSTFIX
126#endif
127
128//-----------------------------------------------------------------------------
129//-----------------------------------------------------------------------------
130// LLV4MATH
131//-----------------------------------------------------------------------------
132//-----------------------------------------------------------------------------
133
134
135#define			LLV4_NUM_AXIS					4
136
137class LLV4Vector3;
138class LLV4Matrix3;
139class LLV4Matrix4;
140
141#endif