cpprisc16  March 16, 2017
 All Namespaces Files Functions Variables Typedefs Macros
cppis1.hpp
Go to the documentation of this file.
1 /* -*- coding: latin-1 -*- */
2 
3 /** \file cpprisc16/cppis1.hpp (March 15, 2017)
4  * \brief Additional Instructions Set 1 IS[1]:
5  * 8 new instructions is1_* and 1 instruction modified is1_add.
6  *
7  * Piece of cpprisc16.
8  * https://bitbucket.org/OPiMedia/cpprisc16
9  *
10  * GPLv3 --- Copyright (C) 2017 Olivier Pirson
11  * http://www.opimedia.be/
12  */
13 
14 #ifndef CPPRISC16_CPPRISC16_CPPIS1_HPP_
15 #define CPPRISC16_CPPRISC16_CPPIS1_HPP_
16 
17 #include "cpprisc16.hpp"
18 
19 
20 
21 /* *******************************
22  * Macros for IS[1] instructions *
23  *********************************/
24 
25 /** \brief (Add Branch if Overflow)
26  * R[result] <-- R[a] + R[b]
27  * and if overflow
28  * then jump to label.
29  *
30  * Count for 1 instruction.
31  */
32 #define is1_add_bo(result, a, b, label) { \
33  assert(a < cpprisc16::nb_registers); \
34  assert(b < cpprisc16::nb_registers); \
35  \
36  if (is1_add(result, a, b)) { goto label; } \
37  }
38 
39 
40 /** \brief (Branch if Greater)
41  * If R[a] > R[b]
42  * then jump to label.
43  *
44  * Count for 1 instruction.
45  */
46 #define is1_bg(a, b, label) { \
47  assert(a < cpprisc16::nb_registers); \
48  assert(b < cpprisc16::nb_registers); \
49  \
50  ++cpprisc16::nb_executed; \
51  if (cpprisc16::registers[a] > cpprisc16::registers[b]) { goto label; } \
52  }
53 
54 
55 /** \brief (Branch if Lower)
56  * If R[a] < R[b]
57  * then jump to label.
58  *
59  * Count for 1 instruction.
60  */
61 #define is1_bl(a, b, label) { \
62  assert(a < cpprisc16::nb_registers); \
63  assert(b < cpprisc16::nb_registers); \
64  \
65  ++cpprisc16::nb_executed; \
66  if (cpprisc16::registers[a] < cpprisc16::registers[b]) { goto label; } \
67  }
68 
69 
70 /** \brief (SHift Arithmetic)
71  * R[result] <-- (R[a] << R[b]) or (R[a] >> -R[b])
72  *
73  * If R[b] >= 0
74  * then shift to the left,
75  * else shift to the right with *duplication of the sign bit*.
76  *
77  * And if overflow
78  * then jump to label.
79  *
80  * Count for 1 instruction.
81  *
82  * @return true iff overflow
83  */
84 #define is1_sha_bo(result, a, b, label) { \
85  assert(a < cpprisc16::nb_registers); \
86  assert(b < cpprisc16::nb_registers); \
87  \
88  if (is1_sha(result, a, b)) { goto label; } \
89  }
90 
91 
92 /** \brief (SHift Logic if Overflow)
93  * R[result] <-- (R[a] << R[b]) or (R[a] >> -R[b])
94  *
95  * If R[b] >= 0
96  * then shift to the left,
97  * else shift to the right.
98  *
99  * And if overflow
100  * then jump to label.
101  *
102  * Count for 1 instruction.
103  */
104 #define is1_shl_bo(result, a, b, label) { \
105  assert(a < cpprisc16::nb_registers); \
106  assert(b < cpprisc16::nb_registers); \
107  \
108  if (is1_shl(result, a, b)) { goto label; } \
109  }
110 
111 
112 /** \brief (Sub Branch if Overflow)
113  * R[result] <-- R[a] - R[b]
114  * and if overflow
115  * then jump to label.
116  *
117  * Count for 1 instruction.
118  */
119 #define is1_sub_bo(result, a, b, label) { \
120  assert(a < cpprisc16::nb_registers); \
121  assert(b < cpprisc16::nb_registers); \
122  \
123  if (is1_sub(result, a, b)) { goto label; } \
124  }
125 
126 
127 
128 namespace cpprisc16 {
129 
130  /* ***********************************
131  * Prototypes for IS[1] instructions *
132  *************************************/
133  /** \brief
134  * R[result] <-- R[a] + R[b]
135  *
136  * See macro is1_add_bo() for jump if overflow.
137  *
138  * Count for 1 instruction.
139  *
140  * @return true iff overflow
141  */
142  bool
143  is1_add(unsigned int result, unsigned int a, unsigned int b);
144 
145 
146  /** \brief
147  * R[result] <-- R[a] NOR R[b] (== ~(a | b))
148  *
149  * Count for 1 instruction.
150  */
151  void
152  is1_nor(unsigned int result, unsigned int a, unsigned int b);
153 
154 
155  /** \brief (SHift Arithmetic)
156  * R[result] <-- (R[a] << R[b]) or (R[a] >> -R[b])
157  *
158  * If R[b] >= 0
159  * then shift to the left,
160  * else shift to the right with *duplication of the sign bit*.
161  *
162  * See macro is1_sha_bo() for jump if overflow.
163  *
164  * Count for 1 instruction.
165  *
166  * @return true iff overflow
167  */
168  bool
169  is1_sha(unsigned int result, unsigned int a, unsigned int b);
170 
171 
172  /** \brief (Shift Immediate)
173  * R[result] <-- (R[a] << immed5) or (R[a] >> -immed5)
174  *
175  * 6 5 43210
176  * immed7 is decomposed in x:M:immed5
177  * where: x is 1 bit unused
178  * M is 1 bit: 0 for logic mode, 1 for arithmetic mode
179  * immed5 is 5 signed bits
180  *
181  * If immed5 >= 0
182  * then shift to the left,
183  * else shift to the right
184  * (with *duplication of the sign bit* if arithmetic mode).
185  *
186  * Count for 1 instruction.
187  */
188  void
189  is1_shifti(unsigned int result, unsigned int a, immed_t immed7);
190 
191 
192  /** \brief (SHift Logic)
193  * R[result] <-- (R[a] << R[b]) or (R[a] >> -R[b])
194  *
195  * If R[b] >= 0
196  * then shift to the left,
197  * else shift to the right.
198  *
199  * See macro is1_shl_bo() for jump if overflow.
200  *
201  * Count for 1 instruction.
202  *
203  * @return true iff overflow
204  */
205  bool
206  is1_shl(unsigned int result, unsigned int a, unsigned int b);
207 
208 
209  /** \brief
210  * R[result] <-- R[a] - R[b]
211  *
212  * See macro is1_sub_bo() for jump if overflow.
213  *
214  * Count for 1 instruction.
215  *
216  * @return true iff overflow
217  */
218  bool
219  is1_sub(unsigned int result, unsigned int a, unsigned int b);
220 
221 
222  /** \brief
223  * R[result] <-- R[a] XOR R[b] (== ~(a ^ b))
224  *
225  * Count for 1 instruction.
226  */
227  void
228  is1_xor(unsigned int result, unsigned int a, unsigned int b);
229 
230 } // namespace cpprisc16
231 
232 
233 #endif // CPPRISC16_CPPRISC16_CPPIS1_HPP_
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
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
std::uint16_t immed_t
Type for immediate value.
Definition: cpprisc16.hpp:48
Instructions set of RiSC16: 8 instructions i_* and 4 pseudo-instructions p_*.
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 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