aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/long.js26
-rw-r--r--src/parseTools.js2
-rw-r--r--tests/i64_precise.txt126
-rwxr-xr-xtests/runner.py9
4 files changed, 89 insertions, 74 deletions
diff --git a/src/long.js b/src/long.js
index 47a194ce..71cffa79 100644
--- a/src/long.js
+++ b/src/long.js
@@ -1588,12 +1588,26 @@ var Wrapper = {
Wrapper.result[1] = parseInt(h.toString()) | 0;
}
},
- modulo: function(xl, xh, yl, yh) {
- var x = new goog.math.Long(xl, xh);
- var y = new goog.math.Long(yl, yh);
- var ret = x.modulo(y);
- Wrapper.result[0] = ret.low_;
- Wrapper.result[1] = ret.high_;
+ modulo: function(xl, xh, yl, yh, unsigned) {
+ if (!Wrapper.two32) Wrapper.makeTwo32();
+ if (!unsigned) {
+ var x = new goog.math.Long(xl, xh);
+ var y = new goog.math.Long(yl, yh);
+ var ret = x.modulo(y);
+ Wrapper.result[0] = ret.low_;
+ Wrapper.result[1] = ret.high_;
+ } else {
+ // slow precise bignum division
+ var x = Wrapper.lh2bignum(xl >>> 0, xh >>> 0);
+ var y = Wrapper.lh2bignum(yl >>> 0, yh >>> 0);
+ var z = new BigInteger();
+ x.divRemTo(y, null, z);
+ var l = new BigInteger();
+ var h = new BigInteger();
+ z.divRemTo(Wrapper.two32, h, l);
+ Wrapper.result[0] = parseInt(l.toString()) | 0;
+ Wrapper.result[1] = parseInt(h.toString()) | 0;
+ }
},
stringify: function(l, h, unsigned) {
var ret = new goog.math.Long(l, h).toString();
diff --git a/src/parseTools.js b/src/parseTools.js
index a37a7c54..c8543963 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -1741,7 +1741,7 @@ function processMathop(item) {
}
case 'urem': case 'srem': {
if (PRECISE_I64_MATH) {
- return i64PreciseOp('modulo');
+ return i64PreciseOp('modulo', op[0] === 'u');
} else {
warnI64_1();
return finish(splitI64(mergeI64(idents[0], op[0] === 'u') + '%' + mergeI64(idents[1], op[0] === 'u')));
diff --git a/tests/i64_precise.txt b/tests/i64_precise.txt
index f32aa177..7072cbf1 100644
--- a/tests/i64_precise.txt
+++ b/tests/i64_precise.txt
@@ -1,66 +1,66 @@
-unsigned 0: 0,5,5,18446744073709551611,0
-unsigned 1: 0,35,35,18446744073709551581,0
-unsigned 2: 1,195,196,18446744073709551422,195
-unsigned 3: 3,1020,1023,18446744073709550599,3060
-unsigned 4: 6,5195,5201,18446744073709546427,31170
-unsigned 5: 12,26165,26177,18446744073709525463,313980
-unsigned 6: 25,131205,131230,18446744073709420436,3280125
-unsigned 7: 51,656790,656841,18446744073708894877,33496290
-unsigned 8: 102,3285485,3285587,18446744073706266233,335119470
-unsigned 9: 204,16430495,16430699,18446744073693121325,3351820980
-unsigned 10: 409,82158615,82159024,18446744073627393410,33602873535
-unsigned 11: 819,410805360,410806179,18446744073298747075,336449589840
-unsigned 12: 1638,2054051375,2054053013,18446744071655501879,3364536152250
-unsigned 13: 3276,10270306025,10270309301,18446744063439248867,33645522537900
-unsigned 14: 6553,51351628425,51351634978,18446744022357929744,336507221069025
-unsigned 15: 13107,256758338730,256758351837,18446743816951225993,3365331545734110
-unsigned 16: 26214,1283792086865,1283792113079,18446742789917490965,33653325765079110
-unsigned 17: 52428,6418961220755,6418961273183,18446737654748383289,336533298881743140
-unsigned 18: 104857,32094807676635,32094807781492,18446711978901979838,3365365248548916195
-unsigned 19: 209715,160474041528900,160474041738615,18446583599668232431,15207069545523711884
-unsigned 20: 419430,802370213935955,802370214355385,18445941703496035091,4496745504385676562
-unsigned 21: 838860,4011851082262685,4011851083101545,18442732222628127791,8073977451737544988
-unsigned 22: 1677721,20059255436479245,20059255438156966,18426684818274750092,6972899699173253061
-unsigned 23: 3355443,100296277232727870,100296277236083313,18346447796480179189,14489229932752165722
-unsigned 24: 6710886,501481386264302645,501481386271013531,17945262687451959857,15765766351451925278
-unsigned 25: 13421772,2507406931522839815,2507406931536261587,15939337142200133573,10086413084431357332
-unsigned 26: 26843545,12537034658016852255,12537034658043695800,5909709415719542906,2731509698427185799
-unsigned 27: 53687091,7344941069760912792,7344941069814599883,11101803004002325915,16256528535618547016
-unsigned 28: 107374182,18277961276705625079,18277961276812999261,168782797111300719,15164270991448465002
-unsigned 29: 214748364,17602830091911144401,17602830092125892765,843913982013155579,4760510224565868172
-unsigned 30: 429496729,14227174171159966481,14227174171589463210,4219569902979081864,9259055794720517673
-unsigned 31: 858993459,15795638647556079442,15795638648415072901,2651105427012465633,8773778578690814806
-unsigned 32: 1717986918,5191216968711994521,5191216970429981439,13255527106715544013,2882763035818302198
-unsigned 33: 3435973836,7509340821390028539,7509340824826002375,10937403255755496913,3002188606886016004
-unsigned 34: 6871947673,653216062610254563,653216069482202236,17793528017971244726,1160311421120597163
-unsigned 35: 13743895347,3266080519209703020,3266080532953598367,15180663568243743943,7490496812310051716
-unsigned 36: 27487790694,16330403008365375515,16330403035853166209,2116341092831966795,8496689265331596482
-unsigned 37: 54975581388,7865039571622391941,7865039626597973329,10581704557062741063,3801217959335798268
-unsigned 38: 109951162777,2431711359960298133,2431711469911460910,16015032823700416260,10929097356750440461
-unsigned 39: 219902325555,12158560098336373990,12158560318238699545,6288184195275503181,3390366976150811602
-unsigned 40: 439804651110,5452574867622981757,5452575307427632867,12994169645891220969,4388876164940275662
-unsigned 41: 879609302220,8816143458544890479,8816144338154192699,9630601494773963357,18063307631679153268
-unsigned 42: 1759218604441,7187255533584415783,7187257292803020224,11259490299343740274,10731539484643328591
-unsigned 43: 3518437208883,17489586370770660544,17489589889207869427,957161221376099955,6745745258281429568
-unsigned 44: 7036874417766,13661061112131362751,13661068149005780517,4785689998452606631,1049124659338985498
-unsigned 45: 14073748835532,12965284445760691897,12965298519509527429,5481473701697695251,3112351931422336876
-unsigned 46: 28147497671065,9486612220139870617,9486640367637541682,8960160001067352064,11094552886493166961
-unsigned 47: 56294995342131,10540417378210381818,10540473673205723949,7906382990494511929,3425601976498736334
-unsigned 48: 112589990684262,15810287593493069793,15810400183483754055,2636569070207166085,4740441117117290918
-unsigned 49: 225179981368524,5267839372347670371,5268064552329038895,13179129881343249769,3129072874530825956
-unsigned 50: 450359962737049,7899208187469855979,7899658547432593028,10547986246202432686,9662536335886195571
-unsigned 51: 900719925474099,2616063588812288148,2616964308737762247,15831581204822737567,18056837904917260668
-unsigned 52: 1801439850948198,13107339541825663715,13109140981676611913,5341205971734836099,3467025862604273778
-unsigned 53: 3602879701896396,10250508683528109677,10254111563230006073,8199838269883338335,8794376607022815964
-unsigned 54: 7205759403792793,14467141661278337053,14474347420682129846,3986808171835007356,17354123729136361045
-unsigned 55: 14411518807585587,17211648867376814222,17226060386184399809,1249506725140322981,17050849970911342154
-unsigned 56: 28823037615171174,12703613606273432261,12732436643888603435,5771953505051290529,11664739411905079422
-unsigned 57: 57646075230342348,9042526938693641687,9100173013923984035,9461863210246252277,16227931067794422612
-unsigned 58: 115292150460684697,10048528802959375663,10163820953420060360,8513507421210860650,10457660234102286359
-unsigned 59: 230584300921369395,16807920381198316008,17038504682119685403,1869407993432605003,16929834404840843576
-unsigned 60: 461168601842738790,17170154638794455431,17631323240637194221,1737758036757834975,7428164801607120330
-unsigned 61: 922337203685477580,7452110880706682785,8374448084392160365,11916970396688346411,17096741387571593292
-unsigned 62: 1844674407370955161,9590438292969086497,11435112700340041658,10700980188111420280,7158457875815234233
+unsigned 0: 0,5,5,18446744073709551611,0,0,0,0,0
+unsigned 1: 0,35,35,18446744073709551581,0,0,0,0,0
+unsigned 2: 1,195,196,18446744073709551422,195,0,195,1,0
+unsigned 3: 3,1020,1023,18446744073709550599,3060,0,340,3,0
+unsigned 4: 6,5195,5201,18446744073709546427,31170,0,865,6,5
+unsigned 5: 12,26165,26177,18446744073709525463,313980,0,2180,12,5
+unsigned 6: 25,131205,131230,18446744073709420436,3280125,0,5248,25,5
+unsigned 7: 51,656790,656841,18446744073708894877,33496290,0,12878,51,12
+unsigned 8: 102,3285485,3285587,18446744073706266233,335119470,0,32210,102,65
+unsigned 9: 204,16430495,16430699,18446744073693121325,3351820980,0,80541,204,131
+unsigned 10: 409,82158615,82159024,18446744073627393410,33602873535,0,200876,409,331
+unsigned 11: 819,410805360,410806179,18446744073298747075,336449589840,0,501593,819,693
+unsigned 12: 1638,2054051375,2054053013,18446744071655501879,3364536152250,0,1253999,1638,1013
+unsigned 13: 3276,10270306025,10270309301,18446744063439248867,33645522537900,0,3135014,3276,161
+unsigned 14: 6553,51351628425,51351634978,18446744022357929744,336507221069025,0,7836354,6553,663
+unsigned 15: 13107,256758338730,256758351837,18446743816951225993,3365331545734110,0,19589405,13107,7395
+unsigned 16: 26214,1283792086865,1283792113079,18446742789917490965,33653325765079110,0,48973528,26214,23873
+unsigned 17: 52428,6418961220755,6418961273183,18446737654748383289,336533298881743140,0,122433837,52428,14519
+unsigned 18: 104857,32094807676635,32094807781492,18446711978901979838,3365365248548916195,0,306081689,104857,13162
+unsigned 19: 209715,160474041528900,160474041738615,18446583599668232431,15207069545523711884,0,765200589,209715,6765
+unsigned 20: 419430,802370213935955,802370214355385,18445941703496035091,4496745504385676562,0,1913001487,419430,243545
+unsigned 21: 838860,4011851082262685,4011851083101545,18442732222628127791,8073977451737544988,0,4782503733,838860,798305
+unsigned 22: 1677721,20059255436479245,20059255438156966,18426684818274750092,6972899699173253061,0,11956252223,1677721,655462
+unsigned 23: 3355443,100296277232727870,100296277236083313,18346447796480179189,14489229932752165722,0,29890621665,3355443,1255275
+unsigned 24: 6710886,501481386264302645,501481386271013531,17945262687451959857,15765766351451925278,0,74726554178,6710886,2920937
+unsigned 25: 13421772,2507406931522839815,2507406931536261587,15939337142200133573,10086413084431357332,0,186816385461,13421772,1182923
+unsigned 26: 26843545,12537034658016852255,12537034658043695800,5909709415719542906,2731509698427185799,0,467040946269,26843545,2368650
+unsigned 27: 53687091,7344941069760912792,7344941069814599883,11101803004002325915,16256528535618547016,0,136810189059,53687091,23175423
+unsigned 28: 107374182,18277961276705625079,18277961276812999261,168782797111300719,15164270991448465002,0,170226780183,107374182,62189773
+unsigned 29: 214748364,17602830091911144401,17602830092125892765,843913982013155579,4760510224565868172,0,81969565513,214748364,203573669
+unsigned 30: 429496729,14227174171159966481,14227174171589463210,4219569902979081864,9259055794720517673,0,33125221242,429496729,319649063
+unsigned 31: 858993459,15795638647556079442,15795638648415072901,2651105427012465633,8773778578690814806,0,18388543570,858993459,389570812
+unsigned 32: 1717986918,5191216968711994521,5191216970429981439,13255527106715544013,2882763035818302198,0,3021685971,1717986918,229867143
+unsigned 33: 3435973836,7509340821390028539,7509340824826002375,10937403255755496913,3002188606886016004,0,2185505821,3435973836,2008329183
+unsigned 34: 6871947673,653216062610254563,653216069482202236,17793528017971244726,1160311421120597163,0,95055447,6871947673,4792629732
+unsigned 35: 13743895347,3266080519209703020,3266080532953598367,15180663568243743943,7490496812310051716,0,237638634,13743895347,3109667022
+unsigned 36: 27487790694,16330403008365375515,16330403035853166209,2116341092831966795,8496689265331596482,0,594096600,27487790694,15548335115
+unsigned 37: 54975581388,7865039571622391941,7865039626597973329,10581704557062741063,3801217959335798268,0,143064236,54975581388,21692352373
+unsigned 38: 109951162777,2431711359960298133,2431711469911460910,16015032823700416260,10929097356750440461,0,22116285,109951162777,107902774688
+unsigned 39: 219902325555,12158560098336373990,12158560318238699545,6288184195275503181,3390366976150811602,0,55290729,219902325555,209605094395
+unsigned 40: 439804651110,5452574867622981757,5452575307427632867,12994169645891220969,4388876164940275662,0,12397719,439804651110,388268163667
+unsigned 41: 879609302220,8816143458544890479,8816144338154192699,9630601494773963357,18063307631679153268,0,10022794,879609302220,621910087799
+unsigned 42: 1759218604441,7187255533584415783,7187257292803020224,11259490299343740274,10731539484643328591,0,4085481,1759218604441,1350294194662
+unsigned 43: 3518437208883,17489586370770660544,17489589889207869427,957161221376099955,6745745258281429568,0,4970839,3518437208883,1473803897707
+unsigned 44: 7036874417766,13661061112131362751,13661068149005780517,4785689998452606631,1049124659338985498,0,1941353,7036874417766,3850578085353
+unsigned 45: 14073748835532,12965284445760691897,12965298519509527429,5481473701697695251,3112351931422336876,0,921238,14073748835532,12216012863281
+unsigned 46: 28147497671065,9486612220139870617,9486640367637541682,8960160001067352064,11094552886493166961,0,337032,28147497671065,4785065491537
+unsigned 47: 56294995342131,10540417378210381818,10540473673205723949,7906382990494511929,3425601976498736334,0,187235,56294995342131,23925326484033
+unsigned 48: 112589990684262,15810287593493069793,15810400183483754055,2636569070207166085,4740441117117290918,0,140423,112589990684262,63331636946967
+unsigned 49: 225179981368524,5267839372347670371,5268064552329038895,13179129881343249769,3129072874530825956,0,23393,225179981368524,204068193788439
+unsigned 50: 450359962737049,7899208187469855979,7899658547432593028,10547986246202432686,9662536335886195571,0,17539,450359962737049,344801024753568
+unsigned 51: 900719925474099,2616063588812288148,2616964308737762247,15831581204822737567,18056837904917260668,0,2904,900719925474099,372925235504652
+unsigned 52: 1801439850948198,13107339541825663715,13109140981676611913,5341205971734836099,3467025862604273778,0,7276,1801439850948198,63186326575067
+unsigned 53: 3602879701896396,10250508683528109677,10254111563230006073,8199838269883338335,8794376607022815964,0,2845,3602879701896396,315931632863057
+unsigned 54: 7205759403792793,14467141661278337053,14474347420682129846,3986808171835007356,17354123729136361045,0,2007,7205759403792793,5182537866201502
+unsigned 55: 14411518807585587,17211648867376814222,17226060386184399809,1249506725140322981,17050849970911342154,0,1194,14411518807585587,4295411119623344
+unsigned 56: 28823037615171174,12703613606273432261,12732436643888603435,5771953505051290529,11664739411905079422,0,440,28823037615171174,21477055598115701
+unsigned 57: 57646075230342348,9042526938693641687,9100173013923984035,9461863210246252277,16227931067794422612,0,156,57646075230342348,49739202760235399
+unsigned 58: 115292150460684697,10048528802959375663,10163820953420060360,8513507421210860650,10457660234102286359,0,87,115292150460684697,18111712879807024
+unsigned 59: 230584300921369395,16807920381198316008,17038504682119685403,1869407993432605003,16929834404840843576,0,72,230584300921369395,205850714859719568
+unsigned 60: 461168601842738790,17170154638794455431,17631323240637194221,1737758036757834975,7428164801607120330,0,37,461168601842738790,106916370613120201
+unsigned 61: 922337203685477580,7452110880706682785,8374448084392160365,11916970396688346411,17096741387571593292,0,8,922337203685477580,73413251222862145
+unsigned 62: 1844674407370955161,9590438292969086497,11435112700340041658,10700980188111420280,7158457875815234233,0,5,1844674407370955161,367066256114310692
signed 0: 0,5,5,-5,0,0,0,0,0
signed 1: 0,-35,-35,35,0,0,0,0,0
signed 2: -1,-155,-156,154,155,0,155,-1,0
diff --git a/tests/runner.py b/tests/runner.py
index 15883749..c7867c88 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -834,9 +834,6 @@ m_divisor is 1091269979
if Settings.USE_TYPED_ARRAYS != 2: return self.skip('full i64 stuff only in ta2')
Settings.PRECISE_I64_MATH = 1
- print 'TODO: i == 64 unsigned'
- print 'TODO: make precise the default, and imprecise in -O3'
-
src = r'''
#include <inttypes.h>
#include <stdio.h>
@@ -848,7 +845,7 @@ m_divisor is 1091269979
y += x;
x /= 3;
y *= 5;
- printf("unsigned %d: %llu,%llu,%llu,%llu,%llu\n", i, x, y, x+y, x-y, x*y);//, y ? x/y : 0, x ? y/x : 0, y ? x%y : 0, x ? y%x : 0);
+ printf("unsigned %d: %llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu\n", i, x, y, x+y, x-y, x*y, y ? x/y : 0, x ? y/x : 0, y ? x%y : 0, x ? y%x : 0);
}
int64_t x2 = 0, y2 = 0;
for (int i = 0; i < 64; i++) {
@@ -863,6 +860,10 @@ m_divisor is 1091269979
'''
self.do_run(src, open(path_from_root('tests', 'i64_precise.txt')).read())
+ print 'TODO: i == 64 unsigned'
+ print 'TODO: make precise the default, and imprecise in -O3'
+ #1/0.
+
def test_unaligned(self):
if Settings.QUANTUM_SIZE == 1: return self.skip('No meaning to unaligned addresses in q1')