Skip to content
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

Add leading/trailing ones and zero count instructions (part 2) #1179

Merged
merged 1 commit into from
Feb 26, 2024

Conversation

Fumuran
Copy link
Contributor

@Fumuran Fumuran commented Dec 11, 2023

This PR adds 4 new instructions for std::math::u64 module:

  • clz: count leading zeros of the u64 value. [n_hi, n_lo, ...] -> [clz, ...]
  • ctz: count trailing zeros of the u64 value. [n_hi, n_lo, ...] -> [ctz, ...]
  • clo: count leading ones of the u64 value. [n_hi, n_lo, ...] -> [clo, ...]
  • cto: count trailing ones of the u64 value. [n_hi, n_lo, ...] -> [cto, ...]

This PR partially implements features mentioned in #1133 issue. This PR should be merged after #1176.

stdlib/asm/math/u64.masm Outdated Show resolved Hide resolved
@Fumuran Fumuran force-pushed the andrew-leading-trailing-one-zero branch from 6db6e1d to 193048e Compare February 9, 2024 15:51
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Thank you! Looks good! I left some potential optimization comments inline.

CHANGELOG.md Outdated Show resolved Hide resolved
stdlib/asm/math/u64.masm Outdated Show resolved Hide resolved
stdlib/asm/math/u64.masm Outdated Show resolved Hide resolved
stdlib/asm/math/u64.masm Outdated Show resolved Hide resolved
stdlib/asm/math/u64.masm Outdated Show resolved Hide resolved
@Fumuran Fumuran force-pushed the andrew-leading-trailing-one-zero branch 3 times, most recently from d6b7450 to 0e7b44b Compare February 18, 2024 09:41
@Fumuran Fumuran force-pushed the andrew-bitwise-counters-u64 branch 3 times, most recently from 3fff4c5 to 6f49946 Compare February 19, 2024 15:13
stdlib/asm/math/u64.masm Outdated Show resolved Hide resolved
stdlib/asm/math/u64.masm Outdated Show resolved Hide resolved
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! I left one comment re updating cycle counts in the docs - but this is something we may need to revisit after #1133 is finalized.

Comment on lines 53 to 56
| clz | Counts the number of leading zeros of one unsigned 64-bit integer.<br /> The input value is assumed to be represented using 32 bit limbs, but this is not checked.<br /> The stack transition looks as follows: `[n_hi, n_lo, ...] -> [clz, ...]`, where `clz` is a number of leading zeros of value `n`.<br /> This takes 59 cycles if $n < 2^{32}$ and 32 cycles otherwise. |
| ctz | Counts the number of trailing zeros of one unsigned 64-bit integer.<br /> The input value is assumed to be represented using 32 bit limbs, but this is not checked.<br /> The stack transition looks as follows: `[n_hi, n_lo, ...] -> [ctz, ...]`, where `ctz` is a number of trailing zeros of value `n`.<br /> This takes 60 cycles if $n < 2^{32}$ and 33 cycles otherwise. |
| clo | Counts the number of leading ones of one unsigned 64-bit integer.<br /> The input value is assumed to be represented using 32 bit limbs, but this is not checked.<br /> The stack transition looks as follows: `[n_hi, n_lo, ...] -> [clo, ...]`, where `clo` is a number of leading ones of value `n`.<br /> This takes 69 cycles if $n < 2^{32}$ and 37 cycles otherwise. |
| cto | Counts the number of trailing ones of one unsigned 64-bit integer.<br /> The input value is assumed to be represented using 32 bit limbs, but this is not checked.<br /> The stack transition looks as follows: `[n_hi, n_lo, ...] -> [cto, ...]`, where `cto` is a number of trailing ones of value `n`.<br /> This takes 70 cycles if $n < 2^{32}$ and 38 cycles otherwise. |
Copy link
Contributor

Choose a reason for hiding this comment

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

Cycle counts here need to be updated.

@Fumuran Fumuran force-pushed the andrew-leading-trailing-one-zero branch 2 times, most recently from ea080b2 to 6fd200e Compare February 22, 2024 08:09
@Fumuran Fumuran force-pushed the andrew-bitwise-counters-u64 branch 2 times, most recently from b4da798 to f4c5c5f Compare February 22, 2024 09:34
@Fumuran Fumuran force-pushed the andrew-leading-trailing-one-zero branch from 6fd200e to 9b75f1d Compare February 23, 2024 07:16
Base automatically changed from andrew-leading-trailing-one-zero to next February 26, 2024 22:13
@bobbinth bobbinth merged commit 6302b23 into next Feb 26, 2024
15 checks passed
@bobbinth bobbinth deleted the andrew-bitwise-counters-u64 branch February 26, 2024 22:30
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.

2 participants