Ignore:
Timestamp:
Jan 30, 2020, 1:40:05 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
b7d6a36
Parents:
75ca7f4
Message:

Started doing some of the x86 implementations and some changes after a code review

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/bits/defs.hfa

    r75ca7f4 rdca5802  
    5656// #define __CFA_NO_BIT_TEST_AND_SET__
    5757
    58 static inline bool bts(volatile unsigned long long int * target, unsigned long long int bit ) {
     58#if defined( __i386 )
     59static inline bool __atomic_bts(volatile unsigned long int * target, unsigned long int bit ) {
     60        #if defined(__CFA_NO_BIT_TEST_AND_SET__)
     61        unsigned long int mask = 1ul << bit;
     62        unsigned long int ret = __atomic_fetch_or(target, mask, (int)__ATOMIC_RELAXED);
     63        return (ret & mask) != 0;
     64    #else
     65        int result = 0;
     66        asm volatile(
     67            "LOCK btsl %[bit], %[target]\n\t"
     68            : "=@ccc" (result)
     69            : [target] "m" (*target), [bit] "r" (bit)
     70        );
     71        return result != 0;
     72    #endif
     73}
     74
     75static inline bool __atomic_btr(volatile unsigned long int * target, unsigned long int bit ) {
     76        #if defined(__CFA_NO_BIT_TEST_AND_SET__)
     77        unsigned long int mask = 1ul << bit;
     78        unsigned long int ret = __atomic_fetch_and(target, ~mask, (int)__ATOMIC_RELAXED);
     79        return (ret & mask) != 0;
     80        #else
     81        int result = 0;
     82        asm volatile(
     83            "LOCK btrl %[bit], %[target]\n\t"
     84            :"=@ccc" (result)
     85            : [target] "m" (*target), [bit] "r" (bit)
     86        );
     87        return result != 0;
     88    #endif
     89}
     90#elif defined( __x86_64 )
     91static inline bool __atomic_bts(volatile unsigned long long int * target, unsigned long long int bit ) {
    5992        #if defined(__CFA_NO_BIT_TEST_AND_SET__)
    6093        unsigned long long int mask = 1ul << bit;
     
    72105}
    73106
    74 static inline bool btr(volatile unsigned long long int * target, unsigned long long int bit ) {
     107static inline bool __atomic_btr(volatile unsigned long long int * target, unsigned long long int bit ) {
    75108        #if defined(__CFA_NO_BIT_TEST_AND_SET__)
    76109        unsigned long long int mask = 1ul << bit;
     
    87120    #endif
    88121}
     122#elif defined( __ARM_ARCH )
     123    #error __atomic_bts and __atomic_btr not implemented for arm
     124#else
     125        #error uknown hardware architecture
     126#endif
Note: See TracChangeset for help on using the changeset viewer.