From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47339492512 for ; Wed, 29 Jul 2026 16:29:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785342606; cv=none; b=SKIXyVsxlU2nSSbR/+N2HsIDk9MUWyNdlTCCzrcvGjQta4FnFAB3q6hcHtu3566LVets6eE7GKLrrL/xsd/k2OaHBqjK/Xa/8kDIHfMbxT+yUbPshvvmFOVmii0u5+whyOg4acUEnB+umFCTC8jiaj9qDxklY+Pa58Z2/l7DE+c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785342606; c=relaxed/simple; bh=UcJm+zVdmhaQ7hxxCJfHfVnp6k95FNk/71r1+BEfajg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=pBe5/0q7z/nJHD7ELcjEVxZW3t/J4DbHsc3mJsqz30FTId2txapLWbD6T8As7aBstI5kU8FkUdXDGP1+VLSPgLrg166RDL+8pI2nn3z0Ar/AsXz3rxa6/MLHKD1LHu2AcyJO0K0lyIpZU/Y1+yBamzWg1wIQ4SqhD5RJ+sGgFqw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SoaJfOm0; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SoaJfOm0" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-92ed19f4d60so4726485a.0 for ; Wed, 29 Jul 2026 09:29:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785342596; x=1785947396; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=N7qydndb8NAC1l2K1cmIvkvmaJhg7Cl0GZ7WZzozaU0=; b=SoaJfOm0xTbcURsPZeeW5j3K5G6cH3DGSWKmOFOxW6Nx138Q+TJtMTxkQcOXruSqaF ukh7gtOeTw/GesU8ejroK6J9IKEhK7vSI3BW2ZYwAf9/aLTkzmrKFSBSyBwIfP0G7vAB Skax5W7KXsxkbOSgzI+8sZH0evlWwhQHjiu7BJ8KHIpeg5yUk+egXXNUrAYDkpQ4m5Ax lnZS8GxF0L/m3VanqahYSYn/x7dewjl6ioS/a8IJmgI6r1ciT5GnShKK/+DxhGiTOzZq LkV++K1aADrbGbNDZkQJWdPkMX590S3sx1/2HVBSh7BpevvTyY0/cOh+TzyPbKNrmL9O uecQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785342596; x=1785947396; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=N7qydndb8NAC1l2K1cmIvkvmaJhg7Cl0GZ7WZzozaU0=; b=dzNcCqTLrfXPjWbE1iWBzYme/MEnvPWm67skdnzWCzf9Y/Ykt3r/Rf+WxZKqzsISwz JYiU80ZG2wxTh3tspg+BTe64MkLF9IcuXdSQJjZNqZ5lwo+kpAVOsUzyDBCHz0RKrnMj C6ZnrhM12ke8p5AkNBcOpA2OvFLcU19fmCz6L3l70GDNpKaT+GrL8iq5xDfCU1A3iWpZ jVXDIigHi3ufgKehIhxTDe6apedow5pzbUNT/NjUC2TRPlD4Lo9TD2OExhujNJ96orzP /d4cwwR6BnD9RA/dGs0s1JrI+tuA2MZdUQRQ4pgjSuiTghYZCRNcXway9m3aQGJw+JPZ W94g== X-Forwarded-Encrypted: i=1; AHgh+Ros1/S//eRRgiTS2gol5+U+IQD6c/Z/qCbICCPFeOy3M+MTfrcHAWkuWv71UkmtWg/2WEbAhZPWKQ7ODZc=@vger.kernel.org X-Gm-Message-State: AOJu0Yxjgu2+47jel2mRoR1kPSjVA7zTzlKd97eHr7HeRsrjRmPTSeWx W085v7nShvgEnKeAhE8LnQFGnYX0IaCLsbpn36BXcniUQIM0qZ23Tx+7 X-Gm-Gg: AR+sD13+PGCYHFIbXxlnWSEshBDNKk66cNgZCdI+0aXSEdJWEeQl8vfOlFQhFCqwWad OTnDXWywPIq+zh4rGivE6Qc85Oxh0o8R5nb9y+zjaa0P+QdSEemIblAHLUpnQavj7iTpK0T2sKl rpnLMDPp9COkJJV2Olv/16XCWRvmzoCcloYFAqDn89GTzL3O+Cg54olOYa3PDKlCsneBViFoQP/ KfW1vYeKoH6WPzIDEU5jeIHz5Rb0/tVrQNIq9IlHpHI2xoAO5VKZsbX/lZTKuscdMPPbIslql9C ifDvnHSri5669NyTD6wABdqSnLyjZbsw3ODbWKXFB7p3cgpjjJ7rnz9HZSbFXCoSNX24OqjsH43 A3RF+LOzaGBsL1rJ0rQRJI2jbVbaCuElnCeqOuLI4kpL7eB3K2ugnOZ8w2EhTAaIu9x3DIU3fd9 lk47dQG8j3e8LoKxj68OtcRAy5pT79Q4lY3Rze9UBBvTiA2x5ZcjJfbI70+8R/toa0RWm/FIV+L Dq5jQ== X-Received: by 2002:a05:620a:1792:b0:918:7e9e:de74 with SMTP id af79cd13be357-93479604838mr256648785a.17.1785342595964; Wed, 29 Jul 2026 09:29:55 -0700 (PDT) Received: from localhost.localdomain ([187.15.144.227]) by smtp.gmail.com with ESMTPSA id af79cd13be357-933e7318180sm201745885a.28.2026.07.29.09.29.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jul 2026 09:29:55 -0700 (PDT) From: Nicholas Dudar To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com, tsbogend@alpha.franken.de, johan.almbladh@anyfinetworks.com, paulburton@kernel.org Cc: martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev, philmd@oss.qualcomm.com, visitorckw@gmail.com, bpf@vger.kernel.org, linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v2 1/2] bpf, mips: Factor out div/mod emission helpers Date: Wed, 29 Jul 2026 12:29:30 -0400 Message-Id: <20260729162931.2369353-2-main.kalliope@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260729162931.2369353-1-main.kalliope@gmail.com> References: <20260729162931.2369353-1-main.kalliope@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Factor MIPS32 and MIPS64 division and modulo emission out of emit_alu_r() and emit_alu_r64(). This prepares the JITs to select signed or unsigned opcodes without duplicating the R6 and pre-R6 handling. No functional change intended. Suggested-by: Philippe Mathieu-Daudé Assisted-by: Codex:gpt-5.6-sol Signed-off-by: Nicholas Dudar --- arch/mips/net/bpf_jit_comp.c | 34 ++++++++++++++++++++++------------ arch/mips/net/bpf_jit_comp64.c | 34 ++++++++++++++++++++++------------ 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/arch/mips/net/bpf_jit_comp.c b/arch/mips/net/bpf_jit_comp.c index 6ee4abe6a..f99bb5705 100644 --- a/arch/mips/net/bpf_jit_comp.c +++ b/arch/mips/net/bpf_jit_comp.c @@ -338,6 +338,26 @@ void emit_alu_i(struct jit_context *ctx, u8 dst, s32 imm, u8 op) clobber_reg(ctx, dst); } +static void emit_div(struct jit_context *ctx, u8 dst, u8 src) +{ + if (cpu_has_mips32r6) { + emit(ctx, divu_r6, dst, dst, src); + } else { + emit(ctx, divu, dst, src); + emit(ctx, mflo, dst); + } +} + +static void emit_mod(struct jit_context *ctx, u8 dst, u8 src) +{ + if (cpu_has_mips32r6) { + emit(ctx, modu, dst, dst, src); + } else { + emit(ctx, divu, dst, src); + emit(ctx, mfhi, dst); + } +} + /* ALU register operation (32-bit) */ void emit_alu_r(struct jit_context *ctx, u8 dst, u8 src, u8 op) { @@ -385,21 +405,11 @@ void emit_alu_r(struct jit_context *ctx, u8 dst, u8 src, u8 op) break; /* dst = dst / src */ case BPF_DIV: - if (cpu_has_mips32r6) { - emit(ctx, divu_r6, dst, dst, src); - } else { - emit(ctx, divu, dst, src); - emit(ctx, mflo, dst); - } + emit_div(ctx, dst, src); break; /* dst = dst % src */ case BPF_MOD: - if (cpu_has_mips32r6) { - emit(ctx, modu, dst, dst, src); - } else { - emit(ctx, divu, dst, src); - emit(ctx, mfhi, dst); - } + emit_mod(ctx, dst, src); break; } clobber_reg(ctx, dst); diff --git a/arch/mips/net/bpf_jit_comp64.c b/arch/mips/net/bpf_jit_comp64.c index fa7e9aa37..befeb63ae 100644 --- a/arch/mips/net/bpf_jit_comp64.c +++ b/arch/mips/net/bpf_jit_comp64.c @@ -197,6 +197,26 @@ static void emit_alu_i64(struct jit_context *ctx, u8 dst, s32 imm, u8 op) clobber_reg(ctx, dst); } +static void emit_div64(struct jit_context *ctx, u8 dst, u8 src) +{ + if (cpu_has_mips64r6) { + emit(ctx, ddivu_r6, dst, dst, src); + } else { + emit(ctx, ddivu, dst, src); + emit(ctx, mflo, dst); + } +} + +static void emit_mod64(struct jit_context *ctx, u8 dst, u8 src) +{ + if (cpu_has_mips64r6) { + emit(ctx, dmodu, dst, dst, src); + } else { + emit(ctx, ddivu, dst, src); + emit(ctx, mfhi, dst); + } +} + /* ALU register operation (64-bit) */ static void emit_alu_r64(struct jit_context *ctx, u8 dst, u8 src, u8 op) { @@ -235,21 +255,11 @@ static void emit_alu_r64(struct jit_context *ctx, u8 dst, u8 src, u8 op) break; /* dst = dst / src */ case BPF_DIV: - if (cpu_has_mips64r6) { - emit(ctx, ddivu_r6, dst, dst, src); - } else { - emit(ctx, ddivu, dst, src); - emit(ctx, mflo, dst); - } + emit_div64(ctx, dst, src); break; /* dst = dst % src */ case BPF_MOD: - if (cpu_has_mips64r6) { - emit(ctx, dmodu, dst, dst, src); - } else { - emit(ctx, ddivu, dst, src); - emit(ctx, mfhi, dst); - } + emit_mod64(ctx, dst, src); break; default: /* Width-generic operations */ -- 2.34.1