size-optimization option and peep-hole optimizer have been introduced.

object files have been moved to binary directory
This commit is contained in:
matsutsuka 2009-12-11 14:59:31 +00:00
parent 6940c85518
commit ebe74fed56
5 changed files with 205 additions and 27 deletions

View File

@ -2,7 +2,7 @@
# Makefile for z80/SDCC
# @author Takahide Matsutsuka <markn@markn.org>
#
# $Id: Makefile.z80,v 1.13 2009/07/09 18:26:55 matsutsuka Exp $
# $Id: Makefile.z80,v 1.14 2009/12/11 14:59:32 matsutsuka Exp $
#
### Compiler definitions
@ -19,14 +19,14 @@ CUSTOM_RULE_ALLOBJS_TO_TARGETLIB=1
CUSTOM_RULE_LINK=1
### Default flags
CFLAGS += --std-c99 -mz80
# --peep-file $(CONTIKI_CPU)/z80peephole.def
CFLAGS += --std-c99 -mz80 --opt-code-size
CFLAGS += --peep-file $(CONTIKI_CPU)/z80peephole.def --fverbose-asm
ASFLAGS +=
LDFLAGS += -mz80 --out-fmt-ihx --no-std-crt0
AROPTS = -a
### CPU-dependent cleanup files
CLEAN += *.lnk *.sym *.lib contiki.ihx
CLEAN +=
### CPU-dependent directories
CONTIKI_CPU_DIRS = . dev lib loader
@ -36,7 +36,6 @@ CONTIKI_SOURCEFILES += strcasecmp.c mtarch.c uip_arch.c \
libconio_z80.c log-conio.c rs232.c \
mef.c
CONTIKI_ASMFILES += uip_arch-asm.S crt0.S
#crt-prg.S
CONTIKI_ASMOBJECTFILES = ${addprefix $(OBJECTDIR)/,$(CONTIKI_ASMFILES:.S=.o)}
@ -65,21 +64,17 @@ $(OBJECTDIR)/%.o: %.cS
endif
#CUSTOM_RULE_ALLOBJS_TO_TARGETLIB
contiki-$(TARGET).lib: $(CONTIKI_OBJECTFILES) $(PROJECT_OBJECTFILES) $(CONTIKI_ASMOBJECTFILES) $(CONTIKI_CASMOBJECTFILES)
$(OBJECTDIR)/contiki-$(TARGET).lib: $(CONTIKI_OBJECTFILES) $(PROJECT_OBJECTFILES) $(CONTIKI_ASMOBJECTFILES) $(CONTIKI_CASMOBJECTFILES)
rm -f $@
for target in $^; do echo $$target >> $@; done
sed -i -e "s/$(OBJECTDIR)\///" $@
#CUSTOM_RULE_LINK
contiki.ihx: contiki-$(TARGET).lib $(OBJECTDIR)/crt0.o
$(CC) $(LDFLAGS) -o $@ $(OBJECTDIR)/crt0.o -lcontiki-$(TARGET).lib
$(LD) -nf contiki
$(OBJECTDIR)/contiki.ihx: $(OBJECTDIR)/contiki-$(TARGET).lib $(OBJECTDIR)/crt0.o
$(CC) $(LDFLAGS) -o $@ $(OBJECTDIR)/crt0.o -L$(OBJECTDIR) -lcontiki-$(TARGET).lib
$(LD) -nf $(OBJECTDIR)/contiki
mv $(OBJECTDIR)/contiki.map .
LDPFLAGS = -mz80 --out-fmt-ihx --no-std-crt0 --code-loc 0 --data-loc 0
test.ihx: contiki-$(TARGET).lib $(OBJECTDIR)/crt-prg.o
$(CC) $(LDPFLAGS) -o $@ $(OBJECTDIR)/crt-prg.o -lcontiki-$(TARGET).lib
$(LD) -nf test
%.ihx: contiki-$(TARGET).lib $(OBJECTDIR)/%*.o
$(OBJECTDIR)/%.ihx: $(OBJECTDIR)/contiki-$(TARGET).lib $(OBJECTDIR)/%*.o
$(CC) $(LDPFLAGS) -o $@ $(OBJECTDIR)/$*.o -lcontiki-$(TARGET).lib
$(LD) -nf $*

183
cpu/z80/z80peephole.def Normal file
View File

@ -0,0 +1,183 @@
#
# Customized peep-hole optimizer for z80/SDCC
# @author Takahide Matsutsuka <markn@markn.org>
#
# $Id: z80peephole.def,v 1.1 2009/12/11 14:59:32 matsutsuka Exp $
#
replace {
ld hl, %1
ld (hl), #0x%2
inc hl
ld (hl), #0x%3
} by {
;; (peep) 1 short store
ld hl, #0x%3%2
ld (%1), hl
}
replace {
ld hl, %1 + 0
ld (hl), %2
ld hl, %1 + 1
ld (hl), %3
} by {
;; (peep) 2 short store
ld hl, %1
ld (hl), %2
inc hl
ld (hl), %3
}
replace {
sub a, #0x01
jr Z, %1
} by {
;; (peep) 3 decrement optimization
dec a
jr z, %1
}
replace {
sub a, #0x01
jr NZ, %1
} by {
;; (peep) 4 decrement optimization
dec a
jr nz, %1
}
replace {
sub a, #0x01
jp Z, %1
} by {
;; (peep) 5 decrement optimization
dec a
jp z, %1
}
replace {
sub a, #0x01
jp NZ, %1
} by {
;; (peep) 6 decrement optimization
dec a
jp nz, %1
}
replace {
push %1
pop iy
ld a, (iy)
or a, a
} by {
;; (peep) 7 or optimization
ld a, (%1)
or a, a
}
replace {
ld iy, %1
ld a, 0 (iy)
} by {
;; (peep) 8 iy optimization
ld a, (%1)
}
replace {
ld iy, %1
ld 0 (iy), a
} by {
;; (peep) 9 iy optimization
ld (%1), a
}
replace {
push %1
pop iy
ld (iy), %2
} by {
;; (peep) 10 iy optimization
ld a, %2
ld (%1), a
}
replace {
ld iy, %1
ld %2,0 (iy)
ld iy, %1
ld %3,1 (iy)
ld iy, %1
ld %4,2 (iy)
ld iy, %1
ld %5,3 (iy)
} by {
;; (peep) 11 iy optimization
ld iy, %1
ld %2,0 (iy)
ld %3,1 (iy)
ld %4,2 (iy)
ld %5,3 (iy)
}
replace {
ld iy, %1
ld %2,0 (iy)
ld iy, %1
ld %3,1 (iy)
} by {
;; (peep) 12 iy optimization
ld iy, %1
ld %2,0 (iy)
ld %3,1 (iy)
}
replace {
ld iy, %1
ld 0 (iy), %2
ld iy, %1
ld 1 (iy), %3
ld iy, %1
ld 2 (iy), %4
ld iy, %1
ld 3 (iy), %5
} by {
;; (peep) 13 iy optimization
ld iy, %1
ld 0 (iy), %2
ld 1 (iy), %3
ld 2 (iy), %4
ld 3 (iy), %5
}
replace {
ld iy, %1
ld 0 (iy), %2
ld iy, %1
ld 1 (iy), %3
} by {
;; (peep) 14 iy optimization
ld iy, %1
ld 0 (iy), %2
ld 1 (iy), %3
}
replace {
jp %1
%2:
} by {
;; (peep) 15 short jump optimization
jr %1
%2:
} if labelInRange
replace {
ld c,%3 (ix)
ld b,%4 (ix)
push bc
pop iy
ld 0 (iy), #0x%6
ld 1 (iy), #0x%5
} by {
;; (peep) 16 store value
ld l, %3 (ix)
ld h, %4 (ix)
ld (hl), #0x%5%6
}

View File

@ -2,7 +2,7 @@
# Makefile for PC-6001 using z80/SDCC
# @author Takahide Matsutsuka <markn@markn.org>
#
# $Id: Makefile.pc-6001,v 1.11 2009/07/09 18:28:20 matsutsuka Exp $
# $Id: Makefile.pc-6001,v 1.12 2009/12/11 14:59:31 matsutsuka Exp $
#
ifndef CONTIKI
@ -102,15 +102,15 @@ CONTIKI_CASMFILES += ctk-conio_arch-asm.cS libconio_arch-asm.cS\
CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)
CLEAN += *.rom *.p6 *.asm
CLEAN += *.rom *.p6
contiki: $(HEX2BIN) contiki.p6
.SUFFIXES:
%.p6: %.ihx
%.p6: $(OBJECTDIR)/%.ihx
$(HEX2BIN) $(HEX2BINFLAGS) $< $(HEX2BINDIR)/ihx/suffix.ihx
%.rom: %.ihx
%.rom: $(OBJECTDIR)/%.ihx
$(HEX2BIN) $(HEX2BINFLAGS) $<
$(HEX2BIN):

View File

@ -27,7 +27,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: contiki-minimal-main.c,v 1.1 2007/09/11 12:12:59 matsutsuka Exp $
* $Id: contiki-minimal-main.c,v 1.2 2009/12/11 14:59:31 matsutsuka Exp $
*
*/
@ -43,7 +43,7 @@
#include "program-handler.h"
#include "tinysample-dsc.h"
extern struct process *tiny_process;
PROCESS_NAME(tiny_process);
/*---------------------------------------------------------------------------*/
int
main(void)

View File

@ -27,7 +27,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: contiki-serial-main.c,v 1.4 2009/03/17 20:32:22 adamdunkels Exp $
* $Id: contiki-serial-main.c,v 1.5 2009/12/11 14:59:31 matsutsuka Exp $
*
*/
@ -62,7 +62,7 @@ rs232_print(char* str) {
}
/*---------------------------------------------------------------------------*/
static void
log_message(char* str) {
log(char* str) {
while (*str != 0) {
libputc_arch(*str++);
}
@ -80,18 +80,18 @@ PROCESS_THREAD(stest_process, ev, data)
etimer_set(&timer, CLOCK_SECOND);
log_message("Starting serial test process");
log("Starting serial test process");
while(1) {
PROCESS_WAIT_EVENT();
if (etimer_expired(&timer)) {
log_message("Sending serial data now");
log("Sending serial data now");
rs232_print("GNU's not Unix\n");
etimer_reset(&timer);
}
if(ev == serial_line_event_message) {
log_message(data);
log(data);
}
}