0016-strxxx-B-ext-opt-version.patch 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. From cb7b9da1f6e784440bbebc2377acc0e6d888e1a4 Mon Sep 17 00:00:00 2001
  2. From: "yilun.xie" <yilun.xie@starfivetech.com>
  3. Date: Wed, 10 Aug 2022 00:16:46 -0700
  4. Subject: [PATCH 16/19] strxxx B ext opt version
  5. ---
  6. sysdeps/riscv/rv64/multiarch/Makefile | 3 +-
  7. .../riscv/rv64/multiarch/ifunc-impl-list.c | 12 +++
  8. sysdeps/riscv/rv64/multiarch/rtld-strchr.S | 1 +
  9. sysdeps/riscv/rv64/multiarch/rtld-strchrnul.S | 1 +
  10. sysdeps/riscv/rv64/multiarch/rtld-strlen.S | 1 +
  11. sysdeps/riscv/rv64/multiarch/rtld-strlen.c | 1 -
  12. sysdeps/riscv/rv64/multiarch/rtld-strncmp.S | 1 +
  13. sysdeps/riscv/rv64/multiarch/strcmp.c | 1 -
  14. sysdeps/riscv/rv64/multiarch/strcmp_as.S | 85 ++++++++++++++++---
  15. sysdeps/riscv/rv64/multiarch/strcmp_riscv.S | 17 ++++
  16. sysdeps/riscv/rv64/multiarch/strlen_as.S | 56 ++++++++++++
  17. .../{strlen_riscv.c => strlen_riscv.S} | 23 ++---
  18. sysdeps/riscv/rv64/strchr.S | 81 ++++++++++++++++++
  19. sysdeps/riscv/rv64/strchrnul.S | 79 +++++++++++++++++
  20. sysdeps/riscv/rv64/strncmp.S | 73 ++++++++++++++++
  21. sysdeps/riscv/rv64/strnlen.S | 62 ++++++++++++++
  22. 16 files changed, 471 insertions(+), 26 deletions(-)
  23. create mode 100644 sysdeps/riscv/rv64/multiarch/rtld-strchr.S
  24. create mode 100644 sysdeps/riscv/rv64/multiarch/rtld-strchrnul.S
  25. create mode 100644 sysdeps/riscv/rv64/multiarch/rtld-strlen.S
  26. delete mode 100644 sysdeps/riscv/rv64/multiarch/rtld-strlen.c
  27. create mode 100644 sysdeps/riscv/rv64/multiarch/rtld-strncmp.S
  28. create mode 100644 sysdeps/riscv/rv64/multiarch/strlen_as.S
  29. rename sysdeps/riscv/rv64/multiarch/{strlen_riscv.c => strlen_riscv.S} (60%)
  30. create mode 100644 sysdeps/riscv/rv64/strchr.S
  31. create mode 100644 sysdeps/riscv/rv64/strchrnul.S
  32. create mode 100644 sysdeps/riscv/rv64/strncmp.S
  33. create mode 100644 sysdeps/riscv/rv64/strnlen.S
  34. diff --git a/sysdeps/riscv/rv64/multiarch/Makefile b/sysdeps/riscv/rv64/multiarch/Makefile
  35. index 7e8bfde544..3123ced35d 100644
  36. --- a/sysdeps/riscv/rv64/multiarch/Makefile
  37. +++ b/sysdeps/riscv/rv64/multiarch/Makefile
  38. @@ -1,5 +1,6 @@
  39. ifeq ($(subdir),string)
  40. sysdep_routines += memcpy_vector memcpy_riscv memchr_riscv memchr_vector memcmp_riscv \
  41. memcmp_vector strcmp_riscv strcmp_vector strlen_riscv strlen_vector \
  42. - memmove_vector memmove_riscv memset_vector memset_riscv memrchr
  43. + memmove_vector memmove_riscv memset_vector memset_riscv memrchr \
  44. +
  45. endif
  46. diff --git a/sysdeps/riscv/rv64/multiarch/ifunc-impl-list.c b/sysdeps/riscv/rv64/multiarch/ifunc-impl-list.c
  47. index 1a6611ab88..7bba6fa30c 100644
  48. --- a/sysdeps/riscv/rv64/multiarch/ifunc-impl-list.c
  49. +++ b/sysdeps/riscv/rv64/multiarch/ifunc-impl-list.c
  50. @@ -60,6 +60,18 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
  51. IFUNC_IMPL (i, name, memset,
  52. IFUNC_IMPL_ADD (array, i, memset, use_rvv, __memset_vector)
  53. IFUNC_IMPL_ADD (array, i, memset, 1, __memset_riscv));
  54. +
  55. + IFUNC_IMPL (i, name, strchr,
  56. + IFUNC_IMPL_ADD (array, i, strchr, use_rvv, __strchr_riscv)
  57. + IFUNC_IMPL_ADD (array, i, strchr, 1, __strchr_riscv));
  58. +
  59. + IFUNC_IMPL (i, name, strchrnul,
  60. + IFUNC_IMPL_ADD (array, i, strchrnul, use_rvv, __strchrnul_riscv)
  61. + IFUNC_IMPL_ADD (array, i, strchrnul, 1, __strchrnul_riscv));
  62. +
  63. + IFUNC_IMPL (i, name, strncmp,
  64. + IFUNC_IMPL_ADD (array, i, strncmp, use_rvv, __strncmp_riscv)
  65. + IFUNC_IMPL_ADD (array, i, strncmp, 1, __strncmp_riscv));
  66. #endif
  67. return i;
  68. }
  69. diff --git a/sysdeps/riscv/rv64/multiarch/rtld-strchr.S b/sysdeps/riscv/rv64/multiarch/rtld-strchr.S
  70. new file mode 100644
  71. index 0000000000..d969c0ab57
  72. --- /dev/null
  73. +++ b/sysdeps/riscv/rv64/multiarch/rtld-strchr.S
  74. @@ -0,0 +1 @@
  75. +#include "../strchr.S"
  76. diff --git a/sysdeps/riscv/rv64/multiarch/rtld-strchrnul.S b/sysdeps/riscv/rv64/multiarch/rtld-strchrnul.S
  77. new file mode 100644
  78. index 0000000000..5799994393
  79. --- /dev/null
  80. +++ b/sysdeps/riscv/rv64/multiarch/rtld-strchrnul.S
  81. @@ -0,0 +1 @@
  82. +#include "../strchrnul.S"
  83. diff --git a/sysdeps/riscv/rv64/multiarch/rtld-strlen.S b/sysdeps/riscv/rv64/multiarch/rtld-strlen.S
  84. new file mode 100644
  85. index 0000000000..801def494d
  86. --- /dev/null
  87. +++ b/sysdeps/riscv/rv64/multiarch/rtld-strlen.S
  88. @@ -0,0 +1 @@
  89. +#include "strlen_as.S"
  90. diff --git a/sysdeps/riscv/rv64/multiarch/rtld-strlen.c b/sysdeps/riscv/rv64/multiarch/rtld-strlen.c
  91. deleted file mode 100644
  92. index d3f1dd4a23..0000000000
  93. --- a/sysdeps/riscv/rv64/multiarch/rtld-strlen.c
  94. +++ /dev/null
  95. @@ -1 +0,0 @@
  96. -# include <string/strlen.c>
  97. diff --git a/sysdeps/riscv/rv64/multiarch/rtld-strncmp.S b/sysdeps/riscv/rv64/multiarch/rtld-strncmp.S
  98. new file mode 100644
  99. index 0000000000..c5a02a137c
  100. --- /dev/null
  101. +++ b/sysdeps/riscv/rv64/multiarch/rtld-strncmp.S
  102. @@ -0,0 +1 @@
  103. +#include "../strncmp.S"
  104. diff --git a/sysdeps/riscv/rv64/multiarch/strcmp.c b/sysdeps/riscv/rv64/multiarch/strcmp.c
  105. index 3b65aaf55d..d18ae03246 100644
  106. --- a/sysdeps/riscv/rv64/multiarch/strcmp.c
  107. +++ b/sysdeps/riscv/rv64/multiarch/strcmp.c
  108. @@ -28,7 +28,6 @@
  109. # include "ifunc-common.h"
  110. riscv_libc_ifunc_redirected (__redirect_strcmp, strcmp, IFUNC_SELECTOR);
  111. -
  112. riscv_libc_ifunc_hidden_def (__redirect_strcmp, strcmp);
  113. #else
  114. # include <string.h>
  115. diff --git a/sysdeps/riscv/rv64/multiarch/strcmp_as.S b/sysdeps/riscv/rv64/multiarch/strcmp_as.S
  116. index db5a6346b8..40bdbfef08 100644
  117. --- a/sysdeps/riscv/rv64/multiarch/strcmp_as.S
  118. +++ b/sysdeps/riscv/rv64/multiarch/strcmp_as.S
  119. @@ -19,21 +19,82 @@
  120. <http://www.gnu.org/licenses/>. */
  121. #include <sysdep.h>
  122. +#define N 3
  123. .p2align 6
  124. ENTRY (strcmp)
  125. -.L_strcmp_by_byte:
  126. - lbu a5,0(a0)
  127. - addi a1,a1,1
  128. - addi a0,a0,1
  129. - lbu a4,-1(a1)
  130. - beqz a5,.L_strcmp_by_byte_exit
  131. - beq a5,a4,.L_strcmp_by_byte
  132. - subw a0,a5,a4
  133. - ret
  134. -.L_strcmp_by_byte_exit:
  135. - negw a0,a4
  136. - ret
  137. + or a4, a0, a1
  138. + li t2, -1
  139. + and a4, a4, 7
  140. + beqz a4, .Lenter
  141. + j .Lmisaligned
  142. +
  143. + .macro check_one_word i n
  144. + ld a2, \i*8(a0)
  145. + ld a3, \i*8(a1)
  146. +
  147. + orc.b t0, a2
  148. +
  149. + bne t0, t2, .Lnull\i
  150. + .if \i+1-\n
  151. + bne a2, a3, .Lmismatch
  152. + .else
  153. + beq a2, a3, .Lloop
  154. + # fall through to .Lmismatch
  155. + .endif
  156. + .endm
  157. +
  158. + .macro foundnull i n
  159. + .ifne \i
  160. + .Lnull\i:
  161. + add a0, a0, \i*8
  162. + add a1, a1, \i*8
  163. + .ifeq \i-1
  164. + .Lnull0:
  165. + .endif
  166. + bne a2, a3, .Lmisaligned
  167. + li a0, 0
  168. + ret
  169. + .endif
  170. + .endm
  171. +
  172. +.Lloop:
  173. + add a0, a0, N*8
  174. + add a1, a1, N*8
  175. +
  176. +.Lenter:
  177. + # examine full words at a time, favoring strings of a couple dozen chars
  178. + check_one_word 0 N
  179. + check_one_word 1 N
  180. + check_one_word 2 N
  181. + # backwards branch to .Lloop contained above
  182. +
  183. +.Lmismatch:
  184. + rev8 a4, a2
  185. + rev8 a5, a3
  186. + bgeu a4, a5, 1f
  187. + li a0, -1
  188. + ret
  189. +1:
  190. + li a0, 1
  191. + ret
  192. +
  193. +.Lmisaligned:
  194. + # misaligned
  195. + lbu a2, 0(a0)
  196. + lbu a3, 0(a1)
  197. + add a0, a0, 1
  198. + add a1, a1, 1
  199. + bne a2, a3, 1f
  200. + bnez a2, .Lmisaligned
  201. +1:
  202. + sub a0, a2, a3
  203. + ret
  204. +
  205. + # cases in which a null byte was detected
  206. + foundnull 0 N
  207. + foundnull 1 N
  208. + foundnull 2 N
  209. END (strcmp)
  210. libc_hidden_builtin_def (strcmp)
  211. diff --git a/sysdeps/riscv/rv64/multiarch/strcmp_riscv.S b/sysdeps/riscv/rv64/multiarch/strcmp_riscv.S
  212. index abf2984230..8a2bfa9629 100644
  213. --- a/sysdeps/riscv/rv64/multiarch/strcmp_riscv.S
  214. +++ b/sysdeps/riscv/rv64/multiarch/strcmp_riscv.S
  215. @@ -1,3 +1,20 @@
  216. +/* The assembly function for strcmp. RISC-V version.
  217. + Copyright (C) 2018 Free Software Foundation, Inc.
  218. + This file is part of the GNU C Library.
  219. +
  220. + The GNU C Library is free software; you can redistribute it and/or
  221. + modify it under the terms of the GNU Lesser General Public
  222. + License as published by the Free Software Foundation; either
  223. + version 2.1 of the License, or (at your option) any later version.
  224. +
  225. + The GNU C Library is distributed in the hope that it will be useful,
  226. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  227. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  228. + Lesser General Public License for more details.
  229. +
  230. + You should have received a copy of the GNU Lesser General Public
  231. + License along with the GNU C Library. If not, see
  232. + <http://www.gnu.org/licenses/>. */
  233. #include <sysdep.h>
  234. diff --git a/sysdeps/riscv/rv64/multiarch/strlen_as.S b/sysdeps/riscv/rv64/multiarch/strlen_as.S
  235. new file mode 100644
  236. index 0000000000..862f5ebb72
  237. --- /dev/null
  238. +++ b/sysdeps/riscv/rv64/multiarch/strlen_as.S
  239. @@ -0,0 +1,56 @@
  240. +/* The assembly function for strlen. RISC-V version.
  241. + Copyright (C) 2018 Free Software Foundation, Inc.
  242. + This file is part of the GNU C Library.
  243. +
  244. + The GNU C Library is free software; you can redistribute it and/or
  245. + modify it under the terms of the GNU Lesser General Public
  246. + License as published by the Free Software Foundation; either
  247. + version 2.1 of the License, or (at your option) any later version.
  248. +
  249. + The GNU C Library is distributed in the hope that it will be useful,
  250. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  251. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  252. + Lesser General Public License for more details.
  253. +
  254. + You should have received a copy of the GNU Lesser General Public
  255. + License along with the GNU C Library. If not, see
  256. + <http://www.gnu.org/licenses/>. */
  257. +
  258. +#include <sysdep.h>
  259. +
  260. + .p2align 6
  261. +ENTRY (strlen)
  262. + andi a3, a0, 7
  263. + andi a1, a0, -8
  264. +.Lprologue:
  265. + li a4, 8
  266. + sub a4, a4, a3
  267. + slli a3, a3, 3
  268. + ld a2, 0(a1)
  269. + srl a2, a2, a3
  270. + orc.b a2, a2
  271. + not a2, a2
  272. + ctz a2, a2
  273. + srli a0, a2, 3
  274. + bgtu a4, a0, .Ldone
  275. + addi a3, a1, 8
  276. + li a4, -1
  277. +
  278. + .align 2
  279. +.Lloop:
  280. + ld a2, 8(a1)
  281. + addi a1, a1, 8
  282. + orc.b a2, a2
  283. + beq a2, a4, .Lloop
  284. +.Lepilogue:
  285. + not a2, a2
  286. + ctz a2, a2
  287. + sub a1, a1, a3
  288. + add a0, a0, a1
  289. + srli a2, a2, 3
  290. + add a0, a0, a2
  291. +.Ldone:
  292. + ret
  293. +
  294. +END (strlen)
  295. +libc_hidden_builtin_def (strlen)
  296. \ No newline at end of file
  297. diff --git a/sysdeps/riscv/rv64/multiarch/strlen_riscv.c b/sysdeps/riscv/rv64/multiarch/strlen_riscv.S
  298. similarity index 60%
  299. rename from sysdeps/riscv/rv64/multiarch/strlen_riscv.c
  300. rename to sysdeps/riscv/rv64/multiarch/strlen_riscv.S
  301. index d3bae0fc43..d6fd969afb 100644
  302. --- a/sysdeps/riscv/rv64/multiarch/strlen_riscv.c
  303. +++ b/sysdeps/riscv/rv64/multiarch/strlen_riscv.S
  304. @@ -1,5 +1,5 @@
  305. -/* RISCV C version strlen.
  306. - Copyright (C) 2018-2021 Free Software Foundation, Inc.
  307. +/* The assembly function for strlen. RISC-V version.
  308. + Copyright (C) 2018 Free Software Foundation, Inc.
  309. This file is part of the GNU C Library.
  310. The GNU C Library is free software; you can redistribute it and/or
  311. @@ -13,20 +13,21 @@
  312. Lesser General Public License for more details.
  313. You should have received a copy of the GNU Lesser General Public
  314. - License along with the GNU C Library; if not, see
  315. - <https://www.gnu.org/licenses/>. */
  316. + License along with the GNU C Library. If not, see
  317. + <http://www.gnu.org/licenses/>. */
  318. +#include <sysdep.h>
  319. -#if IS_IN (libc) && defined SHARED && defined __riscv_vector
  320. -#undef libc_hidden_builtin_def
  321. -#define libc_hidden_builtin_def(name)
  322. +#if IS_IN (libc) && defined SHARED && defined __riscv_vector
  323. +# define strlen __strlen_riscv
  324. +# undef libc_hidden_builtin_def
  325. +# define libc_hidden_builtin_def(name)
  326. +
  327. +# include "strlen_as.S"
  328. -#undef weak_alias
  329. -# define STRLEN __strlen_riscv
  330. -# include <string/strlen.c>
  331. #else
  332. +# include "strlen_as.S"
  333. -# include <string/strlen.c>
  334. #endif
  335. diff --git a/sysdeps/riscv/rv64/strchr.S b/sysdeps/riscv/rv64/strchr.S
  336. new file mode 100644
  337. index 0000000000..a9059c19ca
  338. --- /dev/null
  339. +++ b/sysdeps/riscv/rv64/strchr.S
  340. @@ -0,0 +1,81 @@
  341. +/* The assembly function for strchr. RISC-V version.
  342. + Copyright (C) 2018 Free Software Foundation, Inc.
  343. + This file is part of the GNU C Library.
  344. +
  345. + The GNU C Library is free software; you can redistribute it and/or
  346. + modify it under the terms of the GNU Lesser General Public
  347. + License as published by the Free Software Foundation; either
  348. + version 2.1 of the License, or (at your option) any later version.
  349. +
  350. + The GNU C Library is distributed in the hope that it will be useful,
  351. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  352. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  353. + Lesser General Public License for more details.
  354. +
  355. + You should have received a copy of the GNU Lesser General Public
  356. + License along with the GNU C Library. If not, see
  357. + <http://www.gnu.org/licenses/>. */
  358. +
  359. +#include <sysdep.h>
  360. +
  361. + .p2align 6
  362. +ENTRY (strchr)
  363. + andi a1, a1, 0xff
  364. +
  365. +.Lmisaligned:
  366. + andi a5, a0, 7
  367. + beqz a5, .Laligned
  368. + lbu a5, 0(a0)
  369. + beq a5, a1, .Ldone
  370. + beqz a5, .Lnofind
  371. + addi a0, a0, 1
  372. + j .Lmisaligned
  373. +
  374. +.Laligned:
  375. + slli a5, a1, 0x8
  376. + or a5, a5, a1
  377. + slli t0, a5, 0x10
  378. + or t0, t0, a5
  379. + slli a5, t0, 0x20
  380. + or t0, t0, a5
  381. +
  382. + li a5, -1
  383. + addi a0, a0, -8
  384. +.Lloop:
  385. + addi a0, a0, 8
  386. + ld a2, 0(a0)
  387. + orc.b t1, a2
  388. + bne t1, a5, .Lnull
  389. + xor a3, a2, t0
  390. + orc.b a3, a3
  391. + bne a3, a5, .Lfind
  392. + orc.b a2, a2
  393. + beq a2, a5, .Lloop
  394. +
  395. +.Lnofind:
  396. + li a0, 0
  397. +.Ldone:
  398. + ret
  399. +
  400. +.Lfind:
  401. + not a3, a3
  402. + ctz a3, a3
  403. + srli a3, a3, 3
  404. + add a0, a0, a3
  405. + ret
  406. +
  407. +# cases in which a null byte was detected
  408. +.Lnull:
  409. + bne a2, t0, .Lend
  410. + j .Lfind
  411. +
  412. +.Lend:
  413. + lbu a5, 0(a0)
  414. + beq a5, a1, .Ldone
  415. + beqz a5, .Lnofind
  416. + addi a0, a0, 1
  417. + j .Lend
  418. +
  419. +
  420. +END (strchr)
  421. +libc_hidden_builtin_def (strchr)
  422. \ No newline at end of file
  423. diff --git a/sysdeps/riscv/rv64/strchrnul.S b/sysdeps/riscv/rv64/strchrnul.S
  424. new file mode 100644
  425. index 0000000000..3e48445f11
  426. --- /dev/null
  427. +++ b/sysdeps/riscv/rv64/strchrnul.S
  428. @@ -0,0 +1,79 @@
  429. +/* The assembly function for strchrnul. RISC-V version.
  430. + Copyright (C) 2018 Free Software Foundation, Inc.
  431. + This file is part of the GNU C Library.
  432. +
  433. + The GNU C Library is free software; you can redistribute it and/or
  434. + modify it under the terms of the GNU Lesser General Public
  435. + License as published by the Free Software Foundation; either
  436. + version 2.1 of the License, or (at your option) any later version.
  437. +
  438. + The GNU C Library is distributed in the hope that it will be useful,
  439. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  440. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  441. + Lesser General Public License for more details.
  442. +
  443. + You should have received a copy of the GNU Lesser General Public
  444. + License along with the GNU C Library. If not, see
  445. + <http://www.gnu.org/licenses/>. */
  446. +
  447. +#include <sysdep.h>
  448. +
  449. + .p2align 6
  450. +ENTRY (__strchrnul)
  451. + andi a1, a1, 0xff
  452. +
  453. +.Lmisaligned:
  454. + andi a5, a0, 7
  455. + beqz a5, .Laligned
  456. + lbu a5, 0(a0)
  457. + beq a5, a1, .Ldone
  458. + beqz a5, .Ldone
  459. + addi a0, a0, 1
  460. + j .Lmisaligned
  461. +
  462. +.Laligned:
  463. + slli a5, a1, 0x8
  464. + or a5, a5, a1
  465. + slli t0, a5, 0x10
  466. + or t0, t0, a5
  467. + slli a5, t0, 0x20
  468. + or t0, t0, a5
  469. +
  470. + li a5, -1
  471. + addi a0, a0, -8
  472. +.Lloop:
  473. + addi a0, a0, 8
  474. + ld a2, 0(a0)
  475. + orc.b t1, a2
  476. + bne t1, a5, .Lnull
  477. + xor a3, a2, t0
  478. + orc.b a3, a3
  479. + bne a3, a5, .Lfind
  480. + orc.b a2, a2
  481. + beq a2, a5, .Lloop
  482. +
  483. +.Ldone:
  484. + ret
  485. +
  486. +.Lfind:
  487. + not a3, a3
  488. + ctz a3, a3
  489. + srli a3, a3, 3
  490. + add a0, a0, a3
  491. + ret
  492. +
  493. +# cases in which a null byte was detected
  494. +.Lnull:
  495. + bne a2, t0, .Lend
  496. + j .Lfind
  497. +
  498. +.Lend:
  499. + lbu a5, 0(a0)
  500. + beq a5, a1, .Ldone
  501. + beqz a5, .Ldone
  502. + addi a0, a0, 1
  503. + j .Lend
  504. +
  505. +END (__strchrnul)
  506. +weak_alias (__strchrnul,strchrnul)
  507. +libc_hidden_builtin_def (__strchrnul)
  508. \ No newline at end of file
  509. diff --git a/sysdeps/riscv/rv64/strncmp.S b/sysdeps/riscv/rv64/strncmp.S
  510. new file mode 100644
  511. index 0000000000..85245df98d
  512. --- /dev/null
  513. +++ b/sysdeps/riscv/rv64/strncmp.S
  514. @@ -0,0 +1,73 @@
  515. +/* The assembly function for strncmp. RISC-V version.
  516. + Copyright (C) 2018 Free Software Foundation, Inc.
  517. + This file is part of the GNU C Library.
  518. +
  519. + The GNU C Library is free software; you can redistribute it and/or
  520. + modify it under the terms of the GNU Lesser General Public
  521. + License as published by the Free Software Foundation; either
  522. + version 2.1 of the License, or (at your option) any later version.
  523. +
  524. + The GNU C Library is distributed in the hope that it will be useful,
  525. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  526. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  527. + Lesser General Public License for more details.
  528. +
  529. + You should have received a copy of the GNU Lesser General Public
  530. + License along with the GNU C Library. If not, see
  531. + <http://www.gnu.org/licenses/>. */
  532. +
  533. +#include <sysdep.h>
  534. +
  535. + .p2align 6
  536. +ENTRY (strncmp)
  537. + beqz a2, .Lequal
  538. + or a4, a0, a1
  539. + li t2, -1
  540. + and a4, a4, 7
  541. + beqz a4, .Lenter
  542. + j .Lmisaligned
  543. +
  544. +.Lloop:
  545. + addi a0, a0, 8
  546. + addi a1, a1, 8
  547. + addi a2, a2, -8
  548. +
  549. +.Lenter:
  550. + addi a5, a2, -8
  551. + blez a5, .Lmisaligned
  552. + ld a3, 0(a0)
  553. + ld a4, 0(a1)
  554. + orc.b t0, a3
  555. + bne t0, t2, .Lnull
  556. + beq a3, a4, .Lloop
  557. + rev8 a6, a3
  558. + rev8 a7, a4
  559. + bgeu a6, a7, 1f
  560. + li a0, -1
  561. + ret
  562. +1:
  563. + li a0, 1
  564. + ret
  565. +
  566. +.Lmisaligned:
  567. + blez a2, .Ldone
  568. + lbu a3, 0(a0)
  569. + lbu a4, 0(a1)
  570. + addi a0, a0, 1
  571. + addi a1, a1, 1
  572. + addi a2, a2, -1
  573. + bne a3, a4, .Ldone
  574. + bnez a3, .Lmisaligned
  575. +.Ldone:
  576. + sub a0, a3, a4
  577. + ret
  578. +
  579. +# cases in which a null byte was detected
  580. +.Lnull:
  581. + bne a3, a4, .Lmisaligned
  582. +.Lequal:
  583. + li a0, 0
  584. + ret
  585. +
  586. +END (strncmp)
  587. +libc_hidden_builtin_def (strncmp)
  588. \ No newline at end of file
  589. diff --git a/sysdeps/riscv/rv64/strnlen.S b/sysdeps/riscv/rv64/strnlen.S
  590. new file mode 100644
  591. index 0000000000..33b140a0ac
  592. --- /dev/null
  593. +++ b/sysdeps/riscv/rv64/strnlen.S
  594. @@ -0,0 +1,62 @@
  595. +/* The assembly function for strnlen. RISC-V version.
  596. + Copyright (C) 2018 Free Software Foundation, Inc.
  597. + This file is part of the GNU C Library.
  598. +
  599. + The GNU C Library is free software; you can redistribute it and/or
  600. + modify it under the terms of the GNU Lesser General Public
  601. + License as published by the Free Software Foundation; either
  602. + version 2.1 of the License, or (at your option) any later version.
  603. +
  604. + The GNU C Library is distributed in the hope that it will be useful,
  605. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  606. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  607. + Lesser General Public License for more details.
  608. +
  609. + You should have received a copy of the GNU Lesser General Public
  610. + License along with the GNU C Library. If not, see
  611. + <http://www.gnu.org/licenses/>. */
  612. +
  613. +#include <sysdep.h>
  614. +
  615. + .p2align 6
  616. +ENTRY (strnlen)
  617. + mv a2, a0
  618. + mv a0, a1
  619. + li a3, -1
  620. + beqz a1, .Ldone
  621. + add a0, a2, a1
  622. + bleu a2, a0, 1f
  623. + li a0, -1
  624. +1:
  625. + mv a5, a2
  626. +
  627. +.Lmisaligned:
  628. + andi a4, a5, 7
  629. + beqz a4, .Lloop
  630. + lbu a4, 0(a5)
  631. + beqz a4, .Llenth
  632. + addi a5, a5, 1
  633. + j .Lmisaligned
  634. +
  635. +.Laligned:
  636. + addi a5, a5, 8
  637. + addi a1, a1, -8
  638. +.Lloop:
  639. + bleu a1, x0, .Llenth
  640. + ld a4, 0(a5)
  641. + orc.b a4, a4
  642. + beq a4, a3, .Laligned
  643. + not a4, a4
  644. + ctz a4, a4
  645. + srli a4, a4, 3
  646. + add a5, a5, a4
  647. +.Llenth:
  648. + minu a5, a5, a0
  649. + sub a0, a5, a2
  650. +.Ldone:
  651. + ret
  652. +
  653. +END (strnlen)
  654. +weak_alias (strnlen, __strnlen)
  655. +libc_hidden_builtin_def (strnlen)
  656. +libc_hidden_builtin_def (__strnlen)
  657. --
  658. 2.25.1