source: libcfa/src/bits/defs.hfa @ cd5b58f

ADTast-experimental
Last change on this file since cd5b58f was cd5b58f, checked in by Thierry Delisle <tdelisle@…>, 18 months ago

Changed node link in thread to use dlink called cltr_link

  • Property mode set to 100644
File size: 3.0 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 -- Commen macros, functions and typedefs
8// Most files depend on them and they are always useful to have.
9//
10//  *** Must not contain code specific to libcfathread ***
11//
12// Author           : Thierry Delisle
13// Created On       : Thu Nov  9 13:24:10 2017
14// Last Modified By : Peter A. Buhr
15// Last Modified On : Sat Oct 24 10:53:15 2020
16// Update Count     : 21
17//
18
19#pragma once
20
21#include <stdint.h>
22#include <assert.h>
23
24#define likely(x)   __builtin_expect(!!(x), 1)
25#define unlikely(x) __builtin_expect(!!(x), 0)
26
27typedef void (*fptr_t)();
28typedef int_fast16_t __lock_size_t;
29
30#ifdef __cforall
31#define __cfa_anonymous_object(x) inline struct x
32#define __cfa_dlink1(x) dlink(x)
33#define __cfa_dlink2(x, name) inline struct name { inline dlink(x); }
34#else
35#define __cfa_anonymous_object(x) struct x __cfa_anonymous_object
36#define __cfa_dlink1(x) struct { struct x * next; struct x * back; }
37#define __cfa_dlink2(x, name) struct { struct x * next; struct x * back; } __dlink ## name
38#endif
39
40
41#if defined(__has_attribute)
42#if !__has_attribute(__noclone__)
43#define ATTRIBUTE_NOCLONE
44#endif
45#endif
46#ifndef ATTRIBUTE_NOCLONE
47#define ATTRIBUTE_NOCLONE __attribute__((__noclone__))
48#endif
49
50#define libcfa_public __attribute__((visibility("default")))
51#define libcfa_nopreempt __attribute__((section("cfatext_nopreempt"))) __attribute__((__noinline__)) ATTRIBUTE_NOCLONE
52
53struct __cfa_nopreempt_region {
54        void * start;
55        void * stop;
56};
57
58#ifdef __cforall
59void abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
60void abort( bool signalAbort, const char fmt[], ... ) __attribute__ (( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ ));
61extern "C" {
62#endif
63void __cabi_abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
64#ifdef __cforall
65}
66#endif
67
68#if defined(__cforall_thread__)
69#define OPTIONAL_THREAD
70#else
71#define OPTIONAL_THREAD __attribute__((weak))
72#endif
73
74static inline long long int rdtscl(void) {
75        #if defined( __i386 ) || defined( __x86_64 )
76        unsigned int lo, hi;
77        __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
78        return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
79        #elif defined( __aarch64__ ) || defined( __arm__ )
80        // https://github.com/google/benchmark/blob/v1.1.0/src/cycleclock.h#L116
81        long long int virtual_timer_value;
82        asm volatile("mrs %0, cntvct_el0" : "=r"(virtual_timer_value));
83        return virtual_timer_value;
84        #else
85                #error unsupported hardware architecture
86        #endif
87}
88
89// pause to prevent excess processor bus usage
90#if defined( __i386 ) || defined( __x86_64 )
91        #define Pause() __asm__ __volatile__ ( "pause" : : : )
92#elif defined( __ARM_ARCH )
93        #define Pause() __asm__ __volatile__ ( "YIELD" : : : )
94#else
95        #error unsupported architecture
96#endif
97
98#define CFA_IO_LAZY (1_l64u << 32_l64u)
Note: See TracBrowser for help on using the repository browser.