blob: 590cb38cbaeec51f010ea603aa4d89f9fbe33156 [file] [log] [blame]
Andrew Geissler10fa1492020-12-11 16:25:29 -06001From 50f5f8341ba39f2e12eef4a149e59f71f032f7d3 Mon Sep 17 00:00:00 2001
Brad Bishop286d45c2018-10-02 15:21:57 -04002From: Mahesh Bodapati <mbodapat@xilinx.com>
Andrew Geissler10fa1492020-12-11 16:25:29 -06003Date: Tue, 10 Nov 2020 09:51:24 +0530
4Subject: [PATCH 24/54] [Patch, microblaze]: Add new bit-field instructions
Andrew Geisslera9ff2b32020-10-16 10:11:54 -05005
6This patches adds new bsefi and bsifi instructions.
7BSEFI- The instruction shall extract a bit field from a
8register and place it right-adjusted in the destination register.
9The other bits in the destination register shall be set to zero
10BSIFI- The instruction shall insert a right-adjusted bit field
11from a register at another position in the destination register.
12The rest of the bits in the destination register shall be unchanged
Brad Bishop286d45c2018-10-02 15:21:57 -040013
Brad Bishop26bdd442019-08-16 17:08:17 -040014Signed-off-by :Nagaraju Mekala <nmekala@xilix.com>
Brad Bishop286d45c2018-10-02 15:21:57 -040015---
Andrew Geissler10fa1492020-12-11 16:25:29 -060016 gcc/config/microblaze/microblaze.c | 5 ++
Andrew Geisslera9ff2b32020-10-16 10:11:54 -050017 gcc/config/microblaze/microblaze.h | 2 +
18 gcc/config/microblaze/microblaze.md | 73 +++++++++++++++++++++++++++++
Andrew Geissler10fa1492020-12-11 16:25:29 -060019 3 files changed, 80 insertions(+)
Brad Bishop286d45c2018-10-02 15:21:57 -040020
Andrew Geissler10fa1492020-12-11 16:25:29 -060021diff --git a/gcc/config/microblaze/microblaze.c b/gcc/config/microblaze/microblaze.c
22index 4710def18cf..14c652325a8 100644
23--- a/gcc/config/microblaze/microblaze.c
24+++ b/gcc/config/microblaze/microblaze.c
25@@ -164,6 +164,9 @@ int microblaze_no_unsafe_delay;
26 /* Set to one if the targeted core has the CLZ insn. */
27 int microblaze_has_clz = 0;
28
29+/* Set to one if the targeted core has barrel-shift and cpu > 10.0 */
30+int microblaze_has_bitfield = 0;
31+
32 /* Which CPU pipeline do we use. We haven't really standardized on a CPU
33 version having only a particular type of pipeline. There can still be
34 options on the CPU to scale pipeline features up or down. :(
35@@ -1850,6 +1853,8 @@ microblaze_option_override (void)
36 {
37 if (TARGET_AREA_OPTIMIZED_2)
38 microblaze_pipe = MICROBLAZE_PIPE_8;
39+ if (TARGET_BARREL_SHIFT)
40+ microblaze_has_bitfield = 1;
41 }
42
43 if (TARGET_MULTIPLY_HIGH && TARGET_SOFT_MUL)
Andrew Geisslera9ff2b32020-10-16 10:11:54 -050044diff --git a/gcc/config/microblaze/microblaze.h b/gcc/config/microblaze/microblaze.h
Andrew Geissler10fa1492020-12-11 16:25:29 -060045index 8a668278337..857cb1cd9d0 100644
Andrew Geisslera9ff2b32020-10-16 10:11:54 -050046--- a/gcc/config/microblaze/microblaze.h
47+++ b/gcc/config/microblaze/microblaze.h
48@@ -44,6 +44,7 @@ extern int microblaze_dbx_regno[];
49
50 extern int microblaze_no_unsafe_delay;
51 extern int microblaze_has_clz;
52+extern int microblaze_has_bitfield;
53 extern enum pipeline_type microblaze_pipe;
54
55 #define OBJECT_FORMAT_ELF
Andrew Geissler10fa1492020-12-11 16:25:29 -060056@@ -63,6 +64,7 @@ extern enum pipeline_type microblaze_pipe;
Andrew Geisslera9ff2b32020-10-16 10:11:54 -050057 /* Do we have CLZ? */
58 #define TARGET_HAS_CLZ (TARGET_PATTERN_COMPARE && microblaze_has_clz)
Andrew Geisslera9ff2b32020-10-16 10:11:54 -050059
Andrew Geissler10fa1492020-12-11 16:25:29 -060060+#define TARGET_HAS_BITFIELD (TARGET_BARREL_SHIFT && microblaze_has_bitfield)
Andrew Geisslera9ff2b32020-10-16 10:11:54 -050061 /* The default is to support PIC. */
62 #define TARGET_SUPPORTS_PIC 1
Andrew Geissler10fa1492020-12-11 16:25:29 -060063
Brad Bishop286d45c2018-10-02 15:21:57 -040064diff --git a/gcc/config/microblaze/microblaze.md b/gcc/config/microblaze/microblaze.md
Andrew Geissler10fa1492020-12-11 16:25:29 -060065index c407a81c51e..3e6e2b9276d 100644
Brad Bishop286d45c2018-10-02 15:21:57 -040066--- a/gcc/config/microblaze/microblaze.md
67+++ b/gcc/config/microblaze/microblaze.md
Andrew Geissler84ad7c52020-06-27 00:00:16 -050068@@ -982,6 +982,8 @@
Brad Bishop286d45c2018-10-02 15:21:57 -040069 (set_attr "mode" "DI")
70 (set_attr "length" "20,20,20")])
71
72+
73+
74 ;;----------------------------------------------------------------
75 ;; Data movement
76 ;;----------------------------------------------------------------
Andrew Geissler84ad7c52020-06-27 00:00:16 -050077@@ -1776,6 +1778,7 @@
Brad Bishop286d45c2018-10-02 15:21:57 -040078 (set_attr "length" "28")]
79 )
80
81+
82 ;;----------------------------------------------------------------
83 ;; Setting a register from an integer comparison.
84 ;;----------------------------------------------------------------
Andrew Geissler84ad7c52020-06-27 00:00:16 -050085@@ -2489,4 +2492,74 @@
Brad Bishop286d45c2018-10-02 15:21:57 -040086 DONE;
87 }")
88
89+(define_expand "extvsi"
90+ [(set (match_operand:SI 0 "register_operand" "r")
91+ (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
92+ (match_operand:SI 2 "immediate_operand" "I")
93+ (match_operand:SI 3 "immediate_operand" "I")))]
Andrew Geissler10fa1492020-12-11 16:25:29 -060094+""
Brad Bishop286d45c2018-10-02 15:21:57 -040095+"
96+{
97+ unsigned HOST_WIDE_INT len = UINTVAL (operands[2]);
98+ unsigned HOST_WIDE_INT pos = UINTVAL (operands[3]);
99+
100+ if ((len == 0) || (pos + len > 32) )
101+ FAIL;
102+
103+ ;;if (!register_operand (operands[1], VOIDmode))
104+ ;; FAIL;
105+ if (operands[0] == operands[1])
106+ FAIL;
107+ if (GET_CODE (operands[1]) == ASHIFT)
108+ FAIL;
109+;; operands[2] = GEN_INT(INTVAL(operands[2])+1 );
110+ emit_insn (gen_extv_32 (operands[0], operands[1],
111+ operands[2], operands[3]));
112+ DONE;
113+}")
114+
115+(define_insn "extv_32"
116+ [(set (match_operand:SI 0 "register_operand" "=r")
117+ (zero_extract:SI (match_operand:SI 1 "register_operand" "r")
118+ (match_operand:SI 2 "immediate_operand" "I")
119+ (match_operand:SI 3 "immediate_operand" "I")))]
Andrew Geissler10fa1492020-12-11 16:25:29 -0600120+ "TARGET_BARREL_SHIFT && (UINTVAL (operands[2]) > 0)
Brad Bishop286d45c2018-10-02 15:21:57 -0400121+ && ((UINTVAL (operands[2]) + UINTVAL (operands[3])) <= 32)"
122+ "bsefi %0,%1,%2,%3"
123+ [(set_attr "type" "bshift")
124+ (set_attr "length" "4")])
125+
126+(define_expand "insvsi"
127+ [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+r")
128+ (match_operand:SI 1 "immediate_operand" "I")
129+ (match_operand:SI 2 "immediate_operand" "I"))
130+ (match_operand:SI 3 "register_operand" "r"))]
Andrew Geissler10fa1492020-12-11 16:25:29 -0600131+ ""
Brad Bishop286d45c2018-10-02 15:21:57 -0400132+ "
133+{
134+ unsigned HOST_WIDE_INT len = UINTVAL (operands[1]);
135+ unsigned HOST_WIDE_INT pos = UINTVAL (operands[2]);
136+
137+ if (len <= 0 || pos + len > 32)
138+ FAIL;
139+
140+ ;;if (!register_operand (operands[0], VOIDmode))
141+ ;; FAIL;
142+
143+ emit_insn (gen_insv_32 (operands[0], operands[1],
144+ operands[2], operands[3]));
145+ DONE;
146+}")
147+
148+(define_insn "insv_32"
149+ [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+r")
150+ (match_operand:SI 1 "immediate_operand" "I")
151+ (match_operand:SI 2 "immediate_operand" "I"))
152+ (match_operand:SI 3 "register_operand" "r"))]
Andrew Geissler10fa1492020-12-11 16:25:29 -0600153+ "TARGET_BARREL_SHIFT && UINTVAL (operands[1]) > 0
Brad Bishop286d45c2018-10-02 15:21:57 -0400154+ && UINTVAL (operands[1]) + UINTVAL (operands[2]) <= 32"
155+ "bsifi %0, %3, %1, %2"
156+ [(set_attr "type" "bshift")
157+ (set_attr "length" "4")])
158+
159 (include "sync.md")
160--
Andrew Geisslera9ff2b32020-10-16 10:11:54 -05001612.17.1
Brad Bishop286d45c2018-10-02 15:21:57 -0400162