Skip to content

Introduce integer ecma-value representation to reduce the double allocations #1039

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 1 commit into from
May 17, 2016
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
61 changes: 55 additions & 6 deletions jerry-core/ecma/base/ecma-globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
*/
typedef enum
{
ECMA_TYPE_SIMPLE, /**< simple value */
ECMA_TYPE_NUMBER, /**< 64-bit integer */
ECMA_TYPE_DIRECT, /**< directly encoded value, a 28 bit signed integer or a simple value */
ECMA_TYPE_FLOAT, /**< pointer to a 64 or 32 bit floating point number */
ECMA_TYPE_STRING, /**< pointer to description of a string */
ECMA_TYPE_OBJECT, /**< pointer to description of an object */
ECMA_TYPE___MAX = ECMA_TYPE_OBJECT /** highest value for ecma types */
Expand All @@ -68,10 +68,10 @@ typedef enum
typedef enum
{
/**
* Empty value is implementation defined value, used for:
* - representing empty value in completion values (see also: ECMA-262 v5, 8.9 Completion specification type);
* - values of uninitialized immutable bindings;
* - values of empty register variables.
* Empty value is implementation defined value, used for representing:
* - empty (uninitialized) values
* - immutable binding values
* - special register or stack values for vm
*/
ECMA_SIMPLE_VALUE_EMPTY,
ECMA_SIMPLE_VALUE_UNDEFINED, /**< undefined value */
Expand All @@ -90,6 +90,11 @@ typedef enum
*/
typedef uint32_t ecma_value_t;

/**
* Type for directly encoded integer numbers in JerryScript.
*/
typedef int32_t ecma_integer_value_t;

#if UINTPTR_MAX <= UINT32_MAX

/**
Expand All @@ -114,6 +119,50 @@ typedef uint32_t ecma_value_t;
*/
#define ECMA_VALUE_SHIFT 3

/**
* Mask for directly encoded values
*/
#define ECMA_DIRECT_TYPE_MASK ((1u << ECMA_VALUE_SHIFT) | ECMA_VALUE_TYPE_MASK)

/**
* Ecma integer value type
*/
#define ECMA_DIRECT_TYPE_INTEGER_VALUE ((0u << ECMA_VALUE_SHIFT) | ECMA_TYPE_DIRECT)

/**
* Ecma simple value type
*/
#define ECMA_DIRECT_TYPE_SIMPLE_VALUE ((1u << ECMA_VALUE_SHIFT) | ECMA_TYPE_DIRECT)

/**
* Shift for directly encoded values in ecma_value_t
*/
#define ECMA_DIRECT_SHIFT 4

/**
* Maximum integer number for an ecma value
*/
#if CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT32
#define ECMA_INTEGER_NUMBER_MAX 0x7fffff
#else /* CONFIG_ECMA_NUMBER_TYPE != CONFIG_ECMA_NUMBER_FLOAT32 */
#define ECMA_INTEGER_NUMBER_MAX 0x7ffffff
#endif /* CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT32 */

/**
* Minimum integer number for an ecma value
*/
#if CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT32
#define ECMA_INTEGER_NUMBER_MIN -0x7fffff
#else /* CONFIG_ECMA_NUMBER_TYPE != CONFIG_ECMA_NUMBER_FLOAT32 */
#define ECMA_INTEGER_NUMBER_MIN -0x8000000
#endif /* CONFIG_ECMA_NUMBER_TYPE == CONFIG_ECMA_NUMBER_FLOAT32 */

/**
* Checks whether the integer number is in the integer number range.
*/
#define ECMA_IS_INTEGER_NUMBER(num) \
(ECMA_INTEGER_NUMBER_MIN <= (num) && (num) <= ECMA_INTEGER_NUMBER_MAX)

/**
* Internal properties' identifiers.
*/
Expand Down
9 changes: 9 additions & 0 deletions jerry-core/ecma/base/ecma-helpers-number.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
* @{
*/

JERRY_STATIC_ASSERT (sizeof (ecma_value_t) == sizeof (ecma_integer_value_t),
size_of_ecma_value_t_must_be_equal_to_the_size_of_ecma_integer_value_t);

JERRY_STATIC_ASSERT (ECMA_DIRECT_SHIFT == ECMA_VALUE_SHIFT + 1,
currently_directly_encoded_values_has_one_extra_flag);

JERRY_STATIC_ASSERT (((1 << (ECMA_DIRECT_SHIFT - 1)) | ECMA_TYPE_DIRECT) == ECMA_DIRECT_TYPE_SIMPLE_VALUE,
currently_directly_encoded_values_start_after_direct_type_simple_value);

#define ECMA_NUMBER_SIGN_POS (ECMA_NUMBER_FRACTION_WIDTH + \
ECMA_NUMBER_BIASED_EXP_WIDTH)

Expand Down
Loading