From 5f846dfecf1324dcf0f4aa21b1442dce44afe4fe Mon Sep 17 00:00:00 2001 From: Francis Russell Date: Wed, 4 Apr 2012 11:05:59 +0100 Subject: [PATCH] Calculate PPD locations (in PPD co-ordinate system). --- src/ofc/codegen/BinaryOperator.scala | 12 ++++++++++++ src/ofc/codegen/Expression.scala | 7 ++++++- src/ofc/generators/onetep/PPDFunctionSet.scala | 17 ++++++++++------- 3 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 src/ofc/codegen/BinaryOperator.scala diff --git a/src/ofc/codegen/BinaryOperator.scala b/src/ofc/codegen/BinaryOperator.scala new file mode 100644 index 0000000..406f507 --- /dev/null +++ b/src/ofc/codegen/BinaryOperator.scala @@ -0,0 +1,12 @@ +package ofc.codegen + +object BinaryOperator { + sealed abstract class Operator + case object Add extends Operator + case object Sub extends Operator + case object Mul extends Operator + case object Div extends Operator + case object Mod extends Operator +} + +class BinaryOperator(op: BinaryOperator.Operator, left: Expression, right: Expression) extends Expression diff --git a/src/ofc/codegen/Expression.scala b/src/ofc/codegen/Expression.scala index 7f132bf..0e93d92 100644 --- a/src/ofc/codegen/Expression.scala +++ b/src/ofc/codegen/Expression.scala @@ -1,9 +1,14 @@ package ofc.codegen class Expression { - def %(field: FieldSymbol) : Expression = new FieldAccess(this, field) + def ~>(field: FieldSymbol) : Expression = new FieldAccess(this, field) def readAt(index: List[Expression]) : Expression = new ArrayRead(this, index) def apply(index: Expression*) : Expression = this.readAt(index.toList) + def +(rhs: Expression) : Expression = new BinaryOperator(BinaryOperator.Add, this, rhs) + def -(rhs: Expression) : Expression = new BinaryOperator(BinaryOperator.Sub, this, rhs) + def *(rhs: Expression) : Expression = new BinaryOperator(BinaryOperator.Mul, this, rhs) + def /(rhs: Expression) : Expression = new BinaryOperator(BinaryOperator.Div, this, rhs) + def %(rhs: Expression) : Expression = new BinaryOperator(BinaryOperator.Mod, this, rhs) } // Variable references diff --git a/src/ofc/generators/onetep/PPDFunctionSet.scala b/src/ofc/generators/onetep/PPDFunctionSet.scala index 346e239..bea3b71 100644 --- a/src/ofc/generators/onetep/PPDFunctionSet.scala +++ b/src/ofc/generators/onetep/PPDFunctionSet.scala @@ -6,21 +6,24 @@ class PPDFunctionSet(val basisName: String, dataName: String) extends FunctionSe val data = NamedUnboundVarSymbol(dataName) val pubCell = NamedUnboundVarSymbol("pub_cell") - val numSpheres = basis % FieldSymbol("num"); - val ppdWidths = for(dim <- 1 to 3) yield pubCell % FieldSymbol("n_pt"+dim) - val cellWidthInPPDs = for(dim <- 1 to 3) yield pubCell % FieldSymbol("n_ppds_a"+dim) + val numSpheres = basis~>FieldSymbol("num"); + val ppdWidths = for(dim <- 1 to 3) yield pubCell~>FieldSymbol("n_pt"+dim) + val cellWidthInPPDs = for(dim <- 1 to 3) yield pubCell~>FieldSymbol("n_ppds_a"+dim) def getSuffixFragment = { val producer = new ProducerStatement val sphereIndex = producer.addIteration("sphere_index", numSpheres) - val numPPDs = (basis % FieldSymbol("n_ppds_sphere"))(sphereIndex) + val numPPDs = (basis~>FieldSymbol("n_ppds_sphere"))(sphereIndex) val ppdIndex = producer.addIteration("ppd_index", numPPDs) - val ppdGlobalCount = (basis % FieldSymbol("ppd_list"))(ppdIndex, new IntegerLiteral(1)) + val ppdGlobalCount = (basis~>FieldSymbol("ppd_list"))(ppdIndex, new IntegerLiteral(1)) - new IntegerLiteral(1) - // We need to calculate the integer co-ordinates of the PPD + // We need to calculate the integer co-ordinates of the PPD (0-based) + val a3pos = ppdGlobalCount / (cellWidthInPPDs(0)*cellWidthInPPDs(1)) + val a2pos = (ppdGlobalCount % (cellWidthInPPDs(0)*cellWidthInPPDs(1)))/cellWidthInPPDs(0) + val a1pos = ppdGlobalCount % cellWidthInPPDs(0) //val ppdRanges = for(dim <- 0 to 2) yield producer.addIteration("point"+(dim+1), ppdWidths(dim)) - val tightbox = basis % FieldSymbol("tight_boxes") + val tightbox = basis~>FieldSymbol("tight_boxes") producer } -- 2.47.3