Skip to content

Commit e00b57d

Browse files
committed
implement bclr, bclri, bexti
1 parent 7715b8a commit e00b57d

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ amomin.w
5757
amominu.w
5858
amoswap.w
5959
amoxor.w
60-
bclr
61-
bclri
62-
bexti
6360
binv
6461
binvi
6562
brev8
@@ -134,7 +131,10 @@ auipc
134131
amoor.w
135132
beq
136133
beqz
134+
bclr
135+
bclri
137136
bext
137+
bexti
138138
bge
139139
bgeu
140140
bgez

src/riscv/cpu.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ const opcode0x13func3Table: FuncTable<I_Type> = new Map([
325325
} else if (func7 === 0x14) { // bseti (Zbb)
326326
const result = rs1Value | ( 1 << shamt);
327327
registerSet.setRegister(rd, result);
328+
} else if (func7 === 0x24) { // bclri (Zbs)
329+
const result = rs1Value & ~(1 << shamt);
330+
registerSet.setRegister(rd, result);
328331
} else if (immU === 0b011000000001) { // ctz (Zbb)
329332
let tmp = rs1Value >>> 0;
330333
if (tmp === 0) {
@@ -392,6 +395,10 @@ const opcode0x13func3Table: FuncTable<I_Type> = new Map([
392395
const result = rs1Value >> shamt;
393396
registerSet.setRegister(rd, result);
394397

398+
} else if (func7 === 0x24) { // bexti (Zbs)
399+
const result = (rs1Value >>> shamt) & 1;
400+
registerSet.setRegister(rd, result);
401+
395402
} else throw Error(`Unknown instruction, func7: 0x${func7.toString(16)}`);
396403
}],
397404

@@ -508,6 +515,10 @@ const opcode0x33func3Table: FuncTable<R_Type> = new Map([
508515
const index = rs2Value & 31;
509516
const result = rs1Value | (1 << index);
510517
registerSet.setRegister(rd, result);
518+
} else if(func7 === 0x24) { // bclr (Zbs)
519+
const index = rs2Value & 31;
520+
const result = rs1Value & ~(1 << index);
521+
registerSet.setRegister(rd, result);
511522
} else throw Error(`Unknown instruction, func7: 0x${func7.toString(16)}`);
512523
}],
513524

0 commit comments

Comments
 (0)