Layered Software Architecture & Zero Copy 2 MiB WB Arena
From pure x86_64 assembly control register bootstrap to the quantized Unnamed model forward pass, the entire Almandine OS stack links into a single freestanding PE32+ image with zero dynamic heap fragmentation or page table churn.
Unnamed model Transformer Forward Pass & Interactive REPL
Streams GGUF v3 payloads from NVMe or GPT Partition 2 in 16 MiB chunks, binds tensors zero copy in RAM, runs SentencePiece longest match BPE tokenization, and executes RMSNorm, per head Q/K/V Norm, RoPE, Grouped Query Attention (GQA), GeGLU FFN, and logit softcapping (softcap · tanh(logit / softcap)).
8 P Core Q4_K_M × Q8_K Matrix Vector Dispatcher
Links upstream ggml-cpu (arch/x86/quants.c) directly into BOOTX64.EFI. Initializes hardware F16C lookup tables, quantizes FP32 activations into block_q8_K once on the BSP, and partitions Q4_K_M weight rows across 8 physical P cores on 16 row (64 byte cache line) boundaries.
UEFI Orchestrator, Lock Free MP Spin Pool & Freestanding Libc/Libm
Disables the 5 minute UEFI watchdog, calibrates the CPU TSC, binds USB/PS2 keyboards recursively via ConnectController, wakes APs via EFI_MP_SERVICES_PROTOCOL, parks E cores, and manages the 2 MiB aligned Write Back page arena and hardware SIMD math primitives (expf, sqrtf, tanhf).
Pre C Control Register Unlock & KVM Guarded Intel HWP MSRs
Executes at /entry:efi_start and ap_asm_trampoline before any C function prologue can emit VEX encoded instructions. Unlocks CR0.MP, CR4.OSFXSR, CR4.OSXSAVE, and XCR0 = 0x07 (256 bit YMM0 to YMM15), inspects CPUID.1AH hybrid core types, and programs High Performance hardware P-States via Intel HWP Speed Shift MSRs.
Physical RAM: 2 MiB Aligned Write Back Arena (g_arena_base)
Allocated via BS->AllocatePages(EfiLoaderData) • 64 Byte & 4 KiB Aligned
- 64 MiB (4 × 16 MiB) AVX2 streaming pipeline verification buffers
- UEFI
EFI_BLOCK_IO_PROTOCOLsector probe buffer (0x46554747 "GGUF"magic scan)
- GGUF Header + KV Metadata + Vocabulary Strings (zero copy string refs)
token_embd.weight(GGML_TYPE_Q4_K): direct pointer ing_modelblk.0..N.attn_*&blk.0..N.ffn_*(Q4_K/F32): 32 byte aligned tensor dataoutput_norm.weight(F32) +output.weight(Q4_K)
k_cache: [n_layer][MAX_SEQ_LEN][n_head_kv * head_dim](FP32 contiguous)v_cache: [n_layer][MAX_SEQ_LEN][n_head_kv * head_dim](FP32 contiguous)
x_cur,x_norm,attn_out [n_embd]&q_buf,k_buf,v_bufffn_gate_buf,ffn_up_buf [n_ff](GeGLU intermediate states)work_q8 [max_dim / 256](block_q8_Kquantized activation vector)logits [n_vocab](FP32 softcapped output distribution)
Intel Core i9 & Xeon Bare Metal Silicon Engineering
Without a Linux kernel, UEFI leaves CR4.OSXSAVE = 0, clocks pinned to base BIOS ratios, and hybrid E cores competing for package TDP. Almandine OS configures the processor's SIMD vector registers, hybrid topology, and autonomous Power Control Unit directly in Ring 0.
1. Pre C Assembly AVX2 Bootstrap
CR4.OSXSAVE • XCR0=0x07
When compiled with -march=x86-64-v3 -mavx2, Clang emits VEX encoded vmovups/vxorps instructions inside C function prologues. Because UEFI boots with CR4.OSXSAVE = 0 (0x00000668), calling any C function immediately triggers an Invalid Opcode (#UD, Exception 6) crash. Almandine OS solves this in pure assembly (efi_start and ap_asm_trampoline) before jumping to C.
2. AVX VNNI & Dual Port FMA3 Compute
VPDPBUSD • VFMADD231PS
Each Raptor Cove P core features two 256 bit FMA execution units on Ports 0 & 1 (32 FP32 FLOPs/cycle/core, >1.3 TFLOPS theoretical across 8 P cores). For quantized Q4_K_M × Q8_K dot products, AVX VNNI fuses 32 lane unsigned 8 × signed 8 multiply accumulate into a single vpdpbusd instruction, replacing the 3 instruction AVX2 sequence and avoiding 16 bit saturation.
3. KVM Guarded Intel HWP Speed Shift
MSR 0x1A0 → 0x770 → 0x774
Without an OS scheduler timer, legacy ACPI P states leave the CPU stuck at base clock. cpu_init.S checks CPUID.01H:ECX[31] (skipping MSR writes inside QEMU/KVM to prevent #GP(0) faults) and programs High Performance hardware P-States with EPP = 0x00 and Max = 0xFF so the on die PCU microcontroller scales P cores to full turbo boost in <1 ms.
4. Hybrid P Core Pinning & E Core Parking
CPUID.1AH • 0x40 vs 0x20
On the 24 core (32 thread) Core i9 13980HX, 8 Raptor Cove P cores and 16 Gracemont E cores share a single package power budget (PL1/PL2). mp_dispatch.c inspects CPUID.1AH:EAX[31:24], enrolls only the 8 physical P cores (0x40), and parks all 16 E cores (0x20) and SMT siblings in hardware HLT sleep so 100% of TDP feeds AVX2 compute.
Bare Metal Hardware Bottlenecks & Ring 0 Mitigations
Source: docs/performance_issues.md| Subsystem | Firmware / Hardware Pitfall | Untuned Penalty | Almandine OS Ring 0 Resolution |
|---|---|---|---|
| 1. MTRR / PAT Caching | Buggy laptop BIOSes leave upper physical RAM (>4 GiB) Uncached (UC, 0x00) in Variable MTRRs |
10× to 80× slower | Audit MSR 0x2FF (IA32_MTRR_DEF_TYPE) & MSR 0x277 (IA32_PAT); enforce Write Back (WB, 0x06) on all RAM across BSP & 7 APs |
| 2. Package Power (PL1/PL2) | Pre OS Embedded Controller clamps MSR_PKG_POWER_LIMIT (0x610) to 35W to 45W |
25% to 45% slower | Read MSR 0x606 units; if PKG_LOCK (bit 63) is clear, program MSR 0x610 to PL1 = 115W / PL2 = 157W |
| 3. L2 / DCU Prefetchers | BIOS leaves hardware stream prefetchers disabled in MSR 0x1A4 |
15% to 30% slower | Clear bits 0..3 of MSR_MISC_FEATURE_CONTROL (0x1A4) on all 8 P cores to prefetch 256 weight Q4_K_M super blocks |
| 4. DTLB Thrashing | 4 KiB pages across a ~16 GB model overflow the 2048 entry L2 STLB (covers only 8 MiB) | 8% to 15% slower | Coalesce CR3 page tables covering g_arena_base into 2 MiB (PS=1) or 1 GiB hugepages |
| 5. Cache Line False Sharing | Adjacent P cores writing to the same 64 byte output line during mul_mat |
5% to 12% slower | Partition per core output row ranges (ir0..ir1) on 16 float (64 byte) cache line boundaries |
| 6. UEFI DXE Timer Jitter | UEFI background timer interrupts stalling the 8 core barrier mid token | 2% to 5% jitter | Mask interrupts (cli/sti) on BSP during mp_parallel_for and transition to ExitBootServices() |