mini-llvm
0.1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
ASHR.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 <concepts>
8
#include <optional>
9
#include <type_traits>
10
11
namespace
mini_llvm::ops
{
12
13
struct
ASHR
{
14
template
<
typename
Tx,
typename
Ty>
15
requires
std::integral<Tx> && std::integral<Ty>
16
std::optional<Tx>
operator()
(Tx x, Ty y)
const
noexcept
{
17
std::make_unsigned_t<Ty> uy = std::bit_cast<std::make_unsigned_t<Ty>>(y);
18
if
(uy >=
static_cast<
std::make_unsigned_t<Ty>
>
(
sizeof
(Tx) * CHAR_BIT))
19
return
std::nullopt;
20
return
21
std::bit_cast<Tx>(
22
static_cast<
std::make_signed_t<Tx>
>
(
23
std::bit_cast<std::make_signed_t<Tx>>(x) >> uy));
24
}
25
26
template
<
typename
Ty>
27
requires
std::integral<Ty>
28
std::optional<bool>
operator()
(
bool
x, Ty y)
const
noexcept
{
29
if
(y != 0)
30
return
std::nullopt;
31
return
x;
32
}
33
};
34
35
}
// namespace mini_llvm::ops
mini_llvm::ops
Definition
Add.h:9
mini_llvm::ops::ASHR
Definition
ASHR.h:13
mini_llvm::ops::ASHR::operator()
std::optional< bool > operator()(bool x, Ty y) const noexcept
Definition
ASHR.h:28
mini_llvm::ops::ASHR::operator()
std::optional< Tx > operator()(Tx x, Ty y) const noexcept
Definition
ASHR.h:16
include
mini-llvm
common
ops
ASHR.h
Generated by
1.17.0