Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
Asooka
on March 9, 2023
|
parent
|
context
|
favorite
| on:
SWAR: Find any byte from set
auto broadcast = [](uint8_t v) -> uint64_t { return 0x101010101010101 * v; };
This is actually undefined behaviour. Due to integer promotion rules, v will be promoted to an int64, which is signed, so if it is 128 or more, the product would result in signed overflow. You need to explicitly cast it to an uint64.
david2ndaccount
on March 9, 2023
[–]
Instead of a cast, you can also use a `u` suffix on the constant to force it to be unsigned. Then the `v` will be promoted to the same size .
Join us for
AI Startup School
this June 16-17 in San Francisco!
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: