This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: (len % 1) != 0


Dave Korn wrote:
On 19 February 2008 18:23, Paul Koning wrote:

"Dave" == Dave Korn <dave.korn@artimi.com> writes:
 Dave> On 19 February 2008 16:30, Sheng-Liang Song wrote:
 >> or
 >>
 >> (len & 1) != 0 <=> (len % 2) != 0
 >>

 Dave> That would have the advantage of not requiring a divide
 Dave> operation :)

It shouldn't matter -- the optimizer will do the right thing, as I
recall.

NB len == signed int.


  Yes, it can simplify it to a bunch of shifts and sign extends and masks
without using an explicit divide, but it's not as good as a simple AND
operation.  (Maybe VRP in 4.x could handle that by knowing that the result of
strlen has to be >= 0, but 3.x series won't do it).


?? Not to be pedantic, but on 3.4.3 for mipsel-linux I get:


$ cat j.c
int f1 (int a)
{
    return (a % 2) != 0;
}
$ mipsel-linux-gcc -c -O3 j.c
$ mipsel-linux-objdump -d j.o

j.o: file format elf32-tradlittlemips

Disassembly of section .text:

00000000 <f1>:
   0:   03e00008        jr      ra
   4:   30820001        andi    v0,a0,0x1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]