feat(perf): add Phase 21.8 foundation for IntArrayCore/MatI64 numeric boxes

Prepare infrastructure for specialized numeric array benchmarking:
- Add IntArrayCore plugin stub (crates/nyash_kernel/src/plugin/intarray.rs)
- Add IntArrayCore/MatI64 box definitions (lang/src/runtime/numeric/)
- Add Phase 21.8 documentation and task tracking
- Update nyash.toml/hako.toml with numeric library configuration
- Extend microbench.sh for matmul_core benchmark case

Next: Resolve Stage-B MirBuilder to recognize MatI64/IntArrayCore as boxes

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-11-14 15:18:14 +09:00
parent f1fa182a4b
commit 8214176814
11 changed files with 549 additions and 3 deletions

View File

@ -5,7 +5,7 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
BIN="$ROOT/target/release/hakorune"
usage() { echo "Usage: $0 --case {loop|strlen|box|branch|call|stringchain|arraymap|chip8|kilo|sieve|matmul|linidx|maplin} [--n N] [--runs R] [--backend {llvm|vm}] [--exe] [--budget-ms B]"; }
usage() { echo "Usage: $0 --case {loop|strlen|box|branch|call|stringchain|arraymap|chip8|kilo|sieve|matmul|matmul_core|linidx|maplin} [--n N] [--runs R] [--backend {llvm|vm}] [--exe] [--budget-ms B]"; }
CASE="loop"; N=5000000; RUNS=5; BACKEND="llvm"; EXE_MODE=0; BUDGET_MS=0
while [[ $# -gt 0 ]]; do
@ -562,6 +562,91 @@ C
rm -f "$TMP_CHECK_JSON" 2>/dev/null || true
fi
;;
matmul_core)
# Core numeric matmul using MatI64 + IntArrayCore
# Use smaller default N to keep runtime reasonable
if [[ "$EXE_MODE" = "1" && "$N" = "5000000" ]]; then
N=256
fi
HAKO_FILE=$(mktemp_hako)
cat >"$HAKO_FILE" <<HAKO
using nyash.core.numeric.matrix_i64 as MatI64
static box Main { method main(args) {
local n = ${N}
// Initialize A, B, C as n x n matrices
local A = MatI64.new(n, n)
local B = MatI64.new(n, n)
local C = MatI64.new(n, n)
local i = 0
loop(i < n) {
local j = 0
loop(j < n) {
local idx = i*n + j
A.set(i, j, idx % 97)
B.set(i, j, (idx * 3) % 101)
C.set(i, j, 0)
j = j + 1
}
i = i + 1
}
// Naive matmul via MatI64.mul_naive
local out = A.mul_naive(B)
return out.at(n-1, n-1)
} }
HAKO
C_FILE=$(mktemp_c)
cat >"$C_FILE" <<'C'
#include <stdint.h>
#include <stdlib.h>
typedef struct {
int64_t *ptr;
int64_t rows;
int64_t cols;
int64_t stride;
} MatI64Core;
static inline int64_t mat_get(MatI64Core *m, int64_t r, int64_t c) {
return m->ptr[r * m->stride + c];
}
static inline void mat_set(MatI64Core *m, int64_t r, int64_t c, int64_t v) {
m->ptr[r * m->stride + c] = v;
}
int main() {
int64_t n = N_PLACEHOLDER;
int64_t total = n * n;
MatI64Core A, B, C;
A.rows = B.rows = C.rows = n;
A.cols = B.cols = C.cols = n;
A.stride = B.stride = C.stride = n;
A.ptr = (int64_t*)malloc(sizeof(int64_t)*total);
B.ptr = (int64_t*)malloc(sizeof(int64_t)*total);
C.ptr = (int64_t*)malloc(sizeof(int64_t)*total);
for (int64_t idx = 0; idx < total; idx++) {
A.ptr[idx] = idx % 97;
B.ptr[idx] = (idx * 3) % 101;
C.ptr[idx] = 0;
}
for (int64_t i = 0; i < n; i++) {
for (int64_t k = 0; k < n; k++) {
int64_t aik = mat_get(&A, i, k);
for (int64_t j = 0; j < n; j++) {
int64_t idx = i * C.stride + j;
int64_t v = C.ptr[idx] + aik * mat_get(&B, k, j);
C.ptr[idx] = v;
}
}
}
int64_t r = mat_get(&C, n-1, n-1);
free(A.ptr); free(B.ptr); free(C.ptr);
return (int)(r & 0xFF);
}
C
sed -i "s/N_PLACEHOLDER/${N}/" "$C_FILE"
;;
linidx)
# Linear index pattern: idx = i*cols + j
# Derive rows/cols from N to keep runtime stable