From: Luke Kenneth Casson Leighton Date: Mon, 8 Jan 2024 12:22:49 +0000 (+0000) Subject: bug 1244: add strncpy assembler and c X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2b39e35942c34afc9ffd0413cc350265f57defd2;p=libreriscv.git bug 1244: add strncpy assembler and c --- diff --git a/conferences/fosdem2024/fosdem2024_ddffirst/fosdem2024_ddffirst.tex b/conferences/fosdem2024/fosdem2024_ddffirst/fosdem2024_ddffirst.tex index fcdccdbc5..dcbd7886a 100644 --- a/conferences/fosdem2024/fosdem2024_ddffirst/fosdem2024_ddffirst.tex +++ b/conferences/fosdem2024/fosdem2024_ddffirst/fosdem2024_ddffirst.tex @@ -2,6 +2,8 @@ \usepackage{beamerthemesplit} \usepackage{graphics} \usepackage{pstricks} +\usepackage{pgffor} +\usepackage{listings} \graphicspath{{./}} @@ -209,11 +211,20 @@ function op\_cmpi(BA, RA, SI) # cmpi not vector-cmpi! \end{semiverbatim} } + \frame{\frametitle{strncpy} + \begin{itemize} \item "TODO \end{itemize} } + +\frame{\frametitle{strncpy assembler} + +\lstinputlisting[language={}]{\strncpy.s} + +} + \frame{\frametitle{linked-list walking} \begin{itemize} \item "TODO diff --git a/conferences/fosdem2024/fosdem2024_ddffirst/strncpy.c b/conferences/fosdem2024/fosdem2024_ddffirst/strncpy.c new file mode 100644 index 000000000..0c76efa2a --- /dev/null +++ b/conferences/fosdem2024/fosdem2024_ddffirst/strncpy.c @@ -0,0 +1,4 @@ +for (i = 0; i < n && src[i] != chr(0); i++) + dest[i] = src[i]; +for ( ; i < n; i++) + dest[i] = chr(0); diff --git a/conferences/fosdem2024/fosdem2024_ddffirst/strncpy.s b/conferences/fosdem2024/fosdem2024_ddffirst/strncpy.s new file mode 100644 index 000000000..6fd30f45c --- /dev/null +++ b/conferences/fosdem2024/fosdem2024_ddffirst/strncpy.s @@ -0,0 +1,15 @@ + mtspr 9, 3 # move r3 to CTR + addi 0,0,0 # initialise r0 to zero +L1: # chr-copy loop starts here: + setvl 1,0,64,0,1,1 # VL,r1 = MIN(CTR,MVL=64) + # load VL bytes (update r10 addr) + sv.lbzu/pi *16, 1(10) + sv.cmpi/ff=eq/vli *0,1,*16,0 # cmp 0, chop VL + # store VL bytes (update r12 addr) + sv.stbu/pi *16, 1(12) + sv.bc/all 0, *2, L1 # stop if cmpi failed +L2: # zeroing loop starts here: + setvl 1,0,64,0,1,1 # VL,r1 = MIN(CTR,MVL=64) + # store VL zeros (update r12 addr) + sv.stbu/pi 0, 1(12) + sv.bc 16, *0, L2 # dec CTR by VL