URL
https://opencores.org/ocsvn/hf-risc/hf-risc/trunk
Subversion Repositories hf-risc
[/] [hf-risc/] [trunk/] [tools/] [riscv-gnu-toolchain-master/] [newlib/] [newlib/] [libc/] [machine/] [riscv/] [strcmp.S] - Rev 13
Compare with Previous | Blame | View Log
# Artisanally coded in California by A. Shell Waterman#include <sys/asm.h>#if BYTE_ORDER != LITTLE_ENDIAN# error#endif.text.globl strcmpstrcmp:or a4, a0, a1li t2, -1and a4, a4, SZREG-1bnez a4, .Lmisaligned#if SZREG == 4li t3, 0x7f7f7f7f#elseld t3, mask#endif.macro check_one_word i nREG_L a2, \i*SZREG(a0)REG_L a3, \i*SZREG(a1)and t0, a2, t3or t1, a2, t3add t0, t0, t3or t0, t0, t1bne t0, t2, .Lnull\i.if \i+1-\nbne a2, a3, .Lmismatch.elseadd a0, a0, \n*SZREGadd a1, a1, \n*SZREGbeq a2, a3, .Lloop# fall through to .Lmismatch.endif.endm.macro foundnull i n.ifne \i.Lnull\i:add a0, a0, \i*SZREGadd a1, a1, \i*SZREG.ifeq \i-1.Lnull0:.endifbne a2, a3, .Lmisalignedli a0, 0ret.endif.endm.Lloop:# examine full wordscheck_one_word 0 3check_one_word 1 3check_one_word 2 3# backwards branch to .Lloop contained above.Lmismatch:# words don't match, but a2 has no null byte.#ifdef __riscv64sll a4, a2, 48sll a5, a3, 48bne a4, a5, .Lmismatch_uppersll a4, a2, 32sll a5, a3, 32bne a4, a5, .Lmismatch_upper#endifsll a4, a2, 16sll a5, a3, 16bne a4, a5, .Lmismatch_uppersrl a4, a2, 8*SZREG-16srl a5, a3, 8*SZREG-16sub a0, a4, a5and a1, a0, 0xffbnez a1, 1fret.Lmismatch_upper:srl a4, a4, 8*SZREG-16srl a5, a5, 8*SZREG-16sub a0, a4, a5and a1, a0, 0xffbnez a1, 1fret1:and a4, a4, 0xffand a5, a5, 0xffsub a0, a4, a5ret.Lmisaligned:# misalignedlbu a2, 0(a0)lbu a3, 0(a1)add a0, a0, 1add a1, a1, 1bne a2, a3, 1fbnez a2, .Lmisaligned1:sub a0, a2, a3ret# cases in which a null byte was detectedfoundnull 0, 3foundnull 1, 3foundnull 2, 3#if SZREG == 8.section .srodata.cst8,"aM",@progbits,8.align 3mask:.dword 0x7f7f7f7f7f7f7f7f#endif
