On 18/02/2021 15:32, Royce Pereira (T-star Instrumentation) wrote:
Its curious why the "PD_ODR |= 1<<1" produced the "ld a ...." in the 1st example, while just the 'bset ...' in the second, when both cases were absolute addresses.

The answer is simple: SDCC does not currently have any peephole optimiser rules that cater to the first example.

You can see what rules are applied for optimising to 'bset/bres/bcpl' instructions by looking at src/stm8/peeph.def file in the SDCC source. Rules 18-*, 19-*, and 20-*, if memory serves me correctly.

You can easily formulate some additional rules for yourself and create a custom .def file that can be specified at compile-time with --peep-file argument.

For your example, a rule like the following may be appropriate (note: untested!):

replace restart {
    ld    a, %1+%3
    or    a, #0x02
    ld    %1+%3, a
} by {
    bset    %1+%3, #1
} if notUsed('a'), notUsed('n'), notUsed('z'), operandsLiteral(%3)

The rule would need to be repeated to cover every bit position - e.g. #0x01, #0x02, #0x04, etc. for 'or' instruction second operand; #0, #1, #2, etc. for 'bset' second operand.

Regards,
Basil Hussain


_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to