Iros
 
Loading...
Searching...
No Matches
black_box.h
Go to the documentation of this file.
1#pragma once
2
4#include "di/util/addressof.h"
5
6namespace di::util {
7template<concepts::CopyConstructible T>
8[[gnu::noinline]] auto black_box(T const& value) -> T {
9 // We want to produce an identical value from this function, without the compiler realizing it.
10 // This is done by passing a pointer through inline assembly, since the compiler won't realize
11 // the pointer points to the original object.
12 T const* result;
13 asm volatile("mov %1, %0\n" : "=r"(result) : "r"(util::addressof(value)) : "memory");
14 return *result;
15}
16}
17
18namespace di {
19using util::black_box;
20}
Definition vocab.h:96
auto black_box(T const &value) -> T
Definition black_box.h:8
Definition zstring_parser.h:9