高位 - 以他们做出了uint64_t中成uint8_t有 [英] High Order Bits - Take them and make a uint64_t into a uint8_t

查看:193
本文介绍了高位 - 以他们做出了uint64_t中成uint8_t有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们假设你有一个uint64_t中只在乎的高位为您的uint64_t中的每个字节。像这样:

Let's say you have a uint64_t and care only about the high order bit for each byte in your uint64_t. Like so:

uint32_t的:
0000 ... 1000 0000 1000 0000 1000 0000 1000 0000 ---> 0000 1111

uint32_t: 0000 ... 1000 0000 1000 0000 1000 0000 1000 0000 ---> 0000 1111

有一个更快的方法比:

   return
   (
     ((x >> 56) & 128)+
     ((x >> 49) &  64)+
     ((x >> 42) &  32)+
     ((x >> 35) &  16)+
     ((x >> 28) &   8)+
     ((x >> 21) &   4)+
     ((x >> 14) &   2)+
     ((x >>  7) &   1)
   )

阿卡移位X,屏蔽,并添加正确的位每个字节?这将编译了很多组件,我正在寻找更快的方法......我使用的机器只有到SSE2指令集,我没能找到有用的SIMD欢声笑语。

Aka shifting x, masking, and adding the correct bit for each byte? This will compile to a lot of assembly and I'm looking for a quicker way... The machine I'm using only has up to SSE2 instructions and I failed to find helpful SIMD ops.

感谢您的帮助。

推荐答案

在我的评论中提到, PMOVMSKB 你想要做什么。这里是你如何使用它:

As I mentioned in a comment, pmovmskb does what you want. Here's how you could use it:

MMX + SSE1:

MMX + SSE1:

movq mm0, input ; input can be r/m
pmovmskb output, mm0 ; output must be r

SSE2:

movq xmm0, input
pmovmskb output, xmm0

和我抬头的新途径。

BMI2:

mov rax, 0x8080808080808080
pext output, input, rax ; input must be r

这篇关于高位 - 以他们做出了uint64_t中成uint8_t有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆