On Tue, 2006-12-19 at 11:06 +0100, Arjan van de Ven wrote: > On Mon, 2006-12-18 at 17:12 -0500, Ming Zhang wrote: > > See this code piece > > > > http://lxr.linux.no/source/drivers/scsi/libata-scsi.c?v=2.6.18#L1049 > > > > 1056 lba |= ((u64)scsicmd[2]) << 24; > > 1057 lba |= ((u64)scsicmd[3]) << 16; > > 1058 lba |= ((u64)scsicmd[4]) << 8; > > 1059 lba |= ((u64)scsicmd[5]); > > > > it can also be written as > > > > lba = be32_to_cpu(*(u32 *)(&scsicmd[2]) > > > > > > i wrote a simple code to test this and i found second one is several > > time faster than first one. > > > > if there any pitfall with 2nd way? > > personally I find the original code a lot more clear in what the intent > of it is. > > The device/command give you a set of BYTES, and they get pieced together > into a meaning here... > previously i think my way is faster. and looks "neat", with one statement. i ignored the alignment issue. scsi spec define all in a Big Endian so 4 bytes is like a u32 in BE. -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/