[Mesa-dev] [PATCH 3/4] radeonsi: add more unlikely() uses into si_draw_vbo

Gustaw Smolarczyk wielkiegie at gmail.com
Tue Sep 6 07:54:54 UTC 2016


2016-09-06 3:56 GMT+02:00 Ilia Mirkin <imirkin at alum.mit.edu>:
> On Mon, Sep 5, 2016 at 9:54 PM, Michel Dänzer <michel at daenzer.net> wrote:
>> On 06/09/16 07:46 AM, Marek Olšák wrote:
>>> From: Marek Olšák <marek.olsak at amd.com>
>>
>> Did you measure any significant performance boost with this change?
>> Otherwise, using (un)likely can be bad because it can defeat the CPU's
>> branch prediction, which tends to be pretty good these days.
>
> Is there a way to affect the branch predictor on x86 with instruction
> encodings? I didn't think so. I was under the impression that all
> likely/unlikely did was to affect placement of the code, i.e. where
> the "if" code was placed.

If I may add to the discussion: there was a way to add branch
prediction hints to the instruction encoding (using x86 prefixes that
were to be ignored according to ISA), which was used by NetBurst
architecture (Pentium 4). It is no longer recognized by any modern
architecture and AFAIK compilers will not generate code that uses
them.

The compiler should be able to do two things using the (un)likely
hints (there might be more tricks I am not aware of):
1. Make the likely branch not jump. When the CPU executes a jump
without any branch prediction data cached for it, it assumes that it
doesn't jump.
2. Move the unlikely parts of code outside of a function or to the end
of a function. That increases instruction cache and fetch usage for
likely code.

In the end, it would be best to measure the performance of the (un)likely hints.

Regards,
Gustaw Smolarczyk

>
>   -ilia
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list