Skip to content

Instantly share code, notes, and snippets.

@pnkfelix
Created February 25, 2013 17:57
Show Gist options
  • Save pnkfelix/5031812 to your computer and use it in GitHub Desktop.
Save pnkfelix/5031812 to your computer and use it in GitHub Desktop.
Attempt to narrow down Math.abs type imprecision/oddities from liquid-resize.js parjs-benchmark
18-56-51 src/parjs-benchmarks (git:(no branch)) % git diff
diff --git a/js/src/jsmath.cpp b/js/src/jsmath.cpp
index b166722..0ad677d 100644
--- a/js/src/jsmath.cpp
+++ b/js/src/jsmath.cpp
@@ -96,6 +96,18 @@ js_math_abs(JSContext *cx, unsigned argc, Value *vp)
{
double x, z;
+#ifdef DEBUG
+ if (argc == 1) {
+ Value v = vp[2];
+ if (v.isInt32()) fprintf(stderr, "x_int: ");
+ else if (v.isDouble()) fprintf(stderr, "x_dbl: ");
+ else if (v.isString()) fprintf(stderr, "x_str: ");
+ else if (v.isObject()) fprintf(stderr, "x_obj: ");
+ else fprintf(stderr, "x_unk: ");
+ js_DumpValue(v);
+ }
+#endif
+
if (argc == 0) {
vp->setDouble(js_NaN);
return JS_TRUE;
@@ -104,6 +116,19 @@ js_math_abs(JSContext *cx, unsigned argc, Value *vp)
return JS_FALSE;
z = fabs(x);
vp->setNumber(z);
+
+#ifdef DEBUG
+ {
+ Value v = vp[0];
+ if (v.isInt32()) fprintf(stderr, "z_int: ");
+ else if (v.isDouble()) fprintf(stderr, "z_dbl: ");
+ else if (v.isString()) fprintf(stderr, "z_str: ");
+ else if (v.isObject()) fprintf(stderr, "z_obj: ");
+ else fprintf(stderr, "z_unk: ");
+ js_DumpValue(v);
+ }
+#endif
+
return JS_TRUE;
}
18-56-53 src/parjs-benchmarks (git:(no branch)) % cat foo.js
var array1 = new Array(100);
for (var i=0; i < 100; i++) {
array1[i] = 0;
}
var tinyImage2d = new ParallelArray([10,10], function(i,j) 0);
function detectEdgesPar_2d_arr(arr, mode)
{
var sobX = [-1.0];
var ret=new ParallelArray([7, 7],
function (x,y)
{
var totalX = 0;
var totalY = 0;
var e = arr[x];
totalX += e * sobX[0];
var total = (Math.abs(totalX) + Math.abs(totalY))/8.0 | 0;
return total;
}, mode);
return ret;
}
detectEdgesPar_2d_arr(array1, {mode:"par"});
18-56-58 src/parjs-benchmarks (git:(no branch)) % TERM=xterm-256color INFERFLAGS=none IONFLAGS=bailouts PAFLAGS=full ../../../objdir-dbg-js/js -f foo.js
[Parallel:M] BEGIN ParallelDo (foo.js:6 -> self-hosted:741)
[Parallel:M] Compiling all reachable functions
[Parallel:M] COMPILE 10312cac0:self-hosted:750
[Parallel:M] Safe
[Parallel:M] END compiled
[Parallel:M] COMPILE 10312cc40:self-hosted:770
[Parallel:M] Safe
[Parallel:M] END compiled
[Parallel:M] COMPILE 10312c1c0:foo.js:6
[Parallel:M] Safe
[Parallel:M] END compiled
[Parallel:7] Up
[Parallel:7] Down
[Parallel:0] Up
[Parallel:0] Down
[Parallel:2] Up
[Parallel:2] Down
[Parallel:1] Up
[Parallel:6] Up
[Parallel:3] Up
[Parallel:5] Up
[Parallel:4] Up
[Parallel:1] Down
[Parallel:6] Down
[Parallel:3] Down
[Parallel:5] Down
[Parallel:4] Down
[Parallel:M] END parallel
[Parallel:M] BEGIN ParallelDo (foo.js:23 -> self-hosted:741)
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
[Parallel:M] Compiling all reachable functions
[Parallel:M] COMPILE 10313d580:self-hosted:750
[Parallel:M] Safe
[Parallel:M] END compiled
[Parallel:M] COMPILE 10313d700:self-hosted:770
[Parallel:M] Safe
[Parallel:M] END compiled
[Parallel:M] COMPILE 10312c340:foo.js:13
[Parallel:M] Call: call to native function (foo.js:21)
[Parallel:M] Entry block contains unsafe MIR
[Parallel:M] END can't compile
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_int: 0
z_int: 0
x_dbl: 0
z_int: 0
x_dbl: 0
z_int: 0
x_dbl: 0
z_int: 0
x_dbl: 0
z_int: 0
x_dbl: 0
z_int: 0
x_dbl: 0
z_int: 0
[Parallel:M] END sequential
18-57-03 src/parjs-benchmarks (git:(no branch)) %
@pnkfelix
Copy link
Author

There are three parts to that gist: (1.) the git diff: showing the instrumentation I added to Math.abs to print out the input/output values and their types, (2.) foo.js: the results of my attempt to narrow liquid-resize.js down into something small that illustrates the problem, and (3.) a run of the js shell on the narrowed-down foo.js

@pnkfelix
Copy link
Author

(and in case its not clear, the "HH-MM-SS src/parjs-benchmarks (git:(no branch)) %" entries are my bash prompt; so you will want to search e.g. for "git:(no branch)" to jump between the borders of the three parts.)

@pnkfelix
Copy link
Author

Note in particular the x_dbl's that are cropping up at the end of the run. It seems like there must be some other reason for the invalidation of inlining Math.abs (since we do not see that instrumentation before the Parallel analysis gets to run), but still, maybe they are all symptoms of a common underlying problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment