Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Side by Side Diff: runtime/lib/bigint.dart

Issue 2983633002: Avoid Bigint literals in Dart core library (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | runtime/lib/typed_data_patch.dart » ('j') | runtime/lib/typed_data_patch.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 import 'dart:typed_data' show Uint32List; 5 import 'dart:typed_data' show Uint32List;
6 6
7 // Copyright 2009 The Go Authors. All rights reserved. 7 // Copyright 2009 The Go Authors. All rights reserved.
8 // Use of this source code is governed by a BSD-style 8 // Use of this source code is governed by a BSD-style
9 // license that can be found in the LICENSE file. 9 // license that can be found in the LICENSE file.
10 10
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 // Bits per digit. 50 // Bits per digit.
51 static const int _DIGIT_BITS = 32; 51 static const int _DIGIT_BITS = 32;
52 static const int _LOG2_DIGIT_BITS = 5; 52 static const int _LOG2_DIGIT_BITS = 5;
53 static const int _DIGIT_BASE = 1 << _DIGIT_BITS; 53 static const int _DIGIT_BASE = 1 << _DIGIT_BITS;
54 static const int _DIGIT_MASK = (1 << _DIGIT_BITS) - 1; 54 static const int _DIGIT_MASK = (1 << _DIGIT_BITS) - 1;
55 55
56 // Bits per half digit. 56 // Bits per half digit.
57 static const int _DIGIT2_BITS = _DIGIT_BITS >> 1; 57 static const int _DIGIT2_BITS = _DIGIT_BITS >> 1;
58 static const int _DIGIT2_MASK = (1 << _DIGIT2_BITS) - 1; 58 static const int _DIGIT2_MASK = (1 << _DIGIT2_BITS) - 1;
59 59
60 // Bits per 2 digits
61 static const int _TWO_DIGITS_BITS = _DIGIT_BITS << 1;
62 static const int _TWO_DIGITS_MASK = (1 << _TWO_DIGITS_BITS) - 1;
regis 2017/07/17 16:45:31 How is this supposed to work? Do you avoid the cre
alexmarkov 2017/07/17 20:21:28 Done.
63
60 // Min and max of non bigint values. 64 // Min and max of non bigint values.
61 static const int _MIN_INT64 = (-1) << 63; 65 static const int _MIN_INT64 = (-1) << 63;
62 static const int _MAX_INT64 = 0x7fffffffffffffff; 66 static const int _MAX_INT64 = 0x7fffffffffffffff;
63 67
64 // Bigint constant values. 68 // Bigint constant values.
65 // Note: Not declared as final in order to satisfy optimizer, which expects 69 // Note: Not declared as final in order to satisfy optimizer, which expects
66 // constants to be in canonical form (Smi). 70 // constants to be in canonical form (Smi).
67 static _Bigint _MINUS_ONE = new _Bigint._fromInt(-1); 71 static _Bigint _MINUS_ONE = new _Bigint._fromInt(-1);
68 static _Bigint _ZERO = new _Bigint._fromInt(0); 72 static _Bigint _ZERO = new _Bigint._fromInt(0);
69 static _Bigint _ONE = new _Bigint._fromInt(1); 73 static _Bigint _ONE = new _Bigint._fromInt(1);
(...skipping 1855 matching lines...) Expand 10 before | Expand all | Expand 10 after
1925 // args[_RHO.._RHO_HI] = 1/args[_X.._X_HI] mod _DIGIT_BASE^2. 1929 // args[_RHO.._RHO_HI] = 1/args[_X.._X_HI] mod _DIGIT_BASE^2.
1926 static void _invDigitPair(Uint32List args) { 1930 static void _invDigitPair(Uint32List args) {
1927 var xl = args[_X]; // Lower 32-bit digit of x. 1931 var xl = args[_X]; // Lower 32-bit digit of x.
1928 var y = xl & 3; // y == 1/x mod 2^2 1932 var y = xl & 3; // y == 1/x mod 2^2
1929 y = (y * (2 - (xl & 0xf) * y)) & 0xf; // y == 1/x mod 2^4 1933 y = (y * (2 - (xl & 0xf) * y)) & 0xf; // y == 1/x mod 2^4
1930 y = (y * (2 - (xl & 0xff) * y)) & 0xff; // y == 1/x mod 2^8 1934 y = (y * (2 - (xl & 0xff) * y)) & 0xff; // y == 1/x mod 2^8
1931 y = (y * (2 - (((xl & 0xffff) * y) & 0xffff))) & 1935 y = (y * (2 - (((xl & 0xffff) * y) & 0xffff))) &
1932 0xffff; // y == 1/x mod 2^16 1936 0xffff; // y == 1/x mod 2^16
1933 y = (y * (2 - ((xl * y) & 0xffffffff))) & 0xffffffff; // y == 1/x mod 2^32 1937 y = (y * (2 - ((xl * y) & 0xffffffff))) & 0xffffffff; // y == 1/x mod 2^32
1934 var x = (args[_X_HI] << _Bigint._DIGIT_BITS) | xl; 1938 var x = (args[_X_HI] << _Bigint._DIGIT_BITS) | xl;
1935 y = (y * (2 - ((x * y) & 0xffffffffffffffff))) & 0xffffffffffffffff; 1939 y = (y * (2 - ((x * y) & _Bigint._TWO_DIGITS_MASK))) &
1940 _Bigint._TWO_DIGITS_MASK;
1936 // y == 1/x mod _DIGIT_BASE^2 1941 // y == 1/x mod _DIGIT_BASE^2
1937 y = -y; // We really want the negative inverse. 1942 y = -y; // We really want the negative inverse.
1938 args[_RHO] = y & _Bigint._DIGIT_MASK; 1943 args[_RHO] = y & _Bigint._DIGIT_MASK;
1939 args[_RHO_HI] = (y >> _Bigint._DIGIT_BITS) & _Bigint._DIGIT_MASK; 1944 args[_RHO_HI] = (y >> _Bigint._DIGIT_BITS) & _Bigint._DIGIT_MASK;
1940 } 1945 }
1941 1946
1942 // Operation: 1947 // Operation:
1943 // args[_MU] = args[_RHO]*digits[i] mod _DIGIT_BASE. 1948 // args[_MU] = args[_RHO]*digits[i] mod _DIGIT_BASE.
1944 // return 1. 1949 // return 1.
1945 // Note: Intrinsics on 64-bit platforms process digit pairs at even indices: 1950 // Note: Intrinsics on 64-bit platforms process digit pairs at even indices:
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
2114 return _reduce(r_digits, r_used); 2119 return _reduce(r_digits, r_used);
2115 } 2120 }
2116 2121
2117 int _mul(Uint32List x_digits, int x_used, Uint32List y_digits, int y_used, 2122 int _mul(Uint32List x_digits, int x_used, Uint32List y_digits, int y_used,
2118 Uint32List r_digits) { 2123 Uint32List r_digits) {
2119 var r_used = 2124 var r_used =
2120 _Bigint._mulDigits(x_digits, x_used, y_digits, y_used, r_digits); 2125 _Bigint._mulDigits(x_digits, x_used, y_digits, y_used, r_digits);
2121 return _reduce(r_digits, r_used); 2126 return _reduce(r_digits, r_used);
2122 } 2127 }
2123 } 2128 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/typed_data_patch.dart » ('j') | runtime/lib/typed_data_patch.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698