Skip to content

Commit a0d847f

Browse files
committed
Merge pull request #96 from biboudis/develop
Add infix mod operator for Long integers.
2 parents df3edc5 + a72d710 commit a0d847f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/common/PrimitiveOps.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,15 @@ trait PrimitiveOps extends Variables with OverloadHack {
272272
def parseLong(s: Rep[String])(implicit pos: SourceContext) = obj_long_parse_long(s)
273273
}
274274

275+
def infix_%(lhs: Rep[Long], rhs: Rep[Long])(implicit o: Overloaded2, pos: SourceContext) = long_mod(lhs, rhs)
275276
def infix_&(lhs: Rep[Long], rhs: Rep[Long])(implicit o: Overloaded2, pos: SourceContext) = long_binaryand(lhs, rhs)
276277
def infix_|(lhs: Rep[Long], rhs: Rep[Long])(implicit o: Overloaded2, pos: SourceContext) = long_binaryor(lhs, rhs)
277278
def infix_<<(lhs: Rep[Long], rhs: Rep[Int])(implicit o: Overloaded2, pos: SourceContext) = long_shiftleft(lhs, rhs)
278279
def infix_>>>(lhs: Rep[Long], rhs: Rep[Int])(implicit o: Overloaded2, pos: SourceContext) = long_shiftright_unsigned(lhs, rhs)
279280
def infix_toInt(lhs: Rep[Long])(implicit o: Overloaded2, pos: SourceContext) = long_toint(lhs)
280281

281282
def obj_long_parse_long(s: Rep[String])(implicit pos: SourceContext): Rep[Long]
283+
def long_mod(lhs: Rep[Long], rhs: Rep[Long])(implicit pos: SourceContext): Rep[Long]
282284
def long_binaryand(lhs: Rep[Long], rhs: Rep[Long])(implicit pos: SourceContext): Rep[Long]
283285
def long_binaryor(lhs: Rep[Long], rhs: Rep[Long])(implicit pos: SourceContext): Rep[Long]
284286
def long_shiftleft(lhs: Rep[Long], rhs: Rep[Int])(implicit pos: SourceContext): Rep[Long]
@@ -410,13 +412,15 @@ trait PrimitiveOpsExp extends PrimitiveOps with EffectExp {
410412
case class LongShiftLeft(lhs: Exp[Long], rhs: Exp[Int]) extends Def[Long]
411413
case class LongShiftRightUnsigned(lhs: Exp[Long], rhs: Exp[Int]) extends Def[Long]
412414
case class LongToInt(lhs: Exp[Long]) extends Def[Int]
415+
case class LongMod(lhs: Exp[Long], rhs: Exp[Long]) extends Def[Long]
413416

414417
def obj_long_parse_long(s: Exp[String])(implicit pos: SourceContext) = ObjLongParseLong(s)
415418
def long_binaryor(lhs: Exp[Long], rhs: Exp[Long])(implicit pos: SourceContext) = LongBinaryOr(lhs,rhs)
416419
def long_binaryand(lhs: Exp[Long], rhs: Exp[Long])(implicit pos: SourceContext) = LongBinaryAnd(lhs,rhs)
417420
def long_shiftleft(lhs: Exp[Long], rhs: Exp[Int])(implicit pos: SourceContext) = LongShiftLeft(lhs,rhs)
418421
def long_shiftright_unsigned(lhs: Exp[Long], rhs: Exp[Int])(implicit pos: SourceContext) = LongShiftRightUnsigned(lhs,rhs)
419422
def long_toint(lhs: Exp[Long])(implicit pos: SourceContext) = LongToInt(lhs)
423+
def long_mod(lhs: Exp[Long], rhs: Exp[Long])(implicit pos: SourceContext) = LongMod(lhs, rhs)
420424

421425
override def mirror[A:Manifest](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = ({
422426
implicit var a: Numeric[A] = null // hack!! need to store it in Def instances??
@@ -461,6 +465,7 @@ trait PrimitiveOpsExp extends PrimitiveOps with EffectExp {
461465
case IntShiftRightLogical(x,y) => int_rightshiftlogical(f(x),f(y))
462466
case IntShiftRightArith(x,y) => int_rightshiftarith(f(x),f(y))
463467
case ObjLongParseLong(x) => obj_long_parse_long(f(x))
468+
case LongMod(x,y) => long_mod(f(x),f(y))
464469
case LongShiftLeft(x,y) => long_shiftleft(f(x),f(y))
465470
case LongBinaryOr(x,y) => long_binaryor(f(x),f(y))
466471
case LongBinaryAnd(x,y) => long_binaryand(f(x),f(y))
@@ -505,6 +510,7 @@ trait PrimitiveOpsExp extends PrimitiveOps with EffectExp {
505510
case Reflect(IntShiftLeft(x,y), u, es) => reflectMirrored(Reflect(IntShiftLeft(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos)
506511
case Reflect(IntShiftRightLogical(x,y), u, es) => reflectMirrored(Reflect(IntShiftRightLogical(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos)
507512
case Reflect(IntShiftRightArith(x,y), u, es) => reflectMirrored(Reflect(IntShiftRightArith(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos)
513+
case Reflect(LongMod(x,y), u, es) => reflectMirrored(Reflect(LongMod(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos)
508514
case Reflect(LongShiftLeft(x,y), u, es) => reflectMirrored(Reflect(LongShiftLeft(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos)
509515
case Reflect(LongShiftRightUnsigned(x,y), u, es) => reflectMirrored(Reflect(LongShiftRightUnsigned(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos)
510516
case Reflect(LongBinaryOr(x,y), u, es) => reflectMirrored(Reflect(LongBinaryOr(f(x),f(y)), mapOver(f,u), f(es)))(mtype(manifest[A]), pos)
@@ -605,6 +611,7 @@ trait ScalaGenPrimitiveOps extends ScalaGenBase {
605611
case IntToFloat(lhs) => emitValDef(sym, quote(lhs) + ".toFloat")
606612
case IntToDouble(lhs) => emitValDef(sym, quote(lhs) + ".toDouble")
607613
case ObjLongParseLong(s) => emitValDef(sym, "java.lang.Long.parseLong(" + quote(s) + ")")
614+
case LongMod(lhs,rhs) => emitValDef(sym, quote(lhs) + " % " + quote(rhs))
608615
case LongBinaryOr(lhs,rhs) => emitValDef(sym, quote(lhs) + " | " + quote(rhs))
609616
case LongBinaryAnd(lhs,rhs) => emitValDef(sym, quote(lhs) + " & " + quote(rhs))
610617
case LongShiftLeft(lhs,rhs) => emitValDef(sym, quote(lhs) + " << " + quote(rhs))
@@ -659,6 +666,7 @@ trait CLikeGenPrimitiveOps extends CLikeGenBase {
659666
case IntToFloat(lhs) => emitValDef(sym, "(float)"+quote(lhs))
660667
case IntToDouble(lhs) => emitValDef(sym, "(double)"+quote(lhs))
661668
case ObjLongParseLong(s) => emitValDef(sym, "strtod(" + quote(s) + ".c_str(),NULL)")
669+
case LongMod(lhs,rhs) => emitValDef(sym, quote(lhs) + " % " + quote(rhs))
662670
case LongBinaryOr(lhs,rhs) => emitValDef(sym, quote(lhs) + " | " + quote(rhs))
663671
case LongBinaryAnd(lhs,rhs) => emitValDef(sym, quote(lhs) + " & " + quote(rhs))
664672
case LongShiftLeft(lhs,rhs) => emitValDef(sym, quote(lhs) + " << " + quote(rhs))

0 commit comments

Comments
 (0)