This is the mail archive of the gcc-patches@gcc.gnu.org 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]
Other format: [Raw text]

RE: [PATCH] H8300 Extend 8-bit constant address support to H8300 and H8S, 16-bit constant address support to H8S


Hi,

> 
> Hi Dhananjay,
> 
> > Currently aa:8 and aa:16 addressing mode is only supported 
> on H8300H.
> > The aa:8 mode can also be supported on H8300 and H8S, 
> likewise aa:16 can also 
> > be supported on H8S. 
> > Each of the above reduces code size by 2. 
> > 
> > 2002-09-12 Dhananjay Deshpande <dhananjayd@kpit.com>
> > 	* config/h8300/h8300.h (EIGHTBIT_CONSTANT_ADDRESS_P): 
> Add support for
> > 	  H8300, H8S aa:8 mode
> > 	  (TINY_CONSTANT_ADDRESS_P): Add support for H8S aa:16 mode 
> > 	* config/h8300/h8300.c  (h8300_adjust_insn_length): 
> Adjust length for
> >  	  H8300 aa:8 mode
> > 
> ==============================================================
> =================
> > --- h8300.h.orig	Thu Sep 12 12:09:55 2002
> > +++ h8300.h	Thu Sep 12 12:25:42 2002
> > @@ -822,20 +822,24 @@
> >     ? !h8300_shift_needs_scratch_p (INTVAL (OP), SImode)	\
> >     : 0)
> >  
> > -/* Nonzero if X is a constant address suitable as an 8-bit 
> absolute on
> > -   the H8/300H, which is a special case of the 'R' operand.  */
> > +/* Nonzero if X is a constant address suitable as an 8-bit 
> absolute,
> > +   which is a special case of the 'R' operand.  */
> >  
> > -#define EIGHTBIT_CONSTANT_ADDRESS_P(X)			\
> > -  (GET_CODE (X) == CONST_INT && TARGET_H8300H		\
> > -   && 0xffff00 <= INTVAL (X) && INTVAL (X) <= 0xffffff)
> > +#define EIGHTBIT_CONSTANT_ADDRESS_P(X)			
> 		      \
> > +  (GET_CODE (X) == CONST_INT && 				
> 	      \
> > +  ((TARGET_H8300H && 0xffff00 <= INTVAL (X) && INTVAL (X) 
> <= 0xffffff) ||     \
> > +  (TARGET_H8300S && 0xffffff00 <= INTVAL (X) && INTVAL (X) 
> <= 0xffffffff) ||  \
> > +  (TARGET_H8300 && 0xffffff00 <= INTVAL (X) && INTVAL (X) 
> <= 0xffffffff)))
> 
> I think H8/300 has 16-bit address, not 32-bit.  

Yes, that's true. But the problem is that as host int is 32 bit, INTVAL(x)
returns 32 bit value which is sign extension of 16 bit address. So the comparison
fails if it is compared with 0xff00 and 0xffff. May be it's good idea to mask the 
upper 16 bits returned by INTVAL(x). I have implemented this in patch below. 
( Earlier I thought that masking would be an added operation so its better to write constant )

> Also, it would be nice if you could fix the formatting like
> 
>   A
>   && (B
>       || C
>       || D)
> 
> See the GNU coding standard for details.

OK. Fixed in the patch below.

> 
> Doesn't H8/S have 24-bit address and 32-bit address depending on the
> operating mode?  I have to look into this.

I think 24-bit address and 32-bit address is not depending on operating mode.
Operating mode is Normal ( 16-bit address ) or Advanced ( 32-bit ).
Some of H8/S devices have only 24-bit address space. As we don't have any switch
to specify address space, we can't distinguish between 24-bit and 32-bit address
space. So we can only support aa:16 for 32 bit address. Hitachi compilers do have
an option to specify whether the CPU has 24-bit address space or 32-bit address 
space in advanced mode.

The programming manual of H8/S says that upper 16 bits of effective address in 
aa:16 mode are sign extension of 16 bit address specified in instruction. For the
devices which have only 24-bit address space the upper byte in effective address
is "don't care" so addresses in the range of 0x00FF8000 - 0x00FFFFFF is also valid 
for aa:16 on these devices. But as said earlier, we can't distinguish between
24-bit and 32-bit address space and default aa:32 mode will be used for this 
address range. Since the upper byte is ignored, users can take benefit by writing
constant address with upper byte as 0xff instead of 0x00.

Revised patch is given below.

2002-09-13 Dhananjay Deshpande <dhananjayd@kpit.com>
	* config/h8300/h8300.h (EIGHTBIT_CONSTANT_ADDRESS_P): Add support for
	  H8300, H8S aa:8 mode
	  (TINY_CONSTANT_ADDRESS_P): Add support for H8S aa:16 mode 
	* config/h8300/h8300.c  (h8300_adjust_insn_length): Adjust length for
 	  H8300 aa:8 mode
===============================================================================
--- h8300.h.orig	Thu Sep 12 12:09:55 2002
+++ h8300.h	Fri Sep 13 11:43:42 2002
@@ -822,20 +822,30 @@
    ? !h8300_shift_needs_scratch_p (INTVAL (OP), SImode)	\
    : 0)
 
-/* Nonzero if X is a constant address suitable as an 8-bit absolute on
-   the H8/300H, which is a special case of the 'R' operand.  */
+/* Nonzero if X is a constant address suitable as an 8-bit absolute,
+   which is a special case of the 'R' operand.  */
 
-#define EIGHTBIT_CONSTANT_ADDRESS_P(X)			\
-  (GET_CODE (X) == CONST_INT && TARGET_H8300H		\
-   && 0xffff00 <= INTVAL (X) && INTVAL (X) <= 0xffffff)
+#define EIGHTBIT_CONSTANT_ADDRESS_P(X)					\
+  ((GET_CODE (X) == CONST_INT)						\
+   && ((TARGET_H8300H && 0xffff00 <= INTVAL (X)				\
+	&& INTVAL (X) <= 0xffffff)					\
+       || (TARGET_H8300S && 0xffffff00 <= INTVAL (X)			\
+            && INTVAL (X) <= 0xffffffff)				\
+       || (TARGET_H8300 && 0xff00 <= (INTVAL (X) & 0x0000FFFF)		\
+	   && (INTVAL (X) & 0x0000FFFF) <= 0xffff)))
 
 /* Nonzero if X is a constant address suitable as an 16-bit absolute
-   on the H8/300H.  */
+   on H8/300H and H8/S.  */
 
-#define TINY_CONSTANT_ADDRESS_P(X)				\
-  (GET_CODE (X) == CONST_INT && TARGET_H8300H			\
-   && ((0xff8000 <= INTVAL (X) && INTVAL (X) <= 0xffffff)	\
-       || (0x000000 <= INTVAL (X) && INTVAL (X) <= 0x007fff)))
+#define TINY_CONSTANT_ADDRESS_P(X)					\
+  ((GET_CODE (X) == CONST_INT)						\
+   && ((TARGET_H8300H							\
+	&& ((0xff8000 <= INTVAL (X) && INTVAL (X) <= 0xffffff)		\
+	    || (0x000000 <= INTVAL (X) && INTVAL (X) <= 0x007fff)))	\
+       || (TARGET_H8300S						\
+	   && ((0xffff8000 <= INTVAL (X) && INTVAL (X) <= 0xffffffff)	\
+	       || (0x00000000 <= INTVAL (X)				\
+		   && INTVAL (X) <= 0x00007fff)))))
 
 /* 'U' if valid for a bset destination;
    i.e. a register, register indirect, or the eightbit memory region
===============================================================================
--- h8300.c.orig	Thu Sep 12 12:10:03 2002
+++ h8300.c	Thu Sep 12 13:48:13 2002
@@ -3719,6 +3719,12 @@
 	  /* @Rs is 2 bytes shorter than the longest.  */
 	  if (GET_CODE (addr) == REG)
 	    return -2;
+
+	  /* @aa:8 is 2 bytes shorter than the longest.  */
+	  if (GET_MODE (SET_SRC (pat)) == QImode
+	      && ((GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_FLAG (addr))
+		  || EIGHTBIT_CONSTANT_ADDRESS_P (addr)))
+	    return -2;
 	}
       else
 	{
===============================================================================

Regards,
Dhananjay

> 
> Kazu Hirata
> 


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