[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Tinycc-devel] Jump optimization questions - commit: 8227db3a
From: |
Ekaitz Zarraga |
Subject: |
[Tinycc-devel] Jump optimization questions - commit: 8227db3a |
Date: |
Tue, 09 Aug 2022 18:39:57 +0000 |
Hi all,
I'm working on the RISC-V bootstrapping efforts for Guix, and I have to
backport the RISC-V backend to an older TinyCC version we have patched in order
to be able to build it with a simpler compiler.
The process worked mostly ok, but I can't understand very well the `gtst`
function in the generation part, and I need to write it from scratch as the
commit 8227db3a changed how the tests and jumps are managed.
I read the `gtst` function in other architectures but I don't understand every
field, I hope you can help me.
This is the code I managed to arrange, following what I can see in the arm and
i386 targets, but I need to fill the gaps. I added some comments in the hopes
you can clarify them to me.
The thing that makes me be lost the most is the variable names... `t` and such
are a little bit difficult to follow.
``` c
/* generate a test. set 'inv' to invert test. Stack entry is popped */
int gtst(int inv, int t)
{
// I'd love be sure of what's `t` -> I think it's the jump target. In all the
// gtst calls I see it's `0` but then when other things are called it's set
// to another value and returned, so it might be that: the test doesn't need
// to jump until we insert instructions after it...?
int v = vtop->r & VT_VALMASK;
int r=ind;
// What's `ind`? the current location in the code (it looks like because
// it's incremented in o() )
if (nocode_wanted) {
;
} else if (v == VT_CMP) {
/* TODO */
/*
* vtop->c.i contains the kind of the operation we need to do (we need
* to invert it if we have `inv` set, we can use `negcc` for that, which
* just converts the value to the negated version )
* - TOK_ULT
* - TOK_UGE
* - TOK_EQ
* - TOK_NE
* - TOK_ULE
* - TOK_UGT
* - TOK_Nset
* - TOK_Nclear
* - TOK_LT
* - TOK_GE
* - TOK_LE
* - TOK_GT
* We generate the operation with that, and we need to insert the branch
* too: then o(operation) to generate the code.
* The branch is obtained from:
* - r -> position
* - t -> address
* - fail -> for the case that the jump is too large to be encoded here
* `- That should load the address in steps and all that, but arm
* doesn't implement that yet, so we won't
* RISC-V does not have CPU flags, where's the value stored in that case?
*/
t=r;
} else if (v == VT_JMP || v == VT_JMPI) {
// && and || optimization I don't understand
/* Check if jump is inverted (v&1) and if the gtst was inverted at the
same time */
if ((v & 1) == inv) {
if(!vtop->c.i)
vtop->c.i=t;
// ??
else{
// DOES SOME INSTRUCTION DECODING HERE -> patching previous
// jumps?
}
} else {
// Just jump?
// Why return `t`?
t = gjmp(t);
gsym(vtop->c.i);
}
}
vtop--;
return t;
}
```
Thank you all for the help,
Ekaitz
PS: grischka, I added you on copy as you are the autor of the mentioned commit.
- [Tinycc-devel] Jump optimization questions - commit: 8227db3a,
Ekaitz Zarraga <=
- Re: [Tinycc-devel] Jump optimization questions - commit: 8227db3a, grischka, 2022/08/10
- Re: [Tinycc-devel] Jump optimization questions - commit: 8227db3a, Ekaitz Zarraga, 2022/08/10
- Re: [Tinycc-devel] Jump optimization questions - commit: 8227db3a, Ekaitz Zarraga, 2022/08/11
- Re: [Tinycc-devel] Jump optimization questions - commit: 8227db3a, Ekaitz Zarraga, 2022/08/25
- Re: [Tinycc-devel] Jump optimization questions - commit: 8227db3a, grischka, 2022/08/25
- Re: [Tinycc-devel] Jump optimization questions - commit: 8227db3a, Ekaitz Zarraga, 2022/08/25
- Re: [Tinycc-devel] Jump optimization questions - commit: 8227db3a, grischka, 2022/08/26
- Re: [Tinycc-devel] Jump optimization questions - commit: 8227db3a, Ekaitz Zarraga, 2022/08/26
- Re: [Tinycc-devel] Jump optimization questions - commit: 8227db3a, pursuer2, 2022/08/11