-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add RISC-V Assembly (RISCV64) #199
Comments
Amazing! Sounds like we already have testing figured out, but feel free to indicate whether there's anything the community could assist with. |
No, I haven't figured out the testing yet. I've only confirmed Cgreen compiles in RISCV64. I'm hoping we can test with something like: as solution.s -o solution.o
gcc \
solution.o \
solution_tests.c \
codewars_reporter.o \
tests.c \
-lcgreen \
-o tests
./tests with #include <cgreen/cgreen.h>
TestSuite *solution_tests(); // defined in `solution_tests.c`
int main(int argc, char **argv) {
TestSuite *suite = create_test_suite();
add_suite(suite, solution_tests());
return run_test_suite(suite, create_codewars_reporter()); // use our reporter
} We need to define Maybe you can play with the test framework and see how it works. |
Created a repository https://github.com/DonaldKellett/codewars-riscv64 to experiment with RISCV64 support |
@kazk Initial support for Codewars output format has been added, feel free to take a look. I've also added basic examples of a syntax error and invalid register name. |
Can you prefix all the commands with printf("\n<DESCRIBE::>%s\n", name); This way, the outputs from the solution without trailing Also, you need to replace all
We should skip the outermost You can test how the output is rendered with Kumite.
print("""
<DESCRIBE::>solution_tests
<IT::>works_for_some_fixed_tests
a = 3, b = 5
<FAILED::>Expected [multiply(3, 5)] to [equal] [15]
actual value: [8]
expected value: [15]
<COMPLETEDIN::>
<COMPLETEDIN::>
""") |
@kazk Done, please review |
For the CodeMirror mode, we can probably re-use syntax highlighting for NASM. For the icon, maybe we can use an uncolored version of https://antmicro.com/images/03-06-01-riscv-hero.svg , perhaps without the "RISC-V" at the bottom? |
Nitpicks: char buf[2];
buf[1] = '\0';
while (*message) {
if (*message == '\n') { // <- add `{`
strcat(escaped_message, CODEWARS_LF);
} else {
// instead of `sprintf(buf, "%c", *message);`
buf[0] = *message;
strcat(escaped_message, buf);
}
++message;
} Also, why Can you try adding durations? I'd use https://github.com/cgreen-devs/cgreen/blob/master/src/cdash_reporter.c as a reference. Looks like the reporter can have a |
For CodeMirror mode, I don't think reusing NASM mode will work.
It shouldn't be difficult to create one. |
It's the counterpart to
Thanks, I'll change it shortly.
Thanks for the feedback, I'll look into them shortly. |
Yeah, it's just confusing. Even if that's likely to happen, I don't think it's necessary because it's an internal function only used once. Let's keep it simple and just call |
CodeMirror has a GAS mode for syntax highlighting that I suspect is directly applicable to RISC-V assembly once we define the architecture-dependent registers, since we use the GNU toolchain to assemble the solution and compile the tests: https://github.com/codemirror/codemirror5/blob/master/mode/gas/gas.js If so, I'll skip creating my own repo and demo. Valid register names in RISC-V can be found at https://en.wikichip.org/wiki/risc-v/registers |
Can you transfer the repo again? The link expired. For CodeMirror mode, are you planning to contribute upstream to add By the way, I'm thinking of using language id |
@kazk Noted, I have re-initiated the transfer.
Sure, I'll try to look into it over the next few days, perhaps tonight. I guess we can wait about a week after that, and if the PR isn't yet accepted (or gets rejected) by then, I'll consider creating my own repo with the changes.
Sounds fine by me. |
It might be easier to just create a new mode. It's not difficult. Also, GAS mode requires passing options like: const editor = CodeMirror.fromTextArea(code, {
mode: {name: "gas", architecture: "riscv"},
}); which will require some changes to Codewars' codebase. |
Can you add an example with preloaded? |
Failing tests have exit code Unless I'm misunderstanding, |
Found the cause. The reporter's I'll also look into avoid spamming |
Sure, I'll open a PR tonight if time allows. |
Do we want preloaded in C? |
Yes, we do, for the following reasons:
I'll also address some of the points mentioned in the linked issue thread:
Unless I'm terribly mistaken, placing the / a reference solution in Preloaded is just wrong and definitely a Kata issue since the solver can access and invoke it directly as long as they know the name(s) of the function(s) involved, bypassing the Kata. So this point is moot. Preloaded should only be used for additional boilerplate common to both sample and submission tests, or helper functions fully intended to be utilized by the solver.
Having the sample / submission tests in the same language as the solution is also standard practice on CW, but there are exceptions sometimes because it's simply not possible to use the same language across solution and tests (e.g. SQL with tests in Ruby, BF with tests in JS), or doing so will degrade the experience for Kata authors and translators (e.g. NASM with tests in C). So I don't see why we shouldn't make similar exceptions for preloaded code which the solver does not control.
I fail to see how having tests in C preclude preloaded code from being written in C. If the argument is that all C-related boilerplate for assertions can be simply placed directly in the sample / submission tests, I mentioned above that it could be useful to place them once in Preloaded instead so they can be reused by both sample and submission tests, instead of copy-pasting the same thing twice between sample and submission tests.
Now this seems a bit interesting. But (1) concatenating Preloaded with the solver's solution often creates more problems than it solves, such as making it harder to determine where the error is when there is a bug in the solution (or whether the bug is in the solution at all), and (2) I suppose this (concatenating preloaded code with the solution) precludes assembly-level macros(?) from being used in the sample / submission tests, and one important use case of preloaded code is to share testing-related boilerplate code between sample and submission tests. |
Yeah, preloaded shouldn't be where you put the reference solution in any language. I get that it's annoying to write a reference solution twice, but that shouldn't be the reason to make preloaded code assembly. I also don't want to concatenate because we know it'll be confusing for solvers. @error256 @nomennescio What do you think? We can also decide this later like NASM. |
I still don't like non-self-sufficient sample tests, maybe except some special cases. So the question is if there are more useful applications of preloaded in asm that those special cases for preloaded in C. I haven't looked at the RISC-V environment yet, so I'm not really sure. |
Fair point, but if there's common boilerplate for tests placed in the Preloaded section that shouldn't actually be hidden from the solver other than to avoid cluttering the sample tests, it's possible to replicate the Preloaded section in the Kata description, perhaps under a collapsible section, such that the solver can replicate the entire Kata setup locally. Since we don't (yet) have Preloaded support in NASM either and it hasn't caused us any major issues so far, I say we can postpone the decision for RISC-V as well. |
I decided to create a new RISC-V mode for CodeMirror using the simple mode. https://github.com/codewars/codemirror-riscv/blob/main/riscv.js Demo at https://codewars.github.io/codemirror-riscv The runner has been ready, so I'll try to enable it on Codewars over the weekend or next week. |
Deployed. |
Can we get some extra extensions like vector, bit-manipulation and scalar crypto enabled? It seems that for user-mode emulation setting I roughly checked https://gitlab.com/qemu-project/qemu/-/blob/master/target/riscv/cpu.c and it seems that passing argument Though it seems that the crypto ones ( I've written a kumite that should work (at least compile fine (at least should fail with a different message)) if the changes above are implemented: https://www.codewars.com/kumite/635ac4a48f20014af2cf522e |
@dramforever Can you open a new issue to track this? The image is maintained at https://github.com/codewars/riscv if you want to experiment with. |
We should be able to support by creating a container image for
linux/riscv64
with:Running
Running it with QEMU emulation (the host must have
/proc/sys/fs/binfmt_misc/qemu-riscv64
enabled).Testing
Unfortunately, Criterion doesn't support RISC-V (dependencies fails to compile with invalid architecture). Found Cgreen which compiles, runs test in separate process, and supports custom reporter.
👍 reaction might help to get this request prioritized.
The text was updated successfully, but these errors were encountered: