@fraczak/k 6.10.3 → 6.10.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/DOCS/FILE_FORMATS.md +51 -16
- package/Examples/karatsuba-mult.k +215 -0
- package/backends/arm64/scripts/run-tests.mjs +16 -0
- package/backends/llvm/bin/k-llvm-build.mjs +40 -14
- package/backends/llvm/bin/k-llvm-compile.mjs +29 -12
- package/backends/llvm/runtime/krt.c +10 -10
- package/backends/llvm/runtime/krt.h +6 -1
- package/backends/llvm/scripts/run-tests.mjs +16 -0
- package/backends/llvm/src/cli.mjs +1 -1
- package/backends/llvm/src/executable.mjs +36 -0
- package/backends/llvm/src/kvm2llvm.mjs +10 -4
- package/backends/llvm/tests/integration.sh +11 -0
- package/backends/llvm/tests/test-llvm.mjs +15 -1
- package/backends/wasm/scripts/run-tests.mjs +16 -0
- package/browser/vfs-data.mjs +1 -1
- package/core.k +5 -5
- package/package.json +2 -1
- package/scripts/benchmark-idempotency.mjs +27 -0
- package/scripts/benchmark.mjs +51 -0
- package/scripts/build-repl-html.mjs +17 -0
- package/scripts/generate-dependency-graph.mjs +25 -1
- package/scripts/perf-ieee.mjs +75 -0
- package/scripts/perf-int.mjs +67 -0
- package/scripts/perf-multiplication.mjs +644 -0
- package/scripts/perf-poly.mjs +67 -0
- package/scripts/render-benchmark.mjs +25 -0
- package/scripts/run-tests.mjs +19 -0
- package/tests/test-karatsuba.mjs +133 -0
package/scripts/benchmark.mjs
CHANGED
|
@@ -733,7 +733,58 @@ function printSummary(document) {
|
|
|
733
733
|
console.log("=============================================================\n");
|
|
734
734
|
}
|
|
735
735
|
|
|
736
|
+
function printHelp() {
|
|
737
|
+
console.log(`Usage: node scripts/benchmark.mjs [options]
|
|
738
|
+
|
|
739
|
+
Unified Multi-Backend Benchmark Suite.
|
|
740
|
+
Runs comprehensive arithmetic and IEEE benchmarks across Native JS,
|
|
741
|
+
kVM, KIR-P, Wasm, and LLVM-JIT execution engines.
|
|
742
|
+
|
|
743
|
+
Options:
|
|
744
|
+
--worker
|
|
745
|
+
Internal flag: execute an isolated benchmark worker job.
|
|
746
|
+
-h, --help
|
|
747
|
+
Show this help message and exit.
|
|
748
|
+
|
|
749
|
+
Environment Variables:
|
|
750
|
+
BENCHMARK_CASES
|
|
751
|
+
Comma-separated benchmark cases to run (default: all).
|
|
752
|
+
Cases: ieee.add, ieee.sub, ieee.mul, ieee.div,
|
|
753
|
+
int.times.220d, int.gcd.90d, int.factorial.101,
|
|
754
|
+
int.factorial.242, int.factorial.1174
|
|
755
|
+
BENCHMARK_MODES
|
|
756
|
+
Comma-separated execution modes to run (default: all).
|
|
757
|
+
Modes: Native JS (Envelope-Aware), Native JS (Envelope-Free),
|
|
758
|
+
kVM Interpreter (Env-Free), KIR-P Export,
|
|
759
|
+
k-wasm, k-llvm-jit
|
|
760
|
+
BENCHMARK_SAMPLES
|
|
761
|
+
Number of measurement samples per benchmark (default: 3).
|
|
762
|
+
BENCHMARK_TIMEOUT_MS
|
|
763
|
+
Timeout per benchmark job in milliseconds (default: 120000).
|
|
764
|
+
BENCHMARK_JOBS
|
|
765
|
+
Maximum parallel worker concurrency (default: 1).
|
|
766
|
+
BENCHMARK_STRICT
|
|
767
|
+
Exit with non-zero exit code if any case fails ('1' to enable).
|
|
768
|
+
K_LLVM_RUNTIME_MODE
|
|
769
|
+
Default LLVM runtime compilation mode (default: fast).
|
|
770
|
+
K_LLVM_IEEE_RUNTIME_MODE
|
|
771
|
+
LLVM runtime mode for IEEE benchmarks (default: compact).
|
|
772
|
+
K_LLVM_CLANG_OPT
|
|
773
|
+
Clang optimization flag for LLVM (default: -O3).
|
|
774
|
+
K_LLVM_IEEE_CLANG_OPT
|
|
775
|
+
Clang optimization flag for IEEE LLVM (default: -O0).
|
|
776
|
+
K_LLVM_CACHE_DIR
|
|
777
|
+
Directory to cache compiled LLVM executable binaries.
|
|
778
|
+
K_BENCHMARK_RESULT_PATH
|
|
779
|
+
Custom destination file path for benchmark results JSON.`);
|
|
780
|
+
}
|
|
781
|
+
|
|
736
782
|
async function main() {
|
|
783
|
+
if (process.argv.includes("-h") || process.argv.includes("--help")) {
|
|
784
|
+
printHelp();
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
|
|
737
788
|
if (process.env.K_BENCHMARK_WORKER === "1" || process.argv.includes("--worker")) {
|
|
738
789
|
await workerMain();
|
|
739
790
|
return;
|
|
@@ -10,6 +10,23 @@ const __dirname = path.dirname(__filename);
|
|
|
10
10
|
const projectRoot = path.resolve(__dirname, "..");
|
|
11
11
|
const workspaceRoot = path.resolve(projectRoot, "..");
|
|
12
12
|
|
|
13
|
+
function printHelp() {
|
|
14
|
+
console.log(`Usage: node scripts/build-repl-html.mjs [options]
|
|
15
|
+
|
|
16
|
+
Builds the standalone, self-contained K web REPL (repl.html).
|
|
17
|
+
Bundles browser shims, virtual file system (core.k, Examples, Wasm),
|
|
18
|
+
and UI components into a single zero-dependency HTML file.
|
|
19
|
+
|
|
20
|
+
Options:
|
|
21
|
+
-h, --help
|
|
22
|
+
Show this help message and exit.`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (process.argv.includes("-h") || process.argv.includes("--help")) {
|
|
26
|
+
printHelp();
|
|
27
|
+
process.exit(0);
|
|
28
|
+
}
|
|
29
|
+
|
|
13
30
|
console.log("=== Building Self-Contained K REPL HTML ===");
|
|
14
31
|
|
|
15
32
|
// 1. Node shims plugin for esbuild
|
|
@@ -8,7 +8,31 @@ import { execSync } from "node:child_process";
|
|
|
8
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
9
|
const __dirname = path.dirname(__filename);
|
|
10
10
|
const root = path.resolve(__dirname, "..");
|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
function printHelp() {
|
|
13
|
+
console.log(
|
|
14
|
+
`Usage: node scripts/generate-dependency-graph.mjs [options] [out]
|
|
15
|
+
|
|
16
|
+
Generates a Mermaid dependency diagram from tracked ESM imports.
|
|
17
|
+
|
|
18
|
+
Arguments:
|
|
19
|
+
out-file
|
|
20
|
+
Destination markdown file path.
|
|
21
|
+
(default: DOCS/dependency-graph.md)
|
|
22
|
+
|
|
23
|
+
Options:
|
|
24
|
+
-h, --help
|
|
25
|
+
Show this help message and exit.`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (process.argv.includes("-h") || process.argv.includes("--help")) {
|
|
29
|
+
printHelp();
|
|
30
|
+
process.exit(0);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const outPath = process.argv[2]
|
|
34
|
+
? path.resolve(root, process.argv[2])
|
|
35
|
+
: path.join(root, "DOCS", "dependency-graph.md");
|
|
12
36
|
|
|
13
37
|
function getTrackedMjsFiles() {
|
|
14
38
|
const raw = execSync("git ls-files '*.mjs'", {
|
package/scripts/perf-ieee.mjs
CHANGED
|
@@ -52,6 +52,81 @@ import {
|
|
|
52
52
|
import { compileWasmArtifactFromObject } from "../backends/wasm/src/wasm.mjs";
|
|
53
53
|
import { compileARM64ArtifactFromObject } from "../backends/arm64/src/arm64.mjs";
|
|
54
54
|
|
|
55
|
+
function printHelp() {
|
|
56
|
+
console.log(`Usage: node scripts/perf-ieee.mjs [options]
|
|
57
|
+
|
|
58
|
+
IEEE 754 Floating-Point Arithmetic Benchmark Harness.
|
|
59
|
+
Benchmarks add, sub, mul, and div on Examples/ieee.k across
|
|
60
|
+
Native JS, kVM interpreter, LLVM, Wasm, and ARM64 backends.
|
|
61
|
+
|
|
62
|
+
Options:
|
|
63
|
+
--opt=<levels>, --opts=<levels>
|
|
64
|
+
Comma-separated Clang optimization levels for LLVM (e.g. -O1,-O2).
|
|
65
|
+
--O0, --O1, --O2, --O3
|
|
66
|
+
Direct Clang optimization level flags for LLVM.
|
|
67
|
+
--full
|
|
68
|
+
Run full LLVM optimization sweep (-O0, -O1, -O2).
|
|
69
|
+
--wasm-in-process
|
|
70
|
+
Run WebAssembly in-process instead of persistent subprocess runner.
|
|
71
|
+
-h, --help
|
|
72
|
+
Show this help message and exit.
|
|
73
|
+
|
|
74
|
+
Environment Variables:
|
|
75
|
+
BACKENDS
|
|
76
|
+
Target backend to run: 'llvm', 'wasm', or 'arm64'.
|
|
77
|
+
LLVM_ONLY
|
|
78
|
+
Run only LLVM backend ('1' to enable).
|
|
79
|
+
WASM_ONLY
|
|
80
|
+
Run only WebAssembly backend ('1' to enable).
|
|
81
|
+
ARM64_ONLY
|
|
82
|
+
Run only ARM64 backend ('1' to enable).
|
|
83
|
+
BACKENDS_ONLY
|
|
84
|
+
Skip JS and kVM interpreter baselines ('1' to enable).
|
|
85
|
+
VALUES
|
|
86
|
+
Comma-separated float values to benchmark
|
|
87
|
+
(default: 0.5,-4,0,Infinity,-Infinity,NaN).
|
|
88
|
+
ITERATIONS
|
|
89
|
+
Measured iterations per benchmark (default: 3).
|
|
90
|
+
ARM64_WARMUP_ITERATIONS
|
|
91
|
+
Warmup iterations for ARM64 backend (default: 1).
|
|
92
|
+
ARM64_OPT
|
|
93
|
+
ARM64 backend optimization flags (default: -O2).
|
|
94
|
+
ARM64_SPAWN_PER_CALL
|
|
95
|
+
Spawn process per ARM64 call instead of persistent ('1' or '0').
|
|
96
|
+
ARM64_PIPELINE
|
|
97
|
+
Use persistent pipelined runner for ARM64 ('1' or '0').
|
|
98
|
+
LLVM_WARMUP_ITERATIONS
|
|
99
|
+
Warmup iterations for LLVM backend (default: 1).
|
|
100
|
+
LLVM_SPAWN_PER_CALL
|
|
101
|
+
Spawn process per LLVM call instead of persistent ('1' or '0').
|
|
102
|
+
LLVM_PIPELINE
|
|
103
|
+
Use persistent pipelined runner for LLVM ('1' or '0').
|
|
104
|
+
LLVM_OPTS
|
|
105
|
+
Comma-separated Clang optimization levels for LLVM.
|
|
106
|
+
K_LLVM_IEEE_RUNTIME_MODE
|
|
107
|
+
LLVM runtime compilation mode for IEEE (default: fast).
|
|
108
|
+
K_LLVM_IEEE_CLANG_OPT
|
|
109
|
+
Clang optimization levels for IEEE LLVM (default: -O1).
|
|
110
|
+
K_LLVM_CACHE_DIR
|
|
111
|
+
Directory to cache compiled LLVM executable binaries.
|
|
112
|
+
PERF_FULL
|
|
113
|
+
Set to '1' to test multiple LLVM optimization levels
|
|
114
|
+
(-O0, -O1, -O2).
|
|
115
|
+
WASM_WARMUP_ITERATIONS
|
|
116
|
+
Warmup iterations for WebAssembly backend (default: 10).
|
|
117
|
+
WASM_RESET
|
|
118
|
+
Reset WebAssembly memory between iterations (default: 1).
|
|
119
|
+
WASM_PIPE
|
|
120
|
+
Use persistent subprocess for Wasm (default: 1, '0': in-process).
|
|
121
|
+
WASM_IN_PROCESS
|
|
122
|
+
Run WebAssembly in-process ('1' to enable).`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (process.argv.includes("-h") || process.argv.includes("--help")) {
|
|
126
|
+
printHelp();
|
|
127
|
+
process.exit(0);
|
|
128
|
+
}
|
|
129
|
+
|
|
55
130
|
// Backend selection
|
|
56
131
|
const backendsEnv = process.env.BACKENDS?.toLowerCase();
|
|
57
132
|
const llvmOnly = process.env.LLVM_ONLY === "1" || backendsEnv === "llvm";
|
package/scripts/perf-int.mjs
CHANGED
|
@@ -56,6 +56,73 @@ import {
|
|
|
56
56
|
import { compileARM64ArtifactFromObject } from "../backends/arm64/src/arm64.mjs";
|
|
57
57
|
import { compileWasmArtifactFromObject } from "../backends/wasm/src/wasm.mjs";
|
|
58
58
|
|
|
59
|
+
function printHelp() {
|
|
60
|
+
console.log(`Usage: node scripts/perf-int.mjs [options]
|
|
61
|
+
|
|
62
|
+
Big Integer Arithmetic Performance Benchmark Harness.
|
|
63
|
+
Benchmarks plus, minus, times, and squaring scale on arithmetics.k
|
|
64
|
+
across Native JS, kVM interpreter, LLVM, Wasm, and ARM64 backends.
|
|
65
|
+
|
|
66
|
+
Options:
|
|
67
|
+
--wasm-in-process
|
|
68
|
+
Run WebAssembly in-process instead of persistent subprocess runner.
|
|
69
|
+
-h, --help
|
|
70
|
+
Show this help message and exit.
|
|
71
|
+
|
|
72
|
+
Environment Variables:
|
|
73
|
+
BACKENDS
|
|
74
|
+
Target backend to run: 'llvm', 'wasm', or 'arm64'.
|
|
75
|
+
LLVM_ONLY
|
|
76
|
+
Run only LLVM backend ('1' to enable).
|
|
77
|
+
WASM_ONLY
|
|
78
|
+
Run only WebAssembly backend ('1' to enable).
|
|
79
|
+
ARM64_ONLY
|
|
80
|
+
Run only ARM64 backend ('1' to enable).
|
|
81
|
+
BACKENDS_ONLY
|
|
82
|
+
Skip JS and kVM interpreter baselines ('1' to enable).
|
|
83
|
+
INPUTS
|
|
84
|
+
Comma-separated integer strings to benchmark.
|
|
85
|
+
ITERATIONS
|
|
86
|
+
Measured iterations per benchmark (default: 3).
|
|
87
|
+
ARM64_WARMUP_ITERATIONS
|
|
88
|
+
Warmup iterations for ARM64 backend (default: 1).
|
|
89
|
+
ARM64_OPT
|
|
90
|
+
ARM64 backend optimization flags (default: -O2).
|
|
91
|
+
ARM64_SPAWN_PER_CALL
|
|
92
|
+
Spawn process per ARM64 call instead of persistent ('1' or '0').
|
|
93
|
+
ARM64_PIPELINE
|
|
94
|
+
Use persistent pipelined runner for ARM64 ('1' or '0').
|
|
95
|
+
LLVM_WARMUP_ITERATIONS
|
|
96
|
+
Warmup iterations for LLVM backend (default: 1).
|
|
97
|
+
LLVM_SPAWN_PER_CALL
|
|
98
|
+
Spawn process per LLVM call instead of persistent ('1' or '0').
|
|
99
|
+
LLVM_PIPELINE
|
|
100
|
+
Use persistent pipelined runner for LLVM ('1' or '0').
|
|
101
|
+
K_LLVM_CACHE_DIR
|
|
102
|
+
Directory to cache compiled LLVM executable binaries.
|
|
103
|
+
WASM_WARMUP_ITERATIONS
|
|
104
|
+
Warmup iterations for WebAssembly backend (default: 3).
|
|
105
|
+
WASM_RESET
|
|
106
|
+
Reset WebAssembly memory between iterations (default: 1).
|
|
107
|
+
WASM_PIPE
|
|
108
|
+
Use persistent subprocess for Wasm (default: 1, '0': in-process).
|
|
109
|
+
WASM_IN_PROCESS
|
|
110
|
+
Run WebAssembly in-process ('1' to enable).
|
|
111
|
+
SQUARING_INPUT
|
|
112
|
+
Initial integer for squaring benchmark (default: 987654321).
|
|
113
|
+
SQUARING_STEPS
|
|
114
|
+
Number of squaring steps (default: 10).
|
|
115
|
+
SQUARING_STEP_TIMEOUT_MS
|
|
116
|
+
Timeout per squaring step in milliseconds (default: 60000).
|
|
117
|
+
K_ARENA_CAPACITY_MB
|
|
118
|
+
Memory arena capacity in MB (default: 4096).`);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (process.argv.includes("-h") || process.argv.includes("--help")) {
|
|
122
|
+
printHelp();
|
|
123
|
+
process.exit(0);
|
|
124
|
+
}
|
|
125
|
+
|
|
59
126
|
// Backend selection
|
|
60
127
|
const backendsEnv = process.env.BACKENDS?.toLowerCase();
|
|
61
128
|
const llvmOnly = process.env.LLVM_ONLY === "1" || backendsEnv === "llvm";
|