@@ -4337,9 +4337,6 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
4337
4337
uint32_t unit ;
4338
4338
DECODE_LITERAL (unit , pc );
4339
4339
term src ;
4340
- #ifdef IMPL_EXECUTE_LOOP
4341
- const uint8_t * src_pc = pc ;
4342
- #endif
4343
4340
DECODE_COMPACT_TERM (src , pc )
4344
4341
term flags ;
4345
4342
UNUSED (flags );
@@ -4367,8 +4364,10 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
4367
4364
4368
4365
size_t src_size = term_binary_size (src );
4369
4366
TRIM_LIVE_REGS (live );
4367
+ // there is always room for a MAX_REG + 1 register, used as working register
4368
+ x_regs [live ] = src ;
4370
4369
// TODO: further investigate extra_val
4371
- if (UNLIKELY (memory_ensure_free_with_roots (ctx , src_size + term_binary_heap_size (size_val / 8 ) + extra_val , live , x_regs , MEMORY_CAN_SHRINK ) != MEMORY_GC_OK )) {
4370
+ if (UNLIKELY (memory_ensure_free_with_roots (ctx , src_size + term_binary_heap_size (size_val / 8 ) + extra_val , live + 1 , x_regs , MEMORY_CAN_SHRINK ) != MEMORY_GC_OK )) {
4372
4371
RAISE_ERROR (OUT_OF_MEMORY_ATOM );
4373
4372
}
4374
4373
#endif
@@ -4378,7 +4377,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
4378
4377
4379
4378
#ifdef IMPL_EXECUTE_LOOP
4380
4379
TRACE ("bs_append/8, fail=%u size=%li unit=%u src=0x%lx dreg=%c%i\n" , (unsigned ) fail , size_val , (unsigned ) unit , src , T_DEST_REG (dreg ));
4381
- DECODE_COMPACT_TERM ( src , src_pc )
4380
+ src = x_regs [ live ];
4382
4381
term t = term_create_empty_binary (src_size + size_val / 8 , & ctx -> heap , ctx -> global );
4383
4382
memcpy ((void * ) term_binary_data (t ), (void * ) term_binary_data (src ), src_size );
4384
4383
@@ -5104,9 +5103,6 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
5104
5103
uint32_t fail ;
5105
5104
DECODE_LABEL (fail , pc )
5106
5105
term src ;
5107
- #ifdef IMPL_EXECUTE_LOOP
5108
- const uint8_t * src_pc = pc ;
5109
- #endif
5110
5106
DECODE_COMPACT_TERM (src , pc );
5111
5107
uint32_t live ;
5112
5108
DECODE_LITERAL (live , pc );
@@ -5158,8 +5154,10 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
5158
5154
term_set_match_state_offset (src , bs_offset + size_val * unit );
5159
5155
5160
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 ;
5161
5159
size_t heap_size = term_sub_binary_heap_size (bs_bin , size_val );
5162
- 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 )) {
5163
5161
RAISE_ERROR (OUT_OF_MEMORY_ATOM );
5164
5162
}
5165
5163
#endif
@@ -5168,9 +5166,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
5168
5166
DECODE_DEST_REGISTER (dreg , pc );
5169
5167
5170
5168
#ifdef IMPL_EXECUTE_LOOP
5171
- // re-compute src
5172
- DECODE_COMPACT_TERM (src , src_pc );
5173
- bs_bin = term_get_match_state_binary (src );
5169
+ bs_bin = x_regs [live ];
5174
5170
5175
5171
term t = term_maybe_create_sub_binary (bs_bin , bs_offset / unit , size_val , & ctx -> heap , ctx -> global );
5176
5172
WRITE_REGISTER (dreg , t );
0 commit comments