Skip to content

Commit bfd3992

Browse files
committed
add 'je' and 'jne' instrs
1 parent 73b9262 commit bfd3992

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

impl.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,20 @@ DEF(loop) {
248248
vmnext;
249249
}
250250

251+
DEF(je) {
252+
if (hasf(RVM_FEQ)) {
253+
pc += imm23s;
254+
util_checkpc();
255+
}
256+
vmnext;
257+
}
258+
259+
DEF(jne) {
260+
if (!hasf(RVM_FEQ)) {
261+
pc += imm23s;
262+
util_checkpc();
263+
}
264+
vmnext;
265+
}
266+
251267
#endif /* impl.h */

opcodes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,7 @@ DEF(swp, 35) /* [I] rgA, rgB = rgB, rgA */
5757
DEF(adr, 36) /* [M] rgA = pc + imm19s */
5858
DEF(jr, 37) /* [M] pc = rgA */
5959
DEF(loop, 38) /* [M] if (rgA-- != 0) pc += imm19s */
60+
DEF(je, 39) /* [J] jump if eq */
61+
DEF(jne, 40) /* [J] jump if not-eq */
6062

6163
#endif /* opcodes.h */

rvm.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ const char *rvm_stropc(int opc)
101101
#define imm23s RVM_SGXTD(fnc & RVM_F23MASK, 23)
102102
#define imm23u RVM_ZRXTD(fnc & RVM_F23MASK, 23)
103103

104+
#define setf(v) (cf |= (v))
105+
#define hasf(v) ((cf & (v)) == (v))
106+
#define clrf() (cf = 0)
107+
104108
/* Saving vm state. */
105109
#if RVM_CFG_COUNT_INSTRS_EXEC
106110
# define __RVM_SAVEICNT() (ctx->inst_cnt = icnt)

0 commit comments

Comments
 (0)