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

Improve documentation for bitops #16961

Merged
merged 3 commits into from
Feb 15, 2021
Merged

Improve documentation for bitops #16961

merged 3 commits into from
Feb 15, 2021

Conversation

konsumlamm
Copy link
Contributor

@konsumlamm konsumlamm commented Feb 7, 2021

  • improve wording
  • use func (instead of proc with {.noSideEffect.})
  • use let in runnableExamples where possible
  • add some links

EDIT: Closes #7587.

Use func
Use let in runnableExamples
@timotheecour
Copy link
Member

let's wait for #16622 to get merged 1st as that PR has been in the queue for a while, to avoid conflicts there

@konsumlamm
Copy link
Contributor Author

konsumlamm commented Feb 8, 2021

@timotheecour
Copy link
Member

@konsumlamm ok #16622 got merged, please rebase :)

importc: "__popcnt", header: "<intrin.h>", noSideEffect.}
proc builtin_popcnt64(a2: uint64): uint64 {.
importc: "__popcnt64", header: "<intrin.h>", noSideEffect.}
func builtin_popcnt16(a2: uint16): uint16 {.
Copy link
Member

Choose a reason for hiding this comment

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

optional: turn into more readable 1-liners?

func builtin_popcnt16(a2: uint16): uint16 {.importc: "__popcnt16", header: "<intrin.h>".}

(even if exceeds that (IMO silly) 80 col limit a bit)

Copy link
Member

Choose a reason for hiding this comment

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

let's defer this to an eventual followup PR instead

proc parityBits*(x: SomeInteger): int {.inline, noSideEffect.} =
## Calculate the bit parity in integer. If number of 1-bit
## is odd parity is 1, otherwise 0.
func parityBits*(x: SomeInteger): int {.inline.} =
Copy link
Member

@timotheecour timotheecour Feb 9, 2021

Choose a reason for hiding this comment

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

pre-existing, but why isn't this returning bool? nim isn't C...; casting should have no cost, and resulting api would be easier; maybe we need another proc that returns bool (maybe bitParity ?)

## otherwise result is undefined.
func firstSetBit*(x: SomeInteger): int {.inline.} =
## Returns the 1-based index of the least significant set bit of `x`.
## If `x` is zero, when `noUndefinedBitOpts` is set, the result is 0,
Copy link
Member

Choose a reason for hiding this comment

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

pre-existing but IMO future PR should add -d:nimNoUndefinedBitOpts of which noUndefinedBitOpts would become an undocumented alias

Copy link
Member

@timotheecour timotheecour left a comment

Choose a reason for hiding this comment

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

LGTM, I've checked everything including fact that large main2 block was entirely covered by other tests block even though that's not obvious at 1st sight: some static blocks in main2 are covered by fact we have static: main

the duplication was introduced in #13803 (note that before #13803 bitops were also tested with
-d:noIntrinsicsBitOpts
-d:noUndefinedBitOps
(see https://github.com/nim-lang/Nim/pull/13803/files#diff-cc11adc098ea503d26c0788e763173c275570c6074503ebea374ed348344562c)

in future PR we should add:

discard """
 matrix: "; -d:noIntrinsicsBitOpts -d:noUndefinedBitOps"
"""

to test this as well

@Clyybber Clyybber merged commit 0a9a90d into nim-lang:devel Feb 15, 2021
ardek66 pushed a commit to ardek66/Nim that referenced this pull request Mar 26, 2021
* Improve documentation for bitops

Use func
Use let in runnableExamples

* Remove unnecessary tests

Fix nim-lang#7587
@konsumlamm konsumlamm deleted the bitops branch March 30, 2021 21:48
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.

stdlib bitops incorrect result for popcount
3 participants