[Pixman] [PATCH/RFC 0/4] New option to build pixman as C++ code (--enable-enforced-cplusplus)

Siarhei Siamashka siarhei.siamashka at gmail.com
Tue Dec 18 18:27:36 PST 2012

On Mon, 17 Dec 2012 13:10:38 -0500
Behdad Esfahbod <behdad at behdad.org> wrote:

> On 12-12-16 06:06 PM, Siarhei Siamashka wrote:
> > On Sun, 16 Dec 2012 15:34:57 -0500
> > Behdad Esfahbod <behdad at behdad.org> wrote:
> > 
> >> On 12-12-16 12:13 AM, Siarhei Siamashka wrote:
> >>> Any comments or ideas? Hopefully not a C vs. C++ flamewar :)
> >>
> >> I would go as far as suggesting that C++ becomes a requirement.  I did that in
> >> HarfBuzz and never looked back.  It's possible to use many useful features of
> >> the language (templates, etc) without linking to libstdc++, so from the user's
> >> point of view there's absolutely no difference between that kind of a library
> >> and a C library.
> > 
> > One problem with these useful C++ features is that making use of them,
> > we are wilfully becoming the hostages of a compiler. But the real
> > existing compilers are struggling even to handle inline functions
> > without bugs and performance regressions:
> >     http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54965
> > 
> > So I'm leaning to remain conservative and initially use C++ features
> > only as a debugging aid. Just like OpenMP, gcc vector extensions,
> > 128-bit float types and the other fancy compiler features are only
> > used (or proposed to be used) in the test suite.
> You definitely have a point.  However, this exact example is why I always
> thought Pixman in particular can make good use of templates.  Because
> essentially that's what Pixman is: operation templates instantiated with lots
> of different options. 

Yes, C++ templates are surely more convenient for this type of code.

> Currently we just use always_inline and hope that the compiler
> does the right thing.

With always_inline we can be sure that the compiler does the right
thing. When it does not, this is very visible and hard not to notice,
because gcc treats inability to actually inline an always_inline
function as error (that's what the bug from gcc bugzilla is about).

Doing it in the compiler endorsed way would mean to just use ordinary
'inline' keyword and let the compiler decide whether to honour it
or not.

> With C++ those become template instantiations that have much more
> chance to be inlined and optimized.

It's more like the other way around. The compiler has more chances to
screw up the performance when more complex features are used. It's
basically a trade off between having more convenience and having more
control over how the code is translated to the machine instructions
in the end.

The intrinsics are also a convenience feature which sacrifices some
performance. But that's another topic.

> Incidentally, I think that's the approach Skia took.

And also Qt raster backend.

Best regards,
Siarhei Siamashka

More information about the Pixman mailing list