ImfSystemSpecific.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2012, Industrial Light & Magic, a division of Lucas
  4. // Digital Ltd. LLC
  5. //
  6. // All rights reserved.
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions are
  10. // met:
  11. // * Redistributions of source code must retain the above copyright
  12. // notice, this list of conditions and the following disclaimer.
  13. // * Redistributions in binary form must reproduce the above
  14. // copyright notice, this list of conditions and the following disclaimer
  15. // in the documentation and/or other materials provided with the
  16. // distribution.
  17. // * Neither the name of Industrial Light & Magic nor the names of
  18. // its contributors may be used to endorse or promote products derived
  19. // from this software without specific prior written permission.
  20. //
  21. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. //
  33. ///////////////////////////////////////////////////////////////////////////
  34. #ifndef INCLUDED_IMF_COMPILER_SPECIFIC_H
  35. #define INCLUDED_IMF_COMPILER_SPECIFIC_H
  36. #include "ImfNamespace.h"
  37. #include "ImfSimd.h"
  38. #include <stdlib.h>
  39. #include "ImfExport.h"
  40. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
  41. static unsigned long systemEndianCheckValue = 0x12345678;
  42. static unsigned long* systemEndianCheckPointer = &systemEndianCheckValue;
  43. // EXR files are little endian - check processor architecture is too
  44. // (optimisation currently not supported for big endian machines)
  45. static bool GLOBAL_SYSTEM_LITTLE_ENDIAN =
  46. (*(unsigned char*)systemEndianCheckPointer == 0x78 ? true : false);
  47. #ifdef IMF_HAVE_SSE2
  48. #if defined(__GNUC__)
  49. // Causes issues on certain gcc versions
  50. //#define EXR_FORCEINLINE inline __attribute__((always_inline))
  51. #define EXR_FORCEINLINE inline
  52. #define EXR_RESTRICT __restrict
  53. static void* EXRAllocAligned(size_t size, size_t alignment)
  54. {
  55. // GNUC is used for things like mingw to (cross-)compile for windows
  56. #ifdef _WIN32
  57. return _aligned_malloc(size, alignment);
  58. #elif defined(__ANDROID__)
  59. return memalign(alignment, size);
  60. #else
  61. void* ptr = 0;
  62. posix_memalign(&ptr, alignment, size);
  63. return ptr;
  64. #endif
  65. }
  66. static void EXRFreeAligned(void* ptr)
  67. {
  68. #ifdef _WIN32
  69. _aligned_free(ptr);
  70. #else
  71. free(ptr);
  72. #endif
  73. }
  74. #elif defined _MSC_VER
  75. #define EXR_FORCEINLINE __forceinline
  76. #define EXR_RESTRICT __restrict
  77. static void* EXRAllocAligned(size_t size, size_t alignment)
  78. {
  79. return _aligned_malloc(size, alignment);
  80. }
  81. static void EXRFreeAligned(void* ptr)
  82. {
  83. _aligned_free(ptr);
  84. }
  85. #elif defined (__INTEL_COMPILER) || \
  86. defined(__ICL) || \
  87. defined(__ICC) || \
  88. defined(__ECC)
  89. #define EXR_FORCEINLINE inline
  90. #define EXR_RESTRICT restrict
  91. static void* EXRAllocAligned(size_t size, size_t alignment)
  92. {
  93. return _mm_malloc(size, alignment);
  94. }
  95. static void EXRFreeAligned(void* ptr)
  96. {
  97. _mm_free(ptr);
  98. }
  99. #else
  100. // generic compiler
  101. #define EXR_FORCEINLINE inline
  102. #define EXR_RESTRICT
  103. static void* EXRAllocAligned(size_t size, size_t alignment)
  104. {
  105. return malloc(size);
  106. }
  107. static void EXRFreeAligned(void* ptr)
  108. {
  109. free(ptr);
  110. }
  111. #endif // compiler switch
  112. #else // IMF_HAVE_SSE2
  113. #define EXR_FORCEINLINE inline
  114. #define EXR_RESTRICT
  115. static void* EXRAllocAligned(size_t size, size_t alignment)
  116. {
  117. return malloc(size);
  118. }
  119. static void EXRFreeAligned(void* ptr)
  120. {
  121. free(ptr);
  122. }
  123. #endif // IMF_HAVE_SSE2
  124. //
  125. // Simple CPUID based runtime detection of various capabilities
  126. //
  127. class IMF_EXPORT CpuId
  128. {
  129. public:
  130. CpuId();
  131. bool sse2;
  132. bool sse3;
  133. bool ssse3;
  134. bool sse4_1;
  135. bool sse4_2;
  136. bool avx;
  137. bool f16c;
  138. };
  139. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
  140. #endif //include guard