GithubHelp home page GithubHelp logo

"Notes on SDCC" on website about sduino HOT 4 CLOSED

tenbaht avatar tenbaht commented on August 22, 2024
"Notes on SDCC" on website

from sduino.

Comments (4)

tenbaht avatar tenbaht commented on August 22, 2024

Hi Philipp,

issue 1

Unfortunately, I didn't keep the files when I found that problem. I can't find any examples anymore, so I assume it was fixed in one of the later compiler revisions.

issue 2

minimal example code:

int array[4];
void array_access(unsigned char index)
{
    array[index] = 0;
}

compiled using the latest snapshot build 9998:

$ /opt/sdcc/bin/sdcc -c -mstm8 issue14-2.c
$ /opt/sdcc/bin/sdcc -v
SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8 3.6.9 #9998 (Linux)
published under GNU General Public License (GPL)

results in this code:

      000000                         47 _array_access:
      000000 52 02            [ 2]   48 	sub	sp, #2
                                     49 ;	issue14.c: 6: array[index] = 0;
      000002 AEr00r00         [ 2]   50 	ldw	x, #_array+0
      000005 1F 01            [ 2]   51 	ldw	(0x01, sp), x
      000007 7B 05            [ 1]   52 	ld	a, (0x05, sp)
      000009 97               [ 1]   53 	ld	xl, a
      00000A A6 02            [ 1]   54 	ld	a, #0x02
      00000C 42               [ 4]   55 	mul	x, a
      00000D 72 FB 01         [ 2]   56 	addw	x, (0x01, sp)
      000010 6F 01            [ 1]   57 	clr	(0x1, x)
      000012 7F               [ 1]   58 	clr	(x)
      000013 5B 02            [ 2]   59 	addw	sp, #2
      000015 81               [ 4]   60 	ret

When I look at it I see that the mul command already includes the transfer of the result into x which needs to happen anyway. It would be great if the temporary variable (0x01,sp) could be avoided in the first place.

issues 3-5

Thank you for your explanation!

I noticed the recent changes in the backend, the optimizer and the simulator. I would like to compare the development of the code size compared to an older version. Thank you for all the work there!

Michael

from sduino.

spth avatar spth commented on August 22, 2024

Issue 2: Thanks. I can see how using sllw could save 1 byte and 2 cycles vs the current solution using mul. I'll probably look into implementing it next week.

Philipp

P.S.: Eliminating the temporary at (1,sp) would take more effort, since it needs an optimization capable of folding ADDRESS_OF into '+'.

from sduino.

spth avatar spth commented on August 22, 2024

As of revision #10000, a sllw is used instead of the mul. The mcs51 backend can optimize out the temporary that holds the array address; I'll look into porting the solution to stm8 (and maybe z80).

Philipp

P.S.: See also https://sourceforge.net/p/sdcc/feature-requests/536/

from sduino.

tenbaht avatar tenbaht commented on August 22, 2024

sllw works with rev. 10088 and saves one byte.

I am looking forward to see the temporary optimized out, that could save 7 bytes on every array access. I will follow the discussion on SF, no need to duplicate it here.

from sduino.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.