tsMeshIntrinsics.sse.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "ts/tsMesh.h"
  23. #if (defined( TORQUE_CPU_X86 ) || defined( TORQUE_CPU_X64 ))
  24. #include "ts/tsMeshIntrinsics.h"
  25. #include <xmmintrin.h>
  26. void zero_vert_normal_bulk_SSE(const dsize_t count, U8 * __restrict const outPtr, const dsize_t outStride)
  27. {
  28. // A U8 * version of the in/out pointer
  29. char *outData = reinterpret_cast<char *>(outPtr);
  30. __m128 vPos;
  31. __m128 vNrm;
  32. __m128 vMask;
  33. const __m128 _point3f_zero_mask = { 0.0f, 0.0f, 0.0f, 1.0f };
  34. vMask = _mm_load_ps((const F32*)&_point3f_zero_mask);
  35. // pre-populate cache
  36. for(S32 i = 0; i < 8; i++)
  37. _mm_prefetch(reinterpret_cast<const char *>(outData + outStride * i), _MM_HINT_T0);
  38. for(S32 i = 0; i < count; i++)
  39. {
  40. TSMesh::__TSMeshVertexBase *curElem = reinterpret_cast<TSMesh::__TSMeshVertexBase *>(outData);
  41. // prefetch 8 items ahead (should really detect cache size or something)
  42. _mm_prefetch(reinterpret_cast<const char *>(outData + outStride * 8), _MM_HINT_T0);
  43. // load
  44. vPos = _mm_load_ps(curElem->_vert);
  45. vNrm = _mm_load_ps(curElem->_normal);
  46. // mask
  47. vPos = _mm_mul_ps(vPos, _point3f_zero_mask);
  48. vNrm = _mm_mul_ps(vNrm, _point3f_zero_mask);
  49. // store
  50. _mm_store_ps(curElem->_vert, vPos);
  51. _mm_store_ps(curElem->_normal, vNrm);
  52. // update output pointer
  53. outData += outStride;
  54. }
  55. }
  56. //------------------------------------------------------------------------------
  57. #endif // TORQUE_CPU_X86