Singular_Value_Decomposition_Preamble.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //#####################################################################
  2. // Copyright (c) 2010-2011, Eftychios Sifakis.
  3. //
  4. // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  5. // * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  6. // * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or
  7. // other materials provided with the distribution.
  8. //
  9. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
  10. // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  11. // SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  12. // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  13. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  14. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  15. //#####################################################################
  16. #ifdef PRINT_DEBUGGING_OUTPUT
  17. #include <iomanip>
  18. #include <iostream>
  19. #endif
  20. #ifdef USE_SCALAR_IMPLEMENTATION
  21. #define ENABLE_SCALAR_IMPLEMENTATION(X) X
  22. #else
  23. #define ENABLE_SCALAR_IMPLEMENTATION(X)
  24. #endif
  25. #ifdef USE_SSE_IMPLEMENTATION
  26. #define ENABLE_SSE_IMPLEMENTATION(X) X
  27. #else
  28. #define ENABLE_SSE_IMPLEMENTATION(X)
  29. #endif
  30. #ifdef USE_AVX_IMPLEMENTATION
  31. #include <immintrin.h>
  32. #define ENABLE_AVX_IMPLEMENTATION(X) X
  33. #else
  34. // Stefan: removed include. Why does it import MMX instructions, shouldn't this be under the #ifdef USE_SSE_IMPLEMENTATION above?
  35. //#include <xmmintrin.h>
  36. #define ENABLE_AVX_IMPLEMENTATION(X)
  37. #endif
  38. #ifdef USE_SCALAR_IMPLEMENTATION
  39. // Alec: Why is this using sse intrinsics if it's supposed to be the scalar
  40. // implementation?
  41. #ifdef __SSE__
  42. #include <mmintrin.h>
  43. // Changed to inline
  44. inline float rsqrt(const float f)
  45. {
  46. float buf[4];
  47. buf[0]=f;
  48. __m128 v=_mm_loadu_ps(buf);
  49. v=_mm_rsqrt_ss(v);
  50. _mm_storeu_ps(buf,v);
  51. return buf[0];
  52. }
  53. #else
  54. #include <cmath>
  55. inline float rsqrt(const float f)
  56. {
  57. return 1./sqrtf(f);
  58. }
  59. #endif
  60. #endif