import { ReduceProgram as s } from "./utils/reductions.js";
class i extends s {
  hasGamma;
  constructor(a, t, e = !1) {
    super(a, t, { reductionOp: "mean", elementwise: !0 }, !0), this.shaderKey = "RMSNorm16", e && this.variableNames.push("gamma"), this.variableComponents = [1, 1], this.hasGamma = e;
  }
  getPreprocessSnippet() {
    return "candidate = candidate * candidate;";
  }
  getPostprocessSnippet() {
    return "bestValue = inverseSqrt(bestValue + 1e-8);";
  }
  getWriteSnippet() {
    return `
            let X = unpack2x16float(u32(x[offset + k]));
            ${this.hasGamma ? "let gamma = unpack2x16float(u32(gamma[k]));" : ""}
            let normalized = X * bestValue;
            let outVal = normalized ${this.hasGamma ? " * gamma" : ""};
            result[offset + k] = i32(pack2x16float(outVal));
        `;
  }
}
export {
  i as default
};
