ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.474 by root, Wed Feb 11 19:20:21 2015 UTC vs.
Revision 1.477 by root, Sun Aug 9 00:13:28 2015 UTC

566 #else 566 #else
567 #define ECB_PTRSIZE 4 567 #define ECB_PTRSIZE 4
568 #endif 568 #endif
569#endif 569#endif
570 570
571#define ECB_GCC_AMD64 (__amd64 || __amd64__ || __x86_64 || __x86_64__)
572#define ECB_MSVC_AMD64 (_M_AMD64 || _M_X64)
573
571/* work around x32 idiocy by defining proper macros */ 574/* work around x32 idiocy by defining proper macros */
572#if __amd64 || __x86_64 || _M_AMD64 || _M_X64 575#if ECB_GCC_AMD64 || ECB_MSVC_AMD64
573 #if _ILP32 576 #if _ILP32
574 #define ECB_AMD64_X32 1 577 #define ECB_AMD64_X32 1
575 #else 578 #else
576 #define ECB_AMD64 1 579 #define ECB_AMD64 1
577 #endif 580 #endif
639 642
640#if ECB_NO_SMP 643#if ECB_NO_SMP
641 #define ECB_MEMORY_FENCE do { } while (0) 644 #define ECB_MEMORY_FENCE do { } while (0)
642#endif 645#endif
643 646
647/* http://www-01.ibm.com/support/knowledgecenter/SSGH3R_13.1.0/com.ibm.xlcpp131.aix.doc/compiler_ref/compiler_builtins.html */
648#if __xlC__ && ECB_CPP
649 #include <builtins.h>
650#endif
651
644#ifndef ECB_MEMORY_FENCE 652#ifndef ECB_MEMORY_FENCE
645 #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 653 #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
646 #if __i386 || __i386__ 654 #if __i386 || __i386__
647 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") 655 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory")
648 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") 656 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
649 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") 657 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("")
650 #elif __amd64 || __amd64__ || __x86_64 || __x86_64__ 658 #elif ECB_GCC_AMD64
651 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") 659 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory")
652 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") 660 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
653 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") 661 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("")
654 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ 662 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__
655 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") 663 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
659 #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \ 667 #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \
660 || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__ 668 || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__
661 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") 669 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory")
662 #elif __aarch64__ 670 #elif __aarch64__
663 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb ish" : : : "memory") 671 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb ish" : : : "memory")
664 #elif (__sparc || __sparc__) && !__sparcv8 672 #elif (__sparc || __sparc__) && !(__sparc_v8__ || defined __sparcv8)
665 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad" : : : "memory") 673 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad" : : : "memory")
666 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") 674 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory")
667 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") 675 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore")
668 #elif defined __s390__ || defined __s390x__ 676 #elif defined __s390__ || defined __s390x__
669 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory") 677 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory")
794 802
795#define ECB_CONCAT_(a, b) a ## b 803#define ECB_CONCAT_(a, b) a ## b
796#define ECB_CONCAT(a, b) ECB_CONCAT_(a, b) 804#define ECB_CONCAT(a, b) ECB_CONCAT_(a, b)
797#define ECB_STRINGIFY_(a) # a 805#define ECB_STRINGIFY_(a) # a
798#define ECB_STRINGIFY(a) ECB_STRINGIFY_(a) 806#define ECB_STRINGIFY(a) ECB_STRINGIFY_(a)
807#define ECB_STRINGIFY_EXPR(expr) ((expr), ECB_STRINGIFY_ (expr))
799 808
800#define ecb_function_ ecb_inline 809#define ecb_function_ ecb_inline
801 810
802#if ECB_GCC_VERSION(3,1) || ECB_CLANG_VERSION(2,8) 811#if ECB_GCC_VERSION(3,1) || ECB_CLANG_VERSION(2,8)
803 #define ecb_attribute(attrlist) __attribute__ (attrlist) 812 #define ecb_attribute(attrlist) __attribute__ (attrlist)
840 #define ecb_deprecated __declspec (deprecated) 849 #define ecb_deprecated __declspec (deprecated)
841#else 850#else
842 #define ecb_deprecated ecb_attribute ((__deprecated__)) 851 #define ecb_deprecated ecb_attribute ((__deprecated__))
843#endif 852#endif
844 853
854#if _MSC_VER >= 1500
855 #define ecb_deprecated_message(msg) __declspec (deprecated (msg))
856#elif ECB_GCC_VERSION(4,5)
857 #define ecb_deprecated_message(msg) ecb_attribute ((__deprecated__ (msg))
858#else
859 #define ecb_deprecated_message(msg) ecb_deprecated
860#endif
861
862#if _MSC_VER >= 1400
863 #define ecb_noinline __declspec (noinline)
864#else
845#define ecb_noinline ecb_attribute ((__noinline__)) 865 #define ecb_noinline ecb_attribute ((__noinline__))
866#endif
867
846#define ecb_unused ecb_attribute ((__unused__)) 868#define ecb_unused ecb_attribute ((__unused__))
847#define ecb_const ecb_attribute ((__const__)) 869#define ecb_const ecb_attribute ((__const__))
848#define ecb_pure ecb_attribute ((__pure__)) 870#define ecb_pure ecb_attribute ((__pure__))
849 871
850/* TODO http://msdn.microsoft.com/en-us/library/k6ktzx3s.aspx __declspec(noreturn) */
851#if ECB_C11 || __IBMC_NORETURN 872#if ECB_C11 || __IBMC_NORETURN
852 /* http://pic.dhe.ibm.com/infocenter/compbg/v121v141/topic/com.ibm.xlcpp121.bg.doc/language_ref/noreturn.html */ 873 /* http://www-01.ibm.com/support/knowledgecenter/SSGH3R_13.1.0/com.ibm.xlcpp131.aix.doc/language_ref/noreturn.html */
853 #define ecb_noreturn _Noreturn 874 #define ecb_noreturn _Noreturn
875#elif ECB_CPP11
876 #define ecb_noreturn [[noreturn]]
877#elif _MSC_VER >= 1200
878 /* http://msdn.microsoft.com/en-us/library/k6ktzx3s.aspx */
879 #define ecb_noreturn __declspec (noreturn)
854#else 880#else
855 #define ecb_noreturn ecb_attribute ((__noreturn__)) 881 #define ecb_noreturn ecb_attribute ((__noreturn__))
856#endif 882#endif
857 883
858#if ECB_GCC_VERSION(4,3) 884#if ECB_GCC_VERSION(4,3)
1018ecb_inline ecb_const uint32_t ecb_rotr32 (uint32_t x, unsigned int count) { return (x << (32 - count)) | (x >> count); } 1044ecb_inline ecb_const uint32_t ecb_rotr32 (uint32_t x, unsigned int count) { return (x << (32 - count)) | (x >> count); }
1019ecb_inline ecb_const uint64_t ecb_rotl64 (uint64_t x, unsigned int count) { return (x >> (64 - count)) | (x << count); } 1045ecb_inline ecb_const uint64_t ecb_rotl64 (uint64_t x, unsigned int count) { return (x >> (64 - count)) | (x << count); }
1020ecb_inline ecb_const uint64_t ecb_rotr64 (uint64_t x, unsigned int count) { return (x << (64 - count)) | (x >> count); } 1046ecb_inline ecb_const uint64_t ecb_rotr64 (uint64_t x, unsigned int count) { return (x << (64 - count)) | (x >> count); }
1021 1047
1022#if ECB_GCC_VERSION(4,3) || (ECB_CLANG_BUILTIN(__builtin_bswap32) && ECB_CLANG_BUILTIN(__builtin_bswap64)) 1048#if ECB_GCC_VERSION(4,3) || (ECB_CLANG_BUILTIN(__builtin_bswap32) && ECB_CLANG_BUILTIN(__builtin_bswap64))
1049 #if ECB_GCC_VERSION(4,8) || ECB_CLANG_BUILTIN(__builtin_bswap16)
1050 #define ecb_bswap16(x) __builtin_bswap16 (x)
1051 #else
1023 #define ecb_bswap16(x) (__builtin_bswap32 (x) >> 16) 1052 #define ecb_bswap16(x) (__builtin_bswap32 (x) >> 16)
1053 #endif
1024 #define ecb_bswap32(x) __builtin_bswap32 (x) 1054 #define ecb_bswap32(x) __builtin_bswap32 (x)
1025 #define ecb_bswap64(x) __builtin_bswap64 (x) 1055 #define ecb_bswap64(x) __builtin_bswap64 (x)
1056#elif _MSC_VER
1057 #include <stdlib.h>
1058 #define ecb_bswap16(x) ((uint16_t)_byteswap_ushort ((uint16_t)(x)))
1059 #define ecb_bswap32(x) ((uint32_t)_byteswap_ulong ((uint32_t)(x)))
1060 #define ecb_bswap64(x) ((uint64_t)_byteswap_uint64 ((uint64_t)(x)))
1026#else 1061#else
1027 ecb_function_ ecb_const uint16_t ecb_bswap16 (uint16_t x); 1062 ecb_function_ ecb_const uint16_t ecb_bswap16 (uint16_t x);
1028 ecb_function_ ecb_const uint16_t 1063 ecb_function_ ecb_const uint16_t
1029 ecb_bswap16 (uint16_t x) 1064 ecb_bswap16 (uint16_t x)
1030 { 1065 {
1065 /* but less than using pointers, and always seems to */ 1100 /* but less than using pointers, and always seems to */
1066 /* successfully return a constant. */ 1101 /* successfully return a constant. */
1067 /* the reason why we have this horrible preprocessor mess */ 1102 /* the reason why we have this horrible preprocessor mess */
1068 /* is to avoid it in all cases, at least on common architectures */ 1103 /* is to avoid it in all cases, at least on common architectures */
1069 /* or when using a recent enough gcc version (>= 4.6) */ 1104 /* or when using a recent enough gcc version (>= 4.6) */
1070#if __i386 || __i386__ || _M_X86 || __amd64 || __amd64__ || _M_X64 1105#if ((__i386 || __i386__) && !__VOS__) || _M_IX86 || ECB_GCC_AMD64 || ECB_MSVC_AMD64
1071 return 0x44; 1106 return 0x44;
1072#elif __BYTE_ORDER__ && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 1107#elif __BYTE_ORDER__ && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
1073 return 0x44; 1108 return 0x44;
1074#elif __BYTE_ORDER__ && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 1109#elif __BYTE_ORDER__ && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
1075 return 0x11; 1110 return 0x11;
1126 1161
1127/* basically, everything uses "ieee pure-endian" floating point numbers */ 1162/* basically, everything uses "ieee pure-endian" floating point numbers */
1128/* the only noteworthy exception is ancient armle, which uses order 43218765 */ 1163/* the only noteworthy exception is ancient armle, which uses order 43218765 */
1129#if 0 \ 1164#if 0 \
1130 || __i386 || __i386__ \ 1165 || __i386 || __i386__ \
1131 || __amd64 || __amd64__ || __x86_64 || __x86_64__ \ 1166 || ECB_GCC_AMD64 \
1132 || __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ \ 1167 || __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ \
1133 || defined __s390__ || defined __s390x__ \ 1168 || defined __s390__ || defined __s390x__ \
1134 || defined __mips__ \ 1169 || defined __mips__ \
1135 || defined __alpha__ \ 1170 || defined __alpha__ \
1136 || defined __hppa__ \ 1171 || defined __hppa__ \
1137 || defined __ia64__ \ 1172 || defined __ia64__ \
1138 || defined __m68k__ \ 1173 || defined __m68k__ \
1139 || defined __m88k__ \ 1174 || defined __m88k__ \
1140 || defined __sh__ \ 1175 || defined __sh__ \
1141 || defined _M_IX86 || defined _M_AMD64 || defined _M_IA64 \ 1176 || defined _M_IX86 || defined ECB_MSVC_AMD64 || defined _M_IA64 \
1142 || (defined __arm__ && (defined __ARM_EABI__ || defined __EABI__ || defined __VFP_FP__ || defined _WIN32_WCE || defined __ANDROID__)) \ 1177 || (defined __arm__ && (defined __ARM_EABI__ || defined __EABI__ || defined __VFP_FP__ || defined _WIN32_WCE || defined __ANDROID__)) \
1143 || defined __aarch64__ 1178 || defined __aarch64__
1144 #define ECB_STDFP 1 1179 #define ECB_STDFP 1
1145 #include <string.h> /* for memcpy */ 1180 #include <string.h> /* for memcpy */
1146#else 1181#else
1164 #define ECB_NAN ECB_INFINITY 1199 #define ECB_NAN ECB_INFINITY
1165 #endif 1200 #endif
1166 1201
1167 #if ECB_C99 || _XOPEN_VERSION >= 600 || _POSIX_VERSION >= 200112L 1202 #if ECB_C99 || _XOPEN_VERSION >= 600 || _POSIX_VERSION >= 200112L
1168 #define ecb_ldexpf(x,e) ldexpf ((x), (e)) 1203 #define ecb_ldexpf(x,e) ldexpf ((x), (e))
1204 #define ecb_frexpf(x,e) frexpf ((x), (e))
1169 #else 1205 #else
1170 #define ecb_ldexpf(x,e) (float) ldexp ((x), (e)) 1206 #define ecb_ldexpf(x,e) (float) ldexp ((double) (x), (e))
1207 #define ecb_frexpf(x,e) (float) frexp ((double) (x), (e))
1171 #endif 1208 #endif
1172 1209
1173 /* converts an ieee half/binary16 to a float */ 1210 /* converts an ieee half/binary16 to a float */
1174 ecb_function_ ecb_const float ecb_binary16_to_float (uint16_t x); 1211 ecb_function_ ecb_const float ecb_binary16_to_float (uint16_t x);
1175 ecb_function_ ecb_const float 1212 ecb_function_ ecb_const float
1204 if (x == 0e0f ) return 0x00000000U; 1241 if (x == 0e0f ) return 0x00000000U;
1205 if (x > +3.40282346638528860e+38f) return 0x7f800000U; 1242 if (x > +3.40282346638528860e+38f) return 0x7f800000U;
1206 if (x < -3.40282346638528860e+38f) return 0xff800000U; 1243 if (x < -3.40282346638528860e+38f) return 0xff800000U;
1207 if (x != x ) return 0x7fbfffffU; 1244 if (x != x ) return 0x7fbfffffU;
1208 1245
1209 m = frexpf (x, &e) * 0x1000000U; 1246 m = ecb_frexpf (x, &e) * 0x1000000U;
1210 1247
1211 r = m & 0x80000000U; 1248 r = m & 0x80000000U;
1212 1249
1213 if (r) 1250 if (r)
1214 m = -m; 1251 m = -m;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines