.text
ENTRY(strlen)
mv r6, r0 || ldi r2,
and3 r0, r0,
bnez r0, strlen_byte
;
strlen_word:
ld r0, @r6+
;
seth r5,
or3 r5, r5,
sll3 r7, r5,
strlen_word_loop:
ld r1, @r6+ || not r4, r0
sub r0, r5 || and r4, r7
and r4, r0
bnez r4, strlen_last_bytes
ld r0, @r6+ || not r4, r1
sub r1, r5 || and r4, r7
and r4, r1 || addi r2,
bnez r4, strlen_last_bytes
addi r2,
; NOTE: If a null char. exists, return 0.
; if ((x - 0x01010101) & ~x & 0x80808080)
; return 0;
;
strlen_byte:
ldb r1, @r6 || addi r6,
beqz r1, strlen_exit
addi r2,
;
strlen_last_bytes:
ldi r0,
;
strlen_byte_loop:
ldb r1, @r6 || addi r6,
addi r0,
bc.s strlen_exit || cmpz r0
addi r2,
;
strlen_exit:
mv r0, r2 || jmp r14
.text
ENTRY(strlen)
mv r6, r0
ldi r2,
and3 r0, r0,
bnez r0, strlen_byte
;
strlen_word:
ld r0, @r6+
;
seth r5,
or3 r5, r5,
sll3 r7, r5,
strlen_word_loop:
ld r1, @r6+
not r4, r0 ; NOTE: If a null char. exists, return 0.
sub r0, r5 ; if ((x - 0x01010101) & ~x & 0x80808080)
and r4, r7 ; return 0;
and r4, r0
bnez r4, strlen_last_bytes
addi r2,
;
ld r0, @r6+
not r4, r1 ; NOTE: If a null char. exists, return 0.
sub r1, r5 ; if ((x - 0x01010101) & ~x & 0x80808080)
and r4, r7 ; return 0;
and r4, r1
bnez r4, strlen_last_bytes
addi r2,
bra strlen_word_loop
;
strlen_byte:
ldb r1, @r6
addi r6,
beqz r1, strlen_exit
addi r2,
bra strlen_byte
;
strlen_last_bytes:
ldi r0,
addi r6,
;
strlen_byte_loop:
ldb r1, @r6
addi r6,
addi r0,
beqz r1, strlen_exit
addi r2,
bnez r0, strlen_byte_loop
;
strlen_exit:
mv r0, r2
jmp r14
.end