-
Notifications
You must be signed in to change notification settings - Fork 683
Implement BigInt asIntN and asUintN methods #4736
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
Conversation
7095fd8
to
d2dede2
Compare
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.
The code is coming from the standard?
ecma_value_t bigint, /**< bigint number */ | ||
bool is_signed) /**< The operation is signed */ | ||
{ | ||
JERRY_UNUSED (this_arg); |
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.
due to custom dispatcher passing this_args in unnecessary.
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.
Passing this as argument is unnecessary.
4b77e3a
to
23cd30f
Compare
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 would like to get a bit more info about the high level concept of the algorith, so I could suggest optimizations.
const uint32_t size_of_divisor_in_bits = (sizeof (uint32_t) * sizeof (uint64_t)); | ||
|
||
uint64_t whole_part = (uint64_t) floor (input_bits / size_of_divisor_in_bits); | ||
uint32_t remainder = (uint32_t) fmod (input_bits, size_of_divisor_in_bits); |
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.
The input_bits should be an integer number. Furthermore JerryScript has a maximum length for bigints, any number greater than that does not need any clamping (just increase its refcount and return with it).
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.
The head of the code is coming from the standard. So the input_bits should be a number according to the ToIndex method.
(https://tc39.es/ecma262/#sec-bigint.asintn)
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.
Nice but my comment stiill stands, if the number is greater than the maximum bits allowed, just return with the original value, otherwise you can use an integer div and mod. If uint conversion is needed, and the original value is negative, throw an allocation error.
I would also like to have some tests on JerryScript, not just the test262 ones. These tests should check corner cases of the algorithm, not covered by test262 |
cfb13fc
to
ce1ba9f
Compare
ecma_value_t bigint, /**< bigint number */ | ||
bool is_signed) /**< The operation is signed */ | ||
{ | ||
JERRY_UNUSED (this_arg); |
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.
Passing this as argument is unnecessary.
uint32_t check_sign_mask = (uint32_t) 1 << (mask_bit - 1); | ||
|
||
uint32_t mask = ((uint32_t) 1 << mask_bit) - 1; | ||
|
||
uint32_t last_cell = (exact_size >= sizeof (uint32_t)) ? (uint32_t) (min_size / sizeof (uint32_t)) - 1 : 0; | ||
|
||
bool is_positive = false; | ||
|
||
bool is_representation_positive = false; |
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.
ditto.
The following methods were implemented: - BigInt.asIntN - BigInt.asUintN Custom dispatcher also added to builtin_bigint. JerryScript-DCO-1.0-Signed-off-by: Daniel Batiz [email protected]
ce1ba9f
to
23c771c
Compare
enum | ||
{ | ||
ECMA_BUILTIN_BIGINT_START = 0, | ||
ECMA_BUILTIN_BIGINT_AS_INT_N, |
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.
Missing comments.
const uint32_t size_of_divisor_in_bits = (sizeof (uint32_t) * sizeof (uint64_t)); | ||
|
||
uint64_t whole_part = (uint64_t) floor (input_bits / size_of_divisor_in_bits); | ||
uint32_t remainder = (uint32_t) fmod (input_bits, size_of_divisor_in_bits); |
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.
Nice but my comment stiill stands, if the number is greater than the maximum bits allowed, just return with the original value, otherwise you can use an integer div and mod. If uint conversion is needed, and the original value is negative, throw an allocation error.
is_zero_values = true; | ||
} | ||
} | ||
if (is_zero_values) |
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 no else
here so add a newline here
} | ||
while (digits_p < digits_end_p); | ||
|
||
int16_t equal_bit_s = 0; |
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.
bit_s?
The following methods were implemented: - BigInt.asIntN - BigInt.asUintN Custom dispatcher also added to builtin_bigint. The implementation is based on PR jerryscript-project#4736, only applied the requested changes. Signed-off-by: Gergo Csizi [email protected]
The following methods were implemented: - BigInt.asIntN - BigInt.asUintN Custom dispatcher also added to builtin_bigint. The implementation is based on PR jerryscript-project#4736, only applied the requested changes. Signed-off-by: Gergo Csizi [email protected]
The following methods were implemented: - BigInt.asIntN - BigInt.asUintN Custom dispatcher also added to builtin_bigint. The implementation is based on PR jerryscript-project#4736, only applied the requested changes. JerryScript-DCO-1.0-Signed-off-by: Gergo Csizi [email protected]
The implementation is based on PR jerryscript-project#4736, only resolved the conflicts. JerryScript-DCO-1.0-Signed-off-by: Gergo Csizi [email protected]
The following methods were implemented: - BigInt.asIntN - BigInt.asUintN Custom dispatcher also added to builtin_bigint. The implementation is based on PR jerryscript-project#4736, only applied the requested changes. JerryScript-DCO-1.0-Signed-off-by: Gergo Csizi [email protected] Co-authored-by: Daniel Batiz [email protected]
The following methods were implemented: - BigInt.asIntN - BigInt.asUintN Custom dispatcher also added to builtin_bigint. The implementation is based on PR jerryscript-project#4736, only applied the requested changes. Co-authored-by: Daniel Batiz [email protected] JerryScript-DCO-1.0-Signed-off-by: Gergo Csizi [email protected]
closing, continue in PR #5165 |
The following methods were implemented: - BigInt.asIntN - BigInt.asUintN Custom dispatcher also added to builtin_bigint. The implementation is based on PR jerryscript-project#4736, only applied the requested changes. Co-authored-by: Daniel Batiz [email protected] JerryScript-DCO-1.0-Signed-off-by: Gergo Csizi [email protected]
The following methods were implemented: - BigInt.asIntN - BigInt.asUintN Custom dispatcher also added to builtin_bigint. The implementation is based on PR jerryscript-project#4736, only applied the requested changes. Co-authored-by: Daniel Batiz [email protected] JerryScript-DCO-1.0-Signed-off-by: Gergo Csizi [email protected]
The following methods were implemented: - BigInt.asIntN - BigInt.asUintN Custom dispatcher also added to builtin_bigint. The implementation is based on PR jerryscript-project#4736, only applied the requested changes. Co-authored-by: Daniel Batiz [email protected] JerryScript-DCO-1.0-Signed-off-by: Gergo Csizi [email protected]
The following methods were implemented: - BigInt.asIntN - BigInt.asUintN Custom dispatcher also added to builtin_bigint. The implementation is based on PR #4736, only applied the requested changes. Co-authored-by: Daniel Batiz [email protected] JerryScript-DCO-1.0-Signed-off-by: Gergo Csizi [email protected]
The following methods were implemented:
Custom dispatcher also added to builtin_bigint.
JerryScript-DCO-1.0-Signed-off-by: Daniel Batiz [email protected]