michael@0: load(libdir + 'array-compare.js'); michael@0: michael@0: function compareIAndSet(v) { michael@0: var res = 0; michael@0: var c; michael@0: var i = 0; michael@0: c = (v > 1); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v >= 2); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v < 3); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v <= 4); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v == 5); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v != 6); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v === 7); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v !== 8); michael@0: res |= (c << i); michael@0: i++; michael@0: return res; michael@0: } michael@0: michael@0: function compareIAndBranch(v) { michael@0: var res = 0; michael@0: var c = 1; michael@0: var i = 0; michael@0: if (v > 1) michael@0: res |= (c << i); michael@0: i++; michael@0: if (v >= 2) michael@0: res |= (c << i); michael@0: i++; michael@0: if (v < 3) michael@0: res |= (c << i); michael@0: i++; michael@0: if (v <= 4) michael@0: res |= (c << i); michael@0: i++; michael@0: if (v == 5) michael@0: res |= (c << i); michael@0: i++; michael@0: if (v != 6) michael@0: res |= (c << i); michael@0: i++; michael@0: if (v === 7) michael@0: res |= (c << i); michael@0: i++; michael@0: if (v !== 8) michael@0: res |= (c << i); michael@0: i++; michael@0: if (v) michael@0: res |= (c << i); michael@0: i++; michael@0: return res; michael@0: } michael@0: michael@0: function compareDAndSet(v) { michael@0: var res = 0; michael@0: var c; michael@0: var i = 0; michael@0: c = (v > 1.5); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v >= 2.5); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v < 3.5); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v <= 4.5); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v == 5.5); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v != 6.5); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v === 7.5); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v !== 8.5); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v !== 0.0); michael@0: res |= (c << i); michael@0: i++; michael@0: return res; michael@0: } michael@0: michael@0: function compareDAndBranch(v) { michael@0: var res = 0; michael@0: var c = 1; michael@0: var i = 0; michael@0: if (v > 1.5) michael@0: res |= (c << i); michael@0: i++; michael@0: if (v >= 2.5) michael@0: res |= (c << i); michael@0: i++; michael@0: if (v < 3.5) michael@0: res |= (c << i); michael@0: i++; michael@0: if (v <= 4.5) michael@0: res |= (c << i); michael@0: i++; michael@0: if (v == 5.5) michael@0: res |= (c << i); michael@0: i++; michael@0: if (v != 6.5) michael@0: res |= (c << i); michael@0: i++; michael@0: if (v === 7.5) michael@0: res |= (c << i); michael@0: i++; michael@0: if (v !== 8.5) michael@0: res |= (c << i); michael@0: i++; michael@0: if (v) michael@0: res |= (c << i); michael@0: i++; michael@0: return res; michael@0: } michael@0: michael@0: function compareSAndSet(v) { michael@0: var res = 0; michael@0: var c; michael@0: var i = 0; michael@0: c = (v > "a"); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v >= "b"); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v < "c"); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v <= "d"); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v == "e"); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v != "f"); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v === "g"); michael@0: res |= (c << i); michael@0: i++; michael@0: c = (v !== "h"); michael@0: res |= (c << i); michael@0: i++; michael@0: return res; michael@0: } michael@0: michael@0: function compareSAndBranch(v) { michael@0: var res = 0; michael@0: var c = 1; michael@0: var i = 0; michael@0: if (v > "a") michael@0: res |= (c << i); michael@0: i++; michael@0: if (v >= "b") michael@0: res |= (c << i); michael@0: i++; michael@0: if (v < "c") michael@0: res |= (c << i); michael@0: i++; michael@0: if (v <= "d") michael@0: res |= (c << i); michael@0: i++; michael@0: if (v == "e") michael@0: res |= (c << i); michael@0: i++; michael@0: if (v != "f") michael@0: res |= (c << i); michael@0: i++; michael@0: if (v === "g") michael@0: res |= (c << i); michael@0: i++; michael@0: if (v !== "h") michael@0: res |= (c << i); michael@0: i++; michael@0: if (v) michael@0: res |= (c << i); michael@0: i++; michael@0: return res; michael@0: } michael@0: michael@0: var expected = [ michael@0: // compareIAndSet michael@0: 172, 175, 171, 171, 179, 131, 227, 35, michael@0: // compareIAndBranch michael@0: 428, 431, 427, 427, 435, 387, 483, 291, michael@0: // compareDAndSet michael@0: 428, 428, 431, 427, 427, 435, 387, 483, 291, 416, michael@0: // compareDAndBranch michael@0: 428, 428, 431, 427, 427, 435, 387, 483, 291, 160, 172, michael@0: // compareSAndSet michael@0: 172, 175, 171, 171, 179, 131, 227, 35, 172, michael@0: // compareSAndBranch michael@0: 428, 431, 427, 427, 435, 387, 483, 291, 172 michael@0: ]; michael@0: michael@0: var result = [ michael@0: compareIAndSet(1), michael@0: compareIAndSet(2), michael@0: compareIAndSet(3), michael@0: compareIAndSet(4), michael@0: compareIAndSet(5), michael@0: compareIAndSet(6), michael@0: compareIAndSet(7), michael@0: compareIAndSet(8), michael@0: michael@0: compareIAndBranch(1), michael@0: compareIAndBranch(2), michael@0: compareIAndBranch(3), michael@0: compareIAndBranch(4), michael@0: compareIAndBranch(5), michael@0: compareIAndBranch(6), michael@0: compareIAndBranch(7), michael@0: compareIAndBranch(8), michael@0: michael@0: compareDAndSet(0.5), michael@0: compareDAndSet(1.5), michael@0: compareDAndSet(2.5), michael@0: compareDAndSet(3.5), michael@0: compareDAndSet(4.5), michael@0: compareDAndSet(5.5), michael@0: compareDAndSet(6.5), michael@0: compareDAndSet(7.5), michael@0: compareDAndSet(8.5), michael@0: compareDAndSet(NaN), michael@0: michael@0: compareDAndBranch(0.5), michael@0: compareDAndBranch(1.5), michael@0: compareDAndBranch(2.5), michael@0: compareDAndBranch(3.5), michael@0: compareDAndBranch(4.5), michael@0: compareDAndBranch(5.5), michael@0: compareDAndBranch(6.5), michael@0: compareDAndBranch(7.5), michael@0: compareDAndBranch(8.5), michael@0: compareDAndBranch(NaN), michael@0: compareDAndBranch(0.0), michael@0: michael@0: compareSAndSet("a"), michael@0: compareSAndSet("b"), michael@0: compareSAndSet("c"), michael@0: compareSAndSet("d"), michael@0: compareSAndSet("e"), michael@0: compareSAndSet("f"), michael@0: compareSAndSet("g"), michael@0: compareSAndSet("h"), michael@0: compareSAndSet(""), michael@0: michael@0: compareSAndBranch("a"), michael@0: compareSAndBranch("b"), michael@0: compareSAndBranch("c"), michael@0: compareSAndBranch("d"), michael@0: compareSAndBranch("e"), michael@0: compareSAndBranch("f"), michael@0: compareSAndBranch("g"), michael@0: compareSAndBranch("h"), michael@0: compareSAndBranch("") michael@0: ]; michael@0: michael@0: assertEq(arraysEqual(result, expected), true);