Skip to content

Conversation

batizdaniel
Copy link
Contributor

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]

@batizdaniel batizdaniel force-pushed the bigint_asint branch 4 times, most recently from 7095fd8 to d2dede2 Compare August 18, 2021 09:36
@rerobika rerobika requested a review from zherczeg August 30, 2021 07:58
Copy link
Member

@zherczeg zherczeg left a 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);
Copy link
Member

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.

Copy link
Member

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.

@batizdaniel batizdaniel force-pushed the bigint_asint branch 2 times, most recently from 4b77e3a to 23cd30f Compare August 30, 2021 14:00
Copy link
Member

@zherczeg zherczeg left a 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);
Copy link
Member

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

Copy link
Contributor Author

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)

Copy link
Member

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.

@zherczeg
Copy link
Member

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

@batizdaniel batizdaniel force-pushed the bigint_asint branch 2 times, most recently from cfb13fc to ce1ba9f Compare September 1, 2021 12:45
ecma_value_t bigint, /**< bigint number */
bool is_signed) /**< The operation is signed */
{
JERRY_UNUSED (this_arg);
Copy link
Member

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.

Comment on lines 194 to 189
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;
Copy link
Member

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]
enum
{
ECMA_BUILTIN_BIGINT_START = 0,
ECMA_BUILTIN_BIGINT_AS_INT_N,
Copy link
Member

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);
Copy link
Member

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)
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bit_s?

@LaszloLango LaszloLango added this to the Release 3.0.0 milestone Nov 13, 2024
gergocs added a commit to gergocs/jerryscript that referenced this pull request Nov 15, 2024
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]
gergocs added a commit to gergocs/jerryscript that referenced this pull request Nov 15, 2024
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]
gergocs added a commit to gergocs/jerryscript that referenced this pull request Nov 15, 2024
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]
gergocs added a commit to gergocs/jerryscript that referenced this pull request Nov 15, 2024
The implementation is based on PR jerryscript-project#4736, only resolved the conflicts.

JerryScript-DCO-1.0-Signed-off-by: Gergo Csizi [email protected]
gergocs added a commit to gergocs/jerryscript that referenced this pull request Nov 15, 2024
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]
gergocs added a commit to gergocs/jerryscript that referenced this pull request Nov 15, 2024
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]
@ossy-szeged ossy-szeged removed this from the Release 3.0.0 milestone Nov 15, 2024
@ossy-szeged
Copy link
Contributor

closing, continue in PR #5165

gergocs added a commit to gergocs/jerryscript that referenced this pull request Nov 19, 2024
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]
gergocs added a commit to gergocs/jerryscript that referenced this pull request Nov 20, 2024
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]
gergocs added a commit to gergocs/jerryscript that referenced this pull request Nov 21, 2024
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]
LaszloLango pushed a commit that referenced this pull request Nov 22, 2024
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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants