altos: Shrink ao_add_task by rolling up a memset loop
authorKeith Packard <keithp@keithp.com>
Wed, 6 Jul 2011 20:49:05 +0000 (13:49 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 6 Jul 2011 20:51:18 +0000 (13:51 -0700)
This has a dramatic effect. By pulling the 'stack' variable into
registers it reduces the size of this function from 550 to 231 bytes.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/ao_task.c

index 35f34b491eef2a92d507756504cb47e8222c6ecc..7e34ed61be64e99cc24748b1e9c710d30a100851 100644 (file)
@@ -48,26 +48,31 @@ ao_add_task(__xdata struct ao_task * task, void (*start)(void), __code char *nam
         */
        stack = task->stack;
 
         */
        stack = task->stack;
 
-       *stack++ = ((uint16_t) start);
-       *stack++ = ((uint16_t) start) >> 8;
+       *stack++ = ((uint16_t) start);          /* 0 */
+       *stack++ = ((uint16_t) start) >> 8;     /* 1 */
 
        /* and the stuff saved by ao_switch */
 
        /* and the stuff saved by ao_switch */
-       *stack++ = 0;           /* acc */
-       *stack++ = 0x80;        /* IE */
-       *stack++ = 0;           /* DPL */
-       *stack++ = 0;           /* DPH */
-       *stack++ = 0;           /* B */
-       *stack++ = 0;           /* R2 */
-       *stack++ = 0;           /* R3 */
-       *stack++ = 0;           /* R4 */
-       *stack++ = 0;           /* R5 */
-       *stack++ = 0;           /* R6 */
-       *stack++ = 0;           /* R7 */
-       *stack++ = 0;           /* R0 */
-       *stack++ = 0;           /* R1 */
-       *stack++ = 0;           /* PSW */
-       *stack++ = 0;           /* BP */
-       task->stack_count = stack - task->stack;
+       *stack++ = 0;                           /* 2 acc */  
+       *stack++ = 0x80;                        /* 3 IE */
+
+       /*  4 DPL
+        *  5 DPH
+        *  6 B
+        *  7 R2
+        *  8 R3
+        *  9 R4
+        * 10 R5
+        * 11 R6
+        * 12 R7
+        * 13 R0
+        * 14 R1
+        * 15 PSW
+        * 16 BP
+        */
+       for (t = 0; t < 13; t++)
+               *stack++ = 0;
+
+       task->stack_count = 17;
        task->wchan = NULL;
 }
 
        task->wchan = NULL;
 }