From: David Schleef Date: Tue, 7 Apr 2009 22:57:48 +0000 (-0700) Subject: Move toward static array indexes X-Git-Tag: orc-0.4.0~50 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b9a27925bc463e5b7767fc7c34395a026dbaa1b7;p=platform%2Fupstream%2Forc.git Move toward static array indexes --- diff --git a/orc-test/orctest.c b/orc-test/orctest.c index 6eea796..0ffa209 100644 --- a/orc-test/orctest.c +++ b/orc-test/orctest.c @@ -137,7 +137,9 @@ orc_test_compare_output (OrcProgram *program) orc_executor_set_n (ex, n); dest_index = -1; - for(i=0;in_vars;i++){ + for(i=0;ivars[i].name == NULL) continue; + if (program->vars[i].vartype == ORC_VAR_TYPE_SRC) { uint8_t *data; data = malloc(n*program->vars[i].size); @@ -171,7 +173,8 @@ orc_test_compare_output (OrcProgram *program) printf("%2d:", i); - for(j=0;jn_vars;j++){ + for(j=0;jvars[j].name == NULL) continue; if (program->vars[j].vartype == ORC_VAR_TYPE_SRC && program->vars[j].size > 0) { print_array_val (ex->arrays[j], program->vars[j].size, i); diff --git a/orc/orccompiler.c b/orc/orccompiler.c index 653d21c..a62c384 100644 --- a/orc/orccompiler.c +++ b/orc/orccompiler.c @@ -75,8 +75,8 @@ orc_program_compile_for_target (OrcProgram *program, OrcTarget *target) compiler->n_insns = program->n_insns; memcpy (compiler->vars, program->vars, - program->n_vars * sizeof(OrcVariable)); - compiler->n_vars = program->n_vars; + ORC_N_VARIABLES * sizeof(OrcVariable)); + compiler->n_temp_vars = program->n_temp_vars; for(i=0;i<32;i++) { compiler->valid_regs[i] = 1; @@ -257,8 +257,9 @@ orc_compiler_global_reg_alloc (OrcCompiler *compiler) OrcVariable *var; - for(i=0;in_vars;i++){ + for(i=0;ivars + i; + if (var->name == NULL) continue; switch (var->vartype) { case ORC_VAR_TYPE_CONST: var->first_use = -1; @@ -346,14 +347,16 @@ orc_compiler_rewrite_vars2 (OrcCompiler *compiler) } } - for(i=0;in_vars;i++){ + for(i=0;ivars[i].name == NULL) continue; if (compiler->vars[i].first_use == j) { if (compiler->vars[i].alloc) continue; k = orc_compiler_allocate_register (compiler, TRUE); compiler->vars[i].alloc = k; } } - for(i=0;in_vars;i++){ + for(i=0;ivars[i].name == NULL) continue; if (compiler->vars[i].last_use == j) { compiler->alloc_regs[compiler->vars[i].alloc]--; } @@ -365,13 +368,13 @@ orc_compiler_rewrite_vars2 (OrcCompiler *compiler) int orc_compiler_dup_temporary (OrcCompiler *compiler, int var, int j) { - int i = compiler->n_vars; + int i = ORC_VAR_T1 + compiler->n_temp_vars; compiler->vars[i].vartype = ORC_VAR_TYPE_TEMP; compiler->vars[i].size = compiler->vars[var].size; compiler->vars[i].name = malloc (strlen(compiler->vars[var].name) + 10); sprintf(compiler->vars[i].name, "%s.dup%d", compiler->vars[var].name, j); - compiler->n_vars++; + compiler->n_temp_vars++; return i; } diff --git a/orc/orcopcodes.c b/orc/orcopcodes.c index 763c5ae..c8c0a8c 100644 --- a/orc/orcopcodes.c +++ b/orc/orcopcodes.c @@ -254,13 +254,13 @@ convsuswb (OrcOpcodeExecutor *ex, void *user) static void convusswb (OrcOpcodeExecutor *ex, void *user) { - ex->dest_values[0] = ORC_CLAMP_SB((uint16_t)(ex->src_values[0])); + ex->dest_values[0] = ORC_CLAMP_SB((int)(uint16_t)(ex->src_values[0])); } static void convuuswb (OrcOpcodeExecutor *ex, void *user) { - ex->dest_values[0] = ORC_CLAMP_UB((uint16_t)(ex->src_values[0])); + ex->dest_values[0] = ORC_CLAMP_UB((int)(uint16_t)(ex->src_values[0])); } static void diff --git a/orc/orcprogram-arm.c b/orc/orcprogram-arm.c index 596fa89..f9ccee7 100644 --- a/orc/orcprogram-arm.c +++ b/orc/orcprogram-arm.c @@ -133,7 +133,8 @@ void arm_load_constants (OrcCompiler *compiler) { int i; - for(i=0;in_vars;i++){ + for(i=0;ivars[i].name == NULL) continue; switch (compiler->vars[i].vartype) { case ORC_VAR_TYPE_CONST: //arm_emit_loadiw (compiler, compiler->vars[i].alloc, @@ -333,7 +334,8 @@ arm_emit_loop (OrcCompiler *compiler) } } - for(k=0;kn_vars;k++){ + for(k=0;kvars[k].name == NULL) continue; if (compiler->vars[k].vartype == ORC_VAR_TYPE_SRC || compiler->vars[k].vartype == ORC_VAR_TYPE_DEST) { if (compiler->vars[k].ptr_register) { diff --git a/orc/orcprogram-c.c b/orc/orcprogram-c.c index 5c72e9a..71234b5 100644 --- a/orc/orcprogram-c.c +++ b/orc/orcprogram-c.c @@ -84,8 +84,9 @@ orc_compiler_c_assemble (OrcCompiler *compiler) ORC_ASM_CODE(compiler,"{\n"); ORC_ASM_CODE(compiler," int i;\n"); - for(i=0;in_vars;i++){ + for(i=0;ivars + i; + if (var->name == NULL) continue; switch (var->vartype) { case ORC_VAR_TYPE_CONST: ORC_ASM_CODE(compiler," %s var%d = %d;\n", diff --git a/orc/orcprogram-mmx.c b/orc/orcprogram-mmx.c index d5b3827..50ec707 100644 --- a/orc/orcprogram-mmx.c +++ b/orc/orcprogram-mmx.c @@ -96,7 +96,8 @@ void mmx_load_constants (OrcCompiler *compiler) { int i; - for(i=0;in_vars;i++){ + for(i=0;ivars[i].name == NULL) continue; switch (compiler->vars[i].vartype) { case ORC_VAR_TYPE_CONST: mmx_emit_loadiw (compiler, compiler->vars[i].alloc, @@ -311,7 +312,8 @@ mmx_emit_loop (OrcCompiler *compiler) } } - for(k=0;kn_vars;k++){ + for(k=0;kvars[k].name == NULL) continue; if (compiler->vars[k].vartype == ORC_VAR_TYPE_SRC || compiler->vars[k].vartype == ORC_VAR_TYPE_DEST) { if (compiler->vars[k].ptr_register) { diff --git a/orc/orcprogram-powerpc.c b/orc/orcprogram-powerpc.c index 52ffe68..3bfa698 100644 --- a/orc/orcprogram-powerpc.c +++ b/orc/orcprogram-powerpc.c @@ -364,7 +364,8 @@ void powerpc_load_constants (OrcCompiler *compiler) { int i; - for(i=0;in_vars;i++){ + for(i=0;ivars[i].name == NULL) continue; switch (compiler->vars[i].vartype) { case ORC_VAR_TYPE_CONST: ORC_ASM_CODE(compiler," vspltish %s, %d\n", @@ -547,7 +548,8 @@ orc_compiler_powerpc_assemble (OrcCompiler *compiler) } } - for(k=0;kn_vars;k++){ + for(k=0;kvars[k].name == NULL) continue; if (compiler->vars[k].vartype == ORC_VAR_TYPE_SRC || compiler->vars[k].vartype == ORC_VAR_TYPE_DEST) { if (compiler->vars[k].ptr_register) { diff --git a/orc/orcprogram-sse.c b/orc/orcprogram-sse.c index 5d94a34..da2e723 100644 --- a/orc/orcprogram-sse.c +++ b/orc/orcprogram-sse.c @@ -109,14 +109,15 @@ orc_compiler_sse_init (OrcCompiler *compiler) break; } - compiler->long_jumps = TRUE; + //compiler->long_jumps = TRUE; } void sse_load_constants (OrcCompiler *compiler) { int i; - for(i=0;in_vars;i++){ + for(i=0;ivars[i].name == NULL) continue; switch (compiler->vars[i].vartype) { case ORC_VAR_TYPE_CONST: if (compiler->vars[i].size == 1) { @@ -471,7 +472,8 @@ sse_emit_loop (OrcCompiler *compiler) } } - for(k=0;kn_vars;k++){ + for(k=0;kvars[k].name == NULL) continue; if (compiler->vars[k].vartype == ORC_VAR_TYPE_SRC || compiler->vars[k].vartype == ORC_VAR_TYPE_DEST) { if (compiler->vars[k].ptr_register) { diff --git a/orc/orcprogram.c b/orc/orcprogram.c index 2a0fd5f..2156639 100644 --- a/orc/orcprogram.c +++ b/orc/orcprogram.c @@ -55,8 +55,8 @@ void orc_program_free (OrcProgram *program) { int i; - for(i=0;in_vars;i++){ - free (program->vars[i].name); + for(i=0;ivars[i].name) free (program->vars[i].name); } if (program->name) { free (program->name); @@ -82,12 +82,12 @@ orc_program_get_name (OrcProgram *program) int orc_program_add_temporary (OrcProgram *program, int size, const char *name) { - int i = program->n_vars; + int i = ORC_VAR_T1 + program->n_temp_vars; program->vars[i].vartype = ORC_VAR_TYPE_TEMP; program->vars[i].size = size; program->vars[i].name = strdup(name); - program->n_vars++; + program->n_temp_vars++; return i; } @@ -95,13 +95,13 @@ orc_program_add_temporary (OrcProgram *program, int size, const char *name) int orc_program_dup_temporary (OrcProgram *program, int var, int j) { - int i = program->n_vars; + int i = ORC_VAR_T1 + program->n_temp_vars; program->vars[i].vartype = ORC_VAR_TYPE_TEMP; program->vars[i].size = program->vars[var].size; program->vars[i].name = malloc (strlen(program->vars[var].name) + 10); sprintf(program->vars[i].name, "%s.dup%d", program->vars[var].name, j); - program->n_vars++; + program->n_temp_vars++; return i; } @@ -109,12 +109,12 @@ orc_program_dup_temporary (OrcProgram *program, int var, int j) int orc_program_add_source (OrcProgram *program, int size, const char *name) { - int i = program->n_vars; + int i = ORC_VAR_S1 + program->n_src_vars; program->vars[i].vartype = ORC_VAR_TYPE_SRC; program->vars[i].size = size; program->vars[i].name = strdup(name); - program->n_vars++; + program->n_src_vars++; return i; } @@ -122,12 +122,12 @@ orc_program_add_source (OrcProgram *program, int size, const char *name) int orc_program_add_destination (OrcProgram *program, int size, const char *name) { - int i = program->n_vars; + int i = ORC_VAR_D1 + program->n_dest_vars; program->vars[i].vartype = ORC_VAR_TYPE_DEST; program->vars[i].size = size; program->vars[i].name = strdup(name); - program->n_vars++; + program->n_dest_vars++; return i; } @@ -135,13 +135,13 @@ orc_program_add_destination (OrcProgram *program, int size, const char *name) int orc_program_add_constant (OrcProgram *program, int size, int value, const char *name) { - int i = program->n_vars; + int i = ORC_VAR_C1 + program->n_const_vars; program->vars[i].vartype = ORC_VAR_TYPE_CONST; program->vars[i].size = size; program->vars[i].value = value; program->vars[i].name = strdup(name); - program->n_vars++; + program->n_const_vars++; return i; } @@ -149,12 +149,12 @@ orc_program_add_constant (OrcProgram *program, int size, int value, const char * int orc_program_add_parameter (OrcProgram *program, int size, const char *name) { - int i = program->n_vars; + int i = ORC_VAR_P1 + program->n_param_vars; program->vars[i].vartype = ORC_VAR_TYPE_PARAM; program->vars[i].size = size; program->vars[i].name = strdup(name); - program->n_vars++; + program->n_param_vars++; return i; } @@ -201,8 +201,8 @@ orc_program_find_var_by_name (OrcProgram *program, const char *name) { int i; - for(i=0;in_vars;i++){ - if (strcmp (program->vars[i].name, name) == 0) { + for(i=0;ivars[i].name && strcmp (program->vars[i].name, name) == 0) { return i; } } @@ -215,8 +215,9 @@ orc_compiler_get_dest (OrcCompiler *compiler) { int k; - for(k=0;kn_vars;k++){ - if (compiler->vars[k].vartype == ORC_VAR_TYPE_DEST) { + for(k=0;kvars[k].name && + compiler->vars[k].vartype == ORC_VAR_TYPE_DEST) { return k; } } @@ -275,8 +276,10 @@ orc_program_get_max_var_size (OrcProgram *program) int max; max = 0; - for(i=0;in_vars;i++){ - max = MAX(max, program->vars[i].size); + for(i=0;ivars[i].size) { + max = MAX(max, program->vars[i].size); + } } return max; diff --git a/orc/orcprogram.h b/orc/orcprogram.h index 6dda47a..1045ee2 100644 --- a/orc/orcprogram.h +++ b/orc/orcprogram.h @@ -81,6 +81,45 @@ typedef enum { ORC_VAR_TYPE_PARAM } OrcVarType; +enum { + ORC_VAR_D1, + ORC_VAR_D2, + ORC_VAR_D3, + ORC_VAR_D4, + ORC_VAR_S1, + ORC_VAR_S2, + ORC_VAR_S3, + ORC_VAR_S4, + ORC_VAR_S5, + ORC_VAR_S6, + ORC_VAR_S7, + ORC_VAR_S8, + ORC_VAR_C1, + ORC_VAR_C2, + ORC_VAR_C3, + ORC_VAR_C4, + ORC_VAR_C5, + ORC_VAR_C6, + ORC_VAR_C7, + ORC_VAR_C8, + ORC_VAR_P1, + ORC_VAR_P2, + ORC_VAR_P3, + ORC_VAR_P4, + ORC_VAR_P5, + ORC_VAR_P6, + ORC_VAR_P7, + ORC_VAR_P8, + ORC_VAR_T1, + ORC_VAR_T2, + ORC_VAR_T3, + ORC_VAR_T4, + ORC_VAR_T5, + ORC_VAR_T6, + ORC_VAR_T7, + ORC_VAR_T8 +}; + struct _OrcVariable { char *name; @@ -151,7 +190,12 @@ struct _OrcProgram { int n_insns; OrcVariable vars[ORC_N_VARIABLES]; - int n_vars; + //int n_vars; + int n_src_vars; + int n_dest_vars; + int n_param_vars; + int n_const_vars; + int n_temp_vars; char *name; char *asm_code; @@ -169,7 +213,8 @@ struct _OrcCompiler { int n_insns; OrcVariable vars[ORC_N_VARIABLES]; - int n_vars; + //int n_vars; + int n_temp_vars; unsigned char *codeptr;