Singular_Value_Decomposition_Preamble.hpp 2.6 KB

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