Skip to content
Snippets Groups Projects

Clarify semantics of fancy integer division functions.

Merged Daniel Bauer requested to merge hyteg/pystencils:bauerd/fancy-int-div into v2.0-dev
1 unresolved thread
5 files
+ 202
145
Compare changes
  • Side-by-side
  • Inline
Files
5
@@ -272,7 +272,7 @@ class FreezeExpressions:
@@ -272,7 +272,7 @@ class FreezeExpressions:
def map_TypedSymbol(self, expr: TypedSymbol):
def map_TypedSymbol(self, expr: TypedSymbol):
dtype = expr.dtype
dtype = expr.dtype
match dtype:
match dtype:
case DynamicType.NUMERIC_TYPE:
case DynamicType.NUMERIC_TYPE:
dtype = self._ctx.default_dtype
dtype = self._ctx.default_dtype
@@ -422,12 +422,19 @@ class FreezeExpressions:
@@ -422,12 +422,19 @@ class FreezeExpressions:
return PsBitwiseOr(*args)
return PsBitwiseOr(*args)
case integer_functions.int_power_of_2():
case integer_functions.int_power_of_2():
return PsLeftShift(PsExpression.make(PsConstant(1)), args[0])
return PsLeftShift(PsExpression.make(PsConstant(1)), args[0])
# TODO: what exactly are the semantics?
case integer_functions.round_to_multiple_towards_zero():
# case integer_functions.modulo_floor():
return PsIntDiv(args[0], args[1]) * args[1]
# case integer_functions.div_floor()
case integer_functions.ceil_to_multiple():
# TODO: requires if *expression*
return (
# case integer_functions.modulo_ceil():
PsIntDiv(
# case integer_functions.div_ceil():
args[0] + args[1] - PsExpression.make(PsConstant(1)), args[1]
 
)
 
* args[1]
 
)
 
case integer_functions.div_ceil():
 
return PsIntDiv(
 
args[0] + args[1] - PsExpression.make(PsConstant(1)), args[1]
 
)
case AddressOf():
case AddressOf():
return PsAddressOf(*args)
return PsAddressOf(*args)
case _:
case _:
Loading