Ticket #725 (closed patch: wontfix)

Opened 13 years ago

Last modified 13 years ago

[PATCH] Add c-level branch prediction annotations

Reported by: Infinoid Owned by:
Priority: normal Milestone:
Component: none Version: 1.2.0
Severity: medium Keywords:
Cc: Language:
Patch status: new Platform:

Description

Gcc allows you to tell the optimizer which path of a branch is more likely. The Linux kernel uses this heavily, through the use of the likely() and unlikely() macros.

This patch adds these to parrot, and starts using them in a few places.

I intend to update this patch to add more annotations; I have callgrind data from a non-optimized parrot, but I need to re-analyze it for an optimized parrot. (non-optimized GCC doesn't make use of the annotations, and optimized GCC generates code which looks quite a bit different.)

The first rev of this patch already seems to make about half a second of difference. It's not huge, but it is measurable. Before:

./perl6 -e 'my $i = 0; while ( $i < 100000) { $i++ }'  39.32s user 1.39s system 99% cpu 40.933 total
./perl6 -e 'my $i = 0; while ( $i < 100000) { $i++ }'  39.20s user 1.46s system 99% cpu 40.991 total
./perl6 -e 'my $i = 0; while ( $i < 100000) { $i++ }'  39.08s user 1.41s system 99% cpu 40.766 total
./perl6 -e 'my $i = 0; while ( $i < 100000) { $i++ }'  38.69s user 1.42s system 99% cpu 40.250 total
./perl6 -e 'my $i = 0; while ( $i < 100000) { $i++ }'  39.25s user 1.38s system 98% cpu 41.148 total

After:

./perl6 -e 'my $i = 0; while ( $i < 100000) { $i++ }'  38.54s user 1.40s system 99% cpu 40.211 total
./perl6 -e 'my $i = 0; while ( $i < 100000) { $i++ }'  37.98s user 1.49s system 98% cpu 40.193 total
./perl6 -e 'my $i = 0; while ( $i < 100000) { $i++ }'  38.57s user 1.46s system 99% cpu 40.349 total
./perl6 -e 'my $i = 0; while ( $i < 100000) { $i++ }'  39.16s user 1.33s system 99% cpu 40.864 total
./perl6 -e 'my $i = 0; while ( $i < 100000) { $i++ }'  37.91s user 1.53s system 98% cpu 40.064 total

I believe we can improve this further, by making heavier use of it. This will take some work to find these cases, though. Any case where you see a branch in callgrind which hits 6 million times and misses 3 times (or less), or vice versa, could use one of these annotations.

Attachments

add-branch-prediction-annotations.patch Download (3.0 KB) - added by Infinoid 13 years ago.

Change History

Changed 13 years ago by Infinoid

Changed 13 years ago by Infinoid

  • status changed from new to closed
  • resolution set to wontfix

I spent some more time working on this, for very little gain. Don't bother applying this; it makes the code uglier and doesn't make enough of a difference to measure. Rejecting ticket.

Note: See TracTickets for help on using tickets.