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

Comparing libecb/ecb.h (file contents):
Revision 1.129 by root, Thu Mar 20 22:04:29 2014 UTC vs.
Revision 1.138 by sf-exg, Tue Oct 14 14:38:13 2014 UTC

23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- 25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH-
26 * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 26 * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 * OF THE POSSIBILITY OF SUCH DAMAGE. 27 * OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Alternatively, the contents of this file may be used under the terms of
30 * the GNU General Public License ("GPL") version 2 or any later version,
31 * in which case the provisions of the GPL are applicable instead of
32 * the above. If you wish to allow the use of your version of this file
33 * only under the terms of the GPL and not to allow others to use your
34 * version of this file under the BSD license, indicate your decision
35 * by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL. If you do not delete the
37 * provisions above, a recipient may use your version of this file under
38 * either the BSD or the GPL.
28 */ 39 */
29 40
30#ifndef ECB_H 41#ifndef ECB_H
31#define ECB_H 42#define ECB_H
32 43
79 * causing enormous grief in return for some better fake benchmark numbers. 90 * causing enormous grief in return for some better fake benchmark numbers.
80 * or so. 91 * or so.
81 * we try to detect these and simply assume they are not gcc - if they have 92 * we try to detect these and simply assume they are not gcc - if they have
82 * an issue with that they should have done it right in the first place. 93 * an issue with that they should have done it right in the first place.
83 */ 94 */
84#ifndef ECB_GCC_VERSION
85 #if !defined __GNUC_MINOR__ || defined __INTEL_COMPILER || defined __SUNPRO_C || defined __SUNPRO_CC || defined __llvm__ || defined __clang__ 95#if !defined __GNUC_MINOR__ || defined __INTEL_COMPILER || defined __SUNPRO_C || defined __SUNPRO_CC || defined __llvm__ || defined __clang__
86 #define ECB_GCC_VERSION(major,minor) 0 96 #define ECB_GCC_VERSION(major,minor) 0
87 #else 97#else
88 #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) 98 #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
89 #endif 99#endif
100
101#define ECB_CLANG_VERSION(major,minor) (__clang_major__ > (major) || (__clang_major__ == (major) && __clang_minor__ >= (minor)))
102
103#if __clang__ && defined(__has_builtin)
104 #define ECB_CLANG_BUILTIN(x) __has_builtin(x)
105#else
106 #define ECB_CLANG_BUILTIN(x) 0
90#endif 107#endif
91 108
92#define ECB_CPP (__cplusplus+0) 109#define ECB_CPP (__cplusplus+0)
93#define ECB_CPP11 (__cplusplus >= 201103L) 110#define ECB_CPP11 (__cplusplus >= 201103L)
94 111
287#define ECB_STRINGIFY_(a) # a 304#define ECB_STRINGIFY_(a) # a
288#define ECB_STRINGIFY(a) ECB_STRINGIFY_(a) 305#define ECB_STRINGIFY(a) ECB_STRINGIFY_(a)
289 306
290#define ecb_function_ ecb_inline 307#define ecb_function_ ecb_inline
291 308
292#if ECB_GCC_VERSION(3,1) 309#if ECB_GCC_VERSION(3,1) || ECB_CLANG_VERSION(2,8)
293 #define ecb_attribute(attrlist) __attribute__(attrlist) 310 #define ecb_attribute(attrlist) __attribute__(attrlist)
311#else
312 #define ecb_attribute(attrlist)
313#endif
314
315#if ECB_GCC_VERSION(3,1) || ECB_CLANG_BUILTIN(__builtin_constant_p)
294 #define ecb_is_constant(expr) __builtin_constant_p (expr) 316 #define ecb_is_constant(expr) __builtin_constant_p (expr)
295 #define ecb_expect(expr,value) __builtin_expect ((expr),(value))
296 #define ecb_prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality)
297#else 317#else
298 #define ecb_attribute(attrlist)
299
300 /* possible C11 impl for integral types 318 /* possible C11 impl for integral types
301 typedef struct ecb_is_constant_struct ecb_is_constant_struct; 319 typedef struct ecb_is_constant_struct ecb_is_constant_struct;
302 #define ecb_is_constant(expr) _Generic ((1 ? (struct ecb_is_constant_struct *)0 : (void *)((expr) - (expr)), ecb_is_constant_struct *: 0, default: 1)) */ 320 #define ecb_is_constant(expr) _Generic ((1 ? (struct ecb_is_constant_struct *)0 : (void *)((expr) - (expr)), ecb_is_constant_struct *: 0, default: 1)) */
303 321
304 #define ecb_is_constant(expr) 0 322 #define ecb_is_constant(expr) 0
323#endif
324
325#if ECB_GCC_VERSION(3,1) || ECB_CLANG_BUILTIN(__builtin_expect)
326 #define ecb_expect(expr,value) __builtin_expect ((expr),(value))
327#else
305 #define ecb_expect(expr,value) (expr) 328 #define ecb_expect(expr,value) (expr)
329#endif
330
331#if ECB_GCC_VERSION(3,1) || ECB_CLANG_BUILTIN(__builtin_prefetch)
332 #define ecb_prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality)
333#else
306 #define ecb_prefetch(addr,rw,locality) 334 #define ecb_prefetch(addr,rw,locality)
307#endif 335#endif
308 336
309/* no emulation for ecb_decltype */ 337/* no emulation for ecb_decltype */
310#if ECB_GCC_VERSION(4,5) 338#if ECB_GCC_VERSION(4,5)
311 #define ecb_decltype(x) __decltype(x) 339 #define ecb_decltype(x) __decltype(x)
312#elif ECB_GCC_VERSION(3,0) 340#elif ECB_GCC_VERSION(3,0)
313 #define ecb_decltype(x) __typeof(x) 341 #define ecb_decltype(x) __typeof(x)
314#endif 342#endif
315 343
344#if _MSC_VER >= 1300
345 #define ecb_deprecated __declspec(deprecated)
346#else
347 #define ecb_deprecated ecb_attribute ((__deprecated__))
348#endif
349
316#define ecb_noinline ecb_attribute ((__noinline__)) 350#define ecb_noinline ecb_attribute ((__noinline__))
317#define ecb_unused ecb_attribute ((__unused__)) 351#define ecb_unused ecb_attribute ((__unused__))
318#define ecb_const ecb_attribute ((__const__)) 352#define ecb_const ecb_attribute ((__const__))
319#define ecb_pure ecb_attribute ((__pure__)) 353#define ecb_pure ecb_attribute ((__pure__))
320 354
355/* http://msdn.microsoft.com/en-us/library/k6ktzx3s.aspx __declspec(noreturn) */
321#if ECB_C11 356#if ECB_C11
322 #define ecb_noreturn _Noreturn 357 #define ecb_noreturn _Noreturn
323#else 358#else
324 #define ecb_noreturn ecb_attribute ((__noreturn__)) 359 #define ecb_noreturn ecb_attribute ((__noreturn__))
325#endif 360#endif
342/* for compatibility to the rest of the world */ 377/* for compatibility to the rest of the world */
343#define ecb_likely(expr) ecb_expect_true (expr) 378#define ecb_likely(expr) ecb_expect_true (expr)
344#define ecb_unlikely(expr) ecb_expect_false (expr) 379#define ecb_unlikely(expr) ecb_expect_false (expr)
345 380
346/* count trailing zero bits and count # of one bits */ 381/* count trailing zero bits and count # of one bits */
347#if ECB_GCC_VERSION(3,4) 382#if ECB_GCC_VERSION(3,4) || (ECB_CLANG_BUILTIN(__builtin_clz) && ECB_CLANG_BUILTIN(__builtin_clzll) \
383 && ECB_CLANG_BUILTIN(__builtin_ctz) && ECB_CLANG_BUILTIN(__builtin_ctzll) \
384 && ECB_CLANG_BUILTIN(__builtin_popcount))
348 /* we assume int == 32 bit, long == 32 or 64 bit and long long == 64 bit */ 385 /* we assume int == 32 bit, long == 32 or 64 bit and long long == 64 bit */
349 #define ecb_ld32(x) (__builtin_clz (x) ^ 31) 386 #define ecb_ld32(x) (__builtin_clz (x) ^ 31)
350 #define ecb_ld64(x) (__builtin_clzll (x) ^ 63) 387 #define ecb_ld64(x) (__builtin_clzll (x) ^ 63)
351 #define ecb_ctz32(x) __builtin_ctz (x) 388 #define ecb_ctz32(x) __builtin_ctz (x)
352 #define ecb_ctz64(x) __builtin_ctzll (x) 389 #define ecb_ctz64(x) __builtin_ctzll (x)
483ecb_inline uint32_t ecb_rotl32 (uint32_t x, unsigned int count) { return (x >> (32 - count)) | (x << count); } 520ecb_inline uint32_t ecb_rotl32 (uint32_t x, unsigned int count) { return (x >> (32 - count)) | (x << count); }
484ecb_inline uint32_t ecb_rotr32 (uint32_t x, unsigned int count) { return (x << (32 - count)) | (x >> count); } 521ecb_inline uint32_t ecb_rotr32 (uint32_t x, unsigned int count) { return (x << (32 - count)) | (x >> count); }
485ecb_inline uint64_t ecb_rotl64 (uint64_t x, unsigned int count) { return (x >> (64 - count)) | (x << count); } 522ecb_inline uint64_t ecb_rotl64 (uint64_t x, unsigned int count) { return (x >> (64 - count)) | (x << count); }
486ecb_inline uint64_t ecb_rotr64 (uint64_t x, unsigned int count) { return (x << (64 - count)) | (x >> count); } 523ecb_inline uint64_t ecb_rotr64 (uint64_t x, unsigned int count) { return (x << (64 - count)) | (x >> count); }
487 524
488#if ECB_GCC_VERSION(4,3) 525#if ECB_GCC_VERSION(4,3) || (ECB_CLANG_BUILTIN(__builtin_bswap32) && ECB_CLANG_BUILTIN(__builtin_bswap64))
489 #define ecb_bswap16(x) (__builtin_bswap32 (x) >> 16) 526 #define ecb_bswap16(x) (__builtin_bswap32 (x) >> 16)
490 #define ecb_bswap32(x) __builtin_bswap32 (x) 527 #define ecb_bswap32(x) __builtin_bswap32 (x)
491 #define ecb_bswap64(x) __builtin_bswap64 (x) 528 #define ecb_bswap64(x) __builtin_bswap64 (x)
492#else 529#else
493 ecb_function_ uint16_t ecb_bswap16 (uint16_t x) ecb_const; 530 ecb_function_ uint16_t ecb_bswap16 (uint16_t x) ecb_const;
510 { 547 {
511 return (((uint64_t)ecb_bswap32 (x)) << 32) | ecb_bswap32 (x >> 32); 548 return (((uint64_t)ecb_bswap32 (x)) << 32) | ecb_bswap32 (x >> 32);
512 } 549 }
513#endif 550#endif
514 551
515#if ECB_GCC_VERSION(4,5) 552#if ECB_GCC_VERSION(4,5) || ECB_CLANG_BUILTIN(__builtin_unreachable)
516 #define ecb_unreachable() __builtin_unreachable () 553 #define ecb_unreachable() __builtin_unreachable ()
517#else 554#else
518 /* this seems to work fine, but gcc always emits a warning for it :/ */ 555 /* this seems to work fine, but gcc always emits a warning for it :/ */
519 ecb_inline void ecb_unreachable (void) ecb_noreturn; 556 ecb_inline void ecb_unreachable (void) ecb_noreturn;
520 ecb_inline void ecb_unreachable (void) { } 557 ecb_inline void ecb_unreachable (void) { }
594/* the only noteworthy exception is ancient armle, which uses order 43218765 */ 631/* the only noteworthy exception is ancient armle, which uses order 43218765 */
595#if 0 \ 632#if 0 \
596 || __i386 || __i386__ \ 633 || __i386 || __i386__ \
597 || __amd64 || __amd64__ || __x86_64 || __x86_64__ \ 634 || __amd64 || __amd64__ || __x86_64 || __x86_64__ \
598 || __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ \ 635 || __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ \
599 || defined __arm__ && defined __ARM_EABI__ \
600 || defined __s390__ || defined __s390x__ \ 636 || defined __s390__ || defined __s390x__ \
601 || defined __mips__ \ 637 || defined __mips__ \
602 || defined __alpha__ \ 638 || defined __alpha__ \
603 || defined __hppa__ \ 639 || defined __hppa__ \
604 || defined __ia64__ \ 640 || defined __ia64__ \
605 || defined __m68k__ \ 641 || defined __m68k__ \
606 || defined __m88k__ \ 642 || defined __m88k__ \
607 || defined __sh__ \ 643 || defined __sh__ \
608 || defined _M_IX86 || defined _M_AMD64 || defined _M_IA64 644 || defined _M_IX86 || defined _M_AMD64 || defined _M_IA64 \
645 || (defined __arm__ && (defined __ARM_EABI__ || defined __EABI__ || defined __VFP_FP__ || defined _WIN32_WCE || defined __ANDROID__)) \
646 || defined __aarch64__
609 #define ECB_STDFP 1 647 #define ECB_STDFP 1
610 #include <string.h> /* for memcpy */ 648 #include <string.h> /* for memcpy */
611#else 649#else
612 #define ECB_STDFP 0 650 #define ECB_STDFP 0
613#endif 651#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines