diff mbox series

[avr,applied] Use int types of exact width and signedness in built-ins prototypes

Message ID f80ae26b-1be9-4c23-9c91-34a7ddd57db0@gjlay.de
State New
Headers show
Series [avr,applied] Use int types of exact width and signedness in built-ins prototypes | expand

Commit Message

Georg-Johann Lay Feb. 20, 2024, 2:34 p.m. UTC
AVR: Use types of exact size and signedness in built-ins.

The AVR built-ins used types like "int" or "char" that don't
have exact signedness or type size which depend on -mint8
and -f[no-][un-]signed-char etc.  As the built-ins are modelling
machine instructions of given type sizes and signedness, also
use according types in their prototypes.

gcc/
	* config/avr/builtins.def: Use function prototypes of given size
	and signedness.
	* config/avr/avr.cc (avr_init_builtins): Adjust types required by 
builtins.def.
	* doc/extend.texi (AVR Built-in Functions): Adjust accordingly.
diff mbox series

Patch

diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc
index 4a55f14bff7..d3756a2f036 100644
--- a/gcc/config/avr/avr.cc
+++ b/gcc/config/avr/avr.cc
@@ -14605,35 +14605,35 @@  avr_init_builtins (void)
 {
   tree void_ftype_void
     = build_function_type_list (void_type_node, NULL_TREE);
-  tree uchar_ftype_uchar
-    = build_function_type_list (unsigned_char_type_node,
-				unsigned_char_type_node,
+  tree uintQI_ftype_uintQI
+    = build_function_type_list (unsigned_intQI_type_node,
+				unsigned_intQI_type_node,
 				NULL_TREE);
-  tree uint_ftype_uchar_uchar
-    = build_function_type_list (unsigned_type_node,
-				unsigned_char_type_node,
-				unsigned_char_type_node,
+  tree uintHI_ftype_uintQI_uintQI
+    = build_function_type_list (unsigned_intHI_type_node,
+				unsigned_intQI_type_node,
+				unsigned_intQI_type_node,
 				NULL_TREE);
-  tree int_ftype_char_char
-    = build_function_type_list (integer_type_node,
-				char_type_node,
-				char_type_node,
+  tree intHI_ftype_intQI_intQI
+    = build_function_type_list (intHI_type_node,
+				intQI_type_node,
+				intQI_type_node,
 				NULL_TREE);
-  tree int_ftype_char_uchar
-    = build_function_type_list (integer_type_node,
-				char_type_node,
-				unsigned_char_type_node,
+  tree intHI_ftype_intQI_uintQI
+    = build_function_type_list (intHI_type_node,
+				intQI_type_node,
+				unsigned_intQI_type_node,
 				NULL_TREE);
-  tree void_ftype_ulong
+  tree void_ftype_uintSI
     = build_function_type_list (void_type_node,
-				long_unsigned_type_node,
+				unsigned_intSI_type_node,
 				NULL_TREE);
 
-  tree uchar_ftype_ulong_uchar_uchar
-    = build_function_type_list (unsigned_char_type_node,
-				long_unsigned_type_node,
-				unsigned_char_type_node,
-				unsigned_char_type_node,
+  tree uintQI_ftype_uintSI_uintQI_uintQI
+    = build_function_type_list (unsigned_intQI_type_node,
+				unsigned_intSI_type_node,
+				unsigned_intQI_type_node,
+				unsigned_intQI_type_node,
 				NULL_TREE);
 
   tree const_memx_void_node
@@ -14644,8 +14644,8 @@  avr_init_builtins (void)
   tree const_memx_ptr_type_node
     = build_pointer_type_for_mode (const_memx_void_node, PSImode, false);
 
-  tree char_ftype_const_memx_ptr
-    = build_function_type_list (char_type_node,
+  tree intQI_ftype_const_memx_ptr
+    = build_function_type_list (intQI_type_node,
 				const_memx_ptr_type_node,
 				NULL);
 
diff --git a/gcc/config/avr/builtins.def b/gcc/config/avr/builtins.def
index b4bf7beb590..316bdebe498 100644
--- a/gcc/config/avr/builtins.def
+++ b/gcc/config/avr/builtins.def
@@ -43,17 +43,17 @@  DEF_BUILTIN (SLEEP, 0, void_ftype_void, sleep, NULL)
 /* Mapped to respective instruction but might also be folded away
    or emit as libgcc call if ISA does not provide the instruction.  */
 
-DEF_BUILTIN (SWAP,   1, uchar_ftype_uchar,      rotlqi3_4, NULL)
-DEF_BUILTIN (FMUL,   2, uint_ftype_uchar_uchar, fmul, NULL)
-DEF_BUILTIN (FMULS,  2, int_ftype_char_char,    fmuls, NULL)
-DEF_BUILTIN (FMULSU, 2, int_ftype_char_uchar,   fmulsu, NULL)
+DEF_BUILTIN (SWAP,   1, uintQI_ftype_uintQI,        rotlqi3_4, NULL)
+DEF_BUILTIN (FMUL,   2, uintHI_ftype_uintQI_uintQI, fmul, NULL)
+DEF_BUILTIN (FMULS,  2, intHI_ftype_intQI_intQI,    fmuls, NULL)
+DEF_BUILTIN (FMULSU, 2, intHI_ftype_intQI_uintQI,   fmulsu, NULL)
 
 /* More complex stuff that cannot be mapped 1:1 to an instruction.  */
 
-DEF_BUILTIN (DELAY_CYCLES, -1, void_ftype_ulong, nothing, NULL)
-DEF_BUILTIN (NOPS,         -1, void_ftype_ulong, nothing, NULL)
-DEF_BUILTIN (INSERT_BITS, 3, uchar_ftype_ulong_uchar_uchar, insert_bits, NULL)
-DEF_BUILTIN (FLASH_SEGMENT, 1, char_ftype_const_memx_ptr, flash_segment, NULL)
+DEF_BUILTIN (DELAY_CYCLES, -1, void_ftype_uintSI, nothing, NULL)
+DEF_BUILTIN (NOPS,         -1, void_ftype_uintSI, nothing, NULL)
+DEF_BUILTIN (INSERT_BITS, 3, uintQI_ftype_uintSI_uintQI_uintQI, insert_bits, NULL)
+DEF_BUILTIN (FLASH_SEGMENT, 1, intQI_ftype_const_memx_ptr, flash_segment, NULL)
 
 /* ISO/IEC TR 18037 "Embedded C"
    The following builtins are undocumented and used by stdfix.h.  */
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index b2383b55666..2135dfde9c8 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -16783,32 +16783,30 @@  or if not a specific built-in is implemented or not. For example, if
 @code{__BUILTIN_AVR_NOP} is defined to @code{1} and undefined otherwise.
 
 @defbuiltin{void __builtin_avr_nop (void)}
-@defbuiltinx{void __builtin_avr_nop (void)}
 @defbuiltinx{void __builtin_avr_sei (void)}
 @defbuiltinx{void __builtin_avr_cli (void)}
 @defbuiltinx{void __builtin_avr_sleep (void)}
 @defbuiltinx{void __builtin_avr_wdr (void)}
-@defbuiltinx{{unsigned char} __builtin_avr_swap (unsigned char)}
-@defbuiltinx{{unsigned int} __builtin_avr_fmul (unsigned char, unsigned char)}
-@defbuiltinx{int __builtin_avr_fmuls (char, char)}
-@defbuiltinx{int __builtin_avr_fmulsu (char, unsigned char)}
+@defbuiltinx{uint8_t __builtin_avr_swap (uint8_t)}
+@defbuiltinx{uint16_t __builtin_avr_fmul (uint8_t, uint8_t)}
+@defbuiltinx{int16_t __builtin_avr_fmuls (int8_t, int8_t)}
+@defbuiltinx{int16_t __builtin_avr_fmulsu (int8_t, uint8_t)}
 
 These built-in functions map to the respective machine
 instruction, i.e.@: @code{nop}, @code{sei}, @code{cli}, @code{sleep},
 @code{wdr}, @code{swap}, @code{fmul}, @code{fmuls}
 resp. @code{fmulsu}. The three @code{fmul*} built-ins are implemented
 as library call if no hardware multiplier is available.
-
 @enddefbuiltin
 
-@defbuiltin{void __builtin_avr_delay_cycles (unsigned long @var{ticks})}
+@defbuiltin{void __builtin_avr_delay_cycles (uint32_t @var{ticks})}
 Delay execution for @var{ticks} cycles. Note that this
 built-in does not take into account the effect of interrupts that
 might increase delay time. @var{ticks} must be a compile-time
 integer constant; delays with a variable number of cycles are not supported.
 @enddefbuiltin
 
-@defbuiltin{char __builtin_avr_flash_segment (const __memx void*)}
+@defbuiltin{int8_t __builtin_avr_flash_segment (const __memx void*)}
 This built-in takes a byte address to the 24-bit
 @ref{AVR Named Address Spaces,address space} @code{__memx} and returns
 the number of the flash segment (the 64 KiB chunk) where the address
@@ -16862,7 +16860,7 @@  __builtin_avr_insert_bits (0x01234567, bits, 0);
 @end smallexample
 @enddefbuiltin
 
-@defbuiltin{void __builtin_avr_nops (unsigned @var{count})}
+@defbuiltin{void __builtin_avr_nops (uint16_t @var{count})}
 Insert @var{count} @code{NOP} instructions.
 The number of instructions must be a compile-time integer constant.
 @enddefbuiltin