PageRenderTime 36ms CodeModel.GetById 25ms RepoModel.GetById 1ms 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
Possible License(s): LGPL-2.1
  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. #ifndef LL_LLV4MATH_H
  27. #define LL_LLV4MATH_H
  28. // *NOTE: We do not support SSE acceleration on Windows builds.
  29. // Our minimum specification for the viewer includes 1 GHz Athlon processors,
  30. // which covers the Athlon Thunderbird series that does not support SSE.
  31. //
  32. // Our header files include statements like this
  33. // const F32 HAVOK_TIMESTEP = 1.f / 45.f;
  34. // This creates "globals" that are included in each .obj file. If a single
  35. // .cpp file has SSE code generation turned on (eg, llviewerjointmesh_sse.cpp)
  36. // these globals will be initialized using SSE instructions. This causes SL
  37. // to crash before main() on processors without SSE. Untangling all these
  38. // headers/variables is too much work for the small performance gains of
  39. // vectorization.
  40. //
  41. // Therefore we only support vectorization on builds where the everything is
  42. // built with SSE or Altivec. See https://jira.secondlife.com/browse/VWR-1610
  43. // and https://jira.lindenlab.com/browse/SL-47720 for details.
  44. //
  45. // Sorry the code is such a mess. JC
  46. //-----------------------------------------------------------------------------
  47. //-----------------------------------------------------------------------------
  48. // LLV4MATH - GNUC
  49. //-----------------------------------------------------------------------------
  50. //-----------------------------------------------------------------------------
  51. #if LL_GNUC && __GNUC__ >= 4 && __SSE__
  52. #define LL_VECTORIZE 1
  53. #if LL_DARWIN
  54. #include <Accelerate/Accelerate.h>
  55. #include <xmmintrin.h>
  56. typedef vFloat V4F32;
  57. #else
  58. #include <xmmintrin.h>
  59. typedef float V4F32 __attribute__((vector_size(16)));
  60. #endif
  61. #endif
  62. #if LL_GNUC
  63. #define LL_LLV4MATH_ALIGN_PREFIX
  64. #define LL_LLV4MATH_ALIGN_POSTFIX __attribute__((aligned(16)))
  65. #endif
  66. //-----------------------------------------------------------------------------
  67. //-----------------------------------------------------------------------------
  68. // LLV4MATH - MSVC
  69. //-----------------------------------------------------------------------------
  70. //-----------------------------------------------------------------------------
  71. // Only vectorize if the entire Windows build uses SSE.
  72. // _M_IX86_FP is set when SSE code generation is turned on, and I have
  73. // confirmed this in VS2003, VS2003 SP1, and VS2005. JC
  74. #if LL_MSVC && _M_IX86_FP
  75. #define LL_VECTORIZE 1
  76. #include <xmmintrin.h>
  77. typedef __m128 V4F32;
  78. #endif
  79. #if LL_MSVC
  80. #define LL_LLV4MATH_ALIGN_PREFIX __declspec(align(16))
  81. #define LL_LLV4MATH_ALIGN_POSTFIX
  82. #endif
  83. //-----------------------------------------------------------------------------
  84. //-----------------------------------------------------------------------------
  85. // LLV4MATH - default - no vectorization
  86. //-----------------------------------------------------------------------------
  87. //-----------------------------------------------------------------------------
  88. #if !LL_VECTORIZE
  89. #define LL_VECTORIZE 0
  90. struct V4F32 { F32 __pad__[4]; };
  91. inline F32 llv4lerp(F32 a, F32 b, F32 w) { return ( b - a ) * w + a; }
  92. #endif
  93. #ifndef LL_LLV4MATH_ALIGN_PREFIX
  94. # define LL_LLV4MATH_ALIGN_PREFIX
  95. #endif
  96. #ifndef LL_LLV4MATH_ALIGN_POSTFIX
  97. # define LL_LLV4MATH_ALIGN_POSTFIX
  98. #endif
  99. //-----------------------------------------------------------------------------
  100. //-----------------------------------------------------------------------------
  101. // LLV4MATH
  102. //-----------------------------------------------------------------------------
  103. //-----------------------------------------------------------------------------
  104. #define LLV4_NUM_AXIS 4
  105. class LLV4Vector3;
  106. class LLV4Matrix3;
  107. class LLV4Matrix4;
  108. #endif