Uh oh!
There was an error while loading. Please reload this page.
Massage CityHash to work at comptime - #7331
Conversation
jedisct1
commented
Dec 7, 2020
Looking good. Does it have any performance implications? |
SpexGuy
commented
Dec 7, 2020
Performance in debug mode may be impacted by the new |
| @memcpy(@ptrCast([*]u8, &v), ptr, 4); | ||
| fn fetch32(ptr: [*]const u8, offset: usize) u32 { | ||
| // ptr + offset doesn't work at comptime so we need this instead. | ||
| const offset_ptr = offsetPtr(ptr, offset)[0..4]; |
There was a problem hiding this comment.
What about
returnmem.readIntNative(u32, offsetPtr(ptr, offset)[0..4]);
// orreturnmem.readIntNative(u32, ptr[offset..offset+4]);Ditto for fetch64 (and the other two identical fetch helpers? Can you just pull them at top level and delete a copy?)
There was a problem hiding this comment.
Huh, I thought these wouldn't work at comptime but apparently they do. Since the next line is byte swap, I can replace the whole function with readIntLittle.
[offset .. offset + 4] works at comptime but at runtime this would produce a slice, so I'm sticking with the other one.
There was a problem hiding this comment.
This should work at runtime:
returnmem.readIntLittle(u32, ptr[offset..offset+4][0..4]);(With slices, you can do [offset..][0..4] which is a nice little idiom, but that doesn't work for length-less pointers)
There was a problem hiding this comment.
That works but introduces a new but useless runtime check in debug modes (useless because it's only checking that offset + 4 - offset == 4).ptr[offset .. offset + 4].ptr[0..4] would work, but for consistency I think it's worth sticking with offsetPtr everywhere in this file.
55bc6cb to
1fbd1bfCompareSpexGuy
commented
Dec 9, 2020
Looks like the additional comptime execution for these tests might be putting the test build over the memory limit. That might be a reason to hold off on this until stage 2. |
andrewrk
commented
Jan 11, 2021
Landed in 5cc2e50 but with the comptime execution commented out in the tests. Idea being that we will not have test coverage of this for now, and re-enable them once we ship stage2. |
@sinitax ran into issues trying to use CityHash at compile time. This PR modifies the implementation and tests to work at compile time.