Thiago Macieira
2011-10-16 14:30:39 UTC
When I talked to João this week, he expressed the desire to unify the header
code of QVector, QByteArray and QString. Since QByteArray is a vector of char
and QString is a vector of QChar / ushort, it makes sense to unify the code to
simplify maintenance. Whether specific optimisations in allocation policies are
needed, we can figure out later.
But given my last email, about also bringing in QList for small and movable
types into this merging, I pointed out that QList has one optimisation that
QVector doesn't have.
To support that feature, the QListData header currently is:
QAtomicInt ref;
int alloc;
int begin;
int end;
// size = 16 bytes, alignment = 4 bytes
There's also an 1-bit flag which I have not included. It can be stored in the
sign bit of one of the ints in the future.
In addition, the current QStringData and QByteArrayData headers are (not
including the flags):
QAtomicint ref;
int size;
int alloc;
qptrdiff offset;
// size = 16 (24) bytes, alignment = 4 (8) bytes
Note how there's a 4-byte padding gap before the "offset" member on 64-bit
platforms and how the data starts at an offset of 24 bytes. Given a 16-byte
aligned allocator, which is common on 64-bit platforms, the data starts at an
8 byte offset from the nearest 16-byte alignment, which is a problem for SSE2
optimisations.
I'd like to pick all of your brains for a solution that has the following
properties:
- size always 16 bytes
- contains a qptrdiff offset, to still allow for fromRawData (which we'd
then introduce to QVector too, but not QList)
- can store at least one 1-bit flag, but 2 would be preferred
- size calculation reasonably fast
code of QVector, QByteArray and QString. Since QByteArray is a vector of char
and QString is a vector of QChar / ushort, it makes sense to unify the code to
simplify maintenance. Whether specific optimisations in allocation policies are
needed, we can figure out later.
But given my last email, about also bringing in QList for small and movable
types into this merging, I pointed out that QList has one optimisation that
QVector doesn't have.
To support that feature, the QListData header currently is:
QAtomicInt ref;
int alloc;
int begin;
int end;
// size = 16 bytes, alignment = 4 bytes
There's also an 1-bit flag which I have not included. It can be stored in the
sign bit of one of the ints in the future.
In addition, the current QStringData and QByteArrayData headers are (not
including the flags):
QAtomicint ref;
int size;
int alloc;
qptrdiff offset;
// size = 16 (24) bytes, alignment = 4 (8) bytes
Note how there's a 4-byte padding gap before the "offset" member on 64-bit
platforms and how the data starts at an offset of 24 bytes. Given a 16-byte
aligned allocator, which is common on 64-bit platforms, the data starts at an
8 byte offset from the nearest 16-byte alignment, which is a problem for SSE2
optimisations.
I'd like to pick all of your brains for a solution that has the following
properties:
- size always 16 bytes
- contains a qptrdiff offset, to still allow for fromRawData (which we'd
then introduce to QVector too, but not QList)
- can store at least one 1-bit flag, but 2 would be preferred
- size calculation reasonably fast
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358