mini-llvm
0.1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
SHL.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
3
#pragma once
4
5
#include <bit>
6
#include <climits>
7
#include <cmath>
8
#include <concepts>
9
#include <optional>
10
#include <type_traits>
11
12
namespace
mini_llvm::ops
{
13
14
struct
SHL
{
15
template
<
typename
Tx,
typename
Ty>
16
requires
std::integral<Tx> && std::integral<Ty>
17
std::optional<Tx>
operator()
(Tx x, Ty y)
const
noexcept
{
18
std::make_unsigned_t<Ty> uy = std::bit_cast<std::make_unsigned_t<Ty>>(y);
19
if
(uy >=
static_cast<
std::make_unsigned_t<Ty>
>
(
sizeof
(Tx) * CHAR_BIT))
20
return
std::nullopt;
21
return
static_cast<
Tx
>
(x << uy);
22
}
23
24
template
<
typename
Ty>
25
requires
std::integral<Ty>
26
std::optional<bool>
operator()
(
bool
x, Ty y)
const
noexcept
{
27
if
(y != 0)
28
return
std::nullopt;
29
return
x;
30
}
31
};
32
33
}
// namespace mini_llvm::ops
mini_llvm::ops
Definition
Add.h:9
mini_llvm::ops::SHL
Definition
SHL.h:14
mini_llvm::ops::SHL::operator()
std::optional< Tx > operator()(Tx x, Ty y) const noexcept
Definition
SHL.h:17
mini_llvm::ops::SHL::operator()
std::optional< bool > operator()(bool x, Ty y) const noexcept
Definition
SHL.h:26
include
mini-llvm
common
ops
SHL.h
Generated by
1.17.0