Skip to content

Commit 4ff9d01

Browse files
author
Robert Fancsik
committed
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
put
1 parent 41a6631 commit 4ff9d01

File tree

2 files changed

+55
-50
lines changed

2 files changed

+55
-50
lines changed

jerry-core/vm/vm.c

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ vm_super_call (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
612612
else
613613
{
614614
frame_ctx_p->byte_code_p = byte_code_p;
615-
vm_put_result_flags_t put_result_flags = (1 << ((opcode - CBC_EXT_SUPER_CALL) % 3));
615+
vm_put_result_flags_t put_result_flags = (opcode - CBC_EXT_SUPER_CALL) % 3;
616616

617617
if (!(put_result_flags & (VM_PUT_RESULT_STACK | VM_PUT_RESULT_BLOCK)))
618618
{
@@ -701,7 +701,7 @@ vm_spread_operation (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
701701
}
702702
else
703703
{
704-
vm_put_result_flags_t put_result_flags = (1 << ((opcode - CBC_EXT_SPREAD_CALL) % 3));
704+
vm_put_result_flags_t put_result_flags = (opcode - CBC_EXT_SPREAD_CALL) % 3;
705705

706706
if (!(put_result_flags & (VM_PUT_RESULT_STACK | VM_PUT_RESULT_BLOCK)))
707707
{
@@ -778,7 +778,7 @@ opfunc_call (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
778778
{
779779
frame_ctx_p->byte_code_p = byte_code_p;
780780
ecma_free_value (*(--stack_top_p));
781-
vm_put_result_flags_t put_result_flags = (1 << ((opcode - CBC_CALL) % 3));
781+
vm_put_result_flags_t put_result_flags = (opcode - CBC_CALL) % 3;
782782

783783
if (!(put_result_flags & (VM_PUT_RESULT_STACK | VM_PUT_RESULT_BLOCK)))
784784
{
@@ -907,13 +907,12 @@ opfunc_construct (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
907907
*/
908908
#define VM_LAST_CONTEXT_END() (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth)
909909

910-
#define VM_DECODED_BRANCH_OFFSET 256
911-
#define VM_LITERAL_RESOLVE_OFFSET 256
910+
#define VM_OPCODE_DECODED_ARG_OFFSET 256
912911

913-
#define VM_OPCODE_BRANCH(opcode) (opcode + VM_DECODED_BRANCH_OFFSET)
914-
#define VM_OPCODE_ONE_LITERAL(opcode) (opcode + VM_LITERAL_RESOLVE_OFFSET)
915-
#define VM_OPCODE_TWO_LITERALS(opcode) (VM_OPCODE_ONE_LITERAL (opcode) + VM_LITERAL_RESOLVE_OFFSET)
916-
#define VM_OPCODE_LAST VM_OPCODE_TWO_LITERALS (VM_LITERAL_RESOLVE_OFFSET)
912+
#define VM_OPCODE_BRANCH(opcode) (opcode + VM_OPCODE_DECODED_ARG_OFFSET)
913+
#define VM_OPCODE_ONE_LITERAL(opcode) (opcode + VM_OPCODE_DECODED_ARG_OFFSET)
914+
#define VM_OPCODE_TWO_LITERALS(opcode) (VM_OPCODE_ONE_LITERAL (opcode) + VM_OPCODE_DECODED_ARG_OFFSET)
915+
#define VM_OPCODE_LAST VM_OPCODE_TWO_LITERALS (VM_OPCODE_DECODED_ARG_OFFSET)
917916

918917
#define VM_EXT_OPCODE(opcode) (VM_OPCODE_LAST + opcode)
919918

@@ -936,10 +935,10 @@ op: \
936935
VM_OPCODE_OP_LITERAL_LITERAL (op##_TWO_LITERALS); \
937936
VM_OPCODE_OP_STACK_STACK (op)
938937

939-
#define VM_EXT_OPCODE_BRANCH(ext_opcode) (VM_EXT_OPCODE (ext_opcode) + VM_DECODED_BRANCH_OFFSET)
940-
#define VM_EXT_OPCODE_ONE_LITERAL(ext_opcode) (VM_EXT_OPCODE (ext_opcode) + VM_LITERAL_RESOLVE_OFFSET)
941-
#define VM_EXT_OPCODE_TWO_LITERALS(ext_opcode) (VM_EXT_OPCODE_ONE_LITERAL (ext_opcode) + VM_LITERAL_RESOLVE_OFFSET)
942-
#define VM_EXT_OPCODE_LAST VM_EXT_OPCODE_TWO_LITERALS (VM_LITERAL_RESOLVE_OFFSET)
938+
#define VM_EXT_OPCODE_BRANCH(ext_opcode) (VM_EXT_OPCODE (ext_opcode) + VM_OPCODE_DECODED_ARG_OFFSET)
939+
#define VM_EXT_OPCODE_ONE_LITERAL(ext_opcode) (VM_EXT_OPCODE (ext_opcode) + VM_OPCODE_DECODED_ARG_OFFSET)
940+
#define VM_EXT_OPCODE_TWO_LITERALS(ext_opcode) (VM_EXT_OPCODE_ONE_LITERAL (ext_opcode) + VM_OPCODE_DECODED_ARG_OFFSET)
941+
#define VM_EXT_OPCODE_LAST VM_EXT_OPCODE_TWO_LITERALS (VM_OPCODE_DECODED_ARG_OFFSET)
943942

944943
#define VM_EXT_OPCODE_BRANCH_CASE(op) \
945944
VM_EXT_OPCODE_BRANCH (op) : case VM_EXT_OPCODE_BRANCH (op##_2) : case VM_EXT_OPCODE_BRANCH (op##_3)
@@ -1310,7 +1309,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
13101309
byte_code_p += 3;
13111310
}
13121311

1313-
opcode = (uint16_t) (opcode + VM_LITERAL_RESOLVE_OFFSET);
1312+
opcode = (uint16_t) (opcode + VM_OPCODE_DECODED_ARG_OFFSET);
13141313
goto dispatch_opcode;
13151314

13161315
decode_backward_branch_1:
@@ -1359,15 +1358,15 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
13591358
}
13601359
#endif /* JERRY_VM_HALT */
13611360

1362-
opcode = (uint16_t) (opcode + VM_LITERAL_RESOLVE_OFFSET);
1361+
opcode = (uint16_t) (opcode + VM_OPCODE_DECODED_ARG_OFFSET);
13631362
goto dispatch_opcode;
13641363

13651364
uint16_t literal_index;
13661365
decode_one_literal:
13671366
READ_LITERAL_INDEX (literal_index);
13681367
READ_LITERAL (literal_index, left_value);
13691368

1370-
opcode = (uint16_t) (opcode + VM_LITERAL_RESOLVE_OFFSET);
1369+
opcode = (uint16_t) (opcode + VM_OPCODE_DECODED_ARG_OFFSET);
13711370
goto dispatch_opcode;
13721371

13731372
decode_second_literal:
@@ -1389,7 +1388,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
13891388
READ_LITERAL_INDEX (literal_index);
13901389
READ_LITERAL (literal_index, right_value);
13911390

1392-
opcode = (uint16_t) (opcode + VM_LITERAL_RESOLVE_OFFSET);
1391+
opcode = (uint16_t) (opcode + VM_OPCODE_DECODED_ARG_OFFSET);
13931392
goto dispatch_opcode;
13941393
}
13951394
case CBC_EXT_OPCODE:
@@ -1673,8 +1672,8 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
16731672
VM_OPCODE_OP_LITERAL (CBC_SET_VAR_FUNC);
16741673
result = left_value;
16751674
left_value = ECMA_VALUE_UNDEFINED;
1676-
put_result_flags = VM_PUT_RESULT_IDENT;
1677-
break;
1675+
put_result_flags = VM_PUT_RESULT_NONE;
1676+
goto dispatch_put_ident;
16781677
}
16791678
#if JERRY_ESNEXT
16801679
case VM_EXT_OPCODE (CBC_EXT_CREATE_VAR_EVAL):
@@ -3504,8 +3503,6 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
35043503
}
35053504

35063505
ecma_free_value (left_value);
3507-
left_value = ECMA_VALUE_UNDEFINED;
3508-
35093506
break;
35103507
}
35113508
#endif /* JERRY_BUILTIN_BIGINT */
@@ -3535,7 +3532,6 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
35353532
else
35363533
{
35373534
result = ecma_update_float_number (left_value, result_number + increase);
3538-
left_value = ECMA_VALUE_UNDEFINED;
35393535
}
35403536
break;
35413537

@@ -3567,20 +3563,19 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
35673563
put_result_flags &= (uint8_t) ~VM_PUT_RESULT_BLOCK;
35683564
}
35693565

3570-
left_value = ECMA_VALUE_UNDEFINED;
35713566
break;
35723567
}
35733568
case VM_OPCODE_PUT_RESULT_CASE (CBC_ASSIGN):
35743569
{
35753570
VM_POP_STACK (result);
3576-
put_result_flags = (uint8_t) (VM_PUT_RESULT_REFERENCE | VM_PUT_RESULT_FROM_OPCODE (opcode, CBC_ASSIGN));
3577-
break;
3571+
put_result_flags = (uint8_t) (opcode - CBC_ASSIGN);
3572+
goto dispatch_put_reference;
35783573
}
35793574
case VM_OPCODE_PUT_RESULT_CASE (CBC_ASSIGN_SET_IDENT):
35803575
{
35813576
VM_POP_STACK (result);
3582-
put_result_flags = (uint8_t) (VM_PUT_RESULT_IDENT | VM_PUT_RESULT_FROM_OPCODE (opcode, CBC_ASSIGN_SET_IDENT));
3583-
break;
3577+
put_result_flags = (uint8_t) (opcode - CBC_ASSIGN_SET_IDENT);
3578+
goto dispatch_put_ident;
35843579
}
35853580
case VM_OPCODE_ONE_LITERAL_PUT_RESULT_CASE (CBC_ASSIGN_LITERAL_SET_IDENT):
35863581
{
@@ -3589,10 +3584,8 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
35893584
CBC_ASSIGN_LITERAL_SET_IDENT_BLOCK);
35903585

35913586
result = left_value;
3592-
left_value = ECMA_VALUE_UNDEFINED;
3593-
put_result_flags =
3594-
(uint8_t) (VM_PUT_RESULT_IDENT | VM_PUT_RESULT_FROM_OPCODE (opcode, CBC_ASSIGN_LITERAL_SET_IDENT));
3595-
break;
3587+
put_result_flags = (uint8_t) (opcode - CBC_ASSIGN_LITERAL_SET_IDENT);
3588+
goto dispatch_put_ident;
35963589
}
35973590
case CBC_MOV_IDENT:
35983591
{
@@ -3614,10 +3607,8 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
36143607

36153608
result = stack_top_p[-1];
36163609
stack_top_p[-1] = left_value;
3617-
left_value = ECMA_VALUE_UNDEFINED;
3618-
put_result_flags =
3619-
(uint8_t) (VM_PUT_RESULT_REFERENCE | VM_PUT_RESULT_FROM_OPCODE (opcode, CBC_ASSIGN_PROP_LITERAL));
3620-
break;
3610+
put_result_flags = (uint8_t) (opcode - CBC_ASSIGN_PROP_LITERAL);
3611+
goto dispatch_put_reference;
36213612
}
36223613
case VM_OPCODE_ONE_LITERAL_PUT_RESULT_CASE (CBC_ASSIGN_PROP_THIS_LITERAL):
36233614
{
@@ -3628,10 +3619,8 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
36283619
result = stack_top_p[-1];
36293620
stack_top_p[-1] = ecma_copy_value (frame_ctx_p->this_binding);
36303621
*stack_top_p++ = left_value;
3631-
left_value = ECMA_VALUE_UNDEFINED;
3632-
put_result_flags =
3633-
(uint8_t) (VM_PUT_RESULT_REFERENCE | VM_PUT_RESULT_FROM_OPCODE (opcode, CBC_ASSIGN_PROP_THIS_LITERAL));
3634-
break;
3622+
put_result_flags = (uint8_t) (opcode - CBC_ASSIGN_PROP_THIS_LITERAL);
3623+
goto dispatch_put_reference;
36353624
}
36363625
case CBC_RETURN_FUNCTION_END:
36373626
{
@@ -5318,17 +5307,19 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
53185307
{
53195308
uint16_t literal_index;
53205309

5310+
dispatch_put_ident:
53215311
READ_LITERAL_INDEX (literal_index);
53225312

53235313
if (literal_index < register_end)
53245314
{
53255315
ecma_fast_free_value (VM_GET_REGISTER (frame_ctx_p, literal_index));
53265316
VM_GET_REGISTER (frame_ctx_p, literal_index) = result;
53275317

5328-
if (put_result_flags & (VM_PUT_RESULT_STACK | VM_PUT_RESULT_BLOCK))
5318+
if (!(put_result_flags & (VM_PUT_RESULT_STACK | VM_PUT_RESULT_BLOCK)))
53295319
{
5330-
result = ecma_fast_copy_value (result);
5320+
continue;
53315321
}
5322+
result = ecma_fast_copy_value (result);
53325323
}
53335324
else
53345325
{
@@ -5341,19 +5332,23 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
53415332
{
53425333
ecma_free_value (result);
53435334
result = put_value_result;
5335+
left_value = ECMA_VALUE_UNDEFINED;
53445336
goto error;
53455337
}
53465338

53475339
if (!(put_result_flags & (VM_PUT_RESULT_STACK | VM_PUT_RESULT_BLOCK)))
53485340
{
53495341
ecma_fast_free_value (result);
5342+
continue;
53505343
}
53515344
}
53525345
}
53535346
else if (put_result_flags & VM_PUT_RESULT_REFERENCE)
53545347
{
5355-
ecma_value_t property = *(--stack_top_p);
5356-
ecma_value_t base = *(--stack_top_p);
5348+
ecma_value_t property, base;
5349+
dispatch_put_reference:
5350+
property = *(--stack_top_p);
5351+
base = *(--stack_top_p);
53575352

53585353
if (base == ECMA_VALUE_REGISTER_REF)
53595354
{
@@ -5363,7 +5358,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
53635358

53645359
if (!(put_result_flags & (VM_PUT_RESULT_STACK | VM_PUT_RESULT_BLOCK)))
53655360
{
5366-
goto free_both_values;
5361+
continue;
53675362
}
53685363
result = ecma_fast_copy_value (result);
53695364
}
@@ -5375,27 +5370,36 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
53755370
{
53765371
ecma_free_value (result);
53775372
result = set_value_result;
5373+
left_value = ECMA_VALUE_UNDEFINED;
53785374
goto error;
53795375
}
53805376

53815377
if (!(put_result_flags & (VM_PUT_RESULT_STACK | VM_PUT_RESULT_BLOCK)))
53825378
{
53835379
ecma_fast_free_value (result);
5384-
goto free_both_values;
5380+
continue;
53855381
}
53865382
}
53875383
}
5384+
else if (!(put_result_flags & (VM_PUT_RESULT_STACK | VM_PUT_RESULT_BLOCK)))
5385+
{
5386+
ecma_fast_free_value (result);
5387+
continue;
5388+
}
53885389

53895390
if (put_result_flags & VM_PUT_RESULT_STACK)
53905391
{
53915392
*stack_top_p++ = result;
53925393
}
5393-
else if (put_result_flags & VM_PUT_RESULT_BLOCK)
5394+
else
53945395
{
5396+
JERRY_ASSERT (put_result_flags & VM_PUT_RESULT_BLOCK);
53955397
ecma_fast_free_value (VM_GET_REGISTER (frame_ctx_p, 0));
53965398
VM_GET_REGISTERS (frame_ctx_p)[0] = result;
53975399
}
53985400

5401+
continue;
5402+
53995403
free_both_values:
54005404
ecma_fast_free_value (right_value);
54015405
free_left_value:

jerry-core/vm/vm.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ typedef enum
3636
{
3737
/* These 3 flags must be in this order */
3838
VM_PUT_RESULT_NONE = 0,
39-
VM_PUT_RESULT_STACK = 1 << 1,
40-
VM_PUT_RESULT_BLOCK = 1 << 2,
41-
VM_PUT_RESULT_IDENT = 1 << 3,
39+
VM_PUT_RESULT_STACK = 1 << 0,
40+
VM_PUT_RESULT_BLOCK = 1 << 1,
41+
42+
VM_PUT_RESULT_IDENT = 1 << 2,
4243
VM_PUT_RESULT_REFERENCE = 1 << 4,
4344
VM_PUT_RESULT_DECR = 1 << 5,
4445
VM_PUT_RESULT_POST = 1 << 6,
4546
} vm_put_result_flags_t;
4647

47-
#define VM_PUT_RESULT_FROM_OPCODE(current_op, base_op) (1 << ((current_op) - (base_op)))
48+
#define VM_PUT_RESULT_FROM_OPCODE(current_op, base_op) ((current_op) - (base_op))
4849

4950
/**
5051
* Non-recursive vm_loop: the vm_loop can be suspended

0 commit comments

Comments
 (0)