Bug 51866 - Use __builtin_expect when compiling using RVCT in GNU mode
Summary: Use __builtin_expect when compiling using RVCT in GNU mode
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: 528+ (Nightly build)
Hardware: Other Other
: P2 Normal
Assignee: Siddharth Mathur
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-03 21:14 PST by Daniel Bates
Modified: 2011-01-10 16:52 PST (History)
7 users (show)

See Also:


Attachments
Patch (1.21 KB, patch)
2011-01-03 21:20 PST, Daniel Bates
no flags Details | Formatted Diff | Diff
Exclude RVCT2.2 from using this intrinsic (1.16 KB, patch)
2011-01-10 12:08 PST, Siddharth Mathur
no flags Details | Formatted Diff | Diff
Same patch as above, but with Changelog format issue corrected. (1.16 KB, patch)
2011-01-10 12:11 PST, Siddharth Mathur
dbates: review-
dbates: commit-queue-
Details | Formatted Diff | Diff
Patch (3.42 KB, patch)
2011-01-10 15:37 PST, Daniel Bates
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Bates 2011-01-03 21:14:29 PST
When in GNU mode, RVCT supports the GNU language intrinsic __builtin_expect, which is used to provide the compiler with branch prediction information. We should favor using this intrinsic if we are compiling with RVCT in GNU mode (i.e. COMPILER(RVCT) && defined(__GNUC__)).
Comment 1 Daniel Bates 2011-01-03 21:20:05 PST
Created attachment 77867 [details]
Patch
Comment 2 Darin Adler 2011-01-03 21:29:07 PST
Comment on attachment 77867 [details]
Patch

OK
Comment 3 Laszlo Gombos 2011-01-04 08:47:33 PST
Looks good to me too. A simpler way to express this is to test for defined(__GNUC__), instead of "COMPILER(GCC) || (COMPILER(RVCT) && defined(__GNUC__))".
Comment 4 Daniel Bates 2011-01-04 09:31:00 PST
(In reply to comment #3)
> Looks good to me too. A simpler way to express this is to test for defined(__GNUC__), instead of "COMPILER(GCC) || (COMPILER(RVCT) && defined(__GNUC__))".

Will change before I land.
Comment 5 Daniel Bates 2011-01-04 09:44:51 PST
Committed r74973: <http://trac.webkit.org/changeset/74973>
Comment 6 Siddharth Mathur 2011-01-10 12:08:33 PST
Created attachment 78423 [details]
Exclude RVCT2.2 from using this intrinsic

According to ARM's documentation (http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0202h/Cjabddedbde.html), this GNU-style intrinsic is only available with RVCT 3 and later , so exclude previous major version from using it.
Comment 7 Siddharth Mathur 2011-01-10 12:11:20 PST
Created attachment 78425 [details]
Same patch as above, but with Changelog format issue corrected.
Comment 8 Eric Seidel (no email) 2011-01-10 13:50:40 PST
Comment on attachment 78425 [details]
Same patch as above, but with Changelog format issue corrected. 

rs=me.
Comment 9 Eric Seidel (no email) 2011-01-10 13:51:19 PST
Comment on attachment 77867 [details]
Patch

I'm confused by the status of this bug.  Did this get landed?
Comment 10 Siddharth Mathur 2011-01-10 14:03:14 PST
(In reply to comment #9)
> (From update of attachment 77867 [details])
> I'm confused by the status of this bug.  Did this get landed?

Sorry Eric for the confusion. I reopened a previously closed bug (manually landed by Daniel Bates) to add an amendment, which you just r+ed.
Comment 11 Daniel Bates 2011-01-10 14:36:20 PST
Comment on attachment 78425 [details]
Same patch as above, but with Changelog format issue corrected. 

Why are we hardcoding __ARMCC_2_2__ instead of checking __ARMCC_VERSION >= 300000?
Comment 12 Daniel Bates 2011-01-10 14:37:49 PST
(In reply to comment #11)
> (From update of attachment 78425 [details])
> Why are we hardcoding __ARMCC_2_2__ instead of checking __ARMCC_VERSION >= 300000?

I mean checking that __ARMCC_VERSION <= 300000
Comment 13 Daniel Bates 2011-01-10 15:05:33 PST
(In reply to comment #12)
> (In reply to comment #11)
> > (From update of attachment 78425 [details] [details])
> > Why are we hardcoding __ARMCC_2_2__ instead of checking __ARMCC_VERSION >= 300000?
> 
> I mean checking that __ARMCC_VERSION <= 300000

Disregard this comment. The inequality in the previous comment (comment 11) was correct. That is, we should change the check from:

#if defined(__GNUC__)

to

#if COMPILER(GCC) || (COMPILER(RVCT) && defined(__GNUC__) && __ARMCC_VERSION >= 300000)

so that we only use __builtin_expect if we are compiling with GCC or compiling with RVCT version 3.0 or higher in GNU mode.
Comment 14 Daniel Bates 2011-01-10 15:37:35 PST
Created attachment 78461 [details]
Patch
Comment 15 WebKit Review Bot 2011-01-10 15:39:40 PST
Attachment 78461 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/JavaScriptCore/ChangeLog', u'Source..." exit_code: 1
Source/JavaScriptCore/wtf/Platform.h:1016:  Missing space after ,  [whitespace/comma] [3]
Source/JavaScriptCore/wtf/AlwaysInline.h:44:  Missing space after ,  [whitespace/comma] [3]
Source/JavaScriptCore/wtf/AlwaysInline.h:52:  Missing space after ,  [whitespace/comma] [3]
Total errors found: 3 in 3 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 16 Darin Adler 2011-01-10 15:40:35 PST
Comment on attachment 78461 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=78461&action=review

> Source/JavaScriptCore/wtf/Platform.h:79
> +/* Define this for !RVCT compilers, just so we can write things like COMPILER(RVCT) && RVCT_VERSION_AT_LEAST(3,0,0,0). */

It occurs to me that this means that you could always just use RVCT_VERSION_AT_LEAST(3,0,0,0) without COMPILER(RVCT); maybe we should.

> Source/JavaScriptCore/wtf/Platform.h:91
> -/* define this for !GCC compilers, just so we can write things like COMPILER(GCC) && GCC_VERSION_AT_LEAST(4,1,0) */
> +/* Define this for !GCC compilers, just so we can write things like COMPILER(GCC) && GCC_VERSION_AT_LEAST(4,1,0). */
>  #define GCC_VERSION_AT_LEAST(major, minor, patch) 0

It occurs to me that this means that you could always just use GCC_VERSION_AT_LEAST(3,0,0,0) without COMPILER(GCC); maybe we should.
Comment 17 Daniel Bates 2011-01-10 16:03:44 PST
(In reply to comment #16)
> (From update of attachment 78461 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=78461&action=review
> 
> > Source/JavaScriptCore/wtf/Platform.h:79
> > +/* Define this for !RVCT compilers, just so we can write things like COMPILER(RVCT) && RVCT_VERSION_AT_LEAST(3,0,0,0). */
> 
> It occurs to me that this means that you could always just use RVCT_VERSION_AT_LEAST(3,0,0,0) without COMPILER(RVCT); maybe we should.

Correct. Will change both comment and callsites before landing.

> 
> > Source/JavaScriptCore/wtf/Platform.h:91
> > -/* define this for !GCC compilers, just so we can write things like COMPILER(GCC) && GCC_VERSION_AT_LEAST(4,1,0) */
> > +/* Define this for !GCC compilers, just so we can write things like COMPILER(GCC) && GCC_VERSION_AT_LEAST(4,1,0). */
> >  #define GCC_VERSION_AT_LEAST(major, minor, patch) 0
> 
> It occurs to me that this means that you could always just use GCC_VERSION_AT_LEAST(3,0,0,0) without COMPILER(GCC); maybe we should.

Correct. Will change comment before landing. I suggest that we update the callsites in a separate bug.
Comment 18 Daniel Bates 2011-01-10 16:18:21 PST
Committed r75447: <http://trac.webkit.org/changeset/75447>
Comment 19 Daniel Bates 2011-01-10 16:52:01 PST
(In reply to comment #17)
> (In reply to comment #16)
> > It occurs to me that this means that you could always just use GCC_VERSION_AT_LEAST(3,0,0,0) without COMPILER(GCC); maybe we should.
> 
> Correct. Will change comment before landing. I suggest that we update the callsites in a separate bug.

Filed bug #52178 for this and decided to make the comment change in the patch for this bug.