Matching and testing against smulhsm3

m m@bitsnbites.eu
Fri Feb 7 14:41:00 GMT 2020


Hello!

I am trying to implement the following insns for my back end: smulhssi3, 
smulhshi3, smulhsqi3

According to [1], the operation should be equivalent to:

   narrow op0, op1, op2;
   op0 = (narrow) (((wide) op1 * (wide) op2) >> (N / 2 - 1));

...so I tried to write a corresponding matching pattern, like so:

   (define_insn "smulhshi3"
     [(set (match_operand:HI 0 "register_operand" "=r")
       (truncate:HI
         (ashiftrt:SI
           (mult:SI
             (sign_extend:SI (match_operand:HI 1 "register_operand" "r"))
             (sign_extend:SI (match_operand:HI 2 "register_operand" "r")))
           (const_int 15))))]
   "TARGET_PACKED_OPS"
   "mulq.h\\t%0, %1, %2")

However, I am unable to trigger this code path. I have tried with the 
following C code:

short mulq(short op1, short op2) {
   return (short) (((int) op1 * (int) op2) >> (32 / 2 - 1));
}

But I just get the regular 4-instruction result (2x sign extend, 1x mul, 
1x shift).

Are there any builtins that I need to use, or anything that I need to 
enable for my back end? Or should I use another pattern?

I also have similar problems with avgsi3_floor and friends.

Regards,

  Marcus


[1] https://gcc.gnu.org/onlinedocs/gccint/Standard-Names.html



More information about the Gcc mailing list