[Cbe-oss-dev] [PATCH 23/28]MARS/task: module reduce code size

Yuji Mano yuji.mano at am.sony.com
Fri Feb 6 13:32:58 EST 2009


This removes dependency on memset and memcpy routines to reduce code size by
about 300 bytes.

This also removes an unnecessary error check to reduce code size by a few bytes.

Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>
---
 task/src/mpu/module/task_module.c |   68 ++++++++++++++++++--------------------
 1 file changed, 33 insertions(+), 35 deletions(-)

--- a/task/src/mpu/module/task_module.c
+++ b/task/src/mpu/module/task_module.c
@@ -35,9 +35,6 @@
  * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 #include <spu_mfcio.h>
 
 #include <mars/dma.h>
@@ -375,25 +372,16 @@ static int task_schedule(uint16_t worklo
 	/* initialize task specific context variables */
 	schedule_task->stack = 0;
 	if (args)
-		memcpy(&schedule_task->args, args,
-		       sizeof(struct mars_task_args));
+		schedule_task->args = *args;
 
 	/* end process to schedule the workload in the workload queue */
-	ret = mars_module_workload_schedule_end(workload_id);
-	if (ret != MARS_SUCCESS)
-		return ret;
-
-	return MARS_SUCCESS;
+	return mars_module_workload_schedule_end(workload_id);
 }
 
 static int task_wait(uint16_t workload_id, void *task_heap)
 {
 	int ret;
 
-	/* make sure workload is initialized */
-	if (!mars_module_workload_query(workload_id, MARS_QUERY_IS_INITIALIZED))
-		return MARS_ERROR_STATE;
-
 	ret = mars_module_workload_wait_set(workload_id);
 	if (ret != MARS_SUCCESS)
 		return ret;
@@ -461,36 +449,46 @@ static struct mars_task_module_syscalls 
 	task_signal_try_wait
 };
 
+static void context_start(void)
+{
+	__vector unsigned char *bss_ptr, *bss_end;
+
+	/* 0 the bss section */
+	bss_ptr = (__vector unsigned char *)
+			(MARS_TASK_BASE_ADDR + task->exec_size);
+	bss_end = (__vector unsigned char *)
+			((void *)bss_ptr + task->bss_size);
+
+	while (bss_ptr < bss_end)
+		*bss_ptr++ = spu_splats((unsigned char)0);
+
+	/* dma the text and data section */
+	dma_large((void *)MARS_TASK_BASE_ADDR,
+		  task->exec_ea, task->exec_size, 0);
+	dma_wait();
+
+	/* sync before executing loaded code */
+	spu_sync();
+
+	/* call entry function */
+	((mars_task_entry)task->entry)(&task->args, &task_module_syscalls);
+}
+
 void mars_module_main(void)
 {
 	register void *sp asm("$sp");
 
-	/* get task context */
-	task = get_task();
-
 	/* save module stack pointer */
 	__module_stack = sp;
 
+	/* get task context */
+	task = get_task();
+
 	/* if stack pointer is uninitialized run fresh, otherwise resume */
-	if (!task->stack) {
-		/* dma the exec code into mpu storage from host storage */
-		dma_large((void *)MARS_TASK_BASE_ADDR,
-			  task->exec_ea, task->exec_size, 0);
-		dma_wait();
-
-		/* 0 the bss section */
-		memset((void *)MARS_TASK_BASE_ADDR + task->exec_size, 0,
-		       task->bss_size);
-
-		/* sync before executing loaded code */
-		spu_sync();
-
-		/* call entry function */
-		((mars_task_entry)task->entry)(
-			&task->args, &task_module_syscalls);
-	} else {
+	if (!task->stack)
+		context_start();
+	else
 		context_resume();
-	}
 
 	/* we should never reach here */
 }







More information about the cbe-oss-dev mailing list