Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 95af6daa281c
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d5216879d463
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Dec 19, 2015

  1. Copy the full SHA
    54aeb50 View commit details
  2. Copy the full SHA
    d521687 View commit details
Showing with 40 additions and 0 deletions.
  1. +7 −0 artiq/compiler/transforms/int_monomorphizer.py
  2. +33 −0 artiq/runtime/ksupport.c
7 changes: 7 additions & 0 deletions artiq/compiler/transforms/int_monomorphizer.py
Original file line number Diff line number Diff line change
@@ -26,3 +26,10 @@ def visit_NumT(self, node):
return

node.type["width"].unify(types.TValue(width))

def visit_CallT(self, node):
if types.is_builtin(node.func.type, "int") or \
types.is_builtin(node.func.type, "round"):
typ = node.type.find()
if types.is_var(typ["width"]):
typ["width"].unify(types.TValue(32))
33 changes: 33 additions & 0 deletions artiq/runtime/ksupport.c
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@
#include "dds.h"
#include "rtio.h"

double round(double x);

void ksupport_abort(void);

int64_t now;
@@ -82,6 +84,9 @@ static const struct symbol runtime_exports[] = {
{"__moddi3", &__moddi3},
{"__powidf2", &__powidf2},

/* libm */
{"round", &round},

/* exceptions */
{"_Unwind_Resume", &_Unwind_Resume},
{"__artiq_personality", &__artiq_personality},
@@ -118,6 +123,34 @@ static const struct symbol runtime_exports[] = {
{NULL, NULL}
};

double round(double x)
{
union {double f; uint64_t i;} u = {x};
int e = u.i >> 52 & 0x7ff;
double y;

if (e >= 0x3ff+52)
return x;
if (u.i >> 63)
x = -x;
if (e < 0x3ff-1) {
/* we don't do it in ARTIQ */
/* raise inexact if x!=0 */
// FORCE_EVAL(x + 0x1p52);
return 0*u.f;
}
y = (double)(x + 0x1p52) - 0x1p52 - x;
if (y > 0.5)
y = y + x - 1;
else if (y <= -0.5)
y = y + x + 1;
else
y = y + x;
if (u.i >> 63)
y = -y;
return y;
}

/* called by libunwind */
int fprintf(FILE *stream, const char *fmt, ...)
{