bytecodealliance / bytecodealliance/regalloc2

Replace scratch register with XOR swap

オープン
#206 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Rust
スター
265
フォーク
53
PR マージ指標
30日以内にマージされた PR はありません

説明

I'm getting up to snuff on compiler backend details for a personal project and the `regalloc2` overview and the [follow on article](https://cfallin.org/blog/2022/06/09/cranelift-regalloc2/) have been great.

I'm not going to pretend to completely understand the details here, but the `MachineEnv` requires a scratch register for what I gather is typically swaps, symbolically like this.
```rs
let x = 4;
let y = 5;

let swap = x;
x = y;
y = swap;
```
However there is a way to swap two values without introducing a third variable/register which is via an [XOR swap](https://en.wikipedia.org/wiki/XOR_swap_algorithm):
```rs
x = y ^ x;
y = x ^ y;
x = y ^ x;
```
You shouldn't do this in high level code but should be fine in machine code of course. If an ISA allows integer operations to be applied to float registers then this can be used for both classes.

I'm nearly certain you know of this already, but I wanted to get it out there for the off chance, and if nothing else get details on why it wouldn't work.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。