-
Notifications
You must be signed in to change notification settings - Fork 2
iss: Implement PC annotations [current], [next] and [next next] #951
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
Draft
BadGraphixD
wants to merge
2
commits into
master
Choose a base branch
from
feature/pc-annotations
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // SPDX-FileCopyrightText : © 2026 TU Wien <vadl@tuwien.ac.at> | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| package vadl.viam.annotations; | ||
|
|
||
| import vadl.viam.Annotation; | ||
| import vadl.viam.RegisterTensor; | ||
|
|
||
| /** | ||
| * Annotation for offsetting read pc values by one or two instruction | ||
| * lengths. Can be overwritten by {@link vadl.viam.passes.pcOffset.nodes.PcOffsetNode}. | ||
| * | ||
| * <p>The offset is applied by {@link vadl.viam.passes.pcOffset.PcOffsetPass}. | ||
| */ | ||
| public class PcOffsetAnnotation extends Annotation<RegisterTensor> { | ||
|
|
||
| public PcOffsetAnnotation(int offset) { | ||
| this.offset = offset; | ||
| } | ||
|
|
||
| private final int offset; | ||
|
|
||
| @Override | ||
| public Class<RegisterTensor> parentDefinitionClass() { | ||
| return RegisterTensor.class; | ||
| } | ||
|
|
||
| /** | ||
| * The offset in instructions lengths that is added. | ||
| */ | ||
| public int offset() { | ||
| return offset; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // SPDX-FileCopyrightText : © 2026 TU Wien <vadl@tuwien.ac.at> | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| package vadl.viam.passes.pcOffset; | ||
|
|
||
| import java.io.IOException; | ||
| import javax.annotation.Nullable; | ||
| import vadl.configuration.GeneralConfiguration; | ||
| import vadl.pass.Pass; | ||
| import vadl.pass.PassName; | ||
| import vadl.pass.PassResults; | ||
| import vadl.types.BuiltInTable; | ||
| import vadl.utils.GraphUtils; | ||
| import vadl.utils.ViamUtils; | ||
| import vadl.viam.Instruction; | ||
| import vadl.viam.Specification; | ||
| import vadl.viam.annotations.PcOffsetAnnotation; | ||
| import vadl.viam.graph.Graph; | ||
| import vadl.viam.graph.dependency.BuiltInCall; | ||
| import vadl.viam.graph.dependency.ReadResourceNode; | ||
|
|
||
| /** | ||
| * Applies program counter offsets to program counter reads. | ||
| * | ||
| * <p>When reading a program counter that has been annotated with | ||
| * {@code [current]}, {@code [next]} or {@code [next next]} or when using | ||
| * one of the subcalls {@code .current}, {@code .next} or {@code .nextnext}, | ||
| * the read value is offset by multiples of the instruction length. The subcalls | ||
| * overwrite the annotations. | ||
| * | ||
| * <p>This pass looks for {@link PcOffsetAnnotation}s and checks | ||
| * {@link ReadResourceNode#pcOffset()} and applies them by inserting addition nodes. | ||
| */ | ||
| public class PcOffsetPass extends Pass { | ||
|
|
||
| public PcOffsetPass(GeneralConfiguration configuration) { | ||
| super(configuration); | ||
| } | ||
|
|
||
| @Override | ||
| public PassName getName() { | ||
| return new PassName("PC Offset Pass"); | ||
| } | ||
|
|
||
| @Override | ||
| public @Nullable Object execute(PassResults passResults, Specification viam) | ||
| throws IOException { | ||
| ViamUtils.findAllBehaviors(viam).forEach(this::handleBehaviour); | ||
| return null; | ||
| } | ||
|
|
||
| private void handleBehaviour(Graph behaviour) { | ||
| // FIXME: are instruction lengths always multiples of 8? | ||
| // What if the pc does not counter per byte? | ||
| // FIXME: What instruction length should be used in behaviours outside | ||
| // instructions (eg in functions)? | ||
| int instrBytes = behaviour.parentDefinition() instanceof Instruction instruction | ||
| ? instruction.format().type().bitWidth() / 8 | ||
| : 32; | ||
|
|
||
| behaviour.getNodes(ReadResourceNode.class) | ||
| .forEach(n -> handleRead(n, instrBytes)); | ||
| } | ||
|
|
||
| private void handleRead(ReadResourceNode read, int instrBytes) { | ||
| var offsetAnn = read.resourceDefinition().annotation(PcOffsetAnnotation.class); | ||
| var regOffset = offsetAnn == null ? 0 : offsetAnn.offset(); | ||
| var readOffset = read.pcOffset(); | ||
| int offset = readOffset != null ? readOffset : regOffset; | ||
|
|
||
| if (offset != 0) { | ||
| read.replace(BuiltInCall.of( | ||
| BuiltInTable.ADD, read, | ||
| GraphUtils.intUNode((long) offset * instrBytes, read.type().bitWidth()) | ||
| )); | ||
| } | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
vadl/test/resources/testSource/passes/pcOffset/valid_pc_alias_ann_current.vadl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
|
|
||
| instruction set architecture PcTest = { | ||
| using Regs = Bits<32> | ||
|
|
||
| register A: Regs | ||
| [ current ] | ||
| alias program counter PC: Regs = A | ||
|
|
||
| instruction READ_PC: F = A := PC | ||
|
|
||
| encoding READ_PC = { I = 2 } | ||
| assembly READ_PC = "Test" | ||
|
|
||
| format F: Regs = { | ||
| I: Regs | ||
| } | ||
| } | ||
|
|
||
| processor TEST implements PcTest = {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
praise: Awesome, thank you :)