News for hackers. Stuff that matters.
Re:Making the rav1d Video Decoder 1% Faster by mmastrac on Thursday May 22, 2025 @09:05AM (#44061671)
The associated issue for comparing two u16s is interesting.

https://github.com/rust-lang/rust/issues/140167

Re:Making the rav1d Video Decoder 1% Faster by heybales on Thursday May 22, 2025 @09:34AM (#44061906)
The thing I like most about this is that the discussion isn't just 14 pages of "I'm having this issue as well" and "Any updates on when this will be fixed?" As a web dev, GitHub issues kinda suck.
Re:Making the rav1d Video Decoder 1% Faster by eterm on Thursday May 22, 2025 @11:44AM (#44063190)
It was worse before emoji reactions were added and 90% of messages were literally just "+1"
Re:Making the rav1d Video Decoder 1% Faster by heybales on Thursday May 22, 2025 @01:03PM (#44064094)
+1
Re:Making the rav1d Video Decoder 1% Faster by NoMoreNicksLeft on Friday May 23, 2025 @11:43AM (#44073866)
Wonder if it's a poor interface issue... if people could just click a button that says "me too" but didn't add a full comment but rather just added some minimal notation at the bottom of the comment that indicated their username, 1) would people use it and 2) would that be not overly-busy enough to not be annoying? It could even mute notifications for the me-toos.
Re:Making the rav1d Video Decoder 1% Faster by IshKebab on Friday May 30, 2025 @05:24AM (#44134415)
This seems like an area where LLMs would actually be extremely useful. You can manually mark comments as irrelevant. Why can't GitHub use AI to do it automatically? Or to highlight the "resolution" comment automatically? On very big issues it can take a non-trivial amount of time just to find out what the outcome was.
Re:Making the rav1d Video Decoder 1% Faster by rhdjsjebshjffn on Thursday May 22, 2025 @03:36PM (#44065911)
This just seems to illustrate the complexity of compiler authorship. I am very sure c compilers are wble to address this issue any better in the general case.
Re:Making the rav1d Video Decoder 1% Faster by runevault on Thursday May 22, 2025 @03:56PM (#44066162)
Keep in mind Rust is using the same backend as one of the main C compilers, LLVM. So if it is handling it any better that means the Clang developers handle it before it even reaches the shared LLVM backend. Well, or there is something about the way Clang structures the code that catches a pattern in the backend the Rust developers do not know about.
Re:Making the rav1d Video Decoder 1% Faster by rhdjsjebshjffn on Thursday May 22, 2025 @09:27PM (#44068937)
I mean yea, i just view rust as the quality-oriented spear of western development.

Rust is absolutely an improvement over C in every way.

Re:Making the rav1d Video Decoder 1% Faster by vlovich123 on Thursday May 22, 2025 @03:59PM (#44066204)
The rust issue has people trying this with c code and the compiler generates the same issue. This will get fixed and it’ll help c and Rust code
Re:Making the rav1d Video Decoder 1% Faster by runevault on Thursday May 22, 2025 @09:34PM (#44068993)
Out of curiosity just clang or gcc as well?
Re:Making the rav1d Video Decoder 1% Faster by josephg on Friday May 23, 2025 @09:31AM (#44072736)
I just tried it, and the problem is even worse in gcc.

Given this C code:

    typedef struct { uint16_t a, b; } pair;

    int eq_copy(pair a, pair b) {
        return a.a == b.a && a.b == b.b;
    }
    int eq_ref(pair *a, pair *b) {
        return a->a == b->a && a->b == b->b;
    }
Clang generates clean code for the eq_copy variant, but complex code for the eq_ref variant. Gcc emits pretty complex code in both variants.

For example, here's eq_ref from gcc -O2:

    eq_ref:
        movzx   edx, WORD PTR [rsi]
        xor     eax, eax
        cmp     WORD PTR [rdi], dx
        je      .L9
        ret
    .L9:
        movzx   eax, WORD PTR [rsi+2]
        cmp     WORD PTR [rdi+2], ax
        sete    al
        movzx   eax, al
        ret
Have a play around: https://c.godbolt.org/z/79Eaa3jYf
Re:Making the rav1d Video Decoder 1% Faster by ack_complete on Thursday May 22, 2025 @03:46PM (#44066028)
I'm surprised there's no mention of store forwarding in that discussion. The -O3 codegen is bonkers, but the -O2 output is reasonable. In the case where one of the structs has just been computed, attempting to load it as a single 32-bit load can result in a store forwarding failure that would negate the benefit of merging the loads. In a non-inlined, non-PGO scenario the compiler doesn't have enough information to tell whether the optimization is suitable.
Re:Making the rav1d Video Decoder 1% Faster by Dylan16807 on Friday May 23, 2025 @12:42AM (#44069905)
> In the case where one of the structs has just been computed, attempting to load it as a single 32-bit load can result in a store forwarding failure that would negate the benefit of merging the loads

Would that failure be significantly worse than separate loading?

Just negating the optimization wouldn't be much reason against doing it. A single load is simpler and in the general case faster.

Re:Making the rav1d Video Decoder 1% Faster by ack_complete on Saturday May 24, 2025 @07:24PM (#44084378)
Usually, yeah, it's noticeably worse than using individual loads and stores as it adds around a dozen cycles of latency. This is usually enough for the load to light up hot in a sampling profile. It's possible for that extra latency to be hidden, but then in that case the extra loads/stores wouldn't be an issue either.
Re:Making the rav1d Video Decoder 1% Faster by mshockwave on Friday May 23, 2025 @01:08AM (#44070022)
> In the case where one of the structs has just been computed, attempting to load it as a single 32-bit load can result in a store forwarding failure

It actually depends on the uArch, Apple silicon doesn't seem to have this restriction: https://news.ycombinator.com/item?id=43888005

> In a non-inlined, non-PGO scenario the compiler doesn't have enough information to tell whether the optimization is suitable.

I guess you're talking about stores and load across function boundaries?

Trivia: X86 LLVM creates a whole Pass just to prevent this partial-store-to-load issue on Intel CPUs: https://github.com/llvm/llvm-project/blob/main/llvm/lib/Targ...