Merging emulation of Long to default branch
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 08 Feb 2013 09:09:12 +0100
changeset 7035c349e067fa8
parent 693 92b628f99997
parent 700 b9bf26ea0118
child 704 4fe8b3dfc55f
Merging emulation of Long to default branch
     1.1 --- a/emul/mini/src/main/java/java/lang/Character.java	Wed Feb 06 18:35:40 2013 +0100
     1.2 +++ b/emul/mini/src/main/java/java/lang/Character.java	Fri Feb 08 09:09:12 2013 +0100
     1.3 @@ -2193,6 +2193,10 @@
     1.4       * @see     Character#isDigit(int)
     1.5       * @since   1.5
     1.6       */
     1.7 +    @JavaScriptBody(args = { "codePoint", "radix" }, body=
     1.8 +        "var x = parseInt(String.fromCharCode(codePoint), radix);\n"
     1.9 +      + "return isNaN(x) ? -1 : x;"
    1.10 +    )
    1.11      public static int digit(int codePoint, int radix) {
    1.12          throw new UnsupportedOperationException();
    1.13      }
     2.1 --- a/emul/mini/src/main/java/java/lang/Long.java	Wed Feb 06 18:35:40 2013 +0100
     2.2 +++ b/emul/mini/src/main/java/java/lang/Long.java	Fri Feb 08 09:09:12 2013 +0100
     2.3 @@ -262,7 +262,7 @@
     2.4       * @param   i   a {@code long} to be converted.
     2.5       * @return  a string representation of the argument in base&nbsp;10.
     2.6       */
     2.7 -    @JavaScriptBody(args = "i", body = "return i.toString();")
     2.8 +    @JavaScriptBody(args = "i", body = "return i.toExactString();")
     2.9      public static String toString(long i) {
    2.10          if (i == Long.MIN_VALUE)
    2.11              return "-9223372036854775808";
     3.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java	Wed Feb 06 18:35:40 2013 +0100
     3.2 +++ b/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java	Fri Feb 08 09:09:12 2013 +0100
     3.3 @@ -45,7 +45,7 @@
     3.4      )
     3.5      public static native byte[] expandArray(byte[] arr, int expectedSize);
     3.6  
     3.7 -    @JavaScriptBody(args = {}, body = "new Date().getMilliseconds();")
     3.8 +    @JavaScriptBody(args = {}, body = "return new Date().getMilliseconds();")
     3.9      public static native long currentTimeMillis();
    3.10      
    3.11      public static long nanoTime() {
     4.1 --- a/emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js	Wed Feb 06 18:35:40 2013 +0100
     4.2 +++ b/emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js	Fri Feb 08 09:09:12 2013 +0100
     4.3 @@ -4,6 +4,517 @@
     4.4  Number.prototype.mul32 = function(x) { 
     4.5      return (((this * (x >> 16)) << 16) + this * (x & 0xFFFF)) | 0;
     4.6  };
     4.7 +Number.prototype.neg32 = function() { return (-this) | 0; };
     4.8  
     4.9  Number.prototype.toInt8 = function()  { return (this << 24) >> 24; };
    4.10 -Number.prototype.toInt16 = function() { return (this << 16) >> 16; };
    4.11 \ No newline at end of file
    4.12 +Number.prototype.toInt16 = function() { return (this << 16) >> 16; };
    4.13 +
    4.14 +var __m32 = 0xFFFFFFFF;
    4.15 +
    4.16 +Number.prototype.next32 = function(low) {
    4.17 +  if (this === 0) {
    4.18 +    return low;
    4.19 +  }
    4.20 +  var l = new Number(low);
    4.21 +  l.hi = this | 0;
    4.22 +  return l;
    4.23 +};
    4.24 +
    4.25 +Number.prototype.high32 = function() { 
    4.26 +    return this.hi ? this.hi : (Math.floor(this / (__m32+1))) | 0;
    4.27 +};
    4.28 +Number.prototype.toInt32 = function() { return this | 0; };
    4.29 +Number.prototype.toFP = function() {
    4.30 +    return this.hi ? this.hi * (__m32+1) + this : this;
    4.31 +};
    4.32 +Number.prototype.toLong = function() {
    4.33 +    var hi = (this > __m32) ? (Math.floor(this / (__m32+1))) | 0 : 0;
    4.34 +    return hi.next32(Math.floor(this % (__m32+1)));
    4.35 +};
    4.36 +
    4.37 +Number.prototype.toExactString = function() {
    4.38 +    if (this.hi) {
    4.39 +        // check for Long.MIN_VALUE
    4.40 +        if ((this.hi == (0x80000000 | 0)) && (this == 0)) {
    4.41 +            return '-9223372036854775808';
    4.42 +        }
    4.43 +        var res = 0;
    4.44 +        var a = [ 6,9,2,7,6,9,4,9,2,4 ];
    4.45 +        var s = '';
    4.46 +        var digit;
    4.47 +        var neg = this.hi < 0;
    4.48 +        if (neg) {
    4.49 +            var x = this.neg64();
    4.50 +            var hi = x.hi;
    4.51 +            var low = x;
    4.52 +        } else {
    4.53 +            var hi = this.hi;
    4.54 +            var low = this;
    4.55 +        }
    4.56 +        for (var i = 0; i < a.length; i++) {
    4.57 +            res += hi * a[i];
    4.58 +            var low_digit = low % 10;
    4.59 +            digit = (res % 10) + low_digit;
    4.60 +
    4.61 +            low = Math.floor(low / 10);
    4.62 +            res = Math.floor(res / 10);
    4.63 +
    4.64 +            if (digit >= 10) {
    4.65 +                digit -= 10;
    4.66 +                res++;
    4.67 +            }
    4.68 +            s = String(digit).concat(s);
    4.69 +        }
    4.70 +        s = String(res).concat(s).replace(/^0+/, '');
    4.71 +        return (neg ? '-' : '').concat(s);
    4.72 +    }
    4.73 +    return String(this);
    4.74 +};
    4.75 +
    4.76 +Number.prototype.add64 = function(x) {
    4.77 +    var low = this + x;
    4.78 +    carry = 0;
    4.79 +    if (low > __m32) {
    4.80 +        carry = 1;
    4.81 +        low -= (__m32+1);
    4.82 +    }
    4.83 +    var hi = (this.high32() + x.high32() + carry) | 0;
    4.84 +    return hi.next32(low);
    4.85 +};
    4.86 +
    4.87 +Number.prototype.sub64 = function(x) {
    4.88 +    var low = this - x;
    4.89 +    carry = 0;
    4.90 +    if (low < 0) {
    4.91 +        carry = 1;
    4.92 +        low += (__m32+1);
    4.93 +    }
    4.94 +    var hi = (this.high32() - x.high32() - carry) | 0;
    4.95 +    return hi.next32(low);
    4.96 +};
    4.97 +
    4.98 +Number.prototype.mul64 = function(x) {
    4.99 +    var low = this.mul32(x);
   4.100 +    low += (low < 0) ? (__m32+1) : 0;
   4.101 +    // first count upper 32 bits of (this.low * x.low)
   4.102 +    var hi_hi = 0;
   4.103 +    var hi_low = 0;
   4.104 +    var m = 1;
   4.105 +    for (var i = 0; i < 32; i++) {
   4.106 +        if (x & m) {
   4.107 +            hi_hi += this >>> 16;
   4.108 +            hi_low += this & 0xFFFF
   4.109 +        }
   4.110 +        hi_low >>= 1;
   4.111 +        hi_low += (hi_hi & 1) ? 0x8000 : 0;
   4.112 +        hi_hi >>= 1;
   4.113 +        m <<= 1;
   4.114 +    }
   4.115 +    var hi = (hi_hi << 16) + hi_low;
   4.116 +    
   4.117 +    var m1 = this.high32().mul32(x);
   4.118 +    var m2 = this.mul32(x.high32());
   4.119 +    hi = hi.add32(m1).add32(m2);
   4.120 +    
   4.121 +    return hi.next32(low);
   4.122 +};
   4.123 +
   4.124 +Number.prototype.and64 = function(x) {
   4.125 +    var low = this & x;
   4.126 +    low += (low < 0) ? (__m32+1) : 0;
   4.127 +    if (this.hi && x.hi) {
   4.128 +        var hi = this.hi & x.hi;
   4.129 +        return hi.next32(low);
   4.130 +    };
   4.131 +    return low;
   4.132 +};
   4.133 +
   4.134 +Number.prototype.or64 = function(x) {
   4.135 +    var low = this | x;
   4.136 +    low += (low < 0) ? (__m32+1) : 0;
   4.137 +    if (this.hi || x.hi) {
   4.138 +        var hi = this.hi | x.hi;
   4.139 +        return hi.next32(low);
   4.140 +    };
   4.141 +    return low;
   4.142 +};
   4.143 +
   4.144 +Number.prototype.xor64 = function(x) {
   4.145 +    var low = this ^ x;
   4.146 +    low += (low < 0) ? (__m32+1) : 0;
   4.147 +    if (this.hi || x.hi) {
   4.148 +        var hi = this.hi ^ x.hi;
   4.149 +        return hi.next32(low);
   4.150 +    };
   4.151 +    return low;
   4.152 +};
   4.153 +
   4.154 +Number.prototype.shl64 = function(x) {
   4.155 +    if (x >= 32) {
   4.156 +        var hi = this << (x - 32);
   4.157 +        return hi.next32(0);
   4.158 +    } else {
   4.159 +        var hi = this.high32() << x;
   4.160 +        var low_reminder = this >> (32 - x);
   4.161 +        hi |= low_reminder;
   4.162 +        var low = this << x;
   4.163 +        low += (low < 0) ? (__m32+1) : 0;
   4.164 +        return hi.next32(low);
   4.165 +    }
   4.166 +};
   4.167 +
   4.168 +Number.prototype.shr64 = function(x) {
   4.169 +    if (x >= 32) {
   4.170 +        var low = this.high32() >> (x - 32);
   4.171 +        low += (low < 0) ? (__m32+1) : 0;
   4.172 +        return low;
   4.173 +    } else {
   4.174 +        var low = this >> x;
   4.175 +        var hi_reminder = this.high32() << (32 - x);
   4.176 +        low |= hi_reminder;
   4.177 +        low += (low < 0) ? (__m32+1) : 0;
   4.178 +        var hi = this.high32() >> x;
   4.179 +        return hi.next32(low);
   4.180 +    }
   4.181 +};
   4.182 +
   4.183 +Number.prototype.ushr64 = function(x) {
   4.184 +    if (x >= 32) {
   4.185 +        var low = this.high32() >>> (x - 32);
   4.186 +        low += (low < 0) ? (__m32+1) : 0;
   4.187 +        return low;
   4.188 +    } else {
   4.189 +        var low = this >>> x;
   4.190 +        var hi_reminder = this.high32() << (32 - x);
   4.191 +        low |= hi_reminder;
   4.192 +        low += (low < 0) ? (__m32+1) : 0;
   4.193 +        var hi = this.high32() >>> x;
   4.194 +        return hi.next32(low);
   4.195 +    }
   4.196 +};
   4.197 +
   4.198 +Number.prototype.compare64 = function(x) {
   4.199 +    if (this.high32() === x.high32()) {
   4.200 +        return (this < x) ? -1 : ((this > x) ? 1 : 0);
   4.201 +    }
   4.202 +    return (this.high32() < x.high32()) ? -1 : 1;
   4.203 +};
   4.204 +
   4.205 +Number.prototype.neg64 = function() {
   4.206 +    var hi = this.high32();
   4.207 +    var low = this;
   4.208 +    if ((hi === 0) && (low < 0)) { return -low; }
   4.209 +    hi = ~hi;
   4.210 +    low = ~low;
   4.211 +    low += (low < 0) ? (__m32+1) : 0;
   4.212 +    var ret = hi.next32(low);
   4.213 +    return ret.add64(1);
   4.214 +};
   4.215 +
   4.216 +(function(numberPrototype) {
   4.217 +    function __Int64(hi32, lo32) {
   4.218 +        this.hi32 = hi32 | 0;
   4.219 +        this.lo32 = lo32 | 0;
   4.220 +
   4.221 +        this.get32 = function(bitIndex) {
   4.222 +            var v0;
   4.223 +            var v1;
   4.224 +            bitIndex += 32;
   4.225 +            var selector = bitIndex >>> 5;
   4.226 +            switch (selector) {
   4.227 +                case 0:
   4.228 +                    v0 = 0;
   4.229 +                    v1 = this.lo32;
   4.230 +                    break;
   4.231 +                case 1:
   4.232 +                    v0 = this.lo32;
   4.233 +                    v1 = this.hi32;
   4.234 +                    break;
   4.235 +                case 2:
   4.236 +                    v0 = this.hi32;
   4.237 +                    v1 = 0;
   4.238 +                    break
   4.239 +                default:
   4.240 +                    return 0;
   4.241 +            }
   4.242 +
   4.243 +            var shift = bitIndex & 31;
   4.244 +            if (shift === 0) {
   4.245 +                return v0;
   4.246 +            }
   4.247 +
   4.248 +            return (v1 << (32 - shift)) | (v0 >>> shift);
   4.249 +        }
   4.250 +
   4.251 +        this.get16 = function(bitIndex) {
   4.252 +            return this.get32(bitIndex) & 0xffff;
   4.253 +        }
   4.254 +
   4.255 +        this.set16 = function(bitIndex, value) {
   4.256 +            bitIndex += 32;
   4.257 +            var shift = bitIndex & 15;
   4.258 +            var svalue = (value & 0xffff) << shift; 
   4.259 +            var smask = 0xffff << shift;
   4.260 +            var selector = bitIndex >>> 4;
   4.261 +            switch (selector) {
   4.262 +                case 0:
   4.263 +                    break;
   4.264 +                case 1:
   4.265 +                    this.lo32 = (this.lo32 & ~(smask >>> 16))
   4.266 +                                    | (svalue >>> 16);
   4.267 +                    break;
   4.268 +                case 2:
   4.269 +                    this.lo32 = (this.lo32 & ~smask) | svalue;
   4.270 +                    break;
   4.271 +                case 3:
   4.272 +                    this.lo32 = (this.lo32 & ~(smask << 16))
   4.273 +                                    | (svalue << 16);
   4.274 +                    this.hi32 = (this.hi32 & ~(smask >>> 16))
   4.275 +                                    | (svalue >>> 16);
   4.276 +                    break;
   4.277 +                case 4:
   4.278 +                    this.hi32 = (this.hi32 & ~smask) | svalue;
   4.279 +                    break;
   4.280 +                case 5:
   4.281 +                    this.hi32 = (this.hi32 & ~(smask << 16))
   4.282 +                                    | (svalue << 16);
   4.283 +                    break;
   4.284 +            }
   4.285 +        }
   4.286 +
   4.287 +        this.getDigit = function(index, shift) {
   4.288 +            return this.get16((index << 4) - shift);
   4.289 +        }
   4.290 +
   4.291 +        this.getTwoDigits = function(index, shift) {
   4.292 +            return this.get32(((index - 1) << 4) - shift);
   4.293 +        }
   4.294 +
   4.295 +        this.setDigit = function(index, shift, value) {
   4.296 +            this.set16((index << 4) - shift, value);
   4.297 +        }
   4.298 +
   4.299 +        this.countSignificantDigits = function() {
   4.300 +            var sd;
   4.301 +            var remaining;
   4.302 +
   4.303 +            if (this.hi32 === 0) {
   4.304 +                if (this.lo32 === 0) {
   4.305 +                    return 0;
   4.306 +                }
   4.307 +
   4.308 +                sd = 2;
   4.309 +                remaining = this.lo32;
   4.310 +            } else {
   4.311 +                sd = 4;
   4.312 +                remaining = this.hi32;
   4.313 +            }
   4.314 +
   4.315 +            if (remaining < 0) {
   4.316 +                return sd;
   4.317 +            }
   4.318 +
   4.319 +            return (remaining < 65536) ? sd - 1 : sd;
   4.320 +        }
   4.321 +        
   4.322 +        this.toNumber = function() {
   4.323 +            var lo32 = this.lo32;
   4.324 +            if (lo32 < 0) {
   4.325 +                lo32 += 0x100000000;
   4.326 +            }
   4.327 +
   4.328 +            return this.hi32.next32(lo32);
   4.329 +        }
   4.330 +    }
   4.331 +
   4.332 +    function __countLeadingZeroes16(number) {
   4.333 +        var nlz = 0;
   4.334 +
   4.335 +        if (number < 256) {
   4.336 +            nlz += 8;
   4.337 +            number <<= 8;
   4.338 +        }
   4.339 +
   4.340 +        if (number < 4096) {
   4.341 +            nlz += 4;
   4.342 +            number <<= 4;
   4.343 +        }
   4.344 +
   4.345 +        if (number < 16384) {
   4.346 +            nlz += 2;
   4.347 +            number <<= 2;
   4.348 +        }
   4.349 +
   4.350 +        return (number < 32768) ? nlz + 1 : nlz;
   4.351 +    }
   4.352 +    
   4.353 +    // q = u / v; r = u - q * v;
   4.354 +    // v != 0
   4.355 +    function __div64(q, r, u, v) {
   4.356 +        var m = u.countSignificantDigits();
   4.357 +        var n = v.countSignificantDigits();
   4.358 +
   4.359 +        q.hi32 = q.lo32 = 0;
   4.360 +
   4.361 +        if (n === 1) {
   4.362 +            // v has single digit
   4.363 +            var vd = v.getDigit(0, 0);
   4.364 +            var carry = 0;
   4.365 +            for (var i = m - 1; i >= 0; --i) {
   4.366 +                var ui = (carry << 16) | u.getDigit(i, 0);
   4.367 +                if (ui < 0) {
   4.368 +                    ui += 0x100000000;
   4.369 +                }
   4.370 +                var qi = (ui / vd) | 0;
   4.371 +                q.setDigit(i, 0, qi);
   4.372 +                carry = ui - qi * vd;
   4.373 +            }
   4.374 +
   4.375 +            r.hi32 = 0;
   4.376 +            r.lo32 = carry;
   4.377 +            return;
   4.378 +        }
   4.379 +
   4.380 +        r.hi32 = u.hi32;  
   4.381 +        r.lo32 = u.lo32;
   4.382 +
   4.383 +        if (m < n) {
   4.384 +            return;
   4.385 +        }
   4.386 +
   4.387 +        // Normalize
   4.388 +        var nrm = __countLeadingZeroes16(v.getDigit(n - 1, 0));
   4.389 +
   4.390 +        var vd1 = v.getDigit(n - 1, nrm);                
   4.391 +        var vd0 = v.getDigit(n - 2, nrm);
   4.392 +        for (var j = m - n; j >= 0; --j) {
   4.393 +            // Calculate qj estimate
   4.394 +            var ud21 = r.getTwoDigits(j + n, nrm);
   4.395 +            var ud2 = ud21 >>> 16;
   4.396 +            if (ud21 < 0) {
   4.397 +                ud21 += 0x100000000;
   4.398 +            }
   4.399 +
   4.400 +            var qest = (ud2 === vd1) ? 0xFFFF : ((ud21 / vd1) | 0);
   4.401 +            var rest = ud21 - qest * vd1;
   4.402 +
   4.403 +            // 0 <= (qest - qj) <= 2
   4.404 +
   4.405 +            // Refine qj estimate
   4.406 +            var ud0 = r.getDigit(j + n - 2, nrm);
   4.407 +            while ((qest * vd0) > ((rest * 0x10000) + ud0)) {
   4.408 +                --qest;
   4.409 +                rest += vd1;
   4.410 +            }
   4.411 +
   4.412 +            // 0 <= (qest - qj) <= 1
   4.413 +            
   4.414 +            // Multiply and subtract
   4.415 +            var carry = 0;
   4.416 +            for (var i = 0; i < n; ++i) {
   4.417 +                var vi = qest * v.getDigit(i, nrm);
   4.418 +                var ui = r.getDigit(i + j, nrm) - carry - (vi & 0xffff);
   4.419 +                r.setDigit(i + j, nrm, ui);
   4.420 +                carry = (vi >>> 16) - (ui >> 16);
   4.421 +            }
   4.422 +            var uj = ud2 - carry;
   4.423 +
   4.424 +            if (uj < 0) {
   4.425 +                // qest - qj = 1
   4.426 +
   4.427 +                // Add back
   4.428 +                --qest;
   4.429 +                var carry = 0;
   4.430 +                for (var i = 0; i < n; ++i) {
   4.431 +                    var ui = r.getDigit(i + j, nrm) + v.getDigit(i, nrm)
   4.432 +                                 + carry;
   4.433 +                    r.setDigit(i + j, nrm, ui);
   4.434 +                    carry = ui >> 16;
   4.435 +                }
   4.436 +                uj += carry;
   4.437 +            }
   4.438 +
   4.439 +            q.setDigit(j, 0, qest);
   4.440 +            r.setDigit(j + n, nrm, uj);
   4.441 +        }
   4.442 +    }
   4.443 +    
   4.444 +    numberPrototype.div64 = function(x) {
   4.445 +        var negateResult = false;
   4.446 +        var u, v;
   4.447 +        
   4.448 +        if ((this.high32() & 0x80000000) != 0) {
   4.449 +            u = this.neg64();
   4.450 +            negateResult = !negateResult;
   4.451 +        } else {
   4.452 +            u = this;        
   4.453 +        }
   4.454 +
   4.455 +        if ((x.high32() & 0x80000000) != 0) {
   4.456 +            v = x.neg64();
   4.457 +            negateResult = !negateResult;
   4.458 +        } else {
   4.459 +            v = x;
   4.460 +        }
   4.461 +
   4.462 +        if ((v === 0) && (v.high32() === 0)) {
   4.463 +            // TODO: throw
   4.464 +        }
   4.465 +
   4.466 +        if (u.high32() === 0) {
   4.467 +            if (v.high32() === 0) {
   4.468 +                var result = (u / v) | 0;
   4.469 +                return negateResult ? result.neg64() : result; 
   4.470 +            }
   4.471 +
   4.472 +            return 0;
   4.473 +        }
   4.474 +
   4.475 +        var u64 = new __Int64(u.high32(), u);
   4.476 +        var v64 = new __Int64(v.high32(), v);
   4.477 +        var q64 = new __Int64(0, 0);
   4.478 +        var r64 = new __Int64(0, 0);
   4.479 +
   4.480 +        __div64(q64, r64, u64, v64);
   4.481 +
   4.482 +        var result = q64.toNumber();
   4.483 +        return negateResult ? result.neg64() : result; 
   4.484 +    }
   4.485 +
   4.486 +    numberPrototype.mod64 = function(x) {
   4.487 +        var negateResult = false;
   4.488 +        var u, v;
   4.489 +        
   4.490 +        if ((this.high32() & 0x80000000) != 0) {
   4.491 +            u = this.neg64();
   4.492 +            negateResult = !negateResult;
   4.493 +        } else {
   4.494 +            u = this;        
   4.495 +        }
   4.496 +
   4.497 +        if ((x.high32() & 0x80000000) != 0) {
   4.498 +            v = x.neg64();
   4.499 +        } else {
   4.500 +            v = x;
   4.501 +        }
   4.502 +
   4.503 +        if ((v === 0) && (v.high32() === 0)) {
   4.504 +            // TODO: throw
   4.505 +        }
   4.506 +
   4.507 +        if (u.high32() === 0) {
   4.508 +            var result = (v.high32() === 0) ? (u % v) : u;
   4.509 +            return negateResult ? result.neg64() : result; 
   4.510 +        }
   4.511 +
   4.512 +        var u64 = new __Int64(u.high32(), u);
   4.513 +        var v64 = new __Int64(v.high32(), v);
   4.514 +        var q64 = new __Int64(0, 0);
   4.515 +        var r64 = new __Int64(0, 0);
   4.516 +
   4.517 +        __div64(q64, r64, u64, v64);
   4.518 +
   4.519 +        var result = r64.toNumber();
   4.520 +        return negateResult ? result.neg64() : result; 
   4.521 +    }
   4.522 +})(Number.prototype);
     5.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Wed Feb 06 18:35:40 2013 +0100
     5.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Fri Feb 08 09:09:12 2013 +0100
     5.3 @@ -520,7 +520,7 @@
     5.4                      emit(out, "@1 = @1.add32(@2);", smapper.getI(1), smapper.popI());
     5.5                      break;
     5.6                  case opc_ladd:
     5.7 -                    emit(out, "@1 += @2;", smapper.getL(1), smapper.popL());
     5.8 +                    emit(out, "@1 = @1.add64(@2);", smapper.getL(1), smapper.popL());
     5.9                      break;
    5.10                  case opc_fadd:
    5.11                      emit(out, "@1 += @2;", smapper.getF(1), smapper.popF());
    5.12 @@ -532,7 +532,7 @@
    5.13                      emit(out, "@1 = @1.sub32(@2);", smapper.getI(1), smapper.popI());
    5.14                      break;
    5.15                  case opc_lsub:
    5.16 -                    emit(out, "@1 -= @2;", smapper.getL(1), smapper.popL());
    5.17 +                    emit(out, "@1 = @1.sub64(@2);", smapper.getL(1), smapper.popL());
    5.18                      break;
    5.19                  case opc_fsub:
    5.20                      emit(out, "@1 -= @2;", smapper.getF(1), smapper.popF());
    5.21 @@ -544,7 +544,7 @@
    5.22                      emit(out, "@1 = @1.mul32(@2);", smapper.getI(1), smapper.popI());
    5.23                      break;
    5.24                  case opc_lmul:
    5.25 -                    emit(out, "@1 *= @2;", smapper.getL(1), smapper.popL());
    5.26 +                    emit(out, "@1 = @1.mul64(@2);", smapper.getL(1), smapper.popL());
    5.27                      break;
    5.28                  case opc_fmul:
    5.29                      emit(out, "@1 *= @2;", smapper.getF(1), smapper.popF());
    5.30 @@ -557,7 +557,7 @@
    5.31                           smapper.getI(1), smapper.popI());
    5.32                      break;
    5.33                  case opc_ldiv:
    5.34 -                    emit(out, "@1 = Math.floor(@1 / @2);",
    5.35 +                    emit(out, "@1 = @1.div64(@2);",
    5.36                           smapper.getL(1), smapper.popL());
    5.37                      break;
    5.38                  case opc_fdiv:
    5.39 @@ -570,7 +570,8 @@
    5.40                      emit(out, "@1 %= @2;", smapper.getI(1), smapper.popI());
    5.41                      break;
    5.42                  case opc_lrem:
    5.43 -                    emit(out, "@1 %= @2;", smapper.getL(1), smapper.popL());
    5.44 +                    emit(out, "@1 = @1.mod64(@2);",
    5.45 +                         smapper.getL(1), smapper.popL());
    5.46                      break;
    5.47                  case opc_frem:
    5.48                      emit(out, "@1 %= @2;", smapper.getF(1), smapper.popF());
    5.49 @@ -582,25 +583,25 @@
    5.50                      emit(out, "@1 &= @2;", smapper.getI(1), smapper.popI());
    5.51                      break;
    5.52                  case opc_land:
    5.53 -                    emit(out, "@1 &= @2;", smapper.getL(1), smapper.popL());
    5.54 +                    emit(out, "@1 = @1.and64(@2);", smapper.getL(1), smapper.popL());
    5.55                      break;
    5.56                  case opc_ior:
    5.57                      emit(out, "@1 |= @2;", smapper.getI(1), smapper.popI());
    5.58                      break;
    5.59                  case opc_lor:
    5.60 -                    emit(out, "@1 |= @2;", smapper.getL(1), smapper.popL());
    5.61 +                    emit(out, "@1 = @1.or64(@2);", smapper.getL(1), smapper.popL());
    5.62                      break;
    5.63                  case opc_ixor:
    5.64                      emit(out, "@1 ^= @2;", smapper.getI(1), smapper.popI());
    5.65                      break;
    5.66                  case opc_lxor:
    5.67 -                    emit(out, "@1 ^= @2;", smapper.getL(1), smapper.popL());
    5.68 +                    emit(out, "@1 = @1.xor64(@2);", smapper.getL(1), smapper.popL());
    5.69                      break;
    5.70                  case opc_ineg:
    5.71 -                    emit(out, "@1 = -@1;", smapper.getI(0));
    5.72 +                    emit(out, "@1 = @1.neg32();", smapper.getI(0));
    5.73                      break;
    5.74                  case opc_lneg:
    5.75 -                    emit(out, "@1 = -@1;", smapper.getL(0));
    5.76 +                    emit(out, "@1 = @1.neg64();", smapper.getL(0));
    5.77                      break;
    5.78                  case opc_fneg:
    5.79                      emit(out, "@1 = -@1;", smapper.getF(0));
    5.80 @@ -612,19 +613,19 @@
    5.81                      emit(out, "@1 <<= @2;", smapper.getI(1), smapper.popI());
    5.82                      break;
    5.83                  case opc_lshl:
    5.84 -                    emit(out, "@1 <<= @2;", smapper.getL(1), smapper.popI());
    5.85 +                    emit(out, "@1 = @1.shl64(@2);", smapper.getL(1), smapper.popI());
    5.86                      break;
    5.87                  case opc_ishr:
    5.88                      emit(out, "@1 >>= @2;", smapper.getI(1), smapper.popI());
    5.89                      break;
    5.90                  case opc_lshr:
    5.91 -                    emit(out, "@1 >>= @2;", smapper.getL(1), smapper.popI());
    5.92 +                    emit(out, "@1 = @1.shr64(@2);", smapper.getL(1), smapper.popI());
    5.93                      break;
    5.94                  case opc_iushr:
    5.95                      emit(out, "@1 >>>= @2;", smapper.getI(1), smapper.popI());
    5.96                      break;
    5.97                  case opc_lushr:
    5.98 -                    emit(out, "@1 >>>= @2;", smapper.getL(1), smapper.popI());
    5.99 +                    emit(out, "@1 = @1.ushr64(@2);", smapper.getL(1), smapper.popI());
   5.100                      break;
   5.101                  case opc_iinc: {
   5.102                      ++i;
   5.103 @@ -671,14 +672,14 @@
   5.104                      emit(out, "var @2 = @1;", smapper.popI(), smapper.pushD());
   5.105                      break;
   5.106                  case opc_l2i:
   5.107 -                    emit(out, "var @2 = @1;", smapper.popL(), smapper.pushI());
   5.108 +                    emit(out, "var @2 = @1.toInt32();", smapper.popL(), smapper.pushI());
   5.109                      break;
   5.110                      // max int check?
   5.111                  case opc_l2f:
   5.112 -                    emit(out, "var @2 = @1;", smapper.popL(), smapper.pushF());
   5.113 +                    emit(out, "var @2 = @1.toFP();", smapper.popL(), smapper.pushF());
   5.114                      break;
   5.115                  case opc_l2d:
   5.116 -                    emit(out, "var @2 = @1;", smapper.popL(), smapper.pushD());
   5.117 +                    emit(out, "var @2 = @1.toFP();", smapper.popL(), smapper.pushD());
   5.118                      break;
   5.119                  case opc_f2d:
   5.120                      emit(out, "var @2 = @1;", smapper.popF(), smapper.pushD());
   5.121 @@ -691,7 +692,7 @@
   5.122                           smapper.popF(), smapper.pushI());
   5.123                      break;
   5.124                  case opc_f2l:
   5.125 -                    emit(out, "var @2 = Math.floor(@1);",
   5.126 +                    emit(out, "var @2 = Math.floor(@1).toLong();",
   5.127                           smapper.popF(), smapper.pushL());
   5.128                      break;
   5.129                  case opc_d2i:
   5.130 @@ -699,7 +700,7 @@
   5.131                           smapper.popD(), smapper.pushI());
   5.132                      break;
   5.133                  case opc_d2l:
   5.134 -                    emit(out, "var @2 = Math.floor(@1);",
   5.135 +                    emit(out, "var @2 = Math.floor(@1).toLong();",
   5.136                           smapper.popD(), smapper.pushL());
   5.137                      break;
   5.138                  case opc_i2b:
   5.139 @@ -769,11 +770,19 @@
   5.140                      i += 2;
   5.141                      String v = encodeConstant(indx);
   5.142                      int type = VarType.fromConstantType(jc.getTag(indx));
   5.143 -                    emit(out, "var @1 = @2;", smapper.pushT(type), v);
   5.144 +                    if (type == VarType.LONG) {
   5.145 +                        final Long lv = new Long(v);
   5.146 +                        final int low = (int)(lv.longValue() & 0xFFFFFFFF);
   5.147 +                        final int hi = (int)(lv.longValue() >> 32);
   5.148 +                        emit(out, "var @1 = 0x@3.next32(0x@2);", smapper.pushL(), 
   5.149 +                                Integer.toHexString(low), Integer.toHexString(hi));
   5.150 +                    } else {
   5.151 +                        emit(out, "var @1 = @2;", smapper.pushT(type), v);
   5.152 +                    }
   5.153                      break;
   5.154                  }
   5.155                  case opc_lcmp:
   5.156 -                    emit(out, "var @3 = (@2 == @1) ? 0 : ((@2 < @1) ? -1 : 1);",
   5.157 +                    emit(out, "var @3 = @2.compare64(@1);",
   5.158                           smapper.popL(), smapper.popL(), smapper.pushI());
   5.159                      break;
   5.160                  case opc_fcmpl:
     6.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java	Wed Feb 06 18:35:40 2013 +0100
     6.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java	Fri Feb 08 09:09:12 2013 +0100
     6.3 @@ -143,7 +143,7 @@
     6.4              s
     6.5          );
     6.6      }
     6.7 -    
     6.8 +
     6.9      private static CharSequence codeSeq;
    6.10      private static Invocable code;
    6.11  
    6.12 @@ -157,31 +157,20 @@
    6.13      }
    6.14  
    6.15      private static void assertExec(
    6.16 -        String msg, Class<?> clazz, String method, Object expRes, Object... args) throws Exception {
    6.17 -
    6.18 -        Object ret = null;
    6.19 -        try {
    6.20 -            ret = code.invokeFunction("bck2brwsr");
    6.21 -            ret = code.invokeMethod(ret, "loadClass", clazz.getName());
    6.22 -            ret = code.invokeMethod(ret, method, args);
    6.23 -        } catch (ScriptException ex) {
    6.24 -            fail("Execution failed in\n" + StaticMethodTest.dumpJS(codeSeq), ex);
    6.25 -        } catch (NoSuchMethodException ex) {
    6.26 -            fail("Cannot find method in\n" + StaticMethodTest.dumpJS(codeSeq), ex);
    6.27 -        }
    6.28 -        if (ret == null && expRes == null) {
    6.29 -            return;
    6.30 -        }
    6.31 -        if (expRes.equals(ret)) {
    6.32 +        String msg, Class<?> clazz, String method, Object expRes, Object... args) throws Exception
    6.33 +    {
    6.34 +        Object ret = TestUtils.execCode(code, codeSeq, msg, clazz, method, expRes, args);
    6.35 +        if (ret == null) {
    6.36              return;
    6.37          }
    6.38          if (expRes instanceof Double && ret instanceof Double) {
    6.39              double expD = ((Double)expRes).doubleValue();
    6.40              double retD = ((Double)ret).doubleValue();
    6.41 -            assertEquals(retD, expD, 0.000004, msg + " was " + ret + "\n" + StaticMethodTest.dumpJS(codeSeq));
    6.42 +            assertEquals(retD, expD, 0.000004, msg + " "
    6.43 +                    + StaticMethodTest.dumpJS(codeSeq));
    6.44              return;
    6.45          }
    6.46 -        assertEquals(ret, expRes, msg + "was: " + ret + "\n" + StaticMethodTest.dumpJS(codeSeq));
    6.47 +        assertEquals(ret, expRes, msg + " " + StaticMethodTest.dumpJS(codeSeq));
    6.48      }
    6.49      
    6.50  }
     7.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java	Wed Feb 06 18:35:40 2013 +0100
     7.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java	Fri Feb 08 09:09:12 2013 +0100
     7.3 @@ -353,17 +353,8 @@
     7.4          String msg, Class clazz, String method, 
     7.5          Object expRes, Object... args
     7.6      ) throws Exception {
     7.7 -        Object ret = null;
     7.8 -        try {
     7.9 -            ret = toRun.invokeFunction("bck2brwsr");
    7.10 -            ret = toRun.invokeMethod(ret, "loadClass", clazz.getName());
    7.11 -            ret = toRun.invokeMethod(ret, method, args);
    7.12 -        } catch (ScriptException ex) {
    7.13 -            fail("Execution failed in\n" + dumpJS(theCode), ex);
    7.14 -        } catch (NoSuchMethodException ex) {
    7.15 -            fail("Cannot find method in\n" + dumpJS(theCode), ex);
    7.16 -        }
    7.17 -        if (ret == null && expRes == null) {
    7.18 +        Object ret = TestUtils.execCode(toRun, theCode, msg, clazz, method, expRes, args);
    7.19 +        if (ret == null) {
    7.20              return;
    7.21          }
    7.22          if (expRes != null && expRes.equals(ret)) {
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/TestUtils.java	Fri Feb 08 09:09:12 2013 +0100
     8.3 @@ -0,0 +1,60 @@
     8.4 +/**
     8.5 + * Back 2 Browser Bytecode Translator
     8.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     8.7 + *
     8.8 + * This program is free software: you can redistribute it and/or modify
     8.9 + * it under the terms of the GNU General Public License as published by
    8.10 + * the Free Software Foundation, version 2 of the License.
    8.11 + *
    8.12 + * This program is distributed in the hope that it will be useful,
    8.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.15 + * GNU General Public License for more details.
    8.16 + *
    8.17 + * You should have received a copy of the GNU General Public License
    8.18 + * along with this program. Look for COPYING file in the top folder.
    8.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    8.20 + */
    8.21 +package org.apidesign.vm4brwsr;
    8.22 +
    8.23 +import javax.script.Invocable;
    8.24 +import javax.script.ScriptException;
    8.25 +import static org.testng.Assert.*;
    8.26 +
    8.27 +class TestUtils {
    8.28 +
    8.29 +    static Object execCode(Invocable code, CharSequence codeSeq,
    8.30 +        String msg, Class<?> clazz, String method, Object expRes, Object... args) 
    8.31 +            throws Exception
    8.32 +    {
    8.33 +        Object ret = null;
    8.34 +        try {
    8.35 +            ret = code.invokeFunction("bck2brwsr");
    8.36 +            ret = code.invokeMethod(ret, "loadClass", clazz.getName());
    8.37 +            ret = code.invokeMethod(ret, method, args);
    8.38 +        } catch (ScriptException ex) {
    8.39 +            fail("Execution failed in " + StaticMethodTest.dumpJS(codeSeq), ex);
    8.40 +        } catch (NoSuchMethodException ex) {
    8.41 +            fail("Cannot find method in " + StaticMethodTest.dumpJS(codeSeq), ex);
    8.42 +        }
    8.43 +        if (ret == null && expRes == null) {
    8.44 +            return null;
    8.45 +        }
    8.46 +        if (expRes.equals(ret)) {
    8.47 +            return null;
    8.48 +        }
    8.49 +        if (expRes instanceof Number) {
    8.50 +            // in case of Long it is necessary convert it to number
    8.51 +            // since the Long is represented by two numbers in JavaScript
    8.52 +            try {
    8.53 +                ret = code.invokeMethod(ret, "toFP");
    8.54 +                ret = code.invokeFunction("Number", ret);
    8.55 +            } catch (ScriptException ex) {
    8.56 +                fail("Conversion to number failed in " + StaticMethodTest.dumpJS(codeSeq), ex);
    8.57 +            } catch (NoSuchMethodException ex) {
    8.58 +                fail("Cannot find global Number(x) function in " + StaticMethodTest.dumpJS(codeSeq), ex);
    8.59 +            }
    8.60 +        }
    8.61 +        return ret;
    8.62 +    }
    8.63 +}
     9.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/VMLazyTest.java	Wed Feb 06 18:35:40 2013 +0100
     9.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/VMLazyTest.java	Fri Feb 08 09:09:12 2013 +0100
     9.3 @@ -51,7 +51,7 @@
     9.4         
     9.5          ScriptEngine[] arr = { null };
     9.6          code = StaticMethodTest.compileClass(sb, arr,
     9.7 -            "org/apidesign/vm4brwsr/VM"
     9.8 +            new String[]{"org/apidesign/vm4brwsr/VM", "org/apidesign/vm4brwsr/StaticMethod"}
     9.9          );
    9.10          arr[0].getContext().setAttribute("loader", new BytesLoader(), ScriptContext.ENGINE_SCOPE);
    9.11          codeSeq = sb;
    10.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java	Wed Feb 06 18:35:40 2013 +0100
    10.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java	Fri Feb 08 09:09:12 2013 +0100
    10.3 @@ -47,6 +47,10 @@
    10.4          return x % y;
    10.5      }
    10.6      
    10.7 +    private static int neg(int x) {
    10.8 +        return (-x);
    10.9 +    }
   10.10 +    
   10.11      @Compare public int addOverflow() {
   10.12          return add(Integer.MAX_VALUE, 1);
   10.13      }
   10.14 @@ -91,6 +95,18 @@
   10.15          return mod(1, 2);
   10.16      }
   10.17      
   10.18 +    @Compare public int negate() {
   10.19 +        return neg(123456);
   10.20 +    }
   10.21 +    
   10.22 +    @Compare public int negateMaxInt() {
   10.23 +        return neg(Integer.MAX_VALUE);
   10.24 +    }
   10.25 +    
   10.26 +    @Compare public int negateMinInt() {
   10.27 +        return neg(Integer.MIN_VALUE);
   10.28 +    }
   10.29 +    
   10.30      @Compare public int sumTwoDimensions() {
   10.31          int[][] matrix = createMatrix(4, 3);
   10.32          matrix[0][0] += 10;
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java	Fri Feb 08 09:09:12 2013 +0100
    11.3 @@ -0,0 +1,334 @@
    11.4 +/**
    11.5 + * Back 2 Browser Bytecode Translator
    11.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    11.7 + *
    11.8 + * This program is free software: you can redistribute it and/or modify
    11.9 + * it under the terms of the GNU General Public License as published by
   11.10 + * the Free Software Foundation, version 2 of the License.
   11.11 + *
   11.12 + * This program is distributed in the hope that it will be useful,
   11.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11.15 + * GNU General Public License for more details.
   11.16 + *
   11.17 + * You should have received a copy of the GNU General Public License
   11.18 + * along with this program. Look for COPYING file in the top folder.
   11.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   11.20 + */
   11.21 +package org.apidesign.bck2brwsr.tck;
   11.22 +
   11.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
   11.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
   11.25 +import org.testng.annotations.Factory;
   11.26 +
   11.27 +/**
   11.28 + *
   11.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   11.30 + */
   11.31 +public class LongArithmeticTest {
   11.32 +    
   11.33 +    private static long add(long x, long y) {
   11.34 +        return (x + y);
   11.35 +    }
   11.36 +    
   11.37 +    private static long sub(long x, long y) {
   11.38 +        return (x - y);
   11.39 +    }
   11.40 +    
   11.41 +    private static long mul(long x, long y) {
   11.42 +        return (x * y);
   11.43 +    }
   11.44 +    
   11.45 +    private static long div(long x, long y) {
   11.46 +        return (x / y);
   11.47 +    }
   11.48 +    
   11.49 +    private static long mod(long x, long y) {
   11.50 +        return (x % y);
   11.51 +    }
   11.52 +    
   11.53 +    private static long neg(long x) {
   11.54 +        return (-x);
   11.55 +    }
   11.56 +    
   11.57 +    private static long shl(long x, int b) {
   11.58 +        return (x << b);
   11.59 +    }
   11.60 +    
   11.61 +    private static long shr(long x, int b) {
   11.62 +        return (x >> b);
   11.63 +    }
   11.64 +    
   11.65 +    private static long ushr(long x, int b) {
   11.66 +        return (x >>> b);
   11.67 +    }
   11.68 +    
   11.69 +    private static long and(long x, long y) {
   11.70 +        return (x & y);
   11.71 +    }
   11.72 +    
   11.73 +    private static long or(long x, long y) {
   11.74 +        return (x | y);
   11.75 +    }
   11.76 +    
   11.77 +    private static long xor(long x, long y) {
   11.78 +        return (x ^ y);
   11.79 +    }
   11.80 +    
   11.81 +    public static int compare(long x, long y, int zero) {
   11.82 +        final int xyResult = compareL(x, y, zero);
   11.83 +        final int yxResult = compareL(y, x, zero);
   11.84 +
   11.85 +        return ((xyResult + yxResult) == 0) ? xyResult : -2;
   11.86 +    }
   11.87 +
   11.88 +    private static int compareL(long x, long y, int zero) {
   11.89 +        int result = -2;
   11.90 +        int trueCount = 0;
   11.91 +
   11.92 +        x += zero;
   11.93 +        if (x == y) {
   11.94 +            result = 0;
   11.95 +            ++trueCount;
   11.96 +        }
   11.97 +
   11.98 +        x += zero;
   11.99 +        if (x < y) {
  11.100 +            result = -1;
  11.101 +            ++trueCount;
  11.102 +        }
  11.103 +
  11.104 +        x += zero;
  11.105 +        if (x > y) {
  11.106 +            result = 1;
  11.107 +            ++trueCount;
  11.108 +        }
  11.109 +
  11.110 +        return (trueCount == 1) ? result : -2;
  11.111 +    }
  11.112 +    
  11.113 +    @Compare public long conversion() {
  11.114 +        return Long.MAX_VALUE;
  11.115 +    }
  11.116 +    
  11.117 +    @Compare public long negate1() {
  11.118 +        return neg(0x00fa37d7763e0ca1l);
  11.119 +    }
  11.120 +    
  11.121 +    @Compare public long negate2() {
  11.122 +        return neg(0x80fa37d7763e0ca1l);
  11.123 +    }
  11.124 +
  11.125 +    @Compare public long negate3() {
  11.126 +        return neg(0xfffffffffffffeddl);
  11.127 +    }
  11.128 +
  11.129 +    @Compare public long addOverflow() {
  11.130 +        return add(Long.MAX_VALUE, 1l);
  11.131 +    }
  11.132 +
  11.133 +    @Compare public long subUnderflow() {
  11.134 +        return sub(Long.MIN_VALUE, 1l);
  11.135 +    }
  11.136 +
  11.137 +    @Compare public long addMaxLongAndMaxLong() {
  11.138 +        return add(Long.MAX_VALUE, Long.MAX_VALUE);
  11.139 +    }
  11.140 +    
  11.141 +    @Compare public long subMinLongAndMinLong() {
  11.142 +        return sub(Long.MIN_VALUE, Long.MIN_VALUE);
  11.143 +    }
  11.144 +    
  11.145 +    @Compare public long subMinLongAndMaxLong() {
  11.146 +        return sub(Long.MIN_VALUE, Long.MAX_VALUE);
  11.147 +    }
  11.148 +
  11.149 +    @Compare public long multiplyMaxLong() {
  11.150 +        return mul(Long.MAX_VALUE, 2l);
  11.151 +    }
  11.152 +    
  11.153 +    @Compare public long multiplyMaxLongAndMaxLong() {
  11.154 +        return mul(Long.MAX_VALUE, Long.MAX_VALUE);
  11.155 +    }
  11.156 +    
  11.157 +    @Compare public long multiplyMinLong() {
  11.158 +        return mul(Long.MIN_VALUE, 2l);
  11.159 +    }
  11.160 +    
  11.161 +    @Compare public long multiplyMinLongAndMinLong() {
  11.162 +        return mul(Long.MIN_VALUE, Long.MIN_VALUE);
  11.163 +    }
  11.164 +    
  11.165 +    @Compare public long multiplyPrecision() {
  11.166 +        return mul(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
  11.167 +    }
  11.168 +    
  11.169 +    @Compare public long divideSmallPositiveNumbers() {
  11.170 +        return div(0xabcdef, 0x123);
  11.171 +    }
  11.172 +
  11.173 +    @Compare public long divideSmallNegativeNumbers() {
  11.174 +        return div(-0xabcdef, -0x123);
  11.175 +    }
  11.176 +
  11.177 +    @Compare public long divideSmallMixedNumbers() {
  11.178 +        return div(0xabcdef, -0x123);
  11.179 +    }
  11.180 +
  11.181 +    @Compare public long dividePositiveNumbersOneDigitDenom() {
  11.182 +        return div(0xabcdef0102ffffl, 0x654);
  11.183 +    }
  11.184 +
  11.185 +    @Compare public long divideNegativeNumbersOneDigitDenom() {
  11.186 +        return div(-0xabcdef0102ffffl, -0x654);
  11.187 +    }
  11.188 +
  11.189 +    @Compare public long divideMixedNumbersOneDigitDenom() {
  11.190 +        return div(-0xabcdef0102ffffl, 0x654);
  11.191 +    }
  11.192 +
  11.193 +    @Compare public long dividePositiveNumbersMultiDigitDenom() {
  11.194 +        return div(0x7ffefc003322aabbl, 0x89ab1000l);
  11.195 +    }
  11.196 +
  11.197 +    @Compare public long divideNegativeNumbersMultiDigitDenom() {
  11.198 +        return div(-0x7ffefc003322aabbl, -0x123489ab1001l);
  11.199 +    }
  11.200 +
  11.201 +    @Compare public long divideMixedNumbersMultiDigitDenom() {
  11.202 +        return div(0x7ffefc003322aabbl, -0x38f49b0b7574e36l);
  11.203 +    }
  11.204 +
  11.205 +    @Compare public long divideWithOverflow() {
  11.206 +        return div(0x8000fffe0000l, 0x8000ffffl);
  11.207 +    }
  11.208 +
  11.209 +    @Compare public long divideWithCorrection() {
  11.210 +        return div(0x7fff800000000000l, 0x800000000001l);
  11.211 +    }
  11.212 +
  11.213 +    @Compare public long moduloSmallPositiveNumbers() {
  11.214 +        return mod(0xabcdef, 0x123);
  11.215 +    }
  11.216 +
  11.217 +    @Compare public long moduloSmallNegativeNumbers() {
  11.218 +        return mod(-0xabcdef, -0x123);
  11.219 +    }
  11.220 +
  11.221 +    @Compare public long moduloSmallMixedNumbers() {
  11.222 +        return mod(0xabcdef, -0x123);
  11.223 +    }
  11.224 +
  11.225 +    @Compare public long moduloPositiveNumbersOneDigitDenom() {
  11.226 +        return mod(0xabcdef0102ffffl, 0x654);
  11.227 +    }
  11.228 +
  11.229 +    @Compare public long moduloNegativeNumbersOneDigitDenom() {
  11.230 +        return mod(-0xabcdef0102ffffl, -0x654);
  11.231 +    }
  11.232 +
  11.233 +    @Compare public long moduloMixedNumbersOneDigitDenom() {
  11.234 +        return mod(-0xabcdef0102ffffl, 0x654);
  11.235 +    }
  11.236 +
  11.237 +    @Compare public long moduloPositiveNumbersMultiDigitDenom() {
  11.238 +        return mod(0x7ffefc003322aabbl, 0x89ab1000l);
  11.239 +    }
  11.240 +
  11.241 +    @Compare public long moduloNegativeNumbersMultiDigitDenom() {
  11.242 +        return mod(-0x7ffefc003322aabbl, -0x123489ab1001l);
  11.243 +    }
  11.244 +
  11.245 +    @Compare public long moduloMixedNumbersMultiDigitDenom() {
  11.246 +        return mod(0x7ffefc003322aabbl, -0x38f49b0b7574e36l);
  11.247 +    }
  11.248 +
  11.249 +    @Compare public long moduloWithOverflow() {
  11.250 +        return mod(0x8000fffe0000l, 0x8000ffffl);
  11.251 +    }
  11.252 +
  11.253 +    @Compare public long moduloWithCorrection() {
  11.254 +        return mod(0x7fff800000000000l, 0x800000000001l);
  11.255 +    }
  11.256 +    
  11.257 +    @Compare public long shiftL1() {
  11.258 +        return shl(0x00fa37d7763e0ca1l, 5);
  11.259 +    }
  11.260 +    
  11.261 +    @Compare public long shiftL2() {
  11.262 +        return shl(0x00fa37d7763e0ca1l, 32);
  11.263 +    }
  11.264 +    
  11.265 +    @Compare public long shiftL3() {
  11.266 +        return shl(0x00fa37d7763e0ca1l, 45);
  11.267 +    }
  11.268 +    
  11.269 +    @Compare public long shiftR1() {
  11.270 +        return shr(0x00fa37d7763e0ca1l, 5);
  11.271 +    }
  11.272 +    
  11.273 +    @Compare public long shiftR2() {
  11.274 +        return shr(0x00fa37d7763e0ca1l, 32);
  11.275 +    }
  11.276 +    
  11.277 +    @Compare public long shiftR3() {
  11.278 +        return shr(0x00fa37d7763e0ca1l, 45);
  11.279 +    }
  11.280 +    
  11.281 +    @Compare public long uShiftR1() {
  11.282 +        return ushr(0x00fa37d7763e0ca1l, 5);
  11.283 +    }
  11.284 +    
  11.285 +    @Compare public long uShiftR2() {
  11.286 +        return ushr(0x00fa37d7763e0ca1l, 45);
  11.287 +    }
  11.288 +    
  11.289 +    @Compare public long uShiftR3() {
  11.290 +        return ushr(0xf0fa37d7763e0ca1l, 5);
  11.291 +    }
  11.292 +    
  11.293 +    @Compare public long uShiftR4() {
  11.294 +        return ushr(0xf0fa37d7763e0ca1l, 45);
  11.295 +    }
  11.296 +    
  11.297 +    @Compare public long and1() {
  11.298 +        return and(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
  11.299 +    }
  11.300 +    
  11.301 +    @Compare public long or1() {
  11.302 +        return or(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
  11.303 +    }
  11.304 +    
  11.305 +    @Compare public long xor1() {
  11.306 +        return xor(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
  11.307 +    }
  11.308 +    
  11.309 +    @Compare public long xor2() {
  11.310 +        return xor(0x00fa37d7763e0ca1l, 0x00000000ff00123el);
  11.311 +    }
  11.312 +    
  11.313 +    @Compare public long xor3() {
  11.314 +        return xor(0x00000000763e0ca1l, 0x00000000ff00123el);
  11.315 +    }
  11.316 +    
  11.317 +    @Compare public int compareSameNumbers() {
  11.318 +        return compare(0x0000000000000000l, 0x0000000000000000l, 0);
  11.319 +    }
  11.320 +
  11.321 +    @Compare public int comparePositiveNumbers() {
  11.322 +        return compare(0x0000000000200000l, 0x0000000010000000l, 0);
  11.323 +    }
  11.324 +
  11.325 +    @Compare public int compareNegativeNumbers() {
  11.326 +        return compare(0xffffffffffffffffl, 0xffffffff00000000l, 0);
  11.327 +    }
  11.328 +
  11.329 +    @Compare public int compareMixedNumbers() {
  11.330 +        return compare(0x8000000000000000l, 0x7fffffffffffffffl, 0);
  11.331 +    }
  11.332 +    
  11.333 +    @Factory
  11.334 +    public static Object[] create() {
  11.335 +        return VMTest.create(LongArithmeticTest.class);
  11.336 +    }
  11.337 +}