在64位单词中执行16位数量的顺序

发布于 2025-01-29 04:08:40 字数 171 浏览 2 评论 0原文

我需要对少数小无签名整数进行词素比较。如果(例如)8位整数(例如),那么显而易见的方法是字节汇总并在GPR中进行普通整数。如果有2个32位整数,则32位旋转和普通的比较将可以解决问题。如果有4个16位整数怎么办?显然,有了向量注册,很容易将它们改组,但是是否有有效的方法 - 逆转其订单或进行比较而不反转订单的方法仅使用GPR?

I need to do a lexicographic comparison of a small number of small unsigned integers. If there are (for example) 8 8-bit integers, the obvious approach is to byteswap them and do an ordinary integer compare in a GPR. If there are 2 32-bit integers, a 32-bit rotate and an ordinary compare will do the trick. What if there are 4 16-bit integers? Obviously with a vector register it is easy to shuffle them, but is there an efficient approach—either to reversing their order, or to doing the compare without reversing order—using only GPR?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟织青萝梦 2025-02-05 04:08:40

仅凭反向,这是我的尝试:

wswap2:
        ;;  rdi = ABCD (words)
        mov rax, rdi            
        ror edi, 16             ; rdi = 00DC
        shl rdi, 32             ; rdi = DC00
        shr rax, 32             ; rax = 00AB
        ror eax, 16             ; rax = 00BA
        or rax, rdi             ; rax = DCBA
        ret

能够使用32位旋转来交换两个相邻单词很方便。

我们有两个平行的依赖关系链,每个链条有两个UOP,然后还有一个将它们合并的UOP。

For the reverse alone, here's my attempt:

wswap2:
        ;;  rdi = ABCD (words)
        mov rax, rdi            
        ror edi, 16             ; rdi = 00DC
        shl rdi, 32             ; rdi = DC00
        shr rax, 32             ; rax = 00AB
        ror eax, 16             ; rax = 00BA
        or rax, rdi             ; rax = DCBA
        ret

It's convenient to be able to use a 32-bit rotate to swap two adjacent words.

We've got two parallel dependency chains of two uops each, followed by one more uop to merge them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文