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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [tests/] [instructions/] [TestCmp.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 <sstream>
19
#include <vector>
20
#include <gtest/gtest.h>
21
 
22
#include "EmulateFixture.h"
23
#include "Flags.h"
24
#include "Arithmetic.h"
25
 
26
static const std::vector<struct ArithmeticTest<uint8_t>> cmp8_tests = {
27
    {0, 0, 0, PF | ZF, false}, {0, 1, 0, PF | SF | CF | AF, false},
28
        {3, 2, 3, 0, false}, {0xff, 0xff, 0xff, PF | ZF, false},
29
        {0, 0xff, 0, CF | AF, false},
30
};
31
 
32
static const std::vector<struct ArithmeticTest<uint16_t>> cmp16_tests = {
33
    {0, 0, 0, PF | ZF, false}, {0, 1, 0, PF | SF | CF | AF, false},
34
        {3, 2, 3, 0, false}, {0xffff, 0xffff, 0xffff, PF | ZF, false},
35
        {0, 0xffff, 0, CF | AF, false},
36
};
37
 
38
INSTANTIATE_TEST_CASE_P(Cmp,
39
                        ArithmeticRegReg8Test,
40
                        ::testing::Values(
41
                            // cmp al, bl
42
                            Arith8Params({0x38, 0xd8}, cmp8_tests)));
43
 
44
INSTANTIATE_TEST_CASE_P(Cmp,
45
                        ArithmeticMemReg8Test,
46
                        ::testing::Values(
47
                            // cmp [bx], al
48
                            Arith8Params({0x38, 0x07}, cmp8_tests)));
49
 
50
INSTANTIATE_TEST_CASE_P(Cmp,
51
                        ArithmeticRegReg8TestReversedNoResult,
52
                        ::testing::Values(
53
                            // cmp bl, al
54
                            Arith8Params({0x3a, 0xd8}, cmp8_tests)));
55
 
56
INSTANTIATE_TEST_CASE_P(Cmp,
57
                        ArithmeticMemReg8TestReversedNoResult,
58
                        ::testing::Values(
59
                            // cmp al, [bx]
60
                            Arith8Params({0x3a, 0x07}, cmp8_tests)));
61
 
62
INSTANTIATE_TEST_CASE_P(Cmp,
63
                        ArithmeticRegReg16Test,
64
                        ::testing::Values(
65
                            // cmp ax, bx
66
                            Arith16Params({0x39, 0xd8}, cmp16_tests)));
67
 
68
INSTANTIATE_TEST_CASE_P(Cmp,
69
                        ArithmeticRegMem16Test,
70
                        ::testing::Values(
71
                            // adc [bx], ax
72
                            Arith16Params({0x39, 0x07}, cmp16_tests)));
73
 
74
INSTANTIATE_TEST_CASE_P(Cmp,
75
                        ArithmeticRegReg16TestReversedNoResult,
76
                        ::testing::Values(
77
                            // cmp bx, ax
78
                            Arith16Params({0x3b, 0xd8}, cmp16_tests)));
79
 
80
INSTANTIATE_TEST_CASE_P(Cmp,
81
                        ArithmeticMemReg16TestReversedNoResult,
82
                        ::testing::Values(
83
                            // cmp ax, bx
84
                            Arith16Params({0x3b, 0x07}, cmp16_tests)));
85
 
86
// Immediates
87
 
88
INSTANTIATE_TEST_CASE_P(
89
    Cmp,
90
    ArithmeticRegImmed8Test,
91
    ::testing::Values(
92
        // cmp bl, 1
93
        ArithImmed8Params(std::vector<uint8_t>{0x80, 0xfb, 0x01},
94
                          {2, 2, 0, false}),
95
        ArithImmed8Params(std::vector<uint8_t>{0x82, 0xfb, 0x01},
96
                          {2, 2, 0, false})));
97
 
98
INSTANTIATE_TEST_CASE_P(
99
    Cmp,
100
    ArithmeticMemImmed8Test,
101
    ::testing::Values(
102
        // cmp byte [bx], 1
103
        ArithImmed8Params(std::vector<uint8_t>{0x80, 0x3f, 0x01},
104
                          {2, 2, 0, false}),
105
        ArithImmed8Params(std::vector<uint8_t>{0x82, 0x3f, 0x01},
106
                          {2, 2, 0, false})));
107
 
108
INSTANTIATE_TEST_CASE_P(Cmp,
109
                        ArithmeticRegImmed16Test,
110
                        ::testing::Values(
111
                            // cmp bx, 1
112
                            ArithImmed16Params(std::vector<uint8_t>{0x81, 0xfb,
113
                                                                    0x01, 0x0},
114
                                               {2, 2, 0, false})));
115
 
116
INSTANTIATE_TEST_CASE_P(Cmp,
117
                        ArithmeticMemImmed16Test,
118
                        ::testing::Values(
119
                            // cmp word [bx], 1
120
                            ArithImmed16Params(std::vector<uint8_t>{0x81, 0x3f,
121
                                                                    0x01, 0x00},
122
                                               {2, 2, 0, false})));
123
 
124
INSTANTIATE_TEST_CASE_P(
125
    Cmp,
126
    ArithmeticRegImmed16TestExtend,
127
    ::testing::Values(
128
        // cmp bx, -1
129
        ArithImmed16Params(std::vector<uint8_t>{0x83, 0xfb, 0xff},
130
                           {1, 1, CF | AF, false}),
131
        // cmp bx, 1
132
        ArithImmed16Params(std::vector<uint8_t>{0x83, 0xfb, 0x01},
133
                           {2, 2, 0, false})));
134
 
135
INSTANTIATE_TEST_CASE_P(
136
    Cmp,
137
    ArithmeticMemImmed16TestExtend,
138
    ::testing::Values(
139
        // cmp word [bx], -1
140
        ArithImmed16Params(std::vector<uint8_t>{0x83, 0x3f, 0xff},
141
                           {1, 1, CF | AF, false}),
142
        // cmp word [bx], 1
143
        ArithImmed16Params(std::vector<uint8_t>{0x83, 0x3f, 0x01},
144
                           {2, 2, 0, false})));
145
 
146
INSTANTIATE_TEST_CASE_P(Cmp,
147
                        ArithmeticAlImmedTest,
148
                        ::testing::Values(
149
                            // cmp al, 1
150
                            ArithImmed8Params(std::vector<uint8_t>{0x3c, 0x01},
151
                                              {2, 2, 0, false})));
152
 
153
INSTANTIATE_TEST_CASE_P(Cmp,
154
                        ArithmeticAxImmedTest,
155
                        ::testing::Values(
156
                            // cmp ax, 1
157
                            ArithImmed16Params(std::vector<uint8_t>{0x3d, 0x01,
158
                                                                    0x0},
159
                                               {2, 2, 0, false})));

powered by: WebSVN 2.1.0

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