Boost logo

Boost :

Subject: Re: [boost] Interest request for pointer+bit compressionoptimization
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2009-09-08 15:57:20


Hi,
----- Original Message -----
From: "Doug Gregor" <doug.gregor_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, September 08, 2009 5:22 PM
Subject: Re: [boost] Interest request for pointer+bit compressionoptimization

On Tue, Sep 8, 2009 at 3:51 AM, troy d. straszheim<troy_at_[hidden]> wrote:
> David Abrahams wrote:
>>
>> on Tue Sep 08 2009, Vicente Botet Escriba <vicente.botet-AT-wanadoo.fr>
>> wrote:
>>
>>> Do you have a specific pointer for CLang related to this usage?
>>
>> Nope, this is hearsay. Doug?
>>
>
> If I remember Doug's explanation correctly, one of the
> optimizations inside clang is: There is a global table of 'plain'
> types, e.g. int, bool, float, std::string. Clang internally represents
> CV qualified types by e.g. creating a pointer to the type 'int',
> then using the small bits of the pointer to tag const and volatile. I
> don't recall whether they used more than two bits (for, say reference,
> static, pointer, etc.) Sebastian Redl gave a great intro to clang @
> boostcon, I'd bet he knows the details as well.

Clang's QualType smart pointer uses three bits, for const, volatile,
and restrict, so we have to force 8-byte alignment when we allocate
Type structures. There's a tiny bit of explanation of this part of the
type system here:

  http://clang.llvm.org/docs/InternalsManual.html#QualType

The actual QualType class is here:

  https://llvm.org/svn/llvm-project/cfe/trunk/include/clang/AST/Type.h

We use this bit-mangling trick a *lot* in Clang. The general
infrastructure is "PointerIntPair", which is what it says it is: a
pointer and an integer mangled together, with accessors for each. The
code is here:

  https://llvm.org/svn/llvm-project/llvm/trunk/include/llvm/ADT/PointerIntPair.h

We build most of our bit-mangled structures on top of PointerIntPair
or PointerUnion, a union of two (distinct) pointer types:

  https://llvm.org/svn/llvm-project/llvm/trunk/include/llvm/ADT/PointerUnion.h

 - Doug
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

The PointerIntPair provides exactly what optimized_pair class. The name is much more explicit.
Thanks for the pointer. Extracted from https://llvm.org/svn/llvm-project/llvm/trunk/include/llvm/ADT/PointerIntPair.h
"
/// PointerIntPair - This class implements a pair of a pointer and small
/// integer. It is designed to represent this in the space required by one
/// pointer by bitmangling the integer into the low part of the pointer. This
/// can only be done for small integers: typically up to 3 bits, but it depends
/// on the number of bits available according to PointerLikeTypeTraits for the
/// type.
///
/// Note that PointerIntPair always puts the Int part in the highest bits
/// possible. For example, PointerIntPair<void*, 1, bool> will put the bit for
/// the bool into bit #2, not bit #0, which allows the low two bits to be used
/// for something else. For example, this allows:
/// PointerIntPair<PointerIntPair<void*, 1, bool>, 1, bool>
/// ... and the two bools will land in different bits.
///
template <typename PointerTy, unsigned IntBits, typename IntType=unsigned,
          typename PtrTraits = PointerLikeTypeTraits<PointerTy> >
class PointerIntPair;
"

I like the way it manage to store several bits using a PointerLikeTypeTraits

Thanks to all to pointing to this simple class.

Are you interested on the inclusion of this class to boost?

Vicente


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