summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/ChangeLog6
-rw-r--r--runtime/arith.c79
-rw-r--r--runtime/builtin_functions.h60
-rw-r--r--runtime/runtime.h1
4 files changed, 86 insertions, 60 deletions
diff --git a/runtime/ChangeLog b/runtime/ChangeLog
index fe6fe13b..c0e2ac65 100644
--- a/runtime/ChangeLog
+++ b/runtime/ChangeLog
@@ -1,3 +1,9 @@
+2005-08-12 Frank Ch. Eigler <fche@elastic.org>
+
+ * arith.c: New file to contain arithmetic helper functions.
+ * builtin_functions.h: Remove, unused.
+ * runtime.h: Include it.
+
2005-08-10 Roland McGrath <roland@redhat.com>
* loc2c-runtime.h (store_bitfield): Fix argument use.
diff --git a/runtime/arith.c b/runtime/arith.c
new file mode 100644
index 00000000..175cc4e8
--- /dev/null
+++ b/runtime/arith.c
@@ -0,0 +1,79 @@
+#ifndef _ARITH_C_ /* -*- linux-c -*- */
+#define _ARITH_C_
+
+/** @file arith.
+ * @brief Implements 64-bit signed division/multiplication.
+ */
+
+struct context;
+void _stp_divmod64 (unsigned *errorcount, int64_t x, int64_t y,
+ int64_t *quo, int64_t *rem);
+
+
+/** Divide x by y. In case of overflow or division-by-zero,
+ * increment context errorcount, and return any old value.
+ */
+inline int64_t _stp_div64 (unsigned *errorcount, int64_t x, int64_t y)
+{
+ if (likely ((x >= LONG_MIN && x <= LONG_MAX) &&
+ (y >= LONG_MIN && y <= LONG_MAX)))
+ {
+ long xx = (long) x;
+ long yy = (long) y;
+ // check for division-by-zero and overflow
+ if (unlikely (yy == 0 || (xx == LONG_MIN && yy == -1)))
+ {
+ (*errorcount) ++;
+ return 0;
+ }
+ return xx / yy;
+ }
+ else
+ {
+ int64_t quo = 0;
+ _stp_divmod64 (errorcount, x, y, &quo, NULL);
+ return quo;
+ }
+}
+
+
+/** Modulo x by y. In case of overflow or division-by-zero,
+ * increment context errorcount, and return any old value.
+ */
+inline int64_t _stp_mod64 (unsigned *errorcount, int64_t x, int64_t y)
+{
+ if (likely ((x >= LONG_MIN && x <= LONG_MAX) &&
+ (y >= LONG_MIN && y <= LONG_MAX)))
+ {
+ long xx = (long) x;
+ long yy = (long) y;
+ // check for division-by-zero and overflow
+ if (unlikely (yy == 0 || (xx == LONG_MIN && yy == -1)))
+ {
+ (*errorcount) ++;
+ return 0;
+ }
+ return xx % yy;
+ }
+ else
+ {
+ int64_t rem = 0;
+ _stp_divmod64 (errorcount, x, y, NULL, &rem);
+ return rem;
+ }
+}
+
+
+/** Perform general long division/modulus. */
+void _stp_divmod64 (unsigned *errorcount, int64_t x, int64_t y,
+ int64_t *quo, int64_t *rem)
+{
+ // XXX: wimp out for now
+ (*errorcount) ++;
+ if (quo) *quo = 0;
+ if (rem) *rem = 0;
+}
+
+
+
+#endif /* _ARITH_C_ */
diff --git a/runtime/builtin_functions.h b/runtime/builtin_functions.h
deleted file mode 100644
index 505d073b..00000000
--- a/runtime/builtin_functions.h
+++ /dev/null
@@ -1,60 +0,0 @@
-#ifndef _BUILTIN_FUNCTIONS_
-#define _BUILTIN_FUNCTIONS_
-
-/* Builtin function definitions.
- * Copyright (C) 2005 Red Hat Inc.
- *
- * This file is part of systemtap, and is free software. You can
- * redistribute it and/or modify it under the terms of the GNU General
- * Public License (GPL); either version 2, or (at your option) any
- * later version.
- */
-
-/*
- * This file contains definitions for "builtin functions" which are
- * registered in the systemtap translator, but given no definition.
- * The translator emits calls to builtins exactly the same way it
- * emits calls to functions written in the systemtap language; the
- * only difference is that this file (or a C tapset) must supply the
- * definition.
- *
- * Every builtin function "foo" called by a systemtap script is
- * translated to a C call to a C function named "function_foo". This
- * is the function you must provide in this file. In addition, the
- * translator emits a
- *
- * #define _BUILTIN_FUNCTION_foo_
- *
- * symbol for each such function called, which you can use to elide
- * function definitions which are not used by a given systemtap
- * script.
- */
-
-#ifdef _BUILTIN_FUNCTION_printk_
-static void
-function_printk (struct context *c)
-{
- printk (KERN_INFO "%s\n", c->locals[c->nesting].function_printk.message);
-}
-#endif /* _BUILTIN_FUNCTION_printk_ */
-
-
-#ifdef _BUILTIN_FUNCTION_log_
-static void
-function_log (struct context *c)
-{
- _stp_log (c->locals[c->nesting].function_log.message);
-}
-#endif /* _BUILTIN_FUNCTION_log_ */
-
-
-#ifdef _BUILTIN_FUNCTION_warn_
-static void
-function_warn (struct context *c)
-{
- _stp_warn (c->locals[c->nesting].function_warn.message);
-}
-#endif /* _BUILTIN_FUNCTION_warn_ */
-
-
-#endif /* _BUILTIN_FUNCTIONS_ */
diff --git a/runtime/runtime.h b/runtime/runtime.h
index 5903bede..549738e1 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -55,6 +55,7 @@ static struct
#include "print.c"
#include "string.c"
+#include "arith.c"
/************* Module Stuff ********************/
int probe_start(void);