operator * method

  1. @override
Int64 operator *(
  1. Object other
)

Multiplication operator.

Implementation

@override
Int64 operator *(Object other) {
  Int64 o = _promote(other);

  // Grab 13-bit chunks.
  int a0 = _l & 0x1fff;
  int a1 = (_l >> 13) | ((_m & 0xf) << 9);
  int a2 = (_m >> 4) & 0x1fff;
  int a3 = (_m >> 17) | ((_h & 0xff) << 5);
  int a4 = (_h & 0xfff00) >> 8;

  int b0 = o._l & 0x1fff;
  int b1 = (o._l >> 13) | ((o._m & 0xf) << 9);
  int b2 = (o._m >> 4) & 0x1fff;
  int b3 = (o._m >> 17) | ((o._h & 0xff) << 5);
  int b4 = (o._h & 0xfff00) >> 8;

  // Compute partial products.
  // Optimization: if b is small, avoid multiplying by parts that are 0.
  int p0 = a0 * b0; // << 0
  int p1 = a1 * b0; // << 13
  int p2 = a2 * b0; // << 26
  int p3 = a3 * b0; // << 39
  int p4 = a4 * b0; // << 52

  if (b1 != 0) {
    p1 += a0 * b1;
    p2 += a1 * b1;
    p3 += a2 * b1;
    p4 += a3 * b1;
  }
  if (b2 != 0) {
    p2 += a0 * b2;
    p3 += a1 * b2;
    p4 += a2 * b2;
  }
  if (b3 != 0) {
    p3 += a0 * b3;
    p4 += a1 * b3;
  }
  if (b4 != 0) {
    p4 += a0 * b4;
  }

  // Accumulate into 22-bit chunks:
  // .........................................c10|...................c00|
  // |....................|..................xxxx|xxxxxxxxxxxxxxxxxxxxxx| p0
  // |....................|......................|......................|
  // |....................|...................c11|......c01.............|
  // |....................|....xxxxxxxxxxxxxxxxxx|xxxxxxxxx.............| p1
  // |....................|......................|......................|
  // |.................c22|...............c12....|......................|
  // |..........xxxxxxxxxx|xxxxxxxxxxxxxxxxxx....|......................| p2
  // |....................|......................|......................|
  // |.................c23|..c13.................|......................|
  // |xxxxxxxxxxxxxxxxxxxx|xxxxx.................|......................| p3
  // |....................|......................|......................|
  // |.........c24........|......................|......................|
  // |xxxxxxxxxxxx........|......................|......................| p4

  int c00 = p0 & 0x3fffff;
  int c01 = (p1 & 0x1ff) << 13;
  int c0 = c00 + c01;

  int c10 = p0 >> 22;
  int c11 = p1 >> 9;
  int c12 = (p2 & 0x3ffff) << 4;
  int c13 = (p3 & 0x1f) << 17;
  int c1 = c10 + c11 + c12 + c13;

  int c22 = p2 >> 18;
  int c23 = p3 >> 5;
  int c24 = (p4 & 0xfff) << 8;
  int c2 = c22 + c23 + c24;

  // Propagate high bits from c0 -> c1, c1 -> c2.
  c1 += c0 >> _BITS;
  c2 += c1 >> _BITS;

  return Int64._masked(c0, c1, c2);
}