source: libcfa/src/bits/defs.hfa @ 30763fd

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 30763fd was 7768b8d, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

First step at adding the new ready queue to Cforall

  • Property mode set to 100644
File size: 2.5 KB
RevLine 
[3d5f2ef1]1//
[ea7d2b0]2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
[3d5f2ef1]6//
[73abe95]7// defs.hfa --
[3d5f2ef1]8//
[ea7d2b0]9// Author           : Thierry Delisle
[490d9972]10// Created On       : Thu Nov  9 13:24:10 2017
11// Last Modified By : Peter A. Buhr
[169d944]12// Last Modified On : Thu Feb  8 16:22:41 2018
13// Update Count     : 8
[3d5f2ef1]14//
[ea7d2b0]15
16#pragma once
17
18#include <stdbool.h>
[0cf5b79]19#include <stddef.h>
[ea7d2b0]20#include <stdint.h>
21
[490d9972]22#define likely(x)   __builtin_expect(!!(x), 1)
23#define unlikely(x) __builtin_expect(!!(x), 0)
[0cf5b79]24#define thread_local _Thread_local
25
26typedef void (*fptr_t)();
27typedef int_fast16_t __lock_size_t;
28
29#ifdef __cforall
[b1672e1]30#define __cfa_anonymous_object(x) inline struct x
[0cf5b79]31#else
[b1672e1]32#define __cfa_anonymous_object(x) x __cfa_anonymous_object
[c2b9f21]33#endif
34
35#ifdef __cforall
[169d944]36void abort ( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
[c2b9f21]37extern "C" {
38#endif
[169d944]39void __cabi_abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
[c2b9f21]40#ifdef __cforall
41}
[490d9972]42#endif
[2026bb6]43
44#if defined(__cforall_thread__)
45#define OPTIONAL_THREAD
46#else
47#define OPTIONAL_THREAD __attribute__((weak))
48#endif
[21184e3]49
50static inline long long rdtscl(void) {
51    unsigned int lo, hi;
52    __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
53    return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
54}
[7768b8d]55
56#define __CFA_NO_BIT_TEST_AND_SET__
57
58static inline bool bts(volatile unsigned long long int * target, unsigned long long int bit ) {
59        #if defined(__CFA_NO_BIT_TEST_AND_SET__)
60        unsigned long long int mask = 1ul << bit;
61        unsigned long long int ret = __atomic_fetch_or(target, mask, (int)__ATOMIC_RELAXED);
62        return (ret & mask) != 0;
63    #else
64        int result = 0;
65        asm volatile(
66            "LOCK btsq %[bit], %[target]\n\t"
67            :"=@ccc" (result)
68            : [target] "m" (*target), [bit] "r" (bit)
69        );
70        return result != 0;
71    #endif
72}
73
74static inline bool btr(volatile unsigned long long int * target, unsigned long long int bit ) {
75        #if defined(__CFA_NO_BIT_TEST_AND_SET__)
76        unsigned long long int mask = 1ul << bit;
77        unsigned long long int ret = __atomic_fetch_and(target, ~mask, (int)__ATOMIC_RELAXED);
78        return (ret & mask) != 0;
79        #else
80        int result = 0;
81        asm volatile(
82            "LOCK btrq %[bit], %[target]\n\t"
83            :"=@ccc" (result)
84            : [target] "m" (*target), [bit] "r" (bit)
85        );
86        return result != 0;
87    #endif
88}
Note: See TracBrowser for help on using the repository browser.