[Sdcc-user] Peephole rules

2016-12-16 Thread Травкин Роман
Hello. Where I can read about writing peephole rules for sdcc? I looked at sources and found one file, but its syntax is unclear for me. Target platform is stm8

--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot___
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user


Re: [Sdcc-user] Peephole rules

2016-12-16 Thread 史斌
I  suggest you begin with the simplest  rules in the source. 


Ben Shi

> 在 2016年12月16日,17:14,Травкин Роман  写道:
> 
> Hello. Where I can read about writing peephole rules for sdcc? I looked at 
> sources and found one file, but its syntax is unclear for me. Target platform 
> is stm8
> --
> Check out the vibrant tech community on one of the world's most 
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> ___
> Sdcc-user mailing list
> Sdcc-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sdcc-user



--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user


Re: [Sdcc-user] Peephole rules

2016-12-16 Thread Maarten Brock
> Hello. Where I can read about writing peephole rules for sdcc? I
> looked at sources and found one file, but its syntax is unclear for me.
> Target platform is stm8

Start by looking at the peephole definition file in the sources that is
automatically used.
https://sourceforge.net/p/sdcc/code/HEAD/tree/trunk/sdcc/src/stm8/peeph.def

Maarten

--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user


Re: [Sdcc-user] Peephole rules

2016-12-16 Thread Травкин Роман
I've loocked at this file (as I mentioned earlier). Some moments push me to ask questions. There are parameters like notUsed('a'), 
notSame(%2 'push' 'pop'), 
notSame(%1 'xl' 'xh' 'yl' 'yh'),
immdInRange(0 255 '+' %1 %2 %9),
labelIsUncondJump(),
labelRefCountChange
and many others. i can look at examples and make my own like a monkey, but it's not best practice. 
Tried too lokk at sources of sdcc, but my sw skill isn't enough to understand code.And second. Some params of peep riules are numbered in series like %1, %2, %3 etc,and some like %1, %5, %9. Why is it so?16.12.2016, 12:10, "Maarten Brock" : Hello. Where I can read about writing peephole rules for sdcc? I looked at sources and found one file, but its syntax is unclear for me. Target platform is stm8Start by looking at the peephole definition file in the sources that isautomatically used.https://sourceforge.net/p/sdcc/code/HEAD/tree/trunk/sdcc/src/stm8/peeph.defMaarten--Check out the vibrant tech community on one of the world's mostengaging tech sites, SlashDot.org! http://sdm.link/slashdot___Sdcc-user mailing listSdcc-user@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/sdcc-user--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot___
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user


Re: [Sdcc-user] Peephole rules

2016-12-16 Thread Травкин Роман
Is this rule correct? In PM0044 STM8 CPU Programming manual popw only gets 16bit registers (X, Y) replace restart {    popw    a    popw    a} by {    popw    x    ; peephole 14a merged pop a into popw x} if notUsed('a'), notUsed('x') This rule is from file https://sourceforge.net/p/sdcc/code/HEAD/tree/trunk/sdcc/src/stm8/peeph.def#l412

--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot___
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user


Re: [Sdcc-user] Peephole rules

2016-12-16 Thread R0b0t1
On Fri, Dec 16, 2016 at 4:47 AM, Травкин Роман  wrote:
> Is this rule correct? In PM0044 STM8 CPU Programming manual popw only gets
> 16bit registers (X, Y)
>
> replace restart {
> popwa
> popwa
> } by {
> popwx
> ; peephole 14a merged pop a into popw x
> } if notUsed('a'), notUsed('x')
>
> This rule is from file
> https://sourceforge.net/p/sdcc/code/HEAD/tree/trunk/sdcc/src/stm8/peeph.def#l412
>

Unfortunately the mailing list is not very active; hardware
familiarity might be a bit much to expect. If the definitions in the
distribution aren't right it is up to you to recognize any error.

On Fri, Dec 16, 2016 at 4:25 AM, Травкин Роман  wrote:
> I've loocked at this file (as I mentioned earlier). Some moments push me to
> ask questions. There are parameters like
>
> notUsed('a'),
> notSame(%2 'push' 'pop'),
> notSame(%1 'xl' 'xh' 'yl' 'yh'),
> immdInRange(0 255 '+' %1 %2 %9),
> labelIsUncondJump(),
> labelRefCountChange
> and many others. i can look at examples and make my own like a monkey, but
> it's not best practice.
>
> Tried too lokk at sources of sdcc, but my sw skill isn't enough to
> understand code.
> And second. Some params of peep riules are numbered in series like %1, %2,
> %3 etc,
> and some like %1, %5, %9. Why is it so?
>

I am not sure if wikipedia.ru is as up-to-date as the English
equivalent. In any case:

A peephole optimizer applies a set of hand picked rules against a
moving window of code. The numbered parameters are variables. They are
able to assume values of an instruction or any of its arguments; when
in the argument position, addressing mode sigils constrain the
instruction to be matched.

The predicates you listed constrain the replacement rule. notUsed
checks to see if a register contains user assigned data. notSame
checks to see if an instruction or register is the same as one
provided. immdInRange checks to see if an immediate value (a constant)
is within the range specified. The rest should be relatively
self-explanatory. I wasn't able to find a list of all predicates
available, but you should look for one.

You can refer to http://sdcc.sourceforge.net/doc/sdccman.pdf, but I
admit it isn't very descriptive. Reading through SDCCpeeph.h and
SDCCpeep.c will have little benefit. I suggest getting a copy of the
processor manual and reading through the section on instruction
representation and addressing modes. Once you have done so the
peephole rules should make more sense.

--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user


Re: [Sdcc-user] Peephole rules

2016-12-16 Thread alvin albrecht

>I've loocked at this file (as I mentioned earlier). Some moments push me to 
>ask questions. There are parameters like
 >

>notUsed('a'),
>notSame(%2 'push' 'pop'),
>notSame(%1 'xl' 'xh' 'yl' 'yh'),
>immdInRange(0 255 '+' %1 %2 %9),
>labelIsUncondJump(),
>labelRefCountChange
>and many others. i can look at examples and make my own like a monkey, but 
>it's not best pra>ctice.


>Tried too lokk at sources of sdcc, but my sw skill isn't enough to understand 
>code.
>And second. Some params of peep riules are numbered in series like %1, %2, %3 
>etc,
>and some like %1, %5, %9. Why is it so?


What I found useful is to examine line ~1409 in 
https://sourceforge.net/p/sdcc/code/HEAD/tree/trunk/sdcc/src/SDCCpeeph.c#l1409
(static const struct ftab).  This structure defines all the conditions that can 
be placed on peephole rules.  Their implementation is just above that 
structure.  This is what I wish I had known about when I first started making 
my own peephole rules.

You can use the existing peephole set for examples of how to use these 
qualifiers.

The %n are text strings.  Inside the peephole rules they represent strings 
found in the source code.  The numbers are only identifiers and are not 
important.

The description of peepholer posted by R0b0t1 describes simple peepholers.  
Sdcc's is a little more sophisticated.

--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot___
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user


Re: [Sdcc-user] Peephole rules

2016-12-16 Thread R0b0t1
On Fri, Dec 16, 2016 at 8:29 PM, alvin albrecht
 wrote:
>
> What I found useful is to examine line ~1409 in
> https://sourceforge.net/p/sdcc/code/HEAD/tree/trunk/sdcc/src/SDCCpeeph.c#l1409
> (static const struct ftab).  This structure defines all the conditions that
> can be placed on peephole rules.  Their implementation is just above that
> structure.  This is what I wish I had known about when I first started
> making my own peephole rules.
>

Very informative, thank you! I'm not very acquainted with the
internals - I gave the file a two-over but missed that section.

> The description of peepholer posted by R0b0t1 describes simple peepholers.
> Sdcc’s is a little more sophisticated.
>

Can you explain how they differ? I didn't mean to say anything
specific about which rules are applied or how they might be applied.

--
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
___
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user