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

@ -0,0 +1,28 @@
// IntArrayCoreBox — thin Hako wrapper over NyRT IntArrayCore (handle-based)
// This provides a box-level API for numeric kernels while delegating storage
// to nyash.intarray.* extern calls in NyRT (ring1).
static box IntArrayCore {
init { handle, len }
static new(len) {
local h = externcall "nyash.intarray.new_h"(len)
local b = new IntArrayCore()
b.handle = h
b.len = len
return b
}
length() {
return externcall "nyash.intarray.len_h"(me.handle)
}
get_unchecked(idx) {
return externcall "nyash.intarray.get_hi"(me.handle, idx)
}
set_unchecked(idx, v) {
externcall "nyash.intarray.set_hii"(me.handle, idx, v)
return null
}
}

View File

@ -0,0 +1,65 @@
// MatI64 — simple i64 matrix box built on top of IntArrayCore.
// Internal layout: rows, cols, stride, core (IntArrayCore).
using nyash.core.numeric.intarray as IntArrayCore
static box MatI64 {
init { rows, cols, stride, core }
static new(rows, cols) {
local total = rows * cols
local core = IntArrayCore.new(total)
local m = new MatI64()
m.rows = rows
m.cols = cols
m.stride = cols
m.core = core
return m
}
rowsCount() {
return me.rows
}
colsCount() {
return me.cols
}
at(r, c) {
local idx = r * me.stride + c
return me.core.get_unchecked(idx)
}
set(r, c, v) {
local idx = r * me.stride + c
me.core.set_unchecked(idx, v)
return null
}
// Naive O(n^3) matmul: this * b
mul_naive(b) {
local n = me.rows
local mcols = me.cols
local bcols = b.cols
// assume shapes are compatible and square for now (Phase 21.6 draft)
local out = MatI64.new(n, bcols)
local i = 0
loop(i < n) {
local k = 0
loop(k < mcols) {
local aik = me.at(i, k)
local j = 0
loop(j < bcols) {
local idx = i * out.stride + j
local v = out.core.get_unchecked(idx) + aik * b.at(k, j)
out.core.set_unchecked(idx, v)
j = j + 1
}
k = k + 1
}
i = i + 1
}
return out
}
}