Singular_Value_Decomposition_Preamble.hpp 2.7 KB

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