1 /* 2 Copyright (c) 2018, MIPI Alliance, Inc. 3 All rights reserved. 4 5 Redistribution and use in source and binary forms, with or without 6 modification, are permitted provided that the following conditions 7 are met: 8 9 * Redistributions of source code must retain the above copyright 10 notice, this list of conditions and the following disclaimer. 11 12 * Redistributions in binary form must reproduce the above copyright 13 notice, this list of conditions and the following disclaimer in 14 the documentation and/or other materials provided with the 15 distribution. 16 17 * Neither the name of the copyright holder nor the names of its 18 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 * Contributors: 36 * Norbert Schulz (Intel Corporation) - Initial API and implementation 37 */ 38 39 /* Compiler specific defines */ 40 41 #ifndef MIPI_SYST_COMPILER_INCLUDED 42 #define MIPI_SYST_COMPILER_INCLUDED 43 44 #if defined(__cplusplus) 45 extern "C" { 46 #endif 47 48 #if defined(_WIN32) /* MSVC Compiler section */ 49 50 /* basic integer types 51 */ 52 typedef __int8 mipi_syst_s8; 53 typedef __int16 mipi_syst_s16; 54 typedef __int32 mipi_syst_s32; 55 typedef __int64 mipi_syst_s64; 56 57 typedef unsigned __int8 mipi_syst_u8; 58 typedef unsigned __int16 mipi_syst_u16; 59 typedef unsigned __int32 mipi_syst_u32; 60 typedef unsigned __int64 mipi_syst_u64; 61 62 /* shared library import/export 63 */ 64 #if defined(MIPI_SYST_STATIC) 65 #define MIPI_SYST_EXPORT 66 #define MIPI_SYST_EXPORT 67 #else 68 #if defined(MIPI_SYST_EXPORTS) 69 #define MIPI_SYST_EXPORT __declspec(dllexport) 70 #else 71 #define MIPI_SYST_EXPORT __declspec(dllimport) 72 #endif 73 #endif 74 75 #define MIPI_SYST_CALLCONV __stdcall 76 77 /* Caution: Windows doesn't support attribute based shared library 78 * life time functions. Add these calls into a dllmain routine 79 * instead. 80 */ 81 #define MIPI_SYST_SHAREDLIB_CONSTRUCTOR 82 #define MIPI_SYST_SHAREDLIB_DESTRUCTOR 83 84 #define MIPI_SYST_FUNCTION_NAME __FUNCTION__ 85 #define MIPI_SYST_LINE __LINE__ 86 #define MIPI_SYST_FILE __FILE__ 87 88 #if defined(NDEBUG) 89 #define _MIPI_SYST_OPTIMIZER_ON 90 #endif 91 92 #define MIPI_SYST_CC_INLINE __inline 93 94 /* Macros for byte swapping to little endian 95 * 96 * Assume this compiler is always little endian 97 */ 98 #define MIPI_SYST_HTOLE16(v) (v) 99 #define MIPI_SYST_HTOLE32(v) (v) 100 #define MIPI_SYST_HTOLE64(v) (v) 101 102 /* HW CRC32C support ? */ 103 #if defined(MIPI_SYST_CRC_INTRINSIC_ON) 104 #define MIPI_SYST_CRC_INTRINSIC 105 106 #include <intrin.h> 107 #define _MIPI_SYST_CPU_CRC8(crc, v) _mm_crc32_u8((crc), (v)) 108 #define _MIPI_SYST_CPU_CRC16(crc, v) _mm_crc32_u16((crc), (v)) 109 #define _MIPI_SYST_CPU_CRC32(crc, v) _mm_crc32_u32((crc), (v)) 110 #if defined(_WIN64) 111 #define _MIPI_SYST_CPU_CRC64(crc, v) (mipi_syst_u32)_mm_crc32_u64((crc), (v)) 112 #else 113 #define _MIPI_SYST_CPU_CRC64(crc, v) \ 114 _mm_crc32_u32(\ 115 _mm_crc32_u32((crc), (mipi_syst_u32)(v)), \ 116 ((mipi_syst_u32)((v)>> 32))\ 117 ) 118 #endif 119 #endif 120 121 #elif defined(__GNUC__) /* GNU-C Compiler section */ 122 123 /* basic integer types 124 */ 125 typedef char mipi_syst_s8; 126 typedef short mipi_syst_s16; 127 typedef int mipi_syst_s32; 128 typedef long long mipi_syst_s64; 129 130 typedef unsigned char mipi_syst_u8; 131 typedef unsigned short mipi_syst_u16; 132 typedef unsigned int mipi_syst_u32; 133 typedef unsigned long long mipi_syst_u64; 134 135 /* shared library related settings 136 */ 137 #define MIPI_SYST_EXPORT 138 #define MIPI_SYST_CALLCONV 139 140 #define MIPI_SYST_SHAREDLIB_CONSTRUCTOR __attribute__((constructor)) 141 #define MIPI_SYST_SHAREDLIB_DESTRUCTOR __attribute__((destructor)) 142 143 #define MIPI_SYST_FUNCTION_NAME __PRETTY_FUNCTION__ 144 #define MIPI_SYST_LINE __LINE__ 145 #define MIPI_SYST_FILE __FILE__ 146 #define MIPI_SYST_CC_INLINE inline 147 148 /* Macros for byte swapping to little endian 149 */ 150 #if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 151 #define MIPI_SYST_BIG_ENDIAN 152 153 #define MIPI_SYST_HTOLE16(v) \ 154 ((((mipi_syst_u16)(v))>>8)|((((mipi_syst_u16)(v))&0xFF)<<8)) 155 #define MIPI_SYST_HTOLE32(v) \ 156 ((mipi_syst_u32)__builtin_bswap32((mipi_syst_u32)(v))) 157 #define MIPI_SYST_HTOLE64(v) \ 158 ((mipi_syst_u64)__builtin_bswap64((mipi_syst_u64)(v))) 159 #else 160 #define MIPI_SYST_HTOLE16(v) (v) 161 #define MIPI_SYST_HTOLE32(v) (v) 162 #define MIPI_SYST_HTOLE64(v) (v) 163 #endif 164 165 #if defined(__OPTIMIZE__) 166 #define _MIPI_SYST_OPTIMIZER_ON 167 #endif 168 169 /* HW CRC32C support ? */ 170 #if defined(MIPI_SYST_CRC_INTRINSIC_ON) 171 #define MIPI_SYST_CRC_INTRINSIC 172 173 #define _MIPI_SYST_CPU_CRC8(crc, v) __builtin_ia32_crc32qi((crc), (v)) 174 #define _MIPI_SYST_CPU_CRC16(crc, v) __builtin_ia32_crc32hi((crc), (v)) 175 #define _MIPI_SYST_CPU_CRC32(crc, v) __builtin_ia32_crc32si((crc), (v)) 176 #if defined(_WIN64) || defined(__x86_64__) || defined (__LP64__) 177 #define _MIPI_SYST_CPU_CRC64(crc, v) (mipi_syst_u32)__builtin_ia32_crc32di((crc), (v)) 178 #else 179 #define _MIPI_SYST_CPU_CRC64(crc, v) \ 180 __builtin_ia32_crc32si (\ 181 __builtin_ia32_crc32si((crc), (mipi_syst_u32)(v)), \ 182 ((mipi_syst_u32)((v)>> 32))\ 183 ) 184 #endif 185 #endif 186 #else 187 #error unknown compiler, copy and adapt one of the sections above 188 #endif 189 190 #ifdef __cplusplus 191 } /* extern C */ 192 #endif 193 #endif 194