OpenCores
URL https://opencores.org/ocsvn/s80186/s80186/trunk

Subversion Repositories s80186

[/] [s80186/] [trunk/] [tests/] [instructions/] [Shift.cpp] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jamieiles
// Copyright Jamie Iles, 2017
2
//
3
// This file is part of s80x86.
4
//
5
// s80x86 is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// s80x86 is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with s80x86.  If not, see <http://www.gnu.org/licenses/>.
17
 
18
#include "Shift.h"
19
#include "EmulateFixture.h"
20
#include "Flags.h"
21
 
22
TEST_P(ShiftReg8Test, ResultAndFlags)
23
{
24
    for (auto &t : GetParam().second) {
25
        reset();
26
 
27
        write_flags(t.flags);
28
        write_reg(CL, t.shift_count);
29
        SCOPED_TRACE("SHIFT " + std::to_string(static_cast<int>(t.val)) +
30
                     " << " + std::to_string(static_cast<int>(t.shift_count)) +
31
                     ((t.flags & CF) ? " + CF" : ""));
32
        write_reg(AL, t.val);
33
        set_instruction(GetParam().first);
34
 
35
        emulate();
36
 
37
        ASSERT_EQ(read_reg(AL), t.expected);
38
        ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
39
                            FLAGS_STUCK_BITS | t.expected_flags);
40
    }
41
}
42
 
43
TEST_P(ShiftMem8Test, ResultAndFlags)
44
{
45
    for (auto &t : GetParam().second) {
46
        reset();
47
 
48
        write_flags(t.flags);
49
        write_reg(CL, t.shift_count);
50
        SCOPED_TRACE("SHIFT " + std::to_string(static_cast<int>(t.val)) +
51
                     " << " + std::to_string(static_cast<int>(t.shift_count)) +
52
                     ((t.flags & CF) ? " + CF" : ""));
53
        write_reg(BX, 0x100);
54
        write_mem8(0x100, t.val);
55
        set_instruction(GetParam().first);
56
 
57
        emulate();
58
 
59
        ASSERT_EQ(read_mem8(0x100), t.expected);
60
        ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
61
                            FLAGS_STUCK_BITS | t.expected_flags);
62
    }
63
}
64
 
65
TEST_P(ShiftRegImm8Test, ResultAndFlags)
66
{
67
    for (auto &t : GetParam().second) {
68
        reset();
69
 
70
        write_flags(t.flags);
71
        SCOPED_TRACE("SHIFT " + std::to_string(static_cast<int>(t.val)) +
72
                     " << " + std::to_string(static_cast<int>(t.shift_count)) +
73
                     ((t.flags & CF) ? " + CF" : ""));
74
        write_reg(AL, t.val);
75
        auto instr = GetParam().first;
76
        instr.push_back(static_cast<uint8_t>(t.shift_count));
77
        set_instruction(instr);
78
 
79
        emulate();
80
 
81
        ASSERT_EQ(read_reg(AL), t.expected);
82
        ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
83
                            FLAGS_STUCK_BITS | t.expected_flags);
84
    }
85
}
86
 
87
TEST_P(ShiftMemImm8Test, ResultAndFlags)
88
{
89
    for (auto &t : GetParam().second) {
90
        reset();
91
 
92
        write_flags(t.flags);
93
        SCOPED_TRACE("SHIFT " + std::to_string(static_cast<int>(t.val)) +
94
                     " << " + std::to_string(static_cast<int>(t.shift_count)) +
95
                     ((t.flags & CF) ? " + CF" : ""));
96
        write_reg(BX, 0x100);
97
        write_mem8(0x100, t.val);
98
        auto instr = GetParam().first;
99
        instr.push_back(static_cast<uint8_t>(t.shift_count));
100
        set_instruction(instr);
101
 
102
        emulate();
103
 
104
        ASSERT_EQ(read_mem8(0x100), t.expected);
105
        ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
106
                            FLAGS_STUCK_BITS | t.expected_flags);
107
    }
108
}
109
 
110
TEST_P(ShiftReg16Test, ResultAndFlags)
111
{
112
    // shl ax, COUNT
113
    for (auto &t : GetParam().second) {
114
        reset();
115
 
116
        write_flags(t.flags);
117
        write_reg(CL, t.shift_count);
118
        SCOPED_TRACE("SHIFT " + std::to_string(static_cast<int>(t.val)) +
119
                     " << " + std::to_string(static_cast<int>(t.shift_count)) +
120
                     ((t.flags & CF) ? " + CF" : ""));
121
        write_reg(AX, t.val);
122
        set_instruction(GetParam().first);
123
 
124
        emulate();
125
 
126
        ASSERT_EQ(read_reg(AX), t.expected);
127
        ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
128
                            FLAGS_STUCK_BITS | t.expected_flags);
129
    }
130
}
131
 
132
TEST_P(ShiftMem16Test, ResultAndFlags)
133
{
134
    for (auto &t : GetParam().second) {
135
        reset();
136
 
137
        write_flags(t.flags);
138
        write_reg(CL, t.shift_count);
139
        SCOPED_TRACE("SHIFT " + std::to_string(static_cast<int>(t.val)) +
140
                     " << " + std::to_string(static_cast<int>(t.shift_count)) +
141
                     ((t.flags & CF) ? " + CF" : ""));
142
        write_reg(BX, 0x100);
143
        write_mem16(0x100, t.val);
144
        set_instruction(GetParam().first);
145
 
146
        emulate();
147
 
148
        ASSERT_EQ(read_mem16(0x100), t.expected);
149
        ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
150
                            FLAGS_STUCK_BITS | t.expected_flags);
151
    }
152
}
153
 
154
TEST_P(ShiftRegImm16Test, ResultAndFlags)
155
{
156
    for (auto &t : GetParam().second) {
157
        reset();
158
 
159
        write_flags(t.flags);
160
        SCOPED_TRACE("SHIFT " + std::to_string(static_cast<int>(t.val)) +
161
                     " << " + std::to_string(static_cast<int>(t.shift_count)) +
162
                     ((t.flags & CF) ? " + CF" : ""));
163
        write_reg(AX, t.val);
164
        auto instr = GetParam().first;
165
        instr.push_back(t.shift_count & 0xff);
166
        set_instruction(instr);
167
 
168
        emulate();
169
 
170
        ASSERT_EQ(read_reg(AX), t.expected);
171
        ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
172
                            FLAGS_STUCK_BITS | t.expected_flags);
173
    }
174
}
175
 
176
TEST_P(ShiftMemImm16Test, ResultAndFlags)
177
{
178
    for (auto &t : GetParam().second) {
179
        reset();
180
 
181
        write_flags(t.flags);
182
        SCOPED_TRACE("SHIFT " + std::to_string(static_cast<int>(t.val)) +
183
                     " << " + std::to_string(static_cast<int>(t.shift_count)) +
184
                     ((t.flags & CF) ? " + CF" : ""));
185
        write_reg(BX, 0x100);
186
        write_mem16(0x100, t.val);
187
        auto instr = GetParam().first;
188
        instr.push_back(t.shift_count & 0xff);
189
        set_instruction(instr);
190
 
191
        emulate();
192
 
193
        ASSERT_EQ(read_mem16(0x100), t.expected);
194
        ASSERT_PRED_FORMAT2(AssertFlagsEqual, read_flags(),
195
                            FLAGS_STUCK_BITS | t.expected_flags);
196
    }
197
}
198
 
199
// Shifting the count is an odd thing to do, but we should shift the initial
200
// value even though it is decremented on each iteration.
201
TEST_P(ShiftCLTest, ShiftCL)
202
{
203
    write_reg(CL, GetParam().count);
204
    set_instruction(GetParam().instruction);
205
 
206
    emulate();
207
 
208
    ASSERT_EQ(GetParam().expected, read_reg(CL));
209
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.