Fetch and Add

The fetch-and-add instruction increments the contents of a memory location by a specified value. This is a translation of a C++ fetch add from Godbolt. This operation is normally used in concurrency. More information on this can be found at: Fetch-and-Add

// fetch and add.
fetch_and_add :: (val: *int) #expand {
  #asm {
    mov incr: gpr, 1;
    xadd.q [val], incr;
  }
}

global_variable: int;
fetch_and_add(*global_variable);