Comments (3)
The operation is not actually the same. The behaviour of the u128
version is different from the custom version when bits
is more than 64, as it correctly shifts bits from the upper 64 bits into the lower ones, whereas in the custom version, you get some very weird behaviour.
from rust.
This function is always inlined in functions where num_bits
is way less than 64, usually at most 4, and codegen actually gets worse when I add assert!(num_bits < 64);
. I would expect the compiler to be able to optimize based on the constant the function gets called with, since it is always known at compile time.
from rust.
@linkmauve at least for obvious examples where n_bits
is a compile-time constant, it does appear that the compiler avoids cmov
sequences when it can also prove n_bits < 64
. Even where it is not known at compile-time, if you explicitly mask n_bits
by 63, this also allows it to avoid cmov
sequences (godbolt).
The fact that assert!()
doesn't help here is unfortunate (I even tried using unreachable_unchecked()
to force the generation of a llvm.assume
but that also didn't help) -- most likely there is room for improvement in LLVM's lowering of shr
on types with bitwidth > 64.
from rust.
Related Issues (20)
- I didnt change anything :( HOT 2
- ICE: hit debug-assertions assertion `left == right` failed in compiler/rustc_middle/src/hir/map/mod.rs HOT 5
- std::env::args_os always returns an empty iterator in a musl+gcompat environment HOT 13
- Change SwitchTarget (in TerminatorKind::SwitchInt) to use ScalarInt
- Suggest declaring module when trying to use it
- Colored stack traces HOT 10
- Track implementation for MC/DC HOT 18
- Lints stop firing if macro reports with `Span::call_site`? HOT 4
- Miscompilation due to MatchBranchSimplification MIR pass mixing up discriminants HOT 13
- ICE: `tried to combine ConstKind::Infer/ConstKind::Infer(InferConst::Var)` HOT 1
- Documentation for abs() on signed integers doesn't mention unsigned_abs() HOT 1
- Allowlist for SanitizerCoverage
- ICW when Unknown MIR dialect: ' ' HOT 1
- something is weird about llvm submodule handling HOT 4
- ICE: assertion `left == right` failed at `rustc_const_eval/src/interpret/validity.rs` HOT 4
- generic_const_exprs and inline_const interact poorly. HOT 2
- ICE: inference variables in normalized parameter environment: unconstrained type HOT 2
- testing `cg_gcc` is difficult HOT 30
- ICE on stable due to messed up target/ directory HOT 6
- Unheplful Borrow Error Related to Use of Borrows in Loop
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust.