From c29314ad14e912de70a704bf79196827d46ecfa4 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Fri, 2 Nov 2018 23:44:09 -0300 Subject: [PATCH] Add OpShift arithmetic and logical operations --- include/sirit/sirit.h | 14 ++++++++++++++ src/CMakeLists.txt | 1 + src/insts/bit.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 src/insts/bit.cpp diff --git a/include/sirit/sirit.h b/include/sirit/sirit.h index 7d2ae11..6056248 100644 --- a/include/sirit/sirit.h +++ b/include/sirit/sirit.h @@ -248,6 +248,20 @@ class Module { /// Bit pattern-preserving type conversion. Id OpBitcast(Id result_type, Id operand); + // Bit + + /// Shift the bits in Base right by the number of bits specified in Shift. + /// The most-significant bits will be zero filled. + Id OpShiftRightLogical(Id result_type, Id base, Id shift); + + /// Shift the bits in Base right by the number of bits specified in Shift. + /// The most-significant bits will be filled with the sign bit from Base. + Id OpShiftRightArithmetic(Id result_type, Id base, Id shift); + + /// Shift the bits in Base left by the number of bits specified in Shift. + /// The least-significant bits will be zero filled. + Id OpShiftLeftLogical(Id result_type, Id base, Id shift); + private: Id AddCode(std::unique_ptr op); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c7fbfd3..d8e9a79 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,6 +22,7 @@ add_library(sirit insts/misc.cpp insts/logical.cpp insts/conversion.cpp + insts/bit.cpp ) target_include_directories(sirit PUBLIC ../include diff --git a/src/insts/bit.cpp b/src/insts/bit.cpp new file mode 100644 index 0000000..a8bdc7f --- /dev/null +++ b/src/insts/bit.cpp @@ -0,0 +1,38 @@ +/* This file is part of the sirit project. + * Copyright (c) 2018 ReinUsesLisp + * This software may be used and distributed according to the terms of the GNU + * Lesser General Public License version 2.1 or any later version. + */ + +#include "common_types.h" +#include "op.h" +#include "sirit/sirit.h" +#include + +namespace Sirit { + +Id Module::OpShiftRightLogical(Id result_type, Id base, Id shift) { + auto op{std::make_unique(spv::Op::OpShiftRightLogical, bound++, + result_type)}; + op->Add(base); + op->Add(shift); + return AddCode(std::move(op)); +} + +Id Module::OpShiftRightArithmetic(Id result_type, Id base, Id shift) { + auto op{std::make_unique(spv::Op::OpShiftRightArithmetic, bound++, + result_type)}; + op->Add(base); + op->Add(shift); + return AddCode(std::move(op)); +} + +Id Module::OpShiftLeftLogical(Id result_type, Id base, Id shift) { + auto op{std::make_unique(spv::Op::OpShiftLeftLogical, bound++, + result_type)}; + op->Add(base); + op->Add(shift); + return AddCode(std::move(op)); +} + +} // namespace Sirit \ No newline at end of file