* libc/machine/arm/strcmp.S (compute_return_value): Fix return value.
* testsuite/newlib.string/strcmp-1.c (main): Add new test cases.
This commit is contained in:
parent
d551cb9226
commit
b8637f43b0
|
@ -1,3 +1,8 @@
|
||||||
|
2012-11-30 Greta Yorsh <Greta.Yorsh@arm.com>
|
||||||
|
|
||||||
|
* libc/machine/arm/strcmp.S (compute_return_value): Fix return value.
|
||||||
|
* testsuite/newlib.string/strcmp-1.c (main): Add new test cases.
|
||||||
|
|
||||||
2012-11-29 Sebastian Huber <sebastian.huber@embedded-brains.de>
|
2012-11-29 Sebastian Huber <sebastian.huber@embedded-brains.de>
|
||||||
|
|
||||||
* libc/include/sys/reent.h (__sFILE): Change type of _offset
|
* libc/include/sys/reent.h (__sFILE): Change type of _offset
|
||||||
|
|
|
@ -396,7 +396,17 @@ do_return:
|
||||||
lsr r2, r2, r0
|
lsr r2, r2, r0
|
||||||
|
|
||||||
compute_return_value:
|
compute_return_value:
|
||||||
subs r0, r1, r2
|
movs r0, #1
|
||||||
|
cmp r1, r2
|
||||||
|
/* The return value is computed as follows.
|
||||||
|
If r1>r2 then (C==1 and Z==0) and LS doesn't hold and r0 is #1 at return.
|
||||||
|
If r1<r2 then (C==0 and Z==0) and we execute SBC with carry_in=0,
|
||||||
|
which means r0:=r0-r0-1 and r0 is #-1 at return.
|
||||||
|
If r1=r2 then (C==1 and Z==1) and we execute SBC with carry_in=1,
|
||||||
|
which means r0:=r0-r0 and r0 is #0 at return.
|
||||||
|
(C==0 and Z==1) cannot happen because the carry bit is "not borrow". */
|
||||||
|
it ls
|
||||||
|
sbcls r0, r0, r0
|
||||||
bx lr
|
bx lr
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -239,6 +239,42 @@ main (void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check some corner cases. */
|
||||||
|
src[1] = 'A';
|
||||||
|
dest[1] = 'A';
|
||||||
|
src[2] = 'B';
|
||||||
|
dest[2] = 'B';
|
||||||
|
src[3] = 'C';
|
||||||
|
dest[3] = 'C';
|
||||||
|
src[4] = '\0';
|
||||||
|
dest[4] = '\0';
|
||||||
|
|
||||||
|
src[0] = 0xc1;
|
||||||
|
dest[0] = 0x41;
|
||||||
|
ret = strcmp (src, dest);
|
||||||
|
if (ret <= 0)
|
||||||
|
print_error ("\nFailed: expected positive, return %d\n", ret);
|
||||||
|
|
||||||
|
src[0] = 0x01;
|
||||||
|
dest[0] = 0x82;
|
||||||
|
ret = strcmp (src, dest);
|
||||||
|
if (ret >= 0)
|
||||||
|
print_error ("\nFailed: expected negative, return %d\n", ret);
|
||||||
|
|
||||||
|
dest[0] = src[0] = 'D';
|
||||||
|
src[3] = 0xc1;
|
||||||
|
dest[3] = 0x41;
|
||||||
|
ret = strcmp (src, dest);
|
||||||
|
if (ret <= 0)
|
||||||
|
print_error ("\nFailed: expected positive, return %d\n", ret);
|
||||||
|
|
||||||
|
src[3] = 0x01;
|
||||||
|
dest[3] = 0x82;
|
||||||
|
ret = strcmp (src, dest);
|
||||||
|
if (ret >= 0)
|
||||||
|
print_error ("\nFailed: expected negative, return %d\n", ret);
|
||||||
|
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
if (errors != 0)
|
if (errors != 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue