… | |
… | |
482 | /* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */ |
482 | /* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */ |
483 | /* ECB.H BEGIN */ |
483 | /* ECB.H BEGIN */ |
484 | /* |
484 | /* |
485 | * libecb - http://software.schmorp.de/pkg/libecb |
485 | * libecb - http://software.schmorp.de/pkg/libecb |
486 | * |
486 | * |
487 | * Copyright (©) 2009-2012 Marc Alexander Lehmann <libecb@schmorp.de> |
487 | * Copyright (©) 2009-2013 Marc Alexander Lehmann <libecb@schmorp.de> |
488 | * Copyright (©) 2011 Emanuele Giaquinta |
488 | * Copyright (©) 2011 Emanuele Giaquinta |
489 | * All rights reserved. |
489 | * All rights reserved. |
490 | * |
490 | * |
491 | * Redistribution and use in source and binary forms, with or without modifica- |
491 | * Redistribution and use in source and binary forms, with or without modifica- |
492 | * tion, are permitted provided that the following conditions are met: |
492 | * tion, are permitted provided that the following conditions are met: |
… | |
… | |
547 | #define ECB_PTRSIZE 4 |
547 | #define ECB_PTRSIZE 4 |
548 | #endif |
548 | #endif |
549 | #endif |
549 | #endif |
550 | |
550 | |
551 | /* work around x32 idiocy by defining proper macros */ |
551 | /* work around x32 idiocy by defining proper macros */ |
552 | #if __x86_64 || _M_AMD64 |
552 | #if __amd64 || __x86_64 || _M_AMD64 || _M_X64 |
553 | #if _ILP32 |
553 | #if _ILP32 |
554 | #define ECB_AMD64_X32 1 |
554 | #define ECB_AMD64_X32 1 |
555 | #else |
555 | #else |
556 | #define ECB_AMD64 1 |
556 | #define ECB_AMD64 1 |
557 | #endif |
557 | #endif |
… | |
… | |
617 | || defined __ARM_ARCH_6K__ || defined __ARM_ARCH_6ZK__ |
617 | || defined __ARM_ARCH_6K__ || defined __ARM_ARCH_6ZK__ |
618 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory") |
618 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory") |
619 | #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \ |
619 | #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \ |
620 | || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__ |
620 | || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__ |
621 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") |
621 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") |
622 | #elif __sparc || __sparc__ |
622 | #elif (__sparc || __sparc__) && !__sparcv8 |
623 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad" : : : "memory") |
623 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad" : : : "memory") |
624 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") |
624 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") |
625 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") |
625 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") |
626 | #elif defined __s390__ || defined __s390x__ |
626 | #elif defined __s390__ || defined __s390x__ |
627 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory") |
627 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory") |
… | |
… | |
660 | * #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) |
660 | * #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) |
661 | */ |
661 | */ |
662 | |
662 | |
663 | #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ |
663 | #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ |
664 | #define ECB_MEMORY_FENCE __sync_synchronize () |
664 | #define ECB_MEMORY_FENCE __sync_synchronize () |
|
|
665 | #elif _MSC_VER >= 1500 /* VC++ 2008 */ |
|
|
666 | /* apparently, microsoft broke all the memory barrier stuff in Visual Studio 2008... */ |
|
|
667 | #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) |
|
|
668 | #define ECB_MEMORY_FENCE _ReadWriteBarrier (); MemoryBarrier() |
|
|
669 | #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier (); MemoryBarrier() /* according to msdn, _ReadBarrier is not a load fence */ |
|
|
670 | #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier (); MemoryBarrier() |
665 | #elif _MSC_VER >= 1400 /* VC++ 2005 */ |
671 | #elif _MSC_VER >= 1400 /* VC++ 2005 */ |
666 | #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) |
672 | #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) |
667 | #define ECB_MEMORY_FENCE _ReadWriteBarrier () |
673 | #define ECB_MEMORY_FENCE _ReadWriteBarrier () |
668 | #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */ |
674 | #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */ |
669 | #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () |
675 | #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () |
… | |
… | |
1070 | |
1076 | |
1071 | #ifndef ECB_NO_LIBM |
1077 | #ifndef ECB_NO_LIBM |
1072 | |
1078 | |
1073 | #include <math.h> /* for frexp*, ldexp*, INFINITY, NAN */ |
1079 | #include <math.h> /* for frexp*, ldexp*, INFINITY, NAN */ |
1074 | |
1080 | |
|
|
1081 | /* only the oldest of old doesn't have this one. solaris. */ |
|
|
1082 | #ifdef INFINITY |
|
|
1083 | #define ECB_INFINITY INFINITY |
|
|
1084 | #else |
|
|
1085 | #define ECB_INFINITY HUGE_VAL |
|
|
1086 | #endif |
|
|
1087 | |
1075 | #ifdef NEN |
1088 | #ifdef NAN |
1076 | #define ECB_NAN NAN |
1089 | #define ECB_NAN NAN |
1077 | #else |
1090 | #else |
1078 | #define ECB_NAN INFINITY |
1091 | #define ECB_NAN ECB_INFINITY |
1079 | #endif |
1092 | #endif |
1080 | |
1093 | |
1081 | /* converts an ieee half/binary16 to a float */ |
1094 | /* converts an ieee half/binary16 to a float */ |
1082 | ecb_function_ float ecb_binary16_to_float (uint16_t x) ecb_const; |
1095 | ecb_function_ float ecb_binary16_to_float (uint16_t x) ecb_const; |
1083 | ecb_function_ float |
1096 | ecb_function_ float |
… | |
… | |
1088 | float r; |
1101 | float r; |
1089 | |
1102 | |
1090 | if (!e ) r = ldexpf (m , -24); |
1103 | if (!e ) r = ldexpf (m , -24); |
1091 | else if (e != 31) r = ldexpf (m + 0x400, e - 25); |
1104 | else if (e != 31) r = ldexpf (m + 0x400, e - 25); |
1092 | else if (m ) r = ECB_NAN; |
1105 | else if (m ) r = ECB_NAN; |
1093 | else r = INFINITY; |
1106 | else r = ECB_INFINITY; |
1094 | |
1107 | |
1095 | return x & 0x8000 ? -r : r; |
1108 | return x & 0x8000 ? -r : r; |
1096 | } |
1109 | } |
1097 | |
1110 | |
1098 | /* convert a float to ieee single/binary32 */ |
1111 | /* convert a float to ieee single/binary32 */ |