[EXT] [PATCH 1/1] riscv: Add Zbkb optimized repeat_bytes helper

Peter Bergner bergner@tenstorrent.com
Mon Sep 15 20:52:39 GMT 2025


On 9/15/25 7:40 AM, Pincheng Wang wrote:
> op_t zbkb_v2_repeat_bytes(unsigned char c_in) {
>    op_t out, t16;
>    __asm__ volatile (
>      "packh %0, %2, %2\n\t"
>      "pack %1, %0, %0"
>      : "=&r"(t16), "=&r"(out)
>      : "r"((op_t)c_in));
>    return out;
> }

The "=&r"(out) operand doesn't need to be marked early clobber, since
it is written after all the input and scratch registers have been
read/used.  It's that unnecessary early clobber that is giving you
the extra/unneeded mv insn.  Changing that operand to just "=r"(out),
I see the following asm:

zbkb_v2_repeat_bytes:
	packh a5, a0, a0
	pack a0, a5, a5
	ret

Peter



More information about the Libc-alpha mailing list