Skip to content

Commit 74989c8

Browse files
committed
Merge branch 'develop' of github.com:TiarkRompf/virtualization-lms-core into develop-0.8.x
2 parents 4e16214 + a0d847f commit 74989c8

File tree

5 files changed

+41
-13
lines changed

5 files changed

+41
-13
lines changed

src/common/Functions.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@ trait CGenFunctions extends CGenEffect with BaseGenFunctions {
350350
override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match {
351351
case e@Lambda(fun, x, y) =>
352352
val retType = remap(getBlockResult(y).tp)
353-
stream.println("function<"+retType+"("+
354-
remap(x.tp)+")> "+quote(sym)+
353+
val retTp = if (cppExplicitFunRet == "true") "function<"+retType+"("+remap(x.tp)+")>" else "auto"
354+
stream.println(retTp+" "+quote(sym)+
355355
" = [&]("+remap(x.tp)+" "+quote(x)+") {")
356356
emitBlock(y)
357357
val z = getBlockResult(y)
@@ -378,8 +378,8 @@ trait CGenTupledFunctions extends CGenFunctions with GenericGenUnboxedTupleAcces
378378
override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match {
379379
case Lambda(fun, UnboxedTuple(xs), y) =>
380380
val retType = remap(getBlockResult(y).tp)
381-
stream.println("function<"+retType+"("+
382-
xs.map(s=>remap(s.tp)).mkString(",")+")> "+quote(sym)+
381+
val retTp = if (cppExplicitFunRet == "true") "function<"+retType+"("+xs.map(s=>remap(s.tp)).mkString(",")+")>" else "auto"
382+
stream.println(retTp+" "+quote(sym)+
383383
" = [&]("+xs.map(s=>remap(s.tp)+" "+quote(s)).mkString(",")+") {")
384384
emitBlock(y)
385385
val z = getBlockResult(y)

src/common/IfThenElse.scala

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,28 @@ trait CGenIfThenElse extends CGenEffect with BaseGenIfThenElse {
384384
emitBlock(b)
385385
stream.println("}")
386386
case _ =>
387-
stream.println("%s %s;".format(remap(sym.tp),quote(sym)))
388-
stream.println("if (" + quote(c) + ") {")
389-
emitBlock(a)
390-
stream.println("%s = %s;".format(quote(sym),quote(getBlockResult(a))))
391-
stream.println("} else {")
392-
emitBlock(b)
393-
stream.println("%s = %s;".format(quote(sym),quote(getBlockResult(b))))
394-
stream.println("}")
387+
if (cppIfElseAutoRet == "true") {
388+
val ten = quote(sym) + "True"
389+
val fen = quote(sym) + "False"
390+
def emitCondFun[T: Manifest](fname: String, block: Block[T]) {
391+
stream.println("auto " + fname + " = [&]() {");
392+
emitBlock(block)
393+
stream.println("return " + quote(getBlockResult(block)) + ";")
394+
stream.println("};")
395+
}
396+
emitCondFun(ten, a)
397+
emitCondFun(fen, b)
398+
stream.println("auto " + quote(sym) + " = " + quote(c) + " ? " + ten + "() : " + fen + "();")
399+
} else {
400+
stream.println("%s %s;".format(remap(sym.tp),quote(sym)))
401+
stream.println("if (" + quote(c) + ") {")
402+
emitBlock(a)
403+
stream.println("%s = %s;".format(quote(sym),quote(getBlockResult(a))))
404+
stream.println("} else {")
405+
emitBlock(b)
406+
stream.println("%s = %s;".format(quote(sym),quote(getBlockResult(b))))
407+
stream.println("}")
408+
}
395409
}
396410
/*
397411
val booll = remap(sym.tp).equals("void")

src/common/MathOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ trait MathOps extends Base {
2828
def abs[A:Manifest:Numeric](x: Rep[A])(implicit pos: SourceContext) = math_abs(x)
2929
def max[A:Manifest:Numeric](x: Rep[A], y: Rep[A])(implicit pos: SourceContext) = math_max(x,y)
3030
def min[A:Manifest:Numeric](x: Rep[A], y: Rep[A])(implicit pos: SourceContext) = math_min(x,y)
31-
def Pi(implicit pos: SourceContext) = math_pi
31+
def Pi(implicit pos: SourceContext) = 3.141592653589793238462643383279502884197169
3232
def E(implicit pos: SourceContext) = math_e
3333
}
3434

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))

src/internal/Config.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ trait Config {
88

99
// memory management type for C++ target (refcnt or gc)
1010
val cppMemMgr = System.getProperty("lms.cpp.memmgr","malloc")
11+
12+
// explicit return type of lambda functions (allows recursive functions but is less generic)
13+
val cppExplicitFunRet = System.getProperty("lms.cpp.explicitFunRet","true")
14+
15+
// auto return value of if-else expressions (allows type deduction on if-then-else expressions)
16+
val cppIfElseAutoRet = System.getProperty("lms.cpp.ifElseAutoRet","false")
1117
}

0 commit comments

Comments
 (0)