nio4r 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +61 -0
- data/.rubocop_todo.yml +35 -0
- data/.travis.yml +11 -1
- data/CHANGES.md +13 -0
- data/Gemfile +2 -2
- data/Rakefile +1 -1
- data/examples/echo_server.rb +6 -7
- data/ext/libev/Changes +16 -1
- data/ext/libev/ev.c +339 -141
- data/ext/libev/ev.h +14 -7
- data/ext/libev/ev_epoll.c +2 -2
- data/ext/libev/ev_win32.c +2 -3
- data/ext/nio4r/extconf.rb +23 -34
- data/ext/nio4r/monitor.c +38 -2
- data/ext/nio4r/org/nio4r/Nio4r.java +35 -0
- data/ext/nio4r/selector.c +11 -0
- data/lib/nio/monitor.rb +16 -4
- data/lib/nio/selector.rb +14 -15
- data/lib/nio/version.rb +1 -1
- data/lib/nio.rb +15 -13
- data/nio4r.gemspec +4 -3
- data/spec/nio/acceptables_spec.rb +3 -3
- data/spec/nio/monitor_spec.rb +52 -8
- data/spec/nio/selectables/pipe_spec.rb +5 -5
- data/spec/nio/selectables/ssl_socket_spec.rb +12 -12
- data/spec/nio/selectables/tcp_socket_spec.rb +8 -8
- data/spec/nio/selectables/udp_socket_spec.rb +6 -6
- data/spec/nio/selector_spec.rb +10 -4
- data/spec/spec_helper.rb +7 -5
- data/spec/support/selectable_examples.rb +5 -5
- data/tasks/extension.rake +7 -7
- data/tasks/rspec.rake +2 -2
- data/tasks/rubocop.rake +3 -0
- metadata +22 -6
data/ext/libev/ev.c
CHANGED
|
@@ -497,7 +497,7 @@ struct signalfd_siginfo
|
|
|
497
497
|
/*
|
|
498
498
|
* libecb - http://software.schmorp.de/pkg/libecb
|
|
499
499
|
*
|
|
500
|
-
* Copyright (©) 2009-
|
|
500
|
+
* Copyright (©) 2009-2015 Marc Alexander Lehmann <libecb@schmorp.de>
|
|
501
501
|
* Copyright (©) 2011 Emanuele Giaquinta
|
|
502
502
|
* All rights reserved.
|
|
503
503
|
*
|
|
@@ -538,7 +538,7 @@ struct signalfd_siginfo
|
|
|
538
538
|
#define ECB_H
|
|
539
539
|
|
|
540
540
|
/* 16 bits major, 16 bits minor */
|
|
541
|
-
#define ECB_VERSION
|
|
541
|
+
#define ECB_VERSION 0x00010005
|
|
542
542
|
|
|
543
543
|
#ifdef _WIN32
|
|
544
544
|
typedef signed char int8_t;
|
|
@@ -565,15 +565,18 @@ struct signalfd_siginfo
|
|
|
565
565
|
#endif
|
|
566
566
|
#else
|
|
567
567
|
#include <inttypes.h>
|
|
568
|
-
#if
|
|
568
|
+
#if (defined INTPTR_MAX ? INTPTR_MAX : ULONG_MAX) > 0xffffffffU
|
|
569
569
|
#define ECB_PTRSIZE 8
|
|
570
570
|
#else
|
|
571
571
|
#define ECB_PTRSIZE 4
|
|
572
572
|
#endif
|
|
573
573
|
#endif
|
|
574
574
|
|
|
575
|
+
#define ECB_GCC_AMD64 (__amd64 || __amd64__ || __x86_64 || __x86_64__)
|
|
576
|
+
#define ECB_MSVC_AMD64 (_M_AMD64 || _M_X64)
|
|
577
|
+
|
|
575
578
|
/* work around x32 idiocy by defining proper macros */
|
|
576
|
-
#if
|
|
579
|
+
#if ECB_GCC_AMD64 || ECB_MSVC_AMD64
|
|
577
580
|
#if _ILP32
|
|
578
581
|
#define ECB_AMD64_X32 1
|
|
579
582
|
#else
|
|
@@ -588,12 +591,24 @@ struct signalfd_siginfo
|
|
|
588
591
|
* we try to detect these and simply assume they are not gcc - if they have
|
|
589
592
|
* an issue with that they should have done it right in the first place.
|
|
590
593
|
*/
|
|
591
|
-
#
|
|
592
|
-
#
|
|
593
|
-
|
|
594
|
-
#
|
|
595
|
-
|
|
596
|
-
|
|
594
|
+
#if !defined __GNUC_MINOR__ || defined __INTEL_COMPILER || defined __SUNPRO_C || defined __SUNPRO_CC || defined __llvm__ || defined __clang__
|
|
595
|
+
#define ECB_GCC_VERSION(major,minor) 0
|
|
596
|
+
#else
|
|
597
|
+
#define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
|
|
598
|
+
#endif
|
|
599
|
+
|
|
600
|
+
#define ECB_CLANG_VERSION(major,minor) (__clang_major__ > (major) || (__clang_major__ == (major) && __clang_minor__ >= (minor)))
|
|
601
|
+
|
|
602
|
+
#if __clang__ && defined __has_builtin
|
|
603
|
+
#define ECB_CLANG_BUILTIN(x) __has_builtin (x)
|
|
604
|
+
#else
|
|
605
|
+
#define ECB_CLANG_BUILTIN(x) 0
|
|
606
|
+
#endif
|
|
607
|
+
|
|
608
|
+
#if __clang__ && defined __has_extension
|
|
609
|
+
#define ECB_CLANG_EXTENSION(x) __has_extension (x)
|
|
610
|
+
#else
|
|
611
|
+
#define ECB_CLANG_EXTENSION(x) 0
|
|
597
612
|
#endif
|
|
598
613
|
|
|
599
614
|
#define ECB_CPP (__cplusplus+0)
|
|
@@ -633,27 +648,44 @@ struct signalfd_siginfo
|
|
|
633
648
|
#define ECB_MEMORY_FENCE do { } while (0)
|
|
634
649
|
#endif
|
|
635
650
|
|
|
651
|
+
/* http://www-01.ibm.com/support/knowledgecenter/SSGH3R_13.1.0/com.ibm.xlcpp131.aix.doc/compiler_ref/compiler_builtins.html */
|
|
652
|
+
#if __xlC__ && ECB_CPP
|
|
653
|
+
#include <builtins.h>
|
|
654
|
+
#endif
|
|
655
|
+
|
|
656
|
+
#if 1400 <= _MSC_VER
|
|
657
|
+
#include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */
|
|
658
|
+
#endif
|
|
659
|
+
|
|
636
660
|
#ifndef ECB_MEMORY_FENCE
|
|
637
661
|
#if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
|
|
638
662
|
#if __i386 || __i386__
|
|
639
663
|
#define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory")
|
|
640
664
|
#define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
|
|
641
665
|
#define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("")
|
|
642
|
-
#elif
|
|
666
|
+
#elif ECB_GCC_AMD64
|
|
643
667
|
#define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory")
|
|
644
668
|
#define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
|
|
645
669
|
#define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("")
|
|
646
670
|
#elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__
|
|
647
671
|
#define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
|
|
672
|
+
#elif defined __ARM_ARCH_2__ \
|
|
673
|
+
|| defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \
|
|
674
|
+
|| defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \
|
|
675
|
+
|| defined __ARM_ARCH_5__ || defined __ARM_ARCH_5E__ \
|
|
676
|
+
|| defined __ARM_ARCH_5T__ || defined __ARM_ARCH_5TE__ \
|
|
677
|
+
|| defined __ARM_ARCH_5TEJ__
|
|
678
|
+
/* should not need any, unless running old code on newer cpu - arm doesn't support that */
|
|
648
679
|
#elif defined __ARM_ARCH_6__ || defined __ARM_ARCH_6J__ \
|
|
649
|
-
|| defined __ARM_ARCH_6K__ || defined __ARM_ARCH_6ZK__
|
|
680
|
+
|| defined __ARM_ARCH_6K__ || defined __ARM_ARCH_6ZK__ \
|
|
681
|
+
|| defined __ARM_ARCH_6T2__
|
|
650
682
|
#define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory")
|
|
651
683
|
#elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \
|
|
652
|
-
|| defined
|
|
684
|
+
|| defined __ARM_ARCH_7R__ || defined __ARM_ARCH_7M__
|
|
653
685
|
#define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory")
|
|
654
686
|
#elif __aarch64__
|
|
655
687
|
#define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb ish" : : : "memory")
|
|
656
|
-
#elif (__sparc || __sparc__) && !__sparcv8
|
|
688
|
+
#elif (__sparc || __sparc__) && !(__sparc_v8__ || defined __sparcv8)
|
|
657
689
|
#define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad" : : : "memory")
|
|
658
690
|
#define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory")
|
|
659
691
|
#define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore")
|
|
@@ -687,16 +719,11 @@ struct signalfd_siginfo
|
|
|
687
719
|
#define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE)
|
|
688
720
|
#define ECB_MEMORY_FENCE_RELEASE __atomic_thread_fence (__ATOMIC_RELEASE)
|
|
689
721
|
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
* // see comment below (stdatomic.h) about the C11 memory model.
|
|
696
|
-
* #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST)
|
|
697
|
-
* #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE)
|
|
698
|
-
* #define ECB_MEMORY_FENCE_RELEASE __c11_atomic_thread_fence (__ATOMIC_RELEASE)
|
|
699
|
-
*/
|
|
722
|
+
#elif ECB_CLANG_EXTENSION(c_atomic)
|
|
723
|
+
/* see comment below (stdatomic.h) about the C11 memory model. */
|
|
724
|
+
#define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST)
|
|
725
|
+
#define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE)
|
|
726
|
+
#define ECB_MEMORY_FENCE_RELEASE __c11_atomic_thread_fence (__ATOMIC_RELEASE)
|
|
700
727
|
|
|
701
728
|
#elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__
|
|
702
729
|
#define ECB_MEMORY_FENCE __sync_synchronize ()
|
|
@@ -769,7 +796,7 @@ struct signalfd_siginfo
|
|
|
769
796
|
|
|
770
797
|
/*****************************************************************************/
|
|
771
798
|
|
|
772
|
-
#if
|
|
799
|
+
#if ECB_CPP
|
|
773
800
|
#define ecb_inline static inline
|
|
774
801
|
#elif ECB_GCC_VERSION(2,5)
|
|
775
802
|
#define ecb_inline static __inline__
|
|
@@ -793,47 +820,79 @@ typedef int ecb_bool;
|
|
|
793
820
|
#define ECB_CONCAT(a, b) ECB_CONCAT_(a, b)
|
|
794
821
|
#define ECB_STRINGIFY_(a) # a
|
|
795
822
|
#define ECB_STRINGIFY(a) ECB_STRINGIFY_(a)
|
|
823
|
+
#define ECB_STRINGIFY_EXPR(expr) ((expr), ECB_STRINGIFY_ (expr))
|
|
796
824
|
|
|
797
825
|
#define ecb_function_ ecb_inline
|
|
798
826
|
|
|
799
|
-
#if ECB_GCC_VERSION(3,1)
|
|
800
|
-
#define ecb_attribute(attrlist) __attribute__(attrlist)
|
|
801
|
-
#define ecb_is_constant(expr) __builtin_constant_p (expr)
|
|
802
|
-
#define ecb_expect(expr,value) __builtin_expect ((expr),(value))
|
|
803
|
-
#define ecb_prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality)
|
|
827
|
+
#if ECB_GCC_VERSION(3,1) || ECB_CLANG_VERSION(2,8)
|
|
828
|
+
#define ecb_attribute(attrlist) __attribute__ (attrlist)
|
|
804
829
|
#else
|
|
805
830
|
#define ecb_attribute(attrlist)
|
|
831
|
+
#endif
|
|
806
832
|
|
|
833
|
+
#if ECB_GCC_VERSION(3,1) || ECB_CLANG_BUILTIN(__builtin_constant_p)
|
|
834
|
+
#define ecb_is_constant(expr) __builtin_constant_p (expr)
|
|
835
|
+
#else
|
|
807
836
|
/* possible C11 impl for integral types
|
|
808
837
|
typedef struct ecb_is_constant_struct ecb_is_constant_struct;
|
|
809
838
|
#define ecb_is_constant(expr) _Generic ((1 ? (struct ecb_is_constant_struct *)0 : (void *)((expr) - (expr)), ecb_is_constant_struct *: 0, default: 1)) */
|
|
810
839
|
|
|
811
840
|
#define ecb_is_constant(expr) 0
|
|
841
|
+
#endif
|
|
842
|
+
|
|
843
|
+
#if ECB_GCC_VERSION(3,1) || ECB_CLANG_BUILTIN(__builtin_expect)
|
|
844
|
+
#define ecb_expect(expr,value) __builtin_expect ((expr),(value))
|
|
845
|
+
#else
|
|
812
846
|
#define ecb_expect(expr,value) (expr)
|
|
847
|
+
#endif
|
|
848
|
+
|
|
849
|
+
#if ECB_GCC_VERSION(3,1) || ECB_CLANG_BUILTIN(__builtin_prefetch)
|
|
850
|
+
#define ecb_prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality)
|
|
851
|
+
#else
|
|
813
852
|
#define ecb_prefetch(addr,rw,locality)
|
|
814
853
|
#endif
|
|
815
854
|
|
|
816
855
|
/* no emulation for ecb_decltype */
|
|
817
|
-
#if
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
#define ecb_decltype(x)
|
|
856
|
+
#if ECB_CPP11
|
|
857
|
+
// older implementations might have problems with decltype(x)::type, work around it
|
|
858
|
+
template<class T> struct ecb_decltype_t { typedef T type; };
|
|
859
|
+
#define ecb_decltype(x) ecb_decltype_t<decltype (x)>::type
|
|
860
|
+
#elif ECB_GCC_VERSION(3,0) || ECB_CLANG_VERSION(2,8)
|
|
861
|
+
#define ecb_decltype(x) __typeof__ (x)
|
|
821
862
|
#endif
|
|
822
863
|
|
|
823
864
|
#if _MSC_VER >= 1300
|
|
824
|
-
#define ecb_deprecated __declspec(deprecated)
|
|
865
|
+
#define ecb_deprecated __declspec (deprecated)
|
|
825
866
|
#else
|
|
826
867
|
#define ecb_deprecated ecb_attribute ((__deprecated__))
|
|
827
868
|
#endif
|
|
828
869
|
|
|
829
|
-
#
|
|
870
|
+
#if _MSC_VER >= 1500
|
|
871
|
+
#define ecb_deprecated_message(msg) __declspec (deprecated (msg))
|
|
872
|
+
#elif ECB_GCC_VERSION(4,5)
|
|
873
|
+
#define ecb_deprecated_message(msg) ecb_attribute ((__deprecated__ (msg))
|
|
874
|
+
#else
|
|
875
|
+
#define ecb_deprecated_message(msg) ecb_deprecated
|
|
876
|
+
#endif
|
|
877
|
+
|
|
878
|
+
#if _MSC_VER >= 1400
|
|
879
|
+
#define ecb_noinline __declspec (noinline)
|
|
880
|
+
#else
|
|
881
|
+
#define ecb_noinline ecb_attribute ((__noinline__))
|
|
882
|
+
#endif
|
|
883
|
+
|
|
830
884
|
#define ecb_unused ecb_attribute ((__unused__))
|
|
831
885
|
#define ecb_const ecb_attribute ((__const__))
|
|
832
886
|
#define ecb_pure ecb_attribute ((__pure__))
|
|
833
887
|
|
|
834
|
-
|
|
835
|
-
|
|
888
|
+
#if ECB_C11 || __IBMC_NORETURN
|
|
889
|
+
/* http://www-01.ibm.com/support/knowledgecenter/SSGH3R_13.1.0/com.ibm.xlcpp131.aix.doc/language_ref/noreturn.html */
|
|
836
890
|
#define ecb_noreturn _Noreturn
|
|
891
|
+
#elif ECB_CPP11
|
|
892
|
+
#define ecb_noreturn [[noreturn]]
|
|
893
|
+
#elif _MSC_VER >= 1200
|
|
894
|
+
/* http://msdn.microsoft.com/en-us/library/k6ktzx3s.aspx */
|
|
895
|
+
#define ecb_noreturn __declspec (noreturn)
|
|
837
896
|
#else
|
|
838
897
|
#define ecb_noreturn ecb_attribute ((__noreturn__))
|
|
839
898
|
#endif
|
|
@@ -858,7 +917,10 @@ typedef int ecb_bool;
|
|
|
858
917
|
#define ecb_unlikely(expr) ecb_expect_false (expr)
|
|
859
918
|
|
|
860
919
|
/* count trailing zero bits and count # of one bits */
|
|
861
|
-
#if ECB_GCC_VERSION(3,4)
|
|
920
|
+
#if ECB_GCC_VERSION(3,4) \
|
|
921
|
+
|| (ECB_CLANG_BUILTIN(__builtin_clz) && ECB_CLANG_BUILTIN(__builtin_clzll) \
|
|
922
|
+
&& ECB_CLANG_BUILTIN(__builtin_ctz) && ECB_CLANG_BUILTIN(__builtin_ctzll) \
|
|
923
|
+
&& ECB_CLANG_BUILTIN(__builtin_popcount))
|
|
862
924
|
/* we assume int == 32 bit, long == 32 or 64 bit and long long == 64 bit */
|
|
863
925
|
#define ecb_ld32(x) (__builtin_clz (x) ^ 31)
|
|
864
926
|
#define ecb_ld64(x) (__builtin_clzll (x) ^ 63)
|
|
@@ -867,10 +929,15 @@ typedef int ecb_bool;
|
|
|
867
929
|
#define ecb_popcount32(x) __builtin_popcount (x)
|
|
868
930
|
/* no popcountll */
|
|
869
931
|
#else
|
|
870
|
-
ecb_function_ int ecb_ctz32 (uint32_t x)
|
|
871
|
-
ecb_function_ int
|
|
932
|
+
ecb_function_ ecb_const int ecb_ctz32 (uint32_t x);
|
|
933
|
+
ecb_function_ ecb_const int
|
|
872
934
|
ecb_ctz32 (uint32_t x)
|
|
873
935
|
{
|
|
936
|
+
#if 1400 <= _MSC_VER && (_M_IX86 || _M_X64 || _M_IA64 || _M_ARM)
|
|
937
|
+
unsigned long r;
|
|
938
|
+
_BitScanForward (&r, x);
|
|
939
|
+
return (int)r;
|
|
940
|
+
#else
|
|
874
941
|
int r = 0;
|
|
875
942
|
|
|
876
943
|
x &= ~x + 1; /* this isolates the lowest bit */
|
|
@@ -890,18 +957,25 @@ typedef int ecb_bool;
|
|
|
890
957
|
#endif
|
|
891
958
|
|
|
892
959
|
return r;
|
|
960
|
+
#endif
|
|
893
961
|
}
|
|
894
962
|
|
|
895
|
-
ecb_function_ int ecb_ctz64 (uint64_t x)
|
|
896
|
-
ecb_function_ int
|
|
963
|
+
ecb_function_ ecb_const int ecb_ctz64 (uint64_t x);
|
|
964
|
+
ecb_function_ ecb_const int
|
|
897
965
|
ecb_ctz64 (uint64_t x)
|
|
898
966
|
{
|
|
899
|
-
|
|
967
|
+
#if 1400 <= _MSC_VER && (_M_X64 || _M_IA64 || _M_ARM)
|
|
968
|
+
unsigned long r;
|
|
969
|
+
_BitScanForward64 (&r, x);
|
|
970
|
+
return (int)r;
|
|
971
|
+
#else
|
|
972
|
+
int shift = x & 0xffffffff ? 0 : 32;
|
|
900
973
|
return ecb_ctz32 (x >> shift) + shift;
|
|
974
|
+
#endif
|
|
901
975
|
}
|
|
902
976
|
|
|
903
|
-
ecb_function_ int ecb_popcount32 (uint32_t x)
|
|
904
|
-
ecb_function_ int
|
|
977
|
+
ecb_function_ ecb_const int ecb_popcount32 (uint32_t x);
|
|
978
|
+
ecb_function_ ecb_const int
|
|
905
979
|
ecb_popcount32 (uint32_t x)
|
|
906
980
|
{
|
|
907
981
|
x -= (x >> 1) & 0x55555555;
|
|
@@ -912,9 +986,14 @@ typedef int ecb_bool;
|
|
|
912
986
|
return x >> 24;
|
|
913
987
|
}
|
|
914
988
|
|
|
915
|
-
ecb_function_ int ecb_ld32 (uint32_t x)
|
|
916
|
-
ecb_function_ int ecb_ld32 (uint32_t x)
|
|
989
|
+
ecb_function_ ecb_const int ecb_ld32 (uint32_t x);
|
|
990
|
+
ecb_function_ ecb_const int ecb_ld32 (uint32_t x)
|
|
917
991
|
{
|
|
992
|
+
#if 1400 <= _MSC_VER && (_M_IX86 || _M_X64 || _M_IA64 || _M_ARM)
|
|
993
|
+
unsigned long r;
|
|
994
|
+
_BitScanReverse (&r, x);
|
|
995
|
+
return (int)r;
|
|
996
|
+
#else
|
|
918
997
|
int r = 0;
|
|
919
998
|
|
|
920
999
|
if (x >> 16) { x >>= 16; r += 16; }
|
|
@@ -924,33 +1003,40 @@ typedef int ecb_bool;
|
|
|
924
1003
|
if (x >> 1) { r += 1; }
|
|
925
1004
|
|
|
926
1005
|
return r;
|
|
1006
|
+
#endif
|
|
927
1007
|
}
|
|
928
1008
|
|
|
929
|
-
ecb_function_ int ecb_ld64 (uint64_t x)
|
|
930
|
-
ecb_function_ int ecb_ld64 (uint64_t x)
|
|
1009
|
+
ecb_function_ ecb_const int ecb_ld64 (uint64_t x);
|
|
1010
|
+
ecb_function_ ecb_const int ecb_ld64 (uint64_t x)
|
|
931
1011
|
{
|
|
1012
|
+
#if 1400 <= _MSC_VER && (_M_X64 || _M_IA64 || _M_ARM)
|
|
1013
|
+
unsigned long r;
|
|
1014
|
+
_BitScanReverse64 (&r, x);
|
|
1015
|
+
return (int)r;
|
|
1016
|
+
#else
|
|
932
1017
|
int r = 0;
|
|
933
1018
|
|
|
934
1019
|
if (x >> 32) { x >>= 32; r += 32; }
|
|
935
1020
|
|
|
936
1021
|
return r + ecb_ld32 (x);
|
|
1022
|
+
#endif
|
|
937
1023
|
}
|
|
938
1024
|
#endif
|
|
939
1025
|
|
|
940
|
-
ecb_function_ ecb_bool ecb_is_pot32 (uint32_t x)
|
|
941
|
-
ecb_function_ ecb_bool ecb_is_pot32 (uint32_t x) { return !(x & (x - 1)); }
|
|
942
|
-
ecb_function_ ecb_bool ecb_is_pot64 (uint64_t x)
|
|
943
|
-
ecb_function_ ecb_bool ecb_is_pot64 (uint64_t x) { return !(x & (x - 1)); }
|
|
1026
|
+
ecb_function_ ecb_const ecb_bool ecb_is_pot32 (uint32_t x);
|
|
1027
|
+
ecb_function_ ecb_const ecb_bool ecb_is_pot32 (uint32_t x) { return !(x & (x - 1)); }
|
|
1028
|
+
ecb_function_ ecb_const ecb_bool ecb_is_pot64 (uint64_t x);
|
|
1029
|
+
ecb_function_ ecb_const ecb_bool ecb_is_pot64 (uint64_t x) { return !(x & (x - 1)); }
|
|
944
1030
|
|
|
945
|
-
ecb_function_ uint8_t ecb_bitrev8 (uint8_t x)
|
|
946
|
-
ecb_function_ uint8_t ecb_bitrev8 (uint8_t x)
|
|
1031
|
+
ecb_function_ ecb_const uint8_t ecb_bitrev8 (uint8_t x);
|
|
1032
|
+
ecb_function_ ecb_const uint8_t ecb_bitrev8 (uint8_t x)
|
|
947
1033
|
{
|
|
948
1034
|
return ( (x * 0x0802U & 0x22110U)
|
|
949
|
-
| (x * 0x8020U & 0x88440U)) * 0x10101U >> 16;
|
|
1035
|
+
| (x * 0x8020U & 0x88440U)) * 0x10101U >> 16;
|
|
950
1036
|
}
|
|
951
1037
|
|
|
952
|
-
ecb_function_ uint16_t ecb_bitrev16 (uint16_t x)
|
|
953
|
-
ecb_function_ uint16_t ecb_bitrev16 (uint16_t x)
|
|
1038
|
+
ecb_function_ ecb_const uint16_t ecb_bitrev16 (uint16_t x);
|
|
1039
|
+
ecb_function_ ecb_const uint16_t ecb_bitrev16 (uint16_t x)
|
|
954
1040
|
{
|
|
955
1041
|
x = ((x >> 1) & 0x5555) | ((x & 0x5555) << 1);
|
|
956
1042
|
x = ((x >> 2) & 0x3333) | ((x & 0x3333) << 2);
|
|
@@ -960,8 +1046,8 @@ ecb_function_ uint16_t ecb_bitrev16 (uint16_t x)
|
|
|
960
1046
|
return x;
|
|
961
1047
|
}
|
|
962
1048
|
|
|
963
|
-
ecb_function_ uint32_t ecb_bitrev32 (uint32_t x)
|
|
964
|
-
ecb_function_ uint32_t ecb_bitrev32 (uint32_t x)
|
|
1049
|
+
ecb_function_ ecb_const uint32_t ecb_bitrev32 (uint32_t x);
|
|
1050
|
+
ecb_function_ ecb_const uint32_t ecb_bitrev32 (uint32_t x)
|
|
965
1051
|
{
|
|
966
1052
|
x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1);
|
|
967
1053
|
x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2);
|
|
@@ -974,71 +1060,80 @@ ecb_function_ uint32_t ecb_bitrev32 (uint32_t x)
|
|
|
974
1060
|
|
|
975
1061
|
/* popcount64 is only available on 64 bit cpus as gcc builtin */
|
|
976
1062
|
/* so for this version we are lazy */
|
|
977
|
-
ecb_function_ int ecb_popcount64 (uint64_t x)
|
|
978
|
-
ecb_function_ int
|
|
1063
|
+
ecb_function_ ecb_const int ecb_popcount64 (uint64_t x);
|
|
1064
|
+
ecb_function_ ecb_const int
|
|
979
1065
|
ecb_popcount64 (uint64_t x)
|
|
980
1066
|
{
|
|
981
1067
|
return ecb_popcount32 (x) + ecb_popcount32 (x >> 32);
|
|
982
1068
|
}
|
|
983
1069
|
|
|
984
|
-
ecb_inline uint8_t ecb_rotl8 (uint8_t x, unsigned int count)
|
|
985
|
-
ecb_inline uint8_t ecb_rotr8 (uint8_t x, unsigned int count)
|
|
986
|
-
ecb_inline uint16_t ecb_rotl16 (uint16_t x, unsigned int count)
|
|
987
|
-
ecb_inline uint16_t ecb_rotr16 (uint16_t x, unsigned int count)
|
|
988
|
-
ecb_inline uint32_t ecb_rotl32 (uint32_t x, unsigned int count)
|
|
989
|
-
ecb_inline uint32_t ecb_rotr32 (uint32_t x, unsigned int count)
|
|
990
|
-
ecb_inline uint64_t ecb_rotl64 (uint64_t x, unsigned int count)
|
|
991
|
-
ecb_inline uint64_t ecb_rotr64 (uint64_t x, unsigned int count)
|
|
992
|
-
|
|
993
|
-
ecb_inline uint8_t ecb_rotl8 (uint8_t x, unsigned int count) { return (x >> ( 8 - count)) | (x << count); }
|
|
994
|
-
ecb_inline uint8_t ecb_rotr8 (uint8_t x, unsigned int count) { return (x << ( 8 - count)) | (x >> count); }
|
|
995
|
-
ecb_inline uint16_t ecb_rotl16 (uint16_t x, unsigned int count) { return (x >> (16 - count)) | (x << count); }
|
|
996
|
-
ecb_inline uint16_t ecb_rotr16 (uint16_t x, unsigned int count) { return (x << (16 - count)) | (x >> count); }
|
|
997
|
-
ecb_inline uint32_t ecb_rotl32 (uint32_t x, unsigned int count) { return (x >> (32 - count)) | (x << count); }
|
|
998
|
-
ecb_inline uint32_t ecb_rotr32 (uint32_t x, unsigned int count) { return (x << (32 - count)) | (x >> count); }
|
|
999
|
-
ecb_inline uint64_t ecb_rotl64 (uint64_t x, unsigned int count) { return (x >> (64 - count)) | (x << count); }
|
|
1000
|
-
ecb_inline uint64_t ecb_rotr64 (uint64_t x, unsigned int count) { return (x << (64 - count)) | (x >> count); }
|
|
1001
|
-
|
|
1002
|
-
#if ECB_GCC_VERSION(4,3)
|
|
1070
|
+
ecb_inline ecb_const uint8_t ecb_rotl8 (uint8_t x, unsigned int count);
|
|
1071
|
+
ecb_inline ecb_const uint8_t ecb_rotr8 (uint8_t x, unsigned int count);
|
|
1072
|
+
ecb_inline ecb_const uint16_t ecb_rotl16 (uint16_t x, unsigned int count);
|
|
1073
|
+
ecb_inline ecb_const uint16_t ecb_rotr16 (uint16_t x, unsigned int count);
|
|
1074
|
+
ecb_inline ecb_const uint32_t ecb_rotl32 (uint32_t x, unsigned int count);
|
|
1075
|
+
ecb_inline ecb_const uint32_t ecb_rotr32 (uint32_t x, unsigned int count);
|
|
1076
|
+
ecb_inline ecb_const uint64_t ecb_rotl64 (uint64_t x, unsigned int count);
|
|
1077
|
+
ecb_inline ecb_const uint64_t ecb_rotr64 (uint64_t x, unsigned int count);
|
|
1078
|
+
|
|
1079
|
+
ecb_inline ecb_const uint8_t ecb_rotl8 (uint8_t x, unsigned int count) { return (x >> ( 8 - count)) | (x << count); }
|
|
1080
|
+
ecb_inline ecb_const uint8_t ecb_rotr8 (uint8_t x, unsigned int count) { return (x << ( 8 - count)) | (x >> count); }
|
|
1081
|
+
ecb_inline ecb_const uint16_t ecb_rotl16 (uint16_t x, unsigned int count) { return (x >> (16 - count)) | (x << count); }
|
|
1082
|
+
ecb_inline ecb_const uint16_t ecb_rotr16 (uint16_t x, unsigned int count) { return (x << (16 - count)) | (x >> count); }
|
|
1083
|
+
ecb_inline ecb_const uint32_t ecb_rotl32 (uint32_t x, unsigned int count) { return (x >> (32 - count)) | (x << count); }
|
|
1084
|
+
ecb_inline ecb_const uint32_t ecb_rotr32 (uint32_t x, unsigned int count) { return (x << (32 - count)) | (x >> count); }
|
|
1085
|
+
ecb_inline ecb_const uint64_t ecb_rotl64 (uint64_t x, unsigned int count) { return (x >> (64 - count)) | (x << count); }
|
|
1086
|
+
ecb_inline ecb_const uint64_t ecb_rotr64 (uint64_t x, unsigned int count) { return (x << (64 - count)) | (x >> count); }
|
|
1087
|
+
|
|
1088
|
+
#if ECB_GCC_VERSION(4,3) || (ECB_CLANG_BUILTIN(__builtin_bswap32) && ECB_CLANG_BUILTIN(__builtin_bswap64))
|
|
1089
|
+
#if ECB_GCC_VERSION(4,8) || ECB_CLANG_BUILTIN(__builtin_bswap16)
|
|
1090
|
+
#define ecb_bswap16(x) __builtin_bswap16 (x)
|
|
1091
|
+
#else
|
|
1003
1092
|
#define ecb_bswap16(x) (__builtin_bswap32 (x) >> 16)
|
|
1093
|
+
#endif
|
|
1004
1094
|
#define ecb_bswap32(x) __builtin_bswap32 (x)
|
|
1005
1095
|
#define ecb_bswap64(x) __builtin_bswap64 (x)
|
|
1096
|
+
#elif _MSC_VER
|
|
1097
|
+
#include <stdlib.h>
|
|
1098
|
+
#define ecb_bswap16(x) ((uint16_t)_byteswap_ushort ((uint16_t)(x)))
|
|
1099
|
+
#define ecb_bswap32(x) ((uint32_t)_byteswap_ulong ((uint32_t)(x)))
|
|
1100
|
+
#define ecb_bswap64(x) ((uint64_t)_byteswap_uint64 ((uint64_t)(x)))
|
|
1006
1101
|
#else
|
|
1007
|
-
ecb_function_ uint16_t ecb_bswap16 (uint16_t x)
|
|
1008
|
-
ecb_function_ uint16_t
|
|
1102
|
+
ecb_function_ ecb_const uint16_t ecb_bswap16 (uint16_t x);
|
|
1103
|
+
ecb_function_ ecb_const uint16_t
|
|
1009
1104
|
ecb_bswap16 (uint16_t x)
|
|
1010
1105
|
{
|
|
1011
1106
|
return ecb_rotl16 (x, 8);
|
|
1012
1107
|
}
|
|
1013
1108
|
|
|
1014
|
-
ecb_function_ uint32_t ecb_bswap32 (uint32_t x)
|
|
1015
|
-
ecb_function_ uint32_t
|
|
1109
|
+
ecb_function_ ecb_const uint32_t ecb_bswap32 (uint32_t x);
|
|
1110
|
+
ecb_function_ ecb_const uint32_t
|
|
1016
1111
|
ecb_bswap32 (uint32_t x)
|
|
1017
1112
|
{
|
|
1018
1113
|
return (((uint32_t)ecb_bswap16 (x)) << 16) | ecb_bswap16 (x >> 16);
|
|
1019
1114
|
}
|
|
1020
1115
|
|
|
1021
|
-
ecb_function_ uint64_t ecb_bswap64 (uint64_t x)
|
|
1022
|
-
ecb_function_ uint64_t
|
|
1116
|
+
ecb_function_ ecb_const uint64_t ecb_bswap64 (uint64_t x);
|
|
1117
|
+
ecb_function_ ecb_const uint64_t
|
|
1023
1118
|
ecb_bswap64 (uint64_t x)
|
|
1024
1119
|
{
|
|
1025
1120
|
return (((uint64_t)ecb_bswap32 (x)) << 32) | ecb_bswap32 (x >> 32);
|
|
1026
1121
|
}
|
|
1027
1122
|
#endif
|
|
1028
1123
|
|
|
1029
|
-
#if ECB_GCC_VERSION(4,5)
|
|
1124
|
+
#if ECB_GCC_VERSION(4,5) || ECB_CLANG_BUILTIN(__builtin_unreachable)
|
|
1030
1125
|
#define ecb_unreachable() __builtin_unreachable ()
|
|
1031
1126
|
#else
|
|
1032
1127
|
/* this seems to work fine, but gcc always emits a warning for it :/ */
|
|
1033
|
-
ecb_inline void ecb_unreachable (void)
|
|
1034
|
-
ecb_inline void ecb_unreachable (void) { }
|
|
1128
|
+
ecb_inline ecb_noreturn void ecb_unreachable (void);
|
|
1129
|
+
ecb_inline ecb_noreturn void ecb_unreachable (void) { }
|
|
1035
1130
|
#endif
|
|
1036
1131
|
|
|
1037
1132
|
/* try to tell the compiler that some condition is definitely true */
|
|
1038
1133
|
#define ecb_assume(cond) if (!(cond)) ecb_unreachable (); else 0
|
|
1039
1134
|
|
|
1040
|
-
ecb_inline
|
|
1041
|
-
ecb_inline
|
|
1135
|
+
ecb_inline ecb_const uint32_t ecb_byteorder_helper (void);
|
|
1136
|
+
ecb_inline ecb_const uint32_t
|
|
1042
1137
|
ecb_byteorder_helper (void)
|
|
1043
1138
|
{
|
|
1044
1139
|
/* the union code still generates code under pressure in gcc, */
|
|
@@ -1047,26 +1142,28 @@ ecb_byteorder_helper (void)
|
|
|
1047
1142
|
/* the reason why we have this horrible preprocessor mess */
|
|
1048
1143
|
/* is to avoid it in all cases, at least on common architectures */
|
|
1049
1144
|
/* or when using a recent enough gcc version (>= 4.6) */
|
|
1050
|
-
#if
|
|
1051
|
-
|
|
1052
|
-
#
|
|
1053
|
-
return
|
|
1054
|
-
#elif __BYTE_ORDER__ && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
|
1055
|
-
|
|
1145
|
+
#if (defined __BYTE_ORDER__ && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) \
|
|
1146
|
+
|| ((__i386 || __i386__ || _M_IX86 || ECB_GCC_AMD64 || ECB_MSVC_AMD64) && !__VOS__)
|
|
1147
|
+
#define ECB_LITTLE_ENDIAN 1
|
|
1148
|
+
return 0x44332211;
|
|
1149
|
+
#elif (defined __BYTE_ORDER__ && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) \
|
|
1150
|
+
|| ((__AARCH64EB__ || __MIPSEB__ || __ARMEB__) && !__VOS__)
|
|
1151
|
+
#define ECB_BIG_ENDIAN 1
|
|
1152
|
+
return 0x11223344;
|
|
1056
1153
|
#else
|
|
1057
1154
|
union
|
|
1058
1155
|
{
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
} u = {
|
|
1062
|
-
return u.
|
|
1156
|
+
uint8_t c[4];
|
|
1157
|
+
uint32_t u;
|
|
1158
|
+
} u = { 0x11, 0x22, 0x33, 0x44 };
|
|
1159
|
+
return u.u;
|
|
1063
1160
|
#endif
|
|
1064
1161
|
}
|
|
1065
1162
|
|
|
1066
|
-
ecb_inline ecb_bool ecb_big_endian (void)
|
|
1067
|
-
ecb_inline ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () ==
|
|
1068
|
-
ecb_inline ecb_bool ecb_little_endian (void)
|
|
1069
|
-
ecb_inline ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () ==
|
|
1163
|
+
ecb_inline ecb_const ecb_bool ecb_big_endian (void);
|
|
1164
|
+
ecb_inline ecb_const ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11223344; }
|
|
1165
|
+
ecb_inline ecb_const ecb_bool ecb_little_endian (void);
|
|
1166
|
+
ecb_inline ecb_const ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44332211; }
|
|
1070
1167
|
|
|
1071
1168
|
#if ECB_GCC_VERSION(3,0) || ECB_C99
|
|
1072
1169
|
#define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0))
|
|
@@ -1074,7 +1171,7 @@ ecb_inline ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () ==
|
|
|
1074
1171
|
#define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n)))
|
|
1075
1172
|
#endif
|
|
1076
1173
|
|
|
1077
|
-
#if
|
|
1174
|
+
#if ECB_CPP
|
|
1078
1175
|
template<typename T>
|
|
1079
1176
|
static inline T ecb_div_rd (T val, T div)
|
|
1080
1177
|
{
|
|
@@ -1101,6 +1198,102 @@ ecb_inline ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () ==
|
|
|
1101
1198
|
#define ecb_array_length(name) (sizeof (name) / sizeof (name [0]))
|
|
1102
1199
|
#endif
|
|
1103
1200
|
|
|
1201
|
+
ecb_function_ ecb_const uint32_t ecb_binary16_to_binary32 (uint32_t x);
|
|
1202
|
+
ecb_function_ ecb_const uint32_t
|
|
1203
|
+
ecb_binary16_to_binary32 (uint32_t x)
|
|
1204
|
+
{
|
|
1205
|
+
unsigned int s = (x & 0x8000) << (31 - 15);
|
|
1206
|
+
int e = (x >> 10) & 0x001f;
|
|
1207
|
+
unsigned int m = x & 0x03ff;
|
|
1208
|
+
|
|
1209
|
+
if (ecb_expect_false (e == 31))
|
|
1210
|
+
/* infinity or NaN */
|
|
1211
|
+
e = 255 - (127 - 15);
|
|
1212
|
+
else if (ecb_expect_false (!e))
|
|
1213
|
+
{
|
|
1214
|
+
if (ecb_expect_true (!m))
|
|
1215
|
+
/* zero, handled by code below by forcing e to 0 */
|
|
1216
|
+
e = 0 - (127 - 15);
|
|
1217
|
+
else
|
|
1218
|
+
{
|
|
1219
|
+
/* subnormal, renormalise */
|
|
1220
|
+
unsigned int s = 10 - ecb_ld32 (m);
|
|
1221
|
+
|
|
1222
|
+
m = (m << s) & 0x3ff; /* mask implicit bit */
|
|
1223
|
+
e -= s - 1;
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
/* e and m now are normalised, or zero, (or inf or nan) */
|
|
1228
|
+
e += 127 - 15;
|
|
1229
|
+
|
|
1230
|
+
return s | (e << 23) | (m << (23 - 10));
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
ecb_function_ ecb_const uint16_t ecb_binary32_to_binary16 (uint32_t x);
|
|
1234
|
+
ecb_function_ ecb_const uint16_t
|
|
1235
|
+
ecb_binary32_to_binary16 (uint32_t x)
|
|
1236
|
+
{
|
|
1237
|
+
unsigned int s = (x >> 16) & 0x00008000; /* sign bit, the easy part */
|
|
1238
|
+
unsigned int e = ((x >> 23) & 0x000000ff) - (127 - 15); /* the desired exponent */
|
|
1239
|
+
unsigned int m = x & 0x007fffff;
|
|
1240
|
+
|
|
1241
|
+
x &= 0x7fffffff;
|
|
1242
|
+
|
|
1243
|
+
/* if it's within range of binary16 normals, use fast path */
|
|
1244
|
+
if (ecb_expect_true (0x38800000 <= x && x <= 0x477fefff))
|
|
1245
|
+
{
|
|
1246
|
+
/* mantissa round-to-even */
|
|
1247
|
+
m += 0x00000fff + ((m >> (23 - 10)) & 1);
|
|
1248
|
+
|
|
1249
|
+
/* handle overflow */
|
|
1250
|
+
if (ecb_expect_false (m >= 0x00800000))
|
|
1251
|
+
{
|
|
1252
|
+
m >>= 1;
|
|
1253
|
+
e += 1;
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
return s | (e << 10) | (m >> (23 - 10));
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
/* handle large numbers and infinity */
|
|
1260
|
+
if (ecb_expect_true (0x477fefff < x && x <= 0x7f800000))
|
|
1261
|
+
return s | 0x7c00;
|
|
1262
|
+
|
|
1263
|
+
/* handle zero, subnormals and small numbers */
|
|
1264
|
+
if (ecb_expect_true (x < 0x38800000))
|
|
1265
|
+
{
|
|
1266
|
+
/* zero */
|
|
1267
|
+
if (ecb_expect_true (!x))
|
|
1268
|
+
return s;
|
|
1269
|
+
|
|
1270
|
+
/* handle subnormals */
|
|
1271
|
+
|
|
1272
|
+
/* too small, will be zero */
|
|
1273
|
+
if (e < (14 - 24)) /* might not be sharp, but is good enough */
|
|
1274
|
+
return s;
|
|
1275
|
+
|
|
1276
|
+
m |= 0x00800000; /* make implicit bit explicit */
|
|
1277
|
+
|
|
1278
|
+
/* very tricky - we need to round to the nearest e (+10) bit value */
|
|
1279
|
+
{
|
|
1280
|
+
unsigned int bits = 14 - e;
|
|
1281
|
+
unsigned int half = (1 << (bits - 1)) - 1;
|
|
1282
|
+
unsigned int even = (m >> bits) & 1;
|
|
1283
|
+
|
|
1284
|
+
/* if this overflows, we will end up with a normalised number */
|
|
1285
|
+
m = (m + half + even) >> bits;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
return s | m;
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
/* handle NaNs, preserve leftmost nan bits, but make sure we don't turn them into infinities */
|
|
1292
|
+
m >>= 13;
|
|
1293
|
+
|
|
1294
|
+
return s | 0x7c00 | m | !m;
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1104
1297
|
/*******************************************************************************/
|
|
1105
1298
|
/* floating point stuff, can be disabled by defining ECB_NO_LIBM */
|
|
1106
1299
|
|
|
@@ -1108,7 +1301,7 @@ ecb_inline ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () ==
|
|
|
1108
1301
|
/* the only noteworthy exception is ancient armle, which uses order 43218765 */
|
|
1109
1302
|
#if 0 \
|
|
1110
1303
|
|| __i386 || __i386__ \
|
|
1111
|
-
||
|
|
1304
|
+
|| ECB_GCC_AMD64 \
|
|
1112
1305
|
|| __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ \
|
|
1113
1306
|
|| defined __s390__ || defined __s390x__ \
|
|
1114
1307
|
|| defined __mips__ \
|
|
@@ -1118,7 +1311,7 @@ ecb_inline ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () ==
|
|
|
1118
1311
|
|| defined __m68k__ \
|
|
1119
1312
|
|| defined __m88k__ \
|
|
1120
1313
|
|| defined __sh__ \
|
|
1121
|
-
|| defined _M_IX86 || defined
|
|
1314
|
+
|| defined _M_IX86 || defined ECB_MSVC_AMD64 || defined _M_IA64 \
|
|
1122
1315
|
|| (defined __arm__ && (defined __ARM_EABI__ || defined __EABI__ || defined __VFP_FP__ || defined _WIN32_WCE || defined __ANDROID__)) \
|
|
1123
1316
|
|| defined __aarch64__
|
|
1124
1317
|
#define ECB_STDFP 1
|
|
@@ -1144,26 +1337,17 @@ ecb_inline ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () ==
|
|
|
1144
1337
|
#define ECB_NAN ECB_INFINITY
|
|
1145
1338
|
#endif
|
|
1146
1339
|
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
float r;
|
|
1155
|
-
|
|
1156
|
-
if (!e ) r = ldexpf (m , -24);
|
|
1157
|
-
else if (e != 31) r = ldexpf (m + 0x400, e - 25);
|
|
1158
|
-
else if (m ) r = ECB_NAN;
|
|
1159
|
-
else r = ECB_INFINITY;
|
|
1160
|
-
|
|
1161
|
-
return x & 0x8000 ? -r : r;
|
|
1162
|
-
}
|
|
1340
|
+
#if ECB_C99 || _XOPEN_VERSION >= 600 || _POSIX_VERSION >= 200112L
|
|
1341
|
+
#define ecb_ldexpf(x,e) ldexpf ((x), (e))
|
|
1342
|
+
#define ecb_frexpf(x,e) frexpf ((x), (e))
|
|
1343
|
+
#else
|
|
1344
|
+
#define ecb_ldexpf(x,e) (float) ldexp ((double) (x), (e))
|
|
1345
|
+
#define ecb_frexpf(x,e) (float) frexp ((double) (x), (e))
|
|
1346
|
+
#endif
|
|
1163
1347
|
|
|
1164
1348
|
/* convert a float to ieee single/binary32 */
|
|
1165
|
-
ecb_function_ uint32_t ecb_float_to_binary32 (float x)
|
|
1166
|
-
ecb_function_ uint32_t
|
|
1349
|
+
ecb_function_ ecb_const uint32_t ecb_float_to_binary32 (float x);
|
|
1350
|
+
ecb_function_ ecb_const uint32_t
|
|
1167
1351
|
ecb_float_to_binary32 (float x)
|
|
1168
1352
|
{
|
|
1169
1353
|
uint32_t r;
|
|
@@ -1180,7 +1364,7 @@ ecb_inline ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () ==
|
|
|
1180
1364
|
if (x < -3.40282346638528860e+38f) return 0xff800000U;
|
|
1181
1365
|
if (x != x ) return 0x7fbfffffU;
|
|
1182
1366
|
|
|
1183
|
-
m =
|
|
1367
|
+
m = ecb_frexpf (x, &e) * 0x1000000U;
|
|
1184
1368
|
|
|
1185
1369
|
r = m & 0x80000000U;
|
|
1186
1370
|
|
|
@@ -1202,8 +1386,8 @@ ecb_inline ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () ==
|
|
|
1202
1386
|
}
|
|
1203
1387
|
|
|
1204
1388
|
/* converts an ieee single/binary32 to a float */
|
|
1205
|
-
ecb_function_ float ecb_binary32_to_float (uint32_t x)
|
|
1206
|
-
ecb_function_ float
|
|
1389
|
+
ecb_function_ ecb_const float ecb_binary32_to_float (uint32_t x);
|
|
1390
|
+
ecb_function_ ecb_const float
|
|
1207
1391
|
ecb_binary32_to_float (uint32_t x)
|
|
1208
1392
|
{
|
|
1209
1393
|
float r;
|
|
@@ -1223,7 +1407,7 @@ ecb_inline ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () ==
|
|
|
1223
1407
|
e = 1;
|
|
1224
1408
|
|
|
1225
1409
|
/* we distrust ldexpf a bit and do the 2**-24 scaling by an extra multiply */
|
|
1226
|
-
r =
|
|
1410
|
+
r = ecb_ldexpf (x * (0.5f / 0x800000U), e - 126);
|
|
1227
1411
|
|
|
1228
1412
|
r = neg ? -r : r;
|
|
1229
1413
|
#endif
|
|
@@ -1232,8 +1416,8 @@ ecb_inline ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () ==
|
|
|
1232
1416
|
}
|
|
1233
1417
|
|
|
1234
1418
|
/* convert a double to ieee double/binary64 */
|
|
1235
|
-
ecb_function_ uint64_t ecb_double_to_binary64 (double x)
|
|
1236
|
-
ecb_function_ uint64_t
|
|
1419
|
+
ecb_function_ ecb_const uint64_t ecb_double_to_binary64 (double x);
|
|
1420
|
+
ecb_function_ ecb_const uint64_t
|
|
1237
1421
|
ecb_double_to_binary64 (double x)
|
|
1238
1422
|
{
|
|
1239
1423
|
uint64_t r;
|
|
@@ -1272,8 +1456,8 @@ ecb_inline ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () ==
|
|
|
1272
1456
|
}
|
|
1273
1457
|
|
|
1274
1458
|
/* converts an ieee double/binary64 to a double */
|
|
1275
|
-
ecb_function_ double ecb_binary64_to_double (uint64_t x)
|
|
1276
|
-
ecb_function_ double
|
|
1459
|
+
ecb_function_ ecb_const double ecb_binary64_to_double (uint64_t x);
|
|
1460
|
+
ecb_function_ ecb_const double
|
|
1277
1461
|
ecb_binary64_to_double (uint64_t x)
|
|
1278
1462
|
{
|
|
1279
1463
|
double r;
|
|
@@ -1301,6 +1485,22 @@ ecb_inline ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () ==
|
|
|
1301
1485
|
return r;
|
|
1302
1486
|
}
|
|
1303
1487
|
|
|
1488
|
+
/* convert a float to ieee half/binary16 */
|
|
1489
|
+
ecb_function_ ecb_const uint16_t ecb_float_to_binary16 (float x);
|
|
1490
|
+
ecb_function_ ecb_const uint16_t
|
|
1491
|
+
ecb_float_to_binary16 (float x)
|
|
1492
|
+
{
|
|
1493
|
+
return ecb_binary32_to_binary16 (ecb_float_to_binary32 (x));
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
/* convert an ieee half/binary16 to float */
|
|
1497
|
+
ecb_function_ ecb_const float ecb_binary16_to_float (uint16_t x);
|
|
1498
|
+
ecb_function_ ecb_const float
|
|
1499
|
+
ecb_binary16_to_float (uint16_t x)
|
|
1500
|
+
{
|
|
1501
|
+
return ecb_binary32_to_float (ecb_binary16_to_binary32 (x));
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1304
1504
|
#endif
|
|
1305
1505
|
|
|
1306
1506
|
#endif
|
|
@@ -2855,7 +3055,7 @@ loop_fork (EV_P)
|
|
|
2855
3055
|
#endif
|
|
2856
3056
|
|
|
2857
3057
|
#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE
|
|
2858
|
-
if (ev_is_active (&pipe_w))
|
|
3058
|
+
if (ev_is_active (&pipe_w) && postfork != 2)
|
|
2859
3059
|
{
|
|
2860
3060
|
/* pipe_write_wanted must be false now, so modifying fd vars should be safe */
|
|
2861
3061
|
|
|
@@ -3355,7 +3555,7 @@ VALUE ev_backend_poll(void *ptr)
|
|
|
3355
3555
|
int
|
|
3356
3556
|
ev_run (EV_P_ int flags)
|
|
3357
3557
|
{
|
|
3358
|
-
|
|
3558
|
+
/* ########## NIO4R PATCHERY HO! ########## */
|
|
3359
3559
|
#if defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
|
|
3360
3560
|
struct ev_poll_args poll_args;
|
|
3361
3561
|
#endif
|
|
@@ -3526,10 +3726,8 @@ rb_thread_unsafe_dangerous_crazy_blocking_region_end(...);
|
|
|
3526
3726
|
|
|
3527
3727
|
#ifndef HAVE_RB_THREAD_CALL_WITHOUT_GVL
|
|
3528
3728
|
#ifdef HAVE_RB_THREAD_BLOCKING_REGION
|
|
3529
|
-
|
|
3530
3729
|
#define rb_thread_call_without_gvl(func, data1, ubf, data2) \
|
|
3531
3730
|
rb_thread_blocking_region((rb_blocking_function_t *)func, data1, ubf, data2)
|
|
3532
|
-
|
|
3533
3731
|
#endif
|
|
3534
3732
|
#endif
|
|
3535
3733
|
|
|
@@ -3538,7 +3736,7 @@ rb_thread_unsafe_dangerous_crazy_blocking_region_end(...);
|
|
|
3538
3736
|
poll_args.waittime = waittime;
|
|
3539
3737
|
rb_thread_call_without_gvl(ev_backend_poll, (void *)&poll_args, RUBY_UBF_IO, 0);
|
|
3540
3738
|
#else
|
|
3541
|
-
|
|
3739
|
+
backend_poll (EV_A_ waittime);
|
|
3542
3740
|
#endif
|
|
3543
3741
|
/*
|
|
3544
3742
|
############################# END PATCHERY ############################
|