Skip to content

Implement compact byte code (CBC) support in Jerry #630

Closed
@zherczeg

Description

@zherczeg

Compact byte code (CBC) is the next generation of byte code for Jerry, which can reduce the byte code size around 50%. It also solves parser memory issues, left-hand-side issues, etc. The project is in its early phase, but the following examples shows the idea. All values are stored on a stack, all operations happen there. Several byte codes are "complex", so they do multiple things.

// a + b

   0 : [  1] CBC_PUSH_IDENT 1:literal<b>
   2 : [  1] CBC_BINARY_ADD_LEFT_LITERAL 0:literal<a>
   4 : [  0] CBC_POP
Parse successfully completed. Generated byte code size: 5 bytes

In Jerry: 8 bytes (37.5% saving)

  2:           assignment  130    6    0     // tmp130 = a : TYPEOF(a);
  3:             addition  131  130    1     // tmp131 = tmp130 + b;


// a = b + -c * ((d.c)++ - e)

   0 : [  1] CBC_UNARY_NEGATE_LITERAL 2:literal<c>
   2 : [  2] CBC_PUSH_IDENT 3:literal<d>
   4 : [  2] CBC_POST_INCR_PROP_STRING_PUSH_RESULT 4:string<c>
   6 : [  2] CBC_BINARY_SUBTRACT_RIGHT_LITERAL 5:literal<e>
   8 : [  1] CBC_MULTIPLY
   9 : [  1] CBC_BINARY_ADD_LEFT_LITERAL 1:literal<b>
  11 : [  0] CBC_ASSIGN_IDENT 0:literal<a>
Parse successfully completed. Generated byte code size: 13 bytes

In Jerry: 36 bytes (63.8% saving)

  2:           assignment  130    6    0     // tmp130 = b : TYPEOF(b);
  3:          unary_minus  131    1          // tmp131 = -c;
  4:           assignment  132    5    1     // tmp132 = 'c': STRING;
  5:          prop_getter  133    2  132     // tmp133 = d[tmp132];
  6:            post_incr  134  133          // tmp134 = tmp133++;
  7:         substraction  135  134    3     // tmp135 = tmp134 - e;
  8:       multiplication  136  131  135     // tmp136 = tmp131 * tmp135;
  9:             addition  137  130  136     // tmp137 = tmp130 + tmp136;
 10:           assignment    4    6  137     // a = tmp137 : TYPEOF(tmp137);

Of course nothing is set in stone at the moment, all suggestion are welcome. Especially the byte code definitions, which is the most important part of the project.

See https://github.com/Samsung/jerryscript/tree/compact_byte_code_supp_dev

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions