---
title: "Contributing support for a Wasm instruction to Winch"
description: "Adding a WebAssembly instruction to Winch, Wasmtime's baseline non-optimizing compiler, touches several layers: the wasmparser VisitOperator visitor, the CodeGenContext that manages the value stack, register allocation and spilling, an ISA-independent MacroAssembler, and an x86_64 assembler built on Cranelift's ISLE-generated instruction definitions."
url: "https://swe.quest/articles/contributing-support-for-a-wasm-instruction-to-winch-3a4d14391ef1d680"
canonical: "https://shopify.engineering/contributing-support-for-a-wasm-instruction-to-winch"
source: "Shopify Engineering"
published: "2023-07-18"
difficulty: "hard"
kind: "How-to"
reading_minutes: 9
tags: ["webassembly","compilers","rust","testing","open-source"]
---

# Contributing support for a Wasm instruction to Winch

A post on [Shopify Engineering](https://swe.quest/sources/shopify.md), published 2023-07-18, 9 min read, How-to. Original: [https://shopify.engineering/contributing-support-for-a-wasm-instruction-to-winch](https://shopify.engineering/contributing-support-for-a-wasm-instruction-to-winch)

## Summary

Adding a WebAssembly instruction to Winch, Wasmtime's baseline non-optimizing compiler, touches several layers: the wasmparser VisitOperator visitor, the CodeGenContext that manages the value stack, register allocation and spilling, an ISA-independent MacroAssembler, and an x86\_64 assembler built on Cranelift's ISLE-generated instruction definitions. The i32.clz example shows how the MacroAssembler emits lzcnt when the CPU supports it and otherwise falls back to a bsr/setne sequence. Changes are tested in two ways: filetests check the emitted machine code without running it, so they work on AArch64 Macs, and differential fuzzing on x86\_64 hardware compares Winch's results against another Wasm engine.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [WebAssembly](https://swe.quest/tags/webassembly.md) (Languages)
- [Compilers](https://swe.quest/tags/compilers.md) (Compilers & runtimes)
- [Rust](https://swe.quest/tags/rust.md) (Languages)
- [Testing](https://swe.quest/tags/testing.md) (Engineering practices)
- [Open source](https://swe.quest/tags/open-source.md) (Engineering practices)

## Prerequisites

- WebAssembly stack machine basics ([easy posts on WebAssembly](https://swe.quest/tags/webassembly.md?difficulty=easy))
- x86\_64 assembly
- Rust ([easy posts on Rust](https://swe.quest/tags/rust.md?difficulty=easy))
- register allocation basics

## Keywords

Winch, Wasmtime, Cranelift, ISLE, wasmparser, x86\_64, differential fuzzing

## Related posts

- [Speculative Optimizations for WebAssembly using Deopts and Inlining](https://swe.quest/articles/speculative-optimizations-for-webassembly-using-deopts-and-inlining-bb89e7c53ac7945f.md): V8 · 2025-06-24 · Hard · 17 min read · WebAssembly, Compilers, Runtimes & VMs, Performance engineering
  V8 in Chrome M137 adds speculative call\_indirect inlining and deoptimization support for WebAssembly, using runtime call-target feedback gathered by the Liftoff baseline compiler so TurboFan can inline up to four likely callees behind cheap instance and target checks.
- [Extensible Language Support in Zed - Part 1](https://swe.quest/articles/extensible-language-support-in-zed-part-1-13bc037c6f5096a9.md): Zed · 2024-04-18 · Medium · 7 min read · WebAssembly, Developer tools, Sandboxing & isolation, Compilers, Rust
  Zed loads third-party Tree-sitter grammars as WebAssembly modules using a hybrid design.
- [Introducing the JetStream 3 Benchmark Suite](https://swe.quest/articles/introducing-the-jetstream-3-benchmark-suite-df1c85fb12e2a75d.md): WebKit · 2026-03-31 · Hard · 21 min read · Runtimes & VMs, WebAssembly, Compilers, Memory management, Performance engineering
  JetStream 3 replaces JetStream 2's separate Wasm Startup/Runtime scores with the JavaScript-style first-iteration, worst-case and average-case scoring.
- [Four Approaches to Debugging Server-side WebAssembly](https://swe.quest/articles/four-approaches-to-debugging-server-side-webassembly-70e30fb86ae05146.md): Shopify Engineering · 2022-09-07 · Medium · 8 min read · WebAssembly, Debugging, Developer tools, Rust
  Step-debugging server-side WebAssembly can be done four ways: compiling to a native target and using LLDB/GDB, running the Wasm under Wasmtime inside LLDB, using a Wasm-specific debugger like Wasminspect, or using browser DevTools via Chrome's DWARF extension or source maps.
- [C ABI Changes for \`wasm32-unknown-unknown\` | Rust Blog](https://swe.quest/articles/c-abi-changes-for-wasm32-unknown-unknown-rust-blog-cc1b5edcd4664f9f.md): Rust Blog · Medium · 8 min read · Rust, WebAssembly, Compilers
  Rust is switching the \`extern "C"\` ABI on \`wasm32-unknown-unknown\` from a legacy non-standard definition to the WebAssembly tool-conventions C ABI, which changes generated binaries.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
