cpprisc16  June 16, 2020
cppis2.cpp
Go to the documentation of this file.
1 /* -*- coding: latin-1 -*- */
2 
3 /** \file cpprisc16/cppis2.cpp (March 14, 2017)
4  * \brief Additional Instructions Set 2 IS[2].
5  *
6  * Piece of cpprisc16.
7  * https://bitbucket.org/OPiMedia/cpprisc16
8  *
9  * GPLv3 --- Copyright (C) 2017 Olivier Pirson
10  * http://www.opimedia.be/
11  */
12 
13 #include "cppis2.hpp"
14 
15 #include "cppis1.hpp"
16 
17 
18 namespace cpprisc16 {
19 
20  /* **********************************
21  * Functions for IS[2] instructions *
22  ************************************/
23  bool
24  is2_add(unsigned int result, unsigned int a, unsigned int b) {
25  assert(result < nb_registers);
26  assert(a < nb_registers);
27  assert(b < nb_registers);
28 
29  return is1_add(result, a, b);
30  }
31 
32 
33  void
34  is2_mul(unsigned int result, unsigned int a, unsigned int b) {
35  assert(0 < result);
36  assert(result < nb_registers);
37 
38  assert(a < nb_registers);
39  assert(b < nb_registers);
40 
41  const std::uint32_t prod = (static_cast<std::uint32_t>(registers[a])
42  * static_cast<std::uint32_t>(registers[b]));
43 
44  registers[result - 1] = prod >> 16;
45  registers[result] = prod;
46  registers[0] = 0;
47 
48  ++nb_executed;
49  }
50 
51 
52  void
53  is2_nor(unsigned int result, unsigned int a, unsigned int b) {
54  assert(result < nb_registers);
55  assert(a < nb_registers);
56  assert(b < nb_registers);
57 
58  is1_nor(result, a, b);
59  }
60 
61 
62  bool
63  is2_sha(unsigned int result, unsigned int a, unsigned int b) {
64  assert(result < nb_registers);
65  assert(a < nb_registers);
66  assert(b < nb_registers);
67 
68  return is1_sha(result, a, b);
69  }
70 
71 
72  bool
73  is2_shl(unsigned int result, unsigned int a, unsigned int b) {
74  assert(result < nb_registers);
75  assert(a < nb_registers);
76  assert(b < nb_registers);
77 
78  return is1_shl(result, a, b);
79  }
80 
81 
82  void
83  is2_shifti(unsigned int result, unsigned int a, immed_t immed7) {
84  assert(result < nb_registers);
85  assert(a < nb_registers);
86  assert(immed7 <= 0x7F);
87 
88  is1_shifti(result, a, immed7);
89  }
90 
91 
92  bool
93  is2_sub(unsigned int result, unsigned int a, unsigned int b) {
94  assert(result < nb_registers);
95  assert(a < nb_registers);
96  assert(b < nb_registers);
97 
98  return is1_sub(result, a, b);
99  }
100 
101 
102  void
103  is2_xor(unsigned int result, unsigned int a, unsigned int b) {
104  assert(result < nb_registers);
105  assert(a < nb_registers);
106  assert(b < nb_registers);
107 
108  is1_xor(result, a, b);
109  }
110 
111 } // namespace cpprisc16
void is2_xor(unsigned int result, unsigned int a, unsigned int b)
R[result] <– R[a] XOR R[b] (== ~(a ^ b))
Definition: cppis2.cpp:103
bool is2_shl(unsigned int result, unsigned int a, unsigned int b)
(SHift Logic) R[result] <– (R[a] << R[b]) or (R[a] >> -R[b])
Definition: cppis2.cpp:73
bool is1_add(unsigned int result, unsigned int a, unsigned int b)
R[result] <– R[a] + R[b].
Definition: cppis1.cpp:22
void is1_nor(unsigned int result, unsigned int a, unsigned int b)
R[result] <– R[a] NOR R[b] (== ~(a | b))
Definition: cppis1.cpp:42
Additional Instructions Set 1 IS[1]: 8 new instructions is1_* and 1 instruction modified is1_add...
void is2_shifti(unsigned int result, unsigned int a, immed_t immed7)
(Shift Immediate) R[result] <– (R[a] << immed5) or (R[a] >> -immed5)
Definition: cppis2.cpp:83
void is1_xor(unsigned int result, unsigned int a, unsigned int b)
R[result] <– R[a] XOR R[b] (== ~(a ^ b))
Definition: cppis1.cpp:188
bool is1_sub(unsigned int result, unsigned int a, unsigned int b)
R[result] <– R[a] - R[b].
Definition: cppis1.cpp:170
bool is2_sha(unsigned int result, unsigned int a, unsigned int b)
(SHift Arithmetic) R[result] <– (R[a] << R[b]) or (R[a] >> -R[b])
Definition: cppis2.cpp:63
std::uint16_t immed_t
Type for immediate value.
Definition: cpprisc16.hpp:48
word16_t registers[8]
Registers.
Definition: cpprisc16.cpp:43
const unsigned int nb_registers
Number of registers: 8 word16_t items.
Definition: cpprisc16.cpp:28
void is2_mul(unsigned int result, unsigned int a, unsigned int b)
R[result - 1]:R[result] <– R[a]*R[b].
Definition: cppis2.cpp:34
uint64_t nb_executed
Number of instructions executed.
Definition: cpprisc16.cpp:41
bool is1_shl(unsigned int result, unsigned int a, unsigned int b)
(SHift Logic) R[result] <– (R[a] << R[b]) or (R[a] >> -R[b])
Definition: cppis1.cpp:93
bool is2_add(unsigned int result, unsigned int a, unsigned int b)
R[result] <– R[a] + R[b].
Definition: cppis2.cpp:24
Additional Instructions Set 2 IS[2]: 8 new instructions is2_* and 1 instruction modified is2_add...
bool is2_sub(unsigned int result, unsigned int a, unsigned int b)
R[result] <– R[a] - R[b].
Definition: cppis2.cpp:93
void is2_nor(unsigned int result, unsigned int a, unsigned int b)
R[result] <– R[a] NOR R[b] (== ~(a | b))
Definition: cppis2.cpp:53
bool is1_sha(unsigned int result, unsigned int a, unsigned int b)
(SHift Arithmetic) R[result] <– (R[a] << R[b]) or (R[a] >> -R[b])
Definition: cppis1.cpp:55
void is1_shifti(unsigned int result, unsigned int a, immed_t immed7)
(Shift Immediate) R[result] <– (R[a] << immed5) or (R[a] >> -immed5)
Definition: cppis1.cpp:131