On 8/30/21 4:15 AM, Philipp Tomsich wrote:
+ TCGv tmp = tcg_temp_new(); + + /* Set msb in each byte if the byte was zero. */ + tcg_gen_subi_tl(tmp, source1, dup_const(MO_8, 0x01)); + tcg_gen_andc_tl(tmp, tmp, source1); + tcg_gen_andi_tl(tmp, tmp, dup_const(MO_8, 0x80)); + + /* Replicate the msb of each byte across the byte. */ + tcg_gen_shri_tl(tmp, tmp, 7); + tcg_gen_muli_tl(tmp, tmp, 0xff); + + /* Negate */ + tcg_gen_not_tl(ret, tmp);
It just occurred to me that we can swap the shift/andi and re-use the same constant, and we can fold in the negate with andc.
TCGv ones = tcg_constant_tl(dup_const(MO_8, 1)); TCGv tmp = tcg_temp_new(); tcg_gen_sub_tl(tmp, src1, ones); tcg_gen_andc_tl(tmp, tmp, src1); tcg_gen_shri_tl(tmp, tmp, 7); tcg_gen_andc_tl(tmp, ones, tmp); tcg_gen_muli_tl(tmp, tmp, 0xff); tcg_temp_free(tmp); r~