1 | //===-- RegisterContextTest.cpp -------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "gtest/gtest.h" |
10 | |
11 | #include "Plugins/Process/Utility/RegisterContext_x86.h" |
12 | |
13 | #include "llvm/ADT/STLExtras.h" |
14 | #include "llvm/Support/FormatVariadic.h" |
15 | |
16 | #include <array> |
17 | |
18 | using namespace lldb_private; |
19 | |
20 | struct TagWordTestVector { |
21 | uint16_t sw; |
22 | uint16_t tw; |
23 | uint8_t tw_abridged; |
24 | int st_reg_num; |
25 | }; |
26 | |
27 | constexpr MMSReg st_from_comp(uint64_t mantissa, uint16_t sign_exp) { |
28 | MMSReg ret = {}; |
29 | ret.comp.mantissa = mantissa; |
30 | ret.comp.sign_exp = sign_exp; |
31 | return ret; |
32 | } |
33 | |
34 | const std::array<MMSReg, 8> st_regs = { |
35 | st_from_comp(mantissa: 0x8000000000000000, sign_exp: 0x4000), // +2.0 |
36 | st_from_comp(mantissa: 0x3f00000000000000, sign_exp: 0x0000), // 1.654785e-4932 |
37 | st_from_comp(mantissa: 0x0000000000000000, sign_exp: 0x0000), // +0 |
38 | st_from_comp(mantissa: 0x0000000000000000, sign_exp: 0x8000), // -0 |
39 | st_from_comp(mantissa: 0x8000000000000000, sign_exp: 0x7fff), // +inf |
40 | st_from_comp(mantissa: 0x8000000000000000, sign_exp: 0xffff), // -inf |
41 | st_from_comp(mantissa: 0xc000000000000000, sign_exp: 0xffff), // nan |
42 | st_from_comp(mantissa: 0x8000000000000000, sign_exp: 0xc000), // -2.0 |
43 | }; |
44 | |
45 | const std::array<TagWordTestVector, 8> tag_word_test_vectors{ |
46 | TagWordTestVector{.sw: 0x3800, .tw: 0x3fff, .tw_abridged: 0x80, .st_reg_num: 1}, |
47 | TagWordTestVector{.sw: 0x3000, .tw: 0x2fff, .tw_abridged: 0xc0, .st_reg_num: 2}, |
48 | TagWordTestVector{.sw: 0x2800, .tw: 0x27ff, .tw_abridged: 0xe0, .st_reg_num: 3}, |
49 | TagWordTestVector{.sw: 0x2000, .tw: 0x25ff, .tw_abridged: 0xf0, .st_reg_num: 4}, |
50 | TagWordTestVector{.sw: 0x1800, .tw: 0x25bf, .tw_abridged: 0xf8, .st_reg_num: 5}, |
51 | TagWordTestVector{.sw: 0x1000, .tw: 0x25af, .tw_abridged: 0xfc, .st_reg_num: 6}, |
52 | TagWordTestVector{.sw: 0x0800, .tw: 0x25ab, .tw_abridged: 0xfe, .st_reg_num: 7}, |
53 | TagWordTestVector{.sw: 0x0000, .tw: 0x25a8, .tw_abridged: 0xff, .st_reg_num: 8}, |
54 | }; |
55 | |
56 | TEST(RegisterContext_x86Test, AbridgedToFullTagWord) { |
57 | for (const auto &x : llvm::enumerate(First: tag_word_test_vectors)) { |
58 | SCOPED_TRACE(llvm::formatv("tag_word_test_vectors[{0}]" , x.index())); |
59 | std::array<MMSReg, 8> test_regs; |
60 | for (int i = 0; i < x.value().st_reg_num; ++i) |
61 | test_regs[i] = st_regs[x.value().st_reg_num - i - 1]; |
62 | EXPECT_EQ( |
63 | AbridgedToFullTagWord(x.value().tw_abridged, x.value().sw, test_regs), |
64 | x.value().tw); |
65 | } |
66 | } |
67 | |
68 | TEST(RegisterContext_x86Test, FullToAbridgedTagWord) { |
69 | for (const auto &x : llvm::enumerate(First: tag_word_test_vectors)) { |
70 | SCOPED_TRACE(llvm::formatv("tag_word_test_vectors[{0}]" , x.index())); |
71 | EXPECT_EQ(FullToAbridgedTagWord(x.value().tw), x.value().tw_abridged); |
72 | } |
73 | } |
74 | |