Git Product home page Git Product logo

Comments (3)

joboet avatar joboet commented on July 1, 2024

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.

linkmauve avatar linkmauve commented on July 1, 2024

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.

tylanphear avatar tylanphear commented on July 1, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.