add_ssaaaa and C++

Torbjorn Granlund tege at swox.com
Sun May 22 13:14:54 CEST 2005


Emmanuel Thomé <Emmanuel.Thome at inria.fr> writes:

  Here's a nasty bug with g++ and longlong.h ; not critical for gmp though.
  
  currently, add_ssaaaa is defined on i386 (for example) as
  
  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
    __asm__ ("addl %5,%1\n\tadcl %3,%0"                                   \
             : "=r" ((USItype)(sh)), "=&r" ((USItype)(sl))                \
             : "0"  ((USItype)(ah)), "g" ((USItype)(bh)),                 \
               "%1" ((USItype)(al)), "g" ((USItype)(bl)))
  
  Is there a reason for using the cast-to-lvalue extension ? Such
  extensions are marked deprecated in gcc.
  
I think this was made with the idea to make sure we'd get the
right instruction variants even it the macro is fed with smaller
types.

But that reasoning really doesn't make sense.  And we don't seem
to be casting lvalues in other places in longlong.h.
Furthermore, modern gcc pukes on code trying a non-noop lvalue
cast:

/home/tege/addas.c: In function `foo':
/home/tege/addas.c:9: error: invalid lvalue in asm statement
/home/tege/addas.c:9: error: invalid lvalue in asm statement

I suggest this patch:

Index: longlong.h
===================================================================
RCS file: /home/cvsfiles/gmp/longlong.h,v
retrieving revision 1.120
diff -c -r1.120 longlong.h
*** longlong.h	14 May 2005 17:14:04 -0000	1.120
--- longlong.h	22 May 2005 11:11:33 -0000
***************
*** 656,668 ****
  
  #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
!   __asm__ ("addl %5,%1\n\tadcl %3,%0"					\
! 	   : "=r" ((USItype)(sh)), "=&r" ((USItype)(sl))		\
  	   : "0"  ((USItype)(ah)), "g" ((USItype)(bh)),			\
  	     "%1" ((USItype)(al)), "g" ((USItype)(bl)))
  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
!   __asm__ ("subl %5,%1\n\tsbbl %3,%0"					\
! 	   : "=r" ((USItype)(sh)), "=&r" ((USItype)(sl))		\
  	   : "0" ((USItype)(ah)), "g" ((USItype)(bh)),			\
  	     "1" ((USItype)(al)), "g" ((USItype)(bl)))
  #define umul_ppmm(w1, w0, u, v) \
--- 656,668 ----
  
  #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
!   __asm__ ("addl %5,%k1\n\tadcl %3,%k0"					\
! 	   : "=r" (sh), "=&r" (sl)					\
  	   : "0"  ((USItype)(ah)), "g" ((USItype)(bh)),			\
  	     "%1" ((USItype)(al)), "g" ((USItype)(bl)))
  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
!   __asm__ ("subl %5,%k1\n\tsbbl %3,%k0"					\
! 	   : "=r" (sh), "=&r" (sl)					\
  	   : "0" ((USItype)(ah)), "g" ((USItype)(bh)),			\
  	     "1" ((USItype)(al)), "g" ((USItype)(bl)))
  #define umul_ppmm(w1, w0, u, v) \

-- 
Torbjörn


More information about the gmp-bugs mailing list