source: libcfa/src/bits/defs.hfa@ 2a3d446

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 2a3d446 was b798713, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Working ready queue

  • Property mode set to 100644
File size: 2.5 KB
Line 
1//
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.
6//
7// defs.hfa --
8//
9// Author : Thierry Delisle
10// Created On : Thu Nov 9 13:24:10 2017
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Thu Feb 8 16:22:41 2018
13// Update Count : 8
14//
15
16#pragma once
17
18#include <stdbool.h>
19#include <stddef.h>
20#include <stdint.h>
21
22#define likely(x) __builtin_expect(!!(x), 1)
23#define unlikely(x) __builtin_expect(!!(x), 0)
24#define thread_local _Thread_local
25
26typedef void (*fptr_t)();
27typedef int_fast16_t __lock_size_t;
28
29#ifdef __cforall
30#define __cfa_anonymous_object(x) inline struct x
31#else
32#define __cfa_anonymous_object(x) x __cfa_anonymous_object
33#endif
34
35#ifdef __cforall
36void abort ( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
37extern "C" {
38#endif
39void __cabi_abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
40#ifdef __cforall
41}
42#endif
43
44#if defined(__cforall_thread__)
45#define OPTIONAL_THREAD
46#else
47#define OPTIONAL_THREAD __attribute__((weak))
48#endif
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}
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.