From nobody Mon Feb 9 03:30:56 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1568298953; cv=none; d=zoho.com; s=zohoarc; b=YH6IIpPQktXF1e8mRUsgkPyXzH1/qj6CA0l9SfXKTM4bAVlFfcY3P3fs2VYtSkUcJ/dkglfAeTOWn2V/CgT6p/ExoagIhfbWEKQnkW0J5hCIB4uuns1cdcbLnVywfrVY+/i8TNEhgf1a9sWB9hh2rU23gkDXtjAzhNDa6FdMGYk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568298953; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=xAT5GZratibMVitbATwU9yO6mvZiwwnl0ZlEW9ZEbaU=; b=dB7znDGIz3tKMak8nG5xIvEnVpguAxeOQDELRRsOG73fjzaJSJV3YbwxCqVGTE11v8l/caBYT3Cx12lt5tPR0q4lljt3H5z4sL0fDwFmddidq2PxWz0DA729T88f4C46VpWe68R2bto4fbCAPn8hsx5uoD3z2CsR1sH006dKkxI= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568298953518680.9325632635756; Thu, 12 Sep 2019 07:35:53 -0700 (PDT) Received: from localhost ([::1]:35284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8QCO-000797-5S for importer@patchew.org; Thu, 12 Sep 2019 10:35:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45331) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8PvV-00040p-6U for qemu-devel@nongnu.org; Thu, 12 Sep 2019 10:18:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8PvU-00077w-2s for qemu-devel@nongnu.org; Thu, 12 Sep 2019 10:18:25 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:44068) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i8PvT-00077G-TH for qemu-devel@nongnu.org; Thu, 12 Sep 2019 10:18:24 -0400 Received: by mail-wr1-x442.google.com with SMTP id k6so16515947wrn.11 for ; Thu, 12 Sep 2019 07:18:23 -0700 (PDT) Received: from donizetti.lan ([2001:b07:6468:f312:3166:d768:e1a7:aab8]) by smtp.gmail.com with ESMTPSA id q14sm51083672wrc.77.2019.09.12.07.18.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2019 07:18:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xAT5GZratibMVitbATwU9yO6mvZiwwnl0ZlEW9ZEbaU=; b=nLNFJCk49dI297KEcFLKs6BnXDkWhTtRh+Ol/RIB+7tJvGKS5qb2O+cKXbV13X+k0g Vuae+q2fFewdAanZhAcb9umOhuXlkBGUHXpgpGfu12xly5k0n/CWO9UN993e6csETmLb 9mqYOS65FVu6fnVQrKPh9/8Irny7YqDo+leWkJ6vsKKQMu5U1qathu4j1v/7DD54ZTFh 4GJbU13abI55CtOTOkCQXSRIFJifoLD5OD9V6nFgek2vumYaSdB1Lwiiah8/2Nz+pkQN rc55cyuU9LdfEdy08VhxWJzsQ5ikG+VNmHv4DMfz95yLSC1Sq9RGAKIQT5MzGsVRGqLF 7JsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=xAT5GZratibMVitbATwU9yO6mvZiwwnl0ZlEW9ZEbaU=; b=F//1isUdwb9Q6CRQR6xBaeJ/4wszPhYIMmi23kn86BAG/EUKJY6V37PFMVs6zP2He/ BXGRTTSjLILQk2fCfX0YnVquzGeb1QtndzO5YNEP2sM/+A0Yad3TUF0k5hKgwpUB+MhS DnrTCrcV+RsATJNh5mpW7kv/30rB5yF5ngMEY3kK6RzxDAG6Kt4YidgJUyuOIptDArvc lDaeoWYbFMS2LDQjZFNJZAtfvksXzIH+f93hEPqFogSjMmKdXPjen/tDjVccpmjmDCop xbOxlUx1dsvqSrcSSZanzrxMk4RxZsA7IPJunw1rgdxylYMPW/f2LF9N/p7IzdR5LM2E 4iww== X-Gm-Message-State: APjAAAVwc0lxA2BZUT+x/puFEIRaNINpMbXssE/5iUQPOXciSy2fTZOl FYSGC+BLrHEMyvqBbZM8Pvu/Y4hE7a0= X-Google-Smtp-Source: APXvYqz6AuGlgdllu+72aNaRJXhmxZh0Y21AzGNBvSlzYZUUOb/C3vnYyXpk8MoozDGvSS9syTHH0w== X-Received: by 2002:a5d:6ac8:: with SMTP id u8mr35192860wrw.104.1568297901549; Thu, 12 Sep 2019 07:18:21 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 12 Sep 2019 16:18:20 +0200 Message-Id: <20190912141820.30702-1-pbonzini@redhat.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PATCH] memory: inline and optimize devend_memop X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tony Nguyen , richard.henderson@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" devend_memop can rely on the fact that the result is always either 0 or MO_BSWAP, corresponding respectively to host endianness and the opposite. Native (target) endianness in turn can be either the host endianness, in which case MO_BSWAP is only returned for host-opposite endianness, or the opposite, in which case 0 is only returned for host endianness. With this in mind, devend_memop can be compiled as a setcond+shift for every target. Do this and, while at it, move it to include/exec/memory.h since !NEED_CPU_H files do not (and should not) need it. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- include/exec/memory.h | 19 ++++++++++++++++++- memory.c | 18 ------------------ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 2dd810259d..d898cfb5db 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2201,8 +2201,25 @@ address_space_write_cached(MemoryRegionCache *cache,= hwaddr addr, } } =20 +#ifdef NEED_CPU_H /* enum device_endian to MemOp. */ -MemOp devend_memop(enum device_endian end); +MemOp devend_memop(enum device_endian end) +{ + QEMU_BUILD_BUG_ON(DEVICE_HOST_ENDIAN !=3D DEVICE_LITTLE_ENDIAN && + DEVICE_HOST_ENDIAN !=3D DEVICE_BIG_ENDIAN); + +#ifdef BSWAP_NEEDED + /* Swap if non-host endianness or native (target) endianness */ + return (end =3D=3D DEVICE_HOST_ENDIAN) ? 0 : MO_BSWAP; +#else + const int non_host_endianness =3D + DEVICE_LITTLE_ENDIAN ^ DEVICE_BIG_ENDIAN ^ DEVICE_HOST_ENDIAN; + + /* In this case, native (target) endianness needs no swap. */ + return (end =3D=3D non_host_endianness) ? MO_BSWAP : 0; +#endif +} +#endif =20 #endif =20 diff --git a/memory.c b/memory.c index 61a254c3f9..b9dd6b94ca 100644 --- a/memory.c +++ b/memory.c @@ -3267,21 +3267,3 @@ static void memory_register_types(void) } =20 type_init(memory_register_types) - -MemOp devend_memop(enum device_endian end) -{ - static MemOp conv[] =3D { - [DEVICE_LITTLE_ENDIAN] =3D MO_LE, - [DEVICE_BIG_ENDIAN] =3D MO_BE, - [DEVICE_NATIVE_ENDIAN] =3D MO_TE, - [DEVICE_HOST_ENDIAN] =3D 0, - }; - switch (end) { - case DEVICE_LITTLE_ENDIAN: - case DEVICE_BIG_ENDIAN: - case DEVICE_NATIVE_ENDIAN: - return conv[end]; - default: - g_assert_not_reached(); - } -} --=20 2.21.0