vak: (Default)
[personal profile] vak
Копируем байты посредством векторного процессора RISC-V.
	.globl memcpy, strcpy, strncpy

# void *memcpy(void* dest, const void* src, size_t n)
# a0=dest, a1=src, a2=n
#
memcpy:
mv a3, a0 # Copy destination
1: vsetvli a4, a2, e8,m4 # Vectors of 8b
vlb.v v0, (a1) # Load bytes
add a1, a1, a4 # Bump pointer
sub a2, a2, a4 # Decrement count
vsb.v v0, (a3) # Store bytes
add a3, a3, a4 # Bump pointer
bnez a2, 1b # Any more?
ret


# char* strcpy(char *dst, const char* src)
strcpy:
mv a2, a0 # Copy dst
1: vsetvli x0, x0, e8,m4 # Vectors of bytes
vlbuff.v v4, (a1) # Get src bytes
csrr t1, vl # Get number of bytes fetched
vmseq.vi v0, v4, 0 # Flag zero bytes
vmfirst.m a3, v0 # Zero found?
add a1, a1, t1 # Bump pointer
vmsif.m v0, v0 # Set mask up to and including zero byte.
vsb.v v4, (a2), v0.t # Write out bytes
add a2, a2, t1 # Bump pointer
bltz a3, 1b # Zero byte not found, so loop
ret


# char* strncpy(char *dst, const char* src, size_t n)
strncpy:
mv a3, a0 # Copy dst
1: vsetvli x0, a2, e8 # Vectors of bytes.
vlbuff.v v1, (a1) # Get src bytes
vmseq.vi v0, v1, 0 # Flag zero bytes
vmfirst.m a4, v0 # Zero found?
vmsif.m v0, v0 # Set mask up to and including zero byte.
vsb.v v1, (a3), v0.t # Write out bytes
bgez a4, 2f # Done
csrr t1, vl # Get number of bytes fetched
add a1, a1, t1 # Bump pointer
sub a2, a2, t1 # Decrement count.
add a3, a3, t1 # Bump pointer
bnez a2, 1b # Anymore?
2: ret
Отсюда: http://hoult.org/rvv_lib.s
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org