zyfeier commented on code in PR #8042:
URL: https://github.com/apache/nuttx/pull/8042#discussion_r1064315705


##########
libs/libc/machine/risc-v/gnu/arch_strcmp.S:
##########
@@ -0,0 +1,184 @@
+/****************************************************************************
+ * libs/libc/machine/risc-v/gnu/arch_strcmp.S
+ *
+ * Copyright (c) 2017  SiFive Inc. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the FreeBSD License.   This program is distributed in the hope that
+ * it will be useful, but WITHOUT ANY WARRANTY expressed or implied,
+ * including the implied warranties of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE.  A copy of this license is available at
+ * http://www.opensource.org/licenses.
+ *
+ ****************************************************************************/
+
+#include "asm.h"
+
+.text
+.globl strcmp
+.type  strcmp, @function
+strcmp:
+       or    a4, a0, a1
+       li    t2, -1
+       and   a4, a4, SZREG-1
+       bnez  a4, .Lmisaligned
+
+#if SZREG == 4
+       li a5, 0x7f7f7f7f
+#else
+       ld a5, mask
+#endif
+
+       .macro check_one_word i n
+               REG_L a2, \i*SZREG(a0)
+               REG_L a3, \i*SZREG(a1)
+
+               and   t0, a2, a5
+               or    t1, a2, a5
+               add   t0, t0, a5
+               or    t0, t0, t1
+
+               bne   t0, t2, .Lnull\i
+               .if \i+1-\n
+                       bne   a2, a3, .Lmismatch
+               .else
+                       add   a0, a0, \n*SZREG
+                       add   a1, a1, \n*SZREG
+                       beq   a2, a3, .Lloop
+                       # fall through to .Lmismatch
+               .endif
+       .endm
+
+       .macro foundnull i n
+               .ifne \i
+                       .Lnull\i:
+                       add   a0, a0, \i*SZREG
+                       add   a1, a1, \i*SZREG
+                       .ifeq \i-1
+                               .Lnull0:
+                       .endif
+                       bne   a2, a3, .Lmisaligned
+                       li    a0, 0
+                       ret
+               .endif
+       .endm
+
+.Lloop:
+  # examine full words at a time, favoring strings of a couple dozen chars
+#if __riscv_xlen == 32
+       check_one_word 0 5
+       check_one_word 1 5
+       check_one_word 2 5
+       check_one_word 3 5
+       check_one_word 4 5
+#else
+       check_one_word 0 3
+       check_one_word 1 3
+       check_one_word 2 3
+#endif
+  # backwards branch to .Lloop contained above
+
+.Lmismatch:
+  # words don't match, but a2 has no null byte.
+
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__

Review Comment:
   It's gcc predefined macro.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to