/src/freeimage-svn/FreeImage/trunk/Source/OpenEXR/IlmImf/ImfSystemSpecific.h
Line  | Count  | Source  | 
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  |  |  | 
35  |  | #ifndef INCLUDED_IMF_COMPILER_SPECIFIC_H  | 
36  |  | #define INCLUDED_IMF_COMPILER_SPECIFIC_H  | 
37  |  |  | 
38  |  | #include <ImfNamespace.h>  | 
39  |  | #include <ImfSimd.h>  | 
40  |  | #include <stdlib.h>  | 
41  |  | #include "ImfExport.h"  | 
42  |  |  | 
43  |  | OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER  | 
44  |  |  | 
45  |  |  | 
46  |  | static unsigned long  systemEndianCheckValue   = 0x12345678;  | 
47  |  | static unsigned long* systemEndianCheckPointer = &systemEndianCheckValue;  | 
48  |  |  | 
49  |  | // EXR files are little endian - check processor architecture is too  | 
50  |  | // (optimisation currently not supported for big endian machines)  | 
51  |  | static bool GLOBAL_SYSTEM_LITTLE_ENDIAN =  | 
52  |  |         (*(unsigned char*)systemEndianCheckPointer == 0x78 ? true : false);  | 
53  |  |  | 
54  |  |  | 
55  |  | #ifdef IMF_HAVE_SSE2  | 
56  |  |  | 
57  |  | #ifdef __GNUC__  | 
58  |  | // Causes issues on certain gcc versions  | 
59  |  | //#define EXR_FORCEINLINE inline __attribute__((always_inline))  | 
60  |  | #define EXR_FORCEINLINE inline  | 
61  |  | #define EXR_RESTRICT __restrict  | 
62  |  |  | 
63  |  | static void* EXRAllocAligned(size_t size, size_t alignment)  | 
64  | 0  | { | 
65  | 0  |     void* ptr = 0;  | 
66  | 0  |     posix_memalign(&ptr, alignment, size);  | 
67  | 0  |     return ptr;  | 
68  | 0  | } Unexecuted instantiation: ImfScanLineInputFile.cpp:Imf_2_2::EXRAllocAligned(unsigned long, unsigned long) Unexecuted instantiation: ImfDwaCompressor.cpp:Imf_2_2::EXRAllocAligned(unsigned long, unsigned long) Unexecuted instantiation: ImfSystemSpecific.cpp:Imf_2_2::EXRAllocAligned(unsigned long, unsigned long)  | 
69  |  |  | 
70  |  |  | 
71  |  | static void EXRFreeAligned(void* ptr)  | 
72  | 0  | { | 
73  | 0  |     free(ptr);  | 
74  | 0  | } Unexecuted instantiation: ImfScanLineInputFile.cpp:Imf_2_2::EXRFreeAligned(void*) Unexecuted instantiation: ImfDwaCompressor.cpp:Imf_2_2::EXRFreeAligned(void*) Unexecuted instantiation: ImfSystemSpecific.cpp:Imf_2_2::EXRFreeAligned(void*)  | 
75  |  |  | 
76  |  | #elif defined _MSC_VER  | 
77  |  |  | 
78  |  | #define EXR_FORCEINLINE __forceinline  | 
79  |  | #define EXR_RESTRICT __restrict  | 
80  |  |  | 
81  |  | static void* EXRAllocAligned(size_t size, size_t alignment)  | 
82  |  | { | 
83  |  |     return _aligned_malloc(size, alignment);  | 
84  |  | }  | 
85  |  |  | 
86  |  |  | 
87  |  | static void EXRFreeAligned(void* ptr)  | 
88  |  | { | 
89  |  |     _aligned_free(ptr);  | 
90  |  | }  | 
91  |  |  | 
92  |  | #elif defined (__INTEL_COMPILER) || \  | 
93  |  |         defined(__ICL) || \  | 
94  |  |         defined(__ICC) || \  | 
95  |  |         defined(__ECC)  | 
96  |  |  | 
97  |  | #define EXR_FORCEINLINE inline  | 
98  |  | #define EXR_RESTRICT restrict  | 
99  |  |  | 
100  |  | static void* EXRAllocAligned(size_t size, size_t alignment)  | 
101  |  | { | 
102  |  |     return _mm_malloc(size, alignment);  | 
103  |  | }  | 
104  |  |  | 
105  |  |  | 
106  |  | static void EXRFreeAligned(void* ptr)  | 
107  |  | { | 
108  |  |     _mm_free(ptr);  | 
109  |  | }  | 
110  |  |  | 
111  |  | #else  | 
112  |  |  | 
113  |  | // generic compiler  | 
114  |  | #define EXR_FORCEINLINE inline  | 
115  |  | #define EXR_RESTRICT  | 
116  |  |  | 
117  |  | static void* EXRAllocAligned(size_t size, size_t alignment)  | 
118  |  | { | 
119  |  |     return malloc(size);  | 
120  |  | }  | 
121  |  |  | 
122  |  |  | 
123  |  | static void EXRFreeAligned(void* ptr)  | 
124  |  | { | 
125  |  |     free(ptr);  | 
126  |  | }  | 
127  |  |  | 
128  |  | #endif // compiler switch  | 
129  |  |  | 
130  |  |  | 
131  |  | #else // IMF_HAVE_SSE2  | 
132  |  |  | 
133  |  |  | 
134  |  | #define EXR_FORCEINLINE inline  | 
135  |  | #define EXR_RESTRICT  | 
136  |  |  | 
137  |  | static void* EXRAllocAligned(size_t size, size_t alignment)  | 
138  |  | { | 
139  |  |     return malloc(size);  | 
140  |  | }  | 
141  |  |  | 
142  |  |  | 
143  |  | static void EXRFreeAligned(void* ptr)  | 
144  |  | { | 
145  |  |     free(ptr);  | 
146  |  | }  | 
147  |  |  | 
148  |  |  | 
149  |  | #endif  // IMF_HAVE_SSE2  | 
150  |  |  | 
151  |  | //   | 
152  |  | // Simple CPUID based runtime detection of various capabilities  | 
153  |  | //  | 
154  |  | class IMF_EXPORT CpuId  | 
155  |  | { | 
156  |  |     public:  | 
157  |  |         CpuId();  | 
158  |  |  | 
159  |  |         bool sse2;  | 
160  |  |         bool sse3;  | 
161  |  |         bool ssse3;  | 
162  |  |         bool sse4_1;  | 
163  |  |         bool sse4_2;  | 
164  |  |         bool avx;  | 
165  |  |         bool f16c;  | 
166  |  | };  | 
167  |  |  | 
168  |  |  | 
169  |  | OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT  | 
170  |  |  | 
171  |  |  | 
172  |  | #endif //include guard  |