开发者

Sorting tuples inside signed integers

开发者 https://www.devze.com 2023-02-23 04:58 出处:网络
I\'m sorting tuples of 16+16 bits as 32bit integers with SSE2. There are only signed integer instructions for compare and min/max. I don\'t have a problem with the order for the higher part as its jus

I'm sorting tuples of 16+16 bits as 32bit integers with SSE2. There are only signed integer instructions for compare and min/max. I don't have a problem with the order for the higher part as its just a hash. But entries with negative hashes will be sorted backwards (right?) Possible but not great solutions could be:

  • Zero the higher bit for hashes, losing precision (not great)
  • Convert the position to negative if the higher bit of the hash is set, and convert it back after sort开发者_运维百科ing.

Is there a better way?


Just subtract 0x80000000 from your 32 bit values, use signed operations, then add back the 0x80000000 afterwards.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号