bytecodealliance / bytecodealliance/regalloc2

Replace scratch register with XOR swap

未关闭
#206 2 条评论 0 个 reaction 已指派 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.

贡献指南

这个仓库没有索引到贡献指南

调研方向

首先审查 MachineEnv 的 scratch-register 要求,以及链接的 regalloc2 概览和后续文章。确定 XOR swaps 对相关的寄存器类别和 ISA 是否有效,以及它们是否能保持 allocator 所要求的行为。只有在对是否应以此替换 scratch-register swaps 得出具体且有文档记录的决定后,才算完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
rust
领域
compilers
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。