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

Comparing libecb/ecb.h (file contents):
Revision 1.101 by root, Thu Jun 28 14:50:01 2012 UTC vs.
Revision 1.102 by root, Thu Jun 28 17:23:58 2012 UTC

83#define ECB_C (__STDC__+0) /* this assumes that __STDC__ is either empty or a number */ 83#define ECB_C (__STDC__+0) /* this assumes that __STDC__ is either empty or a number */
84#define ECB_C99 (__STDC_VERSION__ >= 199901L) 84#define ECB_C99 (__STDC_VERSION__ >= 199901L)
85#define ECB_C11 (__STDC_VERSION__ >= 201112L) 85#define ECB_C11 (__STDC_VERSION__ >= 201112L)
86#define ECB_CPP (__cplusplus+0) 86#define ECB_CPP (__cplusplus+0)
87#define ECB_CPP11 (__cplusplus >= 201103L) 87#define ECB_CPP11 (__cplusplus >= 201103L)
88
89#if ECB_CPP
90 #define ECB_EXTERN_C extern "C"
91 #define ECB_EXTERN_C_BEG ECB_EXTERN_C {
92 #define ECB_EXTERN_C_END }
93#else
94 #define ECB_EXTERN_C extern
95 #define ECB_EXTERN_C_BEG
96 #define ECB_EXTERN_C_END
97#endif
88 98
89/*****************************************************************************/ 99/*****************************************************************************/
90 100
91/* ECB_NO_THREADS - ecb is not used by multiple threads, ever */ 101/* ECB_NO_THREADS - ecb is not used by multiple threads, ever */
92/* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */ 102/* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */
138 148
139#ifndef ECB_MEMORY_FENCE 149#ifndef ECB_MEMORY_FENCE
140 #if ECB_GCC_VERSION(4,7) 150 #if ECB_GCC_VERSION(4,7)
141 /* see comment below (stdatomic.h) about the C11 memory model. */ 151 /* see comment below (stdatomic.h) about the C11 memory model. */
142 #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) 152 #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST)
143 #elif defined __clang && __has_feature (cxx_atomic) 153 /*#elif defined __clang && __has_feature (cxx_atomic)*/
144 /* see comment below (stdatomic.h) about the C11 memory model. */ 154 /* see comment below (stdatomic.h) about the C11 memory model. */
145 #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) 155 /*#define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST)*/
146 #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ 156 #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__
147 #define ECB_MEMORY_FENCE __sync_synchronize () 157 #define ECB_MEMORY_FENCE __sync_synchronize ()
148 #elif _MSC_VER >= 1400 /* VC++ 2005 */ 158 #elif _MSC_VER >= 1400 /* VC++ 2005 */
149 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) 159 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier)
150 #define ECB_MEMORY_FENCE _ReadWriteBarrier () 160 #define ECB_MEMORY_FENCE _ReadWriteBarrier ()
524 } 534 }
525#else 535#else
526 #define ecb_array_length(name) (sizeof (name) / sizeof (name [0])) 536 #define ecb_array_length(name) (sizeof (name) / sizeof (name [0]))
527#endif 537#endif
528 538
539#if __STDC_IEC_559__
540 // we assume this is defined for most C and many C++ compilers
541 ecb_inline ecb_bool ecb_float_ieee (void) ecb_const;
542 ecb_inline ecb_bool ecb_float_ieee (void) { return 1; }
543 ecb_inline ecb_bool ecb_double_ieee (void) ecb_const;
544 ecb_inline ecb_bool ecb_double_ieee (void) { return 1; }
545#elif ECB_CPP
546 #include <limits>
547 ecb_inline ecb_bool ecb_float_ieee (void) ecb_const;
548 ecb_inline ecb_bool ecb_float_ieee (void) { return std::numeric_limits<float >::is_iec559; }
549 ecb_inline ecb_bool ecb_double_ieee (void) ecb_const;
550 ecb_inline ecb_bool ecb_double_ieee (void) { return std::numeric_limits<double>::is_iec559; }
551#else
552 ecb_inline ecb_bool ecb_float_ieee (void) ecb_const;
553 ecb_inline ecb_bool ecb_float_ieee (void) { return 0; }
554 ecb_inline ecb_bool ecb_double_ieee (void) ecb_const;
555 ecb_inline ecb_bool ecb_double_ieee (void) { return 0; }
529#endif 556#endif
530 557
558// convert a float to ieee single/binary32
559ecb_function_ uint32_t ecb_float_to_binary32 (float x) ecb_const;
560ecb_function_ uint32_t
561ecb_float_to_binary32 (float x)
562{
563 /* slow emulation, works for anything but nan's and -0 */
564 ECB_EXTERN_C float frexpf (float v, int *e);
565 uint32_t r, m;
566 int e;
567
568 if (x == 0e0f ) return 0;
569 if (x > +3.40282346638528860e+38f) return 0x7f800000U;
570 if (x < -3.40282346638528860e+38f) return 0xff800000U;
571
572 m = frexpf (x, &e) * 0x1000000U;
573
574 r = m & 0x80000000U;
575
576 if (r)
577 m = -m;
578
579 if (e < -125)
580 {
581 m &= 0xffffffU;
582 m >>= (-125 - e);
583 e = -126;
584 }
585
586 r |= (e + 126) << 23;
587 r |= m & 0x7fffffU;
588
589 return r;
590}
591
592// converts a ieee single/binary32 to a float
593ecb_function_ float ecb_binary32_to_float (uint32_t x) ecb_const;
594ecb_function_ float
595ecb_binary32_to_float (uint32_t x)
596{
597 /* emulation, only works for normals and subnormals and +0 */
598 ECB_EXTERN_C float ldexpf (float x, int e);
599
600 int neg = x >> 31;
601 int e = (x >> 23) & 0xffU;
602 float r;
603
604 x &= 0x7fffffU;
605
606 if (e)
607 x |= 0x800000U;
608
609 /* we distrust ldexpf a bit and do the 2**-24 scaling by an extra multiply */
610 r = ldexpf (x * (1.f / 0x1000000U), e - 126);
611
612 return neg ? -r : r;
613}
614
615ecb_function_ uint64_t ecb_double_to_binary64 (double x) ecb_const;
616ecb_function_ uint64_t
617ecb_double_to_binary64 (double x)
618{
619}
620
621#endif
622

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines