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 : Sat Oct 24 10:53:15 2020 |
---|
13 | // Update Count : 21 |
---|
14 | // |
---|
15 | |
---|
16 | #pragma once |
---|
17 | |
---|
18 | #include <stdint.h> |
---|
19 | #include <assert.h> |
---|
20 | |
---|
21 | #define likely(x) __builtin_expect(!!(x), 1) |
---|
22 | #define unlikely(x) __builtin_expect(!!(x), 0) |
---|
23 | #define thread_local _Thread_local |
---|
24 | |
---|
25 | typedef void (*fptr_t)(); |
---|
26 | typedef int_fast16_t __lock_size_t; |
---|
27 | |
---|
28 | #ifdef __cforall |
---|
29 | #define __cfa_anonymous_object(x) inline struct x |
---|
30 | #else |
---|
31 | #define __cfa_anonymous_object(x) x __cfa_anonymous_object |
---|
32 | #endif |
---|
33 | |
---|
34 | #ifdef __cforall |
---|
35 | void abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ )); |
---|
36 | void abort( bool signalAbort, const char fmt[], ... ) __attribute__ (( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ )); |
---|
37 | extern "C" { |
---|
38 | #endif |
---|
39 | void __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 | |
---|
50 | static inline long long int rdtscl(void) { |
---|
51 | #if defined( __i386 ) || defined( __x86_64 ) |
---|
52 | unsigned int lo, hi; |
---|
53 | __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); |
---|
54 | return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 ); |
---|
55 | #elif defined( __aarch64__ ) || defined( __arm__ ) |
---|
56 | // https://github.com/google/benchmark/blob/v1.1.0/src/cycleclock.h#L116 |
---|
57 | long long int virtual_timer_value; |
---|
58 | asm volatile("mrs %0, cntvct_el0" : "=r"(virtual_timer_value)); |
---|
59 | return virtual_timer_value; |
---|
60 | #else |
---|
61 | #error unsupported hardware architecture |
---|
62 | #endif |
---|
63 | } |
---|