github.com/Schaudge/grailbase@v0.0.0-20240223061707-44c758a471c0/compress/libdeflate/compiler_msc.h (about) 1 #ifndef GO_SRC_GITHUB_COM_GRAILBIO_BASE_COMPRESS_LIBDEFLATE_COMPILER_MSC_H_ 2 #define GO_SRC_GITHUB_COM_GRAILBIO_BASE_COMPRESS_LIBDEFLATE_COMPILER_MSC_H_ 3 /* 4 * compiler_msc.h - definitions for the Microsoft C Compiler 5 */ 6 7 #define LIBEXPORT __declspec(dllexport) 8 9 /* 10 * Old versions (e.g. VS2010) of MSC don't have the C99 header stdbool.h. 11 * Beware: the below replacement isn't fully standard, since normally any value 12 * != 0 should be implicitly cast to a bool with value 1... but that doesn't 13 * happen if bool is really just an 'int'. 14 */ 15 typedef int bool; 16 #define true 1 17 #define false 0 18 #define __bool_true_false_are_defined 1 19 20 /* Define ssize_t */ 21 #ifdef _WIN64 22 typedef long long ssize_t; 23 #else 24 typedef int ssize_t; 25 #endif 26 27 /* 28 * Old versions (e.g. VS2010) of MSC have stdint.h but not the C99 header 29 * inttypes.h. Work around this by defining the PRI* macros ourselves. 30 */ 31 #include <stdint.h> 32 #define PRIu8 "hhu" 33 #define PRIu16 "hu" 34 #define PRIu32 "u" 35 #define PRIu64 "llu" 36 #define PRIi8 "hhi" 37 #define PRIi16 "hi" 38 #define PRIi32 "i" 39 #define PRIi64 "lli" 40 #define PRIx8 "hhx" 41 #define PRIx16 "hx" 42 #define PRIx32 "x" 43 #define PRIx64 "llx" 44 45 /* Assume a little endian architecture with fast unaligned access */ 46 #define CPU_IS_LITTLE_ENDIAN() 1 47 #define UNALIGNED_ACCESS_IS_FAST 1 48 49 /* __restrict has nonstandard behavior; don't use it */ 50 #define restrict 51 52 /* ... but we can use __inline and __forceinline */ 53 #define inline __inline 54 #define forceinline __forceinline 55 56 /* Byte swap functions */ 57 #define bswap16 _byteswap_ushort 58 #define bswap32 _byteswap_ulong 59 #define bswap64 _byteswap_uint64 60 61 /* Bit scan functions (32-bit) */ 62 63 static forceinline unsigned 64 bsr32(uint32_t n) 65 { 66 _BitScanReverse(&n, n); 67 return n; 68 } 69 #define bsr32 bsr32 70 71 static forceinline unsigned 72 bsf32(uint32_t n) 73 { 74 _BitScanForward(&n, n); 75 return n; 76 } 77 #define bsf32 bsf32 78 79 #ifdef _M_X64 /* Bit scan functions (64-bit) */ 80 81 static forceinline unsigned 82 bsr64(uint64_t n) 83 { 84 _BitScanReverse64(&n, n); 85 return n; 86 } 87 #define bsr64 bsr64 88 89 static forceinline unsigned 90 bsf64(uint64_t n) 91 { 92 _BitScanForward64(&n, n); 93 return n; 94 } 95 #define bsf64 bsf64 96 97 #endif /* _M_X64 */ 98 99 #endif // GO_SRC_GITHUB_COM_GRAILBIO_BASE_COMPRESS_LIBDEFLATE_COMPILER_MSC_H_