diff options
Diffstat (limited to 'anim/tools')
| -rw-r--r-- | anim/tools/bench.zig | 66 | ||||
| -rw-r--r-- | anim/tools/chart.py | 16 | ||||
| -rw-r--r-- | anim/tools/overflow.c | 10 |
3 files changed, 92 insertions, 0 deletions
diff --git a/anim/tools/bench.zig b/anim/tools/bench.zig index ad6fe4b..020a259 100644 --- a/anim/tools/bench.zig +++ b/anim/tools/bench.zig @@ -32,9 +32,75 @@ fn steps(rec: *canim.Recording, by: canim.Recording.Stop, function: ?[]const u8) } } +/// `bench relations`: the relations' passes on tables of a working frame's +/// size and of a map's (design/README.md, "4. Ties", "Cost": some 4,000 +/// places and 6,000 values), against the table they replace (a list +/// searched from the start for each lookup, so a join is places times values). +fn relationsCost(gpa: std.mem.Allocator) !void { + const rel = canim.relations; + std.debug.print("{s:<8} {s:>6} {s:>6} {s:>6} | {s:>10} {s:>10} {s:>10} | {s:>12}\n", .{ "tables", "places", "values", "pairs", "sort ns", "join ns", "passes ns", "old scan ns" }); + for ([_][2]usize{ .{ 300, 120 }, .{ 4000, 6000 } }, [_][]const u8{ "working", "map" }) |size, label| { + var rng: std.Random.DefaultPrng = .init(7); + const r = rng.random(); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + const rounds = 200; + var took: [4]u64 = @splat(0); + var pairs_n: usize = 0; + for (0..rounds) |_| { + _ = arena.reset(.retain_capacity); + const a = arena.allocator(); + var t: rel.Tables = .{}; + // Places: rows of code (kind 14) and words of the stack (kind 3), and some of every other kind. + for (0..size[0]) |i| { + const kind: u8 = if (i % 3 == 0) 14 else if (i % 3 == 1) 3 else @intCast(1 + r.uintLessThan(u8, 16)); + const addr: u64 = if (kind == 14) 0x401000 + 4 * @as(u64, i) else 0x7fffffffe000 + 8 * @as(u64, i); + t.add(a, .{ .key = rel.keyOf(kind, addr), .box = .{ 0, @floatFromInt(i), 880, @floatFromInt(i + 1) }, .pane = .disasm }); + } + // Values: a third of them code addresses on screen, the rest anything. + for (0..size[1]) |i| { + const v: u64 = if (i % 3 == 0) 0x401000 + 4 * r.uintLessThan(u64, size[0]) else r.int(u64); + t.show(a, .{ .value = v, .box = .{ 0, 0, 0, 0 }, .pane = .stack, .at = 0x7fffffffe000 + 8 * @as(u64, i) }); + } + var clock = rel.clock(); + const by_key = t.byKey(a); + const by_value = t.byValue(a); + took[0] += rel.clock() - clock; + clock = rel.clock(); + var pairs: std.ArrayList(rel.Pair) = .empty; + rel.join(t.values.items(.value), by_value, t.places.items(.key), by_key, 14, ~@as(u64, 0), &pairs, a); + took[1] += rel.clock() - clock; + pairs_n = pairs.items.len; + // The passes over a candidate a pair (the knob on), then cut to the budget. + clock = rel.clock(); + const cands = try a.alloc(rel.Candidate, pairs.items.len); + for (cands, pairs.items) |*c, p| c.* = .{ .kind = .code, .rank = p.value }; + var kept = rel.filter(cands, rel.Knobs.initMany(&.{ .code, .always })); + rel.byPriority(kept); + kept = rel.cut(kept); + took[2] += rel.clock() - clock; + std.mem.doNotOptimizeAway(kept.len); + // The old way: each value's lookup a scan of the places from the start. + clock = rel.clock(); + const keys = t.places.items(.key); + var found: usize = 0; + for (t.values.items(.value)) |v| { + for (keys) |key| if (key == rel.keyOf(14, v)) { + found += 1; + break; + }; + } + std.mem.doNotOptimizeAway(found); + took[3] += rel.clock() - clock; + } + std.debug.print("{s:<8} {d:>6} {d:>6} {d:>6} | {d:>10} {d:>10} {d:>10} | {d:>12}\n", .{ label, size[0], size[1], pairs_n, took[0] / rounds, took[1] / rounds, took[2] / rounds, took[3] / rounds }); + } +} + pub fn main(init: std.process.Init) !void { const gpa = init.gpa; const args = try init.minimal.args.toSlice(init.arena.allocator()); + if (args.len == 2 and std.mem.eql(u8, args[1], "relations")) return relationsCost(gpa); if (args.len >= 3) { inline for (@typeInfo(recordings).@"struct".decl_names) |name| { if (@TypeOf(@field(recordings, name)) == recordings.Program and std.mem.eql(u8, name, args[1])) diff --git a/anim/tools/chart.py b/anim/tools/chart.py index 0f2894f..aa20e43 100644 --- a/anim/tools/chart.py +++ b/anim/tools/chart.py @@ -77,6 +77,22 @@ motion.REGIONS.update({ "sqlite": {**strips(subject(17), True), **words}, "zoom": {**strips(none(9), False), **words}, "gallery": {**strips(beside(13), True), **words}, + # The pair (src/pair.zig, `split`): the source shared across both columns, then each run's disassembly, + # registers and frame as bytes on its side of the seam; no strips. ASan's stderr comes in over its + # registers and its disassembly's lower rows once it has stopped. + "asan": {"source": (64, 48, 1792, ph(5)), + "plain disasm": (64, 212, 880, ph(9)), "asan disasm": (976, 212, 880, ph(5)), + "plain registers": (64, 472, 880, ph(4)), "asan stderr": (976, 376, 880, ph(6)), + "plain frame": (64, 612, 880, ph(10)), "asan frame": (976, 612, 880, ph(10)), **words}, + # The introduction (motion.md, "A scene: the introduction"), chapter I: the address space in the + # program column, the dump in the state column (the texts beside the address space there while + # the dump is on the shelf); the camera at x2 on the dump for its first three beats. + "intro_memory": {"space": (64, 48, 880, 840), "dump": (976, 48, 880, 840), **words}, + # Chapter II: the texts on the left (the program column, empty), the registers built over the stack. + "intro_stack": {"text": (64, 48, 880, 840), "registers": (976, 48, 880, 236), "stack": (976, 296, 880, 592), **words}, + # Chapter III: the aligned panel across both columns under its text above, then the working frame + # (the nodes lens as the list scene's), then the map. + "intro_code": {"text": (64, 48, 1792, 120), "aligned": (64, 168, 1792, 720), **words}, }) # `cut`: the gallery is the catalogue's pages, cut from one to the next (scenes/gallery.zig: 3, 6, 9.6, 13, 16, # 19.8, 21 and 24 s), not a scene: a page's first frame changes everything at once by design. diff --git a/anim/tools/overflow.c b/anim/tools/overflow.c new file mode 100644 index 0000000..bbd9a73 --- /dev/null +++ b/anim/tools/overflow.c @@ -0,0 +1,10 @@ +// A loop writes 32 bytes into a 16-byte stack buffer. +__attribute__((noinline)) static void fill(void) { + char buf[16]; + for (int i = 0; i < 32; i++) buf[i] = 'A'; +} + +int main(void) { + fill(); + return 0; +} |
