Thread: postgreSQL-8.0.1 compilation with icc-8.1 on Itanium-2 gives "error: asm statements not supported"

Hi,

I am trying to compile postgresql-8.0.1 with icc-8.1.028 on a Linux
RHEL AS3 SMP Itanium2 machine and I get an error as follows-
The complete config.log and make.log is online at
http://www.cse.psu.edu/~kalsi/files/

------------------------------------------------------------------------------------------------------------------------------------
icc -static -fPIC -Wall -Wmissing-prototypes -Wpointer-arith
-Wdeclaration-after-statement -Wold-style-definition -Wendif-labels
-fno-strict-aliasing -I../../../../src/include -D_GNU_SOURCE -c -o
xlog.o xlog.c

../../../../src/include/storage/s_lock.h(184): error: asm statements
not supported in this environment
__asm__ __volatile__(
^

../../../../src/include/storage/s_lock.h(186): error: expected a ")"
: "=r"(ret), "+m"(*lock)

------------------------------------------------------------------------------------------------------------------------------------

I am able to sucessfully compile this postgreSQL with gcc on this machine.

I suppose this means that pgsql uses ASM statements and since ASM
statements are not supported in the Intel C++ compiler, the
compilation fails.

Is there some way to workaround this, for e.g. a patch? Will icc be
supported in any future release of pgsql?

All suggestions welcome,

Thanks in anticipation,


Vikram Kalsi <vikramkalsi@gmail.com> writes:
> Will icc be supported in any future release of pgsql?

Only if someone steps forward with patches.  Do you want to do it?

My immediate reaction is that if icc doesn't actually cope with gcc
asm syntax then it has no business being treated as equivalent to
gcc in s_lock.h:

#if defined(__GNUC__) || defined(__ICC)

Can anyone say a reason why the above #if is not wrong ... ie,
are there any platforms where icc does handle gcc asm syntax,
and if so exactly which ones are they?
        regards, tom lane


Tom Lane wrote:
> #if defined(__GNUC__) || defined(__ICC)
>
> Can anyone say a reason why the above #if is not wrong ... ie,
> are there any platforms where icc does handle gcc asm syntax,
> and if so exactly which ones are they?

I believe I added that a few releases ago.  The platform is IA32.  
Evidently, the GCC compatibility on IA64 is not quite as far yet.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/


Tom, Peter,

I have been able to compile and sucessfully run pgSQL after replacing
the asm statement in postgresql-8.0.1/src/include/storage/s_lock.h
with an equivalent intrinsic for the Itanium platform-

------------------------------------------BEGIN OLD
s_lock.h----------------------------------------------------------
#if defined(__ia64__) || defined(__ia64)  /* __ia64 used by ICC compiler? */
#define HAS_TEST_AND_SET
typedef unsigned int slock_t;
#define TAS(lock) tas(lock)

static __inline__ int
tas(volatile slock_t *lock)
{       long int        ret;
       __asm__ __volatile__(               "       xchg4   %0=%1,%2        \n"
:               "=r"(ret), "+m"(*lock)
:               "r"(1)
:               "memory");       return (int) ret;
}
#endif   /* __ia64__ || __ia64 */
-----------------------------------------------END OLD
s_lock.h----------------------------------------------------------

------------------------------------------BEGIN NEW
s_lock.h----------------------------------------------------------
#if defined(__ia64__) || defined(__ia64)  /* __ia64 used by ICC compiler? */
#define HAS_TEST_AND_SET
typedef unsigned int slock_t;
#define TAS(lock) tas(lock)

static __inline__ int
tas(volatile slock_t *lock)
{       int     ret;
       ret = _InterlockedExchange(lock,1);
       return ret;
}
#endif   /* __ia64__ || __ia64 */
----------------------------------------------END NEW
s_lock.h----------------------------------------------------------

The binary appears to be stable and the tpc-H benchmark executed
successfully against it as well. I also ran the regression test but
the following tests failed, the reasons for which I haven't
investigated yet
(http://www.cse.psu.edu/~kalsi/files/regression.diffs)-

test create_function_1    ... FAILED
test create_type          ... FAILED
test create_table         ... FAILED
test create_function_2    ... FAILED
test triggers             ... FAILED
test create_operator      ... FAILED
test create_view          ... FAILED
test transactions         ... FAILED
test misc                 ... FAILED
test select_views         ... FAILED
test rules                ... FAILED
test plpgsql              ... failed (ignored)
test copy2                ... FAILED
test rangefuncs           ... FAILED
test conversion           ... FAILED
test stats                ... FAILED

The _InterlockedExchange() function is defined in ia64intrin.h header file

int _InterlockedExchange(volatile int *Target, long value)
Do an exchange operation atomically. Maps to the xchg4 instruction.

More information is available at
http://www.intel.com/software/products/compilers/clin/docs/ug_cpp/lin1072.htm

Also, some other points to note, _ICC wasn't defined on my
installation when I was using icc by setting env var CC=icc. So, when
I tried to put a "#if defined" for using asm() for gcc and
_InterlockedExchange(), it didn't work. So, after this change gcc
compilation fails.

As of now, I am trying to test the binary further to see if it is
stable. Would you be knowing some good way to test this change?

I am not aware of the procedure of building patches but if this
resolves this issue and you would like me to make some sort of a
patch, then please let me know.

Thanks,
-Vikram


On Thu, 3 Mar 2005 09:55:18 +0100, Peter Eisentraut <peter_e@gmx.net> wrote:
> Tom Lane wrote:
> > #if defined(__GNUC__) || defined(__ICC)
> >
> > Can anyone say a reason why the above #if is not wrong ... ie,
> > are there any platforms where icc does handle gcc asm syntax,
> > and if so exactly which ones are they?
> 
> I believe I added that a few releases ago.  The platform is IA32.
> Evidently, the GCC compatibility on IA64 is not quite as far yet.
> 
> --
> Peter Eisentraut
> http://developer.postgresql.org/~petere/
>


Just an update, the __INTEL_COMPILER is true on Itanium if icc is
being used. So, the following worked for me-

---------------------------BEGIN OLD
s_lock.h-------------------------------------------------
#if defined(__ia64__) || defined(__ia64)  /* __ia64 used by ICC compiler? */
#define HAS_TEST_AND_SET
typedef unsigned int slock_t;
#define TAS(lock) tas(lock)

static __inline__ int
tas(volatile slock_t *lock)
{      long int        ret;
      __asm__ __volatile__(              "       xchg4   %0=%1,%2        \n"
:               "=r"(ret), "+m"(*lock)
:               "r"(1)
:               "memory");      return (int) ret;
}
#endif   /* __ia64__ || __ia64 */
-----------------------------END OLD
s_lock.h-------------------------------------------------

---------------------------BEGIN NEW
s_lock.h-------------------------------------------------
#if defined(__ia64__) || defined(__ia64)  /* __ia64 used by ICC compiler? */
/* Intel Itanium */
#define HAS_TEST_AND_SET

typedef unsigned int slock_t;

#define TAS(lock) tas(lock)

#if defined(__INTEL_COMPILER)

static __inline__ int
tas(volatile slock_t *lock)
{       int     ret;
       ret = _InterlockedExchange(lock,1);
       return ret;
}

#else    /* __INTEL_COMPILER */

static __inline__ int
tas(volatile slock_t *lock)
{       long int        ret;
       __asm__ __volatile__(               "       xchg4   %0=%1,%2        \n"
:               "=r"(ret), "+m"(*lock)
:               "r"(1)
:               "memory");       return (int) ret;
}

#endif   /* __INTEL_COMPILER */

#endif   /* __ia64__ || __ia64 */
-----------------------------END NEW
s_lock.h-------------------------------------------------

Thanks and Regards,


On Fri, 4 Mar 2005 00:57:15 -0500, Vikram Kalsi <vikramkalsi@gmail.com> wrote:
> Tom, Peter,
> 
> I have been able to compile and sucessfully run pgSQL after replacing
> the asm statement in postgresql-8.0.1/src/include/storage/s_lock.h
> with an equivalent intrinsic for the Itanium platform-
> 
> -------------------------------------BEGIN OLD s_lock.h----------------------------------------
> #if defined(__ia64__) || defined(__ia64)  /* __ia64 used by ICC compiler? */
> #define HAS_TEST_AND_SET
> typedef unsigned int slock_t;
> #define TAS(lock) tas(lock)
> 
> static __inline__ int
> tas(volatile slock_t *lock)
> {
>         long int        ret;
> 
>         __asm__ __volatile__(
>                 "       xchg4   %0=%1,%2        \n"
> :               "=r"(ret), "+m"(*lock)
> :               "r"(1)
> :               "memory");
>         return (int) ret;
> }
> #endif   /* __ia64__ || __ia64 */
> ---------------------------------------END OLD s_lock.h----------------------------------------
> 
> -------------------------------------BEGIN NEW s_lock.h--------------------------------------
> #if defined(__ia64__) || defined(__ia64)  /* __ia64 used by ICC compiler? */
> #define HAS_TEST_AND_SET
> typedef unsigned int slock_t;
> #define TAS(lock) tas(lock)
> 
> static __inline__ int
> tas(volatile slock_t *lock)
> {
>         int     ret;
> 
>         ret = _InterlockedExchange(lock,1);
> 
>         return ret;
> }
> #endif   /* __ia64__ || __ia64 */
> ---------------------------------------END NEW s_lock.h--------------------------------------
> 
> The binary appears to be stable and the tpc-H benchmark executed
> successfully against it as well. I also ran the regression test but
> the following tests failed, the reasons for which I haven't
> investigated yet
> (http://www.cse.psu.edu/~kalsi/files/regression.diffs)-
> 
> test create_function_1    ... FAILED
> test create_type          ... FAILED
> test create_table         ... FAILED
> test create_function_2    ... FAILED
> test triggers             ... FAILED
> test create_operator      ... FAILED
> test create_view          ... FAILED
> test transactions         ... FAILED
> test misc                 ... FAILED
> test select_views         ... FAILED
> test rules                ... FAILED
> test plpgsql              ... failed (ignored)
> test copy2                ... FAILED
> test rangefuncs           ... FAILED
> test conversion           ... FAILED
> test stats                ... FAILED
> 
> The _InterlockedExchange() function is defined in ia64intrin.h header file
> 
> int _InterlockedExchange(volatile int *Target, long value)
> Do an exchange operation atomically. Maps to the xchg4 instruction.
> 
> More information is available at
> http://www.intel.com/software/products/compilers/clin/docs/ug_cpp/lin1072.htm
> 
> Also, some other points to note, _ICC wasn't defined on my
> installation when I was using icc by setting env var CC=icc. So, when
> I tried to put a "#if defined" for using asm() for gcc and
> _InterlockedExchange(), it didn't work. So, after this change gcc
> compilation fails.
> 
> As of now, I am trying to test the binary further to see if it is
> stable. Would you be knowing some good way to test this change?
> 
> I am not aware of the procedure of building patches but if this
> resolves this issue and you would like me to make some sort of a
> patch, then please let me know.
> 
> Thanks,
> -Vikram
> 
> 
> On Thu, 3 Mar 2005 09:55:18 +0100, Peter Eisentraut <peter_e@gmx.net> wrote:
> > Tom Lane wrote:
> > > #if defined(__GNUC__) || defined(__ICC)
> > >
> > > Can anyone say a reason why the above #if is not wrong ... ie,
> > > are there any platforms where icc does handle gcc asm syntax,
> > > and if so exactly which ones are they?
> >
> > I believe I added that a few releases ago.  The platform is IA32.
> > Evidently, the GCC compatibility on IA64 is not quite as far yet.
> >
> > --
> > Peter Eisentraut
> > http://developer.postgresql.org/~petere/
> >
>


Re: postgreSQL-8.0.1 compilation with icc-8.1 on Itanium-2

From
Bruce Momjian
Date:
Does the Intel compiler not support inline assembler? 
_InterlockedExchange() is a function call and we prefer to have asm()
code if we can get it.

---------------------------------------------------------------------------

Vikram Kalsi wrote:
> Just an update, the __INTEL_COMPILER is true on Itanium if icc is
> being used. So, the following worked for me-
> 
> ---------------------------BEGIN OLD
> s_lock.h-------------------------------------------------
> #if defined(__ia64__) || defined(__ia64)  /* __ia64 used by ICC compiler? */
> #define HAS_TEST_AND_SET
> typedef unsigned int slock_t;
> #define TAS(lock) tas(lock)
> 
> static __inline__ int
> tas(volatile slock_t *lock)
> {
>        long int        ret;
> 
>        __asm__ __volatile__(
>                "       xchg4   %0=%1,%2        \n"
> :               "=r"(ret), "+m"(*lock)
> :               "r"(1)
> :               "memory");
>        return (int) ret;
> }
> #endif   /* __ia64__ || __ia64 */
> -----------------------------END OLD
> s_lock.h-------------------------------------------------
> 
> ---------------------------BEGIN NEW
> s_lock.h-------------------------------------------------
> #if defined(__ia64__) || defined(__ia64)  /* __ia64 used by ICC compiler? */
> /* Intel Itanium */
> #define HAS_TEST_AND_SET
> 
> typedef unsigned int slock_t;
> 
> #define TAS(lock) tas(lock)
> 
> #if defined(__INTEL_COMPILER)
> 
> static __inline__ int
> tas(volatile slock_t *lock)
> {
>         int     ret;
> 
>         ret = _InterlockedExchange(lock,1);
> 
>         return ret;
> }
> 
> #else    /* __INTEL_COMPILER */
> 
> static __inline__ int
> tas(volatile slock_t *lock)
> {
>         long int        ret;
> 
>         __asm__ __volatile__(
>                 "       xchg4   %0=%1,%2        \n"
> :               "=r"(ret), "+m"(*lock)
> :               "r"(1)
> :               "memory");
>         return (int) ret;
> }
> 
> #endif   /* __INTEL_COMPILER */
> 
> #endif   /* __ia64__ || __ia64 */
> -----------------------------END NEW
> s_lock.h-------------------------------------------------
> 
> Thanks and Regards,
> 
> 
> On Fri, 4 Mar 2005 00:57:15 -0500, Vikram Kalsi <vikramkalsi@gmail.com> wrote:
> > Tom, Peter,
> > 
> > I have been able to compile and sucessfully run pgSQL after replacing
> > the asm statement in postgresql-8.0.1/src/include/storage/s_lock.h
> > with an equivalent intrinsic for the Itanium platform-
> > 
> > -------------------------------------BEGIN OLD s_lock.h----------------------------------------
> > #if defined(__ia64__) || defined(__ia64)  /* __ia64 used by ICC compiler? */
> > #define HAS_TEST_AND_SET
> > typedef unsigned int slock_t;
> > #define TAS(lock) tas(lock)
> > 
> > static __inline__ int
> > tas(volatile slock_t *lock)
> > {
> >         long int        ret;
> > 
> >         __asm__ __volatile__(
> >                 "       xchg4   %0=%1,%2        \n"
> > :               "=r"(ret), "+m"(*lock)
> > :               "r"(1)
> > :               "memory");
> >         return (int) ret;
> > }
> > #endif   /* __ia64__ || __ia64 */
> > ---------------------------------------END OLD s_lock.h----------------------------------------
> > 
> > -------------------------------------BEGIN NEW s_lock.h--------------------------------------
> > #if defined(__ia64__) || defined(__ia64)  /* __ia64 used by ICC compiler? */
> > #define HAS_TEST_AND_SET
> > typedef unsigned int slock_t;
> > #define TAS(lock) tas(lock)
> > 
> > static __inline__ int
> > tas(volatile slock_t *lock)
> > {
> >         int     ret;
> > 
> >         ret = _InterlockedExchange(lock,1);
> > 
> >         return ret;
> > }
> > #endif   /* __ia64__ || __ia64 */
> > ---------------------------------------END NEW s_lock.h--------------------------------------
> > 
> > The binary appears to be stable and the tpc-H benchmark executed
> > successfully against it as well. I also ran the regression test but
> > the following tests failed, the reasons for which I haven't
> > investigated yet
> > (http://www.cse.psu.edu/~kalsi/files/regression.diffs)-
> > 
> > test create_function_1    ... FAILED
> > test create_type          ... FAILED
> > test create_table         ... FAILED
> > test create_function_2    ... FAILED
> > test triggers             ... FAILED
> > test create_operator      ... FAILED
> > test create_view          ... FAILED
> > test transactions         ... FAILED
> > test misc                 ... FAILED
> > test select_views         ... FAILED
> > test rules                ... FAILED
> > test plpgsql              ... failed (ignored)
> > test copy2                ... FAILED
> > test rangefuncs           ... FAILED
> > test conversion           ... FAILED
> > test stats                ... FAILED
> > 
> > The _InterlockedExchange() function is defined in ia64intrin.h header file
> > 
> > int _InterlockedExchange(volatile int *Target, long value)
> > Do an exchange operation atomically. Maps to the xchg4 instruction.
> > 
> > More information is available at
> > http://www.intel.com/software/products/compilers/clin/docs/ug_cpp/lin1072.htm
> > 
> > Also, some other points to note, _ICC wasn't defined on my
> > installation when I was using icc by setting env var CC=icc. So, when
> > I tried to put a "#if defined" for using asm() for gcc and
> > _InterlockedExchange(), it didn't work. So, after this change gcc
> > compilation fails.
> > 
> > As of now, I am trying to test the binary further to see if it is
> > stable. Would you be knowing some good way to test this change?
> > 
> > I am not aware of the procedure of building patches but if this
> > resolves this issue and you would like me to make some sort of a
> > patch, then please let me know.
> > 
> > Thanks,
> > -Vikram
> > 
> > 
> > On Thu, 3 Mar 2005 09:55:18 +0100, Peter Eisentraut <peter_e@gmx.net> wrote:
> > > Tom Lane wrote:
> > > > #if defined(__GNUC__) || defined(__ICC)
> > > >
> > > > Can anyone say a reason why the above #if is not wrong ... ie,
> > > > are there any platforms where icc does handle gcc asm syntax,
> > > > and if so exactly which ones are they?
> > >
> > > I believe I added that a few releases ago.  The platform is IA32.
> > > Evidently, the GCC compatibility on IA64 is not quite as far yet.
> > >
> > > --
> > > Peter Eisentraut
> > > http://developer.postgresql.org/~petere/
> > >
> >
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
>       joining column's datatypes do not match
> 

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 


Re: postgreSQL-8.0.1 compilation with icc-8.1 on Itanium-2

From
Bruce Momjian
Date:
Vikram Kalsi wrote:
> The _InterlockedExchange() function is defined in ia64intrin.h header file
> 
> int _InterlockedExchange(volatile int *Target, long value)
> Do an exchange operation atomically. Maps to the xchg4 instruction.
> 
> More information is available at
> http://www.intel.com/software/products/compilers/clin/docs/ug_cpp/lin1072.htm
> 
> Also, some other points to note, _ICC wasn't defined on my
> installation when I was using icc by setting env var CC=icc. So, when
> I tried to put a "#if defined" for using asm() for gcc and
> _InterlockedExchange(), it didn't work. So, after this change gcc
> compilation fails.

Oh, I see _InterlockedExchange is inlined assembler.  Let me work on a
patch and post it to you.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073