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

Comparing libecb/ecb.h (file contents):
Revision 1.24 by root, Thu May 26 19:49:21 2011 UTC vs.
Revision 1.30 by root, Mon May 30 18:30:00 2011 UTC

1/* 1/*
2 * libecb - http://software.schmorp.de/pkg/libecb 2 * libecb - http://software.schmorp.de/pkg/libecb
3 * 3 *
4 * Copyright (©) 2009-2011 Marc Alexander Lehmann 4 * Copyright (©) 2009-2011 Marc Alexander Lehmann <libecb@schmorp.de>
5 * Copyright (©) 2011 Emanuele Giaquinta 5 * Copyright (©) 2011 Emanuele Giaquinta
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without modifica- 8 * Redistribution and use in source and binary forms, with or without modifica-
9 * tion, are permitted provided that the following conditions are met: 9 * tion, are permitted provided that the following conditions are met:
53typedef _Bool ecb_bool; 53typedef _Bool ecb_bool;
54# else 54# else
55# define ECB_INLINE inline /* yeah! */ 55# define ECB_INLINE inline /* yeah! */
56typedef int ecb_bool; 56typedef int ecb_bool;
57# endif 57# endif
58#else
59# define ECB_INLINE inline
60typedef bool ecb_bool;
58#endif 61#endif
59 62
60#define ECB_CONCAT_(a, b) a ## b 63#define ECB_CONCAT_(a, b) a ## b
61#define ECB_CONCAT(a, b) ECB_CONCAT_(a, b) 64#define ECB_CONCAT(a, b) ECB_CONCAT_(a, b)
62#define ECB_STRINGIFY_(a) # a 65#define ECB_STRINGIFY_(a) # a
81# define ecb_decltype(x) __decltype(x) 84# define ecb_decltype(x) __decltype(x)
82#elif ECB_GCC_VERSION(3,0) 85#elif ECB_GCC_VERSION(3,0)
83# define ecb_decltype(x) typeof(x) 86# define ecb_decltype(x) typeof(x)
84#endif 87#endif
85 88
86#define ecb_artificial ecb_attribute ((__artificial__)) 89#define ecb_artificial ecb_attribute ((__artificial__)) /* 4.3 */
87#define ecb_noinline ecb_attribute ((__noinline__)) 90#define ecb_noinline ecb_attribute ((__noinline__))
88#define ecb_noreturn ecb_attribute ((__noreturn__)) 91#define ecb_noreturn ecb_attribute ((__noreturn__))
89#define ecb_unused ecb_attribute ((__unused__)) 92#define ecb_unused ecb_attribute ((__unused__))
90#define ecb_const ecb_attribute ((__const__)) 93#define ecb_const ecb_attribute ((__const__))
91#define ecb_pure ecb_attribute ((__pure__)) 94#define ecb_pure ecb_attribute ((__pure__))
101/* try to tell the compiler that some condition is definitely true */ 104/* try to tell the compiler that some condition is definitely true */
102#define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0) 105#define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0)
103 106
104/* count trailing zero bits and count # of one bits */ 107/* count trailing zero bits and count # of one bits */
105#if ECB_GCC_VERSION(3,4) 108#if ECB_GCC_VERSION(3,4)
106#define ecb_ctz32 (x) __builtin_ctz (x) 109#define ecb_ctz32(x) __builtin_ctz (x)
107#define ecb_popcount32 (x) __builtin_popcount (x) 110#define ecb_popcount32(x) __builtin_popcount (x)
108#else 111#else
109ECB_HEADER_INLINE int ecb_ctz32 (uint32_t x) ecb_const; 112ECB_HEADER_INLINE int ecb_ctz32 (uint32_t x) ecb_const;
110ECB_HEADER_INLINE 113ECB_HEADER_INLINE
111ecb_ctz32 (uint32_t x) 114ecb_ctz32 (uint32_t x)
112{ 115{
179ECB_HEADER_INLINE ecb_bool ecb_big_endian (void) ecb_const; 182ECB_HEADER_INLINE ecb_bool ecb_big_endian (void) ecb_const;
180ECB_HEADER_INLINE ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; }; 183ECB_HEADER_INLINE ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; };
181ECB_HEADER_INLINE ecb_bool ecb_little_endian (void) ecb_const; 184ECB_HEADER_INLINE ecb_bool ecb_little_endian (void) ecb_const;
182ECB_HEADER_INLINE ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; }; 185ECB_HEADER_INLINE ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; };
183 186
184#define ecb_mod(m, n) ((m) < 0 ? ((n) - (-(m) % (n))) : ((m) % (n))) 187#define ecb_mod(m,n) ((m) < 0 ? ((n) - (-(m) % (n))) : ((m) % (n)))
185 188
186#if ecb_cplusplus_does_not_suck 189#if ecb_cplusplus_does_not_suck
187// does not work for local types (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm) 190// does not work for local types (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm)
188template<typename T, int N> 191template<typename T, int N>
189static inline int ecb_array_length (const T (&arr)[N]) 192static inline int ecb_array_length (const T (&arr)[N])

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines