AltiVec Had Intel’s Neural-Network Instruction 20 Years Early.
From the publisher’s feed, collected in the ZeroLabs newsroom.
AltiVec Had Intel’s Neural-Network Instruction 20 Years Early. On My 2004 Power Mac G5, It Makes a Language Model Seven Times Fasterllama2.c on MorphOS and Mac OS X Leopard: from 1.9 to 13.7 tokens per second on one 1.8 GHz PowerPC 970 core, 18.2 on two, and why memory bandwidth sets the limit.This article was written with the help of Claude (Anthropic), from my notes, ideas and measurements; I reviewed and edited the text. Every measurement was run on my own machines.Illustration generated with ChatGPT.In 2019 Intel added an instruction to its server CPUs for one job: multiplying 8-bit integers in groups of four and summing them into 32-bit totals. It’s part of a set Intel called VNNI, Vector Neural Network Instructions, and it’s what quantized neural networks spend most of their time doing.The PowerPC chips in Apple’s G4 and G5 Macs had that operation in 1999. AltiVec calls it vmsummbm, Vector Multiply Sum Mixed-Sign Byte Modulo. It takes 16 signed bytes and 16 unsigned bytes, multiplies them in pairs, adds the products in groups of four, and accumulates the four sums into 32-bit integers. Intel's version even keeps the odd mix of one signed and one unsigned operand. Intel itself had used that mix since SSSE3 in 2006, where the same job took three instructions; VNNI fused them into one. In 1999 the mix made sense: AltiVec was built for media work, where pixels are unsigned bytes and filter coefficients are signed, and that is most likely why the instruction looks the way it does.I have a Power Mac G5 from 2004 on my bench, and it runs MorphOS. I wanted to know how much that 1999 instruction is worth on a real language model, measured end to end on a real machine.The answer: on one core, it takes a 110-million-parameter model from 1.91 to 13.7 tokens per second. With both processors under Mac OS X Leopard it reaches 18.2. That last stretch doesn’t come from the instruction: it comes from the second processor’s memory bus, and from cutting the overhead of OpenMP itself.The machineThe G5 is a Power Mac G5 Dual 1.8 GHz from June 2004:two IBM PowerPC 970 processors at 1.8 GHz, on a 900 MHz bus;2 GB of DDR400 in four 512 MB modules;a Radeon 9600 XT with 128 MB;two 80 GB Seagate hard disks from 2004.One detail about the processors. Apple’s specifications for this model, PowerMac7,3, list the 90 nm PowerPC 970FX, but both processors in mine report PVR 0x0039 rev 2.2, the original 130 nm 970. I don’t know the machine’s history, so I report what the chips say: every figure in this article comes from the 130 nm 970.One disk has Mac OS X Leopard, the other MorphOS 3.20, released in May 2026. MorphOS is an operating system for PowerPC in the Amiga tradition. It runs AmigaOS software and is still developed. I grew up on Commodore machines, so on this Mac MorphOS is the system I boot.MorphOS sees both processors, but it runs everything on the first one. Every number in this article is from one core, except the Leopard test near the end.Who did this before meBefore writing anything I looked for prior work, and there is a fair amount.Andrew Rossignol ran llama2.c on a 2005 PowerBook G4 in March 2025. He used fp32 weights with AltiVec multiply-adds, and the 110M model went from 0.77 to 0.88 tokens per second.Alex Hoopes’s MacinAI Local (March 2026) runs 8-bit Q8_0 models with AltiVec on a 1 GHz PowerBook G4 under Mac OS 9, up to TinyLlama 1.1B with disk paging. Its 8-bit path converts the weights to float and multiplies them with vec_madd; it doesn't use vmsummbm.Scott (Scottcjn) maintains llama-cpp-tigerleopard, a llama.cpp for Mac OS X Tiger and Leopard, which reports TinyLlama 1.1B in 4-bit at 3 to 5 tokens per second on a dual 2.0 GHz G5. In a pull request to Microsoft’s BitNet, open since early 2026, he already used vmsummbm on a G5, for ternary weights against 8-bit activations. A 700M model runs at 1.4 tokens per second on one thread and 2.0 on two.llama2.c has also been ported to other PowerPC machines: the Xbox 360, the PlayStation 3 and a 1998 iMac G3. For Commodore fans, it also runs on classic 68k Amigas (Llama 2 Everywhere) and on a C64 with a RAM expansion.On IBM’s POWER servers the instruction is in production: ONNX Runtime uses it for 8-bit token generation, and llama.cpp has used its POWER10 successor, xvi8ger4, for 8-bit matrix multiplies.So I’m not the first to use vmsummbm for a language model on a G5, nor the first to run 8-bit weights with AltiVec.On MorphOS I found nothing. I searched morph.zone and Aminet: the AI software there, AmigaGPT and the newer AI4MorphOS, are clients for cloud APIs. As far as I can tell, this is the first language model running locally on MorphOS.What this article adds:as far as I can find, the first integer kernel built on vmsummbm for a Llama-architecture model on a G4 or G5;every result set against the memory bandwidth I measured on the same machine;the first language model I could find running locally on MorphOS;two-processor scaling under Leopard, measured against the bandwidth and the cost of OpenMP itself.Porting llama2.cllama2.c is Andrej Karpathy’s single-file C inference for the Llama 2 architecture. I used it with his two TinyStories models, which were trained to write short children’s stories:stories15M: 15 million parameters, 61 MB in fp32;stories110M: 110 million parameters, 438 MB in fp32.These are toy models. What they offer here is a real transformer (attention, RoPE, SwiGLU, a 32,000-token vocabulary) in a size that fits a 2004 machine.The MorphOS SDK on the G5 has GCC 6.4 from 2018. The port needed three changes:No mmap. MorphOS doesn't have it, so the program reads the whole model into a buffer aligned to 16 bytes for AltiVec loads.Big-endian. The model files are little-endian and the PowerPC is big-endian, so every 32-bit value is byte-swapped at load time.No clock_gettime. I used gettimeofday instead.To check the byte-swapping, I built the same code on my Linux PC with the swap forced on and fed it pre-swapped files. The output was byte-for-byte the same as the original program’s.Two things on the G5 cost me some time:SSH doesn’t load the SDK. MorphOS’s SSH runs one command per connection without the SDK’s environment, so I compiled through small AmigaDOS scripts copied over SFTP. Without Execute SYS:Development/Startup at the top of the script, GCC exits with code 1 and prints nothing.-mcpu=7450 switches AltiVec on. The 2018 assembler doesn't know -mcpu=970. The G4 setting -mcpu=7450 works, but it quietly enables AltiVec. My first "plain C" measurement was already vectorized. A true scalar build needs -mno-altivec.fp32: AltiVec reaches the memory wallI started with the original 32-bit floating-point weights. The AltiVec version keeps four vec_madd accumulators per row, four floats each.fp32 on one G5 core: AltiVec doubles the speed of the 110M model, to 87% of the measured memory bandwidth.To see where the limit is, I wrote a small program that reads a 256 MB buffer and timed it, keeping the best of five runs. The G5 reads memory at 2.25 GB/s with AltiVec loads and 1.90 GB/s with plain C.Generating a token means reading every weight once, so the 110M model at 4.47 tokens per second reads 1.96 GB/s. That’s 87% of what the machine can deliver. In fp32 the G5 can’t go meaningfully faster. To go faster, it has to read fewer bytes.For comparison, the G5 runs the 110M model 5.1 times faster than the PowerBook G4.int8: the instruction from 1999llama2.c also has an 8-bit version, runq.c. Weights are stored as int8 in groups of 64 (32 for the 15M model), each group with its own fp32 scale. Activations are quantized to int8 on the fly before each matrix multiply.That cuts the 110M model from 438 to 116 MB, nearly four times less to read per token. Karpathy’s export script needs PyTorch and pickled checkpoints. I wrote a small NumPy quantizer that works from the fp32 .bin instead. Its worst-case rounding error is 0.0076 for the 110M model.In plain C, int8 is slower than fp32: 1.91 tokens per second against 2.26. Without an instruction for it, every 8-bit product costs a sign extension, an integer multiply and an add. Fewer bytes don’t help when the core can’t keep up.vmsummbm fixes that, with one catch: one operand must be signed and the other unsigned, while both weights and activations are signed. I took four steps:int8 on one G5 core, step by step: the 110M model goes from 1.91 to 13.7 tokens per second.One group at a time. I flip the top bit of the activations, which adds 128 and makes them unsigned. Then I subtract 128 times the sum of the weights from each result. That sum depends only on the weights, so it could be computed once at load time, but then every group would carry it in memory, adding bytes to every token. In this version I compute it inside the inner loop instead. Even so, the 110M model goes from 1.91 to 7.77 tokens per second.Four groups at a time. Each group ends as four partial sums in a vector. Instead of reducing every group to a single number, I interleave the partial sums of four groups with vec_mergeh and vec_mergel. Then one conversion to float and one multiply by the scales handle all four groups.The rest of the forward pass. I computed RoPE’s sines and cosines once per token instead of once per layer, and vectorized the attention dot products. I also replaced the C library’s round(), which was slow here, with a version that adds 0.5 to positive values and subtracts it from negative ones, in double precision, then truncates. Double precision makes it exact on float inputs, it rounds halves away from zero exactly like round(), negative values included, and the generated text didn't change.Weights stored unsigned. I flip the top bit of the weights once, when the model is loaded. The correction then involves the sum of the activations, which is the same for every row, so it’s computed once per matrix multiply instead of once per row:// weights were stored as w+128 at load time; activations x stay signedfor (int k = 0; k acc = vec_msum(vec_ld(k, x), vec_ld(k, w), acc); // vmsummbm: 16 products// x·w = x·(w+128) − 128·Σx, and Σx is computed once per group, not once per rowThe algebra is one line. Adding 128 to every weight adds 128 times the sum of the activations to the dot product, whatever the weights are, so subtracting that sum undoes it. The correction happens per quantization group and in integers: each group’s sum is corrected first, then multiplied by that group’s two scales, one for the weights and one for the activations. The inner loop is left with two loads and one vmsummbm per 16 bytes.The trick itself isn’t new. It is the zero-point algebra that Google’s gemmlowp library documents, and llama.cpp has precomputed the activation sum the same way since 2023. What the G5 adds is that the cost of each choice shows up directly in tokens per second.The final version runs the 110M model at 13.7 tokens per second. That’s 7.2 times plain C int8, 6.1 times plain C fp32, and 3.1 times the best fp32 AltiVec version. It runs the small model at 79 tokens per second.The output didn’t change. Across every int8 version, the 110M model writes the same story to the letter. A test build compares the AltiVec matrix multiply with the plain C one on the first three matrix multiplies (768 × 768). The largest absolute difference is about 1e-7, from the order of the float additions. The integer sums can’t overflow: a group of 64 products adds up to at most 64 × 127 × 255, about 2.1 million, a thousand times below what a 32-bit integer holds, and every group starts from zero. With the prompt “Once”, the model writes:Once upon a time, there was a little girl named Lily. She loved to play outside in the sunshine. One day, she saw a big, red apple on a tree. She wanted to eat it, but it was too high up.Where the time goesI read the PowerPC’s timebase register before and after each part of the forward pass. These are the shares for the final version on the 110M model:Where the time goes in the final version (stories110M, MorphOS, one core), measured with the PowerPC timebase register.In the profiling run, the matrix multiplies read their weights at 1.94 GB/s, 86% of the measured bandwidth. If everything else took no time, 116 MB per token at 2.25 GB/s would give about 19 tokens per second. 13.7 is 71% of that ceiling.I also tried software prefetch (dcbt) and gained 1.5%, which is within noise. The core already waits on memory most of the time.The GPU and the second processorThe Radeon 9600 XT can’t help much, by my estimate (I didn’t build it).Its pixel shaders (version 2.0) have no loops, so one matrix-vector multiply becomes hundreds of rendering passes per token.The 110M model in int8 doesn’t fit in its 128 MB next to the screen.The second processor is a different matter. MorphOS doesn’t use it, but Leopard does. I rebooted the G5 into Mac OS X 10.5.8 and built the same code with Apple’s GCC 4.2 and OpenMP, which splits the rows of each matrix multiply between the two CPUs.Two processors under Leopard read 64% more than one; with fused OpenMP regions the 110M model runs 39% faster than on one CPU.Two CPUs read 64% more than one. Each 970 has its own bus to the system controller, and together they reach 3.63 GB/s.The 110M model first gained only 31%, to 17.2 tokens per second. By Amdahl’s law it should have gained 50 to 60%, because on one CPU the matrix multiplies take 85% of the time and should speed up like the bandwidth.The missing time is OpenMP itself. A loop of empty parallel regions shows that one region costs 2.6 µs with one thread and 76 µs with two, with the libgomp of Apple’s GCC 4.2. The code opened 97 regions per token, so two CPUs spent about 7 ms of every 58 just starting and stopping them.Without that cost, the matrix multiplies scale like the memory. With two CPUs the profile gives them 47.9 ms per token, against 64.8 with one. Take out the cost of their 85 regions and they run 1.56 times faster, close to the 1.64 of the bandwidth test.Fewer regions, more speed. The q, k and v projections read the same input, and so do w1 and w3, so each group can share one region: 61 regions per token instead of 97. At the measured cost that should save about 2.7 ms; the measured saving is 3.3 ms. The 110M model goes from 17.2 to 18.2 tokens per second and writes the same story. With one CPU the fusion changes nothing, as expected.The regions weigh more on the small model. Before the fusion, two CPUs ran the 15M model at 75.5 tokens per second, below MorphOS on one CPU (79.1). With fused regions they reach 84.4.With one CPU, Leopard is 4 to 17% slower than MorphOS, most likely because of its older compiler (GCC 4.2 against 6.4).So the best G5 result comes from Leopard with both processors and fused regions: 18.2 tokens per second on the 110M model, 33% faster than MorphOS on one. What’s left runs on one CPU: the activation quantization, SwiGLU, RoPE and the rest of the attention take 10 to 12 ms per token either way.In perspectiveOn one core of a 2023 Ryzen 9 7900, the same C code without my AltiVec kernels, built with plain -O3, runs the 15M model at 127 tokens per second in fp32 and 474 in int8. The G5's best figures are 28.9 and 79.1: the Ryzen core is 4.4 times faster in fp32 and 6.0 times in int8. That is a minimum, not the real gap: built this way, the Ryzen runs without AVX2 and without the VNNI instructions Zen 4 has.The int8 gap is partly the cache, not the core. In int8 the 15M model takes 17 MB, which fits in the 32 MB of L3 cache a single Ryzen core can use, so the Ryzen reads it from cache. In fp32 it takes 61 MB and doesn’t fit. The G5 has 512 KB of L2 cache and no L3, so it reads every byte from its DDR400.The models themselves are tiny. The 110M writes children’s stories, and nobody should run an assistant on a G5. What matters here is the instruction and the measurement.My previous articles ran a 125-billion-parameter model on old PCs, and the result there was the same as here: when generation is limited by memory, its ceiling is the memory bandwidth divided by the bytes each token has to read. It held on a 2013 workstation, on two PCs sharing a gigabit cable and on a 2014 Xeon, and it holds on a 2004 Power Mac.The steps are the ones every modern inference engine takes. Quantize, so each token reads fewer bytes. Then use the processor’s 8-bit dot-product instruction, so the arithmetic keeps up with the memory. On the G5, fp32 hit the bandwidth wall at 4.47 tokens per second. In int8, plain C was slower than that, and it took vmsummbm to turn a quarter of the bytes into speed: 13.7 tokens per second on one processor, 18.2 on two. Today the instruction is called VNNI on Intel and SDOT on Arm, and IBM's POWER line, where AltiVec lives on, added xvi8ger4, which still multiplies signed bytes by unsigned ones, to the matrix unit of POWER10. Memory is far faster than in 2004, but arithmetic has grown faster still, which is why the bandwidth wall matters more today, not less.MethodMachine: Power Mac G5 (PowerMac7,3, June 2004), two PowerPC 970 at 1.8 GHz (130 nm, PVR 0x0039 rev 2.2; Apple’s specifications for this model list the 90 nm 970FX), 900 MHz bus, 2 GB DDR400 (4 × 512 MB), MorphOS 3.20. MorphOS uses one processor, so all MorphOS figures are single-core; the Leopard test uses both.Compiler on MorphOS: GCC 6.4.0 from the MorphOS SDK (2018), installed on the G5, with libnix. Every build is ppc-morphos-gcc-6 -O3 -mcpu=7450 -noixemul -DSENZA_MMAP .c -lm, plus:fp32 plain C: -mno-altivec; fp32 AltiVec: -maltivec;int8 plain C: -mno-altivec; one group at a time: nothing more; four groups: -DQUATTRO; faster RoPE, rounding and attention: -DQUATTRO -DVELOCE; final version: -DVELOCE -DV3.SENZA_MMAP selects the loader without mmap and the byte swapping.Compiler on Leopard: Apple GCC 4.2.1 (build 5577) from Xcode, gcc-4.2 -O3 -mcpu=970 -maltivec -fopenmp -std=gnu99 -DSENZA_MMAP -DVELOCE -DV3 runq_leo.c -lm, with the libgomp that comes with that compiler. The fused version is runq_leo2.c with -DFONDI added.Code: llama2.c at commit 350e04f, changed by two patch scripts (fp32 run.c and int8 runq.c). The patches, the generated sources, the quantizer, the bandwidth tests, the build and measurement scripts and the raw results are on GitHub: github.com/dexmac221/g5-llama2c.Models: Karpathy’s stories15M and stories110M from Hugging Face (karpathy/tinyllamas), with SHA-256 checked. The int8 files were made with my own NumPy quantizer from the fp32 .bin, in llama2.c's Q8_0 format. Group size is 32 for the 15M model and 64 for the 110M. The largest absolute difference between a weight and its quantized value, over every quantized tensor, is 0.0023 and 0.0076.Runs: greedy decoding (-t 0), prompt "Once". Lengths: 256 tokens for the 15M model and 128 for the 110M, in both fp32 and int8. Speed is llama2.c's own "achieved tok/s", over the whole run.Repeats: every MorphOS figure is the median of three runs made in one session, with the versions interleaved; the three runs differed by 0.1 to 3.2%. Only one version didn’t reproduce across sessions: one group at a time ran at 9.14 and 37.2 tokens per second the day before, and at 7.6 to 8.1 and 29.5 to 30.3 in this session. I report this session’s runs. The other versions came within 6% of the day before.Correctness: a test build that compares the AltiVec matrix multiply with the plain C one on the first three matrix multiplies (768 × 768); the generated text compared across versions.Bandwidth: a 256 MB buffer read sequentially, best of five runs, with AltiVec loads and with plain C.Profile: the PowerPC timebase register read around each part of the forward pass.Leopard test: Mac OS X 10.5.8 on the same G5. OpenMP splits the rows of the int8 matrix multiply (my addition) and the attention heads (already in llama2.c). The fused version (-DFONDI) runs the rows of q, k and v, and of w1 and w3, in one parallel region each. The cost of a region comes from 100,000 almost empty regions over 768 rows, best of three; the per-part times come from a profiling build timed with mach_absolute_time(). Three runs per setting, which differed by less than 1%. The bandwidth test is the same 256 MB read, split between the threads.x86 reference: Ryzen 9 7900, one thread, GCC -O3, stories15M, same prompt and settings.AltiVec Had Intel’s Neural-Network Instruction 20 Years Early. was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.