ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libecb/ecb.h
(Generate patch)

Comparing libecb/ecb.h (file contents):
Revision 1.11 by root, Thu May 26 18:00:42 2011 UTC vs.
Revision 1.13 by root, Thu May 26 18:21:04 2011 UTC

30#ifndef ECB_H 30#ifndef ECB_H
31#define ECB_H 31#define ECB_H
32 32
33#include <inttypes.h> 33#include <inttypes.h>
34 34
35/* many compilers define _GNUC_ to some versions but then only implement
36 * what their idiot authors think are the "more important" extensions,
37 * causing enourmous grief for some better fake benchmark numbers or so.
38 * we try to detect these and simply assume they are not gcc - if they have
39 * an issue with that they should have done it right in the first place.
40 */
41#if defined(__INTEL_COMPILER) || defined(__SUNPRO_C) || defined(__llvm__)
42# define ECB_GCC_VERSION(major,minor) 0
43#else
35#define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) 44# define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
45#endif
36 46
37#ifndef __cplusplus 47#ifndef __cplusplus
38# if __STDC_VERSION__ >= 199901L 48# if __STDC_VERSION__ >= 199901L
39# define ECB_INLINE inline 49# define ECB_INLINE inline
40typedef _Bool ecb_bool; 50typedef _Bool ecb_bool;
76#define ecb_const ecb_attribute ((const)) 86#define ecb_const ecb_attribute ((const))
77#define ecb_pure ecb_attribute ((pure)) 87#define ecb_pure ecb_attribute ((pure))
78#define ecb_hot ecb_attribute ((hot)) /* 4.3 */ 88#define ecb_hot ecb_attribute ((hot)) /* 4.3 */
79#define ecb_cold ecb_attribute ((cold)) /* 4.3 */ 89#define ecb_cold ecb_attribute ((cold)) /* 4.3 */
80 90
81#if ECB_GCC_VERSION(4,5)
82# define ecb_unreachable() __builtin_unreachable ()
83#else
84/* this seems to work fine, but gcc always emits a warning for it :/ */
85ECB_HEADER_INLINE void ecb_unreachable () ecb_attribute ((noreturn));
86ECB_HEADER_INLINE void ecb_unreachable () { }
87#endif
88
89/* put into ifs if you are very sure that the expression */ 91/* put into ifs if you are very sure that the expression */
90/* is mostly true or mosty false. note that these return */ 92/* is mostly true or mosty false. note that these return */
91/* booleans, not the expression. */ 93/* booleans, not the expression. */
92#define ecb_unlikely(expr) ecb_expect (!!(expr), 0) 94#define ecb_unlikely(expr) ecb_expect (!!(expr), 0)
93#define ecb_likely(expr) ecb_expect (!!(expr), 1) 95#define ecb_likely(expr) ecb_expect (!!(expr), 1)
126 128
127 return x >> 24; 129 return x >> 24;
128} 130}
129#endif 131#endif
130 132
133#if ECB_GCC_VERSION(4,3)
134ECB_GCC_VERSION uint32_t ecb_bswap32 (uint32_t x) { return __builtin_bswap32 (x); }
135#else
136ECB_GCC_VERSION uint32_t
137ecb_bswap32 (uint32_t x)
138{
139 return (x >> 24)
140 | ((x >> 8) & 0x0000ff00)
141 | ((x << 8) & 0x00ff0000)
142 | (x << 24);
143}
144#endif
145
146#if ECB_GCC_VERSION(4,5)
147# define ecb_unreachable() __builtin_unreachable ()
148#else
149/* this seems to work fine, but gcc always emits a warning for it :/ */
150ECB_HEADER_INLINE void ecb_unreachable () ecb_attribute ((noreturn));
151ECB_HEADER_INLINE void ecb_unreachable () { }
152#endif
153
131ECB_HEADER_INLINE unsigned char 154ECB_HEADER_INLINE unsigned char
132ecb_byteorder_helper () ecb_const 155ecb_byteorder_helper () ecb_const
133{ 156{
134 const uint32_t u = 0x11223344; 157 const uint32_t u = 0x11223344;
135 return *(unsigned char *)&u; 158 return *(unsigned char *)&u;
159ecb_rotl32 (uint32_t x, unsigned int count) 182ecb_rotl32 (uint32_t x, unsigned int count)
160{ 183{
161 return (x >> (32 - count)) | (x << count); 184 return (x >> (32 - count)) | (x << count);
162} 185}
163 186
164#if ECB_GCC_VERSION(4,3)
165# define ecb_bswap32(x) __builtin_bswap32 (x)
166#else
167ECB_GCC_VERSION uint32_t
168ecb_bswap32 (uint32_t x)
169{
170 return (x >> 24)
171 | ((x >> 8) & 0x0000ff00)
172 | ((x << 8) & 0x00ff0000)
173 | (x << 24);
174}
175#endif 187#endif
176 188
177#endif
178

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines