Skip to content
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

Fix lem build in Makefile #353

Merged
merged 2 commits into from
Dec 19, 2023
Merged

Conversation

Alasdair
Copy link
Collaborator

'class' is a reserved keyword in lem, so the use of class as a variable name was causing issues. While ultimately this should be fixed in Sail this can easily be worked around here.

Fortunately the code in questions was always using a pattern like

let class = f(x);
let y = match class {
  ...
};
y

which can be simplified to

match f(x) {
  ...
}

So I didn't have to invent a new variable name, and got to make the code simpler in the process!

Fixing this unfortunately causes some other issues to become apparent. The machine words library can't handle the large vlenmax, so we have to create a separate file with a smaller vlenmax for the theorem provers. There were also some other issues, so I switched out the default representation to bitlists until they can be resolved, and cleaned up some legacy cruft in handwritten_support while I was there.

The rmem target has similar issues, but as this is only really useful for rmem maintainers it doesn't make sense to run by default, so I removed it from the default set of targets.

This should fix #325

@Alasdair
Copy link
Collaborator Author

I split the commits so the actual model changes are in the first commit (which are all small refactorings).

The second commit contains all the lem hackery to fix the build

Copy link

Unit Test Results

712 tests  ±0   712 ✔️ ±0   0s ⏱️ ±0s
    6 suites ±0       0 💤 ±0 
    1 files   ±0       0 ±0 

Results for commit 17a6c93. ± Comparison against base commit 9f4cad6.

@billmcspadden-riscv billmcspadden-riscv self-assigned this Nov 29, 2023
Copy link
Collaborator

@billmcspadden-riscv billmcspadden-riscv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My review is mainly questions. I don't see anything wrong in the code and will approve the PR once the questions are answered.

One exception: the 'effects' of certain functions need to be removed, yes?

Unable to comment on lem code due to lack of knowledge.

@@ -184,15 +185,7 @@ C_LIBS += $(SAIL_LIB_DIR)/coverage/libsail_coverage.a -lm -lpthread -ldl
endif

RISCV_EXTRAS_LEM_FILES = riscv_extras.lem mem_metadata.lem riscv_extras_fdext.lem
# Feature detect if we are on the latest development version of Sail
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the check of the Sail version removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a check for a version of Sail that is many years old, and no longer works with the model.

@@ -976,8 +976,7 @@ function rsqrt7 (v, sub) = {

val riscv_f16Rsqrte7 : (bits_rm, bits_H) -> (bits_fflags, bits_H) effect {rreg}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove effect throughout.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines are not part of this PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are seeing them just because this PR was opened before my other PR removing the effects separately was merged.

@@ -1006,14 +1003,12 @@ function riscv_f32Rsqrte7 (rm, v) = {
0x0080 => (zeros(5), 0x00000000),
0x0020 => (zeros(5), rsqrt7(v, true)[31 .. 0]),
_ => (zeros(5), rsqrt7(v, false)[31 .. 0])
};
(fflags, result)
}
}

val riscv_f64Rsqrte7 : (bits_rm, bits_D) -> (bits_fflags, bits_D) effect {rreg}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove effect

@@ -988,14 +987,12 @@ function riscv_f16Rsqrte7 (rm, v) = {
0x0080 => (zeros(5), 0x0000),
0x0020 => (zeros(5), rsqrt7(v, true)[15 .. 0]),
_ => (zeros(5), rsqrt7(v, false)[15 .. 0])
};
(fflags, result)
}
}

val riscv_f32Rsqrte7 : (bits_rm, bits_S) -> (bits_fflags, bits_S) effect {rreg}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove effect.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this part of this PR? Seems like an orthogonal addition.

Copy link
Collaborator Author

@Alasdair Alasdair Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two reasons the lem build fails. First, the use of class as an identifier, and second that the vlenmax is much too high. To make the lem build work we need a smaller vlenmax.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we would be able to disable V, but the extension is too intertwined into the base model right now to have a sail-riscv model without V, so having a shorter vlenmax is the best we can do.

@jrtc27
Copy link
Collaborator

jrtc27 commented Dec 6, 2023

Merge branch 'master' into class_fix

Please rebase rather than merge to keep the history untangled

@Alasdair
Copy link
Collaborator Author

Alasdair commented Dec 6, 2023

Merge branch 'master' into class_fix

Please rebase rather than merge to keep the history untangled

Sorry, I didn't realise the github update branch button did a merge by default. I'll fix it.

class is a reserved keyword in lem, so the use of class as a variable
name was causing issues. While ultimately this should be fixed in Sail
this can easily be worked around here.

Fortunately the code in questions was ultimately using a pattern like

let class = f(x);
let y = match class {
  ...
};
y

which can be simplified to

match f(x) {
  ...
}

removing the variable entirely, and making the code simpler so a
win-win overall!
Copy link

github-actions bot commented Dec 6, 2023

Test Results

712 tests  ±0   712 ✔️ ±0   0s ⏱️ ±0s
    6 suites ±0       0 💤 ±0 
    1 files   ±0       0 ±0 

Results for commit 2f3dc1c. ± Comparison against base commit 393e7ed.

♻️ This comment has been updated with latest results.

@bacam
Copy link
Collaborator

bacam commented Dec 7, 2023

For what it's worth, I've got development versions of Lem and Sail to handle the model with vectors and machine words, but I think the switch to bitlists by default is worthwhile because it's a little more robust. However, this does mean that the vlenmax change is unnecessary, so I suggest dropping that.

Switch to bitlist representation because the machine words
can't handle the vector code currently

Remove RMEM target from default set of targets in Makefile.
This is only interesting for RMEM maintainers. There's no reason for it
to be generated by default, and it's also broken.

While we are hacking on these files purge the duplicate versions for Sail 0.11+
@Alasdair
Copy link
Collaborator Author

Alasdair commented Dec 7, 2023

Ok, the additional vlen file is gone and it seems to build fine.

@Alasdair
Copy link
Collaborator Author

I think more people are running into this issue, would be good to get this merged I think

@billmcspadden-riscv
Copy link
Collaborator

billmcspadden-riscv commented Dec 19, 2023 via email

@billmcspadden-riscv billmcspadden-riscv merged commit d7a3d80 into riscv:master Dec 19, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fail to run 'make' for sail-riscv
4 participants