| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 } | 182 } |
| 183 | 183 |
| 184 if (negative) { | 184 if (negative) { |
| 185 _l = ~_l & _MASK; | 185 _l = ~_l & _MASK; |
| 186 _m = ~_m & _MASK; | 186 _m = ~_m & _MASK; |
| 187 _h = ~_h & _MASK_2; | 187 _h = ~_h & _MASK_2; |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 | 190 |
| 191 factory int64.fromBytes(List<int> bytes) { | 191 factory int64.fromBytes(List<int> bytes) { |
| 192 int top = bytes[7] & 0xff; | 192 int top = bytes[7] & 0xff; |
| 193 top <<= 8; | 193 top <<= 8; |
| 194 top |= bytes[6] & 0xff; | 194 top |= bytes[6] & 0xff; |
| 195 top <<= 8; | 195 top <<= 8; |
| 196 top |= bytes[5] & 0xff; | 196 top |= bytes[5] & 0xff; |
| 197 top <<= 8; | 197 top <<= 8; |
| 198 top |= bytes[4] & 0xff; | 198 top |= bytes[4] & 0xff; |
| 199 | 199 |
| 200 int bottom = bytes[3] & 0xff; | 200 int bottom = bytes[3] & 0xff; |
| 201 bottom <<= 8; | 201 bottom <<= 8; |
| 202 bottom |= bytes[2] & 0xff; | 202 bottom |= bytes[2] & 0xff; |
| 203 bottom <<= 8; | 203 bottom <<= 8; |
| 204 bottom |= bytes[1] & 0xff; | 204 bottom |= bytes[1] & 0xff; |
| 205 bottom <<= 8; | 205 bottom <<= 8; |
| 206 bottom |= bytes[0] & 0xff; | 206 bottom |= bytes[0] & 0xff; |
| 207 | 207 |
| 208 return new int64.fromInts(top, bottom); | 208 return new int64.fromInts(top, bottom); |
| 209 } | 209 } |
| 210 | 210 |
| 211 factory int64.fromBytesBigEndian(List<int> bytes) { | 211 factory int64.fromBytesBigEndian(List<int> bytes) { |
| 212 int top = bytes[0] & 0xff; | 212 int top = bytes[0] & 0xff; |
| 213 top <<= 8; | 213 top <<= 8; |
| 214 top |= bytes[1] & 0xff; | 214 top |= bytes[1] & 0xff; |
| 215 top <<= 8; | 215 top <<= 8; |
| 216 top |= bytes[2] & 0xff; | 216 top |= bytes[2] & 0xff; |
| 217 top <<= 8; | 217 top <<= 8; |
| 218 top |= bytes[3] & 0xff; | 218 top |= bytes[3] & 0xff; |
| 219 | 219 |
| 220 int bottom = bytes[4] & 0xff; | 220 int bottom = bytes[4] & 0xff; |
| 221 bottom <<= 8; | 221 bottom <<= 8; |
| 222 bottom |= bytes[5] & 0xff; | 222 bottom |= bytes[5] & 0xff; |
| 223 bottom <<= 8; | 223 bottom <<= 8; |
| 224 bottom |= bytes[6] & 0xff; | 224 bottom |= bytes[6] & 0xff; |
| 225 bottom <<= 8; | 225 bottom <<= 8; |
| 226 bottom |= bytes[7] & 0xff; | 226 bottom |= bytes[7] & 0xff; |
| 227 | 227 |
| 228 return new int64.fromInts(top, bottom); | 228 return new int64.fromInts(top, bottom); |
| 229 } | 229 } |
| 230 | 230 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 n &= 63; | 451 n &= 63; |
| 452 | 452 |
| 453 int res0, res1, res2; | 453 int res0, res1, res2; |
| 454 | 454 |
| 455 // Sign extend h(a). | 455 // Sign extend h(a). |
| 456 int a2 = _h; | 456 int a2 = _h; |
| 457 bool negative = (a2 & _SIGN_BIT_VALUE) != 0; | 457 bool negative = (a2 & _SIGN_BIT_VALUE) != 0; |
| 458 if (negative) { | 458 if (negative) { |
| 459 a2 += 0x3 << _BITS2; // add extra one bits on the left | 459 a2 += 0x3 << _BITS2; // add extra one bits on the left |
| 460 } | 460 } |
| 461 | 461 |
| 462 if (n < _BITS) { | 462 if (n < _BITS) { |
| 463 res2 = _shiftRight(a2, n); | 463 res2 = _shiftRight(a2, n); |
| 464 if (negative) { | 464 if (negative) { |
| 465 res2 |= _MASK_2 & ~(_MASK_2 >> n); | 465 res2 |= _MASK_2 & ~(_MASK_2 >> n); |
| 466 } | 466 } |
| 467 res1 = _shiftRight(_m, n) | (a2 << (_BITS - n)); | 467 res1 = _shiftRight(_m, n) | (a2 << (_BITS - n)); |
| 468 res0 = _shiftRight(_l, n) | (_m << (_BITS - n)); | 468 res0 = _shiftRight(_l, n) | (_m << (_BITS - n)); |
| 469 } else if (n < _BITS01) { | 469 } else if (n < _BITS01) { |
| 470 res2 = negative ? _MASK_2 : 0; | 470 res2 = negative ? _MASK_2 : 0; |
| 471 res1 = _shiftRight(a2, n - _BITS); | 471 res1 = _shiftRight(a2, n - _BITS); |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1088 } | 1088 } |
| 1089 } | 1089 } |
| 1090 return ZERO; | 1090 return ZERO; |
| 1091 } | 1091 } |
| 1092 | 1092 |
| 1093 // Generate the quotient using bit-at-a-time long division. | 1093 // Generate the quotient using bit-at-a-time long division. |
| 1094 return _divModHelper(aIsCopy ? a : new int64._copy(a), b, negative, | 1094 return _divModHelper(aIsCopy ? a : new int64._copy(a), b, negative, |
| 1095 aIsNegative, aIsMinValue, computeRemainder); | 1095 aIsNegative, aIsMinValue, computeRemainder); |
| 1096 } | 1096 } |
| 1097 } | 1097 } |
| OLD | NEW |