I'm trying to concatenate two uint32_t and get back a uint64_t. Here's my method
uint64_t concat_int1_int2 (uint32_t int1, uint32_t int2) {
uint64_t concatenated = int1;
return concatenated << 32 | int2;
}
This seems to be extremely slow (I need to do it ~1,000,000 times and it is taking ~ 6 minutes). Two questions, why does the bit shift take so long (that seems to be the limiting step), and does anyone have a suggestion for a faster way to do this?
The way you are doing it is correct. It may help to inline
the function. Most likely your performance problem is in code you haven't shown us.
Your solution is near optiomal, it can't be much faster. Marking the function as inline
may help a very little, but will not make much difference.
I made a test here in my machine using your code, it took 10ms to run 1,000,000 iterations of it. Your speed problem is somewhere else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With