From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750999AbcFDFOO (ORCPT ); Sat, 4 Jun 2016 01:14:14 -0400 Received: from science.sciencehorizons.net ([71.41.210.147]:32999 "HELO ns.sciencehorizons.net" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with SMTP id S1750748AbcFDFON (ORCPT ); Sat, 4 Jun 2016 01:14:13 -0400 Date: 4 Jun 2016 01:14:11 -0400 Message-ID: <20160604051411.3635.qmail@ns.sciencehorizons.net> From: "George Spelvin" To: andriy.shevchenko@linux.intel.com Subject: [PATCH v2 1/2] lib/vsprintf.c: Simplify uuid_string() Cc: bjorn@mork.no, linux-kernel@vger.kernel.org, linux@sciencehorizons.net, matt@codeblueprint.co.uk, rv@rasmusvillemoes.dk In-Reply-To: <20160604051305.3521.qmail@ns.sciencehorizons.net> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rather than have a second pass to upcase the buffer, just make the hex lookup table a variable. Removing the conditional branch from the inner loop is also a speedup, but since this is not hot code, the important factor it shrinks both source and compiled forms: Before After Delta Percentage x86-32 245 199 -46 -18.8% x86-64 246 186 -60 -24.4% arm 292 264 -28 -9.6% thumb 220 160 -60 -27.3% arm64 296 244 -52 -17.6% Signed-off-by: George Spelvin --- lib/vsprintf.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 7332a5d7..4ee07e89 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1316,24 +1316,24 @@ char *uuid_string(char *buf, char *end, const u8 *addr, char *p = uuid; int i; const u8 *index = uuid_be_index; - bool uc = false; + const char *hex = hex_asc; - switch (*(++fmt)) { + switch (fmt[1]) { case 'L': - uc = true; /* fall-through */ + hex = hex_asc_upper; /* fall-through */ case 'l': index = uuid_le_index; break; case 'B': - uc = true; + hex = hex_asc_upper; break; } for (i = 0; i < 16; i++) { - if (uc) - p = hex_byte_pack_upper(p, addr[index[i]]); - else - p = hex_byte_pack(p, addr[index[i]]); + u8 byte = addr[index[i]]; + + *p++ = hex[byte >> 4]; + *p++ = hex[byte & 0x0f]; switch (i) { case 3: case 5: -- 2.8.1