2022-07-17 09:14:24 -07:00
|
|
|
// It is convenient to have a single panic routine, which we can jump to from
|
|
|
|
|
// anywhere.
|
|
|
|
|
global panic:
|
|
|
|
|
JUMPDEST
|
|
|
|
|
PANIC
|
|
|
|
|
|
|
|
|
|
// Consumes the top element and asserts that it is zero.
|
|
|
|
|
%macro assert_zero
|
2022-07-20 15:05:09 -07:00
|
|
|
%jumpi(panic)
|
2022-07-17 09:14:24 -07:00
|
|
|
%endmacro
|
|
|
|
|
|
|
|
|
|
// Consumes the top element and asserts that it is nonzero.
|
|
|
|
|
%macro assert_nonzero
|
|
|
|
|
ISZERO
|
2022-07-20 15:05:09 -07:00
|
|
|
%jumpi(panic)
|
2022-07-17 09:14:24 -07:00
|
|
|
%endmacro
|
|
|
|
|
|
|
|
|
|
%macro assert_eq
|
|
|
|
|
EQ
|
|
|
|
|
%assert_nonzero
|
|
|
|
|
%endmacro
|
|
|
|
|
|
|
|
|
|
%macro assert_lt
|
2022-07-17 09:23:37 -07:00
|
|
|
// %assert_zero is cheaper than %assert_nonzero, so we will leverage the
|
|
|
|
|
// fact that (x < y) == !(x >= y).
|
|
|
|
|
GE
|
|
|
|
|
%assert_zero
|
2022-07-17 09:14:24 -07:00
|
|
|
%endmacro
|
|
|
|
|
|
|
|
|
|
%macro assert_le
|
2022-07-17 09:23:37 -07:00
|
|
|
// %assert_zero is cheaper than %assert_nonzero, so we will leverage the
|
|
|
|
|
// fact that (x <= y) == !(x > y).
|
|
|
|
|
GT
|
|
|
|
|
%assert_zero
|
2022-07-17 09:14:24 -07:00
|
|
|
%endmacro
|
|
|
|
|
|
|
|
|
|
%macro assert_gt
|
2022-07-17 09:23:37 -07:00
|
|
|
// %assert_zero is cheaper than %assert_nonzero, so we will leverage the
|
|
|
|
|
// fact that (x > y) == !(x <= y).
|
|
|
|
|
LE
|
|
|
|
|
%assert_zero
|
2022-07-17 09:14:24 -07:00
|
|
|
%endmacro
|
|
|
|
|
|
|
|
|
|
%macro assert_ge
|
2022-07-17 09:23:37 -07:00
|
|
|
// %assert_zero is cheaper than %assert_nonzero, so we will leverage the
|
|
|
|
|
// fact that (x >= y) == !(x < y).
|
|
|
|
|
LT
|
|
|
|
|
%assert_zero
|
2022-07-17 09:14:24 -07:00
|
|
|
%endmacro
|
|
|
|
|
|
|
|
|
|
%macro assert_eq_const(c)
|
2022-07-20 15:05:09 -07:00
|
|
|
%eq_const($c)
|
2022-07-17 09:14:24 -07:00
|
|
|
%assert_nonzero
|
|
|
|
|
%endmacro
|
|
|
|
|
|
|
|
|
|
%macro assert_lt_const(c)
|
|
|
|
|
// %assert_zero is cheaper than %assert_nonzero, so we will leverage the
|
|
|
|
|
// fact that (x < c) == !(x >= c).
|
2022-07-20 15:05:09 -07:00
|
|
|
%ge_const($c)
|
2022-07-17 09:14:24 -07:00
|
|
|
%assert_zero
|
|
|
|
|
%endmacro
|
|
|
|
|
|
|
|
|
|
%macro assert_le_const(c)
|
|
|
|
|
// %assert_zero is cheaper than %assert_nonzero, so we will leverage the
|
|
|
|
|
// fact that (x <= c) == !(x > c).
|
2022-07-20 15:05:09 -07:00
|
|
|
%gt_const($c)
|
2022-07-17 09:14:24 -07:00
|
|
|
%assert_zero
|
|
|
|
|
%endmacro
|
|
|
|
|
|
|
|
|
|
%macro assert_gt_const(c)
|
|
|
|
|
// %assert_zero is cheaper than %assert_nonzero, so we will leverage the
|
|
|
|
|
// fact that (x > c) == !(x <= c).
|
2022-07-20 15:05:09 -07:00
|
|
|
%le_const($c)
|
2022-07-17 09:14:24 -07:00
|
|
|
%assert_zero
|
|
|
|
|
%endmacro
|
|
|
|
|
|
|
|
|
|
%macro assert_ge_const(c)
|
|
|
|
|
// %assert_zero is cheaper than %assert_nonzero, so we will leverage the
|
|
|
|
|
// fact that (x >= c) == !(x < c).
|
2022-07-20 15:05:09 -07:00
|
|
|
%lt_const($c)
|
2022-07-17 09:14:24 -07:00
|
|
|
%assert_zero
|
|
|
|
|
%endmacro
|