mini-llvm
0.1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
Trunc.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
3
#pragma once
4
5
#include <bit>
6
#include <concepts>
7
#include <cstdlib>
8
#include <type_traits>
9
10
namespace
mini_llvm::ops
{
11
12
template
<
typename
To>
13
requires
std::integral<To>
14
struct
Trunc
{
15
template
<
typename
From>
16
requires
std::integral<From>
17
To
operator()
(From)
const
noexcept
{
18
abort();
19
}
20
21
template
<
typename
From>
22
requires
(std::integral<From> && !std::same_as<From, bool> &&
sizeof
(To) <=
sizeof
(From))
23
To
operator
()(From x)
const
noexcept
{
24
return
25
std::bit_cast<To>(
26
static_cast<
std::make_unsigned_t<To>
>
(
27
std::bit_cast<std::make_unsigned_t<From>>(x)));
28
}
29
};
30
31
template
<>
32
struct
Trunc
<bool> {
33
template
<
typename
From>
34
requires
std::integral<From>
35
bool
operator()
(From x)
const
noexcept
{
36
return
static_cast<
bool
>
(x & 1);
37
}
38
39
bool
operator()
(
bool
x)
const
noexcept
{
40
return
x;
41
}
42
};
43
44
}
// namespace mini_llvm::ops
mini_llvm::ops
Definition
Add.h:9
mini_llvm::ops::Trunc< bool >::operator()
bool operator()(From x) const noexcept
Definition
Trunc.h:35
mini_llvm::ops::Trunc< bool >::operator()
bool operator()(bool x) const noexcept
Definition
Trunc.h:39
mini_llvm::ops::Trunc
Definition
Trunc.h:14
mini_llvm::ops::Trunc::operator()
To operator()(From) const noexcept
Definition
Trunc.h:17
include
mini-llvm
common
ops
Trunc.h
Generated by
1.17.0