You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is there any shift right/left operation's implementation for typed_data Int32x4 on dart? #47114
I'm working on some crypto algorithms using SIMD on Dart. And I need to shift right all the lanes in Int32x4.
I have read the API Docs, and I have found the and/xor/or bit-wise operaion, but no shiftr/shiftl operaion.
Maybe I can implentment it as follwing:
import'dart:typed_data';
void_run10000000TimesXorAndShuffle(int x, int y, int z, int w) {
var ope =Int32x4(x, y, z, w);
var ope2 =Int32x4(y, z, w, x);
for (var i =0; i <10000000; ++i) {
var c = ope ^ ope2;
c.hashCode;
}
}
void_run10000000TimesShiftRightAndShuffle(int x, int y, int z, int w) {
var ope =Int32x4(x, y, z, w);
for (var i =0; i <10000000; ++i) {
var x = ope.x;
var y = ope.y;
var z = ope.z;
var w = ope.w;
var res =Int32x4(x <<1, y <<1, z <<1, w <<1);
res.hashCode;
}
}
voidmain() {
var start =DateTime.now().millisecondsSinceEpoch;
_run10000000TimesXorAndShuffle(0x918a57a0, 0x2095b753, 0x2041660, 0xe0e98a15);
var end =DateTime.now().millisecondsSinceEpoch;
print(end - start);
start =DateTime.now().millisecondsSinceEpoch;
_run10000000TimesShiftRightAndShuffle(
0x918a57a0, 0x2095b753, 0x2041660, 0xe0e98a15);
end =DateTime.now().millisecondsSinceEpoch;
print(end - start);
}
// 30// 7660
But it seems not efficient as the xor operation. So is there any other way to implement shiftr/shiftl operation on Int32x4, or will dart API add such method?
There is currently no shift operations on Int32x4.
If all you need is to do a left-shift by one, you can probably get around it as var res = ope + ope;.
Right shift, as you ask for, is much harder to simulate.
Activity
lrhn commentedon Sep 6, 2021
There is currently no shift operations on
Int32x4.If all you need is to do a left-shift by one, you can probably get around it as
var res = ope + ope;.Right shift, as you ask for, is much harder to simulate.
licy183 commentedon Sep 6, 2021
So will Dart SDK add such operators in the future? I think this is important for mathematical calculations using SIMD on Dart.