Skip to content

Commit

Permalink
Finish adaption to yarc bn-in-fn.
Browse files Browse the repository at this point in the history
  • Loading branch information
yqszxx committed Aug 18, 2019
1 parent e2d05c6 commit e69bab0
Show file tree
Hide file tree
Showing 70 changed files with 213 additions and 1,977 deletions.
16 changes: 7 additions & 9 deletions bv/bitVector.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func Bv(width uint) BitVector {
return newBv
}

func (bv BitVector) ToUint64() uint64 {
var n uint64
func (bv BitVector) ToUint32() uint32 {
var n uint32
for i := len(bv.bits) - 1; i >= 0; i-- {
n <<= 1
if bv.bits[i] {
Expand Down Expand Up @@ -97,21 +97,19 @@ func (bv BitVector) Equal(_bv BitVector, strict bool) bool {
}

func (bv *BitVector) From(i interface{}) {
var _i uint64
var _i uint32
switch v := i.(type) {
case uint16:
_i = uint64(v)
_i = uint32(v)
case int:
_i = uint64(uint(v))
_i = uint32(uint(v))
case uint32:
_i = uint64(v)
case uint64:
_i = v
case bool:
bv.bits[0] = v
return
default:
log.Panicf("Unable to convert %T to uint64.\n", i)
log.Panicf("Unable to convert %T to uint32.\n", i)
}
var j uint32
for j = 0; j < uint32(len(bv.bits)); j++ {
Expand Down Expand Up @@ -158,7 +156,7 @@ func (bv BitVector) String() string {
// w = 8
// }
// format := fmt.Sprintf("0x%%0%dX of width %%d", w)
// return fmt.Sprintf(format, bv.ToUint64(), bv.Width)
// return fmt.Sprintf(format, bv.ToUint32(), bv.Width)
//}

func B(s string) BitVector {
Expand Down
10 changes: 5 additions & 5 deletions instruction/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ var ADD = Instruction{
pattern: bv.P("0000000 XXXXX XXXXX 000 XXXXX 0110011"),
operation: func(_inst *Instruction) {
log.Printf("Decoding as ADD x%d, x%d, x%d",
_inst.rd.ToUint64(),
_inst.rs1.ToUint64(),
_inst.rs2.ToUint64())
_inst.rd.ToUint32(),
_inst.rs1.ToUint32(),
_inst.rs2.ToUint32())

op1 := _inst.p.ReadReg(_inst.rs1) // first operator of alu
op2 := _inst.p.ReadReg(_inst.rs2) // second operator of alu
result := bv.Bv(64) // will hold the result of alu
result.From(op1.ToUint64() + op2.ToUint64()) // perform computation
result := bv.Bv(32) // will hold the result of alu
result.From(op1.ToUint32() + op2.ToUint32()) // perform computation
_inst.p.WriteReg(_inst.rd, result) // write result back to rd
},
}
12 changes: 6 additions & 6 deletions instruction/addi.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ var ADDI = Instruction{
pattern: bv.P("XXXXXXXXXXXX XXXXX 000 XXXXX 0010011"),
operation: func(_inst *Instruction) {
log.Printf("Decoding as ADDI x%d, x%d, %d",
_inst.rd.ToUint64(),
_inst.rs1.ToUint64(),
int64(_inst.iImm.SignExtendTo(64).ToUint64()))
_inst.rd.ToUint32(),
_inst.rs1.ToUint32(),
int32(_inst.iImm.SignExtendTo(32).ToUint32()))

op1 := _inst.p.ReadReg(_inst.rs1) // first operator of alu
op2 := _inst.iImm.SignExtendTo(64) // second operator of alu
result := bv.Bv(64) // will hold the result of alu
result.From(op1.ToUint64() + op2.ToUint64()) // perform computation
op2 := _inst.iImm.SignExtendTo(32) // second operator of alu
result := bv.Bv(32) // will hold the result of alu
result.From(op1.ToUint32() + op2.ToUint32()) // perform computation
_inst.p.WriteReg(_inst.rd, result) // write result back to rd
},
}
26 changes: 0 additions & 26 deletions instruction/addiw.go

This file was deleted.

26 changes: 0 additions & 26 deletions instruction/addw.go

This file was deleted.

10 changes: 5 additions & 5 deletions instruction/and.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ var AND = Instruction{
pattern: bv.P("0000000 XXXXX XXXXX 111 XXXXX 0110011"),
operation: func(_inst *Instruction) {
log.Printf("Decoding as AND x%d, x%d, x%d",
_inst.rd.ToUint64(),
_inst.rs1.ToUint64(),
_inst.rs2.ToUint64())
_inst.rd.ToUint32(),
_inst.rs1.ToUint32(),
_inst.rs2.ToUint32())

op1 := _inst.p.ReadReg(_inst.rs1) // first operator of alu
op2 := _inst.p.ReadReg(_inst.rs2) // second operator of alu
result := bv.Bv(64) // will hold the result of alu
result.From(op1.ToUint64() & op2.ToUint64()) // perform computation
result := bv.Bv(32) // will hold the result of alu
result.From(op1.ToUint32() & op2.ToUint32()) // perform computation
_inst.p.WriteReg(_inst.rd, result) // write result back to rd
},
}
12 changes: 6 additions & 6 deletions instruction/andi.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ var ANDI = Instruction{
pattern: bv.P("XXXXXXXXXXXX XXXXX 111 XXXXX 0010011"),
operation: func(_inst *Instruction) {
log.Printf("Decoding as ANDI x%d, x%d, %d",
_inst.rd.ToUint64(),
_inst.rs1.ToUint64(),
_inst.iImm.SignExtendTo(64).ToUint64())
_inst.rd.ToUint32(),
_inst.rs1.ToUint32(),
_inst.iImm.SignExtendTo(32).ToUint32())

op1 := _inst.p.ReadReg(_inst.rs1) // first operator of alu
op2 := _inst.iImm.SignExtendTo(64) // second operator of alu
result := bv.Bv(64) // will hold the result of alu
result.From(op1.ToUint64() & op2.ToUint64()) // perform computation
op2 := _inst.iImm.SignExtendTo(32) // second operator of alu
result := bv.Bv(32) // will hold the result of alu
result.From(op1.ToUint32() & op2.ToUint32()) // perform computation
_inst.p.WriteReg(_inst.rd, result) // write result back to rd
},
}
10 changes: 5 additions & 5 deletions instruction/auipc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ var AUIPC = Instruction{
name: "AUIPC",
pattern: bv.P("XXXXXXXXXXXXXXXXXXXX XXXXX 0010111"),
operation: func(_inst *Instruction) {
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
op1 := bv.Cat(_inst.uImm, bv.B("0000 0000 0000"))

log.Printf("Decoding as AUIPC x%d, %d",
_inst.rd.ToUint64(),
_inst.uImm.ToUint64())
_inst.rd.ToUint32(),
_inst.uImm.ToUint32())

result := bv.Bv(64) // will hold the result
result.From(op1.ToUint64() + _inst.p.ReadPc().ToUint64()) // adds op1 to the pc
result := bv.Bv(32) // will hold the result
result.From(op1.ToUint32() + _inst.p.ReadPc().ToUint32()) // adds op1 to the pc
_inst.p.WriteReg(_inst.rd, result) // places the result in register rd
},
}
36 changes: 0 additions & 36 deletions instruction/beq.go

This file was deleted.

37 changes: 0 additions & 37 deletions instruction/bge.go

This file was deleted.

37 changes: 0 additions & 37 deletions instruction/bgeu.go

This file was deleted.

37 changes: 0 additions & 37 deletions instruction/blt.go

This file was deleted.

37 changes: 0 additions & 37 deletions instruction/bltu.go

This file was deleted.

Loading

0 comments on commit e69bab0

Please sign in to comment.