mini-llvm 0.1.0
Loading...
Searching...
No Matches
URem.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 <optional>
8#include <type_traits>
9
10namespace mini_llvm::ops {
11
12struct URem {
13 template <typename T>
14 requires std::integral<T>
15 std::optional<T> operator()(T x, T y) const noexcept {
16 if (y == 0)
17 return std::nullopt;
18 return
19 std::bit_cast<T>(
20 static_cast<std::make_unsigned_t<T>>(
21 std::bit_cast<std::make_unsigned_t<T>>(x) % std::bit_cast<std::make_unsigned_t<T>>(y)));
22 }
23
24 std::optional<bool> operator()(bool, bool y) const noexcept {
25 if (y == false)
26 return std::nullopt;
27 return false;
28 }
29};
30
31} // namespace mini_llvm::ops
Definition Add.h:9
Definition URem.h:12
std::optional< bool > operator()(bool, bool y) const noexcept
Definition URem.h:24
std::optional< T > operator()(T x, T y) const noexcept
Definition URem.h:15