pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
TAS patch for building on armel/armhf thumb
2+ messages / 2 participants
[nested] [flat]

* TAS patch for building on armel/armhf thumb
@ 2011-12-16 09:36  Martin Pitt <mpitt@debian.org>
  0 siblings, 1 reply; 2+ messages in thread

From: Martin Pitt @ 2011-12-16 09:36 UTC (permalink / raw)
  To: pgsql-bugs

Hello,

if you build postgresql (tested all releases from 8.4 up to trunk) for
ARM with the -mthumb instruction set (much better performance), it
fails with

gcc -g -O2 -g -Wall -O2 -fPIC -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -g -I../../../../src/include -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include/tcl8.5 -c -o xlog.o xlog.c
/tmp/cc8Wkglp.s: Assembler messages:
/tmp/cc8Wkglp.s:1456: Error: selected processor does not support `swpb r3,r3,[r0]'
/tmp/cc8Wkglp.s:1587: Error: selected processor does not support `swpb r2,r2,[r0]'

A fair while ago, Alexander Sack from Linaro applied a patch to our
packages to drop the Assembler bits and instead use gcc's atomic
builtins [1], which provide a proper implementation for thumb, too.

The original patch spectacularly failed on our slightly newer Panda
boards (our old builders were Freescale Babbage boards), but I got
that to work yesterday. Now it's working on Babbage, Panda, both with
and without hard float (armhf) enabled.

I'm not sure how appropriate it is for upstream to have GCC-isms in
the code, but even if it can't land upstream, perhaps it is useful for
other porters/packagers.

Thanks,

Martin

[1] http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html
-- 
Martin Pitt                        | http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)

Attachments:

01-armel-tas.patch (text/x-diff, 1.1K) download Description: use gcc intrinsics rather than assembler to implement tas Author: Alexander Sack <asac@ubuntu.com> Author: Martin Pitt <martin.pitt@ubuntu.com> Bug-Ubuntu: https://launchpad.net/bugs/497331 Bug-Ubuntu: https://launchpad.net/bugs/904828 Index: postgresql-9.1-9.1.2/src/include/storage/s_lock.h =================================================================== --- postgresql-9.1-9.1.2.orig/src/include/storage/s_lock.h 2011-12-01 22:47:20.000000000 +0100 +++ postgresql-9.1-9.1.2/src/include/storage/s_lock.h 2011-12-15 21:17:32.965569760 +0100 @@ -255,21 +255,15 @@ #if defined(__arm__) || defined(__arm) #define HAS_TEST_AND_SET -typedef unsigned char slock_t; +typedef unsigned int slock_t; #define TAS(lock) tas(lock) +#define S_UNLOCK(lock) __sync_lock_release(lock) static __inline__ int tas(volatile slock_t *lock) { - register slock_t _res = 1; - - __asm__ __volatile__( - " swpb %0, %0, [%2] \n" -: "+r"(_res), "+m"(*lock) -: "r"(lock) -: "memory"); - return (int) _res; + return __sync_lock_test_and_set (lock, 1); } #endif /* __arm__ */
signature.asc (application/pgp-signature, 835B) download ^ permalink raw reply [nested|flat] 2+ messages in thread

* Re: TAS patch for building on armel/armhf thumb
@ 2011-12-16 10:24  Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
  parent: Martin Pitt <mpitt@debian.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Heikki Linnakangas @ 2011-12-16 10:24 UTC (permalink / raw)
  To: pgsql-bugs

On 16.12.2011 11:36, Martin Pitt wrote:
> if you build postgresql (tested all releases from 8.4 up to trunk) for
> ARM with the -mthumb instruction set (much better performance), it
> fails with
>
> gcc -g -O2 -g -Wall -O2 -fPIC -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -g -I../../../../src/include -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include/tcl8.5 -c -o xlog.o xlog.c
> /tmp/cc8Wkglp.s: Assembler messages:
> /tmp/cc8Wkglp.s:1456: Error: selected processor does not support `swpb r3,r3,[r0]'
> /tmp/cc8Wkglp.s:1587: Error: selected processor does not support `swpb r2,r2,[r0]'
>
> A fair while ago, Alexander Sack from Linaro applied a patch to our
> packages to drop the Assembler bits and instead use gcc's atomic
> builtins [1], which provide a proper implementation for thumb, too.
>
> The original patch spectacularly failed on our slightly newer Panda
> boards (our old builders were Freescale Babbage boards), but I got
> that to work yesterday. Now it's working on Babbage, Panda, both with
> and without hard float (armhf) enabled.
>
> I'm not sure how appropriate it is for upstream to have GCC-isms in
> the code, but even if it can't land upstream, perhaps it is useful for
> other porters/packagers.

Should be ok, as long as it's within #ifdef __GNUC__.

An even better approach would be to have a configure test for 
__sync_lock_test_and_set. A quick google search suggests that Intel C 
Compiler version >= 11.0 also supports __sync_lock_test_and_set, for 
example. It probably makes sense to use it on any platform where it's 
defined. Presumably an implementation provided by the compiler is always 
going to be at least as good as any magic assembler incantations we can 
come up with.

-- 
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2011-12-16 10:24 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-12-16 09:36 TAS patch for building on armel/armhf thumb Martin Pitt <mpitt@debian.org>
2011-12-16 10:24 ` Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox