===================================================================
@@ -1812,21 +1812,25 @@
;; ----------------------------------------------------------------------
(define_expand "clzsi2"
- [(parallel [(set (match_operand:SI 0 "register_operand" "")
- (unspec:SI [(match_operand:SI 1 "register_operand" "")
- (const_int 0)] UNSPEC_BSCH))
+ [(parallel [(set (match_operand:SI 0 "register_operand")
+ (unspec:SI [(match_operand:SI 1 "register_operand")]
+ UNSPEC_BSCH))
(clobber (reg:CC CC_REG))])]
"TARGET_AM33"
)
+;; The XOR in the instruction sequence below is there because the BSCH
+;; instruction returns the bit number of the highest set bit and we want
+;; the number of zero bits above that bit. The AM33 does not have a
+;; reverse subtraction instruction, but we can use an xor instead since
+;; we know that the top 27 bits are clear.
(define_insn "*bsch"
- [(set (match_operand:SI 0 "register_operand" "=r")
- (unspec:SI [(match_operand:SI 1 "register_operand" "r")
- (match_operand:SI 2 "nonmemory_operand" "0")]
+ [(set (match_operand:SI 0 "register_operand" "=&r")
+ (unspec:SI [(match_operand:SI 1 "register_operand" "r")]
UNSPEC_BSCH))
(clobber (reg:CC CC_REG))]
"TARGET_AM33"
- "bsch %1,%0"
+ "clr %0 ; bsch %1, %0; xor 31, %0"
)
;; ----------------------------------------------------------------------