From patchwork Wed Jun 5 21:15:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 801645 Delivered-To: patch@linaro.org Received: by 2002:a5d:5610:0:b0:35b:5a80:51b4 with SMTP id l16csp37008wrv; Wed, 5 Jun 2024 14:18:12 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXndlSYQC+76WJEHXWCi7k7qIxaibKwnaZsk2LCL7fEJZYM/AirZzyl9q6mORhU0Yx797XiedC0x3XDMzIn7o+4 X-Google-Smtp-Source: AGHT+IGV8Au2uTtY+BVuNDNp1wjeIogcVAYxc/bkZFqTb//c5lW6j77f1tr6i3gNxRe9xBI79wJh X-Received: by 2002:a05:6e02:1b09:b0:374:9f16:d7 with SMTP id e9e14a558f8ab-374b1f027fcmr40680545ab.13.1717622292546; Wed, 05 Jun 2024 14:18:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717622292; cv=none; d=google.com; s=arc-20160816; b=AxkMTWCUL+X9eDT2jgsjecYJsiaUkLa6MT8ZONsi2y5kQLx6uVMcraV/qjjQozJJMh +Jutn/aP8b3rjMl7om2S4bkRt1UPxw6kI7VD/eFv27xK5PtqvvYhqLL8FXTF9nLkEt8Y 2sntc4Bn7brBjuY1BXwZafnm9dYk+pszQ1zhnRqPMYp/Z5l9+Kj7wfvwtwNBTV+3dXc/ Y1m4Fq+JPATiZLRGIi952Ni9j2+lp4zMsp+BGdphoBmHCrDkOLGwnsq1x5H3ziRYosOB kSVQvEA5fZCIvKQEyqjCpRYdbFPf0vlQ1emmga4LPSS/67oQwU0QsjnF1Di6Mwt3h50C PqpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DtdfLvGNq7oKYg7RFoNL4PoVXIIUjVrx0tqYusGM3x8=; fh=kQadAhxV42GJ3cd2VUw1RyURv/zJQGvmUdF7iLEVTtc=; b=Vqvfc7RmfsGezEedfH1WVqQt0S2KAWQMfHGnbd4yTSIOB5qbCE+nhccoHfzBDQdd4d Mwyt4+G1YzcFoh3VH6Ru8Nu6GKEiUpOOK44h08jYHwhMhgXnArAolQYoKNfVUog4UE1w gVHQRdl5S4bW1sXr/brRSgHCxwQRBs8p+JKY0XHzfapo/oCfuBgRD0piiCMloDlhfG6P jpi22vpo0gSnrJ+lmd8JW1Nv7CdyOJOdLcaumheM5MFw2xJh+sIgI9N7zf7hUMA2Eoue 9V2HmG4S/Vu9bJumkIekrKKUVVlO62Xgir31mhrIfenMXUZqXAW2kP/K6rqyovWA/sFh ymgg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="W/vBvgb6"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7951f10e1b6si375082885a.432.2024.06.05.14.18.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jun 2024 14:18:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="W/vBvgb6"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sExz0-0000eJ-Gs; Wed, 05 Jun 2024 17:15:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sExyt-0000cA-4y for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:39 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sExyi-0003PI-8E for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:36 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-703ed15b273so231564b3a.1 for ; Wed, 05 Jun 2024 14:15:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717622126; x=1718226926; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DtdfLvGNq7oKYg7RFoNL4PoVXIIUjVrx0tqYusGM3x8=; b=W/vBvgb6b9uNTvDGoTZk04dmdVx4wQFRskozZSwCg02r5VhMJZyr9eNFE4/+D9vilY BETNF5yQSMt67uTArEYYDhj8sSj7FXhJR3Tljq94QI0BeNlyTGGGmnCdHrlg/wcdFv47 fZrGEFSeHkjR6RnQOgl086v0jrAkNeQUmeUisP7mUB2rRzvOFJZLOX+XtfXM3kNsFoU3 o5qFxw2fq1RLh9IAuOJ7tIrSR7cztQ6MbR/8t2Ek2gnst9iKeb4U+GFkJN74qxDdqkxw c8BpuRnJCs6oWahYmw7C84aYJLmtBA4qJbE96qlPmUImeXnR1I0aMZP0Zox3VCrjwDJw 1SlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717622126; x=1718226926; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DtdfLvGNq7oKYg7RFoNL4PoVXIIUjVrx0tqYusGM3x8=; b=mbw7U6YVBOkqbO6jF24eOEyzojZdTFTMx0yGemha1+S1J+0/IfsZjRVPCys9KoYh6n YM+W/andBCcaMfMDk+lJwOcfFxVWl8VBoyuE1QqAXkI5TmyZmITUsxCEtIr5y7SeFsT6 b8n/a2DVWb9yL8JTnwnGIS371OyF34EsXc8XDlMAsIQXGS9bP42jZgJgPl240O7KzDsx 9gHWLpevxiZ9dKSqKWuvnwEfm526ZEm3HUtISM8jZxsE1rcbXwG1u1iYmKPoqBj6ey/M WizXGm7YvZ2sC9LZaEyzmPEjFpKtu4JeSNGzOrWHNdYE8SCkRUr17/yc5pEA4z57ve0A pFSw== X-Gm-Message-State: AOJu0Yy2XlAOPtT8z5hPhStVO751b5ewI8arHU6S2tKG4xcjLBA42FGf mUOWoEzy5yQRFs/z65pdcUAF6pGg5swyRgHsJhr+etbXYvJ42MlBVTS8oiGOjtdJp8d4ZQUcP3/ j X-Received: by 2002:a05:6a21:3998:b0:1b2:2ed2:b80a with SMTP id adf61e73a8af0-1b2b76374f4mr4477852637.61.1717622125595; Wed, 05 Jun 2024 14:15:25 -0700 (PDT) Received: from stoup.. ([71.212.132.216]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242aec7d0sm9347538b3a.99.2024.06.05.14.15.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:15:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 03/16] util/hexdump: Inline g_string_append_printf "%02x" Date: Wed, 5 Jun 2024 14:15:08 -0700 Message-Id: <20240605211521.577094-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605211521.577094-1-richard.henderson@linaro.org> References: <20240605211521.577094-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Trivial arithmetic can be used for emitting the nibbles, rather than full-blown printf formatting. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20240412073346.458116-6-richard.henderson@linaro.org> --- util/hexdump.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/util/hexdump.c b/util/hexdump.c index b29326b7f2..ae0d4992dc 100644 --- a/util/hexdump.c +++ b/util/hexdump.c @@ -16,6 +16,11 @@ #include "qemu/osdep.h" #include "qemu/cutils.h" +static inline char hexdump_nibble(unsigned x) +{ + return (x < 10 ? '0' : 'a' - 10) + x; +} + GString *qemu_hexdump_line(GString *str, const void *vbuf, size_t len, size_t unit_len, size_t block_len) { @@ -35,6 +40,8 @@ GString *qemu_hexdump_line(GString *str, const void *vbuf, size_t len, } for (u = 0, b = 0; len; u++, b++, len--, buf++) { + uint8_t c; + if (unit_len && u == unit_len) { g_string_append_c(str, ' '); u = 0; @@ -43,7 +50,10 @@ GString *qemu_hexdump_line(GString *str, const void *vbuf, size_t len, g_string_append_c(str, ' '); b = 0; } - g_string_append_printf(str, "%02x", *buf); + + c = *buf; + g_string_append_c(str, hexdump_nibble(c / 16)); + g_string_append_c(str, hexdump_nibble(c % 16)); } return str;