1 #include "lfds610_abstraction_internal_body.h"
7 /****************************************************************************/
8 #if (defined _WIN64 && defined _MSC_VER)
10 /* TRD : 64 bit Windows (user-mode or kernel) on any CPU with the Microsoft C compiler
12 _WIN64 indicates 64 bit Windows
13 _MSC_VER indicates Microsoft C compiler
16 static LFDS610_INLINE unsigned char lfds610_abstraction_dcas( volatile lfds610_atom_t *destination, lfds610_atom_t *exchange, lfds610_atom_t *compare )
18 assert( destination != NULL );
19 assert( exchange != NULL );
20 assert( compare != NULL );
22 return( _InterlockedCompareExchange128((volatile __int64 *) destination, (__int64) *(exchange+1), (__int64) *exchange, (__int64 *) compare) );
31 /****************************************************************************/
32 #if (!defined _WIN64 && defined _WIN32 && defined _MSC_VER)
34 /* TRD : 32 bit Windows (user-mode or kernel) on any CPU with the Microsoft C compiler
36 (!defined _WIN64 && defined _WIN32) indicates 32 bit Windows
37 _MSC_VER indicates Microsoft C compiler
40 static LFDS610_INLINE unsigned char lfds610_abstraction_dcas( volatile lfds610_atom_t *destination, lfds610_atom_t *exchange, lfds610_atom_t *compare )
45 assert( destination != NULL );
46 assert( exchange != NULL );
47 assert( compare != NULL );
49 *(__int64 *) &original_compare = *(__int64 *) compare;
51 *(__int64 *) compare = _InterlockedCompareExchange64( (volatile __int64 *) destination, *(__int64 *) exchange, *(__int64 *) compare );
53 return( (unsigned char) (*(__int64 *) compare == *(__int64 *) &original_compare) );
62 /****************************************************************************/
63 #if (defined __x86_64__ && defined __GNUC__)
65 /* TRD : any OS on x64 with GCC
67 __x86_64__ indicates x64
68 __GNUC__ indicates GCC
71 static LFDS610_INLINE unsigned char lfds610_abstraction_dcas( volatile lfds610_atom_t *destination, lfds610_atom_t *exchange, lfds610_atom_t *compare )
76 assert( destination != NULL );
77 assert( exchange != NULL );
78 assert( compare != NULL );
82 "lock;" // make cmpxchg16b atomic
83 "cmpxchg16b %0;" // cmpxchg16b sets ZF on success
84 "setz %3;" // if ZF set, set cas_result to 1
87 : "+m" (*(volatile lfds610_atom_t (*)[2]) destination), "+a" (*compare), "+d" (*(compare+1)), "=q" (cas_result)
90 : "b" (*exchange), "c" (*(exchange+1))
105 /****************************************************************************/
106 #if ((defined __i686__ || defined __arm__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 1 && __GNUC_PATCHLEVEL__ >= 0)
108 /* TRD : any OS on x86 or ARM with GCC 4.1.0 or better
110 GCC 4.1.0 introduced the __sync_*() atomic intrinsics
112 __GNUC__ / __GNUC_MINOR__ / __GNUC_PATCHLEVEL__ indicates GCC and which version
115 static LFDS610_INLINE unsigned char lfds610_abstraction_dcas( volatile lfds610_atom_t *destination, lfds610_atom_t *exchange, lfds610_atom_t *compare )
120 unsigned long long int
121 original_destination;
123 assert( destination != NULL );
124 assert( exchange != NULL );
125 assert( compare != NULL );
127 original_destination = __sync_val_compare_and_swap( (volatile unsigned long long int *) destination, *(unsigned long long int *) compare, *(unsigned long long int *) exchange );
129 if( original_destination == *(unsigned long long int *) compare )
132 *(unsigned long long int *) compare = original_destination;
134 return( cas_result );