Re: Something's been bugging me

Поиск
Список
Период
Сортировка
От Florian Weimer
Тема Re: Something's been bugging me
Дата
Msg-id 82tzp7bbbh.fsf@mid.bfk.de
обсуждение исходный текст
Ответ на Re: Something's been bugging me  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
* Tom Lane:

> I ran into an interesting failure here on HPPA: the code the compiler
> generated for copying unaligned toast pointers into aligned local
> variables failed, because it was assuming halfword (2-byte) alignment of
> the data to be copied!  (Instead of a memcpy call it was generating an
> inline loop of ldh/sth instructions.)  Apparently gcc's thought process
> is "the pointer is declared as struct varlena *, therefore must be at
> least 4-aligned, therefore the data at offset 2 is at least 2-aligned".
> The intermediate cast to "varattrib_1b_e *" did not prevent this; I
> had to assign the datum pointer into a separate local variable of that
> type to suppress the "optimization".

This is quite deliberate, it leads to better code.  In general, once
you've cast a pointer to something which needs more alignment than
what's actually, there is no way to get away from that (except using
asm insertions as optimization barriers, of course).  This is fine
from the C semantics because undefined behavior occurs during the cast
already.

I believe that other compilers have similar rules (certainly when it
comes to aliasing), so it's better not to try to outsmart the C
standard here.

--
Florian Weimer                <fweimer@bfk.de>
BFK edv-consulting GmbH       http://www.bfk.de/
Kriegsstraße 100              tel: +49-721-96201-1
D-76133 Karlsruhe             fax: +49-721-96201-99


В списке pgsql-hackers по дате отправления:

Предыдущее
От: "Guillaume Smet"
Дата:
Сообщение: Re: Getting to 8.3 beta1
Следующее
От: Neil Conway
Дата:
Сообщение: Re: Getting to 8.3 beta1