[AMDGPU][AsmParser][NFC] Translate parsed MIMG instructions to MCInsts automatically.
[llvm-project.git] / lldb / unittests / Instruction / ARM64 / TestAArch64Emulator.cpp
blob4506c200dee3b74b6e5ee94ebe30c781cb26291a
1 //===-- TestAArch64Emulator.cpp ------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
10 #include "gtest/gtest.h"
12 #include "lldb/Core/Address.h"
13 #include "lldb/Core/Disassembler.h"
14 #include "lldb/Target/ExecutionContext.h"
15 #include "lldb/Utility/ArchSpec.h"
17 #include "Plugins/Instruction/ARM64/EmulateInstructionARM64.h"
19 using namespace lldb;
20 using namespace lldb_private;
22 struct Arch64EmulatorTester : public EmulateInstructionARM64 {
23 Arch64EmulatorTester()
24 : EmulateInstructionARM64(ArchSpec("arm64-apple-ios")) {}
26 static uint64_t AddWithCarry(uint32_t N, uint64_t x, uint64_t y, bool carry_in,
27 EmulateInstructionARM64::ProcState &proc_state) {
28 return EmulateInstructionARM64::AddWithCarry(N, x, y, carry_in, proc_state);
32 class TestAArch64Emulator : public testing::Test {
33 public:
34 static void SetUpTestCase();
35 static void TearDownTestCase();
37 protected:
40 void TestAArch64Emulator::SetUpTestCase() {
41 EmulateInstructionARM64::Initialize();
44 void TestAArch64Emulator::TearDownTestCase() {
45 EmulateInstructionARM64::Terminate();
48 TEST_F(TestAArch64Emulator, TestOverflow) {
49 EmulateInstructionARM64::ProcState pstate;
50 memset(&pstate, 0, sizeof(pstate));
51 uint64_t ll_max = std::numeric_limits<int64_t>::max();
52 Arch64EmulatorTester emu;
53 ASSERT_EQ(emu.AddWithCarry(64, ll_max, 0, 0, pstate), ll_max);
54 ASSERT_EQ(pstate.V, 0ULL);
55 ASSERT_EQ(pstate.C, 0ULL);
56 ASSERT_EQ(emu.AddWithCarry(64, ll_max, 1, 0, pstate), (uint64_t)(ll_max + 1));
57 ASSERT_EQ(pstate.V, 1ULL);
58 ASSERT_EQ(pstate.C, 0ULL);
59 ASSERT_EQ(emu.AddWithCarry(64, ll_max, 0, 1, pstate), (uint64_t)(ll_max + 1));
60 ASSERT_EQ(pstate.V, 1ULL);
61 ASSERT_EQ(pstate.C, 0ULL);