@@ -62,4 +62,53 @@ I32_BINOP(i32_add, +)
6262I32_BINOP (i32_sub , - )
6363I32_BINOP (i32_mul , * )
6464
65+ #define I32_CMP (name , op ) \
66+ void name (StencilContext * ctx ) { \
67+ ctx -> stack_pointer -= 1 ; \
68+ \
69+ int32_t b = (int32_t )ctx -> stack [ctx -> stack_pointer ]; \
70+ int32_t a = (int32_t )ctx -> stack [ctx -> stack_pointer - 1 ]; \
71+ \
72+ ctx -> stack [ctx -> stack_pointer - 1 ] = (a op b ) ? 1 : 0 ; \
73+ ctx -> pc += 1 ; \
74+ \
75+ CHECK_SNAPSHOT (ctx ); \
76+ __attribute__((musttail )) return ctx -> fn_table [ctx -> pc ](ctx ); \
77+ }
78+
79+ I32_CMP (i32_lt_signed , < )
80+ I32_CMP (i32_gt_signed , > )
81+ I32_CMP (i32_le_signed , <=)
82+ I32_CMP (i32_ge_signed , >=)
83+ I32_CMP (i32_eq , = = )
84+ I32_CMP (i32_ne , != )
85+
86+ #define U32_CMP (name , op ) \
87+ void name (StencilContext * ctx ) { \
88+ ctx -> stack_pointer -= 1 ; \
89+ \
90+ uint32_t b = (uint32_t )ctx -> stack [ctx -> stack_pointer ]; \
91+ uint32_t a = (uint32_t )ctx -> stack [ctx -> stack_pointer - 1 ]; \
92+ \
93+ ctx -> stack [ctx -> stack_pointer - 1 ] = (a op b ) ? 1 : 0 ; \
94+ ctx -> pc += 1 ; \
95+ \
96+ CHECK_SNAPSHOT (ctx ); \
97+ __attribute__((musttail )) return ctx -> fn_table [ctx -> pc ](ctx ); \
98+ }
99+
100+ U32_CMP (i32_lt_unsigned , < )
101+ U32_CMP (i32_gt_unsigned , > )
102+ U32_CMP (i32_le_unsigned , <=)
103+ U32_CMP (i32_ge_unsigned , >=)
104+
105+ void i32_eq_zero (StencilContext * ctx ) {
106+ uint32_t a = (uint32_t )ctx -> stack [ctx -> stack_pointer - 1 ];
107+ ctx -> stack [ctx -> stack_pointer - 1 ] = (a == 0 ) ? 1 : 0 ;
108+ ctx -> pc += 1 ;
109+
110+ CHECK_SNAPSHOT (ctx );
111+ __attribute__((musttail )) return ctx -> fn_table [ctx -> pc ](ctx );
112+ }
113+
65114void return_ (StencilContext * ctx ) { ctx -> exit_reason = EXIT_RETURN ; }
0 commit comments