Skip to content

Commit 7c0ff35

Browse files
committed
arc: Use intrinsics for __builtin_mul_overflow ()
This patch handles both signed and unsigned builtin multiplication overflow. Uses the "mpy.f" instruction to set the condition codes based on the result. In the event of an overflow, the V flag is set, triggering a conditional move depending on the V flag status. For example, set "1" to "r0" in case of overflow: mov_s r0,1 mpy.f r0,r0,r1 j_s.d [blink] mov.nv r0,0 Signed-off-by: Luis Silva <[email protected]>
1 parent fc28c8f commit 7c0ff35

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

gcc/config/arc/arc.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,9 @@ archs4x, archs4xd"
842842
; Optab prefix for sign/zero-extending operations
843843
(define_code_attr su_optab [(sign_extend "") (zero_extend "u")])
844844

845+
;; Code iterator for sign/zero extension
846+
(define_code_iterator ANY_EXTEND [sign_extend zero_extend])
847+
845848
(define_insn "*<SEZ_prefix>xt<SQH_postfix>_cmp0_noout"
846849
[(set (match_operand 0 "cc_set_register" "")
847850
(compare:CC_ZN (SEZ:SI (match_operand:SQH 1 "register_operand" "r"))
@@ -1068,6 +1071,36 @@ archs4x, archs4xd"
10681071
(set_attr "cond" "set_zn")
10691072
(set_attr "length" "*,4,4,4,8")])
10701073

1074+
(define_expand "<su_optab>mulvsi4"
1075+
[(ANY_EXTEND:DI (match_operand:SI 0 "register_operand"))
1076+
(ANY_EXTEND:DI (match_operand:SI 1 "register_operand"))
1077+
(ANY_EXTEND:DI (match_operand:SI 2 "register_operand"))
1078+
(label_ref (match_operand 3 "" ""))]
1079+
"TARGET_MPY"
1080+
{
1081+
emit_insn (gen_<su_optab>mulsi3_Vcmp (operands[0], operands[1],
1082+
operands[2]));
1083+
arc_gen_unlikely_cbranch (NE, CC_Vmode, operands[3]);
1084+
DONE;
1085+
})
1086+
1087+
(define_insn "<su_optab>mulsi3_Vcmp"
1088+
[(parallel
1089+
[(set
1090+
(reg:CC_V CC_REG)
1091+
(compare:CC_V
1092+
(mult:DI
1093+
(ANY_EXTEND:DI (match_operand:SI 1 "register_operand" "%0,r,r,r"))
1094+
(ANY_EXTEND:DI (match_operand:SI 2 "nonmemory_operand" "I,L,r,C32")))
1095+
(ANY_EXTEND:DI (mult:SI (match_dup 1) (match_dup 2)))))
1096+
(set (match_operand:SI 0 "register_operand" "=r,r,r,r")
1097+
(mult:SI (match_dup 1) (match_dup 2)))])]
1098+
"register_operand (operands[1], SImode)
1099+
|| register_operand (operands[2], SImode)"
1100+
"mpy<su_optab>.f\\t%0,%1,%2"
1101+
[(set_attr "length" "4,4,4,8")
1102+
(set_attr "type" "mpy")])
1103+
10711104
(define_insn "*mulsi3_cmp0"
10721105
[(set (reg:CC_Z CC_REG)
10731106
(compare:CC_Z

0 commit comments

Comments
 (0)