使用未使用的v0的“vperm v0,v0,v0,v17”是做什么的?

问题描述 投票:5回答:1

我正在使用SHA-256 implementation制作Power8 built-ins。性能有点偏差。我估计它每个字节大约2个周期(cpb)。

在块上执行SHA的C / C ++代码如下所示:

// Schedule 64-byte message
SHA256_SCHEDULE(W, data);

uint32x4_p8 a = abcd, e = efgh;
uint32x4_p8 b = VectorShiftLeft<4>(a);
uint32x4_p8 f = VectorShiftLeft<4>(e);
uint32x4_p8 c = VectorShiftLeft<4>(b);
uint32x4_p8 g = VectorShiftLeft<4>(f);
uint32x4_p8 d = VectorShiftLeft<4>(c);
uint32x4_p8 h = VectorShiftLeft<4>(g);

for (unsigned int i=0; i<64; i+=4)
{
    const uint32x4_p8 k = VectorLoad32x4u(K, i*4);
    const uint32x4_p8 w = VectorLoad32x4u(W, i*4);
    SHA256_ROUND<0>(w,k, a,b,c,d,e,f,g,h);
    SHA256_ROUND<1>(w,k, a,b,c,d,e,f,g,h);
    SHA256_ROUND<2>(w,k, a,b,c,d,e,f,g,h);
    SHA256_ROUND<3>(w,k, a,b,c,d,e,f,g,h);
}

我在ppc64-le机器上使用-O3-mcpu=power8在GCC编译程序。当我看到反汇编时,我看到其中的几个:

...
10000b0c:   a6 03 09 7d     mtctr   r8
10000b10:   57 02 00 f0     xxswapd vs32,vs32
10000b14:   6b 04 00 10     vperm   v0,v0,v0,v17
10000b18:   57 02 00 f0     xxswapd vs32,vs32
10000b1c:   99 57 00 7c     stxvd2x vs32,0,r10
10000b20:   99 26 0c 7c     lxvd2x  vs32,r12,r4
10000b24:   57 02 00 f0     xxswapd vs32,vs32
10000b28:   6b 04 00 10     vperm   v0,v0,v0,v17
10000b2c:   57 02 00 f0     xxswapd vs32,vs32
10000b30:   99 67 0a 7c     stxvd2x vs32,r10,r12
10000b34:   99 26 0b 7c     lxvd2x  vs32,r11,r4
10000b38:   57 02 00 f0     xxswapd vs32,vs32
10000b3c:   6b 04 00 10     vperm   v0,v0,v0,v17
10000b40:   57 02 00 f0     xxswapd vs32,vs32
10000b44:   99 5f 0a 7c     stxvd2x vs32,r10,r11
10000b48:   99 26 05 7c     lxvd2x  vs32,r5,r4
10000b4c:   57 02 00 f0     xxswapd vs32,vs32
10000b50:   6b 04 00 10     vperm   v0,v0,v0,v17
10000b54:   57 02 00 f0     xxswapd vs32,vs32
10000b58:   99 2f 0a 7c     stxvd2x vs32,r10,r5
...

vperm v0,v0,v0,v17似乎是死命令,因为排列后没有使用v0

vperm v0,v0,v0,v17做什么?


C ++源代码可在sha256-p8.cxx获得。

源文件是使用g++ -g3 -O3 -Wall -DTEST_MAIN -mcpu=power8 sha256-2-p8.cxx -o sha256-2-p8.exe编译的。

完整的拆卸可在PPC64 SHA-256 disassembly获得。


我认为上面的片段是由SHA256_SCHEDULE制作的。我在相关区块之后看到了VectorShiftLeftvsldoi)的集合。

为了更加零,我相当肯定它是前16个单词的endian-swapper:

const uint8x16_p8 mask = {3,2,1,0, 7,6,5,4, 11,10,9,8, 15,14,13,12};
for (unsigned int i=0; i<16; i+=4)
    VectorStore32x4u(VectorPermute32x4(VectorLoad32x4u(data, i*4), mask), W, i*4);

SHA256_SCHEDULE看起来像这样:

// +2 because Schedule reads beyond the last element
void SHA256_SCHEDULE(uint32_t W[64+2], const uint8_t* data)
{
#if (__LITTLE_ENDIAN__)
    const uint8x16_p8 mask = {3,2,1,0, 7,6,5,4, 11,10,9,8, 15,14,13,12};
    for (unsigned int i=0; i<16; i+=4)
        VectorStore32x4u(VectorPermute32x4(VectorLoad32x4u(data, i*4), mask), W, i*4);
#else
    for (unsigned int i=0; i<16; i+=4)
        VectorStore32x4u(VectorLoad32x4u(data, i*4), W, i*4);
#endif

    // At i=62, W[i-2] reads the 65th and 66th elements. W[] has 2 extra "don't care" elements.
    for (unsigned int i = 16; i < 64; i+=2)
    {
        const uint32x4_p8 s0 = Vector_sigma0(VectorLoad32x4u(W, (i-15)*4));
        const uint32x4_p8 w0 = VectorLoad32x4u(W, (i-16)*4);
        const uint32x4_p8 s1 = Vector_sigma1(VectorLoad32x4u(W, (i-2)*4));
        const uint32x4_p8 w1 = VectorLoad32x4u(W, (i-7)*4);

        const uint32x4_p8 r = vec_add(s1, vec_add(w1, vec_add(s0, w0)));
        VectorStore32x4u(r, W, i*4);
    }
}

以下是v0突出显示的相关部分的图像。

enter image description here

c++ gcc sha intrinsics powerpc
1个回答
7
投票

乍一看,你已经完成了所有繁重的工作,截图看起来很像它将成为LE endian交换器部分。我假设你在这里。我希望v17是掩码变量 - 它早先从TOC加载为vs49。

你缺少的关键信息是v0是vs32(我知道无休止的混乱)。我不确定在哪里展示这个最好的地方,但ABI会这样做。你可以在这里下载:https://members.openpowerfoundation.org/document/dl/576

图2-17。作为VSR的一部分的向量寄存器在第44页应该有助于说明我的意思,这就是它在硬件中的作用。

© www.soinside.com 2019 - 2024. All rights reserved.