Skip to content

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions jerry-core/ecma/base/ecma-globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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. :)

Copy link
Member

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.

} ecma_type_t;

/**
Expand All @@ -85,34 +86,33 @@ typedef enum
/**
* Description of an ecma value
*
* Bit-field structure: type (2) | error (1) | value (ECMA_POINTER_FIELD_WIDTH)
* Bit-field structure: type (2) | error (1) | value (29)
*/
typedef uint32_t ecma_value_t;

#if UINTPTR_MAX <= UINT32_MAX

/**
* Value type (ecma_type_t)
* MEM_ALIGNMENT_LOG aligned pointers can be stored directly in ecma_value_t
*/
#define ECMA_VALUE_TYPE_POS (0)
#define ECMA_VALUE_TYPE_WIDTH (2)
#define ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY

#endif /* UINTPTR_MAX <= UINT32_MAX */

/**
* Value is error (boolean)
* Mask for ecma types in ecma_type_t
*/
#define ECMA_VALUE_ERROR_POS (ECMA_VALUE_TYPE_POS + \
ECMA_VALUE_TYPE_WIDTH)
#define ECMA_VALUE_ERROR_WIDTH (1)
#define ECMA_VALUE_TYPE_MASK 0x3u

/**
* Simple value (ecma_simple_value_t) or compressed pointer to value (depending on value_type)
* Error flag in ecma_type_t
*/
#define ECMA_VALUE_VALUE_POS (ECMA_VALUE_ERROR_POS + \
ECMA_VALUE_ERROR_WIDTH)
#define ECMA_VALUE_VALUE_WIDTH (ECMA_POINTER_FIELD_WIDTH)
#define ECMA_VALUE_ERROR_FLAG 0x4u

/**
* Size of ecma value description, in bits
* Shift for value part in ecma_type_t
*/
#define ECMA_VALUE_SIZE (ECMA_VALUE_VALUE_POS + ECMA_VALUE_VALUE_WIDTH)
#define ECMA_VALUE_SHIFT 3

/**
* Internal properties' identifiers.
Expand Down
Loading