aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-05-26 16:29:59 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-05-26 16:29:59 -0700
commit196cc4113a0ab6a0f04d482689428951a19e3725 (patch)
tree5b47f7650f3fc935327a132c498636acc45ccd7c
parent78ee9a8f64d734405e8e85e03c3d3768fce45e41 (diff)
improve AUTO_OPTIMIZE
-rw-r--r--src/library.js26
-rw-r--r--src/library_sdl.js1
-rw-r--r--src/parseTools.js8
-rw-r--r--src/preamble.js11
-rw-r--r--tests/runner.py20
5 files changed, 43 insertions, 23 deletions
diff --git a/src/library.js b/src/library.js
index bd9491af..ab560ad4 100644
--- a/src/library.js
+++ b/src/library.js
@@ -1281,10 +1281,15 @@ var Library = {
// Converts a value we have as signed, into an unsigned value. For
// example, -1 in int32 would be a very large number as unsigned.
-function unSign(value, bits, ignore) {
- if (value >= 0) return value;
+function unSign(value, bits, ignore, sig) {
+ if (value >= 0) {
#if CHECK_SIGNS
- if (!ignore) CorrectionsMonitor.note('UnSign');
+ if (!ignore) CorrectionsMonitor.note('UnSign', 1, sig);
+#endif
+ return value;
+ }
+#if CHECK_SIGNS
+ if (!ignore) CorrectionsMonitor.note('UnSign', 0, sig);
#endif
return bits <= 32 ? 2*Math.abs(1 << (bits-1)) + value // Need some trickery, since if bits == 32, we are right at the limit of the bits JS uses in bitshifts
: Math.pow(2, bits) + value;
@@ -1293,8 +1298,13 @@ function unSign(value, bits, ignore) {
// Converts a value we have as unsigned, into a signed value. For
// example, 200 in a uint8 would be a negative number.
-function reSign(value, bits, ignore) {
- if (value <= 0) return value;
+function reSign(value, bits, ignore, sig) {
+ if (value <= 0) {
+#if CHECK_SIGNS
+ if (!ignore) CorrectionsMonitor.note('ReSign', 1, sig);
+#endif
+ return value;
+ }
var half = bits <= 32 ? Math.abs(1 << (bits-1)) // abs is needed if bits == 32
: Math.pow(2, bits-1);
#if CHECK_SIGNS
@@ -1303,7 +1313,7 @@ function reSign(value, bits, ignore) {
if (value >= half) {
#if CHECK_SIGNS
if (!ignore) {
- CorrectionsMonitor.note('ReSign');
+ CorrectionsMonitor.note('ReSign', 0, sig);
noted = true;
}
#endif
@@ -1315,11 +1325,11 @@ function reSign(value, bits, ignore) {
// would indeed give the exact same result.
if (bits === 32 && (value|0) !== value && typeof value !== 'boolean') {
if (!ignore) {
- CorrectionsMonitor.note('ReSign');
+ CorrectionsMonitor.note('ReSign', 0, sig);
noted = true;
}
}
- if (!noted) CorrectionsMonitor.note('ReSign', true);
+ if (!noted) CorrectionsMonitor.note('ReSign', 1, sig);
#endif
return value;
}
diff --git a/src/library_sdl.js b/src/library_sdl.js
index dbd509ed..909292ba 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -170,6 +170,7 @@ mergeInto(Library, {
}
surfData.ctx.putImageData(surfData.image, 0, 0);
}
+ __shutdownRuntime__();
throw 'SDL_Quit!';
},
diff --git a/src/parseTools.js b/src/parseTools.js
index 5dec458e..bd68888b 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -850,7 +850,9 @@ function handleOverflow(text, bits) {
if (!bits) return text;
var correct = correctOverflows();
warn(!correct || bits <= 32, 'Cannot correct overflows of this many bits: ' + bits);
- if (CHECK_OVERFLOWS) return 'CHECK_OVERFLOW(' + text + ', ' + bits + ')';
+ if (CHECK_OVERFLOWS) return 'CHECK_OVERFLOW(' + text + ', ' + bits + ', ' + Math.floor(correctSpecificOverflow() && !AUTO_OPTIMIZE) + (
+ AUTO_OPTIMIZE ? ', "' + Debugging.getIdentifier(Framework.currItem.lineNum) + '"' : ''
+ ) + ')';
if (!correct) return text;
if (bits <= 32) {
return '(' + text + ')&' + (Math.pow(2, bits) - 1);
@@ -897,7 +899,9 @@ function makeSignOp(value, type, op) {
}
}
}
- return op + 'Sign(' + value + ', ' + bits + ', ' + Math.floor(correctSpecificSign()) + ')'; // If we are correcting a specific sign here, do not check for it
+ return op + 'Sign(' + value + ', ' + bits + ', ' + Math.floor(correctSpecificSign() && !AUTO_OPTIMIZE) + (
+ AUTO_OPTIMIZE ? ', "' + Debugging.getIdentifier(Framework.currItem.lineNum) + '"' : ''
+ ) + ')'; // If we are correcting a specific sign here, do not check for it
} else {
return value;
}
diff --git a/src/preamble.js b/src/preamble.js
index cb4e8571..1a4fdff3 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -117,7 +117,6 @@ var CorrectionsMonitor = {
if (this.corrections >= this.MAX_ALLOWED) abort('\n\nToo many corrections!');
}
#if AUTO_OPTIMIZE
- if (succeed) return; // XXX - enable this later on, as a profiling tool
if (!sig)
sig = (new Error().stack).toString().split('\n')[2].split(':').slice(-1)[0]; // Spidermonkey-specific FIXME
sig = type + '|' + sig;
@@ -157,18 +156,18 @@ function cRound(x) {
//========================================
// Debugging tools - Mathop overflows
//========================================
-function CHECK_OVERFLOW(value, bits, ignore) {
+function CHECK_OVERFLOW(value, bits, ignore, sig) {
if (ignore) return value;
var twopbits = Math.pow(2, bits);
var twopbits1 = Math.pow(2, bits-1);
// For signedness issue here, see settings.js, CHECK_SIGNED_OVERFLOWS
#if CHECK_SIGNED_OVERFLOWS
if (value === Infinity || value === -Infinity || value >= twopbits1 || value < -twopbits1) {
- CorrectionsMonitor.note('SignedOverflow');
+ CorrectionsMonitor.note('SignedOverflow', 0, sig);
if (value === Infinity || value === -Infinity || Math.abs(value) >= twopbits) CorrectionsMonitor.note('Overflow');
#else
if (value === Infinity || value === -Infinity || Math.abs(value) >= twopbits) {
- CorrectionsMonitor.note('Overflow');
+ CorrectionsMonitor.note('Overflow', 0, sig);
#endif
#if CORRECT_OVERFLOWS
// Fail on >32 bits - we warned at compile time
@@ -178,9 +177,9 @@ function CHECK_OVERFLOW(value, bits, ignore) {
#endif
} else {
#if CHECK_SIGNED_OVERFLOWS
- CorrectionsMonitor.note('SignedOverflow', 1);
+ CorrectionsMonitor.note('SignedOverflow', 1, sig);
#endif
- CorrectionsMonitor.note('Overflow', 1);
+ CorrectionsMonitor.note('Overflow', 1, sig);
}
return value;
}
diff --git a/tests/runner.py b/tests/runner.py
index b978acb4..f6c62087 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -2429,11 +2429,10 @@ if 'benchmark' not in sys.argv:
self.do_test(src.replace('TYPE', 'int'), '*-2**2**-5**5*')
def test_autooptimize(self):
- global CHECK_OVERFLOWS, CORRECT_OVERFLOWS, AUTO_OPTIMIZE
+ global CHECK_OVERFLOWS, CORRECT_OVERFLOWS, CHECK_SIGNS, CORRECT_SIGNS, AUTO_OPTIMIZE
+ global COMPILER_TEST_OPTS; COMPILER_TEST_OPTS = ['-g']
- AUTO_OPTIMIZE = 1
- CHECK_OVERFLOWS = 1
- CORRECT_OVERFLOWS = 1
+ AUTO_OPTIMIZE = CHECK_OVERFLOWS = CORRECT_OVERFLOWS = CHECK_SIGNS = CORRECT_SIGNS = 1
src = '''
#include<stdio.h>
@@ -2443,17 +2442,24 @@ if 'benchmark' not in sys.argv:
t = t*5 + 1;
}
printf("*%d,%d*\\n", t, t & 127);
+
+ int varey = 100;
+ unsigned int MAXEY = -1;
+ for (int j = 0; j < 2; j++) {
+ printf("*%d*\\n", varey >= MAXEY); // 100 >= -1? not in unsigned!
+ MAXEY = 1; // So we succeed the second time around
+ }
return 0;
}
'''
def check(output):
# TODO: check the line #
- assert 'Overflow' in output, 'no indication of Overflow corrections'
- assert '12 hits, %100 failures' in output, 'no notice of the amount of hits and failures'
+ assert 'Overflow|src.cpp:6 : 60 hits, %20 failures' in output, 'no indication of Overflow corrections'
+ assert 'UnSign|src.cpp:13 : 6 hits, %16 failures' in output, 'no indication of Sign corrections'
return output
- self.do_test(src, '*186854335,63*', output_nicerizer=check)
+ self.do_test(src, '*186854335,63*\n', output_nicerizer=check)
# Generate tests for all our compilers