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

sets use non-optimized countBits32 #11330

Closed
data-man opened this issue May 25, 2019 · 5 comments · Fixed by #17334
Closed

sets use non-optimized countBits32 #11330

data-man opened this issue May 25, 2019 · 5 comments · Fixed by #17334

Comments

@data-man
Copy link
Contributor

countbits32

/cc @krux02

related #10617

@krux02
Copy link
Contributor

krux02 commented May 26, 2019

I am aware of this. Unfortunately I can't do a lot about it.

# bitops can't be imported here, therefore the code duplication.

This is the problem:

  • The fast countSetBits is implemented in bitops.nim
  • Slow but compatible countBits32 and countBits64 is implemented in sets.nim
  • system.nim includes sets.nim
  • bitops defines a macro, setBits (it is a macro, because we don't have proper varargs forwarding like in c++).
  • macros may not be imported from system.nim.

Therefore, sets need to be implemented with the slow countBits32/64. The solution that I see possible is the following: Fix varargs in nim templates with proper varargs forwarding that isn't based on macros (like in c++). Then the macros in bitops can be implemented as pure templates and bitops can be imported from sets.nim (and therefore also from system.nim).

@data-man
Copy link
Contributor Author

@krux02
I don't know all details, but can be bitops added to implicit imports?
Something like conf.implicitImports.add ....
And call countBits there:
https://github.com/nim-lang/Nim/blob/devel/compiler/ccgexprs.nim#L1855-L1857

@krux02
Copy link
Contributor

krux02 commented May 27, 2019

No don't use implicitImports at all. It only causes harm. That would be worse than importing bitops in system.nim which I just explained isn't possible because of its macros.

@Clyybber
Copy link
Contributor

@krux02 Isn't it possible to use from bitops import countBits32/64 ?

@Araq
Copy link
Member

Araq commented May 27, 2019

Move countBit32/64 to system, import it from bitops, problem solved.

ringabout added a commit to ringabout/Nim that referenced this issue Mar 11, 2021
Araq added a commit that referenced this issue Mar 21, 2021
* Update lib/pure/bitops.nim
* Update lib/system/sets.nim
* Apply suggestions from code review

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
ringabout added a commit to ringabout/Nim that referenced this issue Mar 22, 2021
ardek66 pushed a commit to ardek66/Nim that referenced this issue Mar 26, 2021
* Update lib/pure/bitops.nim
* Update lib/system/sets.nim
* Apply suggestions from code review

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants