Kuan-Wei Chiu 9ac621e671 lib/bcd: optimize _bin2bcd() for improved performance
[ Upstream commit cbf164cd44e06c78938b4a4a4479d3541779c319 ]

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 Huang (Jim) <jserv@ccns.ncku.edu.tw>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
[visitorckw@gmail.com: Adapt to bin2bcd() in include/bcd.h]
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
2026-01-02 15:51:54 -06:00
..
2025-11-06 08:30:33 -06:00
2025-11-24 09:34:29 -06:00
2025-12-08 13:17:27 -06:00
2025-11-21 19:25:56 +01:00
2025-12-04 09:38:58 -06:00
2024-10-17 03:12:47 +02:00
2025-08-25 16:20:48 +02:00
2025-06-02 17:26:15 -06:00
2024-07-29 15:01:04 -06:00
2025-07-23 17:37:14 -06:00
2024-08-26 14:05:38 -06:00
2025-10-26 09:03:32 -06:00
2025-06-12 16:14:33 -06:00
2024-07-29 15:01:04 -06:00
2025-06-02 17:26:15 -06:00
2025-05-29 08:29:16 -06:00
2025-06-02 17:26:15 -06:00
2025-12-30 11:22:57 -06:00
2025-08-06 08:41:30 +02:00
2024-06-14 12:59:07 -06:00
2025-09-26 11:55:13 -06:00
2025-11-07 15:34:04 -06:00
2025-06-02 17:26:15 -06:00
2024-09-24 13:41:20 -06:00
2025-08-25 16:20:48 +02:00
2025-05-13 11:30:09 -06:00
2024-07-29 15:01:04 -06:00
2025-06-27 11:48:20 -06:00
2024-07-29 15:01:04 -06:00
2024-07-29 15:01:04 -06:00
2025-08-06 08:41:30 +02:00
2025-06-02 17:26:16 -06:00
2025-12-19 10:30:26 -06:00
2025-03-10 07:41:16 +01:00
2025-04-03 11:41:54 -06:00
2025-04-03 16:54:49 -06:00
2024-07-29 15:01:04 -06:00
2024-07-29 15:01:04 -06:00
2024-10-24 11:21:48 -06:00
2024-07-29 15:01:04 -06:00
2024-07-29 15:01:04 -06:00
2025-07-08 13:11:12 -06:00
2025-05-29 08:30:25 -06:00
2025-08-18 15:47:58 +02:00
2024-11-25 23:07:37 -03:00
2024-09-30 17:48:12 -06:00
2025-05-05 14:16:50 -06:00
2024-09-12 17:35:37 +02:00
2025-07-08 13:11:12 -06:00
2025-05-29 18:35:49 -06:00
2024-07-29 15:01:04 -06:00
2025-04-16 19:57:19 -06:00
2025-02-28 08:41:54 -06:00
2024-07-29 15:01:04 -06:00
2025-02-11 20:10:58 -06:00
2025-01-07 15:45:51 +02:00
2025-12-04 09:38:58 -06:00
2025-01-01 10:40:33 -06:00
2025-07-11 10:43:29 -06:00
2024-07-29 15:01:04 -06:00
2024-07-29 15:01:04 -06:00
2025-02-03 16:01:36 -06:00
2024-07-29 15:01:04 -06:00