]> www.infradead.org Git - users/jedix/linux-maple.git/commit
lib/bcd: optimize _bin2bcd() for improved performance
authorKuan-Wei Chiu <visitorckw@gmail.com>
Mon, 12 Aug 2024 17:02:29 +0000 (01:02 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 2 Sep 2024 03:43:33 +0000 (20:43 -0700)
commitcbf164cd44e06c78938b4a4a4479d3541779c319
tree92fbe8efae109927b1c172177447e9cb6b11ccc4
parentccbfd2df3018e2694f750abe5e93b647a4eef5b1
lib/bcd: optimize _bin2bcd() for improved performance

The original _bin2bcd() function used / 10 and % 10 operations for
conversion.  Although GCC optimizes these operations and does not generate
division or modulus instructions, the new implementation reduces the
number of mov instructions in the generated code for both x86-64 and ARM
architectures.

This optimization calculates the tens digit using (val * 103) >> 10, which
is accurate for values of 'val' in the range [0, 178].  Given that the
valid input range is [0, 99], this method ensures correctness while
simplifying the generated code.

Link: https://lkml.kernel.org/r/20240812170229.229380-1-visitorckw@gmail.com
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Cc: Ching-Chun (Jim) Huang <jserv@ccns.ncku.edu.tw>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
lib/bcd.c