[PATCH 1/2] mtd: nand: force NAND_CMD_READID onto 8-bit bus
Gupta, Pekon
pekon at ti.com
Thu Jan 30 15:18:07 EST 2014
Hi Ezequiel,
>> >+static inline int nand_opcode_8bits(unsigned int command)
>> >+{
>> >+ return command == NAND_CMD_READID;
>> >+}
>> >+
>> >
>> Can 'nand_opcode_8bits, made a macro instead of inline function ?
>> #define IS_8BIT_CMD(cmd) (unlikely(cmd == NAND_CMD_READID))
>>
>> Because 'nand_opcode_8bits' is used in nand_command() and nand_command_lp()
>> which is performance critical code (chip->cmd is called multiple times for fetching
>> page data and OOB). Though we should expect compiler to treat this inline function
>> same as macro here, But just to be doubly sure for future changes also.
>>
>
>I'm not a compiler guru, but I'd be very surprised if the compiler would make
>a difference here, given the function is static, inline and small. Besides,
>an inline function is more readable and type-aware. I'd say it's the Right
>Thing to do.
>
>Nevertheless, I did a small check on my platform (handbuilt ARM GCC 4.7.2) and
>both macro and inline is compiled into a "cmp" instruction. The unlikely
>doesn't seem to have any effect.
>
Please check the JMP instruction just after CMP instruction..
In-case of (unlikely(x == y)) JMP/JE will be used to branch when x == y.
where as in-case of (likely(x == y)) JMP/JNE will be used to branch x != y.
As in most cases 'command != NAND_CMD_READID' so with unlikely()
Compiler should lay down the instructions in such an order that program
executes _without_ branching. Thus JMP will point to the code when
command == NAND_CMD_READID.
(this is my understanding, however may be for small branches this has
no effect because both paths can be fetched simultaneously into pipeline).
with regards, pekon
More information about the linux-mtd
mailing list