From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 89E3436B937 for ; Mon, 10 Aug 2026 19:42:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786390959; cv=none; b=EcI10d6GjMpCGimcJWHXae8QGQv0LEOpBSABFrEQsMEn3dcFwXiT6d7krmNs9C9mRkieoZ/VgZpObK3M4ANiV1spaQTGJ5WHehA35oYuK7K6YKBpdWqXdWtNLfz39AC+gFfSoadyubHGzW7h4t/wAxjLee9Mqf6TfN2CegGn4Dw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786390959; c=relaxed/simple; bh=mBGGbUnHaBPZ8pdYtaa0x1Q6F4i0OojXHM/laGEULY4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=dSvRl9Bq4EmelVLLMD8v3glLkyWrIHI088vjS1XdROcV4c1hcccJlRlnNepH3ZlG0bGpTyn1NpgBlNnWWYniZlIMp3H5Qll+jfUU0qiniOlOCmtxrzBjJ0nYxnPLnuJY7//mE8KmJb9gUCpDSa1qW1D3L5RdrAviap+ZCXr+4c4= 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=mv6/rtyw; arc=none smtp.client-ip=209.85.218.51 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="mv6/rtyw" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-c1f5208b38dso6492166b.0 for ; Mon, 10 Aug 2026 12:42:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786390947; x=1786995747; 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=Lkr1vFJIkyhno/UkUAQp7w4u73WRJzZ2tehGeX/lslo=; b=mv6/rtywV8CHhPJWdfIkU61GxZiieDRmhXBdzKm7Vqe7/yHkac8cGsaVwMlrk1DOPE Avjxj+T4Nt8dYatYMW+kUFp5w81k0eLU7zchoMHINfCYuKAIng/SdYM/peu5rytG02m4 CSEaFIq+cwLE3Uq3WfjkLH3KlxgR18RtAZ5TV39MyQVOUhov3+Mgppc8AAI/n8z34CCi Yye57AibjBRuRnUN8dAXJmzTLJbZYkFBthtCkL8+yL/EfHGZc3PxtGm3dLWsq1+vMwVc EHILb9sHt0Sja8G56f691E/NBlAOPY4wkSCnaaAVe38jll00KDW9FKMLwQZq1ou5BVVk gdDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786390947; x=1786995747; 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=Lkr1vFJIkyhno/UkUAQp7w4u73WRJzZ2tehGeX/lslo=; b=fuxQmOPd633UwWNX583PplAq2jEJ94QhWAfQ8RawHQZ5SlgOpbY26NTykD4CwAorMD Gm8Ymam2NUGNquhNq8jAaYHQ5cqAXq5qaJGptYV4lKxFJmLAlqZMWaGo7h89xhy9DRm6 m/nx5RnZeJ3z0jFPd7HKsVWJsSlyqukjVnB2wn6hXJE/4eRjNu6u1NmOUArkdje8hpLC vSzvSN3htwZBoeuOrFDxZ4G8o0w7gnshe1tI+TkiIrFWpWeuQHaWWOjZHH550cCSCIf+ Lr/BdbrL9Av0Jkgpg0vvuFHZ9y9MBw/1URK7ZaBKWJWGFa5z6uTMBTwTdx/mxG8uEyyJ OVLw== X-Forwarded-Encrypted: i=1; AHgh+Rr/b6FxDQUTo9BpNMMUdcVKEgkf9LMQDwUY30z5WZDgJleuLYCO7NImG7NFRgPuu7m/RDGRpfAsvhtMKBk=@vger.kernel.org X-Gm-Message-State: AOJu0Yyb/2ffEqn4QFwvvNGgNSBwwCPbi7T2p6PCSROztwd/GI9w/23P m1sWM7nXlQK0q9JEP7PT67bqD/bEsAQZU0joWzmK+DSWtibQEzRW/fS4 X-Gm-Gg: AR+sD11H6p2cOmpv4MbQJkX93l121a6zViPK4rGlWqbbQnri2HDhWsgsQKKrMk1LPCZ hhL6yNkFW87STE4lmM8gLE5B6YR/uDwRUkwAZqkJT8DS5pY1eA/mZUOAxe1xU3bLHh3H7LPwzOA PkFiPqdxp4r4heFTZlFpvWGjLTtvMpLrTtAT12jM97HV6T+al2773dlpKID0sQ01ocheSJcXyFc 0FvpacS68uI0EYAB0rznPh8zm+KY7RRuRnS+2z/jS/zhxRBBNAI1OcmxR5WcYCjflApUk0g4fNX u9zYfmM7T7qvKdxXKsfuhOR9lqPiKhBMt1vSph1Pr4N3m8gE0zeC0M2udo+3ytc9cTbNUw9anFk gLWzd4TWGmffPqPUgObx1NWy2TaIhDhwwYAzUbeQMG4HnP+C9udDyI4iRJm8rqh90pLKKcCf4C0 +8b9ixzRegFfUF7z2IjJ7vZj8SHY7ZgRTc83rsCJLhgLagutUFDTnvc9s7qgKKDdl2 X-Received: by 2002:a17:907:1ca7:b0:c1c:4adc:31a9 with SMTP id a640c23a62f3a-c2039e3fe56mr2139790766b.28.1786390947146; Mon, 10 Aug 2026 12:42:27 -0700 (PDT) Received: from TurinLinux.. ([187.15.140.84]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c2080a6f414sm430309066b.17.2026.08.10.12.42.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2026 12:42:26 -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, bpf@vger.kernel.org, linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v3 1/3] bpf, mips: Factor out div/mod emission helpers Date: Mon, 10 Aug 2026 15:42:13 -0400 Message-Id: <20260810194215.3754591-2-main.kalliope@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260810194215.3754591-1-main.kalliope@gmail.com> References: <20260810194215.3754591-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é Reviewed-by: Philippe Mathieu-Daudé Assisted-by: Codex:gpt-5.6-sol Signed-off-by: Nicholas Dudar --- arch/mips/net/bpf_jit_comp.c | 36 ++++++++++++++++++++++------------ arch/mips/net/bpf_jit_comp64.c | 36 ++++++++++++++++++++++------------ 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/arch/mips/net/bpf_jit_comp.c b/arch/mips/net/bpf_jit_comp.c index 6ee4abe6a1f7..320180330fb3 100644 --- a/arch/mips/net/bpf_jit_comp.c +++ b/arch/mips/net/bpf_jit_comp.c @@ -338,6 +338,28 @@ void emit_alu_i(struct jit_context *ctx, u8 dst, s32 imm, u8 op) clobber_reg(ctx, dst); } +/* ALU division operation (32-bit) */ +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); + } +} + +/* ALU modulo operation (32-bit) */ +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 +407,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 fa7e9aa37f49..2520e1db7ab7 100644 --- a/arch/mips/net/bpf_jit_comp64.c +++ b/arch/mips/net/bpf_jit_comp64.c @@ -197,6 +197,28 @@ static void emit_alu_i64(struct jit_context *ctx, u8 dst, s32 imm, u8 op) clobber_reg(ctx, dst); } +/* ALU division operation (64-bit) */ +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); + } +} + +/* ALU modulo operation (64-bit) */ +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 +257,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 */