Browse Source

library:
* use explicit register parameters for Sprite8/16/32, bsearch and qsort;
* regenerate headers;
* 2-byte optimization in Sprite8: shift count can be computed differently.

git-svn-id: file:///var/svn/tigccpp/trunk@1360 9552661e-59e3-4036-b4f2-dbe53926924f

debrouxl 14 years ago
parent
commit
a31e256bbf

+ 3 - 3
tigcc/archive/bsearch.c

@@ -49,13 +49,13 @@ register long __tbl asm ("a5");
  * have to make lim 3, then halve, obtaining 1, so that we will only
  * look at item 3.
  */
-__ATTR_LIB_C__ void *bsearch(const void *key, const void *bptr, short n, short w, compare_t cmp_func);
+void *bsearch(const void *key asm("a0"), const void *bptr asm("a1"), short n asm("d0"), short w asm("d1"), compare_t cmp_func asm("a2")) __ATTR_LIB_ASM__;
 asm("
 	.text
 	.even
 	.globl	bsearch
 bsearch:
-	movem.l %d3-%d5/%a2-%a4,-(%sp)
+	movem.l %d3-%d5/%a3-%a4,-(%sp)
 	move.l %a0,%d5	;# key, key
 	move.w %d1,%d4	;# w, w
 	move.l %a1,%a3	;# bptr, base
@@ -82,7 +82,7 @@ bsearch:
 	suba.l %a4,%a4	;# rptr
 .L4:
 	move.l %a4,%a0	;# rptr, <result>
-	movem.l (%sp)+,%d3-%d5/%a2-%a4
+	movem.l (%sp)+,%d3-%d5/%a3-%a4
 	rts
 ");
 

+ 4 - 5
tigcc/archive/qsort.c

@@ -6,7 +6,7 @@ register long __tbl asm ("a5");
 // This is not a quick sort, it's a shell sort.
 // For sorting data that has no significant statistical property, on embedded platforms
 // without processor caches, the shell sort is one of the very best size/speed tradeoffs.
-__ATTR_LIB_C__ void qsort(void *list, short num_items, short size, compare_t cmp_func);
+void qsort(void *list asm("a0"), short num_items asm("d0"), short size asm("d1"), compare_t cmp_func asm("a2")) __ATTR_LIB_ASM__;
 
 asm("
 | d3 <- p
@@ -22,10 +22,9 @@ asm("
 	.even
 	.globl qsort
 qsort:
-	movem.l %d3-%d7/%a2-%a4/%a6,-(%sp)
+	movem.l %d3-%d7/%a3-%a4/%a6,-(%sp)
 	move.l %a0,%a4	;# list, list
 	move.w %d1,%d7	;# size, size
-	move.l %a1,%a2	;# cmp_func, cmp_func
 	move.w #4096,%d5	;#, k
 	cmp.w #16,%d0	;#, num_items
 	bhi.s .L4	;#
@@ -84,7 +83,7 @@ qsort:
 	sub.w %d0,%d5	;# tmp60, k
 	bne.s .L6	;#
 
-	movem.l (%sp)+,%d3-%d7/%a2-%a4/%a6
+	movem.l (%sp)+,%d3-%d7/%a3-%a4/%a6
 	rts
 ");
 
@@ -192,4 +191,4 @@ qsort:
 	addq.w #8,%sp
 	rts
 */
-// In six steps, 30 bytes were saved, yielding the ASM routine at the top of this file.
+// In seven steps, 34 bytes were saved, yielding the ASM routine at the top of this file.

+ 13 - 15
tigcc/archive/sprite16.s

@@ -15,21 +15,19 @@ Sprite16:
 	and.w #15,%d0 | 4
 	addq.w #1,%d0 | 2
 
-	move.w %d4,-(%a7) | 2
-	move.l %d3,-(%a7) | 2
-| d4: drawing mode.
-	move.w 4+6(%a7),%d4 | 4
-	subq.w #1,%d4 | 2
-| d3: mask used by AND and RPLC.
-	moveq #-1,%d3 | 2
-	clr.w %d3 | 2
-	rol.l %d0,%d3 | 2
+	move.l %d4,-(%a7) | 2
+| d3: drawing mode.
+	subq.w #1,%d3 | 2
+| d4: mask used by AND and RPLC.
+	moveq #-1,%d4 | 2
+	clr.w %d4 | 2
+	rol.l %d0,%d4 | 2
 | Jump to loop entry.
 	bra.s .L__s16_loopentry | 2
 
 | AND.
 .L__s16_Am:
-	or.l %d3,%d1 | 2
+	or.l %d4,%d1 | 2
 	and.l %d1,(%a1) | 2
 
 | Next line.
@@ -44,13 +42,13 @@ Sprite16:
 	moveq #0,%d1 | 2
 	move.w (%a0)+,%d1 | 2
 	lsl.l %d0,%d1 | 2
-	cmp.w #1,%d4 | 4
+	cmp.w #1,%d3 | 4
 	beq.s .L__s16_Am | 2
-	tst.w %d4 | 2
+	tst.w %d3 | 2
 	blt.s .L__s16_Xm | 2
 	beq.s .L__s16_Om | 2
 | RPLC.
-	and.l %d3,(%a1) | 2
+	and.l %d4,(%a1) | 2
 
 | OR.
 .L__s16_Om:
@@ -64,6 +62,6 @@ Sprite16:
 
 | Return
 .L__s16_rts:
-	move.l (%a7)+,%d3 | 2
-	move.w (%a7)+,%d4 | 2
+	addq.w #1,%d3 | 2
+	move.l (%a7)+,%d4 | 2
 	rts | 2

+ 12 - 13
tigcc/archive/sprite32.s

@@ -17,20 +17,19 @@ Sprite32:
 	sub.w %d0,%d5 | 2
 
 | d4: drawing mode.
-	move.w 4+5*4(%a7),%d4 | 4
-	subq.w #1,%d4 | 2
+	subq.w #1,%d3 | 2
 | d3, d6: masks used by AND and RPLC.
-	moveq #-1,%d3 | 2
-	lsr.w %d0,%d3 | 2
-        move.w %d3,%d6 | 2
-        not.l %d3 | 2
-        swap %d3 | 2
+	moveq #-1,%d4 | 2
+	lsr.w %d0,%d4 | 2
+	move.w %d4,%d6 | 2
+	not.l %d4 | 2
+	swap %d4 | 2
 | Jump to loop entry.
 	bra.s .L__s32_loopentry | 2
 
 | AND.
 .L__s32_Am:
-	or.l %d3,%d1 | 2
+	or.l %d4,%d1 | 2
 	or.w %d6,%d7 | 2
 	and.l %d1,(%a1)+ | 2
 	and.w %d7,(%a1) | 2
@@ -46,15 +45,15 @@ Sprite32:
 
 	move.l (%a0)+,%d1 | 2
 	move.w %d1,%d7 | 2
-        lsr.l %d0,%d1 | 2
-        lsl.w %d5,%d7 | 2
-	cmp.w #1,%d4 | 4
+	lsr.l %d0,%d1 | 2
+	lsl.w %d5,%d7 | 2
+	cmp.w #1,%d3 | 4
 	beq.s .L__s32_Am | 2
-	tst.w %d4 | 2
+	tst.w %d3 | 2
 	blt.s .L__s32_Xm | 2
 	beq.s .L__s32_Om | 2
 | RPLC.
-	and.l %d3,(%a1) | 2
+	and.l %d4,(%a1) | 2
 	and.w %d6,4(%a1) | 2
 | OR.
 .L__s32_Om:

+ 21 - 23
tigcc/archive/sprite8.s

@@ -11,26 +11,24 @@ Sprite8:
 	add.w %d1,%d1 | 2
 	adda.w %d1,%a1 | 2
 | d0: shift count.
-	not.w %d0 | 2
+	moveq #24,%d1 | 2
 	and.w #15,%d0 | 4
-	add.w #9,%d0 | 4
+	sub.w %d0,%d1 | 2
 
-	move.w %d4,-(%a7) | 2
-	move.l %d3,-(%a7) | 2
-| d4: drawing mode.
-	move.w 4+6(%a7),%d4 | 4
-	subq.w #1,%d4 | 2
-| d3: mask used by AND and RPLC.
-	moveq #-1,%d3 | 2
-	clr.b %d3 | 2
-	rol.l %d0,%d3 | 2
+	move.l %d4,-(%a7) | 2
+| d3: drawing mode.
+	subq.w #1,%d3 | 2
+| d4: mask used by AND and RPLC.
+	moveq #-1,%d4 | 2
+	clr.b %d4 | 2
+	rol.l %d1,%d4 | 2
 | Jump to loop entry.
 	bra.s .L__s8_loopentry | 2
 
 | AND.
 .L__s8_Am:
-	or.l %d3,%d1 | 2
-	and.l %d1,(%a1) | 2
+	or.l %d4,%d0 | 2
+	and.l %d0,(%a1) | 2
 
 | Next line.
 .L__s8_loop:
@@ -41,29 +39,29 @@ Sprite8:
 	subq.w #1,%d2 | 2
 	blt.s .L__s8_rts | 2
 
-	moveq #0,%d1 | 2
-	move.b (%a0)+,%d1 | 2
-	lsl.l %d0,%d1 | 2
-	cmp.w #1,%d4 | 4
+	moveq #0,%d0 | 2
+	move.b (%a0)+,%d0 | 2
+	lsl.l %d1,%d0 | 2
+	cmp.w #1,%d3 | 4
 	beq.s .L__s8_Am | 2
-	tst.w %d4 | 2
+	tst.w %d3 | 2
 	blt.s .L__s8_Xm | 2
 	beq.s .L__s8_Om | 2
 | RPLC.
-	and.l %d3,(%a1) | 2
+	and.l %d4,(%a1) | 2
 
 | OR.
 .L__s8_Om:
-	or.l %d1,(%a1) | 2
+	or.l %d0,(%a1) | 2
 	bra.s .L__s8_loop | 2
 
 | XOR
 .L__s8_Xm:
-	eor.l %d1,(%a1) | 2
+	eor.l %d0,(%a1) | 2
 	bra.s .L__s8_loop | 2
 
 | Return
 .L__s8_rts:
-	move.l (%a7)+,%d3 | 2
-	move.w (%a7)+,%d4 | 2
+	addq.w #1,%d3 | 2
+	move.l (%a7)+,%d4 | 2
 	rts | 2

+ 12 - 1
tigcc/doc/System/Include/sprites.h/Sprite16.hsf

@@ -4,7 +4,18 @@ Type=Function
 Subtype=tigcc.a
 Header Files=sprites.h
 Definition=void Sprite16 (short x, short y, short height, const unsigned short *sprite, void *vm_addr, short mode);
-Real Definition=extern void Sprite16(short,short,short,__cpushort,void*,short)__ATTR_LIB_C__;
+Real Definition=extern void Sprite16(short asm("d0"),short asm("d1"),short asm("d2"),__cpushort asm("a0"),void* asm("a1"),short asm("d3"))__ATTR_LIB_ASM__;
+
+[Library Call]
+Asm=1
+
+[Registers]
+x=d0
+y=d1
+height=d2
+sprite=a0
+vm_addr=a1
+mode=d3
 
 [Description]
 Draws a sprite with a width of 16 pixels or less on the screen.

+ 24 - 6
tigcc/doc/System/Include/sprites.h/Sprite32.hsf

@@ -4,7 +4,18 @@ Type=Function
 Subtype=tigcc.a
 Header Files=sprites.h
 Definition=void Sprite32 (short x, short y, short height, const unsigned long *sprite, void *vm_addr, short mode);
-Real Definition=extern void Sprite32(short,short,short,__cpulong,void*,short)__ATTR_LIB_C__;
+Real Definition=extern void Sprite32(short asm("d0"),short asm("d1"),short asm("d2"),__cpulong asm("a0"),void* asm("a1"),short asm("d3"))__ATTR_LIB_ASM__;
+
+[Library Call]
+Asm=1
+
+[Registers]
+x=d0
+y=d1
+height=d2
+sprite=a0
+vm_addr=a1
+mode=d3
 
 [Description]
 Draws a sprite with a width of 32 pixels or less on the screen.
@@ -22,10 +33,17 @@ unsigned long integer, and the first 16 bits are still zero as if they actually
 To take care of this problem, add the <B>'L'</B> (long) suffix to the end of the value.
 <BR><BR>
 If you want to use sprites wider than 32 pixels (which is not very likely), one solution is to
-use DoorsOS and its "put_sprite" function (see <A HREF="$$INFOLINK(faq)">Frequently Asked Questions</A>
-for more info about how to do it). If you don't want to use DoorsOS, the proposed method depends
-on what the use of the sprite will be. If you don't need too fast action, the built-in TIOS function
-<A HREF="$$LINK(graph.h/BitmapPut)">BitmapPut</A> may be good enough. If you need a very fast sprite
-routine for very large sprites, then you must write it yourself.
+use a "kernel"-based program and <CODE>graphlib::put_sprite</CODE> (see <A HREF="$$INFOLINK(faq)">Frequently Asked Questions</A>
+for more info about how to do it). If you don't want to use kernel-based programs, the proposed method depends
+on what the use of the sprite will be:
+<UL>
+<LI>
+If you don't need too fast action, the built-in TIOS function <A HREF="$$LINK(graph.h/BitmapPut)">BitmapPut</A> may be good enough.
+</LI>
+<LI>
+If you need a very fast sprite routine for very large sprites, then you must write it yourself, or use prewritten ones in
+ExtGraph or Genlib.
+</LI>
+</UL>
 <BR><BR>
 See <A HREF="$$LINK(sprites.h/Sprite8)">Sprite8</A> for more info about sprites.

+ 11 - 0
tigcc/doc/System/Include/sprites.h/Sprite8.hsf

@@ -5,6 +5,17 @@ Subtype=tigcc.a
 Header Files=sprites.h
 Definition=void Sprite8 (short x, short y, short height, const unsigned char *sprite, void *vm_addr, short mode);
 
+[Library Call]
+Asm=1
+
+[Registers]
+x=d0
+y=d1
+height=d2
+sprite=a0
+vm_addr=a1
+mode=d3
+
 [Description]
 Draws a sprite with a width of 8 pixels or less on the screen.
 

+ 1 - 1
tigcc/doc/System/Include/sprites.h/sprites.hsh

@@ -5,4 +5,4 @@ See Also=graph.h/, gray.h/
 Simple sprite routines
 
 [Bottom]
-For a lot of advanced drawing routines, we recommend you to download the <A HREF="http://www.ticalc.org/archives/files/fileinfo/187/18705.html">ExtGraph library</A> by the <A HREF="http://tict.ticalc.org/">TI-Chess Team</A>.
+For lots of advanced drawing routines, we recommend you to download either the <A HREF="http://tict.ticalc.org/">ExtGraph static library</A> by the <A HREF="http://tict.ticalc.org/">TI-Chess Team</A> or <A HREF="http://www.yaronet.com/t3/?id=20">Genlib "kernel"-based dynamic library</A> by the <A HREF="http://www.yaronet.com/t3/">Time To Team</A>.

+ 10 - 0
tigcc/doc/System/Include/stdlib.h/bsearch.hsf

@@ -6,6 +6,16 @@ Header Files=stdlib.h
 Definition=void *bsearch (const void *Key, const void *BasePtr, unsigned short NoOfElements, unsigned short Width, compare_t cmp_func);
 See Also=stdlib.h/qsort
 
+[Library Call]
+Asm=1
+
+[Registers]
+Key=a0
+BasePtr=a1
+NoOfElements=d0
+Width=d1
+cmp_func=a2
+
 [Description]
 Binary search.
 

+ 10 - 0
tigcc/doc/System/Include/stdlib.h/qsort.hsf

@@ -4,6 +4,16 @@ Type=Function
 Subtype=tigcc.a
 Header Files=stdlib.h
 Definition=void qsort (void *BasePtr, unsigned short NoOfElements, unsigned short Width, compare_t cmp_func);
+See Also=stdlib.h/bsearch
+
+[Library Call]
+Asm=1
+
+[Registers]
+BasePtr=a0
+NoOfElements=d0
+Width=d1
+cmp_func=a2
 
 [Description]
 Sorts an area of items.

+ 1 - 0
tigcc/include/C/basfunc.h

@@ -24,6 +24,7 @@ typedef ESQ*ESI;
 typedef CESI SYM_STR;
 #endif
 #if MIN_AMS>=101
+#define push_format ({__need_in_use_bit;_rom_call(void,(ESI,ESI),315);})
 #define push_getfold _rom_call(void,(void),317)
 #define push_getkey ({__need_in_use_bit;_rom_call(void,(void),316);})
 #define push_getmode _rom_call(void,(CESI),318)

+ 2 - 0
tigcc/include/C/estack.h

@@ -172,6 +172,8 @@ enum TokenizeSymNameFlags{TSF_FULLY_QUALIFIED=0x01,TSF_ALLOW_RESERVED=0x02,TSF_P
 #define index_main_var _rom_call(ESI,(CESI),2CF)
 #define index_numeric_term _rom_call(ESI,(CESI),2CD)
 #define index_of_lead_base_of_lead_term _rom_call(ESI,(CESI),2CE)
+#define init_list_indices _rom_call(ESI*,(ESI*,CESI),2BA)
+#define init_matrix_indices _rom_call(ESI*,(ESI*,CESI),2BB)
 #define is_advanced_tag _rom_call(short,(ESQ),2D0)
 #define is_antisymmetric ({__need_in_use_bit;_rom_call(short,(CESI,CESI),2D1);})
 #define is_complex0 _rom_call(short,(CESI),2D3)

+ 3 - 3
tigcc/include/C/sprites.h

@@ -5,9 +5,9 @@
 
 /* Begin Auto-Generated Part */
 enum SprtModes{SPRT_XOR,SPRT_OR,SPRT_AND,SPRT_RPLC};
-extern void Sprite8(short,short,short,const unsigned char*,void*,short)__ATTR_LIB_C__;
-extern void Sprite16(short,short,short,__cpushort,void*,short)__ATTR_LIB_C__;
-extern void Sprite32(short,short,short,__cpulong,void*,short)__ATTR_LIB_C__;
+extern void Sprite8(short asm("d0"),short asm("d1"),short asm("d2"),const unsigned char* asm("a0"),void* asm("a1"),short asm("d3"))__ATTR_LIB_ASM__;
+extern void Sprite16(short asm("d0"),short asm("d1"),short asm("d2"),__cpushort asm("a0"),void* asm("a1"),short asm("d3"))__ATTR_LIB_ASM__;
+extern void Sprite32(short asm("d0"),short asm("d1"),short asm("d2"),__cpulong asm("a0"),void* asm("a1"),short asm("d3"))__ATTR_LIB_ASM__;
 /* End Auto-Generated Part */
 
 #endif

+ 2 - 2
tigcc/include/C/stdlib.h

@@ -41,7 +41,7 @@ void *alloca(long)__ATTR_GCC__;
 extern short atexit(atexit_t)__ATTR_LIB_ASM__;
 extern short atoi(const char*)__ATTR_LIB_C__;
 extern long atol(const char*)__ATTR_LIB_C__;
-extern void *bsearch(const void*,const void*,short,short,compare_t)__ATTR_LIB_C__;
+extern void *bsearch(const void* asm("a0"),const void* asm("a1"),short asm("d0"),short asm("d1"),compare_t asm("a2"))__ATTR_LIB_ASM__;
 #ifndef __HAVE_calloc
 #define __HAVE_calloc
 extern void *calloc(short asm("d0"),short asm("d1"))__ATTR_LIB_ASM__;
@@ -57,7 +57,7 @@ long labs(long)__ATTR_GCC__;
 #define malloc _rom_call(void*,(long),A2)
 #define max(a,b) ({typeof(a) __a = (a); typeof(b) __b = (b); (__a > __b) ? __a : __b;})
 #define min(a,b) ({typeof(a) __a = (a); typeof(b) __b = (b); (__a < __b) ? __a : __b;})
-extern void qsort(void*,short,short,compare_t)__ATTR_LIB_C__;
+extern void qsort(void* asm("a0"),short asm("d0"),short asm("d1"),compare_t asm("a2"))__ATTR_LIB_ASM__;
 extern short rand(void)__ATTR_LIB_ASM__;
 #define random(x) ((short)((long)(unsigned short)rand()*(unsigned short)(x)/32768))
 #define randomize() srand(*(volatile unsigned char*)0x600017)

+ 6 - 9
tigcc/include/C/unknown.h

@@ -272,7 +272,7 @@ typedef unsigned short unknown_retval;
 #define InitDEAxesRng _rom_call(unknown_retval,(),1E9)
 #define InitDEMem ({__need_in_use_bit;_rom_call(unknown_retval,(),1EA);})
 #define InitTimeSeq ({__need_in_use_bit;_rom_call(unknown_retval,(),1D9);})
-#define is_executable _rom_call(unknown_retval,(),25A)
+#define is_executable _rom_call(short,(CESI),25A)
 #define LoadSymFromFindHandle _rom_call(void,(void),281)
 #define NG_cleanup_graph_fun ({__need_in_use_bit;_rom_call(unknown_retval,(),262);})
 #define NG_setup_graph_fun ({__need_in_use_bit;_rom_call(unknown_retval,(),261);})
@@ -329,8 +329,6 @@ typedef unsigned short unknown_retval;
 #define get_matrix_indices _rom_call(unknown_retval,(),2B9)
 #define has_unit_base _rom_call(short,(ESI),3AF)
 #define index_after_match_endtag _rom_call(ESI,(ESI,char),2B1)
-#define init_list_indices _rom_call(unknown_retval,(),2BA)
-#define init_matrix_indices _rom_call(unknown_retval,(),2BB)
 #define init_unit_system _rom_call(unknown_retval,(),3B0)
 #define is_pathname _rom_call(short,(CESI),3C6)
 #define is_units_term _rom_call(short,(CESI),3B1)
@@ -338,17 +336,16 @@ typedef unsigned short unknown_retval;
 #define nonblank _rom_call(void,(void),3C8)
 #define push_ans_entry _rom_call(HANDLE,(CESI),2B0)
 #define push_auto_units_conversion ({__need_in_use_bit;_rom_call(unknown_retval,(),3B2);})
-#define push_float_qr_fact ({__need_in_use_bit;_rom_call(unknown_retval,(),2BC);})
-#define push_format ({__need_in_use_bit;_rom_call(unknown_retval,(),315);})
-#define push_lu_fact ({__need_in_use_bit;_rom_call(unknown_retval,(),2BD);})
-#define push_mrow_aux ({__need_in_use_bit;_rom_call(unknown_retval,(),31B);})
+#define push_float_qr_fact ({__need_in_use_bit;_rom_call(ESI,(ESI,float),2BC);})
+#define push_lu_fact ({__need_in_use_bit;_rom_call(ESI,(ESI,float),2BD);})
+#define push_mrow_aux ({__need_in_use_bit;_rom_call(void,(ESI,ESI,short,short),31B);})
 #define push_parse_prgm_or_func_text _rom_call(void,(const char*,ESI,short),3C9)
 #define push_sq_matrix_to_whole_number ({__need_in_use_bit;_rom_call(unknown_retval,(),3C0);})
-#define push_symbolic_qr_fact ({__need_in_use_bit;_rom_call(unknown_retval,(),2BE);})
+#define push_symbolic_qr_fact ({__need_in_use_bit;_rom_call(ESI,(ESI),2BE);})
 #define push_unit_system_list _rom_call(unknown_retval,(),3B3)
 #define push_user_func ({__need_in_use_bit;_rom_call(void,(ESI,short),2B3);})
 #define push_var _rom_call(void,(const char*,const char*),3CB)
-#define push_zero_partial_column _rom_call(unknown_retval,(),3C2)
+#define push_zero_partial_column _rom_call(void,(ESI,short,short),3C2)
 #define setup_unit_system _rom_call(unknown_retval,(),3B4)
 #define store_func_def ({__need_in_use_bit;_rom_call(void,(ESI),2B4);})
 #define store_to_subscripted_element ({__need_in_use_bit;_rom_call(void,(CESI,CESI),2B5);})