mirror of
https://github.com/juanjiant-bit/JIANT.git
synced 2026-12-06 12:54:29 +01:00
Technique from JIANT BYTE byte-cpu-light (devcpu2/devcpu3, commits 6892b2b6..212c8772): the FM-1's time a block
goes by the distinct 32-byte lines of the flash the sound reads (~1.25 us each; the 32 KiB I-cache shared by both
cores and the UI), plus its instructions.
- tools/build.py audio_map: every build writes tools/audio_map.txt (each device function's size, section, address
taken, calls through a register, callees).
- tests/cpu_lines_test.{c,py}, cpu_lines_lk.c: the model on the host (built -fno-inline, valgrind lackey: each
block's lines a core and a part; callgrind: the calls; the device's split replayed). Scenes: GEN songs 101..105
(101 with CLOUD, the delay and the chorus) and 0c, SAVE > TOOLS 6 CPU TEST's song. CL_TOP=N lists the dearest
functions. Not a CI gate yet (FM's worst GEN block is over 65 %): numbers only.
- fx.c: CPU_LINES_PART marks around a part's block (nothing on the device: the same image) and, on the model's host,
mix_part_m0 a function of its own as on the FM-1.
- tools/build.py check: each RAM code call's reach from its own address (BYTE's devcpu3).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
97 lines
4.6 KiB
C
97 lines
4.6 KiB
C
/* SPDX-License-Identifier: GPL-3.0-only
|
|
* Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant) */
|
|
/* (V10.8.60, technique from JIANT BYTE byte-cpu-light) the scenes of the lines model (tests/cpu_lines_test.py): the
|
|
* FM-1's time follows the 32-byte lines of the flash the sound reads each block (code and constants), core by core, more
|
|
* than its instructions. Run under valgrind's lackey: each block of the scene between two stores to cl_mark, core 1's
|
|
* work (mc_job) between two to cl_c1, each part (fx.c mix_part_t) between two to cl_part[k].
|
|
* cpu_lines_test SCENE NBLK (SCENE hex: 101 GEN EXPLORE s123 ENERGY 85 with CLOUD, the delay and the chorus;
|
|
* 102 .. 105 other GEN songs; 0c SAVE > TOOLS 6 CPU TEST's song (TRACKS 4))
|
|
* CL_COST="c0,..,c5,fx" (us): each part's cost as the FM-1 measures it (mc_tk, mc_fx_tk), for the device's split */
|
|
#include <stdint.h>
|
|
#define UI_TEST_NO_MAIN 1
|
|
#define MC_HOST_ASYNC
|
|
static int cl_mc_run(void (*f)(uint32_t), uint32_t a);
|
|
#define mc_run(f, a) cl_mc_run(f, a)
|
|
#define mc_wait() 0
|
|
#define HOST_LIFE 0
|
|
volatile int cl_mark, cl_c1, cl_ex, cl_part[8];
|
|
#define CPU_LINES_PART(i, v) (cl_part[(i) & 7u] = (v))
|
|
#include "ui_test.c"
|
|
static __attribute__((noinline)) void core1_run(void (*f)(uint32_t), uint32_t a) { f(a); __asm__ volatile(""); }
|
|
static int cl_mc_run(void (*f)(uint32_t), uint32_t a)
|
|
{
|
|
if (!mc_host) return 0;
|
|
mc_host_cpu = 1;
|
|
cl_c1 = 1;
|
|
core1_run(f, a);
|
|
cl_c1 = 2;
|
|
mc_host_cpu = 0;
|
|
return 1;
|
|
}
|
|
static int32_t vo[2 * CTL];
|
|
static uint32_t blk;
|
|
static void move(void) /* the matrix's sources moving: the macros, AT, MODW */
|
|
{
|
|
uint32_t k, ph = blk++;
|
|
for (k = 0; k < NTRK; k++) { trk[k].at = (uint8_t)((ph * 5u + k * 17u) % 128u); trk[k].mw = (uint8_t)((ph * 2u) % 128u); }
|
|
}
|
|
static uint32_t cl_cost[NTRK + 1u], cl_cost_on;
|
|
static void cost_in(void) /* (the device's split: what each part took, as it measures it) */
|
|
{
|
|
uint32_t k;
|
|
if (!cl_cost_on) return;
|
|
for (k = 0; k < NTRK; k++) mc_tk[k] = cl_cost[k];
|
|
mc_fx_tk = cl_cost[NTRK];
|
|
}
|
|
static uint32_t scene(uint32_t mask, uint32_t nblk)
|
|
{
|
|
uint32_t b, q, f = 0, h = 2166136261u;
|
|
blk = 0;
|
|
ui_power_on(); go_home(); frames(4);
|
|
if (mask >= 0x100u) { /* GEN songs, TRACKS 6 */
|
|
static const struct { uint8_t g; uint16_t s; uint8_t e; int8_t m; } GS[6] = {
|
|
{0, 123, 85, 0}, {0, 123, 85, 0}, {0, 7, 90, 50}, {7, 42, 85, 0}, {12, 2024, 85, 50}, {0, 999, 100, 0}};
|
|
uint32_t k, gi = (mask & 0xFFu) < 6u ? mask & 0xFFu : 0u;
|
|
ui_rec_prefs |= PREF_SIX >> 8; rp_apply();
|
|
gp.genre = GS[gi].g ? GS[gi].g : GEN_EXPLORE; gp.seed = GS[gi].s; gp.energy = GS[gi].e; gp.form = 1;
|
|
grd.mood = GS[gi].m;
|
|
gp.complex = 70; gp.swing = GA_AUTO; gp.human = 30;
|
|
for (k = 0; k < GP_N; k++) gp.amt[k] = GA_AUTO;
|
|
gen_go();
|
|
if (mask == 0x101u) { song.g[G_RTYPE] = 4; song.g[G_DFDBK] = 70;
|
|
for (k = 0; k < NTRK; k++) { trk[k].p[P_DLY] = 70; trk[k].p[P_REV] = 80; trk[k].p[P_CHOR] = 70; } }
|
|
} else { /* SAVE > TOOLS 6 CPU TEST's song, TRACKS 4 (the device's measure) */
|
|
ui_rec_prefs &= (uint8_t)~(PREF_SIX >> 8); rp_apply();
|
|
cpu_test_song();
|
|
}
|
|
song.master_q12 = 4096;
|
|
if (live.mode) chain_play_ui(); else transport_req = 1;
|
|
ui_input();
|
|
for (b = 0; b < 400u + nblk; b++) { /* (its first 400 blocks to warm: the song under way) */
|
|
if (b % 23u == 0u) { f++; ui_input(); song_poll(); host_ticks += 1000000u / 30u; fm1_ms += 1000u / 30u; }
|
|
move();
|
|
cost_in();
|
|
if (b >= 400u) cl_mark = 1;
|
|
mix_block(vo, CTL);
|
|
if (b >= 400u) cl_mark = 2;
|
|
for (q = 0; q < 2u * CTL; q++) h = (h ^ (uint32_t)vo[q]) * 16777619u;
|
|
}
|
|
(void)f;
|
|
return h;
|
|
}
|
|
int main(int argc, char **argv)
|
|
{
|
|
uint32_t m = argc > 1 ? strtoul(argv[1], 0, 16) : 0x101u, nblk = argc > 2 ? strtoul(argv[2], 0, 10) : 16u, h, k;
|
|
mc_host = 1; /* (two cores: core 1's job at once, between cl_c1's stores) */
|
|
if (getenv("CL_COST")) {
|
|
char *p = getenv("CL_COST");
|
|
cl_cost_on = 1;
|
|
for (k = 0; k <= NTRK && *p; k++) { cl_cost[k] = strtoul(p, &p, 10); if (*p == ',') p++; }
|
|
}
|
|
h = scene(m, nblk);
|
|
printf("cpu_lines: scene %03x hash %08x voices", m, h);
|
|
for (k = 0; k < NTRK; k++) { uint32_t i, n = 0; for (i = 0; i < NVOICE; i++) n += trk[k].v[i].active != 0; printf(" %u", n); }
|
|
printf("\n");
|
|
return 0;
|
|
}
|