public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Fei Gao" <gaofei@eswincomputing.com>
To: "Kito Cheng" <kito.cheng@sifive.com>,
	 gcc-patches <gcc-patches@gcc.gnu.org>,
	 "Kito Cheng" <kito.cheng@gmail.com>,
	 "Palmer Dabbelt" <palmer@dabbelt.com>,
	 jeffreyalaw <jeffreyalaw@gmail.com>
Cc: "Kito Cheng" <kito.cheng@sifive.com>,  jinma <jinma@linux.alibaba.com>
Subject: Re: [PATCH] RISC-V: Fix misaligned stack offset for interrupt function
Date: Fri, 29 Dec 2023 15:56:46 +0800	[thread overview]
Message-ID: <2023122915552931894937@eswincomputing.com> (raw)
In-Reply-To: <20231225084521.78251-1-kito.cheng@sifive.com>

On 2023-12-25 16:45  Kito Cheng <kito.cheng@sifive.com> wrote:

>+++ b/gcc/testsuite/gcc.target/riscv/interrupt-misaligned.c
>@@ -0,0 +1,29 @@
>+/* { dg-do compile } */
>+/* { dg-options "-O2 -march=rv64gc -mabi=lp64d -fno-schedule-insns -fno-schedule-insns2" } */
>+/* { dg-skip-if "" { *-*-* } { "-flto -fno-fat-lto-objects" } } */
>+
>+/*  Make sure no stack offset are misaligned.
>+**  interrupt:
>+**  ...
>+**        sd\tt0,40\(sp\)
>+**        frcsr\tt0
>+**        sw\tt0,32\(sp\)
>+**        sd\tt1,24\(sp\)
>+**        fsd\tft0,8\(sp\)
>+**  ...
>+**        lw\tt0,32\(sp\)
>+**        fscsr\tt0
>+**        ld\tt0,40\(sp\)
>+**        ld\tt1,24\(sp\)
>+**        fld\tft0,8\(sp\)
>+**  ...
>+*/
Hi Kito

The fix is fine but maybe using s0 instead of t0 is better:
1. simpler codes.
2. less stack size

current implementaion:
>+**        sd\tt0,40\(sp\)
>+**        frcsr\tt0
>+**        sw\tt0,32\(sp\)      //save content of frcsr in stack

use s0:
>+**        sd\tt0,40\(sp\)
>+**        frcsr\ts0                //save content of frcsr in s0 instead of stack. If s0 is used as callee saved register, it will be saved again later by legacy codes .

Also adding this change in riscv_expand_prologue & epilogue would be consistent with current stack allocation logic.

I can try it if you think necessary. 

BR
Fei
>+
>+
>+void interrupt(void) __attribute__((interrupt));
>+void interrupt(void)
>+{
>+  asm volatile ("# clobber!":::"t0", "t1", "ft0");
>+}
>+
>+/* { dg-final { check-function-bodies "**" "" } } */
>--
>2.40.1

  parent reply	other threads:[~2023-12-29  7:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-25  8:45 Kito Cheng
2023-12-28 15:58 ` Jeff Law
2024-01-04  8:02   ` Kito Cheng
2023-12-29  7:56 ` Fei Gao [this message]
2024-01-04  8:02   ` Kito Cheng

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=2023122915552931894937@eswincomputing.com \
    --to=gaofei@eswincomputing.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jeffreyalaw@gmail.com \
    --cc=jinma@linux.alibaba.com \
    --cc=kito.cheng@gmail.com \
    --cc=kito.cheng@sifive.com \
    --cc=palmer@dabbelt.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).