ProtoCore
v0.0.2
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
speed_opt.h
Go to the documentation of this file.
1
// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2
// SPDX-License-Identifier: AGPL-3.0-or-later
3
4
/**
5
* @file speed_opt.h
6
* @brief Build one file at a named optimization level instead of the framework's.
7
*
8
* The framework's size-optimized level is appended after any build-system flags, so a consumer
9
* cannot raise it from outside. That level declines to inline small functions, and an appender
10
* chain that does not inline cannot fold: a literal's length stays a runtime scan and a bounded
11
* copy stays a call. Put @ref PC_OPTIMIZE_O2 at the top of such a `.cpp`, after its includes.
12
*
13
* The level is in the name rather than behind a knob, so a file states what it is built at and a
14
* reader does not have to resolve a second macro to find out. A macro rather than the pragma itself
15
* because core carries no toolchain language.
16
*
17
* O2 is the only level here because O2 is what has been measured (docs/FEATURE_PERFORMANCE.md 2b).
18
* O3 is untested on this path - not rejected. A file that needs another level adds the macro for it
19
* here rather than redefining this one.
20
*
21
* Apply only where there are no secrets or the code is constant-time by structure. An optimizer can
22
* turn a branchless mask-select into a data-dependent branch; `crypto/crypto_opt.h` is the crypto
23
* policy layer with per-die levels and those caveats.
24
*
25
* @author Douglas Quigg (dstroy0)
26
* @date 2026
27
*/
28
29
#ifndef PROTOCORE_SPEED_OPT_H
30
#define PROTOCORE_SPEED_OPT_H
31
32
// The capability is branched on ONCE, here. Each level below is then defined exactly once, so a
33
// level cannot end up spelled differently in two arms, and adding one does not touch this test.
34
// A toolchain without the per-file pragma expands to nothing and keeps its own level - speed only,
35
// never behaviour.
36
#if defined(__GNUC__) && !defined(__clang__)
37
#define PC_TU_PRAGMA(directive) _Pragma(#directive)
38
#else
39
#define PC_TU_PRAGMA(directive)
40
#endif
41
42
/** @brief Build this file at optimization level 2, overriding the framework's size-optimized level. */
43
#define PC_OPTIMIZE_O2 PC_TU_PRAGMA(GCC optimize("O2"))
44
45
#endif
// PROTOCORE_SPEED_OPT_H
src
shared_primitives
speed_opt.h
Generated by
1.9.8