Skip to content
A jigsaw of white pieces with a single golden piece dropped into place.

One loop. Every core, every GPU.

Heterogeneous data-parallel programming. Write an ordinary loop in xc or C, and xcc runs it across every CPU core, on the GPU through Metal, CUDA, Vulkan or WebGPU, across several GPUs at once, or on a GPU on another machine, then keeps whichever is fastest.
#import "Stdio.xc"
#define W 4096
#define H 4096
float pixels[W * H];
i32 main(void)
{
for (u32 i in 0..W * H)
pixels[i] = (float)(i % 251) / 250.0;
// An ordinary loop. Its iterations are independent, so xcc makes it a
// par block: every CPU core, the GPU, or both, whichever is faster.
for (u32 i in 0..W * H)
pixels[i] = pixels[i] * pixels[i] * 0.8 + 0.1;
Stdio.printf("%f\n", pixels[12345]);
return 0;
}

xcc -O3 -o brighten brighten.xc is the whole build. There are no kernels to write, no device code, no annotations and no separate build for the GPU. xcc finds the loops whose iterations are independent and compiles each one for the CPU’s threads and vector units and for every GPU back end. The program measures the devices on the machine it runs on and keeps the fastest choice for later runs. A loop can also ask for this itself, as a par block with reductions, grids and a choice of device.

Every figure is measured with the released compiler on machines you can buy, and the sources are published.

21× faster on the GPU

md5 on an Apple M3 Max runs 21 times faster on its GPU than on all sixteen CPU cores, from the same plain loop. GPU results →

Plain C, 2.1× faster than OpenMP

Unchanged C files built by xcc, on all 32 threads of a Ryzen 9 9955HX, against GCC with a hand-written #pragma omp parallel for (3.0× against clang), as a geometric mean. C results →

GPUs from different vendors, together

One block is cut into tiles and run on an NVIDIA RTX 5080 through CUDA and an RTX 3090 through Vulkan at once, with the CPU taking tiles too. Parallel blocks →

A GPU on another machine

xcd serves a machine’s GPUs to programs elsewhere on the network: mandel_deep runs about ten times faster from a Raspberry Pi 5 on a remote RTX 5080 than on the Pi’s own CPU and GPU. Networked results →

The CPU code is fast too. On one thread xc is ahead of C++ built by clang (1.13× on an M3 Max, 1.10× on a Ryzen 9 9955HX), and of C++ built by GCC, Objective-C and Swift, as a geometric mean over the CPU benchmarks.

One executable carries code for the CPU and kernels for every GPU API, and decides at run time which of the devices it finds to use.

  • GPUs: Metal on Apple silicon; CUDA on NVIDIA GPUs under Windows and Linux; Vulkan on Linux, Windows, Android and the Raspberry Pi 5; WebGPU in a browser.
  • CPUs: arm64 macOS and Linux, x86-64 Linux and Windows, with the vector units (NEON, SME, AVX2 and AVX-512) used where the machine has them.
  • The browser: WebAssembly, with WebGPU for par blocks.

The native targets assemble and link in-house: xcc carries its own assemblers, linkers and executable writers, so a build needs no system toolchain.

xcc also compiles C. It reads a .c file through clang’s front end and generates the code itself, through the same optimiser and the same parallel runtime, so an existing C loop gets the CPU’s threads and the GPU with no change to the source. See C programs.

xc is a typed, class-based language that stays close to C: classes with inheritance and protocols, automatic reference counting with weak references, closures and bound methods, checked errors, typed collections, threads and a Foundation-style standard library, with C’s syntax, C’s types and inline assembly. The compiler is self-hosting: xcc is written in xc.

xc is developed in the open on GitHub, at github.com/ThrudTheBarbarian/xc: the compiler, the runtime, the standard library, the benchmarks and these pages. The compiler is GPLv3, and the programs you compile with it are yours, with no obligation of any kind (licensing). Issues and pull requests are welcome; Contributing says how.

The same compiler and standard library also reach much smaller machines: the Motorola 68000, 32-bit ARM, and a banked 6502 whose code and data the compiler spreads across paged memory windows. xc started there, and every target still passes the full test corpus. See the targets.

Parallel blocks

How a loop becomes a par block: reductions, grids, choosing a device, and running on several devices at once.

Read about par →

Using the compiler

Installing, the xcc flags, C programs, environment variables and the networked daemon.

See compiler usage →

Downloads

macOS, Linux (x86-64 and arm64), Windows, and the xcd daemon.

Get xcc →