FAQ  •  Register  •  Login

Efficiency Optimizations

<<

britlion

Posts: 720

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Thu May 21, 2009 2:27 pm

Efficiency Optimizations

I know, I know - I'm always harping on about this.

1> Does setting array and string indexes to start at 1 - to make it like basic - make for less efficient code?
(that is using the new default for --sinclair that Boriel is presumably putting into the next version)

2> Boriel once mentioned that the default behavior for code like:

  Code:
LET A=A+1
LET A=A*2


Was

  Code:
   ld a, 10               ;Init
   ld (_A), a            ;Load
   inc a                   ;Inc
   ld (_A), a            ; Store         <<<<< Not needed
   sla a                   ; Multiply
   ld (_A), a            ; Store



And that -O3 should remove that extra code. I actually can't tell the difference in the above with or without -O3.

What does -O3 do? My code seems to be remarkably similar. In fact, the runtime routines for almost everything are included still - most of the print system (AT, COLOR, BOLD, ITALIC) even if never used).

Is -O3 doing what it's supposed to? I find most short code seems to be just about the same size, suggesting it isn't cutting down on runtime routines at all.

Actual program used:

  Code:
DIM A as byte

LET A=5
LET A=A+1
LET A=A*2

PRINT A


Actual -O3 Result:

  Code:
E:\ZX\ZXBwork>zxb Test2.bas -A -O3
INFO: __PRINTI8 is not defined. No optimization is done.
INFO: PRINT_EOL is not defined. No optimization is done.

E:\ZX\ZXBwork>notepad Test2.asm


The produced code was 1134 bytes without -O3 and 1132 bytes with -O3.

The difference is the end of the program. Optimized it does
  Code:
ld bc, 0

Unoptimized it closes out with
  Code:
ld hl, 0
ld b, h
ld c, l


That's the only difference.
These error messages seem a little odd. Am I misusing the -O3 option, somehow? I was expecting it to cut out all the runtimes that wouldn't be needed.

Admittedly in a larger project, most of the runtimes would likely end up being used. I was a little spoiled by the tiny code that the hisoft compiler made, I think :-)
<<

boriel

Site Admin

Posts: 1239

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Thu May 21, 2009 6:47 pm

Re: Efficiency Optimizations

I think, this is best moved to "Whishlist" (TO DO list, wishes, suggestions, etc...) so it won't get buried among other threads. :)

Return to Wishlist

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO