@@ -5103,9 +5103,6 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
5103
5103
uint32_t fail ;
5104
5104
DECODE_LABEL (fail , pc )
5105
5105
term src ;
5106
- #ifdef IMPL_EXECUTE_LOOP
5107
- const uint8_t * src_pc = pc ;
5108
- #endif
5109
5106
DECODE_COMPACT_TERM (src , pc );
5110
5107
uint32_t live ;
5111
5108
DECODE_LITERAL (live , pc );
@@ -5157,8 +5154,10 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
5157
5154
term_set_match_state_offset (src , bs_offset + size_val * unit );
5158
5155
5159
5156
TRIM_LIVE_REGS (live );
5157
+ // there is always room for a MAX_REG + 1 register, used as working register
5158
+ x_regs [live ] = bs_bin ;
5160
5159
size_t heap_size = term_sub_binary_heap_size (bs_bin , size_val );
5161
- if (UNLIKELY (memory_ensure_free_with_roots (ctx , heap_size , live , x_regs , MEMORY_CAN_SHRINK ) != MEMORY_GC_OK )) {
5160
+ if (UNLIKELY (memory_ensure_free_with_roots (ctx , heap_size , live + 1 , x_regs , MEMORY_CAN_SHRINK ) != MEMORY_GC_OK )) {
5162
5161
RAISE_ERROR (OUT_OF_MEMORY_ATOM );
5163
5162
}
5164
5163
#endif
@@ -5167,9 +5166,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
5167
5166
DECODE_DEST_REGISTER (dreg , pc );
5168
5167
5169
5168
#ifdef IMPL_EXECUTE_LOOP
5170
- // re-compute src
5171
- DECODE_COMPACT_TERM (src , src_pc );
5172
- bs_bin = term_get_match_state_binary (src );
5169
+ bs_bin = x_regs [live ];
5173
5170
5174
5171
term t = term_maybe_create_sub_binary (bs_bin , bs_offset / unit , size_val , & ctx -> heap , ctx -> global );
5175
5172
WRITE_REGISTER (dreg , t );
0 commit comments