-
Notifications
You must be signed in to change notification settings - Fork 13
Heuristically choose and preserve rdx across mulx #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
d6f0538
b92a58c
b9608a0
ca9a928
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -463,6 +463,9 @@ export class RegisterAllocator { | |
| const caf = (flagToCheck: AllocationFlags): boolean => | ||
| ((allocationReq.allocationFlags ?? AllocationFlags.NONE) & flagToCheck) === flagToCheck; | ||
| const inAllocationsTemp = allocationReq.in.map((readVariable) => { | ||
| const currentLocation = this._allocations[readVariable]; | ||
| if (currentLocation && isRegister(currentLocation.store)) return currentLocation.store; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need this condition up here?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So instead of mov rdx, [rsi]
mulx r8 , r9, [rsi]it will now emit mov rdx, [rsi]
mulx r8 , r9, rdx?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then I'd like to write a test case for that.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No wait. This would be a square operation, which is handled differently anyway. mov rax, [rsi]
...
mulx r8 , r9, raxinstead of mov rax, [rsi]
...
mulx r8 , r9, [rsi] |
||
|
|
||
| const argMatchRes = matchArg(readVariable); | ||
| if (argMatchRes) { | ||
| // if we read from an argument such as arg1[3], we actually want to find arg1 in the allocations. | ||
|
|
@@ -474,7 +477,6 @@ export class RegisterAllocator { | |
| throw new Error(`${readVariable} matched ~arg, but has no baseVar? wtf. Giving up.`); | ||
| } | ||
| } | ||
| const currentLocation = this._allocations[readVariable]; | ||
| if (!currentLocation) { | ||
| // if is it not already allocated, it must be an immval, cause 'arg1' is always somewhere | ||
| if (caf(AllocationFlags.DISALLOW_IMM)) { | ||
|
|
@@ -593,7 +595,7 @@ export class RegisterAllocator { | |
| } | ||
| } | ||
|
|
||
| if (caf(AllocationFlags.ONE_IN_MUST_BE_IN_RDX) && !inAllocations.includes(Register.rdx)) { | ||
| if (caf(AllocationFlags.ONE_IN_MUST_BE_IN_RDX) && !allocationReq.in.some((i) => this._allocations[i].store === Register.rdx)) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we check
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not remember for sure, but I think it was a difference between
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thing is, I could see this working but also failing. |
||
| // since in inAllocations there is no rdx (otherwise we wont be in this branch) | ||
| // we need to move one of inAllocations to rdx | ||
|
|
||
|
|
@@ -605,8 +607,17 @@ export class RegisterAllocator { | |
|
|
||
| // we want now change any of those inAllocations with rdx. | ||
|
|
||
| // Paul chooses an element, which we'll move to rdx. | ||
| const element = Paul.chooseArg(allocationReq.in); | ||
| // try to be sophisticated in choosing the mulx Load value | ||
| const { msg, candidate } = Model.chooseMulxLoadValue(allocationReq.in); | ||
| this.addToPreInstructions(msg); | ||
| let element = ""; | ||
| if (candidate != null) { | ||
| element = candidate; | ||
| } else { | ||
| // if this didn't work (none is clearly preferrable) | ||
| // let Paul choose an element, which we'll move to rdx. | ||
| element = Paul.chooseArg(allocationReq.in); | ||
| } | ||
| const idx = allocationReq.in.indexOf(element); | ||
| //TODO: refactor that a lil bit | ||
|
|
||
|
|
@@ -1500,7 +1511,9 @@ export class RegisterAllocator { | |
| Object.keys(this._allocations) | ||
| .filter(matchArg) | ||
| .forEach((v) => { | ||
| delete this._allocations[v]; | ||
| if (isMem(this._allocations[v].store)) { | ||
|
dderjoel marked this conversation as resolved.
|
||
| delete this._allocations[v]; | ||
| } | ||
| }); | ||
|
|
||
| // empty and get current pres | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not understand why this is necessary. Are we checking if a value is in an register and a memory location at the same time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not understand why the entire conditional is necessary, but without the
&&the assertion failed with all my other changes. I believe the old conditional asks whether the variable is an input-array cell, and the new conditional asks whether it is stored in memory. The difference would be an input variable that is cached in a register, for examplerdx.