ProtoCore
v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
speed_opt.h
Go to the documentation of this file.
1
// ProtoCore v1.0.16 - 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 PROTOCORE_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 defined here (see docs/FEATURE_PERFORMANCE.md 2b). A file that needs another
18
* level adds the macro for it here rather than redefining this one.
19
*
20
* Apply only where there are no secrets or the code is constant-time by structure. An optimizer can
21
* turn a branchless mask-select into a data-dependent branch; the OPT each crypto module states in its CMakeLists is
22
* the crypto policy layer with per-die levels and those caveats.
23
*
24
* @author Douglas Quigg (dstroy0)
25
* @date 2026
26
*/
27
28
#ifndef PROTOCORE_SPEED_OPT_H
29
#define PROTOCORE_SPEED_OPT_H
30
31
// The capability is branched on ONCE, here. Each level below is then defined exactly once, so a
32
// level cannot end up spelled differently in two arms, and adding one does not touch this test.
33
// A toolchain without the per-file pragma expands to nothing and keeps its own level - speed only,
34
// never behaviour.
35
#if defined(__GNUC__) && !defined(__clang__)
36
#define PROTOCORE_TU_PRAGMA(directive) _Pragma(#directive)
37
#else
38
#define PROTOCORE_TU_PRAGMA(directive)
39
#endif
40
41
/** @brief Build this file at optimization level 2, overriding the framework's size-optimized level. */
42
#define PROTOCORE_OPTIMIZE_O2 PROTOCORE_TU_PRAGMA(GCC optimize("O2"))
43
44
#endif
// PROTOCORE_SPEED_OPT_H
src
shared
speed_opt
speed_opt.h
Generated by
1.9.8