Boost logo

Boost :

Subject: Re: [boost] Accelerating algorithms with SIMD - Segmented iterators and alternatives
From: Bryce Lelbach (admin_at_[hidden])
Date: 2010-10-13 01:02:17


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Notes on clang/LLVM + C++ + JIT stuff:

////////////////////////////////////////////////////////////////////
// Copyright 2008 Eric Niebler. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <iostream>
#include <boost/proto/core.hpp>
#include <boost/proto/context.hpp>
#include <boost/typeof/std/ostream.hpp>
namespace proto = boost::proto;

proto::terminal< std::ostream & >::type cout_ = {std::cout};

template< typename Expr >
void evaluate( Expr const & expr )
{
    proto::default_context ctx;
    proto::eval(expr, ctx);
}

int main()
{
    evaluate( cout_ << "hello" << ',' << " world" );
    return 0;
}
//]
wash_at_Pegasus:~/sandbox$ time clang++ -cc1 -triple x86_64-unknown-linux-gnu
- -emit-llvm-bc -x c++ hello.cpp

real 0m1.958s
user 0m1.676s
sys 0m0.276s
wash_at_Pegasus:~/sandbox$ lli hello.bc
hello, world
wash_at_Pegasus:~/sandbox$

There's nothing magic about JITing C++, even JITing non-trivial C++. It's
basically pointless, because the LLVM bitcode/LLVM assembly generated by a C++
program is absolutely, positively not portable. Starting in the earliest stages
of compilation (preprocessing), platform dependencies enter the code (not to
mention all the preprocessor workarounds). Add in alignment jazz. Plus sizes.
Plus implementation details (GNU expands sizeof and assert in the preprocessor,
for example). CXXABI. C++ is not Java, and clang/LLVM are not magic. We can do
cool things with clang/LLVM, C++ and JIT, but at the end of the day, C++ is not
Java.

Other stuff:

I think I saw some comments implying that C compilers were faster or better
than C++ compilers. I know that I saw people claim that C compilers were
faster, better or could optimize better than C++ compilers implemented using
expression templates and metaprogramming techniques. Such claims are
unfounded.

http://clang.llvm.org/performance.html - clang uses limited template
metaprogramming techniques, however it is quickly shaping into a solid,
production-quality open-source C++ compiler (I have compiled a semi-functional
Linux kernel with clang), and it is by far superior to it's C predeccessor GCC
when it comes to optimization.

Boost.Wave, a standards compliant C preprocessor is implemented using
Boost.Spirit.

www.ll.mit.edu/HPEC/agendas/proc02/abstracts/mullin.pdf - really smart MIT
guy's paper on really cool optimizations, done in C++ with C++ TMP techniques,
specifically expressive templates.

- --
Bryce Lelbach aka wash
http://groups.google.com/group/ariel_devel
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAky1PVkACgkQO/fqqIuE2t6gBwCcDjnYwO8kYzzBu7HOyl6yyAhB
UJsAoMfUKrujDLkBHHEOe7Eyep9AJOJi
=hYSg
-----END PGP SIGNATURE-----


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk