Flutter Engine
The Flutter Engine
simd128.cc
Go to the documentation of this file.
1// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
6
7#include "vm/exceptions.h"
8#include "vm/native_entry.h"
9#include "vm/object.h"
10#include "vm/symbols.h"
11
12namespace dart {
13
14static void ThrowMaskRangeException(int64_t m) {
15 if ((m < 0) || (m > 255)) {
17 255);
18 }
19}
20
21DEFINE_NATIVE_ENTRY(Float32x4_fromDoubles, 0, 4) {
22 GET_NON_NULL_NATIVE_ARGUMENT(Double, x, arguments->NativeArgAt(0));
23 GET_NON_NULL_NATIVE_ARGUMENT(Double, y, arguments->NativeArgAt(1));
24 GET_NON_NULL_NATIVE_ARGUMENT(Double, z, arguments->NativeArgAt(2));
25 GET_NON_NULL_NATIVE_ARGUMENT(Double, w, arguments->NativeArgAt(3));
26 float _x = static_cast<float>(x.value());
27 float _y = static_cast<float>(y.value());
28 float _z = static_cast<float>(z.value());
29 float _w = static_cast<float>(w.value());
30 return Float32x4::New(_x, _y, _z, _w);
31}
32
33DEFINE_NATIVE_ENTRY(Float32x4_splat, 0, 1) {
34 GET_NON_NULL_NATIVE_ARGUMENT(Double, v, arguments->NativeArgAt(0));
35 float _v = v.value();
36 return Float32x4::New(_v, _v, _v, _v);
37}
38
39DEFINE_NATIVE_ENTRY(Float32x4_zero, 0, 1) {
40 ASSERT(
41 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(0)).IsNull());
42 return Float32x4::New(0.0f, 0.0f, 0.0f, 0.0f);
43}
44
45DEFINE_NATIVE_ENTRY(Float32x4_fromInt32x4Bits, 0, 2) {
46 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, v, arguments->NativeArgAt(1));
47 return Float32x4::New(v.value());
48}
49
50DEFINE_NATIVE_ENTRY(Float32x4_fromFloat64x2, 0, 2) {
51 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, v, arguments->NativeArgAt(1));
52 float _x = static_cast<float>(v.x());
53 float _y = static_cast<float>(v.y());
54 return Float32x4::New(_x, _y, 0.0f, 0.0f);
55}
56
57DEFINE_NATIVE_ENTRY(Float32x4_add, 0, 2) {
58 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
59 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, other, arguments->NativeArgAt(1));
60 float _x = self.x() + other.x();
61 float _y = self.y() + other.y();
62 float _z = self.z() + other.z();
63 float _w = self.w() + other.w();
64 return Float32x4::New(_x, _y, _z, _w);
65}
66
67DEFINE_NATIVE_ENTRY(Float32x4_negate, 0, 1) {
68 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
69 float _x = -self.x();
70 float _y = -self.y();
71 float _z = -self.z();
72 float _w = -self.w();
73 return Float32x4::New(_x, _y, _z, _w);
74}
75
76DEFINE_NATIVE_ENTRY(Float32x4_sub, 0, 2) {
77 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
78 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, other, arguments->NativeArgAt(1));
79 float _x = self.x() - other.x();
80 float _y = self.y() - other.y();
81 float _z = self.z() - other.z();
82 float _w = self.w() - other.w();
83 return Float32x4::New(_x, _y, _z, _w);
84}
85
86DEFINE_NATIVE_ENTRY(Float32x4_mul, 0, 2) {
87 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
88 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, other, arguments->NativeArgAt(1));
89 float _x = self.x() * other.x();
90 float _y = self.y() * other.y();
91 float _z = self.z() * other.z();
92 float _w = self.w() * other.w();
93 return Float32x4::New(_x, _y, _z, _w);
94}
95
96DEFINE_NATIVE_ENTRY(Float32x4_div, 0, 2) {
97 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
98 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, other, arguments->NativeArgAt(1));
99 float _x = Utils::DivideAllowZero(self.x(), other.x());
100 float _y = Utils::DivideAllowZero(self.y(), other.y());
101 float _z = Utils::DivideAllowZero(self.z(), other.z());
102 float _w = Utils::DivideAllowZero(self.w(), other.w());
103 return Float32x4::New(_x, _y, _z, _w);
104}
105
106DEFINE_NATIVE_ENTRY(Float32x4_cmplt, 0, 2) {
107 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, a, arguments->NativeArgAt(0));
108 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, b, arguments->NativeArgAt(1));
109 uint32_t _x = a.x() < b.x() ? 0xFFFFFFFF : 0x0;
110 uint32_t _y = a.y() < b.y() ? 0xFFFFFFFF : 0x0;
111 uint32_t _z = a.z() < b.z() ? 0xFFFFFFFF : 0x0;
112 uint32_t _w = a.w() < b.w() ? 0xFFFFFFFF : 0x0;
113 return Int32x4::New(_x, _y, _z, _w);
114}
115
116DEFINE_NATIVE_ENTRY(Float32x4_cmplte, 0, 2) {
117 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, a, arguments->NativeArgAt(0));
118 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, b, arguments->NativeArgAt(1));
119 uint32_t _x = a.x() <= b.x() ? 0xFFFFFFFF : 0x0;
120 uint32_t _y = a.y() <= b.y() ? 0xFFFFFFFF : 0x0;
121 uint32_t _z = a.z() <= b.z() ? 0xFFFFFFFF : 0x0;
122 uint32_t _w = a.w() <= b.w() ? 0xFFFFFFFF : 0x0;
123 return Int32x4::New(_x, _y, _z, _w);
124}
125
126DEFINE_NATIVE_ENTRY(Float32x4_cmpgt, 0, 2) {
127 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, a, arguments->NativeArgAt(0));
128 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, b, arguments->NativeArgAt(1));
129 uint32_t _x = a.x() > b.x() ? 0xFFFFFFFF : 0x0;
130 uint32_t _y = a.y() > b.y() ? 0xFFFFFFFF : 0x0;
131 uint32_t _z = a.z() > b.z() ? 0xFFFFFFFF : 0x0;
132 uint32_t _w = a.w() > b.w() ? 0xFFFFFFFF : 0x0;
133 return Int32x4::New(_x, _y, _z, _w);
134}
135
136DEFINE_NATIVE_ENTRY(Float32x4_cmpgte, 0, 2) {
137 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, a, arguments->NativeArgAt(0));
138 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, b, arguments->NativeArgAt(1));
139 uint32_t _x = a.x() >= b.x() ? 0xFFFFFFFF : 0x0;
140 uint32_t _y = a.y() >= b.y() ? 0xFFFFFFFF : 0x0;
141 uint32_t _z = a.z() >= b.z() ? 0xFFFFFFFF : 0x0;
142 uint32_t _w = a.w() >= b.w() ? 0xFFFFFFFF : 0x0;
143 return Int32x4::New(_x, _y, _z, _w);
144}
145
146DEFINE_NATIVE_ENTRY(Float32x4_cmpequal, 0, 2) {
147 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, a, arguments->NativeArgAt(0));
148 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, b, arguments->NativeArgAt(1));
149 uint32_t _x = a.x() == b.x() ? 0xFFFFFFFF : 0x0;
150 uint32_t _y = a.y() == b.y() ? 0xFFFFFFFF : 0x0;
151 uint32_t _z = a.z() == b.z() ? 0xFFFFFFFF : 0x0;
152 uint32_t _w = a.w() == b.w() ? 0xFFFFFFFF : 0x0;
153 return Int32x4::New(_x, _y, _z, _w);
154}
155
156DEFINE_NATIVE_ENTRY(Float32x4_cmpnequal, 0, 2) {
157 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, a, arguments->NativeArgAt(0));
158 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, b, arguments->NativeArgAt(1));
159 uint32_t _x = a.x() != b.x() ? 0xFFFFFFFF : 0x0;
160 uint32_t _y = a.y() != b.y() ? 0xFFFFFFFF : 0x0;
161 uint32_t _z = a.z() != b.z() ? 0xFFFFFFFF : 0x0;
162 uint32_t _w = a.w() != b.w() ? 0xFFFFFFFF : 0x0;
163 return Int32x4::New(_x, _y, _z, _w);
164}
165
166DEFINE_NATIVE_ENTRY(Float32x4_scale, 0, 2) {
167 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
168 GET_NON_NULL_NATIVE_ARGUMENT(Double, scale, arguments->NativeArgAt(1));
169 float _s = static_cast<float>(scale.value());
170 float _x = self.x() * _s;
171 float _y = self.y() * _s;
172 float _z = self.z() * _s;
173 float _w = self.w() * _s;
174 return Float32x4::New(_x, _y, _z, _w);
175}
176
177DEFINE_NATIVE_ENTRY(Float32x4_abs, 0, 1) {
178 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
179 float _x = fabsf(self.x());
180 float _y = fabsf(self.y());
181 float _z = fabsf(self.z());
182 float _w = fabsf(self.w());
183 return Float32x4::New(_x, _y, _z, _w);
184}
185
186DEFINE_NATIVE_ENTRY(Float32x4_clamp, 0, 3) {
187 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
188 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, lo, arguments->NativeArgAt(1));
189 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, hi, arguments->NativeArgAt(2));
190 // The order of the clamping must match the order of the optimized code:
191 // MAX(MIN(self, hi), lo).
192 float _x;
193 float _y;
194 float _z;
195 float _w;
196 // ARM semantics are different from X86/X64 at an instruction level. Ensure
197 // that we match the semantics of the architecture in the C version.
198#if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) || \
199 defined(USING_SIMULATOR)
200 _x = self.x() < hi.x() ? self.x() : hi.x();
201 _y = self.y() < hi.y() ? self.y() : hi.y();
202 _z = self.z() < hi.z() ? self.z() : hi.z();
203 _w = self.w() < hi.w() ? self.w() : hi.w();
204 _x = lo.x() < _x ? _x : lo.x();
205 _y = lo.y() < _y ? _y : lo.y();
206 _z = lo.z() < _z ? _z : lo.z();
207 _w = lo.w() < _w ? _w : lo.w();
208#else
209 _x = fminf(self.x(), hi.x());
210 _y = fminf(self.y(), hi.y());
211 _z = fminf(self.z(), hi.z());
212 _w = fminf(self.w(), hi.w());
213 _x = fmaxf(_x, lo.x());
214 _y = fmaxf(_y, lo.y());
215 _z = fmaxf(_z, lo.z());
216 _w = fmaxf(_w, lo.w());
217#endif
218 return Float32x4::New(_x, _y, _z, _w);
219}
220
221DEFINE_NATIVE_ENTRY(Float32x4_getX, 0, 1) {
222 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
223 double value = static_cast<double>(self.x());
224 return Double::New(value);
225}
226
227DEFINE_NATIVE_ENTRY(Float32x4_getY, 0, 1) {
228 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
229 double value = static_cast<double>(self.y());
230 return Double::New(value);
231}
232
233DEFINE_NATIVE_ENTRY(Float32x4_getZ, 0, 1) {
234 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
235 double value = static_cast<double>(self.z());
236 return Double::New(value);
237}
238
239DEFINE_NATIVE_ENTRY(Float32x4_getW, 0, 1) {
240 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
241 double value = static_cast<double>(self.w());
242 return Double::New(value);
243}
244
245DEFINE_NATIVE_ENTRY(Float32x4_getSignMask, 0, 1) {
246 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
247 uint32_t mx = (bit_cast<uint32_t>(self.x()) & 0x80000000) >> 31;
248 uint32_t my = (bit_cast<uint32_t>(self.y()) & 0x80000000) >> 31;
249 uint32_t mz = (bit_cast<uint32_t>(self.z()) & 0x80000000) >> 31;
250 uint32_t mw = (bit_cast<uint32_t>(self.w()) & 0x80000000) >> 31;
251 uint32_t value = mx | (my << 1) | (mz << 2) | (mw << 3);
252 return Integer::New(value);
253}
254
255DEFINE_NATIVE_ENTRY(Int32x4_getSignMask, 0, 1) {
256 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
257 uint32_t mx = (self.x() & 0x80000000) >> 31;
258 uint32_t my = (self.y() & 0x80000000) >> 31;
259 uint32_t mz = (self.z() & 0x80000000) >> 31;
260 uint32_t mw = (self.w() & 0x80000000) >> 31;
261 uint32_t value = mx | (my << 1) | (mz << 2) | (mw << 3);
262 return Integer::New(value);
263}
264
265DEFINE_NATIVE_ENTRY(Float32x4_shuffle, 0, 2) {
266 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
267 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(1));
268 int64_t m = mask.AsInt64Value();
270 float data[4] = {self.x(), self.y(), self.z(), self.w()};
271 float _x = data[m & 0x3];
272 float _y = data[(m >> 2) & 0x3];
273 float _z = data[(m >> 4) & 0x3];
274 float _w = data[(m >> 6) & 0x3];
275 return Float32x4::New(_x, _y, _z, _w);
276}
277
278DEFINE_NATIVE_ENTRY(Float32x4_shuffleMix, 0, 3) {
279 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
280 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, other, arguments->NativeArgAt(1));
281 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(2));
282 int64_t m = mask.AsInt64Value();
284 float data[4] = {self.x(), self.y(), self.z(), self.w()};
285 float other_data[4] = {other.x(), other.y(), other.z(), other.w()};
286 float _x = data[m & 0x3];
287 float _y = data[(m >> 2) & 0x3];
288 float _z = other_data[(m >> 4) & 0x3];
289 float _w = other_data[(m >> 6) & 0x3];
290 return Float32x4::New(_x, _y, _z, _w);
291}
292
293DEFINE_NATIVE_ENTRY(Float32x4_setX, 0, 2) {
294 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
295 GET_NON_NULL_NATIVE_ARGUMENT(Double, x, arguments->NativeArgAt(1));
296 float _x = static_cast<float>(x.value());
297 float _y = self.y();
298 float _z = self.z();
299 float _w = self.w();
300 return Float32x4::New(_x, _y, _z, _w);
301}
302
303DEFINE_NATIVE_ENTRY(Float32x4_setY, 0, 2) {
304 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
305 GET_NON_NULL_NATIVE_ARGUMENT(Double, y, arguments->NativeArgAt(1));
306 float _x = self.x();
307 float _y = static_cast<float>(y.value());
308 float _z = self.z();
309 float _w = self.w();
310 return Float32x4::New(_x, _y, _z, _w);
311}
312
313DEFINE_NATIVE_ENTRY(Float32x4_setZ, 0, 2) {
314 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
315 GET_NON_NULL_NATIVE_ARGUMENT(Double, z, arguments->NativeArgAt(1));
316 float _x = self.x();
317 float _y = self.y();
318 float _z = static_cast<float>(z.value());
319 float _w = self.w();
320 return Float32x4::New(_x, _y, _z, _w);
321}
322
323DEFINE_NATIVE_ENTRY(Float32x4_setW, 0, 2) {
324 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
325 GET_NON_NULL_NATIVE_ARGUMENT(Double, w, arguments->NativeArgAt(1));
326 float _x = self.x();
327 float _y = self.y();
328 float _z = self.z();
329 float _w = static_cast<float>(w.value());
330 return Float32x4::New(_x, _y, _z, _w);
331}
332
333DEFINE_NATIVE_ENTRY(Float32x4_min, 0, 2) {
334 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
335 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, other, arguments->NativeArgAt(1));
336 float _x = self.x() < other.x() ? self.x() : other.x();
337 float _y = self.y() < other.y() ? self.y() : other.y();
338 float _z = self.z() < other.z() ? self.z() : other.z();
339 float _w = self.w() < other.w() ? self.w() : other.w();
340 return Float32x4::New(_x, _y, _z, _w);
341}
342
343DEFINE_NATIVE_ENTRY(Float32x4_max, 0, 2) {
344 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
345 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, other, arguments->NativeArgAt(1));
346 float _x = self.x() > other.x() ? self.x() : other.x();
347 float _y = self.y() > other.y() ? self.y() : other.y();
348 float _z = self.z() > other.z() ? self.z() : other.z();
349 float _w = self.w() > other.w() ? self.w() : other.w();
350 return Float32x4::New(_x, _y, _z, _w);
351}
352
353DEFINE_NATIVE_ENTRY(Float32x4_sqrt, 0, 1) {
354 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
355 float _x = sqrtf(self.x());
356 float _y = sqrtf(self.y());
357 float _z = sqrtf(self.z());
358 float _w = sqrtf(self.w());
359 return Float32x4::New(_x, _y, _z, _w);
360}
361
362DEFINE_NATIVE_ENTRY(Float32x4_reciprocal, 0, 1) {
363 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
364 float _x = Utils::DivideAllowZero(1.0f, self.x());
365 float _y = Utils::DivideAllowZero(1.0f, self.y());
366 float _z = Utils::DivideAllowZero(1.0f, self.z());
367 float _w = Utils::DivideAllowZero(1.0f, self.w());
368 return Float32x4::New(_x, _y, _z, _w);
369}
370
371DEFINE_NATIVE_ENTRY(Float32x4_reciprocalSqrt, 0, 1) {
372 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, self, arguments->NativeArgAt(0));
373 float _x = sqrtf(Utils::DivideAllowZero(1.0f, self.x()));
374 float _y = sqrtf(Utils::DivideAllowZero(1.0f, self.y()));
375 float _z = sqrtf(Utils::DivideAllowZero(1.0f, self.z()));
376 float _w = sqrtf(Utils::DivideAllowZero(1.0f, self.w()));
377 return Float32x4::New(_x, _y, _z, _w);
378}
379
380DEFINE_NATIVE_ENTRY(Int32x4_fromInts, 0, 4) {
381 GET_NON_NULL_NATIVE_ARGUMENT(Integer, x, arguments->NativeArgAt(0));
382 GET_NON_NULL_NATIVE_ARGUMENT(Integer, y, arguments->NativeArgAt(1));
383 GET_NON_NULL_NATIVE_ARGUMENT(Integer, z, arguments->NativeArgAt(2));
384 GET_NON_NULL_NATIVE_ARGUMENT(Integer, w, arguments->NativeArgAt(3));
385 int32_t _x = static_cast<int32_t>(x.AsTruncatedUint32Value());
386 int32_t _y = static_cast<int32_t>(y.AsTruncatedUint32Value());
387 int32_t _z = static_cast<int32_t>(z.AsTruncatedUint32Value());
388 int32_t _w = static_cast<int32_t>(w.AsTruncatedUint32Value());
389 return Int32x4::New(_x, _y, _z, _w);
390}
391
392DEFINE_NATIVE_ENTRY(Int32x4_fromBools, 0, 4) {
393 GET_NON_NULL_NATIVE_ARGUMENT(Bool, x, arguments->NativeArgAt(0));
394 GET_NON_NULL_NATIVE_ARGUMENT(Bool, y, arguments->NativeArgAt(1));
395 GET_NON_NULL_NATIVE_ARGUMENT(Bool, z, arguments->NativeArgAt(2));
396 GET_NON_NULL_NATIVE_ARGUMENT(Bool, w, arguments->NativeArgAt(3));
397 int32_t _x = x.value() ? 0xFFFFFFFF : 0x0;
398 int32_t _y = y.value() ? 0xFFFFFFFF : 0x0;
399 int32_t _z = z.value() ? 0xFFFFFFFF : 0x0;
400 int32_t _w = w.value() ? 0xFFFFFFFF : 0x0;
401 return Int32x4::New(_x, _y, _z, _w);
402}
403
404DEFINE_NATIVE_ENTRY(Int32x4_fromFloat32x4Bits, 0, 2) {
405 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, v, arguments->NativeArgAt(1));
406 return Int32x4::New(v.value());
407}
408
409DEFINE_NATIVE_ENTRY(Int32x4_or, 0, 2) {
410 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
411 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, other, arguments->NativeArgAt(1));
412 int32_t _x = self.x() | other.x();
413 int32_t _y = self.y() | other.y();
414 int32_t _z = self.z() | other.z();
415 int32_t _w = self.w() | other.w();
416 return Int32x4::New(_x, _y, _z, _w);
417}
418
419DEFINE_NATIVE_ENTRY(Int32x4_and, 0, 2) {
420 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
421 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, other, arguments->NativeArgAt(1));
422 int32_t _x = self.x() & other.x();
423 int32_t _y = self.y() & other.y();
424 int32_t _z = self.z() & other.z();
425 int32_t _w = self.w() & other.w();
426 return Int32x4::New(_x, _y, _z, _w);
427}
428
429DEFINE_NATIVE_ENTRY(Int32x4_xor, 0, 2) {
430 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
431 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, other, arguments->NativeArgAt(1));
432 int32_t _x = self.x() ^ other.x();
433 int32_t _y = self.y() ^ other.y();
434 int32_t _z = self.z() ^ other.z();
435 int32_t _w = self.w() ^ other.w();
436 return Int32x4::New(_x, _y, _z, _w);
437}
438
439DEFINE_NATIVE_ENTRY(Int32x4_add, 0, 2) {
440 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
441 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, other, arguments->NativeArgAt(1));
442 int32_t _x = self.x() + other.x();
443 int32_t _y = self.y() + other.y();
444 int32_t _z = self.z() + other.z();
445 int32_t _w = self.w() + other.w();
446 return Int32x4::New(_x, _y, _z, _w);
447}
448
449DEFINE_NATIVE_ENTRY(Int32x4_sub, 0, 2) {
450 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
451 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, other, arguments->NativeArgAt(1));
452 int32_t _x = self.x() - other.x();
453 int32_t _y = self.y() - other.y();
454 int32_t _z = self.z() - other.z();
455 int32_t _w = self.w() - other.w();
456 return Int32x4::New(_x, _y, _z, _w);
457}
458
459DEFINE_NATIVE_ENTRY(Int32x4_getX, 0, 1) {
460 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
461 int32_t value = self.x();
462 return Integer::New(value);
463}
464
465DEFINE_NATIVE_ENTRY(Int32x4_getY, 0, 1) {
466 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
467 int32_t value = self.y();
468 return Integer::New(value);
469}
470
471DEFINE_NATIVE_ENTRY(Int32x4_getZ, 0, 1) {
472 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
473 int32_t value = self.z();
474 return Integer::New(value);
475}
476
477DEFINE_NATIVE_ENTRY(Int32x4_getW, 0, 1) {
478 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
479 int32_t value = self.w();
480 return Integer::New(value);
481}
482
483DEFINE_NATIVE_ENTRY(Int32x4_shuffle, 0, 2) {
484 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
485 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(1));
486 int64_t m = mask.AsInt64Value();
488 int32_t data[4] = {self.x(), self.y(), self.z(), self.w()};
489 int32_t _x = data[m & 0x3];
490 int32_t _y = data[(m >> 2) & 0x3];
491 int32_t _z = data[(m >> 4) & 0x3];
492 int32_t _w = data[(m >> 6) & 0x3];
493 return Int32x4::New(_x, _y, _z, _w);
494}
495
496DEFINE_NATIVE_ENTRY(Int32x4_shuffleMix, 0, 3) {
497 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
498 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, zw, arguments->NativeArgAt(1));
499 GET_NON_NULL_NATIVE_ARGUMENT(Integer, mask, arguments->NativeArgAt(2));
500 int64_t m = mask.AsInt64Value();
502 int32_t data[4] = {self.x(), self.y(), self.z(), self.w()};
503 int32_t zw_data[4] = {zw.x(), zw.y(), zw.z(), zw.w()};
504 int32_t _x = data[m & 0x3];
505 int32_t _y = data[(m >> 2) & 0x3];
506 int32_t _z = zw_data[(m >> 4) & 0x3];
507 int32_t _w = zw_data[(m >> 6) & 0x3];
508 return Int32x4::New(_x, _y, _z, _w);
509}
510
511DEFINE_NATIVE_ENTRY(Int32x4_setX, 0, 2) {
512 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
513 GET_NON_NULL_NATIVE_ARGUMENT(Integer, x, arguments->NativeArgAt(1));
514 int32_t _x = static_cast<int32_t>(x.AsInt64Value() & 0xFFFFFFFF);
515 int32_t _y = self.y();
516 int32_t _z = self.z();
517 int32_t _w = self.w();
518 return Int32x4::New(_x, _y, _z, _w);
519}
520
521DEFINE_NATIVE_ENTRY(Int32x4_setY, 0, 2) {
522 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
523 GET_NON_NULL_NATIVE_ARGUMENT(Integer, y, arguments->NativeArgAt(1));
524 int32_t _x = self.x();
525 int32_t _y = static_cast<int32_t>(y.AsInt64Value() & 0xFFFFFFFF);
526 int32_t _z = self.z();
527 int32_t _w = self.w();
528 return Int32x4::New(_x, _y, _z, _w);
529}
530
531DEFINE_NATIVE_ENTRY(Int32x4_setZ, 0, 2) {
532 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
533 GET_NON_NULL_NATIVE_ARGUMENT(Integer, z, arguments->NativeArgAt(1));
534 int32_t _x = self.x();
535 int32_t _y = self.y();
536 int32_t _z = static_cast<int32_t>(z.AsInt64Value() & 0xFFFFFFFF);
537 int32_t _w = self.w();
538 return Int32x4::New(_x, _y, _z, _w);
539}
540
541DEFINE_NATIVE_ENTRY(Int32x4_setW, 0, 2) {
542 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
543 GET_NON_NULL_NATIVE_ARGUMENT(Integer, w, arguments->NativeArgAt(1));
544 int32_t _x = self.x();
545 int32_t _y = self.y();
546 int32_t _z = self.z();
547 int32_t _w = static_cast<int32_t>(w.AsInt64Value() & 0xFFFFFFFF);
548 return Int32x4::New(_x, _y, _z, _w);
549}
550
551DEFINE_NATIVE_ENTRY(Int32x4_getFlagX, 0, 1) {
552 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
553 int32_t value = self.x();
554 return Bool::Get(value != 0).ptr();
555}
556
557DEFINE_NATIVE_ENTRY(Int32x4_getFlagY, 0, 1) {
558 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
559 int32_t value = self.y();
560 return Bool::Get(value != 0).ptr();
561}
562
563DEFINE_NATIVE_ENTRY(Int32x4_getFlagZ, 0, 1) {
564 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
565 int32_t value = self.z();
566 return Bool::Get(value != 0).ptr();
567}
568
569DEFINE_NATIVE_ENTRY(Int32x4_getFlagW, 0, 1) {
570 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
571 int32_t value = self.w();
572 return Bool::Get(value != 0).ptr();
573}
574
575DEFINE_NATIVE_ENTRY(Int32x4_setFlagX, 0, 2) {
576 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
577 GET_NON_NULL_NATIVE_ARGUMENT(Bool, flagX, arguments->NativeArgAt(1));
578 int32_t _x = self.x();
579 int32_t _y = self.y();
580 int32_t _z = self.z();
581 int32_t _w = self.w();
582 _x = flagX.ptr() == Bool::True().ptr() ? 0xFFFFFFFF : 0x0;
583 return Int32x4::New(_x, _y, _z, _w);
584}
585
586DEFINE_NATIVE_ENTRY(Int32x4_setFlagY, 0, 2) {
587 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
588 GET_NON_NULL_NATIVE_ARGUMENT(Bool, flagY, arguments->NativeArgAt(1));
589 int32_t _x = self.x();
590 int32_t _y = self.y();
591 int32_t _z = self.z();
592 int32_t _w = self.w();
593 _y = flagY.ptr() == Bool::True().ptr() ? 0xFFFFFFFF : 0x0;
594 return Int32x4::New(_x, _y, _z, _w);
595}
596
597DEFINE_NATIVE_ENTRY(Int32x4_setFlagZ, 0, 2) {
598 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
599 GET_NON_NULL_NATIVE_ARGUMENT(Bool, flagZ, arguments->NativeArgAt(1));
600 int32_t _x = self.x();
601 int32_t _y = self.y();
602 int32_t _z = self.z();
603 int32_t _w = self.w();
604 _z = flagZ.ptr() == Bool::True().ptr() ? 0xFFFFFFFF : 0x0;
605 return Int32x4::New(_x, _y, _z, _w);
606}
607
608DEFINE_NATIVE_ENTRY(Int32x4_setFlagW, 0, 2) {
609 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
610 GET_NON_NULL_NATIVE_ARGUMENT(Bool, flagW, arguments->NativeArgAt(1));
611 int32_t _x = self.x();
612 int32_t _y = self.y();
613 int32_t _z = self.z();
614 int32_t _w = self.w();
615 _w = flagW.ptr() == Bool::True().ptr() ? 0xFFFFFFFF : 0x0;
616 return Int32x4::New(_x, _y, _z, _w);
617}
618
619// Used to convert between int32_t and float32 without breaking strict
620// aliasing rules.
622 float f;
623 int32_t u;
624 float32_int32(float v) { f = v; }
625 float32_int32(int32_t v) { u = v; }
626};
627
628DEFINE_NATIVE_ENTRY(Int32x4_select, 0, 3) {
629 GET_NON_NULL_NATIVE_ARGUMENT(Int32x4, self, arguments->NativeArgAt(0));
630 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, tv, arguments->NativeArgAt(1));
631 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, fv, arguments->NativeArgAt(2));
632 int32_t _maskX = self.x();
633 int32_t _maskY = self.y();
634 int32_t _maskZ = self.z();
635 int32_t _maskW = self.w();
636 // Extract floats and interpret them as masks.
637 float32_int32 tvx(tv.x());
638 float32_int32 tvy(tv.y());
639 float32_int32 tvz(tv.z());
640 float32_int32 tvw(tv.w());
641 float32_int32 fvx(fv.x());
642 float32_int32 fvy(fv.y());
643 float32_int32 fvz(fv.z());
644 float32_int32 fvw(fv.w());
645 // Perform select.
646 float32_int32 tempX((_maskX & tvx.u) | (~_maskX & fvx.u));
647 float32_int32 tempY((_maskY & tvy.u) | (~_maskY & fvy.u));
648 float32_int32 tempZ((_maskZ & tvz.u) | (~_maskZ & fvz.u));
649 float32_int32 tempW((_maskW & tvw.u) | (~_maskW & fvw.u));
650 return Float32x4::New(tempX.f, tempY.f, tempZ.f, tempW.f);
651}
652
653DEFINE_NATIVE_ENTRY(Float64x2_fromDoubles, 0, 2) {
654 GET_NON_NULL_NATIVE_ARGUMENT(Double, x, arguments->NativeArgAt(0));
655 GET_NON_NULL_NATIVE_ARGUMENT(Double, y, arguments->NativeArgAt(1));
656 return Float64x2::New(x.value(), y.value());
657}
658
659DEFINE_NATIVE_ENTRY(Float64x2_splat, 0, 1) {
660 GET_NON_NULL_NATIVE_ARGUMENT(Double, v, arguments->NativeArgAt(0));
661 return Float64x2::New(v.value(), v.value());
662}
663
664DEFINE_NATIVE_ENTRY(Float64x2_zero, 0, 1) {
665 ASSERT(
666 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(0)).IsNull());
667 return Float64x2::New(0.0, 0.0);
668}
669
670DEFINE_NATIVE_ENTRY(Float64x2_fromFloat32x4, 0, 2) {
671 ASSERT(
672 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(0)).IsNull());
673 GET_NON_NULL_NATIVE_ARGUMENT(Float32x4, v, arguments->NativeArgAt(1));
674 double _x = v.x();
675 double _y = v.y();
676 return Float64x2::New(_x, _y);
677}
678
679DEFINE_NATIVE_ENTRY(Float64x2_add, 0, 2) {
680 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0));
681 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, other, arguments->NativeArgAt(1));
682 double _x = self.x() + other.x();
683 double _y = self.y() + other.y();
684 return Float64x2::New(_x, _y);
685}
686
687DEFINE_NATIVE_ENTRY(Float64x2_negate, 0, 1) {
688 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0));
689 double _x = -self.x();
690 double _y = -self.y();
691 return Float64x2::New(_x, _y);
692}
693
694DEFINE_NATIVE_ENTRY(Float64x2_sub, 0, 2) {
695 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0));
696 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, other, arguments->NativeArgAt(1));
697 double _x = self.x() - other.x();
698 double _y = self.y() - other.y();
699 return Float64x2::New(_x, _y);
700}
701
702DEFINE_NATIVE_ENTRY(Float64x2_mul, 0, 2) {
703 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0));
704 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, other, arguments->NativeArgAt(1));
705 double _x = self.x() * other.x();
706 double _y = self.y() * other.y();
707 return Float64x2::New(_x, _y);
708}
709
710DEFINE_NATIVE_ENTRY(Float64x2_div, 0, 2) {
711 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0));
712 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, other, arguments->NativeArgAt(1));
713 double _x = Utils::DivideAllowZero(self.x(), other.x());
714 double _y = Utils::DivideAllowZero(self.y(), other.y());
715 return Float64x2::New(_x, _y);
716}
717
718DEFINE_NATIVE_ENTRY(Float64x2_scale, 0, 2) {
719 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0));
720 GET_NON_NULL_NATIVE_ARGUMENT(Double, scale, arguments->NativeArgAt(1));
721 double _s = scale.value();
722 double _x = self.x() * _s;
723 double _y = self.y() * _s;
724 return Float64x2::New(_x, _y);
725}
726
727DEFINE_NATIVE_ENTRY(Float64x2_abs, 0, 1) {
728 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0));
729 double _x = fabs(self.x());
730 double _y = fabs(self.y());
731 return Float64x2::New(_x, _y);
732}
733
734DEFINE_NATIVE_ENTRY(Float64x2_clamp, 0, 3) {
735 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0));
736 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, lo, arguments->NativeArgAt(1));
737 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, hi, arguments->NativeArgAt(2));
738 // The order of the clamping must match the order of the optimized code:
739 // MAX(MIN(self, hi), lo).
740 double _x;
741 double _y;
742
743 // ARM semantics are different from X86/X64 at an instruction level. Ensure
744 // that we match the semantics of the architecture in the C version.
745#if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) || \
746 defined(USING_SIMULATOR)
747 _x = self.x() < hi.x() ? self.x() : hi.x();
748 _y = self.y() < hi.y() ? self.y() : hi.y();
749 _x = lo.x() < _x ? _x : lo.x();
750 _y = lo.y() < _y ? _y : lo.y();
751#else
752 _x = fmin(self.x(), hi.x());
753 _y = fmin(self.y(), hi.y());
754 _x = fmax(_x, lo.x());
755 _y = fmax(_y, lo.y());
756#endif
757 return Float64x2::New(_x, _y);
758}
759
760DEFINE_NATIVE_ENTRY(Float64x2_getX, 0, 1) {
761 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0));
762 return Double::New(self.x());
763}
764
765DEFINE_NATIVE_ENTRY(Float64x2_getY, 0, 1) {
766 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0));
767 return Double::New(self.y());
768}
769
770DEFINE_NATIVE_ENTRY(Float64x2_getSignMask, 0, 1) {
771 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0));
772 uint32_t mx = (bit_cast<uint64_t>(self.x()) & 0x8000000000000000LL) >> 63;
773 uint32_t my = (bit_cast<uint64_t>(self.y()) & 0x8000000000000000LL) >> 63;
774 uint32_t value = mx | (my << 1);
775 return Integer::New(value);
776}
777
778DEFINE_NATIVE_ENTRY(Float64x2_setX, 0, 2) {
779 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0));
780 GET_NON_NULL_NATIVE_ARGUMENT(Double, x, arguments->NativeArgAt(1));
781 double _x = x.value();
782 double _y = self.y();
783 return Float64x2::New(_x, _y);
784}
785
786DEFINE_NATIVE_ENTRY(Float64x2_setY, 0, 2) {
787 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0));
788 GET_NON_NULL_NATIVE_ARGUMENT(Double, y, arguments->NativeArgAt(1));
789 double _x = self.x();
790 double _y = y.value();
791 return Float64x2::New(_x, _y);
792}
793
794DEFINE_NATIVE_ENTRY(Float64x2_min, 0, 2) {
795 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0));
796 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, other, arguments->NativeArgAt(1));
797 double _x = self.x() < other.x() ? self.x() : other.x();
798 double _y = self.y() < other.y() ? self.y() : other.y();
799 return Float64x2::New(_x, _y);
800}
801
802DEFINE_NATIVE_ENTRY(Float64x2_max, 0, 2) {
803 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0));
804 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, other, arguments->NativeArgAt(1));
805 double _x = self.x() > other.x() ? self.x() : other.x();
806 double _y = self.y() > other.y() ? self.y() : other.y();
807 return Float64x2::New(_x, _y);
808}
809
810DEFINE_NATIVE_ENTRY(Float64x2_sqrt, 0, 1) {
811 GET_NON_NULL_NATIVE_ARGUMENT(Float64x2, self, arguments->NativeArgAt(0));
812 double _x = sqrt(self.x());
813 double _y = sqrt(self.y());
814 return Float64x2::New(_x, _y);
815}
816
817} // namespace dart
static const Bool & Get(bool value)
Definition: object.h:10801
static const Bool & True()
Definition: object.h:10797
static DoublePtr New(double d, Heap::Space space=Heap::kNew)
Definition: object.cc:23402
static DART_NORETURN void ThrowRangeError(const char *argument_name, const Integer &argument_value, intptr_t expected_from, intptr_t expected_to)
Definition: exceptions.cc:1094
static Float32x4Ptr New(float value0, float value1, float value2, float value3, Heap::Space space=Heap::kNew)
Definition: object.cc:25307
static Float64x2Ptr New(double value0, double value1, Heap::Space space=Heap::kNew)
Definition: object.cc:25475
static Int32x4Ptr New(int32_t value0, int32_t value1, int32_t value2, int32_t value3, Heap::Space space=Heap::kNew)
Definition: object.cc:25391
static IntegerPtr New(const String &str, Heap::Space space=Heap::kNew)
Definition: object.cc:22984
ObjectPtr ptr() const
Definition: object.h:332
static Object & Handle()
Definition: object.h:407
static float DivideAllowZero(float a, float b)
Definition: utils.h:496
#define ASSERT(E)
static bool b
struct MyStruct a[10]
uint8_t value
double y
double x
Definition: dart_vm.cc:33
static void ThrowMaskRangeException(int64_t m)
Definition: simd128.cc:14
DEFINE_NATIVE_ENTRY(List_allocate, 0, 2)
Definition: array.cc:13
static int8_t data[kExtLength]
SIN Vec< N, float > sqrt(const Vec< N, float > &x)
Definition: SkVx.h:706
#define GET_NON_NULL_NATIVE_ARGUMENT(type, name, value)
Definition: native_entry.h:74
SkScalar w
const Scalar scale
float32_int32(float v)
Definition: simd128.cc:624
float32_int32(int32_t v)
Definition: simd128.cc:625