In javascript you can use Int8, Uint8, Int16, etc., but it takes a little more effort than usual - see TypedArrays .
var A = new Uint32Array(new ArrayBuffer(4*n)); var B = new Uint32Array(new ArrayBuffer(4*n)); //assign some example values to A for(var i=0;i<n;i++) A[i] = i; //note RHS is implicitly converted to uint32 //assign some example values to B for(var i=0;i<n;i++) B[i] = 4*i+3; //again, note RHS is implicitly converted to uint32 //this is true integer arithmetic for(var i=0;i<n;i++) A[i] += B[i];
Recently, the asm.js project allowed you to compile C / C ++ code for a weird looking javascript that uses these TypedArrays so that you can use your existing C / C ++ code and it should work pretty quickly in the browser (especially if browser developers implement special optimizations for this type of code, which should happen soon).
On a side note *, if you program, you can do SIMD parallelism (see wikipeda), that is, if your code uses a set of SSEx instructions, your arithmetic will be much faster, and in fact using int8s will be twice as fast as using int16s etc.
* I do not think this is relevant for browsers because they are too difficult to use on the fly. Edit: Turns out Firefox is experimenting with such optimizations. Also Dart (true Dart, not Dart compiled in js) will be able to do this in Chrome.
source share