Skip to content

setjmp optimization#10

Open
puranikvinit wants to merge 3 commits into
mainfrom
setjmp-opt
Open

setjmp optimization#10
puranikvinit wants to merge 3 commits into
mainfrom
setjmp-opt

Conversation

@puranikvinit

Copy link
Copy Markdown
Owner

There wasn't much here to optimize, I just made use of the Zilsd extension to reduce the code size. The entire code is basically register load/store instructions, no logic involved as such. Eric had suggested to have a look at the Zcmp extension, but since we are using a buffer to save the register state and not the stack itself, I don't think it'd be useful.

I got a code size reduction of 40b when the target supports Zilsd extension.

@thebigclub

Copy link
Copy Markdown
Collaborator

@puranikvinit What if you temporarily point the SP to the buffer so that the Zcmp instructions will then read/write to the buffer instead of the stack, and restore the SP at the end? Could that work when optimizing for space?

@christian-herber-nxp

Copy link
Copy Markdown
Collaborator

@puranikvinit What if you temporarily point the SP to the buffer so that the Zcmp instructions will then read/write to the buffer instead of the stack, and restore the SP at the end? Could that work when optimizing for space?

does not sound like something one should do. This will fall apart in case of a trap, which would rely on a proper sp value.

tyan0 added 2 commits May 7, 2025 16:32
... and restore it when app exits. The commit 0bfd91d has a bug
that the console mode is stored into the shared memory when both:
  (1) cygwin process is started from non-cygwin process.
  (2) cygwin process started from non-cygwin process exits.
(1) is intended, but (2) is not. Due to (2), the stored console mode
is unexpectedly broken when the cygwin process exits. Then the mode
restored will be not as expected. This causes undesired console mode
in the use case that cygwin and non-cygwin apps are mixed.

With this patch, the console mode will stored only in the case (1).
This is done by putting the code, which stores the console mode, into
fhandler_console::open() rather than fhandler_console::set_input_mode()
and fhandler_console::set_output_mode().

Fixes: 0bfd91d ("Cygwin: console: tty::restore really restores the previous mode")
Reported-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
In the commit 0bfd91d, the behaviour of the tty::restore was
changed so that the console mode is set to the previouslly stored
console mode. Therefore, the console mode for the background non-
cygwin app should not be set to tty::restore anymore in setup_for_
non_cygwin_app(). This should have been fixed in that commit.
This patch belatedly fixes it.

Fixes: 0bfd91d ("Cygwin: console: tty::restore really restores the previous mode")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Comment thread newlib/libc/machine/riscv/setjmp.S Outdated
RISC-V: setjmp: remove redundant checks for Zclsd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants