summaryrefslogtreecommitdiff
path: root/libguile/vm-engine.h
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2010-05-02 13:14:58 +0200
committerAndy Wingo <wingo@pobox.com>2010-05-02 13:14:58 +0200
commitba2d960396c692986ee42274dc7f1d7eb72a9c89 (patch)
tree03f4e1595b8b5281773bf19574b5385a76efc8ab /libguile/vm-engine.h
parent41e64dd73c687400c3d88a974069d1676b26b6d7 (diff)
downloadguile-ba2d960396c692986ee42274dc7f1d7eb72a9c89.tar.gz
add SCM_UNLIKELY to CHECK_UNDERFLOW
* libguile/vm-engine.h (CHECK_OVERFLOW, CHECK_UNDERFLOW): Add SCM_UNLIKELY blocks. Fix off-by-one error in CHECK_UNDERFLOW. (PRE_CHECK_UNDERFLOW): New macro, for checking underflow before accessing the current sp. (POP): Use PRE_CHECK_UNDERFLOW.
Diffstat (limited to 'libguile/vm-engine.h')
-rw-r--r--libguile/vm-engine.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/libguile/vm-engine.h b/libguile/vm-engine.h
index 66e03c8b1..836648c30 100644
--- a/libguile/vm-engine.h
+++ b/libguile/vm-engine.h
@@ -259,17 +259,21 @@
#endif
#define CHECK_OVERFLOW() \
- if (sp >= stack_limit) \
+ if (SCM_UNLIKELY (sp >= stack_limit)) \
goto vm_error_stack_overflow
#define CHECK_UNDERFLOW() \
- if (sp < SCM_FRAME_UPPER_ADDRESS (fp)) \
+ if (SCM_UNLIKELY (sp <= SCM_FRAME_UPPER_ADDRESS (fp))) \
+ goto vm_error_stack_underflow;
+
+#define PRE_CHECK_UNDERFLOW(N) \
+ if (SCM_UNLIKELY (sp - N <= SCM_FRAME_UPPER_ADDRESS (fp))) \
goto vm_error_stack_underflow;
#define PUSH(x) do { sp++; CHECK_OVERFLOW (); *sp = x; } while (0)
#define DROP() do { sp--; CHECK_UNDERFLOW (); NULLSTACK (1); } while (0)
-#define DROPN(_n) do { sp -= (_n); CHECK_UNDERFLOW (); NULLSTACK (_n); } while (0)
-#define POP(x) do { x = *sp; DROP (); } while (0)
+#define DROPN(_n) do { sp -= (_n); CHECK_UNDERFLOW (); NULLSTACK (_n); } while (0)
+#define POP(x) do { PRE_CHECK_UNDERFLOW (1); x = *sp--; NULLSTACK (1); } while (0)
/* A fast CONS. This has to be fast since its used, for instance, by
POP_LIST when fetching a function's argument list. Note: `scm_cell' is an