From patchwork Fri Apr 12 07:33:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 788270 Delivered-To: patch@linaro.org Received: by 2002:adf:e6ca:0:b0:346:15ad:a2a with SMTP id y10csp591419wrm; Fri, 12 Apr 2024 00:37:44 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUzFV/qn67PWlWNXModzZ58BXQ+8EZ3iY9YMiy3itHnuRrJWGsUwDk5TnQfDRREiy4XIMFW4HML/r+N8wt/JPIp X-Google-Smtp-Source: AGHT+IELVAenZrINXcD1tky4mVC3yWZf6I9Ors8GiiOH045VsyKZ+M+rmjxST0K7WuJTjXTyVeWX X-Received: by 2002:a05:622a:19a1:b0:436:4c3d:e0c3 with SMTP id u33-20020a05622a19a100b004364c3de0c3mr2408815qtc.33.1712907464510; Fri, 12 Apr 2024 00:37:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712907464; cv=none; d=google.com; s=arc-20160816; b=EMCNb6ZchyJYCAwmeQZkCrwscIhNNzJaP6lqpSnh6ak+QbjYywRcoYMw0YhMONQErY rWHNF9JpaSaknFTCFsxYdVfMt4smbcCZhtDQttPfYlYTSjzlTvENrHUxkPqK4rY7LTBR kO8HNjec5SeeE01pJVL9UDtzON4Hw3lsxDqBpyHmXECvZ+Nnabp+HVDDUGEsbHUR4k8k r1K2hfsrnzPG7JXlmQwSM26qGjtikbEyAmicSRKbc6UGou5PqdiNHSu2D+MBZ+kWymle D4UaD/2weoF/djofnakiqcmy9Mg0aanc5EozsbSwn6JUZygqJ8CwO1i50+9mfCEU6OKj AuMQ== 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:to:from :dkim-signature; bh=rvakkgiyK54UTlLULBlH8+XzGitioxqA6YEQltyd0/U=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=iblhwI/1kv1+rDyiSuWUUSy5Gs4Ds6EIG53Gdtxc8PFxkQUwElKo+/JMKywKyVmcdX R4naX2BYcNBioAUk5rDlz67RNaqhbexIOzDlDVjoU/BURKpTHRUXWgY25QGdzAGIEnV8 o5ZHK/t2VYvWt4o7tXW7qoNEfYSUpXGQryr16bOrli70UP+0NK7jRa/8eSw3/Q2qh8uI +xS6HEDhih5qrmilK0JjxtqP5wLcBD7RCFVTPkAeIN4YJ3DGH5jmPQn7lyFcDDal+YaO G9s2q/ETRhUcB0mLZjE9BIHGWbvL5pHBQxyHF2i/X5b3/BhRK8hzDhVzMdDaLch9Feo2 /X9Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hKhneatP; 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 p12-20020a05622a13cc00b0043697b12d33si391085qtk.603.2024.04.12.00.37.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Apr 2024 00:37:44 -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=hKhneatP; 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 1rvBQI-00074M-ST; Fri, 12 Apr 2024 03:34:10 -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 1rvBQF-00073M-M2 for qemu-devel@nongnu.org; Fri, 12 Apr 2024 03:34:07 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rvBQ0-00075y-Vg for qemu-devel@nongnu.org; Fri, 12 Apr 2024 03:34:06 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1e455b630acso3259055ad.1 for ; Fri, 12 Apr 2024 00:33:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712907231; x=1713512031; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=rvakkgiyK54UTlLULBlH8+XzGitioxqA6YEQltyd0/U=; b=hKhneatP3JxefFbpSjx+2RsvWTzNmgAROrGwt10PAYaGUGnMYQqWju2IjtD9lhLw3G 3cDQz/YzF6IzIA8A0R9etF06dNM9pgKspsuTBfWNaaM1KydQN9NlpqtmDzDb0CZ8mqAn U76MfmrFD+Ap72LpiwR+B/cbzmO2PHW8IokQ/IgPZvCf1RaaaOzYoRlb2dOXKA1iizyu BBlcChnOFfg8nB5yBMSmJnXyHZxWhyHW1w1OoxXxmjbqWc9hxNzgqN9Y1b25WvUUmCyB 7lLm9SKdutRX8ZmHrw7FiSmo019YHbAnbauSkIiUsOiL7LZbYZjDVBAn4bZWx0UmrxoI jXIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712907231; x=1713512031; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rvakkgiyK54UTlLULBlH8+XzGitioxqA6YEQltyd0/U=; b=of0EQwyglxxM+qxmUejj1hXznes6C+R7D+0lJZ2GtRN0dNZAonisC5zuLwphzyO4zN vXSwah4VW2k4+BVQojV1Ffrvyi9Lg6XhqHbjPims897OK3AAcF8qNWMOeP4R8gnOJjfX w5wbEsoqub2sVxPZO4y4ELtan6lLydB2Ggv6RvuO4Zw6dDA8zb38qMAew8e5aK5hnUBS A1U+2xuJ+1MUMX2OyRClLscLX3SOIb3RK4bZDqTD6q94bqcqeBxXvF0S3Ub+RaQ4BuNj a4AaZD/+uQ4zzpjCBO2ISX6XodlPuFKfEfMhUOjV5UFYKcytVmy8YXmxNcDFvavUrxct Wbew== X-Gm-Message-State: AOJu0YyZodsSI2NWI/H6qC/YsFp+0KH0WpxAHPykF5m9WwMDOFEMzVz4 7HcinVxXdV8+eSi8zLMmZJbPrIJblIGBtP1QPJRUO4F1wBw6CTiJt5owH9s6FEj805sYoW9oY5s i X-Received: by 2002:a17:902:6f16:b0:1e5:3c5:55a5 with SMTP id w22-20020a1709026f1600b001e503c555a5mr1557546plk.8.1712907231562; Fri, 12 Apr 2024 00:33:51 -0700 (PDT) Received: from stoup.. (174-21-72-5.tukw.qwest.net. [174.21.72.5]) by smtp.gmail.com with ESMTPSA id e5-20020a17090301c500b001e556734814sm2206099plh.134.2024.04.12.00.33.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 00:33:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 05/27] util/hexdump: Inline g_string_append_printf "%02x" Date: Fri, 12 Apr 2024 00:33:24 -0700 Message-Id: <20240412073346.458116-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240412073346.458116-1-richard.henderson@linaro.org> References: <20240412073346.458116-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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é --- 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;