extend.texi (AVR Built-in Functions): Document __builtin_avr_flash_segment.
authorGeorg-Johann Lay <avr@gjlay.de>
Thu, 1 Mar 2012 15:28:44 +0000 (15:28 +0000)
committerGeorg-Johann Lay <gjl@gcc.gnu.org>
Thu, 1 Mar 2012 15:28:44 +0000 (15:28 +0000)
* doc/extend.texi (AVR Built-in Functions): Document
__builtin_avr_flash_segment.
* config/avr/builtins.def (__builtin_avr_flash_segment): New entry.
* config/avr/avr.md (flash_segment, flash_segment1): New expanders.
(*split.flash_segment): New insn-and-split.
* config/avr/avr.c (avr_init_builtins): Add local variables:
const_memx_void_node, const_memx_ptr_type_node,
char_ftype_const_memx_ptr.

From-SVN: r184746

gcc/ChangeLog
gcc/config/avr/avr.c
gcc/config/avr/avr.md
gcc/config/avr/builtins.def
gcc/doc/extend.texi

index 8cedbf526c0d67e2b14ac84db23604452e3629a5..0ffa80207b7d739feebacc0c43d89674bfd8d452 100644 (file)
@@ -1,3 +1,15 @@
+2012-03-01  Georg-Johann Lay  <avr@gjlay.de>
+
+       * doc/extend.texi (AVR Built-in Functions): Document
+       __builtin_avr_flash_segment.
+
+       * config/avr/builtins.def (__builtin_avr_flash_segment): New entry.
+       * config/avr/avr.md (flash_segment, flash_segment1): New expanders.
+       (*split.flash_segment): New insn-and-split.
+       * config/avr/avr.c (avr_init_builtins): Add local variables:
+       const_memx_void_node, const_memx_ptr_type_node,
+       char_ftype_const_memx_ptr.
+
 2012-03-01  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/52445
index 73afc480584cb43e7f066a9ae5d96dc14a066660..7ead6f47d13b19d6185a230e87528a2dbb74694f 100644 (file)
@@ -10432,6 +10432,19 @@ avr_init_builtins (void)
                                 unsigned_char_type_node,
                                 NULL_TREE);
 
+  tree const_memx_void_node
+      = build_qualified_type (void_type_node,
+                              TYPE_QUAL_CONST
+                              | ENCODE_QUAL_ADDR_SPACE (ADDR_SPACE_MEMX));
+
+  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,
+                                  const_memx_ptr_type_node,
+                                  NULL);
+
 #define DEF_BUILTIN(NAME, N_ARGS, ID, TYPE, CODE)                       \
   add_builtin_function (NAME, TYPE, ID, BUILT_IN_MD, NULL, NULL_TREE);
 #include "builtins.def"  
index 73f273f69471e0bccf289ef16b2b7464b8bbdd35..5cc3e3e4f249d89e5f1df8b4546a0ecca54919cb 100644 (file)
    (set_attr "cc" "clobber")])
 
 
+;; __builtin_avr_flash_segment
+
+;; Just a helper for the next "official" expander.
+
+(define_expand "flash_segment1"
+  [(set (match_operand:QI 0 "register_operand" "")
+        (subreg:QI (match_operand:PSI 1 "register_operand" "")
+                   2))
+   (set (cc0)
+        (compare (match_dup 0)
+                 (const_int 0)))
+   (set (pc)
+        (if_then_else (ge (cc0)
+                          (const_int 0))
+                      (label_ref (match_operand 2 "" ""))
+                      (pc)))
+   (set (match_dup 0)
+        (const_int -1))])
+
+(define_expand "flash_segment"
+  [(parallel [(match_operand:QI 0 "register_operand" "")
+              (match_operand:PSI 1 "register_operand" "")])]
+  ""
+  {
+    rtx label = gen_label_rtx ();
+    emit (gen_flash_segment1 (operands[0], operands[1], label));
+    emit_label (label);
+    DONE;
+  })
+
+;; Actually, it's too late now to work out address spaces known at compiletime.
+;; Best place would be to fold ADDR_SPACE_CONVERT_EXPR in avr_fold_builtin.
+;; However, avr_addr_space_convert can add some built-in knowledge for PSTR
+;; so that ADDR_SPACE_CONVERT_EXPR in the built-in must not be resolved.
+
+(define_insn_and_split "*split.flash_segment"
+  [(set (match_operand:QI 0 "register_operand"                        "=d")
+        (subreg:QI (lo_sum:PSI (match_operand:QI 1 "nonmemory_operand" "ri")
+                               (match_operand:HI 2 "register_operand"  "r"))
+                   2))]
+  ""
+  { gcc_unreachable(); }
+  ""
+  [(set (match_dup 0)
+        (match_dup 1))])
+
+
 ;; Parity
 
 ;; Postpone expansion of 16-bit parity to libgcc call until after combine for
index 4aa0f1159f914a7a46614f84dabf1f6a4796c52a..24537052eb01a51dc5b612505466e822d47c6a7a 100644 (file)
@@ -48,3 +48,4 @@ DEF_BUILTIN ("__builtin_avr_fmulsu", 2, AVR_BUILTIN_FMULSU, int_ftype_char_uchar
 /* More complex stuff that cannot be mapped 1:1 to an instruction.  */
 DEF_BUILTIN ("__builtin_avr_delay_cycles", -1, AVR_BUILTIN_DELAY_CYCLES, void_ftype_ulong, -1)
 DEF_BUILTIN ("__builtin_avr_insert_bits", 3, AVR_BUILTIN_INSERT_BITS, uchar_ftype_ulong_uchar_uchar, CODE_FOR_insert_bits)
+DEF_BUILTIN ("__builtin_avr_flash_segment", 1, AVR_BUILTIN_FLASH_SEGMENT, char_ftype_const_memx_ptr, CODE_FOR_flash_segment)
index 990192c93115afa3b79004ca04c03377f814bae6..aa3518c585ad0db5e3a0d5784f64e56cb405214d 100644 (file)
@@ -8809,7 +8809,18 @@ might increase delay time. @code{ticks} must be a compile time
 integer constant; delays with a variable number of cycles are not supported.
 
 @smallexample
-     unsigned char __builtin_avr_insert_bits (unsigned long map, unsigned char bits, unsigned char val)
+char __builtin_avr_flash_segment (const __memx void*)
+@end smallexample
+
+@noindent
+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
+points to.  Counting starts at @code{0}.
+If the address does not point to flash memory, return @code{-1}.
+
+@smallexample
+unsigned char __builtin_avr_insert_bits (unsigned long map, unsigned char bits, unsigned char val)
 @end smallexample
 
 @noindent