0002-add-vector-support-for-memset-memcmp-memmove-memcpy-.patch 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529
  1. From 0d709adf42cb79137b8d125eff8c4a386cf69187 Mon Sep 17 00:00:00 2001
  2. From: "max.ma" <max.ma@starfivetech.com>
  3. Date: Tue, 21 Dec 2021 17:42:04 -0800
  4. Subject: [PATCH 02/19] add vector support for
  5. memset/memcmp/memmove/memcpy/memchr/strlen/strcmp
  6. ---
  7. sysdeps/riscv/riscv-ifunc.h | 34 ++++++
  8. sysdeps/riscv/rv64/multiarch/Makefile | 5 +
  9. sysdeps/riscv/rv64/multiarch/aeabi_memcpy.c | 2 +
  10. sysdeps/riscv/rv64/multiarch/ifunc-common.h | 30 +++++
  11. .../riscv/rv64/multiarch/ifunc-impl-list.c | 65 ++++++++++
  12. sysdeps/riscv/rv64/multiarch/memchr.c | 32 +++++
  13. sysdeps/riscv/rv64/multiarch/memchr_as.S | 88 ++++++++++++++
  14. sysdeps/riscv/rv64/multiarch/memchr_riscv.S | 25 ++++
  15. sysdeps/riscv/rv64/multiarch/memchr_vector.S | 53 ++++++++
  16. sysdeps/riscv/rv64/multiarch/memcmp.c | 32 +++++
  17. sysdeps/riscv/rv64/multiarch/memcmp_riscv.c | 29 +++++
  18. sysdeps/riscv/rv64/multiarch/memcmp_vector.S | 56 +++++++++
  19. sysdeps/riscv/rv64/multiarch/memcpy.c | 33 +++++
  20. sysdeps/riscv/rv64/multiarch/memcpy_as.S | 114 ++++++++++++++++++
  21. sysdeps/riscv/rv64/multiarch/memcpy_riscv.S | 25 ++++
  22. sysdeps/riscv/rv64/multiarch/memcpy_vector.S | 54 +++++++++
  23. sysdeps/riscv/rv64/multiarch/memmove.c | 32 +++++
  24. sysdeps/riscv/rv64/multiarch/memmove_riscv.c | 29 +++++
  25. sysdeps/riscv/rv64/multiarch/memmove_vector.S | 56 +++++++++
  26. sysdeps/riscv/rv64/multiarch/memset.c | 33 +++++
  27. sysdeps/riscv/rv64/multiarch/memset_riscv.c | 29 +++++
  28. sysdeps/riscv/rv64/multiarch/memset_vector.S | 45 +++++++
  29. sysdeps/riscv/rv64/multiarch/rtld-memchr.S | 1 +
  30. sysdeps/riscv/rv64/multiarch/rtld-memcmp.c | 1 +
  31. sysdeps/riscv/rv64/multiarch/rtld-memcpy.S | 1 +
  32. sysdeps/riscv/rv64/multiarch/rtld-memmove.c | 19 +++
  33. sysdeps/riscv/rv64/multiarch/rtld-memset.c | 1 +
  34. sysdeps/riscv/rv64/multiarch/rtld-strcmp.S | 1 +
  35. sysdeps/riscv/rv64/multiarch/rtld-strlen.c | 1 +
  36. sysdeps/riscv/rv64/multiarch/strcmp.c | 33 +++++
  37. sysdeps/riscv/rv64/multiarch/strcmp_.S | 39 ++++++
  38. sysdeps/riscv/rv64/multiarch/strcmp_riscv.S | 9 ++
  39. sysdeps/riscv/rv64/multiarch/strcmp_vector.S | 54 +++++++++
  40. sysdeps/riscv/rv64/multiarch/strlen.c | 32 +++++
  41. sysdeps/riscv/rv64/multiarch/strlen_riscv.c | 29 +++++
  42. sysdeps/riscv/rv64/multiarch/strlen_vector.S | 46 +++++++
  43. sysdeps/riscv/sysdep.h | 24 ++++
  44. sysdeps/unix/sysv/linux/riscv/sysdep.h | 2 +-
  45. 38 files changed, 1193 insertions(+), 1 deletion(-)
  46. create mode 100644 sysdeps/riscv/riscv-ifunc.h
  47. create mode 100644 sysdeps/riscv/rv64/multiarch/Makefile
  48. create mode 100644 sysdeps/riscv/rv64/multiarch/aeabi_memcpy.c
  49. create mode 100644 sysdeps/riscv/rv64/multiarch/ifunc-common.h
  50. create mode 100644 sysdeps/riscv/rv64/multiarch/ifunc-impl-list.c
  51. create mode 100644 sysdeps/riscv/rv64/multiarch/memchr.c
  52. create mode 100644 sysdeps/riscv/rv64/multiarch/memchr_as.S
  53. create mode 100644 sysdeps/riscv/rv64/multiarch/memchr_riscv.S
  54. create mode 100644 sysdeps/riscv/rv64/multiarch/memchr_vector.S
  55. create mode 100644 sysdeps/riscv/rv64/multiarch/memcmp.c
  56. create mode 100644 sysdeps/riscv/rv64/multiarch/memcmp_riscv.c
  57. create mode 100644 sysdeps/riscv/rv64/multiarch/memcmp_vector.S
  58. create mode 100644 sysdeps/riscv/rv64/multiarch/memcpy.c
  59. create mode 100644 sysdeps/riscv/rv64/multiarch/memcpy_as.S
  60. create mode 100644 sysdeps/riscv/rv64/multiarch/memcpy_riscv.S
  61. create mode 100644 sysdeps/riscv/rv64/multiarch/memcpy_vector.S
  62. create mode 100644 sysdeps/riscv/rv64/multiarch/memmove.c
  63. create mode 100644 sysdeps/riscv/rv64/multiarch/memmove_riscv.c
  64. create mode 100644 sysdeps/riscv/rv64/multiarch/memmove_vector.S
  65. create mode 100644 sysdeps/riscv/rv64/multiarch/memset.c
  66. create mode 100644 sysdeps/riscv/rv64/multiarch/memset_riscv.c
  67. create mode 100644 sysdeps/riscv/rv64/multiarch/memset_vector.S
  68. create mode 100644 sysdeps/riscv/rv64/multiarch/rtld-memchr.S
  69. create mode 100644 sysdeps/riscv/rv64/multiarch/rtld-memcmp.c
  70. create mode 100644 sysdeps/riscv/rv64/multiarch/rtld-memcpy.S
  71. create mode 100644 sysdeps/riscv/rv64/multiarch/rtld-memmove.c
  72. create mode 100644 sysdeps/riscv/rv64/multiarch/rtld-memset.c
  73. create mode 100644 sysdeps/riscv/rv64/multiarch/rtld-strcmp.S
  74. create mode 100644 sysdeps/riscv/rv64/multiarch/rtld-strlen.c
  75. create mode 100644 sysdeps/riscv/rv64/multiarch/strcmp.c
  76. create mode 100644 sysdeps/riscv/rv64/multiarch/strcmp_.S
  77. create mode 100644 sysdeps/riscv/rv64/multiarch/strcmp_riscv.S
  78. create mode 100644 sysdeps/riscv/rv64/multiarch/strcmp_vector.S
  79. create mode 100644 sysdeps/riscv/rv64/multiarch/strlen.c
  80. create mode 100644 sysdeps/riscv/rv64/multiarch/strlen_riscv.c
  81. create mode 100644 sysdeps/riscv/rv64/multiarch/strlen_vector.S
  82. create mode 100644 sysdeps/riscv/sysdep.h
  83. diff --git a/sysdeps/riscv/riscv-ifunc.h b/sysdeps/riscv/riscv-ifunc.h
  84. new file mode 100644
  85. index 0000000000..6b4ea24758
  86. --- /dev/null
  87. +++ b/sysdeps/riscv/riscv-ifunc.h
  88. @@ -0,0 +1,34 @@
  89. +/* Common definition for ifunc resolvers. Linux/RISCV version.
  90. + This file is part of the GNU C Library.
  91. + Copyright (C) 2017-2021 Free Software Foundation, Inc.
  92. +
  93. + The GNU C Library is free software; you can redistribute it and/or
  94. + modify it under the terms of the GNU Lesser General Public
  95. + License as published by the Free Software Foundation; either
  96. + version 2.1 of the License, or (at your option) any later version.
  97. +
  98. + The GNU C Library is distributed in the hope that it will be useful,
  99. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  100. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  101. + Lesser General Public License for more details.
  102. +
  103. + You should have received a copy of the GNU Lesser General Public
  104. + License along with the GNU C Library; if not, see
  105. + <https://www.gnu.org/licenses/>. */
  106. +
  107. +#include <sysdep.h>
  108. +#include <ifunc-init.h>
  109. +
  110. +#define INIT_ARCH()
  111. +
  112. +#define riscv_libc_ifunc_redirected(redirected_name, name, expr) \
  113. + __ifunc (redirected_name, name, expr(hwcap), int hwcap, INIT_ARCH)
  114. +
  115. +#if defined SHARED
  116. +# define riscv_libc_ifunc_hidden_def(redirect_name, name) \
  117. + __hidden_ver1 (name, __GI_##name, redirect_name) \
  118. + __attribute__ ((visibility ("hidden"))) \
  119. + __attribute_copy__ (name)
  120. +#else
  121. +# define riscv_libc_ifunc_hidden_def(redirect_name, name)
  122. +#endif
  123. diff --git a/sysdeps/riscv/rv64/multiarch/Makefile b/sysdeps/riscv/rv64/multiarch/Makefile
  124. new file mode 100644
  125. index 0000000000..3349bf4888
  126. --- /dev/null
  127. +++ b/sysdeps/riscv/rv64/multiarch/Makefile
  128. @@ -0,0 +1,5 @@
  129. +ifeq ($(subdir),string)
  130. +sysdep_routines += memcpy_vector memcpy_riscv memchr_riscv memchr_vector memcmp_riscv \
  131. + memcmp_vector strcmp_riscv strcmp_vector strlen_riscv strlen_vector \
  132. + memmove_vector memmove_riscv memset_vector memset_riscv
  133. +endif
  134. diff --git a/sysdeps/riscv/rv64/multiarch/aeabi_memcpy.c b/sysdeps/riscv/rv64/multiarch/aeabi_memcpy.c
  135. new file mode 100644
  136. index 0000000000..2054d18261
  137. --- /dev/null
  138. +++ b/sysdeps/riscv/rv64/multiarch/aeabi_memcpy.c
  139. @@ -0,0 +1,2 @@
  140. +/* Empty file to override sysdeps/riscv version. See memcpy.S for definitions
  141. + of these functions. */
  142. diff --git a/sysdeps/riscv/rv64/multiarch/ifunc-common.h b/sysdeps/riscv/rv64/multiarch/ifunc-common.h
  143. new file mode 100644
  144. index 0000000000..8c4c95371f
  145. --- /dev/null
  146. +++ b/sysdeps/riscv/rv64/multiarch/ifunc-common.h
  147. @@ -0,0 +1,30 @@
  148. +/* Common definition for memcmp resolver.
  149. + Copyright (C) 2017-2021 Free Software Foundation, Inc.
  150. + This file is part of the GNU C Library.
  151. +
  152. + The GNU C Library is free software; you can redistribute it and/or
  153. + modify it under the terms of the GNU Lesser General Public
  154. + License as published by the Free Software Foundation; either
  155. + version 2.1 of the License, or (at your option) any later version.
  156. +
  157. + The GNU C Library is distributed in the hope that it will be useful,
  158. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  159. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  160. + Lesser General Public License for more details.
  161. +
  162. + You should have received a copy of the GNU Lesser General Public
  163. + License along with the GNU C Library; if not, see
  164. + <https://www.gnu.org/licenses/>. */
  165. +
  166. +#include <sys/auxv.h>
  167. +
  168. +__typeof (REDIRECT_NAME) OPTIMIZE (riscv) attribute_hidden;
  169. +__typeof (REDIRECT_NAME) OPTIMIZE (vector) attribute_hidden;
  170. +
  171. +static inline void *
  172. +IFUNC_SELECTOR (int hwcap)
  173. +{
  174. + if (hwcap & HWCAP_ISA_V)
  175. + return OPTIMIZE (vector);
  176. + return OPTIMIZE (riscv);
  177. +}
  178. diff --git a/sysdeps/riscv/rv64/multiarch/ifunc-impl-list.c b/sysdeps/riscv/rv64/multiarch/ifunc-impl-list.c
  179. new file mode 100644
  180. index 0000000000..28c6e123f0
  181. --- /dev/null
  182. +++ b/sysdeps/riscv/rv64/multiarch/ifunc-impl-list.c
  183. @@ -0,0 +1,65 @@
  184. +/* Enumerate available IFUNC implementations of a function. RISCV version.
  185. + Copyright (C) 2013-2021 Free Software Foundation, Inc.
  186. + This file is part of the GNU C Library.
  187. +
  188. + The GNU C Library is free software; you can redistribute it and/or
  189. + modify it under the terms of the GNU Lesser General Public
  190. + License as published by the Free Software Foundation; either
  191. + version 2.1 of the License, or (at your option) any later version.
  192. +
  193. + The GNU C Library is distributed in the hope that it will be useful,
  194. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  195. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  196. + Lesser General Public License for more details.
  197. +
  198. + You should have received a copy of the GNU Lesser General Public
  199. + License along with the GNU C Library; if not, see
  200. + <https://www.gnu.org/licenses/>. */
  201. +
  202. +#include <stdbool.h>
  203. +#include <string.h>
  204. +#include <ldsodefs.h>
  205. +#include <sysdep.h>
  206. +#include <ifunc-impl-list.h>
  207. +
  208. +/* Fill ARRAY of MAX elements with IFUNC implementations for function
  209. + NAME and return the number of valid entries. */
  210. +
  211. +size_t
  212. +__libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
  213. + size_t max)
  214. +{
  215. + size_t i = 0;
  216. +
  217. + bool use_rvv = (GLRO(dl_hwcap) & HWCAP_ISA_V) != 0;
  218. +
  219. + IFUNC_IMPL (i, name, memcpy,
  220. + IFUNC_IMPL_ADD (array, i, memcpy, use_rvv, __memcpy_vector)
  221. + IFUNC_IMPL_ADD (array, i, memcpy, 1, __memcpy_riscv));
  222. +
  223. + IFUNC_IMPL (i, name, memchr,
  224. + IFUNC_IMPL_ADD (array, i, memchr, use_rvv, __memchr_vector)
  225. + IFUNC_IMPL_ADD (array, i, memchr, 1, __memchr_riscv));
  226. +
  227. + IFUNC_IMPL (i, name, memcmp,
  228. + IFUNC_IMPL_ADD (array, i, memcmp, use_rvv, __memcmp_vector)
  229. + IFUNC_IMPL_ADD (array, i, memcmp, 1, __memcmp_riscv));
  230. +
  231. + IFUNC_IMPL (i, name, strcmp,
  232. + IFUNC_IMPL_ADD (array, i, strcmp, use_rvv, __strcmp_vector)
  233. + IFUNC_IMPL_ADD (array, i, strcmp, 1, __strcmp_riscv));
  234. +
  235. + IFUNC_IMPL (i, name, strlen,
  236. + IFUNC_IMPL_ADD (array, i, strlen, use_rvv, __strlen_vector)
  237. + IFUNC_IMPL_ADD (array, i, strlen, 1, __strlen_riscv));
  238. +
  239. + IFUNC_IMPL (i, name, memmove,
  240. + IFUNC_IMPL_ADD (array, i, memmove, use_rvv, __memmove_vector)
  241. + IFUNC_IMPL_ADD (array, i, memmove, 1, __memmove_riscv));
  242. +
  243. + IFUNC_IMPL (i, name, memset,
  244. + IFUNC_IMPL_ADD (array, i, memset, use_rvv, __memset_vector)
  245. + IFUNC_IMPL_ADD (array, i, memset, 1, __memset_riscv));
  246. +
  247. + return i;
  248. +}
  249. diff --git a/sysdeps/riscv/rv64/multiarch/memchr.c b/sysdeps/riscv/rv64/multiarch/memchr.c
  250. new file mode 100644
  251. index 0000000000..1544bc3d01
  252. --- /dev/null
  253. +++ b/sysdeps/riscv/rv64/multiarch/memchr.c
  254. @@ -0,0 +1,32 @@
  255. +/* Multiple versions of memchr.
  256. + All versions must be listed in ifunc-impl-list.c.
  257. + Copyright (C) 2017-2021 Free Software Foundation, Inc.
  258. + This file is part of the GNU C Library.
  259. +
  260. + The GNU C Library is free software; you can redistribute it and/or
  261. + modify it under the terms of the GNU Lesser General Public
  262. + License as published by the Free Software Foundation; either
  263. + version 2.1 of the License, or (at your option) any later version.
  264. +
  265. + The GNU C Library is distributed in the hope that it will be useful,
  266. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  267. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  268. + Lesser General Public License for more details.
  269. +
  270. + You should have received a copy of the GNU Lesser General Public
  271. + License along with the GNU C Library; if not, see
  272. + <https://www.gnu.org/licenses/>. */
  273. +
  274. +#if IS_IN (libc)
  275. +# define memchr __redirect_memchr
  276. +# include <string.h>
  277. +# undef memchr
  278. +
  279. +# include <riscv-ifunc.h>
  280. +
  281. +# define SYMBOL_NAME memchr
  282. +# include "ifunc-common.h"
  283. +
  284. +riscv_libc_ifunc_redirected (__redirect_memchr, memchr, IFUNC_SELECTOR);
  285. +riscv_libc_ifunc_hidden_def (__redirect_memchr, memchr);
  286. +#endif
  287. diff --git a/sysdeps/riscv/rv64/multiarch/memchr_as.S b/sysdeps/riscv/rv64/multiarch/memchr_as.S
  288. new file mode 100644
  289. index 0000000000..557098afda
  290. --- /dev/null
  291. +++ b/sysdeps/riscv/rv64/multiarch/memchr_as.S
  292. @@ -0,0 +1,88 @@
  293. +
  294. +/* The assembly function for memchr. RISC-V version.
  295. + Copyright (C) 2018 Free Software Foundation, Inc.
  296. + This file is part of the GNU C Library.
  297. +
  298. + The GNU C Library is free software; you can redistribute it and/or
  299. + modify it under the terms of the GNU Lesser General Public
  300. + License as published by the Free Software Foundation; either
  301. + version 2.1 of the License, or (at your option) any later version.
  302. +
  303. + The GNU C Library is distributed in the hope that it will be useful,
  304. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  305. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  306. + Lesser General Public License for more details.
  307. +
  308. + You should have received a copy of the GNU Lesser General Public
  309. + License along with the GNU C Library. If not, see
  310. + <http://www.gnu.org/licenses/>. */
  311. +
  312. +#include <sysdep.h>
  313. +
  314. +ENTRY (memchr)
  315. + zext.b a3,a1
  316. + beqz a2, .L_not_found
  317. + andi a5,a0,7
  318. +.L_not_aligned:
  319. + beqz a5,.L_aligned_8byte
  320. + lbu a5,0(a0)
  321. + addi a2,a2,-1
  322. + beq a5,a3,.L_found
  323. + addi a0,a0,1
  324. + andi a5,a0,7
  325. + bnez a2,.L_not_aligned
  326. +
  327. +.L_not_found:
  328. + li a0,0
  329. +.L_found:
  330. + ret
  331. +
  332. +.L_aligned_8byte:
  333. + zext.b a1,a1
  334. + slli a5,a1,0x8
  335. + or a1,a1,a5
  336. + slli a5,a1,0x10
  337. + or a5,a5,a1
  338. + slli a1,a5,0x20
  339. + li a4,7
  340. + or a1,a1,a5
  341. + bgeu a4,a2,.L_less_8bytes
  342. +
  343. + ld a7, mask1
  344. + ld a6, mask2
  345. +
  346. + li t1,7
  347. + j .L_8byte_compare_loop
  348. +.L_8byte_compare:
  349. + addi a2,a2,-8
  350. + addi a0,a0,8
  351. + bgeu t1,a2,.L_8byte_compare_exit
  352. +.L_8byte_compare_loop:
  353. + ld a5,0(a0)
  354. + xor a5,a5,a1
  355. + add a4,a5,a7
  356. + not a5,a5
  357. + and a5,a5,a4
  358. + and a5,a5,a6
  359. + beqz a5,.L_8byte_compare
  360. +
  361. +.L_less_8bytes:
  362. + add a2,a2,a0
  363. + j .L_less_8bytes_compare
  364. +.L_less_8bytes_loop:
  365. + addi a0,a0,1
  366. + beq a2,a0,.L_not_found
  367. +.L_less_8bytes_compare:
  368. + lbu a5,0(a0)
  369. + bne a5,a3,.L_less_8bytes_loop
  370. + ret
  371. +.L_8byte_compare_exit:
  372. + bnez a2,.L_less_8bytes
  373. + j .L_not_found
  374. + .align 3
  375. +mask1:
  376. + .dword 0xfefefefefefefeff
  377. +mask2:
  378. + .dword 0x8080808080808080
  379. +END (memchr)
  380. +libc_hidden_builtin_def (memchr)
  381. diff --git a/sysdeps/riscv/rv64/multiarch/memchr_riscv.S b/sysdeps/riscv/rv64/multiarch/memchr_riscv.S
  382. new file mode 100644
  383. index 0000000000..ce7b64bbe0
  384. --- /dev/null
  385. +++ b/sysdeps/riscv/rv64/multiarch/memchr_riscv.S
  386. @@ -0,0 +1,25 @@
  387. +/* The assembly function for memchr. RISC-V version.
  388. + Copyright (C) 2018 Free Software Foundation, Inc.
  389. + This file is part of the GNU C Library.
  390. +
  391. + The GNU C Library is free software; you can redistribute it and/or
  392. + modify it under the terms of the GNU Lesser General Public
  393. + License as published by the Free Software Foundation; either
  394. + version 2.1 of the License, or (at your option) any later version.
  395. +
  396. + The GNU C Library is distributed in the hope that it will be useful,
  397. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  398. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  399. + Lesser General Public License for more details.
  400. +
  401. + You should have received a copy of the GNU Lesser General Public
  402. + License along with the GNU C Library. If not, see
  403. + <http://www.gnu.org/licenses/>. */
  404. +
  405. +#include <sysdep.h>
  406. +
  407. +#define memchr __memchr_riscv
  408. +#undef libc_hidden_builtin_def
  409. +#define libc_hidden_builtin_def(name)
  410. +
  411. +#include "memchr_as.S"
  412. \ No newline at end of file
  413. diff --git a/sysdeps/riscv/rv64/multiarch/memchr_vector.S b/sysdeps/riscv/rv64/multiarch/memchr_vector.S
  414. new file mode 100644
  415. index 0000000000..77693d716d
  416. --- /dev/null
  417. +++ b/sysdeps/riscv/rv64/multiarch/memchr_vector.S
  418. @@ -0,0 +1,53 @@
  419. +/* The assembly function for memchr. RISC-V version.
  420. + Copyright (C) 2018 Free Software Foundation, Inc.
  421. + This file is part of the GNU C Library.
  422. +
  423. + The GNU C Library is free software; you can redistribute it and/or
  424. + modify it under the terms of the GNU Lesser General Public
  425. + License as published by the Free Software Foundation; either
  426. + version 2.1 of the License, or (at your option) any later version.
  427. +
  428. + The GNU C Library is distributed in the hope that it will be useful,
  429. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  430. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  431. + Lesser General Public License for more details.
  432. +
  433. + You should have received a copy of the GNU Lesser General Public
  434. + License along with the GNU C Library. If not, see
  435. + <http://www.gnu.org/licenses/>. */
  436. +
  437. +#include <sysdep.h>
  438. +
  439. +/* For __riscv_vector this file defines memchr. */
  440. +/* #ifndef __riscv_vector */
  441. +# define memchr __memchr_vector
  442. +# undef libc_hidden_builtin_def
  443. +# define libc_hidden_builtin_def(a)
  444. +/* #endif */
  445. +
  446. + .p2align 6
  447. +ENTRY (memchr)
  448. +
  449. + zext.b a1,a1
  450. +
  451. +.L_memchr_loop:
  452. + vsetvli a3,a2,e8,m8,tu,mu
  453. + vle8ff.v v0,(a0)
  454. + vmseq.vx v8,v0,a1
  455. + csrr a3,vl
  456. + vfirst.m a4,v8
  457. + sub a2,a2,a3
  458. + bgez a4,.L_found
  459. + add a0,a0,a3
  460. + bltu zero,a2,.L_memchr_loop
  461. +
  462. +.L_found:
  463. + bltz a4,.L_not_found
  464. +
  465. + add a0,a0,a4
  466. + ret
  467. +.L_not_found:
  468. + add a0,zero,zero
  469. + ret
  470. +END (memchr)
  471. +libc_hidden_builtin_def (memchr)
  472. diff --git a/sysdeps/riscv/rv64/multiarch/memcmp.c b/sysdeps/riscv/rv64/multiarch/memcmp.c
  473. new file mode 100644
  474. index 0000000000..29730c6ed1
  475. --- /dev/null
  476. +++ b/sysdeps/riscv/rv64/multiarch/memcmp.c
  477. @@ -0,0 +1,32 @@
  478. +/* Multiple versions of memcmp.
  479. + All versions must be listed in ifunc-impl-list.c.
  480. + Copyright (C) 2017-2021 Free Software Foundation, Inc.
  481. + This file is part of the GNU C Library.
  482. +
  483. + The GNU C Library is free software; you can redistribute it and/or
  484. + modify it under the terms of the GNU Lesser General Public
  485. + License as published by the Free Software Foundation; either
  486. + version 2.1 of the License, or (at your option) any later version.
  487. +
  488. + The GNU C Library is distributed in the hope that it will be useful,
  489. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  490. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  491. + Lesser General Public License for more details.
  492. +
  493. + You should have received a copy of the GNU Lesser General Public
  494. + License along with the GNU C Library; if not, see
  495. + <https://www.gnu.org/licenses/>. */
  496. +
  497. +#if IS_IN (libc)
  498. +# define memcmp __redirect_memcmp
  499. +# include <string.h>
  500. +# undef memcmp
  501. +
  502. +# include <riscv-ifunc.h>
  503. +
  504. +# define SYMBOL_NAME memcmp
  505. +# include "ifunc-common.h"
  506. +
  507. +riscv_libc_ifunc_redirected (__redirect_memcmp, memcmp, IFUNC_SELECTOR);
  508. +riscv_libc_ifunc_hidden_def (__redirect_memcmp, memcmp);
  509. +#endif
  510. diff --git a/sysdeps/riscv/rv64/multiarch/memcmp_riscv.c b/sysdeps/riscv/rv64/multiarch/memcmp_riscv.c
  511. new file mode 100644
  512. index 0000000000..dda15d7d35
  513. --- /dev/null
  514. +++ b/sysdeps/riscv/rv64/multiarch/memcmp_riscv.c
  515. @@ -0,0 +1,29 @@
  516. +/* RISCV C version memcmp.
  517. + Copyright (C) 2018-2021 Free Software Foundation, Inc.
  518. + This file is part of the GNU C Library.
  519. +
  520. + The GNU C Library is free software; you can redistribute it and/or
  521. + modify it under the terms of the GNU Lesser General Public
  522. + License as published by the Free Software Foundation; either
  523. + version 2.1 of the License, or (at your option) any later version.
  524. +
  525. + The GNU C Library is distributed in the hope that it will be useful,
  526. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  527. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  528. + Lesser General Public License for more details.
  529. +
  530. + You should have received a copy of the GNU Lesser General Public
  531. + License along with the GNU C Library; if not, see
  532. + <https://www.gnu.org/licenses/>. */
  533. +
  534. +#if IS_IN (libc)
  535. +#undef libc_hidden_builtin_def
  536. +#define libc_hidden_builtin_def(name)
  537. +
  538. +#undef weak_alias
  539. +# define MEMCMP __memcmp_riscv
  540. +# include <string/memcmp.c>
  541. +#else
  542. +
  543. +# include <string/memcmp.c>
  544. +#endif
  545. diff --git a/sysdeps/riscv/rv64/multiarch/memcmp_vector.S b/sysdeps/riscv/rv64/multiarch/memcmp_vector.S
  546. new file mode 100644
  547. index 0000000000..f6cbc1307b
  548. --- /dev/null
  549. +++ b/sysdeps/riscv/rv64/multiarch/memcmp_vector.S
  550. @@ -0,0 +1,56 @@
  551. +/* The assembly function for memcmp. RISC-V version.
  552. + Copyright (C) 2018 Free Software Foundation, Inc.
  553. + This file is part of the GNU C Library.
  554. +
  555. + The GNU C Library is free software; you can redistribute it and/or
  556. + modify it under the terms of the GNU Lesser General Public
  557. + License as published by the Free Software Foundation; either
  558. + version 2.1 of the License, or (at your option) any later version.
  559. +
  560. + The GNU C Library is distributed in the hope that it will be useful,
  561. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  562. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  563. + Lesser General Public License for more details.
  564. +
  565. + You should have received a copy of the GNU Lesser General Public
  566. + License along with the GNU C Library. If not, see
  567. + <http://www.gnu.org/licenses/>. */
  568. +
  569. +#include <sysdep.h>
  570. +
  571. +/* For __riscv_vector this file defines strcmp. */
  572. +/* #ifndef __riscv_vector */
  573. +# define memcmp __memcmp_vector
  574. +# undef libc_hidden_builtin_def
  575. +# define libc_hidden_builtin_def(a)
  576. +/* #endif */
  577. +
  578. + .p2align 6
  579. +ENTRY (memcmp)
  580. +
  581. +.L_compare_loop:
  582. + vsetvli a3,a2,e8,m8,tu,mu
  583. + vle8.v v0,(a0)
  584. + vle8.v v8,(a1)
  585. + vmsne.vv v16,v0,v8
  586. + sub a2,a2,a3
  587. + vfirst.m a4,v16
  588. + bgez a4,.L_compare_not_equal
  589. + add a0,a0,a3
  590. + add a1,a1,a3
  591. + bltu zero,a2,.L_compare_loop
  592. + bltz a4,.L_compare_equal
  593. +
  594. +.L_compare_not_equal:
  595. + add a0,a0,a4
  596. + add a1,a1,a4
  597. + lbu a5,0(a0)
  598. + lbu a6,0(a1)
  599. + sub a0,a5,a6
  600. + ret
  601. +.L_compare_equal:
  602. + add a0,zero,zero
  603. + ret
  604. +END (memcmp)
  605. +libc_hidden_builtin_def (memcmp)
  606. +
  607. diff --git a/sysdeps/riscv/rv64/multiarch/memcpy.c b/sysdeps/riscv/rv64/multiarch/memcpy.c
  608. new file mode 100644
  609. index 0000000000..0f20b7fd44
  610. --- /dev/null
  611. +++ b/sysdeps/riscv/rv64/multiarch/memcpy.c
  612. @@ -0,0 +1,33 @@
  613. +/* Multiple versions of memcpy.
  614. + All versions must be listed in ifunc-impl-list.c.
  615. + Copyright (C) 2017-2021 Free Software Foundation, Inc.
  616. + This file is part of the GNU C Library.
  617. +
  618. + The GNU C Library is free software; you can redistribute it and/or
  619. + modify it under the terms of the GNU Lesser General Public
  620. + License as published by the Free Software Foundation; either
  621. + version 2.1 of the License, or (at your option) any later version.
  622. +
  623. + The GNU C Library is distributed in the hope that it will be useful,
  624. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  625. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  626. + Lesser General Public License for more details.
  627. +
  628. + You should have received a copy of the GNU Lesser General Public
  629. + License along with the GNU C Library; if not, see
  630. + <https://www.gnu.org/licenses/>. */
  631. +
  632. +#if IS_IN (libc)
  633. +# define memcpy __redirect_memcpy
  634. +# include <string.h>
  635. +# undef memcpy
  636. +
  637. +# include <riscv-ifunc.h>
  638. +
  639. +# define SYMBOL_NAME memcpy
  640. +# include "ifunc-common.h"
  641. +
  642. +riscv_libc_ifunc_redirected (__redirect_memcpy, memcpy, IFUNC_SELECTOR);
  643. +
  644. +riscv_libc_ifunc_hidden_def (__redirect_memcpy, memcpy);
  645. +#endif
  646. diff --git a/sysdeps/riscv/rv64/multiarch/memcpy_as.S b/sysdeps/riscv/rv64/multiarch/memcpy_as.S
  647. new file mode 100644
  648. index 0000000000..f0a074df13
  649. --- /dev/null
  650. +++ b/sysdeps/riscv/rv64/multiarch/memcpy_as.S
  651. @@ -0,0 +1,114 @@
  652. +/* The assembly function for memcpy. RISC-V version.
  653. + Copyright (C) 2018 Free Software Foundation, Inc.
  654. + This file is part of the GNU C Library.
  655. +
  656. + The GNU C Library is free software; you can redistribute it and/or
  657. + modify it under the terms of the GNU Lesser General Public
  658. + License as published by the Free Software Foundation; either
  659. + version 2.1 of the License, or (at your option) any later version.
  660. +
  661. + The GNU C Library is distributed in the hope that it will be useful,
  662. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  663. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  664. + Lesser General Public License for more details.
  665. +
  666. + You should have received a copy of the GNU Lesser General Public
  667. + License along with the GNU C Library. If not, see
  668. + <http://www.gnu.org/licenses/>. */
  669. +
  670. +#include <sysdep.h>
  671. +
  672. +
  673. +# define LABLE_ALIGN \
  674. + .balignl 16, 0x00000013
  675. +
  676. +ENTRY (memcpy)
  677. +
  678. + /* Test if len less than 8 bytes. */
  679. + mv t6, a0
  680. + sltiu a3, a2, 8
  681. + li t3, 1
  682. + bnez a3, .L_copy_by_byte
  683. +
  684. + andi a3, a0, 7
  685. + li t5, 8
  686. + /* Test if dest is not 8 bytes aligned. */
  687. + bnez a3, .L_dest_not_aligned
  688. +.L_dest_aligned:
  689. + /* If dest is aligned, then copy. */
  690. + srli t4, a2, 6
  691. + /* Test if len less than 32 bytes. */
  692. + beqz t4, .L_len_less_16bytes
  693. + andi a2, a2, 63
  694. +
  695. +.L_len_larger_16bytes:
  696. + ld a4, 0(a1)
  697. + sd a4, 0(a0)
  698. + ld a5, 8(a1)
  699. + sd a5, 8(a0)
  700. + ld a6, 16(a1)
  701. + sd a6, 16(a0)
  702. + ld a7, 24(a1)
  703. + sd a7, 24(a0)
  704. + ld a4, 32(a1)
  705. + sd a4, 32(a0)
  706. + ld a5, 40(a1)
  707. + sd a5, 40(a0)
  708. + ld a6, 48(a1)
  709. + sd a6, 48(a0)
  710. + ld a7, 56(a1)
  711. + sub t4, t4, t3
  712. + addi a1, a1, 64
  713. + sd a7, 56(a0)
  714. + addi a0, a0, 64
  715. + bnez t4, .L_len_larger_16bytes
  716. +
  717. +.L_len_less_16bytes:
  718. + srli t4, a2, 2
  719. + beqz t4, .L_copy_by_byte
  720. + andi a2, a2, 3
  721. +.L_len_less_16bytes_loop:
  722. + lw a4, 0(a1)
  723. + sub t4, t4, t3
  724. + addi a1, a1, 4
  725. + sw a4, 0(a0)
  726. + addi a0, a0, 4
  727. + bnez t4, .L_len_less_16bytes_loop
  728. +
  729. + /* Copy tail. */
  730. +.L_copy_by_byte:
  731. + andi t4, a2, 7
  732. + beqz t4, .L_return
  733. +.L_copy_by_byte_loop:
  734. + lb a4, 0(a1)
  735. + sub t4, t4, t3
  736. + addi a1, a1, 1
  737. + sb a4, 0(a0)
  738. + addi a0, a0, 1
  739. + bnez t4, .L_copy_by_byte_loop
  740. +
  741. +.L_return:
  742. + mv a0, t6
  743. + ret
  744. +
  745. + /* If dest is not aligned, just copying some bytes makes the dest
  746. + align. */
  747. +.L_dest_not_aligned:
  748. + sub a3, t5, a3
  749. + mv t5, a3
  750. +.L_dest_not_aligned_loop:
  751. + /* Makes the dest align. */
  752. + lb a4, 0(a1)
  753. + sub a3, a3, t3
  754. + addi a1, a1, 1
  755. + sb a4, 0(a0)
  756. + addi a0, a0, 1
  757. + bnez a3, .L_dest_not_aligned_loop
  758. + sub a2, a2, t5
  759. + sltiu a3, a2, 4
  760. + bnez a3, .L_copy_by_byte
  761. + /* Check whether the src is aligned. */
  762. + j .L_dest_aligned
  763. +END (memcpy)
  764. +
  765. +libc_hidden_builtin_def (memcpy)
  766. diff --git a/sysdeps/riscv/rv64/multiarch/memcpy_riscv.S b/sysdeps/riscv/rv64/multiarch/memcpy_riscv.S
  767. new file mode 100644
  768. index 0000000000..a0ba2150fc
  769. --- /dev/null
  770. +++ b/sysdeps/riscv/rv64/multiarch/memcpy_riscv.S
  771. @@ -0,0 +1,25 @@
  772. +/* The assembly function for memcpy. RISC-V version.
  773. + Copyright (C) 2018 Free Software Foundation, Inc.
  774. + This file is part of the GNU C Library.
  775. +
  776. + The GNU C Library is free software; you can redistribute it and/or
  777. + modify it under the terms of the GNU Lesser General Public
  778. + License as published by the Free Software Foundation; either
  779. + version 2.1 of the License, or (at your option) any later version.
  780. +
  781. + The GNU C Library is distributed in the hope that it will be useful,
  782. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  783. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  784. + Lesser General Public License for more details.
  785. +
  786. + You should have received a copy of the GNU Lesser General Public
  787. + License along with the GNU C Library. If not, see
  788. + <http://www.gnu.org/licenses/>. */
  789. +
  790. +#include <sysdep.h>
  791. +
  792. +#define memcpy __memcpy_riscv
  793. +#undef libc_hidden_builtin_def
  794. +#define libc_hidden_builtin_def(name)
  795. +
  796. +#include "memcpy_as.S"
  797. \ No newline at end of file
  798. diff --git a/sysdeps/riscv/rv64/multiarch/memcpy_vector.S b/sysdeps/riscv/rv64/multiarch/memcpy_vector.S
  799. new file mode 100644
  800. index 0000000000..2319647de8
  801. --- /dev/null
  802. +++ b/sysdeps/riscv/rv64/multiarch/memcpy_vector.S
  803. @@ -0,0 +1,54 @@
  804. +/* The assembly function for memcpy. RISC-V version.
  805. + Copyright (C) 2018 Free Software Foundation, Inc.
  806. + This file is part of the GNU C Library.
  807. +
  808. + The GNU C Library is free software; you can redistribute it and/or
  809. + modify it under the terms of the GNU Lesser General Public
  810. + License as published by the Free Software Foundation; either
  811. + version 2.1 of the License, or (at your option) any later version.
  812. +
  813. + The GNU C Library is distributed in the hope that it will be useful,
  814. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  815. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  816. + Lesser General Public License for more details.
  817. +
  818. + You should have received a copy of the GNU Lesser General Public
  819. + License along with the GNU C Library. If not, see
  820. + <http://www.gnu.org/licenses/>. */
  821. +
  822. +#include <sysdep.h>
  823. +
  824. +/* For __riscv_vector this file defines memcpy. */
  825. +/* #ifndef __riscv_vector */
  826. +# define memcpy __memcpy_vector
  827. +# undef libc_hidden_builtin_def
  828. +# define libc_hidden_builtin_def(a)
  829. +/* #endif */
  830. +
  831. + .p2align 6
  832. +ENTRY (memcpy)
  833. + mv a3, a0
  834. + sltiu a4, a2, 16
  835. + bnez a4, .loop_cpy
  836. + andi a5, a0, 15
  837. + li a6, 16
  838. + beqz a5, .loop_cpy
  839. + sub a5, a6, a5
  840. + vsetvli t0, a5, e8, m4
  841. + vle8.v v0, (a1)
  842. + add a1, a1, t0
  843. + sub a2, a2, t0
  844. + vse8.v v0, (a3)
  845. + add a3, a3, t0
  846. +.loop_cpy:
  847. + vsetvli t0, a2, e8, m4
  848. + vle8.v v0, (a1)
  849. + add a1, a1, t0
  850. + sub a2, a2, t0
  851. + vse8.v v0, (a3)
  852. + add a3, a3, t0
  853. + bnez a2, .loop_cpy
  854. + ret
  855. +END (memcpy)
  856. +
  857. +libc_hidden_builtin_def (memcpy)
  858. diff --git a/sysdeps/riscv/rv64/multiarch/memmove.c b/sysdeps/riscv/rv64/multiarch/memmove.c
  859. new file mode 100644
  860. index 0000000000..8d33da166d
  861. --- /dev/null
  862. +++ b/sysdeps/riscv/rv64/multiarch/memmove.c
  863. @@ -0,0 +1,32 @@
  864. +/* Multiple versions of memmove.
  865. + All versions must be listed in ifunc-impl-list.c.
  866. + Copyright (C) 2017-2021 Free Software Foundation, Inc.
  867. + This file is part of the GNU C Library.
  868. +
  869. + The GNU C Library is free software; you can redistribute it and/or
  870. + modify it under the terms of the GNU Lesser General Public
  871. + License as published by the Free Software Foundation; either
  872. + version 2.1 of the License, or (at your option) any later version.
  873. +
  874. + The GNU C Library is distributed in the hope that it will be useful,
  875. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  876. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  877. + Lesser General Public License for more details.
  878. +
  879. + You should have received a copy of the GNU Lesser General Public
  880. + License along with the GNU C Library; if not, see
  881. + <https://www.gnu.org/licenses/>. */
  882. +
  883. +#if IS_IN (libc)
  884. +# define memmove __redirect_memmove
  885. +# include <string.h>
  886. +# undef memmove
  887. +
  888. +# include <riscv-ifunc.h>
  889. +
  890. +# define SYMBOL_NAME memmove
  891. +# include "ifunc-common.h"
  892. +
  893. +riscv_libc_ifunc_redirected (__redirect_memmove, memmove, IFUNC_SELECTOR);
  894. +riscv_libc_ifunc_hidden_def (__redirect_memmove, memmove);
  895. +#endif
  896. diff --git a/sysdeps/riscv/rv64/multiarch/memmove_riscv.c b/sysdeps/riscv/rv64/multiarch/memmove_riscv.c
  897. new file mode 100644
  898. index 0000000000..e11a9d1a43
  899. --- /dev/null
  900. +++ b/sysdeps/riscv/rv64/multiarch/memmove_riscv.c
  901. @@ -0,0 +1,29 @@
  902. +/* RISCV C version memmov.
  903. + Copyright (C) 2018-2021 Free Software Foundation, Inc.
  904. + This file is part of the GNU C Library.
  905. +
  906. + The GNU C Library is free software; you can redistribute it and/or
  907. + modify it under the terms of the GNU Lesser General Public
  908. + License as published by the Free Software Foundation; either
  909. + version 2.1 of the License, or (at your option) any later version.
  910. +
  911. + The GNU C Library is distributed in the hope that it will be useful,
  912. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  913. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  914. + Lesser General Public License for more details.
  915. +
  916. + You should have received a copy of the GNU Lesser General Public
  917. + License along with the GNU C Library; if not, see
  918. + <https://www.gnu.org/licenses/>. */
  919. +
  920. +#if IS_IN (libc)
  921. +#undef libc_hidden_builtin_def
  922. +#define libc_hidden_builtin_def(name)
  923. +
  924. +#undef weak_alias
  925. +# define MEMMOVE __memmove_riscv
  926. +# include <string/memmove.c>
  927. +#else
  928. +
  929. +# include <string/memmove.c>
  930. +#endif
  931. diff --git a/sysdeps/riscv/rv64/multiarch/memmove_vector.S b/sysdeps/riscv/rv64/multiarch/memmove_vector.S
  932. new file mode 100644
  933. index 0000000000..7bf89e6cf6
  934. --- /dev/null
  935. +++ b/sysdeps/riscv/rv64/multiarch/memmove_vector.S
  936. @@ -0,0 +1,56 @@
  937. +/* The assembly function for memmov. RISC-V version.
  938. + Copyright (C) 2018 Free Software Foundation, Inc.
  939. + This file is part of the GNU C Library.
  940. +
  941. + The GNU C Library is free software; you can redistribute it and/or
  942. + modify it under the terms of the GNU Lesser General Public
  943. + License as published by the Free Software Foundation; either
  944. + version 2.1 of the License, or (at your option) any later version.
  945. +
  946. + The GNU C Library is distributed in the hope that it will be useful,
  947. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  948. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  949. + Lesser General Public License for more details.
  950. +
  951. + You should have received a copy of the GNU Lesser General Public
  952. + License along with the GNU C Library. If not, see
  953. + <http://www.gnu.org/licenses/>. */
  954. +
  955. +#include <sysdep.h>
  956. +
  957. +/* For __riscv_vector this file defines memmov. */
  958. +/* #ifndef __riscv_vector */
  959. +# define memmove __memmove_vector
  960. +# undef libc_hidden_builtin_def
  961. +# define libc_hidden_builtin_def(a)
  962. +/* #endif */
  963. +
  964. + .p2align 6
  965. +ENTRY (memmove)
  966. + add a4,a0,zero
  967. + bgeu a1,a0,.L_forward_copy_loop
  968. + add a5,a1,a2
  969. + add a6,a0,a2
  970. + bltu a0,a5,.L_backward_copy_loop
  971. +
  972. +.L_forward_copy_loop:
  973. + vsetvli a3,a2,e8,m8,tu,mu
  974. + vle8.v v0,(a1)
  975. + sub a2,a2,a3
  976. + add a1,a1,a3
  977. + vse8.v v0,(a4)
  978. + add a4,a4,a3
  979. + bltu zero,a2,.L_forward_copy_loop
  980. + ret
  981. +
  982. +.L_backward_copy_loop:
  983. + vsetvli a3,a2,e8,m8,tu,mu
  984. + sub a5,a5,a3
  985. + vle8.v v0,(a5)
  986. + sub a2,a2,a3
  987. + sub a6,a6,a3
  988. + vse8.v v0,(a6)
  989. + bltu zero,a2,.L_backward_copy_loop
  990. + ret
  991. +END (memmove)
  992. +libc_hidden_builtin_def (memmove)
  993. \ No newline at end of file
  994. diff --git a/sysdeps/riscv/rv64/multiarch/memset.c b/sysdeps/riscv/rv64/multiarch/memset.c
  995. new file mode 100644
  996. index 0000000000..0d3582e49f
  997. --- /dev/null
  998. +++ b/sysdeps/riscv/rv64/multiarch/memset.c
  999. @@ -0,0 +1,33 @@
  1000. +/* Multiple versions of memset.
  1001. + All versions must be listed in ifunc-impl-list.c.
  1002. + Copyright (C) 2017-2021 Free Software Foundation, Inc.
  1003. + This file is part of the GNU C Library.
  1004. +
  1005. + The GNU C Library is free software; you can redistribute it and/or
  1006. + modify it under the terms of the GNU Lesser General Public
  1007. + License as published by the Free Software Foundation; either
  1008. + version 2.1 of the License, or (at your option) any later version.
  1009. +
  1010. + The GNU C Library is distributed in the hope that it will be useful,
  1011. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  1012. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1013. + Lesser General Public License for more details.
  1014. +
  1015. + You should have received a copy of the GNU Lesser General Public
  1016. + License along with the GNU C Library; if not, see
  1017. + <https://www.gnu.org/licenses/>. */
  1018. +
  1019. +#if IS_IN (libc)
  1020. +# define memset __redirect_memset
  1021. +# include <string.h>
  1022. +# undef memset
  1023. +
  1024. +# include <riscv-ifunc.h>
  1025. +
  1026. +# define SYMBOL_NAME memset
  1027. +# include "ifunc-common.h"
  1028. +
  1029. +riscv_libc_ifunc_redirected (__redirect_memset, memset, IFUNC_SELECTOR);
  1030. +
  1031. +riscv_libc_ifunc_hidden_def (__redirect_memset, memset);
  1032. +#endif
  1033. diff --git a/sysdeps/riscv/rv64/multiarch/memset_riscv.c b/sysdeps/riscv/rv64/multiarch/memset_riscv.c
  1034. new file mode 100644
  1035. index 0000000000..1101c10f96
  1036. --- /dev/null
  1037. +++ b/sysdeps/riscv/rv64/multiarch/memset_riscv.c
  1038. @@ -0,0 +1,29 @@
  1039. +/* RISCV C version memset.
  1040. + Copyright (C) 2018-2021 Free Software Foundation, Inc.
  1041. + This file is part of the GNU C Library.
  1042. +
  1043. + The GNU C Library is free software; you can redistribute it and/or
  1044. + modify it under the terms of the GNU Lesser General Public
  1045. + License as published by the Free Software Foundation; either
  1046. + version 2.1 of the License, or (at your option) any later version.
  1047. +
  1048. + The GNU C Library is distributed in the hope that it will be useful,
  1049. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  1050. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1051. + Lesser General Public License for more details.
  1052. +
  1053. + You should have received a copy of the GNU Lesser General Public
  1054. + License along with the GNU C Library; if not, see
  1055. + <https://www.gnu.org/licenses/>. */
  1056. +
  1057. +#if IS_IN (libc)
  1058. +#undef libc_hidden_builtin_def
  1059. +#define libc_hidden_builtin_def(name)
  1060. +
  1061. +#undef weak_alias
  1062. +# define MEMSET __memset_riscv
  1063. +# include <string/memset.c>
  1064. +#else
  1065. +
  1066. +# include <string/memset.c>
  1067. +#endif
  1068. diff --git a/sysdeps/riscv/rv64/multiarch/memset_vector.S b/sysdeps/riscv/rv64/multiarch/memset_vector.S
  1069. new file mode 100644
  1070. index 0000000000..54d04238d3
  1071. --- /dev/null
  1072. +++ b/sysdeps/riscv/rv64/multiarch/memset_vector.S
  1073. @@ -0,0 +1,45 @@
  1074. +
  1075. +/* The assembly function for memset. RISC-V version.
  1076. + Copyright (C) 2018 Free Software Foundation, Inc.
  1077. + This file is part of the GNU C Library.
  1078. +
  1079. + The GNU C Library is free software; you can redistribute it and/or
  1080. + modify it under the terms of the GNU Lesser General Public
  1081. + License as published by the Free Software Foundation; either
  1082. + version 2.1 of the License, or (at your option) any later version.
  1083. +
  1084. + The GNU C Library is distributed in the hope that it will be useful,
  1085. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  1086. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1087. + Lesser General Public License for more details.
  1088. +
  1089. + You should have received a copy of the GNU Lesser General Public
  1090. + License along with the GNU C Library. If not, see
  1091. + <http://www.gnu.org/licenses/>. */
  1092. +
  1093. +#include <sysdep.h>
  1094. +
  1095. +/* For __riscv_vector this file defines memcpy. */
  1096. +/* #ifndef __riscv_vector */
  1097. +# define memset __memset_vector
  1098. +# undef libc_hidden_builtin_def
  1099. +# define libc_hidden_builtin_def(a)
  1100. +/* #endif */
  1101. +
  1102. + .p2align 6
  1103. +ENTRY (memset)
  1104. +
  1105. + zext.b a1,a1
  1106. + add a5,a0,zero
  1107. + vsetvli a3,a2,e8,m8,tu,mu
  1108. + vmv.v.x v0,a1
  1109. +.L_memset_loop:
  1110. + vse8.v v0,(a5)
  1111. + sub a2,a2,a3
  1112. + add a5,a5,a3
  1113. + vsetvli a3,a2,e8,m8,tu,mu
  1114. + bltu zero,a2,.L_memset_loop
  1115. + ret
  1116. +
  1117. +END (memset)
  1118. +libc_hidden_builtin_def (memset)
  1119. diff --git a/sysdeps/riscv/rv64/multiarch/rtld-memchr.S b/sysdeps/riscv/rv64/multiarch/rtld-memchr.S
  1120. new file mode 100644
  1121. index 0000000000..0e68548e97
  1122. --- /dev/null
  1123. +++ b/sysdeps/riscv/rv64/multiarch/rtld-memchr.S
  1124. @@ -0,0 +1 @@
  1125. +#include "memchr_as.S"
  1126. \ No newline at end of file
  1127. diff --git a/sysdeps/riscv/rv64/multiarch/rtld-memcmp.c b/sysdeps/riscv/rv64/multiarch/rtld-memcmp.c
  1128. new file mode 100644
  1129. index 0000000000..25faa66478
  1130. --- /dev/null
  1131. +++ b/sysdeps/riscv/rv64/multiarch/rtld-memcmp.c
  1132. @@ -0,0 +1 @@
  1133. +#include "memcmp_riscv.c"
  1134. diff --git a/sysdeps/riscv/rv64/multiarch/rtld-memcpy.S b/sysdeps/riscv/rv64/multiarch/rtld-memcpy.S
  1135. new file mode 100644
  1136. index 0000000000..81f48f3aea
  1137. --- /dev/null
  1138. +++ b/sysdeps/riscv/rv64/multiarch/rtld-memcpy.S
  1139. @@ -0,0 +1 @@
  1140. +#include "memcpy_as.S"
  1141. \ No newline at end of file
  1142. diff --git a/sysdeps/riscv/rv64/multiarch/rtld-memmove.c b/sysdeps/riscv/rv64/multiarch/rtld-memmove.c
  1143. new file mode 100644
  1144. index 0000000000..435c059184
  1145. --- /dev/null
  1146. +++ b/sysdeps/riscv/rv64/multiarch/rtld-memmove.c
  1147. @@ -0,0 +1,19 @@
  1148. +/* RISCV C version memmove.
  1149. + Copyright (C) 2018-2021 Free Software Foundation, Inc.
  1150. + This file is part of the GNU C Library.
  1151. +
  1152. + The GNU C Library is free software; you can redistribute it and/or
  1153. + modify it under the terms of the GNU Lesser General Public
  1154. + License as published by the Free Software Foundation; either
  1155. + version 2.1 of the License, or (at your option) any later version.
  1156. +
  1157. + The GNU C Library is distributed in the hope that it will be useful,
  1158. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  1159. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1160. + Lesser General Public License for more details.
  1161. +
  1162. + You should have received a copy of the GNU Lesser General Public
  1163. + License along with the GNU C Library; if not, see
  1164. + <https://www.gnu.org/licenses/>. */
  1165. +
  1166. +#include "memmove_riscv.c"
  1167. diff --git a/sysdeps/riscv/rv64/multiarch/rtld-memset.c b/sysdeps/riscv/rv64/multiarch/rtld-memset.c
  1168. new file mode 100644
  1169. index 0000000000..eff6790df5
  1170. --- /dev/null
  1171. +++ b/sysdeps/riscv/rv64/multiarch/rtld-memset.c
  1172. @@ -0,0 +1 @@
  1173. +#include "memset_riscv.c"
  1174. \ No newline at end of file
  1175. diff --git a/sysdeps/riscv/rv64/multiarch/rtld-strcmp.S b/sysdeps/riscv/rv64/multiarch/rtld-strcmp.S
  1176. new file mode 100644
  1177. index 0000000000..eb6ff5f8d3
  1178. --- /dev/null
  1179. +++ b/sysdeps/riscv/rv64/multiarch/rtld-strcmp.S
  1180. @@ -0,0 +1 @@
  1181. +#include "strcmp_.S"
  1182. \ No newline at end of file
  1183. diff --git a/sysdeps/riscv/rv64/multiarch/rtld-strlen.c b/sysdeps/riscv/rv64/multiarch/rtld-strlen.c
  1184. new file mode 100644
  1185. index 0000000000..73308eb0fa
  1186. --- /dev/null
  1187. +++ b/sysdeps/riscv/rv64/multiarch/rtld-strlen.c
  1188. @@ -0,0 +1 @@
  1189. +#include "strlen_riscv.c"
  1190. diff --git a/sysdeps/riscv/rv64/multiarch/strcmp.c b/sysdeps/riscv/rv64/multiarch/strcmp.c
  1191. new file mode 100644
  1192. index 0000000000..56969c77e8
  1193. --- /dev/null
  1194. +++ b/sysdeps/riscv/rv64/multiarch/strcmp.c
  1195. @@ -0,0 +1,33 @@
  1196. +/* Multiple versions of strcmp.
  1197. + All versions must be listed in ifunc-impl-list.c.
  1198. + Copyright (C) 2017-2021 Free Software Foundation, Inc.
  1199. + This file is part of the GNU C Library.
  1200. +
  1201. + The GNU C Library is free software; you can redistribute it and/or
  1202. + modify it under the terms of the GNU Lesser General Public
  1203. + License as published by the Free Software Foundation; either
  1204. + version 2.1 of the License, or (at your option) any later version.
  1205. +
  1206. + The GNU C Library is distributed in the hope that it will be useful,
  1207. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  1208. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1209. + Lesser General Public License for more details.
  1210. +
  1211. + You should have received a copy of the GNU Lesser General Public
  1212. + License along with the GNU C Library; if not, see
  1213. + <https://www.gnu.org/licenses/>. */
  1214. +
  1215. +#if IS_IN (libc)
  1216. +# define strcmp __redirect_strcmp
  1217. +# include <string.h>
  1218. +# undef strcmp
  1219. +
  1220. +# include <riscv-ifunc.h>
  1221. +
  1222. +# define SYMBOL_NAME strcmp
  1223. +# include "ifunc-common.h"
  1224. +
  1225. +riscv_libc_ifunc_redirected (__redirect_strcmp, strcmp, IFUNC_SELECTOR);
  1226. +
  1227. +riscv_libc_ifunc_hidden_def (__redirect_strcmp, strcmp);
  1228. +#endif
  1229. diff --git a/sysdeps/riscv/rv64/multiarch/strcmp_.S b/sysdeps/riscv/rv64/multiarch/strcmp_.S
  1230. new file mode 100644
  1231. index 0000000000..db5a6346b8
  1232. --- /dev/null
  1233. +++ b/sysdeps/riscv/rv64/multiarch/strcmp_.S
  1234. @@ -0,0 +1,39 @@
  1235. +
  1236. +
  1237. +/* The assembly function for strcmp. RISC-V version.
  1238. + Copyright (C) 2018 Free Software Foundation, Inc.
  1239. + This file is part of the GNU C Library.
  1240. +
  1241. + The GNU C Library is free software; you can redistribute it and/or
  1242. + modify it under the terms of the GNU Lesser General Public
  1243. + License as published by the Free Software Foundation; either
  1244. + version 2.1 of the License, or (at your option) any later version.
  1245. +
  1246. + The GNU C Library is distributed in the hope that it will be useful,
  1247. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  1248. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1249. + Lesser General Public License for more details.
  1250. +
  1251. + You should have received a copy of the GNU Lesser General Public
  1252. + License along with the GNU C Library. If not, see
  1253. + <http://www.gnu.org/licenses/>. */
  1254. +
  1255. +#include <sysdep.h>
  1256. +
  1257. + .p2align 6
  1258. +ENTRY (strcmp)
  1259. +.L_strcmp_by_byte:
  1260. + lbu a5,0(a0)
  1261. + addi a1,a1,1
  1262. + addi a0,a0,1
  1263. + lbu a4,-1(a1)
  1264. + beqz a5,.L_strcmp_by_byte_exit
  1265. + beq a5,a4,.L_strcmp_by_byte
  1266. + subw a0,a5,a4
  1267. + ret
  1268. +.L_strcmp_by_byte_exit:
  1269. + negw a0,a4
  1270. + ret
  1271. +
  1272. +END (strcmp)
  1273. +libc_hidden_builtin_def (strcmp)
  1274. diff --git a/sysdeps/riscv/rv64/multiarch/strcmp_riscv.S b/sysdeps/riscv/rv64/multiarch/strcmp_riscv.S
  1275. new file mode 100644
  1276. index 0000000000..93e598f0c5
  1277. --- /dev/null
  1278. +++ b/sysdeps/riscv/rv64/multiarch/strcmp_riscv.S
  1279. @@ -0,0 +1,9 @@
  1280. +
  1281. +/* For __riscv_vector this file defines strcmp. */
  1282. +/* #ifndef __riscv_vector */
  1283. +# define strcmp __strcmp_riscv
  1284. +# undef libc_hidden_builtin_def
  1285. +# define libc_hidden_builtin_def(a)
  1286. +/* #endif */
  1287. +
  1288. +#include "strcmp_.S"
  1289. \ No newline at end of file
  1290. diff --git a/sysdeps/riscv/rv64/multiarch/strcmp_vector.S b/sysdeps/riscv/rv64/multiarch/strcmp_vector.S
  1291. new file mode 100644
  1292. index 0000000000..41d653748a
  1293. --- /dev/null
  1294. +++ b/sysdeps/riscv/rv64/multiarch/strcmp_vector.S
  1295. @@ -0,0 +1,54 @@
  1296. +/* The assembly function for strcmp. RISC-V version.
  1297. + Copyright (C) 2018 Free Software Foundation, Inc.
  1298. + This file is part of the GNU C Library.
  1299. +
  1300. + The GNU C Library is free software; you can redistribute it and/or
  1301. + modify it under the terms of the GNU Lesser General Public
  1302. + License as published by the Free Software Foundation; either
  1303. + version 2.1 of the License, or (at your option) any later version.
  1304. +
  1305. + The GNU C Library is distributed in the hope that it will be useful,
  1306. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  1307. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1308. + Lesser General Public License for more details.
  1309. +
  1310. + You should have received a copy of the GNU Lesser General Public
  1311. + License along with the GNU C Library. If not, see
  1312. + <http://www.gnu.org/licenses/>. */
  1313. +
  1314. +#include <sysdep.h>
  1315. +
  1316. +/* For __riscv_vector this file defines strcmp. */
  1317. +/* #ifndef __riscv_vector */
  1318. +# define strcmp __strcmp_vector
  1319. +# undef libc_hidden_builtin_def
  1320. +# define libc_hidden_builtin_def(a)
  1321. +/* #endif */
  1322. +
  1323. + .p2align 6
  1324. +ENTRY (strcmp)
  1325. +
  1326. + vsetvli a3,zero,e8,m8,tu,mu
  1327. +.L_strcmp_loop:
  1328. + vle8ff.v v0,(a0)
  1329. + vmseq.vx v16,v0,zero
  1330. + vle8ff.v v8,(a1)
  1331. + vmsne.vv v17,v0,v8
  1332. + vmor.mm v16,v16,v17
  1333. + vfirst.m a4,v16
  1334. + bgez a4, .L_strcmp_loop_exit
  1335. + add a0,a0,a3
  1336. + add a1,a1,a3
  1337. + j .L_strcmp_loop
  1338. +
  1339. +.L_strcmp_loop_exit:
  1340. + add a0,a0,a4
  1341. + add a1,a1,a4
  1342. + lbu a4,0(a0)
  1343. + lbu a5,0(a1)
  1344. + sub a0,a4,a5
  1345. + ret
  1346. +
  1347. +END (strcmp)
  1348. +libc_hidden_builtin_def (strcmp)
  1349. +
  1350. diff --git a/sysdeps/riscv/rv64/multiarch/strlen.c b/sysdeps/riscv/rv64/multiarch/strlen.c
  1351. new file mode 100644
  1352. index 0000000000..292c9103fa
  1353. --- /dev/null
  1354. +++ b/sysdeps/riscv/rv64/multiarch/strlen.c
  1355. @@ -0,0 +1,32 @@
  1356. +/* Multiple versions of strlen.
  1357. + All versions must be listed in ifunc-impl-list.c.
  1358. + Copyright (C) 2017-2021 Free Software Foundation, Inc.
  1359. + This file is part of the GNU C Library.
  1360. +
  1361. + The GNU C Library is free software; you can redistribute it and/or
  1362. + modify it under the terms of the GNU Lesser General Public
  1363. + License as published by the Free Software Foundation; either
  1364. + version 2.1 of the License, or (at your option) any later version.
  1365. +
  1366. + The GNU C Library is distributed in the hope that it will be useful,
  1367. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  1368. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1369. + Lesser General Public License for more details.
  1370. +
  1371. + You should have received a copy of the GNU Lesser General Public
  1372. + License along with the GNU C Library; if not, see
  1373. + <https://www.gnu.org/licenses/>. */
  1374. +
  1375. +#if IS_IN (libc)
  1376. +# define strlen __redirect_strlen
  1377. +# include <string.h>
  1378. +# undef strlen
  1379. +
  1380. +# include <riscv-ifunc.h>
  1381. +
  1382. +# define SYMBOL_NAME strlen
  1383. +# include "ifunc-common.h"
  1384. +
  1385. +riscv_libc_ifunc_redirected (__redirect_strlen, strlen, IFUNC_SELECTOR);
  1386. +riscv_libc_ifunc_hidden_def (__redirect_strlen, strlen);
  1387. +#endif
  1388. diff --git a/sysdeps/riscv/rv64/multiarch/strlen_riscv.c b/sysdeps/riscv/rv64/multiarch/strlen_riscv.c
  1389. new file mode 100644
  1390. index 0000000000..e17a5dde31
  1391. --- /dev/null
  1392. +++ b/sysdeps/riscv/rv64/multiarch/strlen_riscv.c
  1393. @@ -0,0 +1,29 @@
  1394. +/* RISCV C version strlen.
  1395. + Copyright (C) 2018-2021 Free Software Foundation, Inc.
  1396. + This file is part of the GNU C Library.
  1397. +
  1398. + The GNU C Library is free software; you can redistribute it and/or
  1399. + modify it under the terms of the GNU Lesser General Public
  1400. + License as published by the Free Software Foundation; either
  1401. + version 2.1 of the License, or (at your option) any later version.
  1402. +
  1403. + The GNU C Library is distributed in the hope that it will be useful,
  1404. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  1405. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1406. + Lesser General Public License for more details.
  1407. +
  1408. + You should have received a copy of the GNU Lesser General Public
  1409. + License along with the GNU C Library; if not, see
  1410. + <https://www.gnu.org/licenses/>. */
  1411. +
  1412. +#if IS_IN (libc)
  1413. +#undef libc_hidden_builtin_def
  1414. +#define libc_hidden_builtin_def(name)
  1415. +
  1416. +#undef weak_alias
  1417. +# define STRLEN __strlen_riscv
  1418. +# include <string/strlen.c>
  1419. +#else
  1420. +
  1421. +# include <string/strlen.c>
  1422. +#endif
  1423. diff --git a/sysdeps/riscv/rv64/multiarch/strlen_vector.S b/sysdeps/riscv/rv64/multiarch/strlen_vector.S
  1424. new file mode 100644
  1425. index 0000000000..dd080e3a2f
  1426. --- /dev/null
  1427. +++ b/sysdeps/riscv/rv64/multiarch/strlen_vector.S
  1428. @@ -0,0 +1,46 @@
  1429. +/* The assembly function for strlen. RISC-V version.
  1430. + Copyright (C) 2018 Free Software Foundation, Inc.
  1431. + This file is part of the GNU C Library.
  1432. +
  1433. + The GNU C Library is free software; you can redistribute it and/or
  1434. + modify it under the terms of the GNU Lesser General Public
  1435. + License as published by the Free Software Foundation; either
  1436. + version 2.1 of the License, or (at your option) any later version.
  1437. +
  1438. + The GNU C Library is distributed in the hope that it will be useful,
  1439. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  1440. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1441. + Lesser General Public License for more details.
  1442. +
  1443. + You should have received a copy of the GNU Lesser General Public
  1444. + License along with the GNU C Library. If not, see
  1445. + <http://www.gnu.org/licenses/>. */
  1446. +
  1447. +#include <sysdep.h>
  1448. +
  1449. +/* For __riscv_vector this file defines strlen. */
  1450. +/* #ifndef __riscv_vector */
  1451. +# define strlen __strlen_vector
  1452. +# undef libc_hidden_builtin_def
  1453. +# define libc_hidden_builtin_def(a)
  1454. +/* #endif */
  1455. +
  1456. + .p2align 6
  1457. +ENTRY (strlen)
  1458. + mv a1,a0
  1459. +
  1460. +.strlen_loop:
  1461. + vsetvli a2,zero,e8,m8,tu,mu
  1462. + vle8ff.v v0,(a1)
  1463. + csrr a2,vl
  1464. + vmseq.vi v8,v0,0
  1465. + vfirst.m a3,v8
  1466. + add a1,a1,a2
  1467. + bltz a3, .strlen_loop
  1468. + add a0,a0,a2
  1469. + add a1,a1,a3
  1470. + sub a0,a1,a0
  1471. + ret
  1472. +
  1473. +END (strlen)
  1474. +libc_hidden_builtin_def (strlen)
  1475. diff --git a/sysdeps/riscv/sysdep.h b/sysdeps/riscv/sysdep.h
  1476. new file mode 100644
  1477. index 0000000000..5229cfaf02
  1478. --- /dev/null
  1479. +++ b/sysdeps/riscv/sysdep.h
  1480. @@ -0,0 +1,24 @@
  1481. +/* Copyright (C) 2011-2021 Free Software Foundation, Inc.
  1482. + This file is part of the GNU C Library.
  1483. +
  1484. + The GNU C Library is free software; you can redistribute it and/or
  1485. + modify it under the terms of the GNU Lesser General Public
  1486. + License as published by the Free Software Foundation; either
  1487. + version 2.1 of the License, or (at your option) any later version.
  1488. +
  1489. + The GNU C Library is distributed in the hope that it will be useful,
  1490. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  1491. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1492. + Lesser General Public License for more details.
  1493. +
  1494. + You should have received a copy of the GNU Lesser General Public
  1495. + License along with the GNU C Library; if not, see
  1496. + <https://www.gnu.org/licenses/>. */
  1497. +
  1498. +#define _SYSDEPS_SYSDEP_H 1
  1499. +#include <sysdeps/generic/sysdep.h>
  1500. +#include <sys/auxv.h>
  1501. +
  1502. +#ifdef __ASSEMBLER__
  1503. +
  1504. +#endif /* __ASSEMBLER__ */
  1505. diff --git a/sysdeps/unix/sysv/linux/riscv/sysdep.h b/sysdeps/unix/sysv/linux/riscv/sysdep.h
  1506. index c9f8fd8236..7b75bdfee2 100644
  1507. --- a/sysdeps/unix/sysv/linux/riscv/sysdep.h
  1508. +++ b/sysdeps/unix/sysv/linux/riscv/sysdep.h
  1509. @@ -21,6 +21,7 @@
  1510. #include <sysdeps/unix/sysv/linux/generic/sysdep.h>
  1511. #include <tls.h>
  1512. +# include <bits/hwcap.h>
  1513. #undef SYS_ify
  1514. #define SYS_ify(syscall_name) __NR_##syscall_name
  1515. @@ -50,7 +51,6 @@
  1516. #ifdef __ASSEMBLER__
  1517. -# include <bits/hwcap.h>
  1518. # include <sys/asm.h>
  1519. # define ENTRY(name) LEAF(name)
  1520. --
  1521. 2.25.1