v / examples / cpu_features / SSE_and_MMX_Extensions / ssse3.v
31 lines · 29 sloc · 1006 bytes · 05377f3c0378ce0285bc8584106bf78865c551a6
Raw
1// SSE Instruction Set
2// SSSE3: Added with Xeon 5100 and early Core 2
3// PSIGNW, PSIGND, PSIGNB, PSHUFB, PMULHRSW, PMADDUBSW, PHSUBW, PHSUBSW, PHSUBD, PHADDW, PHADDSW,
4// PHADDD, PALIGNR, PABSW, PABSD, PABSB
5// The PSIGNW instruction negates or leaves elements unchanged based on another vector's signs.
6
7@[if amd64 && !tinyc && !msvc]
8fn psignw_example(a &i16, b &i16, result &i16) {
9 unsafe {
10 asm volatile amd64 {
11 movdqa xmm0, [a] // Load 8 signed 16-bit integers from array a into xmm0
12 movdqa xmm1, [b] // Load 8 signed 16-bit integers from array b into xmm1
13 psignw xmm0, xmm1 // Adjust the sign of elements in xmm0 based on xmm1
14 movdqa [result], xmm0 // Store the result back to memory
15 ; ; r (a)
16 r (b)
17 r (result)
18 ; xmm0
19 xmm1
20 }
21 }
22}
23
24fn main() {
25 a0 := [i16(1), -2, 3, -4, 5, -6, 7, -8]
26 b0 := [i16(1), -1, 1, -1, 1, -1, 1, -1]
27 result0 := []i16{len: 8}
28 psignw_example(&a0[0], &b0[0], &result0[0])
29 dump(result0)
30 assert result0 == [i16(1), 2, 3, 4, 5, 6, 7, 8]
31}
32