[Webkit-unassigned] [Bug 38045] Fix VectorBuffer's alignment on ARM

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Fri Apr 23 14:46:50 PDT 2010


https://bugs.webkit.org/show_bug.cgi?id=38045





--- Comment #4 from Gabor Loki <loki at webkit.org>  2010-04-23 14:46:49 PST ---
(Sorry, I had to run. So, here comes the explanation.)

The main problem is the declaration of the array. If it is casted to another
array type, the alignment of the source elements should be the same (or bigger)
as the alignment of the target elements. Lets see an example.

char F[6] __attribute__((__aligned__(4)));

This array takes 6 bytes for the value and 2 bytes for padding. So it takes 8
bytes in overall.

typedef struct {
  char c __attribute__((__aligned__(4)));
} S_t;
S_t S[2];

This second array takes 2 bytes for the value and 6 bytes for padding. Sum is 8
bytes as well. (You can ignore the different addressing possibilities of the
character arrays. We will cast them before using.)

What is the difference between this two array? The alignment of the elements.
You can easily see the S[0] and S[1] is aligned to 4 bytes. So a simple
reinterpret_cast<int*>(S) conversion can be done without any alignment problem.
On the first case, the compiler cannot ensure that the F[1], F[2],... are
aligned to 4 bytes (because the minimum required aligned is 1 for char and 4
for int). This is the reason of the warning.

Why does this solution improve things? It uses such a buffer where each element
of the buffer is aligned to the target type. So the corresponding elements of
the buffer have the same address in both types. There is no other magic in it.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list