libsnobol4
1.0.2
High-performance SNOBOL4-style pattern matching library
Loading...
Searching...
No Matches
snobol_attrs.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
snobol/c23_compat.h
"
4
5
#ifdef __cplusplus
6
extern
"C"
{
7
#endif
8
9
24
25
/* ── SNOBOL_NODISCARD ──────────────────────────────────────────────────── */
26
#ifndef SNOBOL_NODISCARD
27
#if defined(__cplusplus) && __cplusplus >= 201703L
28
#define SNOBOL_NODISCARD [[nodiscard]]
29
#elif !defined(__cplusplus) && defined(__STDC_VERSION__) && \
30
__STDC_VERSION__ >= 202311L
31
#define SNOBOL_NODISCARD [[nodiscard]]
32
#elif defined(__GNUC__) || defined(__clang__)
33
#define SNOBOL_NODISCARD __attribute__((warn_unused_result))
34
#else
35
#define SNOBOL_NODISCARD
36
#endif
37
#endif
38
39
/* ── SNOBOL_MAYBE_UNUSED ───────────────────────────────────────────────── */
40
#ifndef SNOBOL_MAYBE_UNUSED
41
#if defined(__cplusplus) && __cplusplus >= 201703L
42
#define SNOBOL_MAYBE_UNUSED [[maybe_unused]]
43
#elif !defined(__cplusplus) && defined(__STDC_VERSION__) && \
44
__STDC_VERSION__ >= 202311L
45
#define SNOBOL_MAYBE_UNUSED [[maybe_unused]]
46
#elif defined(__GNUC__) || defined(__clang__)
47
#define SNOBOL_MAYBE_UNUSED __attribute__((unused))
48
#else
49
#define SNOBOL_MAYBE_UNUSED
50
#endif
51
#endif
52
53
/* ── SNOBOL_ALWAYS_INLINE / SNOBOL_FORCE_INLINE ────────────────────────── */
54
#ifndef SNOBOL_ALWAYS_INLINE
55
#if defined(__GNUC__) || defined(__clang__)
56
#define SNOBOL_ALWAYS_INLINE __attribute__((always_inline))
57
#elif defined(_MSC_VER)
58
#define SNOBOL_ALWAYS_INLINE __forceinline
59
#else
60
#define SNOBOL_ALWAYS_INLINE inline
61
#endif
62
#endif
63
64
/* ── SNOBOL_HOT / SNOBOL_COLD ──────────────────────────────────────────── */
65
/* Place frequently executed code in the .text.hot section (hot) and
66
* rarely taken paths (error handling, fallback branches) in .text.cold
67
* (cold) to reduce iTLB pressure on the hot dispatch / scan loops. */
68
#ifndef SNOBOL_HOT
69
#if defined(__GNUC__) || defined(__clang__)
70
#define SNOBOL_HOT __attribute__((hot))
71
#else
72
#define SNOBOL_HOT
73
#endif
74
#endif
75
76
#ifndef SNOBOL_COLD
77
#if defined(__GNUC__) || defined(__clang__)
78
#define SNOBOL_COLD __attribute__((cold))
79
#else
80
#define SNOBOL_COLD
81
#endif
82
#endif
83
84
/* ── SNOBOL_PURE / SNOBOL_CONST ────────────────────────────────────────── */
85
/* pure: result depends only on arguments + visible memory; enables CSE/DCE.
86
* const: result depends only on arguments (no memory reads at all). */
87
#ifndef SNOBOL_PURE
88
#if defined(__GNUC__) || defined(__clang__)
89
#define SNOBOL_PURE __attribute__((pure))
90
#else
91
#define SNOBOL_PURE
92
#endif
93
#endif
94
95
#ifndef SNOBOL_CONST
96
#if defined(__GNUC__) || defined(__clang__)
97
#define SNOBOL_CONST __attribute__((const))
98
#else
99
#define SNOBOL_CONST
100
#endif
101
#endif
102
103
/* ── SNOBOL_RESTRICT ───────────────────────────────────────────────────── */
104
/* Portable spelling of the C 'restrict' qualifier for pointer parameters of
105
* hot functions whose pointers are provably non-aliasing. */
106
#ifndef SNOBOL_RESTRICT
107
#ifdef _MSC_VER
108
#define SNOBOL_RESTRICT __restrict
109
#elif defined(__GNUC__) || defined(__clang__)
110
#define SNOBOL_RESTRICT __restrict__
111
#else
112
#define SNOBOL_RESTRICT
113
#endif
114
#endif
115
116
/* ── likely() / unlikely() ─────────────────────────────────────────────── */
117
/* Branch prediction hints. Wrapped so unknown compilers degrade to the plain
118
* expression with no overhead. */
119
#ifndef likely
120
#if defined(__GNUC__) || defined(__clang__)
121
#define likely(x) __builtin_expect(!!(x), 1)
122
#else
123
#define likely(x) (x)
124
#endif
125
#endif
126
127
#ifndef unlikely
128
#if defined(__GNUC__) || defined(__clang__)
129
#define unlikely(x) __builtin_expect(!!(x), 0)
130
#else
131
#define unlikely(x) (x)
132
#endif
133
#endif
134
135
/* ── SNOBOL_ALIGNED ─────────────────────────────────────────────────────── */
136
/* Cache-line alignment hint for hot dispatch / scan-loop entry points so the
137
* function prologue and the innermost loop body land in the same cache line.
138
* GCC/Clang support per-function alignment via __attribute__((aligned(n)));
139
* MSVC has no per-function alignment attribute (__declspec(align(n)) applies
140
* only to variables, struct members and tag types), so it is a no-op there. */
141
#ifndef SNOBOL_ALIGNED
142
#if defined(__GNUC__) || defined(__clang__)
143
#define SNOBOL_ALIGNED(n) __attribute__((aligned(n)))
144
#elif defined(_MSC_VER)
145
#define SNOBOL_ALIGNED(n)
146
#else
147
#define SNOBOL_ALIGNED(n)
148
#endif
149
#endif
150
151
/* ── SNOBOL_THREAD_LOCAL ─────────────────────────────────────────────────── */
152
/* Thread-local storage qualifier. MSVC (pre-C11 threads) uses __declspec;
153
* C11+ (GCC/Clang, modern MSVC) uses _Thread_local. */
154
#ifndef SNOBOL_THREAD_LOCAL
155
#if defined(_MSC_VER) && !defined(__STDC_VERSION__)
156
#define SNOBOL_THREAD_LOCAL __declspec(thread)
157
#else
158
#define SNOBOL_THREAD_LOCAL _Thread_local
159
#endif
160
#endif
161
162
#ifdef __cplusplus
163
}
164
#endif
c23_compat.h
core
include
snobol
snobol_attrs.h
Generated by
1.15.0