PSHUFD SHUFPD有什么区别

发布于 2025-02-06 16:25:38 字数 57 浏览 0 评论 0 原文

我阅读了这两个操作的手册描述,但还不了解差异。有人可以用示例解释ShufPD与PSHUFD的比较吗?

I read the manual description of those two operations but don't understand the difference yet. Can someone explain with an example how shufpd compares to pshufd?

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

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

发布评论

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

评论(1

荒芜了季节 2025-02-13 16:25:38
  1. pshufd 将32位作为一个单位进行洗牌。 Shufpd 将64位作为一个单位进行洗牌。
  2. pshufd 单个寄存器中的混音。 shufpd 可以合并2个寄存器。
  3. PSHUFD 具有单独的源和目标操作数,因此您有时可以在寄存器之间保存副本。
  4. 它们可用于执行相同的任务,但是将整数和浮点指令( pshufd 带有浮点)或用整数使用 shufpd )可能会导致 bypass延迟

以下是来自英特尔文档的复制粘贴,该文档用伪代码解释了每个操作。当您仔细阅读时,差异非常明显。

pshufd a, a, imm8
  DEFINE SELECT4(src, control) {
    CASE(control[1:0]) OF
    0:  tmp[31:0] := src[31:0]
    1:  tmp[31:0] := src[63:32]
    2:  tmp[31:0] := src[95:64]
    3:  tmp[31:0] := src[127:96]
    ESAC
    RETURN tmp[31:0]
  }
  dst[31:0] := SELECT4(a[127:0], imm8[1:0])
  dst[63:32] := SELECT4(a[127:0], imm8[3:2])
  dst[95:64] := SELECT4(a[127:0], imm8[5:4])
  dst[127:96] := SELECT4(a[127:0], imm8[7:6])

shufpd a, b, imm8
  dst[63:0] := (imm8[0] == 0) ? a[63:0] : a[127:64]
  dst[127:64] := (imm8[1] == 0) ? b[63:0] : b[127:64]

例子?

a = [1, 1, 2, 2]
b = [3, 3, 4, 4]

shufpd a, b, 1 -> [2, 2, 3, 3]

您不能使用 pshufd 进行此操作,但是有时两者都可以用于同一任务。

a = [1, 1, 2, 2]

pshufd a, a, 0x4e -> [2, 2, 1, 1]
shufpd a, a, 1 -> [2, 2, 1, 1]
  1. pshufd shuffles 32 bits as a unit. shufpd shuffles 64 bits as a unit.
  2. pshufd shuffles within a single register. shufpd can merge-shuffle 2 registers.
  3. pshufd has a separate source and destination operand, so you can sometimes save a copy between registers.
  4. They can be used to do the same task, but mixing integer and floating point instructions (pshufd with floating points, or shufpd with integers) may cause a bypass delay.

Below is a copy paste from the Intel docs explaining each operation with pseudocode. The difference is very clear when you read carefully.

pshufd a, a, imm8
  DEFINE SELECT4(src, control) {
    CASE(control[1:0]) OF
    0:  tmp[31:0] := src[31:0]
    1:  tmp[31:0] := src[63:32]
    2:  tmp[31:0] := src[95:64]
    3:  tmp[31:0] := src[127:96]
    ESAC
    RETURN tmp[31:0]
  }
  dst[31:0] := SELECT4(a[127:0], imm8[1:0])
  dst[63:32] := SELECT4(a[127:0], imm8[3:2])
  dst[95:64] := SELECT4(a[127:0], imm8[5:4])
  dst[127:96] := SELECT4(a[127:0], imm8[7:6])

shufpd a, b, imm8
  dst[63:0] := (imm8[0] == 0) ? a[63:0] : a[127:64]
  dst[127:64] := (imm8[1] == 0) ? b[63:0] : b[127:64]

Examples?

a = [1, 1, 2, 2]
b = [3, 3, 4, 4]

shufpd a, b, 1 -> [2, 2, 3, 3]

You cannot do this with pshufd, but sometimes both can be used for the same task.

a = [1, 1, 2, 2]

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