Skip to content

Commit

Permalink
aligned view factor can be a multiple of the banking factor
Browse files Browse the repository at this point in the history
  • Loading branch information
rachitnigam committed May 2, 2019
1 parent 7f375d0 commit 9e43c62
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/Errors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ object Errors {
case class InvalidShrinkWidth(pos: Position, bf: Int, width: Int) extends TypeError(
s"Invalid shrinking factor for view. Expected factor of $bf (banking factor), received: $width", pos)
case class InvalidAlignFactor(pos: Position, afac: Int, bank: Int) extends TypeError(
s"Aligned suffix factor $afac does not divide the banking factor $bank.", pos)
s"Aligned suffix factor $afac is not a multiple of the banking factor $bank.", pos)
case class ViewInsideUnroll(pos: Position, arrId: Id) extends TypeError(
s"Cannot create view for $arrId inside an unrolled context.", pos)
case class InvalidSplitFactor(id: Id, arrId: Id, split: Int, bank: Int, dim: Int) extends TypeError(
Expand Down
8 changes: 5 additions & 3 deletions src/main/scala/TypeCheck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,11 @@ object TypeChecker {
throw InvalidShrinkWidth(view.pos, bank, shrink.get)
}

val newBank = shrink.getOrElse(bank)

val idx = suf match {
case Aligned(fac, idx) => if (bank < fac || bank % fac != 0) {
throw InvalidAlignFactor(suf.pos, fac, bank)
case Aligned(fac, idx) => if (newBank > fac || fac % newBank != 0) {
throw InvalidAlignFactor(suf.pos, fac, newBank)
} else {
idx
}
Expand All @@ -273,7 +275,7 @@ object TypeChecker {
case _:IntType => () // IntTypes are valid
}

nEnv -> (pre.getOrElse(len) -> shrink.getOrElse(bank))
nEnv -> (pre.getOrElse(len) -> newBank)
}

private def checkC(cmd: Command)
Expand Down
26 changes: 23 additions & 3 deletions src/test/scala/TypeCheckerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ class TypeCheckerSpec extends FunSpec {
typeCheck("""
decl a: bit<10>[16 bank 8];
for (let i = 0..4) {
view v = a[4 * i :]
view v = a[8 * i :]
}
""" )
}
Expand Down Expand Up @@ -846,20 +846,40 @@ class TypeCheckerSpec extends FunSpec {
it("width must be factor of banking factor") {
assertThrows[InvalidAlignFactor] {
typeCheck("""
decl x: bit<32>;
decl a: bit<10>[10 bank 5];
view v = a[3 * i :]
view v = a[3 * x :]
""" )
}
}

it("width must be a multiple of the banking factor") {
assertThrows[InvalidAlignFactor] {
typeCheck("""
decl x: bit<32>;
decl a: bit<10>[10 bank 10];
view v = a[5 * x :]
""" )
}
}

it("width must be statically known") {
assertThrows[ParserError] {
typeCheck("""
decl x: bit<32>;
decl a: bit<10>[10 bank 5];
view v = a[i * i :]
view v = a[x * x :]
""" )
}
}

it("suffix factor is a factor of the new banking") {
typeCheck("""
decl x: bit<32>;
decl a: bit<10>[16 bank 8];
view v = a[6 * x : bank 2]
""" )
}
}

describe("Simple rotation views") {
Expand Down

0 comments on commit 9e43c62

Please sign in to comment.