=== add optimisation helpers === '''Background:''' Having profiled, a number of places in the code would benefit from annotation as to which branch is likely to occur in real use. gcc > version 2 provides a nice __builtin_expect function to add this to code to help the optimiser in places. It would be great to add a SAL_LIKELY, SAL_UNLIKELY pair of macros to sal/inc/sal/macros.hxx using this function. It would also might be useful to have SAL_HOT, SAL_COLD pair that (under gcc) would add the __attribute__ (("hot")) or cold - that can also help the optimiser for performance critical functions. Clearly these must not be used without profiling. '''Skills:''' C, build
Deteted "Easyhack" from summary
adding LibreOffice developer list as CC to unresolved EasyHacks for better visibility. see e.g. http://nabble.documentfoundation.org/minutes-of-ESC-call-td4076214.html for details
That header sal/inc/sal/macros.h these days lives in include/sal/macros.h. BTW, there never was sal/inc/sal/macros.hxx. It was always sal/inc/sal/macros.h.
I am working on this bug.
(In reply to comment #3) > That header sal/inc/sal/macros.h these days lives in include/sal/macros.h. > > BTW, there never was sal/inc/sal/macros.hxx. It was always > sal/inc/sal/macros.h. ...and such platform-dependent SAL_LIKELY functionality would more naturally fit into sal/types.h than sal/macros.h
also note that GCC __builtin_expect (with its first parameter being of type long) is plain, simple, and generally does not work as one would naively hope: > class C { > private: > struct S; > typedef void (S::* B)(); > public: > operator B(); > }; > int f(C c) { > if (c) { > if (__builtin_expect(c, 1)) { > return 1; > } else { > return 2; > } > } else { > return 3; > } > } will cause a compilation error "cannot convert ‘C’ to ‘long int’ for argument ‘1’ to ‘long int __builtin_expect(long int, long int)’"
I guess it might be worth talking to the glib developers; gmacros.h has a reasonably workable version - however the _G_BOOLEAN_EXPR stuff is not the ultimate in beauty =) The implementation in glib is all written by: Matthias Clasen <matthiasc@src.gnome.org> I just dug throught he commit log for glib =) I'd be inclined to simply re-use G_LIKELY and G_UNLIKELY with a SAL prefix myself.
(In reply to comment #7) > I just dug throught he commit log for glib =) I'd be inclined to simply > re-use G_LIKELY and G_UNLIKELY with a SAL prefix myself. That _G_BOOLEAN_EXPR trick would work. An alternative would be to restrict this to C++ and instead stick an explicit conversion to bool into the __builtin_expect call.
As you like; we have less and less C these days I guess, and IIRC we compile it as C++ (?) =)
Migrating Whiteboard tags to Keywords: (easyHack, difficultyBeginner, skillCpp) [NinjaEdit]
I add SAL_LIKELY, SAL_UNLIKELY ,SAL_HOT, SAL_COLD pair of macro in sal/types.h , before that I add _SAL_BOOLEAN_EXPR which is an alternative way of using __builtin_expect which is good for implicit conversion to bool, because __builtin_expect cause a compilation error it cannot convert to long int. see here the patch http://ci.libreoffice.org/job/lo_gerrit_master/9846/
you point at the ci build job not the patch. the patch is https://gerrit.libreoffice.org/#/c/21070 I have added it to my review list.
Sheikha AL-Hinai committed a patch related to this issue. It has been pushed to "master": http://cgit.freedesktop.org/libreoffice/core/commit/?id=eafb1ebf74c3caf8fbecdc6a4fc7037c3c8f4964 tdf#39631: Add optimisation helpers It will be available in 5.2.0. The patch should be included in the daily builds available at http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: http://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Michael Meeks committed a patch related to this issue. It has been pushed to "master": http://cgit.freedesktop.org/libreoffice/core/commit/?id=e75406e54c57fc3113d4f1983249eb2aec0a3bcd tdf#39631 - branch hints: comment, and tweak variously, also use. It will be available in 5.2.0. The patch should be included in the daily builds available at http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: http://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
looks like Sheikha fixed this one, thanks!
Remove LibreOffice Dev List from CC on EasyHacks (curtailing excessive email to list) [NinjaEdit]