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

Dummy atomic support #92

Merged
merged 4 commits into from
Jun 13, 2024
Merged

Conversation

XuJiandong
Copy link
Collaborator

@XuJiandong XuJiandong commented Jun 5, 2024

Some Rust code can be compiled into atomic instructions for the RISC-V
target. However, these atomic instructions are not supported on ckb-vm. To
address this issue, this module has been introduced.

This module provides a Rust dummy atomic implementation inspired by
xxuejie/lib-dummy-atomics.

When the RISC-V atomic extension is disabled by specifying the
target-feature=-a flag, LLVM will attempt to link the atomic operations to
functions prefixed with __atomic in this module. For more details, refer
to the LLVM Atomics Documentation.

On the CKB-VM, only a single thread is present, making dummy atomic
operations sufficient for its purposes.

make some crates(like bytes, log) work on ckb-vm
Copy link
Collaborator

@xxuejie xxuejie left a comment

Choose a reason for hiding this comment

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

First of all, the feature name atomic is far too generic, dummy-atomic or single-core-atomic might be better. To me it makes sense to be clear that we are not building an atomic solution, but a placeholder for single core environment.

And I recommend making atomic a riscv-only feature, either by tweaking Cargo file, or adding some guards in build.rs. It really does not make sense to enable atomic for other architectures. Or we can simply make atomic a no-op for other architectures.

Finally, by restricting this feature to riscv only, we don't need to do read_unaligned / write_unaligned, we can just use the aligned version(which would make no different in ckb-vm's implementation) for less cycle consumption.

@XuJiandong XuJiandong changed the title Atomic support Dummy atomic support Jun 6, 2024
* feature name changed to `dummy-atomic`
* feature `dummy-atomic` can't be used on non risc-v target
* use read/write instead of read_unaligned/write_unaligned
README.md Outdated
@@ -15,7 +15,7 @@ This library contains several modules that help you write CKB contract with Rust
* `debug!` macro: a `println!` like macro helps debugging
* `entry!` macro: defines contract entry point
* `default_alloc!` macro: defines global allocator for no-std rust

* `atomic` module: atomic operations
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please update the note here.

@XuJiandong XuJiandong merged commit da5a078 into nervosnetwork:master Jun 13, 2024
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.

None yet

2 participants