-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compiler: monomorphize int64(round(x)) to not lose precision.
This applies to any expression with an indeterminate integer type cast to int64(), not just round().
whitequark
committed
Dec 2, 2016
1 parent
696db32
commit 68de724
Showing
8 changed files
with
40 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
""" | ||
:class:`CastMonomorphizer` uses explicit casts to monomorphize | ||
expressions of undetermined integer type to either 32 or 64 bits. | ||
""" | ||
|
||
from pythonparser import algorithm, diagnostic | ||
from .. import types, builtins | ||
|
||
class CastMonomorphizer(algorithm.Visitor): | ||
def __init__(self, engine): | ||
self.engine = engine | ||
|
||
def visit_CallT(self, node): | ||
self.generic_visit(node) | ||
|
||
if (types.is_builtin(node.func.type, "int") or | ||
types.is_builtin(node.func.type, "int32") or | ||
types.is_builtin(node.func.type, "int64")): | ||
typ = node.type.find() | ||
if (not types.is_var(typ["width"]) and | ||
builtins.is_int(node.args[0].type) and | ||
types.is_var(node.args[0].type.find()["width"])): | ||
node.args[0].type.unify(typ) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,3 @@ | |
|
||
y = int(1) | ||
# CHECK-L: y: numpy.int32 | ||
|
||
z = round(1.0) | ||
# CHECK-L: z: numpy.int32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# RUN: %python -m artiq.compiler.testbench.inferencer +mono %s >%t | ||
# RUN: OutputCheck %s --file-to-check=%t | ||
|
||
# CHECK-L: round:<function round>(1.0:float):numpy.int32 | ||
round(1.0) | ||
|
||
# CHECK-L: round:<function round>(2.0:float):numpy.int32 | ||
int32(round(2.0)) | ||
|
||
# CHECK-L: round:<function round>(3.0:float):numpy.int64 | ||
int64(round(3.0)) |