| [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 | //
|
|---|
| [454f478] | 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 ***
|
|---|
| [3d5f2ef1] | 11 | //
|
|---|
| [ea7d2b0] | 12 | // Author : Thierry Delisle
|
|---|
| [490d9972] | 13 | // Created On : Thu Nov 9 13:24:10 2017
|
|---|
| 14 | // Last Modified By : Peter A. Buhr
|
|---|
| [8920c6d] | 15 | // Last Modified On : Mon Oct 27 22:40:05 2025
|
|---|
| 16 | // Update Count : 23
|
|---|
| [3d5f2ef1] | 17 | //
|
|---|
| [ea7d2b0] | 18 |
|
|---|
| 19 | #pragma once
|
|---|
| 20 |
|
|---|
| 21 | #include <stdint.h>
|
|---|
| [d685cb0] | 22 | #include <assert.h>
|
|---|
| [ea7d2b0] | 23 |
|
|---|
| [490d9972] | 24 | #define likely(x) __builtin_expect(!!(x), 1)
|
|---|
| 25 | #define unlikely(x) __builtin_expect(!!(x), 0)
|
|---|
| [0cf5b79] | 26 |
|
|---|
| [8920c6d] | 27 | typedef void (* fptr_t)();
|
|---|
| [a30fceb] | 28 | typedef uint64_t func_id_t;
|
|---|
| [0cf5b79] | 29 | typedef int_fast16_t __lock_size_t;
|
|---|
| 30 |
|
|---|
| 31 | #ifdef __cforall
|
|---|
| [b1672e1] | 32 | #define __cfa_anonymous_object(x) inline struct x
|
|---|
| [0cf5b79] | 33 | #else
|
|---|
| [8b73526] | 34 | #define __cfa_anonymous_object(x) struct x __cfa_anonymous_object
|
|---|
| [c2b9f21] | 35 | #endif
|
|---|
| 36 |
|
|---|
| [b443db0] | 37 |
|
|---|
| 38 | #if defined(__has_attribute)
|
|---|
| 39 | #if !__has_attribute(__noclone__)
|
|---|
| 40 | #define ATTRIBUTE_NOCLONE
|
|---|
| 41 | #endif
|
|---|
| 42 | #endif
|
|---|
| 43 | #ifndef ATTRIBUTE_NOCLONE
|
|---|
| 44 | #define ATTRIBUTE_NOCLONE __attribute__((__noclone__))
|
|---|
| 45 | #endif
|
|---|
| 46 |
|
|---|
| [8108ba8] | 47 | #define libcfa_public __attribute__((visibility("default")))
|
|---|
| [b443db0] | 48 | #define libcfa_nopreempt __attribute__((section("cfatext_nopreempt"))) __attribute__((__noinline__)) ATTRIBUTE_NOCLONE
|
|---|
| 49 |
|
|---|
| 50 | struct __cfa_nopreempt_region {
|
|---|
| 51 | void * start;
|
|---|
| 52 | void * stop;
|
|---|
| 53 | };
|
|---|
| [8108ba8] | 54 |
|
|---|
| [c2b9f21] | 55 | #ifdef __cforall
|
|---|
| [8a13c47] | 56 | void abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
|
|---|
| 57 | void abort( bool signalAbort, const char fmt[], ... ) __attribute__ (( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ ));
|
|---|
| [c2b9f21] | 58 | extern "C" {
|
|---|
| [9cd5bd2] | 59 | #endif
|
|---|
| [95dab9e] | 60 | void __cabi_abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
|
|---|
| [9cd5bd2] | 61 | #ifdef __cforall
|
|---|
| [c2b9f21] | 62 | }
|
|---|
| [490d9972] | 63 | #endif
|
|---|
| [2026bb6] | 64 |
|
|---|
| 65 | #if defined(__cforall_thread__)
|
|---|
| 66 | #define OPTIONAL_THREAD
|
|---|
| 67 | #else
|
|---|
| 68 | #define OPTIONAL_THREAD __attribute__((weak))
|
|---|
| 69 | #endif
|
|---|
| [21184e3] | 70 |
|
|---|
| [d685cb0] | 71 | static inline long long int rdtscl(void) {
|
|---|
| [98cf828] | 72 | #if defined( __i386 ) || defined( __x86_64 )
|
|---|
| 73 | unsigned int lo, hi;
|
|---|
| 74 | __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
|
|---|
| 75 | return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
|
|---|
| 76 | #elif defined( __aarch64__ ) || defined( __arm__ )
|
|---|
| [d685cb0] | 77 | // https://github.com/google/benchmark/blob/v1.1.0/src/cycleclock.h#L116
|
|---|
| 78 | long long int virtual_timer_value;
|
|---|
| 79 | asm volatile("mrs %0, cntvct_el0" : "=r"(virtual_timer_value));
|
|---|
| 80 | return virtual_timer_value;
|
|---|
| 81 | #else
|
|---|
| [98cf828] | 82 | #error unsupported hardware architecture
|
|---|
| [c1076a2f] | 83 | #endif
|
|---|
| [21184e3] | 84 | }
|
|---|
| [454f478] | 85 |
|
|---|
| 86 | // pause to prevent excess processor bus usage
|
|---|
| 87 | #if defined( __i386 ) || defined( __x86_64 )
|
|---|
| 88 | #define Pause() __asm__ __volatile__ ( "pause" : : : )
|
|---|
| 89 | #elif defined( __ARM_ARCH )
|
|---|
| 90 | #define Pause() __asm__ __volatile__ ( "YIELD" : : : )
|
|---|
| 91 | #else
|
|---|
| 92 | #error unsupported architecture
|
|---|
| 93 | #endif
|
|---|
| [dddb3dd0] | 94 |
|
|---|
| 95 | #define CFA_IO_LAZY (1_l64u << 32_l64u)
|
|---|