Singular_Value_Decomposition_Preamble.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. // Prevent warnings
  21. #ifdef ENABLE_SCALAR_IMPLEMENTATION
  22. # undef ENABLE_SCALAR_IMPLEMENTATION
  23. #endif
  24. #ifdef ENABLE_SSE_IMPLEMENTATION
  25. # undef ENABLE_SSE_IMPLEMENTATION
  26. #endif
  27. #ifdef ENABLE_AVX_IMPLEMENTATION
  28. # undef ENABLE_AVX_IMPLEMENTATION
  29. #endif
  30. #ifdef USE_SCALAR_IMPLEMENTATION
  31. #define ENABLE_SCALAR_IMPLEMENTATION(X) X
  32. #else
  33. #define ENABLE_SCALAR_IMPLEMENTATION(X)
  34. #endif
  35. #ifdef USE_SSE_IMPLEMENTATION
  36. #define ENABLE_SSE_IMPLEMENTATION(X) X
  37. #else
  38. #define ENABLE_SSE_IMPLEMENTATION(X)
  39. #endif
  40. #ifdef USE_AVX_IMPLEMENTATION
  41. #include <immintrin.h>
  42. #define ENABLE_AVX_IMPLEMENTATION(X) X
  43. #else
  44. // Stefan: removed include. Why does it import MMX instructions, shouldn't this be under the #ifdef USE_SSE_IMPLEMENTATION above?
  45. //#include <xmmintrin.h>
  46. #define ENABLE_AVX_IMPLEMENTATION(X)
  47. #endif
  48. #ifdef USE_SCALAR_IMPLEMENTATION
  49. // Alec: Why is this using sse intrinsics if it's supposed to be the scalar
  50. // implementation?
  51. #ifdef __SSE__
  52. #include <mmintrin.h>
  53. // Changed to inline
  54. inline float rsqrt(const float f)
  55. {
  56. float buf[4];
  57. buf[0]=f;
  58. __m128 v=_mm_loadu_ps(buf);
  59. v=_mm_rsqrt_ss(v);
  60. _mm_storeu_ps(buf,v);
  61. return buf[0];
  62. }
  63. #else
  64. #include <cmath>
  65. inline float rsqrt(const float f)
  66. {
  67. return 1./sqrtf(f);
  68. }
  69. #endif
  70. #endif