Skip to content

Commit e69bab0

Browse files
committed
Finish adaption to yarc bn-in-fn.
1 parent e2d05c6 commit e69bab0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+213
-1977
lines changed

bv/bitVector.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ func Bv(width uint) BitVector {
2020
return newBv
2121
}
2222

23-
func (bv BitVector) ToUint64() uint64 {
24-
var n uint64
23+
func (bv BitVector) ToUint32() uint32 {
24+
var n uint32
2525
for i := len(bv.bits) - 1; i >= 0; i-- {
2626
n <<= 1
2727
if bv.bits[i] {
@@ -97,21 +97,19 @@ func (bv BitVector) Equal(_bv BitVector, strict bool) bool {
9797
}
9898

9999
func (bv *BitVector) From(i interface{}) {
100-
var _i uint64
100+
var _i uint32
101101
switch v := i.(type) {
102102
case uint16:
103-
_i = uint64(v)
103+
_i = uint32(v)
104104
case int:
105-
_i = uint64(uint(v))
105+
_i = uint32(uint(v))
106106
case uint32:
107-
_i = uint64(v)
108-
case uint64:
109107
_i = v
110108
case bool:
111109
bv.bits[0] = v
112110
return
113111
default:
114-
log.Panicf("Unable to convert %T to uint64.\n", i)
112+
log.Panicf("Unable to convert %T to uint32.\n", i)
115113
}
116114
var j uint32
117115
for j = 0; j < uint32(len(bv.bits)); j++ {
@@ -158,7 +156,7 @@ func (bv BitVector) String() string {
158156
// w = 8
159157
// }
160158
// format := fmt.Sprintf("0x%%0%dX of width %%d", w)
161-
// return fmt.Sprintf(format, bv.ToUint64(), bv.Width)
159+
// return fmt.Sprintf(format, bv.ToUint32(), bv.Width)
162160
//}
163161

164162
func B(s string) BitVector {

instruction/add.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ var ADD = Instruction{
1212
pattern: bv.P("0000000 XXXXX XXXXX 000 XXXXX 0110011"),
1313
operation: func(_inst *Instruction) {
1414
log.Printf("Decoding as ADD x%d, x%d, x%d",
15-
_inst.rd.ToUint64(),
16-
_inst.rs1.ToUint64(),
17-
_inst.rs2.ToUint64())
15+
_inst.rd.ToUint32(),
16+
_inst.rs1.ToUint32(),
17+
_inst.rs2.ToUint32())
1818

1919
op1 := _inst.p.ReadReg(_inst.rs1) // first operator of alu
2020
op2 := _inst.p.ReadReg(_inst.rs2) // second operator of alu
21-
result := bv.Bv(64) // will hold the result of alu
22-
result.From(op1.ToUint64() + op2.ToUint64()) // perform computation
21+
result := bv.Bv(32) // will hold the result of alu
22+
result.From(op1.ToUint32() + op2.ToUint32()) // perform computation
2323
_inst.p.WriteReg(_inst.rd, result) // write result back to rd
2424
},
2525
}

instruction/addi.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ var ADDI = Instruction{
1212
pattern: bv.P("XXXXXXXXXXXX XXXXX 000 XXXXX 0010011"),
1313
operation: func(_inst *Instruction) {
1414
log.Printf("Decoding as ADDI x%d, x%d, %d",
15-
_inst.rd.ToUint64(),
16-
_inst.rs1.ToUint64(),
17-
int64(_inst.iImm.SignExtendTo(64).ToUint64()))
15+
_inst.rd.ToUint32(),
16+
_inst.rs1.ToUint32(),
17+
int32(_inst.iImm.SignExtendTo(32).ToUint32()))
1818

1919
op1 := _inst.p.ReadReg(_inst.rs1) // first operator of alu
20-
op2 := _inst.iImm.SignExtendTo(64) // second operator of alu
21-
result := bv.Bv(64) // will hold the result of alu
22-
result.From(op1.ToUint64() + op2.ToUint64()) // perform computation
20+
op2 := _inst.iImm.SignExtendTo(32) // second operator of alu
21+
result := bv.Bv(32) // will hold the result of alu
22+
result.From(op1.ToUint32() + op2.ToUint32()) // perform computation
2323
_inst.p.WriteReg(_inst.rd, result) // write result back to rd
2424
},
2525
}

instruction/addiw.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

instruction/addw.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

instruction/and.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ var AND = Instruction{
1111
pattern: bv.P("0000000 XXXXX XXXXX 111 XXXXX 0110011"),
1212
operation: func(_inst *Instruction) {
1313
log.Printf("Decoding as AND x%d, x%d, x%d",
14-
_inst.rd.ToUint64(),
15-
_inst.rs1.ToUint64(),
16-
_inst.rs2.ToUint64())
14+
_inst.rd.ToUint32(),
15+
_inst.rs1.ToUint32(),
16+
_inst.rs2.ToUint32())
1717

1818
op1 := _inst.p.ReadReg(_inst.rs1) // first operator of alu
1919
op2 := _inst.p.ReadReg(_inst.rs2) // second operator of alu
20-
result := bv.Bv(64) // will hold the result of alu
21-
result.From(op1.ToUint64() & op2.ToUint64()) // perform computation
20+
result := bv.Bv(32) // will hold the result of alu
21+
result.From(op1.ToUint32() & op2.ToUint32()) // perform computation
2222
_inst.p.WriteReg(_inst.rd, result) // write result back to rd
2323
},
2424
}

instruction/andi.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ var ANDI = Instruction{
1212
pattern: bv.P("XXXXXXXXXXXX XXXXX 111 XXXXX 0010011"),
1313
operation: func(_inst *Instruction) {
1414
log.Printf("Decoding as ANDI x%d, x%d, %d",
15-
_inst.rd.ToUint64(),
16-
_inst.rs1.ToUint64(),
17-
_inst.iImm.SignExtendTo(64).ToUint64())
15+
_inst.rd.ToUint32(),
16+
_inst.rs1.ToUint32(),
17+
_inst.iImm.SignExtendTo(32).ToUint32())
1818

1919
op1 := _inst.p.ReadReg(_inst.rs1) // first operator of alu
20-
op2 := _inst.iImm.SignExtendTo(64) // second operator of alu
21-
result := bv.Bv(64) // will hold the result of alu
22-
result.From(op1.ToUint64() & op2.ToUint64()) // perform computation
20+
op2 := _inst.iImm.SignExtendTo(32) // second operator of alu
21+
result := bv.Bv(32) // will hold the result of alu
22+
result.From(op1.ToUint32() & op2.ToUint32()) // perform computation
2323
_inst.p.WriteReg(_inst.rd, result) // write result back to rd
2424
},
2525
}

instruction/auipc.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ var AUIPC = Instruction{
1111
name: "AUIPC",
1212
pattern: bv.P("XXXXXXXXXXXXXXXXXXXX XXXXX 0010111"),
1313
operation: func(_inst *Instruction) {
14-
op1 := bv.Cat(_inst.uImm, bv.B("0000 0000 0000")).SignExtendTo(64) // appends 12 low-order zero bits to the 20-bit U-immediate and sign extends to 64 bit
14+
op1 := bv.Cat(_inst.uImm, bv.B("0000 0000 0000"))
1515

1616
log.Printf("Decoding as AUIPC x%d, %d",
17-
_inst.rd.ToUint64(),
18-
_inst.uImm.ToUint64())
17+
_inst.rd.ToUint32(),
18+
_inst.uImm.ToUint32())
1919

20-
result := bv.Bv(64) // will hold the result
21-
result.From(op1.ToUint64() + _inst.p.ReadPc().ToUint64()) // adds op1 to the pc
20+
result := bv.Bv(32) // will hold the result
21+
result.From(op1.ToUint32() + _inst.p.ReadPc().ToUint32()) // adds op1 to the pc
2222
_inst.p.WriteReg(_inst.rd, result) // places the result in register rd
2323
},
2424
}

instruction/beq.go

Lines changed: 0 additions & 36 deletions
This file was deleted.

instruction/bge.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)