-
Notifications
You must be signed in to change notification settings - Fork 5
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 C example, handwritten example, and generic tester #5
base: master
Are you sure you want to change the base?
Conversation
|
||
i64 reverse_bytes(i64 a){ | ||
i64 b = 0; | ||
b += (a & 0xff00000000000000)>>56; |
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.
Replace +=
with |=
and magic happens: https://godbolt.org/z/GYL1L0
Unfortunately, wasm does not have bswap support.
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.
Cool!
But Wasm has no bswap opcode. I would have to look at the output wasm, but don't think there is a difference since addition + and or | both use the ALU in one cycle.
|
||
// call function based on selector value | ||
switch (*selector) { | ||
case 0x1a029399: |
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'm curious, why are the selector values here different from those in the example pseudo-code for this repository?
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 think that you are referring to the wrc20 spec https://gist.github.com/axic/16158c5c88fbc7b1d09dfa8c658bc363 where the selector has value 0x9993021a
. The selector here is reversed because callDataCopy()
puts the call data into wasm memory, and Wasm reverses the bytes when it loads/stores memory to the stack. I could have also done reverse_bytes()
on selector and used the same selector byte-ordering as the wrc20 spec.
Please do not merge yet. I am not sure that people want source code in this repo. It may be better to just have a spec, a tester, and links to implementations. Any thoughts? In this PR, wrc20.c, the tester, and the handwritten examples now live in the C_ewasm_contracts repo. So I think that this PR should be closed, and another one opened with just the tester. |
.PHONY: all | ||
|
||
#LLVM_BUILD_DIR=/path/to/llvm-build | ||
LLVM_BUILD_DIR=/home/user/repos/benchmarking/wasmception/build/llvm |
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 believe the upstream LLVM has wasm target enabled by default. How do you want to handle the LLVM installation?
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.
This PR is old and outdated. I don't want this repo to include the wrc20.c code anymore. I think that this PR should be closed, but am waiting for feedback before I close.
This is a great question which I need advice for in the current wrc20.c repo https://github.com/poemm/C_ewasm_contracts . It is good that newer version of ubuntu have LLVM 8+ by default. But getting LLVM 8+ may be a challenge for some users. The linked repo gives instructions in the README and compilation commands in the Makefile, but, in my experience, I have had to restart the compilation several times before it finished. Maybe this conversation should be moved to that repo, but I am happy to continue here.
Ideally we can ditch These are much more concise and human-readable than state tests. Current limitations of Truffle revolve around Here's what I've done so far to the C contract to reflect the issues I just mentioned: https://github.com/ewasm/wrc20-examples/pull/8/files#diff-cce65dd672810c34ebe43a8482583861 |
No description provided.