| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of fixnum; | 5 part of fixnum; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * An immutable 64-bit signed integer, in the range [-2^63, 2^63 - 1]. | 8 * An immutable 64-bit signed integer, in the range [-2^63, 2^63 - 1]. |
| 9 * Arithmetic operations may overflow in order to maintain this range. | 9 * Arithmetic operations may overflow in order to maintain this range. |
| 10 */ | 10 */ |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 } | 92 } |
| 93 | 93 |
| 94 // [radix] and [digit] are at most 6 bits, component is 22, so we can | 94 // [radix] and [digit] are at most 6 bits, component is 22, so we can |
| 95 // multiply and add within 30 bit temporary values. | 95 // multiply and add within 30 bit temporary values. |
| 96 d0 = d0 * radix + digit; | 96 d0 = d0 * radix + digit; |
| 97 int carry = d0 >> _BITS; | 97 int carry = d0 >> _BITS; |
| 98 d0 = _MASK & d0; | 98 d0 = _MASK & d0; |
| 99 | 99 |
| 100 d1 = d1 * radix + carry; | 100 d1 = d1 * radix + carry; |
| 101 carry = d1 >> _BITS; | 101 carry = d1 >> _BITS; |
| 102 d1 = _MASK & d1;; | 102 d1 = _MASK & d1; |
| 103 | 103 |
| 104 d2 = d2 * radix + carry; | 104 d2 = d2 * radix + carry; |
| 105 d2 = _MASK2 & d2; | 105 d2 = _MASK2 & d2; |
| 106 } | 106 } |
| 107 | 107 |
| 108 if (negative) return _negate(d0, d1, d2); | 108 if (negative) return _negate(d0, d1, d2); |
| 109 | 109 |
| 110 return new Int64._bits(d0, d1, d2); | 110 return new Int64._bits(d0, d1, d2); |
| 111 } | 111 } |
| 112 | 112 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 return new Int64.fromInts(top, bottom); | 195 return new Int64.fromInts(top, bottom); |
| 196 } | 196 } |
| 197 | 197 |
| 198 /** | 198 /** |
| 199 * Constructs an [Int64] from a pair of 32-bit integers having the value | 199 * Constructs an [Int64] from a pair of 32-bit integers having the value |
| 200 * [:((top & 0xffffffff) << 32) | (bottom & 0xffffffff):]. | 200 * [:((top & 0xffffffff) << 32) | (bottom & 0xffffffff):]. |
| 201 */ | 201 */ |
| 202 factory Int64.fromInts(int top, int bottom) { | 202 factory Int64.fromInts(int top, int bottom) { |
| 203 top &= 0xffffffff; | 203 top &= 0xffffffff; |
| 204 bottom &= 0xffffffff; | 204 bottom &= 0xffffffff; |
| 205 int d0 = bottom & _MASK; | 205 int d0 = _MASK & bottom; |
| 206 int d1 = ((top & 0xfff) << 10) | ((bottom >> _BITS) & 0x3ff); | 206 int d1 = ((0xfff & top) << 10) | (0x3ff & (bottom >> _BITS)); |
| 207 int d2 = (top >> 12) & _MASK2; | 207 int d2 = _MASK2 & (top >> 12); |
| 208 return new Int64._bits(d0, d1, d2); | 208 return new Int64._bits(d0, d1, d2); |
| 209 } | 209 } |
| 210 | 210 |
| 211 // Returns the [Int64] representation of the specified value. Throws | 211 // Returns the [Int64] representation of the specified value. Throws |
| 212 // [ArgumentError] for non-integer arguments. | 212 // [ArgumentError] for non-integer arguments. |
| 213 static Int64 _promote(val) { | 213 static Int64 _promote(val) { |
| 214 if (val is Int64) { | 214 if (val is Int64) { |
| 215 return val; | 215 return val; |
| 216 } else if (val is int) { | 216 } else if (val is int) { |
| 217 return new Int64(val); | 217 return new Int64(val); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 int c13 = (p3 & 0x1f) << 17; | 305 int c13 = (p3 & 0x1f) << 17; |
| 306 int c1 = c10 + c11 + c12 + c13; | 306 int c1 = c10 + c11 + c12 + c13; |
| 307 | 307 |
| 308 int c22 = p2 >> 18; | 308 int c22 = p2 >> 18; |
| 309 int c23 = p3 >> 5; | 309 int c23 = p3 >> 5; |
| 310 int c24 = (p4 & 0xfff) << 8; | 310 int c24 = (p4 & 0xfff) << 8; |
| 311 int c2 = c22 + c23 + c24; | 311 int c2 = c22 + c23 + c24; |
| 312 | 312 |
| 313 // Propagate high bits from c0 -> c1, c1 -> c2. | 313 // Propagate high bits from c0 -> c1, c1 -> c2. |
| 314 c1 += c0 >> _BITS; | 314 c1 += c0 >> _BITS; |
| 315 c0 &= _MASK; | |
| 316 c2 += c1 >> _BITS; | 315 c2 += c1 >> _BITS; |
| 317 c1 &= _MASK; | |
| 318 c2 &= _MASK2; | |
| 319 | 316 |
| 320 return new Int64._bits(c0, c1, c2); | 317 return Int64._masked(c0, c1, c2); |
| 321 } | 318 } |
| 322 | 319 |
| 323 Int64 operator %(other) => _divide(this, other, _RETURN_MOD); | 320 Int64 operator %(other) => _divide(this, other, _RETURN_MOD); |
| 324 | 321 |
| 325 Int64 operator ~/(other) => _divide(this, other, _RETURN_DIV); | 322 Int64 operator ~/(other) => _divide(this, other, _RETURN_DIV); |
| 326 | 323 |
| 327 Int64 remainder(other) => _divide(this, other, _RETURN_REM); | 324 Int64 remainder(other) => _divide(this, other, _RETURN_REM); |
| 328 | 325 |
| 329 Int64 operator &(other) { | 326 Int64 operator &(other) { |
| 330 Int64 o = _promote(other); | 327 Int64 o = _promote(other); |
| 331 int a0 = _l & o._l; | 328 int a0 = _l & o._l; |
| 332 int a1 = _m & o._m; | 329 int a1 = _m & o._m; |
| 333 int a2 = _h & o._h; | 330 int a2 = _h & o._h; |
| 334 return new Int64._bits(a0, a1, a2); | 331 return new Int64._bits(a0, a1, a2); |
| 335 } | 332 } |
| 336 | 333 |
| 337 Int64 operator |(other) { | 334 Int64 operator |(other) { |
| 338 Int64 o = _promote(other); | 335 Int64 o = _promote(other); |
| 339 int a0 = _l | o._l; | 336 int a0 = _l | o._l; |
| 340 int a1 = _m | o._m; | 337 int a1 = _m | o._m; |
| 341 int a2 = _h | o._h; | 338 int a2 = _h | o._h; |
| 342 return new Int64._bits(a0, a1, a2); | 339 return new Int64._bits(a0, a1, a2); |
| 343 } | 340 } |
| 344 | 341 |
| 345 Int64 operator ^(other) { | 342 Int64 operator ^(other) { |
| 346 Int64 o = _promote(other); | 343 Int64 o = _promote(other); |
| 347 int a0 = _l ^ o._l; | 344 int a0 = _l ^ o._l; |
| 348 int a1 = _m ^ o._m; | 345 int a1 = _m ^ o._m; |
| 349 int a2 = _h ^ o._h; | 346 int a2 = _h ^ o._h; |
| 350 return new Int64._bits(a0, a1, a2); | 347 return Int64._masked(a0, a1, a2); |
| 351 } | 348 } |
| 352 | 349 |
| 353 Int64 operator ~() { | 350 Int64 operator ~() { |
| 354 return Int64._masked(~_l, ~_m, ~_h); | 351 return Int64._masked(~_l, ~_m, ~_h); |
| 355 } | 352 } |
| 356 | 353 |
| 357 Int64 operator <<(int n) { | 354 Int64 operator <<(int n) { |
| 358 if (n < 0) { | 355 if (n < 0) { |
| 359 throw new ArgumentError(n); | 356 throw new ArgumentError(n); |
| 360 } | 357 } |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 assert(r2 < b2 || // Handles case where B = -(MIN_VALUE) | 1018 assert(r2 < b2 || // Handles case where B = -(MIN_VALUE) |
| 1022 new Int64._bits(r0, r1, r2) < new Int64._bits(b0, b1, b2)); | 1019 new Int64._bits(r0, r1, r2) < new Int64._bits(b0, b1, b2)); |
| 1023 | 1020 |
| 1024 assert(what == _RETURN_DIV || what == _RETURN_MOD || what == _RETURN_REM); | 1021 assert(what == _RETURN_DIV || what == _RETURN_MOD || what == _RETURN_REM); |
| 1025 if (what == _RETURN_DIV) { | 1022 if (what == _RETURN_DIV) { |
| 1026 if (aNeg != bNeg) return _negate(q0, q1, q2); | 1023 if (aNeg != bNeg) return _negate(q0, q1, q2); |
| 1027 return Int64._masked(q0, q1, q2); // Masking for type inferrer. | 1024 return Int64._masked(q0, q1, q2); // Masking for type inferrer. |
| 1028 } | 1025 } |
| 1029 | 1026 |
| 1030 if (!aNeg) { | 1027 if (!aNeg) { |
| 1031 return new Int64._bits(_MASK & r0, r1, r2); // Masking for type inferrer. | 1028 return Int64._masked(r0, r1, r2); // Masking for type inferrer. |
| 1032 } | 1029 } |
| 1033 | 1030 |
| 1034 if (what == _RETURN_MOD) { | 1031 if (what == _RETURN_MOD) { |
| 1035 if (r0 == 0 && r1 == 0 && r2 == 0) { | 1032 if (r0 == 0 && r1 == 0 && r2 == 0) { |
| 1036 return ZERO; | 1033 return ZERO; |
| 1037 } else { | 1034 } else { |
| 1038 return _sub(b0, b1, b2, r0, r1, r2); | 1035 return _sub(b0, b1, b2, r0, r1, r2); |
| 1039 } | 1036 } |
| 1040 } else { | 1037 } else { |
| 1041 return _negate(r0, r1, r2); | 1038 return _negate(r0, r1, r2); |
| 1042 } | 1039 } |
| 1043 } | 1040 } |
| 1044 } | 1041 } |
| OLD | NEW |