Skip to content

Commit

Permalink
Attempting to fix travis webgl issues with shifted mods
Browse files Browse the repository at this point in the history
  • Loading branch information
Strilanc committed Jun 8, 2018
1 parent 5c30463 commit 4f7e96f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/gates/AmplitudeDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const SPREAD_LENGTH_ACROSS_POLAR_KETS_SHADER = makePseudoShaderWithInputsAndOutp
uniform float bit;
float xorBit(float v) {
float b = mod(floor(v/bit), 2.0);
float b = floor(mod(floor(v/bit) + 0.5, 2.0));
float d = 1.0 - 2.0*b;
return v + bit*d;
}
Expand Down Expand Up @@ -257,7 +257,7 @@ const TO_RATIOS_VS_REPRESENTATIVE_SHADER = makePseudoShaderWithInputsAndOutputAn
],
Outputs.vec4(),
`vec4 outputFor(float k) {
return vec4(read_ket(k), read_rep(mod(k, len_rep())).xy);
return vec4(read_ket(k), read_rep(floor(mod(k + 0.5, len_rep()))).xy);
}`);

/**
Expand Down
12 changes: 2 additions & 10 deletions src/gates/ModularAdditionGates.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,8 @@ const MODULAR_ADDITION_SHADER = ketShaderPermute(
}
float d = read_input_A();
d *= factor;
d = mod(d, r);
float result = mod(out_id + r - d, r);
// Despite sanity, I consistently get result=33 instead of result=0 when out_id=0, d=0, r=33.
// HACK: Fix it by hand.
if (result >= r) {
result -= r;
}
return result;
d = floor(mod(d + 0.5, r));
return floor(mod(out_id + r - d + 0.5, r));
`);

ModularAdditionGates.PlusAModRFamily = Gate.buildFamily(1, 16, (span, builder) => builder.
Expand Down
6 changes: 3 additions & 3 deletions src/gates/MultiplyAccumulateGates.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ const BIG_MUL_MOD_SHADER_CODE = `
float t = 0.0;
float r;
for (int k = 0; k < ${Math.ceil(Config.MAX_WIRE_COUNT/MUL_STEP)}; k++) {
r = mod(f, ${1<<MUL_STEP}.0);
r = floor(mod(f + 0.5, ${1<<MUL_STEP}.0));
f -= r;
t = mod(t + b*r, modulus);
b = mod(b * ${1<<MUL_STEP}.0, modulus);
t = floor(mod(t + b*r + 0.5, modulus));
b = floor(mod(b * ${1<<MUL_STEP}.0 + 0.5, modulus));
f /= ${1<<MUL_STEP}.0;
}
return t;
Expand Down
2 changes: 1 addition & 1 deletion test/webgl/ShaderCoders_Base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ suite.testUsingWebGL("boolOutputs", () => {
let output = BOOL_TYPE_CODER.outputPart;
let shader = combinedShaderPartsWithCode([output], `
bool outputFor(float k) {
return mod(k, 3.0) == 1.0;
return floor(mod(k + 0.5, 3.0)) == 1.0;
}`);

assertThat(shaderWithOutputPartAndArgs(shader, output, []).readBoolOutputs(3)).isEqualTo(new Uint8Array([
Expand Down

0 comments on commit 4f7e96f

Please sign in to comment.