mirror of
https://github.com/roytam1/basilisk55.git
synced 2026-05-26 15:02:46 +00:00
import mergediff of "Issue #2895 - Implement 32-bit compatible Xoroshiro128++"
This commit is contained in:
@@ -12302,6 +12302,8 @@ CodeGenerator::visitRandom(LRandom* ins)
|
||||
masm.Pop(tempReg);
|
||||
#endif
|
||||
masm.add64(s0Reg, imrReg);
|
||||
|
||||
// Store the result in mState[2], freeing up the intermediate register again.
|
||||
masm.store64(imrReg, state2Addr);
|
||||
|
||||
// s1 ^= s0;
|
||||
@@ -12319,10 +12321,10 @@ CodeGenerator::visitRandom(LRandom* ins)
|
||||
|
||||
// mState[0] = rotl(s0, 49) ^ s1 ^ (s1 << 21); // a, b
|
||||
#ifdef JS_PUNBOX64
|
||||
masm.rotateLeft64(Imm32(49), s0Reg, s0Reg); // imr = s0 rotl 49
|
||||
masm.rotateLeft64(Imm32(49), s0Reg, s0Reg); // s0 rotl 49
|
||||
#else
|
||||
masm.Push(tempReg);
|
||||
masm.rotateLeft64(Imm32(49), s0Reg, s0Reg, tempReg); // imr = s0 rotl 49
|
||||
masm.rotateLeft64(Imm32(49), s0Reg, s0Reg, tempReg); // s0 rotl 49
|
||||
masm.Pop(tempReg);
|
||||
#endif
|
||||
masm.move64(s1Reg, imrReg); // imr = s1
|
||||
@@ -12331,6 +12333,7 @@ CodeGenerator::visitRandom(LRandom* ins)
|
||||
masm.xor64(s1Reg, s0Reg); // s0 ^= s1
|
||||
masm.store64(s0Reg, state0Addr);
|
||||
|
||||
// Recall the result from mState[2]
|
||||
masm.load64(state2Addr, s1Reg);
|
||||
|
||||
// See comment in Xoroshiro128PlusPlusRNG::nextDouble().
|
||||
|
||||
@@ -31,15 +31,17 @@ const original = () => {
|
||||
var startTime = performance.now();
|
||||
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
||||
const data = imageData.data;
|
||||
for (let i = 0; i < data.length; i += 4) {
|
||||
for (let j = 0; j < 10; j++) { // 10x for performance measurement
|
||||
for (let i = 0; i < data.length; i += 4) {
|
||||
data[i] = Math.random()*255; // red
|
||||
data[i + 1] = Math.random()*255; // green
|
||||
data[i + 2] = Math.random()*255; // blue
|
||||
data[i+3] = 255;
|
||||
}
|
||||
}
|
||||
ctx.putImageData(imageData, 0, 0);
|
||||
var endTime = performance.now();
|
||||
duration.innerHTML = "Total pixels: " + (data.length / 4) +" -- Time taken: " + (endTime - startTime) + " ms";
|
||||
duration.innerHTML = "Total pixels: " + (10 * data.length / 4) +" -- Time taken: " + (endTime - startTime) + " ms";
|
||||
};
|
||||
|
||||
const invert = () => {
|
||||
@@ -60,16 +62,18 @@ const grayscale = () => {
|
||||
var startTime = performance.now();
|
||||
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
||||
const data = imageData.data;
|
||||
for (let i = 0; i < data.length; i += 4) {
|
||||
for (let j = 0; j < 10; j++) { // 10x for performance measurement
|
||||
for (let i = 0; i < data.length; i += 4) {
|
||||
const avg = Math.random()*255;
|
||||
data[i] = avg; // red
|
||||
data[i + 1] = avg; // green
|
||||
data[i + 2] = avg; // blue
|
||||
data[i+3] = 255;
|
||||
}
|
||||
}
|
||||
ctx.putImageData(imageData, 0, 0);
|
||||
var endTime = performance.now();
|
||||
duration.innerHTML = "Total pixels: " + (data.length / 4) +" -- Time taken: " + (endTime - startTime) + " ms";
|
||||
duration.innerHTML = "Total pixels: " + (10 * data.length / 4) +" -- Time taken: " + (endTime - startTime) + " ms";
|
||||
};
|
||||
|
||||
const sepia = () => {
|
||||
|
||||
@@ -32,13 +32,14 @@ namespace non_crypto {
|
||||
* the same speed and use half of the space; the same comments apply.
|
||||
* They are suitable only for low-scale parallel applications.
|
||||
*
|
||||
* The stream of numbers produced by this method repeats every 2**256 - 1 calls (i.e. never, for all practical
|
||||
* The stream of numbers produced by this method repeats every 2^128 - 1 calls (i.e. never, for all practical
|
||||
* purposes).
|
||||
*
|
||||
*/
|
||||
class Xoroshiro128PlusPlusRNG {
|
||||
/*
|
||||
* mState[2] is used for temporary storage in JIT code.
|
||||
* mState[0] and mState[1] are as-described in the Xoroshiro128++ paper.
|
||||
* mState[2] is used for temporary storage of the result in JIT code.
|
||||
*/
|
||||
uint64_t mState[3];
|
||||
|
||||
@@ -85,15 +86,15 @@ class Xoroshiro128PlusPlusRNG {
|
||||
|
||||
/*
|
||||
* Return a pseudo-random floating-point value in the range [0, 1). More
|
||||
* precisely, choose an integer in the range [0, 2**53) and divide it by
|
||||
* 2**53. Given the 2**256 - 1 period noted above, the produced doubles are
|
||||
* precisely, choose an integer in the range [0, 2^53) and divide it by
|
||||
* 2^53. Given the 2^128 - 1 period noted above, the produced doubles are
|
||||
* all but uniformly distributed in this range.
|
||||
*/
|
||||
double nextDouble() {
|
||||
/*
|
||||
* Because the IEEE 64-bit floating point format stores the leading '1' bit
|
||||
* of the mantissa implicitly, it effectively represents a mantissa in the
|
||||
* range [0, 2**53) in only 52 bits. FloatingPoint<double>::kExponentShift
|
||||
* range [0, 2^53) in only 52 bits. FloatingPoint<double>::kExponentShift
|
||||
* is the width of the bitfield in the in-memory format, so we must add one
|
||||
* to get the mantissa's range.
|
||||
*/
|
||||
@@ -112,7 +113,7 @@ class Xoroshiro128PlusPlusRNG {
|
||||
MOZ_ASSERT(aState0 || aState1);
|
||||
mState[0] = aState0;
|
||||
mState[1] = aState1;
|
||||
mState[2] = 0;
|
||||
mState[2] = 0; // Could be left uninitialized, but we do this just-in-case.
|
||||
}
|
||||
|
||||
static size_t offsetOfState0() {
|
||||
|
||||
Reference in New Issue
Block a user