Source file
src/simd/archsimd/ops_emulated_wasm.go
1
2
3
4
5
6
7 package archsimd
8
9 var nn = [2]int64{-1 << 63, -1 << 63}
10 var f0s = [16]int8{-1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0}
11 var ff00s = [8]int16{-1, 0, -1, 0, -1, 0, -1, 0}
12 var ffff0000s = [4]int32{-1, 0, -1, 0}
13
14
15
16
17
18
19
20
21
22 func (x Uint64x2) Less(y Uint64x2) Mask64x2 {
23 signs := LoadInt64x2Array(&nn)
24 ix := x.BitsToInt64().Xor(signs)
25 iy := y.BitsToInt64().Xor(signs)
26 return ix.Less(iy)
27 }
28
29
30 func (x Uint64x2) LessEqual(y Uint64x2) Mask64x2 {
31 signs := LoadInt64x2Array(&nn)
32 ix := x.BitsToInt64().Xor(signs)
33 iy := y.BitsToInt64().Xor(signs)
34 return ix.LessEqual(iy)
35 }
36
37
38 func (x Uint64x2) Greater(y Uint64x2) Mask64x2 {
39 signs := LoadInt64x2Array(&nn)
40 ix := x.BitsToInt64().Xor(signs)
41 iy := y.BitsToInt64().Xor(signs)
42 return ix.Greater(iy)
43 }
44
45
46 func (x Uint64x2) GreaterEqual(y Uint64x2) Mask64x2 {
47 signs := LoadInt64x2Array(&nn)
48 ix := x.BitsToInt64().Xor(signs)
49 iy := y.BitsToInt64().Xor(signs)
50 return ix.GreaterEqual(iy)
51 }
52
53
54 func (x Int64x2) Max(y Int64x2) Int64x2 {
55 mask := x.Greater(y).ToInt64x2()
56 return x.And(mask).Or(y.AndNot(mask))
57 }
58
59
60 func (x Int64x2) Min(y Int64x2) Int64x2 {
61 mask := x.Less(y).ToInt64x2()
62 return x.And(mask).Or(y.AndNot(mask))
63 }
64
65
66 func (x Uint64x2) Max(y Uint64x2) Uint64x2 {
67 mask := x.Greater(y).ToInt64x2().ToBits()
68 return x.And(mask).Or(y.AndNot(mask))
69 }
70
71
72 func (x Uint64x2) Min(y Uint64x2) Uint64x2 {
73 mask := x.Less(y).ToInt64x2().ToBits()
74 return x.And(mask).Or(y.AndNot(mask))
75 }
76
77
78 func (x Int8x16) Mul(y Int8x16) Int8x16 {
79
80
81
82
83 mask := LoadInt8x16Array(&f0s)
84 mask16 := mask.ToBits().ReshapeToUint16s()
85 xe := x.And(mask).ToBits().ReshapeToUint16s()
86 xo := x.AndNot(mask).ToBits().ReshapeToUint16s().ShiftAllRight(8)
87 ye := y.And(mask).ToBits().ReshapeToUint16s()
88 yo := y.AndNot(mask).ToBits().ReshapeToUint16s().ShiftAllRight(8)
89 pe := xe.Mul(ye).And(mask16)
90 po := xo.Mul(yo).And(mask16).ShiftAllLeft(8)
91 return pe.Or(po).ReshapeToUint8s().BitsToInt8()
92 }
93
94
95 func (x Uint8x16) Mul(y Uint8x16) Uint8x16 {
96 mask := LoadInt8x16Array(&f0s).ToBits()
97 mask16 := mask.ReshapeToUint16s()
98 xe := x.And(mask).ReshapeToUint16s()
99 xo := x.AndNot(mask).ReshapeToUint16s().ShiftAllRight(8)
100 ye := y.And(mask).ReshapeToUint16s()
101 yo := y.AndNot(mask).ReshapeToUint16s().ShiftAllRight(8)
102 pe := xe.Mul(ye).And(mask16)
103 po := xo.Mul(yo).And(mask16).ShiftAllLeft(8)
104 return pe.Or(po).ReshapeToUint8s()
105 }
106
107
108 func (x Int16x8) OnesCount() Int16x8 {
109 mask := LoadInt8x16Array(&f0s)
110 c := x.ToBits().ReshapeToUint8s().BitsToInt8().OnesCount()
111 ce := c.And(mask).ToBits().ReshapeToUint16s().BitsToInt16()
112 co := c.AndNot(mask).ToBits().ReshapeToUint16s().BitsToInt16().ShiftAllRight(8)
113 return ce.Add(co)
114 }
115
116
117 func (x Int32x4) OnesCount() Int32x4 {
118 mask := LoadInt8x16Array(&f0s)
119 c := x.ToBits().ReshapeToUint8s().BitsToInt8().OnesCount()
120 ce := c.And(mask).ToBits().ReshapeToUint16s().BitsToInt16()
121 co := c.AndNot(mask).ToBits().ReshapeToUint16s().BitsToInt16().ShiftAllRight(8)
122 mask16 := LoadInt16x8Array(&ff00s)
123 y := ce.Add(co)
124 ye := y.And(mask16).ToBits().ReshapeToUint32s().BitsToInt32()
125 yo := y.AndNot(mask16).ToBits().ReshapeToUint32s().BitsToInt32().ShiftAllRight(16)
126 return ye.Add(yo)
127 }
128
129
130 func (x Int64x2) OnesCount() Int64x2 {
131 mask := LoadInt8x16Array(&f0s)
132 c := x.ToBits().ReshapeToUint8s().BitsToInt8().OnesCount()
133 ce := c.And(mask).ToBits().ReshapeToUint16s().BitsToInt16()
134 co := c.AndNot(mask).ToBits().ReshapeToUint16s().BitsToInt16().ShiftAllRight(8)
135 mask16 := LoadInt16x8Array(&ff00s)
136 y := ce.Add(co)
137 ye := y.And(mask16).ToBits().ReshapeToUint32s().BitsToInt32()
138 yo := y.AndNot(mask16).ToBits().ReshapeToUint32s().BitsToInt32().ShiftAllRight(16)
139 mask32 := LoadInt32x4Array(&ffff0000s)
140 z := ye.Add(yo)
141 ze := z.And(mask32).ToBits().ReshapeToUint64s().BitsToInt64()
142 zo := z.AndNot(mask32).ToBits().ReshapeToUint64s().BitsToInt64().ShiftAllRight(32)
143 return ze.Add(zo)
144 }
145
146
147 func (x Uint8x16) OnesCount() Uint8x16 {
148 return x.BitsToInt8().OnesCount().ToBits()
149 }
150
151
152 func (x Uint16x8) OnesCount() Uint16x8 {
153 return x.BitsToInt16().OnesCount().ToBits()
154 }
155
156
157 func (x Uint32x4) OnesCount() Uint32x4 {
158 return x.BitsToInt32().OnesCount().ToBits()
159 }
160
161
162 func (x Uint64x2) OnesCount() Uint64x2 {
163 return x.BitsToInt64().OnesCount().ToBits()
164 }
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180 func (x Uint64x2) CarrylessMultiplyEven(y Uint64x2) Uint64x2 {
181 return x.carrylessMultiply(y)
182 }
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198 func (x Uint64x2) CarrylessMultiplyOdd(y Uint64x2) Uint64x2 {
199 x = x.SetElem(0, x.GetElem(1))
200 y = y.SetElem(0, x.GetElem(1))
201 return x.carrylessMultiply(y)
202 }
203
View as plain text