-
Notifications
You must be signed in to change notification settings - Fork 683
Refactor ecma value to store pointers directly in ecma values rather than compressing them. #1006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor ecma value to store pointers directly in ecma values rather than compressing them. #1006
Conversation
Overall: 10% speedup and 10K binary reduction. |
@@ -58,7 +58,8 @@ typedef enum | |||
ECMA_TYPE_SIMPLE, /**< simple value */ | |||
ECMA_TYPE_NUMBER, /**< 64-bit integer */ | |||
ECMA_TYPE_STRING, /**< pointer to description of a string */ | |||
ECMA_TYPE_OBJECT /**< pointer to description of an object */ | |||
ECMA_TYPE_OBJECT, /**< pointer to description of an object */ | |||
ECMA_TYPE___MAX = ECMA_TYPE_OBJECT /** highest value for ecma types */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK, the common suffix is __COUNT
instead of __MAX
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I introduced this form some time ago and use it nowadays. It is useful for switches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is 36 matches for __COUNT
and 6 matches for __MAX
in the current source base. I'd prefer to use only one of them, because they mean the same. But this could be in a followup patch. Leave as is, the code looks good to me. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a clarification comment: __MAX
is the highest possible value, __COUNT
is the number of possible values. If an enum is numbered from 0, as usual, then __COUNT == __MAX + 1
. However, if enum labels have "arbitrarily" set values, then either __MAX
or __COUNT
may make no sense to use.
41eb163
to
17e062b
Compare
LGTM, if @akiss77 has no objection, you can land it. |
ECMA_VALUE_VALUE_POS, | ||
ECMA_VALUE_VALUE_WIDTH); | ||
} /* ecma_get_value_value_field */ | ||
if (sizeof (void *) <= sizeof (ecma_value_t)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should rather be a compile-time decision. We've had similar before: #976 .
#if UINTPTR_MAX <= UINT32_MAX
That would be the equivalent, if I'm right. (A comment might be added pointing out that ecma_value_t
is a typedef to uint32_t
.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This IS a compile time decision. I don't understand this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a slight difference between if (0)
and #if 0
. You wrote the former, I prefer the latter.
if (0)
can be optiized away (and usually is, I admit) but still has to be valid code (e.g., it must reference existing structure fields, which may not be there because of preproc guards used elsewhere -- not applicable to this case), while #if 0
certainly is dead code that the complier does not even see. That's why the latter is used normally.
Even in the current code base, we (almost) never decide on type sizes with C code, but (almost) always with preprocessor conditionals. I've worked my way through 250+ occurrences of sizeof
in jerry-core, and the only exception I've found is ecma-helpers-external-pointers.c
, which uses if (sizeof (x) < sizeof (y))
style. Which it shouldn't either, IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And we don't need special comments. Compilers are clever enough to evaluate constants inside ifs/loops. E.g. while(true) is optimized with unconditional branches, and not load true into a register, and branch if that register is true. Or do {} while(false) is eliminated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the code is valid in both cases. I worry that we might change the type of ecma_value_t and forget about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My problem with ECMA_VALUE_MAX is that it suggests that ecma value is a number. In reality it is a bit structure stored in a word sized value. I would like to store small integer values in ecma_value_t in the future, and would like to reserve MAX and MIN stuff for that purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then go for the second alternative for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the following define
#define ECMA_VALUE_CAN_HOLD_POINTERS
This define could be used for other purposes, like encoding internal pointer properties. They also don't need compresiion on 32 bit systems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a commit on top of the current one to show how it would look like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
17e062b
to
dc2a51b
Compare
Patch updated. |
Much nicer to my eyes. |
…than compressing them. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
ce84b35
to
e92ecd4
Compare
Ecma value is 32 bit long, and only 3 bits are used for type and flags. The rest is enough for encoding 8 byte aligned pointers without compressing them.