Skip to content

Commit f6256dd

Browse files
Claudiu Zissulescuartemiy-volkov
authored andcommitted
arc64: Add bitscan instructions.
Add the next bitscan instructions: NORM, NORMH, FFS, FLS, NORML, FFSL, FLSL which will support the next gcc builtins: clz - counting leading zeros ctz - counting trailing zeros clrsb - count leading redudant sign bits Signed-off-by: Claudiu Zissulescu <claziss@synopsys.com>
1 parent 852b55c commit f6256dd

File tree

3 files changed

+62
-5
lines changed

3 files changed

+62
-5
lines changed

gcc/config/arc64/arc64.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,14 @@ enum reg_class
340340
low-order few bits. */
341341
#define SHIFT_COUNT_TRUNCATED 1
342342

343+
/* Defines if the CLZ result is undefined or has a useful value. */
344+
#define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \
345+
((VALUE) = GET_MODE_SIZE((MODE)) * BITS_PER_UNIT - 1, 2)
346+
347+
/* Defines if the CTZ result is undefined or has a useful value. */
348+
#define CTZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \
349+
((VALUE) = GET_MODE_SIZE((MODE)) * BITS_PER_UNIT - 1, 2)
350+
343351
/* Function argument passing. */
344352

345353
/* Define a data type for recording info about an argument list during

gcc/config/arc64/arc64.md

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
ARC64_VUNSPEC_ATOOPS
9494

9595
ARC64_UNSPEC_MEMBAR
96+
ARC64_UNSPEC_FLS
9697
])
9798

9899
(include "constraints.md")
@@ -114,6 +115,9 @@
114115
;; Iterator for all integer modes (up to 64-bit)
115116
(define_mode_iterator ALLI [QI HI SI DI])
116117

118+
;; Iterator for HI SI and DI modes
119+
(define_mode_iterator EPI [HI SI DI])
120+
117121
;; This mode iterator allows :P to be used for patterns that operate on
118122
;; pointer-sized quantities. Exactly one of the two alternatives will match.
119123
(define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
@@ -238,11 +242,11 @@
238242
(define_attr "type" "abs, adcl, add, addhl, addl, and, andl, asl,
239243
asll, asr, asrl, atldop, atldlop, bic, bl, block, bmsk, branch,
240244
branchcc, brk, bset, bsetl, btst, bxor, bxorl, compare, dbnz, dmb, ex,
241-
div, divl, ext, flag, jl, jump, ld, llock, lsr, lsrl, lr, max, maxl,
242-
min, minl, move, movecc, mod, modl, neg, nop, norm, normh, norml, mpy,
243-
mpyl, not, notl, or, orl, return, ror,rol, sbcl, scond, setcc, sex,
244-
sr, st, sub, subl, swape, swapel, sync, trap, udiv, udivl, umod,
245-
umodl, unknown, xbfu, xor, xorl"
245+
div, divl, ext, ffs, fls, flag, jl, jump, ld, llock, lsr, lsrl, lr,
246+
max, maxl, min, minl, move, movecc, mod, modl, neg, nop, norm, normh,
247+
norml, mpy, mpyl, not, notl, or, orl, return, ror,rol, sbcl, scond,
248+
setcc, sex, sr, st, sub, subl, swape, swapel, sync, trap, udiv, udivl,
249+
umod, umodl, unknown, xbfu, xor, xorl"
246250
(const_string "unknown"))
247251

248252
(define_attr "iscompact" "yes,no,maybe" (const_string "no"))
@@ -1494,6 +1498,47 @@ umodl, unknown, xbfu, xor, xorl"
14941498
(set_attr "length" "4,8")
14951499
(set_attr "predicable" "no")])
14961500

1501+
;; -------------------------------------------------------------------
1502+
;; Bitscan
1503+
;; -------------------------------------------------------------------
1504+
1505+
(define_insn "clrsb<mode>2"
1506+
[(set (match_operand:EPI 0 "register_operand" "=r")
1507+
(clrsb:EPI (match_operand:EPI 1 "register_operand" "r")))]
1508+
"TARGET_BITSCAN"
1509+
"norm<sfxtab>\\t%0,%1"
1510+
[(set_attr "length" "4")
1511+
(set_attr "type" "norm<sfxtab>")])
1512+
1513+
(define_expand "clz<mode>2"
1514+
[(match_operand:GPI 0 "register_operand")
1515+
(match_operand:GPI 1 "register_operand")]
1516+
"TARGET_BITSCAN"
1517+
{
1518+
rtx tmp = gen_reg_rtx (<MODE>mode);
1519+
unsigned int size = GET_MODE_SIZE (<MODE>mode) * BITS_PER_UNIT - 1;
1520+
emit_insn (gen_arc64_fls<sfxtab>2 (tmp, operands[1]));
1521+
emit_insn (gen_sub<mode>3 (operands[0], GEN_INT (size), tmp));
1522+
DONE;
1523+
})
1524+
1525+
(define_insn "ctz<mode>2"
1526+
[(set (match_operand:GPI 0 "register_operand" "=r")
1527+
(ctz:GPI (match_operand:GPI 1 "register_operand" "r")))]
1528+
"TARGET_BITSCAN"
1529+
"ffs<sfxtab>\\t%0,%1"
1530+
[(set_attr "length" "4")
1531+
(set_attr "type" "ffs")])
1532+
1533+
(define_insn "arc64_fls<sfxtab>2"
1534+
[(set (match_operand:GPI 0 "register_operand" "=r")
1535+
(unspec:GPI [(match_operand:GPI 1 "register_operand" "r")]
1536+
ARC64_UNSPEC_FLS))]
1537+
"TARGET_BITSCAN"
1538+
"fls<sfxtab>\\t%0,%1"
1539+
[(set_attr "length" "4")
1540+
(set_attr "type" "fls")])
1541+
14971542
;; -------------------------------------------------------------------
14981543
;; Floating-point intrinsics
14991544
;; -------------------------------------------------------------------

gcc/config/arc64/arc64.opt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ mdiv-rem
6060
Target Report Var(TARGET_ARC64_DIVREM) Init(TARGET_ARC64_DIVREM_DEFAULT)
6161
Enable DIV-REM instructions.
6262

63+
mbitscan
64+
Target Mask(BITSCAN)
65+
Enable NORM, NORMH, FFS, FLS, NORML, FFSL, and FLSL bitscan instructions.
66+
6367
mcpu=
6468
Target RejectNegative Joined
6569
-mcpu= Generate code for specific ARCv3 CPU variant.

0 commit comments

Comments
 (0)