2015-02-10 123 views
0

我正在使用AltiVec編程接口進行項目工作。AltiVec中mm_storel_epi64的等價物?

在一個地方,我想從一個向量寄存器8個字節存儲到緩衝器中。

在SSE,我們有一個固有_mm_storel_epi64到低8個字節SIMD寄存器的存儲到緩衝器中。

上的AltiVec執行8字節存儲任何想法?

+0

我的輸出指針未對齊。 – sunmoon 2015-02-10 09:28:26

回答

1

我認爲,配備AltiVec做到這一點的唯一方法是:

- load 16 bytes containing 8 byte destination buffer (`vec_ld`) 
- mask in the 8 bytes you want to write (`vec_sel`) 
- store the modified 16 byte vector (`vec_st`) 

這個假設需要8字節的目的當然落在一個16字節對齊矢量內。例如,假設目標地址是0x1004,那麼您將從地址0x1000加載,修改字節4..11,然後將該向量寫回0x1000。

+0

我想做未對齊的商店。 – sunmoon 2015-02-10 09:28:08

+0

您在問題中沒有提到這一點,但只要目標8字節位於對齊的16字節範圍內,那麼上述方法仍然有效。如果8字節的目的地位於16字節的邊界上,那麼你將不得不做更多的工作。 – 2015-02-10 09:29:39

+0

vec_st對齊傳入的指針並存儲向量寄存器。我可能會過度使用我不打算這樣做的數據。與vec_st。 – sunmoon 2015-02-10 09:32:01

0

我發現存放8個字節來存儲未對齊的地址的一種方式。

以下是節目。

下面的程序存儲到buf中的前8個字節的載體。 k - 我用作變量來改變buf中的位置以存儲數據

int main(int argc, char *argv[]) 
{ 
    unsigned char buf[40]; 
    vector unsigned char res; 
    vector unsigned char on = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; 

    memset(buf, 0, 40); 

    int k = atoi(argv[1]); 

    unsigned char *outp = &(buf[k]); 

    res = vec_perm(on, on, vec_lvsr(0, (unsigned char *)outp); 

    vec_ste((vector unsigned char)res, 0, (unsigned char *)outp); 

    vec_ste((vector unsigned short)res, 1, (unsigned short *)outp); 

    vec_ste((vector unsigned short)res, 2, (unsigned short *)outp); 

    vec_ste((vector unsigned short)res, 4, (unsigned short *)outp); 

    vec_ste((vector unsigned short)res, 6, (unsigned short *)outp); 

    vec_ste((vector unsigned char)res, 7, (unsigned char *)outp); 

    print(buf); 

} 
+1

謝謝Paul的格式化。 – sunmoon 2015-02-12 06:52:09