imul function

int imul(
  1. int a,
  2. int b
)

Returns the result of the C-like 32-bit multiplication of the two parameters.

Implementation

@pragma('vm:prefer-inline')
int imul(int a, int b) {
  final ah = (a >>> 16) & 0xffff;
  final al = a & 0xffff;
  final bh = (b >>> 16) & 0xffff;
  final bl = b & 0xffff;
  // the shift by 0 fixes the sign on the high part
  return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0)).toSigned(32);
}