This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

avr port & expmed.c patch

I want to change expmed.c because GCC generates better code with my
version of expmed.c for any targets which have BRANCH_COST == 0.

        Old expmed.c                     New expmed.c
_foo:                            _foo:                 
	push	r6		         push    r6    
	mov.w	r7,r6		         mov.w   r7,r6 
	mov.w	r0,r2		         mov.w   r0,r0 
	shll	r2l		         bge     .L3   
	rotxl	r2h		         adds    #1,r0 
	bst	#0,r2l		 .L3:                  
	and #1,r2l		         shar    r0h   
	and #0,r2h		         rotxr   r0l   
	add.w	r2,r0		         pop     r6    
	shar	r0h		         rts           
	rotxr	r0l
	pop	r6


foo:                             foo:                           
/* prologue: frame size=0 */	 /* prologue: frame size=0 */   
/* prologue end (size=0) */	 /* prologue end (size=0) */    
	mov r18,r24		         sbrc r25,7             
	mov r19,r25		         adiw r24,1             
	lsl r25			 .L3:                           
	sbc r24,r24		         asr r25                
	neg r24			         ror r24                
	clr r25			 /* epilogue: frame size=0 */   
	add r18,r24		         ret                    
	adc r19,r25
	asr r19
	ror r18
	mov r25,r19
	mov r24,r18
/* epilogue: frame size=0 */


foo:                             foo:                             
	ldy	*_.frame	         ldy     *_.frame        
	pshy			         pshy                    
	sts	*_.frame	         sts     *_.frame        
	ldy	*_.d1		         cpx     #0              
	pshy			         bmi     .L5             
	ldy	*_.d2		         beq     .L5             
	pshy			 .L3:                            
	ldy	*_.d3		         ldy     #1              
	pshy			         bsr     ___ashrsi3      
	ldy	*_.d4		         puly                    
	pshy			         sty     *_.frame        
	std	*_.d4		         rts                     
	stx	*_.d3		 .L5:                            
	std	*_.d2		         cpx     #0              
	ldd	*_.d3		         bpl     .L3             
	std	*_.d1		         addd    #1              
	ldd	*_.d2		         bcc     .L6             
	ldy	#31		         inx                     
	bsr	___ashrsi3	 .L6:                            
	ldy	#31		         bra     .L3             
	bsr	___lshrsi3
	std	*_.d2
	stx	*_.d1
	ldd	*_.d4
	ldx	*_.d3
	addd	*_.d2
	adcb	*_.d1+1
	adca	_.d1
	ldy	#1
	bsr	___ashrsi3
	sty	*_.d4
	sty	*_.d3
	sty	*_.d2
	sty	*_.d1
	sty	*_.frame


_foo:                            _foo:                    
	.word 0x0		         .word 0x0
	movl 4(ap),r0		         movl 4(ap),r0
	ashl $-31,r0,r1		         jgeq L2
	movb $1,r2		         incl r0
	extzv $31,r2,r1,r1	 L2:
	addl2 r1,r0		         ashl $-1,r0,r0   
	ashl $-1,r0,r0		         ret

I can't test convex because cc1 generates SIGSEGV.


_foo:                               _foo:                                      
;       /* function prologue foo*/          ;       /* function prologue foo*/ 
	mov fp, -(sp)		            mov fp, -(sp)                      
	mov sp, fp		            mov sp, fp                         
	mov r2, -(sp)		            ;/* end of prologue */             
	mov r3, -(sp)		                                               
	;/* end of prologue */	            mov 4(r5), r0                      
				            bge L_3                            
	mov 4(r5), r0		            inc r0                             
	mov r0, r3		    L_3:                                       
	ash $177761,r3		            asr r0                             
	clr r2			                                               
	ashc $177761,r2		            ;       /*function epilogue */     
	add r3, r0		            mov fp, sp                         
	asr r0			            mov (sp)+, fp                      
				            rts pc                             
        /*function epilogue */              ;/* end of epilogue*/              
	mov 37777777774(fp), r3	    
	mov 37777777776(fp), r2	    
	mov fp, sp
	mov (sp)+, fp
	rts pc

Sat Sep 23 19:10:20 2000  Denis Chertykov  <>
	* config/avr/avr.h (BRANCH_COST): Define as 0.

	* expmed.c (expand_divmod): For signed divide by 2, prefer
	a branch and fewer shifts if branches are very cheap.

	* config/pdp11/pdp11.c: #include "tree.h" added.

diff -rc3p orig/egcs/gcc/config/avr/avr.h egcs/gcc/config/avr/avr.h
*** orig/egcs/gcc/config/avr/avr.h	Thu Sep 14 17:45:16 2000
--- egcs/gcc/config/avr/avr.h	Sat Sep 23 11:34:16 2000
*************** do {									    \
*** 1896,1901 ****
--- 1896,1905 ----
     between two registers, you should define this macro to express the
     relative cost.  */
+ #define BRANCH_COST 0
+ /* A C expression for the cost of a branch instruction.  A value of 1
+    is the default; other values are interpreted relative to that.  */
  #define SLOW_BYTE_ACCESS 0
  /* Define this macro as a C expression which is nonzero if accessing
     less than a word of memory (i.e. a `char' or a `short') is no
diff -rc3p orig/egcs/gcc/expmed.c egcs/gcc/expmed.c
*** orig/egcs/gcc/expmed.c	Fri Sep 15 18:18:50 2000
--- egcs/gcc/expmed.c	Sat Sep 23 11:38:06 2000
*************** expand_divmod (rem_flag, code, mode, op0
*** 3240,3246 ****
  		else if (EXACT_POWER_OF_2_OR_ZERO_P (abs_d))
  		    lgup = floor_log2 (abs_d);
! 		    if (abs_d != 2 && BRANCH_COST < 3)
  			rtx label = gen_label_rtx ();
  			rtx t1;
--- 3240,3246 ----
  		else if (EXACT_POWER_OF_2_OR_ZERO_P (abs_d))
  		    lgup = floor_log2 (abs_d);
! 		    if (BRANCH_COST < 1 || (abs_d != 2 && BRANCH_COST < 3))
  			rtx label = gen_label_rtx ();
  			rtx t1;
Index: pdp11.c
RCS file: /cvs/gcc/egcs/gcc/config/pdp11/pdp11.c,v
retrieving revision 1.14
diff -c -3 -p -r1.14 pdp11.c
*** pdp11.c	2000/08/24 20:09:27	1.14
--- pdp11.c	2000/09/23 16:20:29
*************** Boston, MA 02111-1307, USA.  */
*** 34,39 ****
--- 34,40 ----
  #include "insn-attr.h"
  #include "flags.h"
  #include "recog.h"
+ #include "tree.h"
  #include "tm_p.h"

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]