AsmGrader 0.0.0
Loading...
Searching...
No Matches
os.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <libassert/assert.hpp>
6
7#include <bit>
8
9namespace asmgrader {
10
11// NOLINTNEXTLINE(readability-identifier-naming)
13
14#if defined(__aarch64__)
15#define ASMGRADER_AARCH64
16constexpr auto SYSTEM_PROCESSOR = ProcessorKind::Aarch64;
17#elif defined(__x86_64__)
18#define ASMGRADER_X86_64
19constexpr auto SYSTEM_PROCESSOR = ProcessorKind::x86_64;
20#else
21#error "Unsupported system architecture!"
22#endif
23
24consteval bool is_little_endian() {
25 struct S
26 {
27 u8 msb;
28 u8 lsb;
29 };
30
31 static_assert(sizeof(S) == 2, "Strange, unsupported system. struct { u8; u8; } is not packed as 2 bytes.");
32
33 u16 one = 0x00'01;
34
35 auto check = std::bit_cast<S>(one);
36
37 if (check.msb == 1 && check.lsb == 0) {
38 return true;
39 }
40 if (check.msb == 0 && check.lsb == 1) {
41 return false;
42 }
43
44 UNREACHABLE("Unsupported system endianness!");
45}
46
47enum class EndiannessKind { Little = 0, Big = 1, Native = (is_little_endian() ? Little : Big) };
48
49} // namespace asmgrader
Definition asm_buffer.hpp:20
consteval bool is_little_endian()
Definition os.hpp:24
EndiannessKind
Definition os.hpp:47
ProcessorKind
Definition os.hpp:12