mini-llvm 0.1.0
Loading...
Searching...
No Matches
LSHR.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
11namespace mini_llvm::ops {
12
13struct LSHR {
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_unsigned_t<Tx>>(
23 std::bit_cast<std::make_unsigned_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
Definition Add.h:9
Definition LSHR.h:13
std::optional< Tx > operator()(Tx x, Ty y) const noexcept
Definition LSHR.h:16
std::optional< bool > operator()(bool x, Ty y) const noexcept
Definition LSHR.h:28