<commit_before>var n = 1024;
var a = generateMatrix(n);
var b = generateMatrix(n);
var c = generateC(n);
var LOG_N = 10;

function matMul() {
  var start = window.performance.now();
  for (var i = 0; i < n; i++) {
    for (var jh = 0; jh < n; jh += 4) {
      for (var k = 0; k < n; k += 4) {
        for (var jl = 0; jl < 4; jl++) {
          var simdC = SIMD.Float32x4.load(c, (i << LOG_N) | jh);
          var simdA = SIMD.Float32x4.load(a, (i << LOG_N) | k);
          var simdB = SIMD.Float32x4.load(b, ((jh + jl) << LOG_N) | k);
          var simdMul = SIMD.Float32x4.mul(simdA, simdB);
          var simdCPlusAB = SIMD.Float32x4.add(simdC, simdMul);
          SIMD.Float32x4.store(c, (i << LOG_N) | jh, simdCPlusAB);
        }
      }
    }
  }
  var end = window.performance.now();
  return end - start;
}

function generateC(n) {
  var c = new Float32Array(n * n);
  for (var i = 0; i < n; i++) {
    for (var j = 0; j < n; j++) {
      c[i * n + j] = 0;
    }
  }
  return c;
}

function generateMatrix(n) {
  var a = new Float32Array(n * n);
  for (var i = 0; i < n; i++) {
    for (var j = 0; j < n; j++) {
      a[i * n + j] = Math.random();
    }
  }
  return a;
}

function perfTest(name, fun) {
  var runs = [];
  var total = 16;
  var warmup = 4;
  for (var i = 0; i < total + warmup; i++) {
    console.log(i);
    var time = fun();
    runs.push(time);
  }

  // Only average, stddev would be pretty interesting too
  var min = runs.reduce(function(a, b) {
    return Math.min(a, b);
  });

  console.log(name + ': ' + min + ' ms');
}

function testTriply() {
  perfTest('Triply-nested global typed transposed aggregated arrays', matMul);<commit_msg>Use Float64x2 instead<commit_after>var n = 1024;
var a = generateMatrix(n);
var b = generateMatrix(n);
var c = generateC(n);
var LOG_N = 10;

function matMul() {
  var start = window.performance.now();
  for (var i = 0; i < n; i++) {
    for (var jh = 0; jh < n; jh += 2) {
      for (var k = 0; k < n; k += 2) {
        for (var jl = 0; jl < 2; jl++) {
          var simdC = SIMD.Float64x2.load(c, (i << LOG_N) | jh);
          var simdA = SIMD.Float64x2.load(a, (i << LOG_N) | k);
          var simdB = SIMD.Float64x2.load(b, ((jh + jl) << LOG_N) | k);
          var simdMul = SIMD.Float64x2.mul(simdA, simdB);
          var simdCPlusAB = SIMD.Float64x2.add(simdC, simdMul);
          SIMD.Float64x2.store(c, (i << LOG_N) | jh, simdCPlusAB);
        }
      }
    }
  }
  var end = window.performance.now();
  return end - start;
}

function generateC(n) {
  var c = new Float64Array(n * n);
  for (var i = 0; i < n; i++) {
    for (var j = 0; j < n; j++) {
      c[i * n + j] = 0;
    }
  }
  return c;
}

function generateMatrix(n) {
  var a = new Float64Array(n * n);
  for (var i = 0; i < n; i++) {
    for (var j = 0; j < n; j++) {
      a[i * n + j] = Math.random();
    }
  }
  return a;
}

function perfTest(name, fun) {
  var runs = [];
  var total = 16;
  var warmup = 4;
  for (var i = 0; i < total + warmup; i++) {
    console.log(i);
    var time = fun();
    runs.push(time);
  }

  // Only average, stddev would be pretty interesting too
  var min = runs.reduce(function(a, b) {
    return Math.min(a, b);
  });

  console.log(name + ': ' + min + ' ms');
}

function testTriply() {
  perfTest('Triply-nested global typed transposed aggregated arrays', matMul);
{'fraction_non_alphanumeric': 0.17513448894202033, 'fraction_numerical': 0.027196652719665274, 'mean_word_length': 2.297536945812808, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1288610', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1363, 'n_words': 387}