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

fix hashWangYi1 when nimvm result to 0 #15915

Closed
wants to merge 1 commit into from
Closed

Conversation

bung87
Copy link
Collaborator

@bung87 bung87 commented Nov 11, 2020

reason same as hiXorLo

run nim js -r a.nim

code example:

import hashes
const h2 = hashWangYi1('a'.uint64)
echo "const:",h2
let h4 = hashWangYi1('a'.uint64)
echo "runtime:",hashWangYi1('a'.uint64)

@ringabout
Copy link
Member

What's the issue?
Or the testcase for the issue?

bung87 added a commit to bung87/Nim that referenced this pull request Nov 12, 2020
@cooldome
Copy link
Member

cooldome commented Nov 12, 2020

For the code snippet above I am getting the following output:

const:661948602591176288
runtime:661948602591176288

I don't see issues here. Could you please explain?
Possibly it is platform specific, what is your compilation target?

@bung87
Copy link
Collaborator Author

bung87 commented Nov 12, 2020

For the code snippet above I am getting the following output:

const:661948602591176288
runtime:661948602591176288

I don't see issues here. Could you please explain.

do you run it target js, the const will go to when nimvm branch ,it need result= , after adding it you still get a number differs from js runtime result. and you check CI tests all fails.

I create a pr for issue this, please check #15933

@cooldome
Copy link
Member

I see it is the javascript backend is affected.
Without this fix I get:

const:0
runtime:4423056995083872

with fix I am getting:

const:889415264
runtime:4423056995083872

It is still different but getting better. It needs to match though.

@c-blake
Copy link
Contributor

c-blake commented Nov 12, 2020

The lower 32-bits do match (probably everyone knows, but bears mentioning - print the numbers in hex and you will see the lower 8 nibbles match).

I 100% agree, though, that we should get the whole number matching. That JS hash is actually pretty slow and has its current definition specifically to match the C/C++ backends as much as possible.

Also, while this result = workaround is fine, it probably speaks to a deeper/more general compiler bug, possibly related to having result = in the asm but not in the when nimvm and/or default else: branches. (Just guessing...). Someone may want to create a more isolated test case for that and file an issue so it does not get forgotten.

@c-blake
Copy link
Contributor

c-blake commented Nov 12, 2020

Oh, wait..I just read my comment in the asm. Lol. We are only supposed to expect matching the lowest 32-bits. (tables and sets use and to range reduce to table size. So, this will match for up to 4 GiEntry tables.) But I would still put result = in all 3 when branches to be consistent, and still try to isolate the broader problem.

@bung87
Copy link
Collaborator Author

bung87 commented Nov 12, 2020

when nimvm has problem when it only has one branch, there's a issue for that, the problem here is caculate at compile time target to js , js has correct version , while vm not, if only low 32bit matters , maybe need a custom == operator to handle this.

@c-blake
Copy link
Contributor

c-blake commented Nov 12, 2020

Hmm. The when nimvm here all have 2 branches. Maybe you need the result = here because proc hiXorLo also does result =? There still seems like a deeper issue (though there may already be a github issue for it).

If matching is important then we could also mask the high bits to zero (just for the JS target and just in the nimvm mode). The idea behind this limited 32-bit range on JS was that anyone doing giant 4GiEntry*8..32B = 32..128 GiB single tables was also probably enough of a power user to just define their own hash. That's kind of a footgun until Nim uses BigInt as a backend for JS integers, not the JS "number".

@ringabout
Copy link
Member

Related issue:
#15624

And it's better to move tests from #15933 to here.

@bung87
Copy link
Collaborator Author

bung87 commented Nov 12, 2020

haha , dont mind when nimvm issue , this PR just proven hashWangYi1 not get result default value (0), that test case will cover these two problem, here mainly is focus on result to zero . c-blake make your fix, this PR doesn't matters.

@cooldome
Copy link
Member

I believe result = is needed because result symbol in js branch is used explicitly. Please also add result = on line 134 as well.
Please investigate how to make hashes in vm and jsgen aligned.

c-blake added a commit to c-blake/Nim that referenced this pull request Nov 12, 2020
resolve the problem mentioned there (`hash() == 0`) as well as
to close nim-lang#15624
@bung87
Copy link
Collaborator Author

bung87 commented Nov 12, 2020

Close in favour of #15937

@bung87 bung87 closed this Nov 12, 2020
bung87 added a commit to bung87/Nim that referenced this pull request Nov 13, 2020
no need mention PR nim-lang#15915, fixed in nim-lang#15937
Araq pushed a commit that referenced this pull request Nov 13, 2020
* Alternate PR to #15915 to
resolve the problem mentioned there (`hash() == 0`) as well as
to close #15624

* Address #15937 (comment)
{ though this was only a move from 2 copies to 3 copies. ;-) }
bung87 added a commit to bung87/Nim that referenced this pull request Nov 13, 2020
bung87 added a commit to bung87/Nim that referenced this pull request Nov 13, 2020
no need mention PR nim-lang#15915, fixed in nim-lang#15937
ringabout added a commit that referenced this pull request Dec 13, 2020
* test for issue #15624 and PR #15915 for patch #13823

* Update thashes.nim

no need mention PR #15915, fixed in #15937

* rebase to devel(issue maybe fixed), ignore ouputs

* Apply suggestions from code review

Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>
PMunch pushed a commit to PMunch/Nim that referenced this pull request Jan 6, 2021
* Alternate PR to nim-lang#15915 to
resolve the problem mentioned there (`hash() == 0`) as well as
to close nim-lang#15624

* Address nim-lang#15937 (comment)
{ though this was only a move from 2 copies to 3 copies. ;-) }
mildred pushed a commit to mildred/Nim that referenced this pull request Jan 11, 2021
* Alternate PR to nim-lang#15915 to
resolve the problem mentioned there (`hash() == 0`) as well as
to close nim-lang#15624

* Address nim-lang#15937 (comment)
{ though this was only a move from 2 copies to 3 copies. ;-) }
mildred pushed a commit to mildred/Nim that referenced this pull request Jan 11, 2021
* test for issue nim-lang#15624 and PR nim-lang#15915 for patch nim-lang#13823

* Update thashes.nim

no need mention PR nim-lang#15915, fixed in nim-lang#15937

* rebase to devel(issue maybe fixed), ignore ouputs

* Apply suggestions from code review

Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>
irdassis pushed a commit to irdassis/Nim that referenced this pull request Mar 16, 2021
* Alternate PR to nim-lang#15915 to
resolve the problem mentioned there (`hash() == 0`) as well as
to close nim-lang#15624

* Address nim-lang#15937 (comment)
{ though this was only a move from 2 copies to 3 copies. ;-) }
ardek66 pushed a commit to ardek66/Nim that referenced this pull request Mar 26, 2021
* Alternate PR to nim-lang#15915 to
resolve the problem mentioned there (`hash() == 0`) as well as
to close nim-lang#15624

* Address nim-lang#15937 (comment)
{ though this was only a move from 2 copies to 3 copies. ;-) }
ardek66 pushed a commit to ardek66/Nim that referenced this pull request Mar 26, 2021
* test for issue nim-lang#15624 and PR nim-lang#15915 for patch nim-lang#13823

* Update thashes.nim

no need mention PR nim-lang#15915, fixed in nim-lang#15937

* rebase to devel(issue maybe fixed), ignore ouputs

* Apply suggestions from code review

Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>
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.

4 participants