From: Sahil <sahilcdq0@gmail.com>
To: Stafford Horne <shorne@gmail.com>
Cc: jonas@southpole.se, stefan.kristiansson@saunalahti.fi,
naveen@kernel.org, davem@davemloft.net, mhiramat@kernel.org,
pjw@kernel.org, wangruikang@iscas.ac.cn, namcao@linutronix.de,
kees@kernel.org, linux-openrisc@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 1/4] openrisc: Add utilities and clean up simulation of instructions
Date: Wed, 18 Nov 2026 17:02:35 +0530 [thread overview]
Message-ID: <0c859418-ef73-4870-a45d-66137882ab74@gmail.com> (raw)
In-Reply-To: <avkHMp3Qa_C01Nd8@antec>
On 11/15/26 6:43 AM, Stafford Horne wrote:
> On Fri, Nov 13, 2026 at 10:41:56PM +0530, Sahil wrote:
>> Hi Stafford,
>>
>> On 11/7/26 12:15 PM, Stafford Horne wrote:
>>> Hi Sahil,
>>>
>>> Thanks for your patches, sorry its taken me time to get around to them, my year
>>> since summer has been quite hectic.
>>
>> No worries. I completely understand :)
>>
>>> I will do the review in chunks so give me some time.
>>
>> Thank you for the review.
>>
>>> On Tue, Oct 27, 2026 at 01:42:37AM +0530, Sahil Siddiq wrote:
>>>> Introduce new instruction-related utilities and macros for OpenRISC.
>>>> This is in preparation for patches that add tracing support such as
>>>> KProbes and Kretprobes.
>>>> [...]
>>>> +
>>>> +void simulate_branch(struct pt_regs *regs, unsigned long jmp_insn)
>>>> +{
>>>> + int displacement;
>>>> + unsigned int rb, op, link_offset, temp;
>>>> +
>>>> + displacement = sign_extend32(
>>>> + ((jmp_insn) & OPENRISC_JUMP_IMM_MASK) << OPENRISC_JUMP_IMM_SHIFT, 27);
>>>> + rb = (jmp_insn & OPENRISC_JUMP_REG_MASK) >> OPENRISC_JUMP_REG_SHIFT;
>>>> + op = get_6_bit_opcode(jmp_insn);
>>>> + link_offset = OPENRISC_INSN_SIZE;
>>>> +
>>>> + if (static_branch_likely(&delay_slot))
>>>> + link_offset <<= 1;
>>>
>>> Why do shift left here instead of += OPENRISC_INSN_SIZE? Since logically we are
>>> adding one more insn for the delay slot, not doubling.
>>
>> Since link_offset is initialized to OPENRISC_INSN_SIZE, shifting it to the left by 1 would
>> update link_offset to 2 * OPENRISC_INSN_SIZE. This is a little more obscure than explicitly
>> setting it to 2 * OPENRISC_INSN_SIZE. Initially, I thought the left shift operator might be
>> less expensive than multiplying.
>>
>> I was going through mor1kx's design and noticed there's also a pipelined implementation for
>> the multiplier [1]. But it looks like the implementation for shifting is simpler and can be done
>> in one cycle. Please let me know if my understanding is incorrect here.
>
> That's correct, but my suggestion was to use += OPENRISC_INSN_SIZE instead of
> 2 *.
>
>>> However, It may be more efficient to avoid using the alu and write as:
>>>
>>> if (static_branch_likely(&delay_slot))
>>> link_offset = 2 * OPENRISC_INSN_SIZE;
>>> else
>>> link_offset = OPENRISC_INSN_SIZE;
>>>
>>> what do you think?
>>
>> I am not sure if I have understood the alu part. WIll it be more efficient because 2 * OPENRISC_INSN_SIZE
>> will be optimized by the compiler to simply be a single number? So no alu operation will be required,
>> just one store operation?
>
> Yup, since 2 * OPENRISC_INSN_SIZE is a constant expression the compiler
> will replace it with 8. Then the above code would be just one store operation,
> something like:
>
> if (static_branch_likely(&delay_slot))
> link_offset = 8;
> else
> link_offset = 4;
>
Got it. Thank you for the clarification. Based on our conversation in commit #3
regarding delay slots, it should now be fine to remove the static key and handle
delay slots unconditionally.
>>
>>>> + switch (op) {
>>>> + case OPENRISC_OPCODE_J: /* l.j */
>>>
>>> I think these comments (/* l.j */) are no longer needed sinc you have
>>> the named macros.
>>
>> Got it, I'll remove the comments.
>
> [snip]
>
> Thanks,
> -Stafford
Thanks,
Sahil
next prev parent reply other threads:[~2026-11-18 11:32 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260930202744.50489-1-sahilcdq0@gmail.com>
2026-10-26 20:12 ` [PATCH v3 0/4] openrisc: Add support for KProbes and Kretprobes Sahil Siddiq
2026-11-13 9:04 ` Masami Hiramatsu (Google)
2026-11-13 17:22 ` Sahil
2026-10-26 20:12 ` [PATCH v3 1/4] openrisc: Add utilities and clean up simulation of instructions Sahil Siddiq
2026-11-07 6:45 ` Stafford Horne
2026-11-13 17:11 ` Sahil
2026-11-15 1:13 ` Stafford Horne
2026-11-18 11:32 ` Sahil [this message]
2026-10-26 20:12 ` [PATCH v3 2/4] openrisc: Add KProbes Sahil Siddiq
2026-10-26 20:26 ` Sahil
2026-10-26 20:35 ` sashiko-bot
2026-11-08 7:46 ` Stafford Horne
2026-11-13 17:13 ` Sahil
2026-11-15 1:44 ` Stafford Horne
2026-11-18 5:51 ` Sahil
2026-11-28 7:39 ` Stafford Horne
2026-10-26 20:12 ` [PATCH v3 3/4] openrisc: Add unit tests for KProbes on branch instructions Sahil Siddiq
2026-10-26 20:26 ` sashiko-bot
2026-11-08 8:03 ` Stafford Horne
2026-11-13 17:15 ` Sahil
2026-11-15 1:52 ` Stafford Horne
2026-11-18 11:26 ` Sahil
2026-10-26 20:12 ` [PATCH v3 4/4] openrisc: Add Kretprobes Sahil Siddiq
2026-10-26 20:28 ` sashiko-bot
2026-11-08 7:58 ` Stafford Horne
2026-11-13 17:16 ` Sahil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0c859418-ef73-4870-a45d-66137882ab74@gmail.com \
--to=sahilcdq0@gmail.com \
--cc=davem@davemloft.net \
--cc=jonas@southpole.se \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-openrisc@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=namcao@linutronix.de \
--cc=naveen@kernel.org \
--cc=pjw@kernel.org \
--cc=shorne@gmail.com \
--cc=stefan.kristiansson@saunalahti.fi \
--cc=wangruikang@iscas.ac.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.