public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: "Xiao Zeng" <zengxiao@eswincomputing.com>
To: "Torbjorn SVENSSON" <torbjorn.svensson@foss.st.com>,
	 "newlib@sourceware.org" <newlib@sourceware.org>
Cc: "vapier@gentoo.org" <vapier@gentoo.org>,
	 "palmer@rivosinc.com" <palmer@rivosinc.com>,
	 jeffreyalaw <jeffreyalaw@gmail.com>
Subject: Re: Re: [PATCH] newlib: libc: Improved the readability of strcspn with minor optimization
Date: Sat, 16 Dec 2023 12:45:47 +0800	[thread overview]
Message-ID: <2023121612454699234314@eswincomputing.com> (raw)
In-Reply-To: <70b09ef7-fe4a-4669-ad27-2bd6c8bdca61@foss.st.com>

2023-12-15 18:28  Torbjorn SVENSSON <torbjorn.svensson@foss.st.com> wrote:
>
Hi Bob, I worked under the risc-v architecture and obtained the newlib library through
cross compilation. This is my first attempt to contribute code to newlib. 

>Hello Xiao,
>
>On 2023-12-15 09:31, Xiao Zeng wrote:
>> Signed-off-by: Xiao Zeng <zengxiao@eswincomputing.com>
>> ---
>>   newlib/libc/string/strcspn.c | 6 ++----
>>   1 file changed, 2 insertions(+), 4 deletions(-)
>>
>> diff --git a/newlib/libc/string/strcspn.c b/newlib/libc/string/strcspn.c
>> index abaa93ad6..8ac0bf10c 100644
>> --- a/newlib/libc/string/strcspn.c
>> +++ b/newlib/libc/string/strcspn.c
>> @@ -37,12 +37,10 @@ strcspn (const char *s1,
>>         for (c = s2; *c; c++)
>>   {
>>     if (*s1 == *c)
>> -	    break;
>> +	    goto end;
>>   }
>> -      if (*c)
>> -	break;
>>         s1++;
>>       }
>> -
>> +end:
>>     return s1 - s;
>>   }
>
>Just looking at this small snippet of code, I would say that the
>previous code and your suggestion won't do the same thing.
>
>Do you have unit tests that confirm that the behavior is identical with
>the current implementation and your suggested change? 
1 I must admit that I did not conduct a complete newlib regression test.
Anyway, I should apologize for this. After completing cross compilation, I tried:
-----------------
make check
-----------------

Received the following error message:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Target is riscv64-unknown-elf
Host   is x86_64-pc-linux-gnu
...
The error code is TCL LOOKUP COMMAND newlib_target_compile
The info on the error is:
invalid command name "newlib_target_compile"
    while executing
"::tcl_unknown newlib_target_compile /home/user/Downloads/tools/tools.git/newlib.git/newlib/testsuite/newlib.iconv/iconvnm.c /home/user/Downloads/tools..."
    ("uplevel" body line 1)
    invoked from within
"uplevel 1 ::tcl_unknown $args"
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

I know the reason for the error: Target and Host do not match, which
is a common issue in cross compilation. I have looked up some
information, but I have not found a solution.

2 On the basis of the above, I searched for test cases of the strcspn
function in newlib:
-------------------------------------------------------------------------------------------------
newlib/libm/test/string.c:311:  check(strcspn("abcba", "qx") == 5); /* Whole string. */
newlib/libm/test/string.c:312:  check(strcspn("abcba", "cx") == 2); /* Partial. */
newlib/libm/test/string.c:313:  check(strcspn("abc", "abc") == 0);	/* None. */
newlib/libm/test/string.c:314:  check(strcspn("", "ab") == 0); /* Null string. */
newlib/libm/test/string.c:315:  check(strcspn("abc", "") == 3); /* Null search list. */
-------------------------------------------------------------------------------------------------

I simply believe that these 5 test cases are all the test cases related to
strcspn in newlib. After local testing, all these test cases can pass in my patch.
>
>When I run your suggestion, I get return value 0, but with the current
>implementation it's 3 for this call: strspn("129th", "1234567890"). 
3 It is worth noting that strcspn and strspn only differ by one letter 'c'. I also
often confuse them -:), maybe you are the same.

>
>Kind regards,
>Torbjörn
  
4 Perhaps someone could point out how to test newlib under the risc-v
architecture, and I would greatly appreciate it. Of course, there are also
great methods for testing newlib under other architectures.

5 By the way, it is not possible to compile the latest newlib on host (x86_64-pc-linux-gnu) 
(compilation quickly ended as if nothing had happened), even if ../configure
comes with the parameter -- with-newlib.


Thanks
Xiao Zeng


  reply	other threads:[~2023-12-16  4:45 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-15  8:31 Xiao Zeng
2023-12-15 10:28 ` Torbjorn SVENSSON
2023-12-16  4:45   ` Xiao Zeng [this message]
2023-12-16  4:56     ` Xiao Zeng
2023-12-20 15:08     ` Torbjorn SVENSSON
2023-12-21  1:22       ` Xiao Zeng
2023-12-16  9:30   ` Xiao Zeng
2023-12-20  4:24     ` Jeff Johnston
2023-12-20  5:51       ` Xiao Zeng
2023-12-20 22:24       ` Brian Inglis
2023-12-21  8:00         ` Stefan Tauner
2023-12-21 17:47           ` Brian Inglis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2023121612454699234314@eswincomputing.com \
    --to=zengxiao@eswincomputing.com \
    --cc=jeffreyalaw@gmail.com \
    --cc=newlib@sourceware.org \
    --cc=palmer@rivosinc.com \
    --cc=torbjorn.svensson@foss.st.com \
    --cc=vapier@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).