BINARY_SB(cmpeqb, "(%s == %s) ? (~0) : 0")
BINARY_SB(cmpgtsb, "(%s > %s) ? (~0) : 0")
UNARY_SB(copyb, "%s")
-UNARY_SB(loadb, "%s")
UNARY_SB(loadpb, "%s")
BINARY_SB(maxsb, "ORC_MAX(%s, %s)")
BINARY_UB(maxub, "ORC_MAX((orc_uint8)%s, (orc_uint8)%s)")
BINARY_SB(shrsb, "%s >> %s")
BINARY_UB(shrub, "((orc_uint8)%s) >> %s")
UNARY_SB(signb, "ORC_CLAMP(%s,-1,1)")
-UNARY_SB(storeb, "%s")
BINARY_SB(subb, "%s - %s")
BINARY_SB(subssb, "ORC_CLAMP_SB(%s - %s)")
BINARY_UB(subusb, "ORC_CLAMP_UB((orc_uint8)%s - (orc_uint8)%s)")
BINARY_SW(cmpeqw, "(%s == %s) ? (~0) : 0")
BINARY_SW(cmpgtsw, "(%s > %s) ? (~0) : 0")
UNARY_SW(copyw, "%s")
-UNARY_SW(loadw, "%s")
UNARY_SW(loadpw, "%s")
BINARY_SW(maxsw, "ORC_MAX(%s, %s)")
BINARY_UW(maxuw, "ORC_MAX((orc_uint16)%s, (orc_uint16)%s)")
BINARY_SW(shrsw, "%s >> %s")
BINARY_UW(shruw, "((orc_uint16)%s) >> %s")
UNARY_SW(signw, "ORC_CLAMP(%s,-1,1)")
-UNARY_SW(storew, "%s")
BINARY_SW(subw, "%s - %s")
BINARY_SW(subssw, "ORC_CLAMP_SW(%s - %s)")
BINARY_UW(subusw, "ORC_CLAMP_UW((orc_uint16)%s - (orc_uint16)%s)")
BINARY_SL(cmpeql, "(%s == %s) ? (~0) : 0")
BINARY_SL(cmpgtsl, "(%s > %s) ? (~0) : 0")
UNARY_SL(copyl, "%s")
-UNARY_SL(loadl, "%s")
UNARY_SL(loadpl, "%s")
BINARY_SL(maxsl, "ORC_MAX(%s, %s)")
BINARY_UL(maxul, "ORC_MAX((orc_uint32)%s, (orc_uint32)%s)")
BINARY_SL(shrsl, "%s >> %s")
BINARY_UL(shrul, "((orc_uint32)%s) >> %s")
UNARY_SL(signl, "ORC_CLAMP(%s,-1,1)")
-UNARY_SL(storel, "%s")
BINARY_SL(subl, "%s - %s")
BINARY_SL(subssl, "ORC_CLAMP_SL((orc_int64)%s - (orc_int64)%s)")
BINARY_UL(subusl, "ORC_CLAMP_UL((orc_int64)(orc_uint32)%s - (orc_int64)(orc_uint32)%s)")
memcpy (compiler->vars, program->vars,
ORC_N_VARIABLES * sizeof(OrcVariable));
+ memset (compiler->vars + ORC_N_VARIABLES, 0,
+ (ORC_N_COMPILER_VARIABLES - ORC_N_VARIABLES) * sizeof(OrcVariable));
compiler->n_temp_vars = program->n_temp_vars;
compiler->n_dup_vars = 0;
ORC_INFO("compiling for target \"%s\"", compiler->target->name);
compiler->target->compile (compiler);
- if (compiler->error) goto error;
+ if (compiler->error) {
+ compiler->result = ORC_COMPILE_RESULT_UNKNOWN_COMPILE;
+ goto error;
+ }
program->orccode = orc_code_new ();
program->orccode->exec = program->code_exec;
OrcInstruction *cinsn;
cinsn = compiler->insns + compiler->n_insns;
+ compiler->insn_flags[compiler->n_insns] |= ORC_INSN_FLAG_ADDED;
compiler->n_insns++;
if (var->size == 1) {
OrcInstruction *cinsn;
cinsn = compiler->insns + compiler->n_insns;
+ compiler->insn_flags[compiler->n_insns] |= ORC_INSN_FLAG_ADDED;
compiler->n_insns++;
if (var->size == 1) {
OrcInstruction *cinsn;
cinsn = compiler->insns + compiler->n_insns;
+ compiler->insn_flags[compiler->n_insns] |= ORC_INSN_FLAG_ADDED;
compiler->n_insns++;
if (var->size == 1) {
var->alloc = orc_compiler_allocate_register (compiler, TRUE);
compiler->insn_flags[i] |= ORC_INSN_FLAG_INVARIANT;
}
+
+ if (opcode->flags & ORC_STATIC_OPCODE_ITERATOR) {
+ compiler->has_iterator_opcode = TRUE;
+ }
}
if (compiler->alloc_loop_counter && !compiler->error) {
BINARY_SB(cmpgtsb, (a > b) ? (~0) : 0)
UNARY_SB(copyb, a)
UNARY_SB(loadb, a)
+UNARY_SB(loadoffb, a)
+UNARY_SB(loadupdb, a)
+UNARY_SB(loadupib, a)
UNARY_SB(loadpb, a)
BINARY_SB(maxsb, (a > b) ? a : b)
BINARY_UB(maxub, (a > b) ? a : b)
BINARY_SW(cmpgtsw, (a > b) ? (~0) : 0)
UNARY_SW(copyw, a)
UNARY_SW(loadw, a)
+UNARY_SW(loadoffw, a)
UNARY_SW(loadpw, a)
BINARY_SW(maxsw, (a > b) ? a : b)
BINARY_UW(maxuw, (a > b) ? a : b)
BINARY_SL(cmpgtsl, (a > b) ? (~0) : 0)
UNARY_SL(copyl, a)
UNARY_SL(loadl, a)
+UNARY_SL(loadoffl, a)
UNARY_SL(loadpl, a)
BINARY_SL(maxsl, (a > b) ? a : b)
BINARY_UL(maxul, ((orc_uint32)a > (orc_uint32)b) ? a : b)
{ "cmpgtsb", cmpgtsb, NULL, 0, { 1 }, { 1, 1 }, emulate_cmpgtsb },
{ "copyb", copyb, NULL, 0, { 1 }, { 1 }, emulate_copyb },
{ "loadb", loadb, NULL, ORC_STATIC_OPCODE_LOAD, { 1 }, { 1 }, emulate_loadb },
+ { "loadoffb", loadoffb, NULL, ORC_STATIC_OPCODE_LOAD|ORC_STATIC_OPCODE_SCALAR, { 1 }, { 1, 4 }, emulate_loadoffb },
+ { "loadupdb", loadupdb, NULL, ORC_STATIC_OPCODE_LOAD|ORC_STATIC_OPCODE_ITERATOR, { 1 }, { 1 }, emulate_loadupdb },
+ { "loadupib", loadupib, NULL, ORC_STATIC_OPCODE_LOAD|ORC_STATIC_OPCODE_ITERATOR, { 1 }, { 1 }, emulate_loadupib },
{ "loadpb", loadpb, NULL, ORC_STATIC_OPCODE_LOAD|ORC_STATIC_OPCODE_SCALAR|ORC_STATIC_OPCODE_INVARIANT, { 1 }, { 1 }, emulate_loadpb },
{ "maxsb", maxsb, NULL, 0, { 1 }, { 1, 1 }, emulate_maxsb },
{ "maxub", maxub, NULL, 0, { 1 }, { 1, 1 }, emulate_maxub },
{ "cmpgtsw", cmpgtsw, NULL, 0, { 2 }, { 2, 2 }, emulate_cmpgtsw },
{ "copyw", copyw, NULL, 0, { 2 }, { 2 }, emulate_copyw },
{ "loadw", loadw, NULL, ORC_STATIC_OPCODE_LOAD, { 2 }, { 2 }, emulate_loadw },
+ { "loadoffw", loadoffw, NULL, ORC_STATIC_OPCODE_LOAD|ORC_STATIC_OPCODE_SCALAR, { 2 }, { 2, 4 }, emulate_loadoffw },
{ "loadpw", loadpw, NULL, ORC_STATIC_OPCODE_LOAD|ORC_STATIC_OPCODE_SCALAR|ORC_STATIC_OPCODE_INVARIANT, { 2 }, { 2 }, emulate_loadpw },
{ "maxsw", maxsw, NULL, 0, { 2 }, { 2, 2 }, emulate_maxsw },
{ "maxuw", maxuw, NULL, 0, { 2 }, { 2, 2 }, emulate_maxuw },
{ "cmpgtsl", cmpgtsl, NULL, 0, { 4 }, { 4, 4 }, emulate_cmpgtsl },
{ "copyl", copyl, NULL, 0, { 4 }, { 4 }, emulate_copyl },
{ "loadl", loadl, NULL, ORC_STATIC_OPCODE_LOAD, { 4 }, { 4 }, emulate_loadl },
+ { "loadoffl", loadoffl, NULL, ORC_STATIC_OPCODE_LOAD|ORC_STATIC_OPCODE_SCALAR, { 4 }, { 4, 4 }, emulate_loadoffl },
{ "loadpl", loadpl, NULL, ORC_STATIC_OPCODE_LOAD|ORC_STATIC_OPCODE_SCALAR|ORC_STATIC_OPCODE_INVARIANT, { 4 }, { 4 }, emulate_loadpl },
{ "maxsl", maxsl, NULL, 0, { 4 }, { 4, 4 }, emulate_maxsl },
{ "maxul", maxul, NULL, 0, { 4 }, { 4, 4 }, emulate_maxul },
ORC_ASM_CODE(compiler,"{\n");
}
+#if 0
+ if (!(compiler->target_flags & ORC_TARGET_C_OPCODE)) {
+ ORC_ASM_CODE(compiler,"%*s int offset = 0;\n", prefix, "");
+ }
+#endif
ORC_ASM_CODE(compiler,"%*s int i;\n", prefix, "");
if (compiler->program->is_2d) {
ORC_ASM_CODE(compiler," int j;\n");
}
break;
case ORC_VAR_TYPE_TEMP:
- ORC_ASM_CODE(compiler," %s var%d;\n", c_get_type_name(var->size), i);
+ if (!(var->last_use == -1 && var->first_use == 0)) {
+ ORC_ASM_CODE(compiler," %s var%d;\n", c_get_type_name(var->size), i);
+ }
break;
case ORC_VAR_TYPE_SRC:
ORC_ASM_CODE(compiler," const %s *%s ptr%d;\n",
compiler->error = TRUE;
}
}
+#if 0
/* update pointers */
for(i=0;i<ORC_N_VARIABLES;i++){
OrcVariable *var = compiler->vars + i;
ORC_ASM_CODE (compiler, "%*s ptr%d++;\n", prefix, "", i);
}
}
+#endif
ORC_ASM_CODE(compiler,"%*s }\n", prefix, "");
if (compiler->program->is_2d) {
ORC_ASM_CODE(compiler," }\n");
static void
c_rule_loadX (OrcCompiler *p, void *user, OrcInstruction *insn)
{
- ORC_ASM_CODE(p," var%d = *ptr%d;\n", insn->dest_args[0],
+ if (p->insn_flags[insn-p->insns] & ORC_INSN_FLAG_ADDED) {
+ ORC_ASM_CODE(p," var%d = ptr%d[i];\n", insn->dest_args[0],
+ insn->src_args[0]);
+ } else {
+ ORC_ASM_CODE(p," var%d = ptr%d[offset + i];\n", insn->dest_args[0],
+ insn->src_args[0]);
+ }
+}
+
+static void
+c_rule_loadoffX (OrcCompiler *p, void *user, OrcInstruction *insn)
+{
+ ORC_ASM_CODE(p," var%d = ptr%d[offset + i+var%d];\n", insn->dest_args[0],
+ insn->src_args[0], insn->src_args[1]);
+}
+
+static void
+c_rule_loadupdb (OrcCompiler *p, void *user, OrcInstruction *insn)
+{
+ ORC_ASM_CODE(p," var%d = ptr%d[(offset + i)>>1];\n", insn->dest_args[0],
insn->src_args[0]);
}
static void
-c_rule_storeX (OrcCompiler *p, void *user, OrcInstruction *insn)
+c_rule_loadupib (OrcCompiler *p, void *user, OrcInstruction *insn)
{
- ORC_ASM_CODE(p," *ptr%d = var%d;\n", insn->dest_args[0],
+ ORC_ASM_CODE(p," var%d = ((offset + i)&1) ? (ptr%d[(offset + i)>>1] + ptr%d[((offset + i)>>1)+1] + 1)>>1 : ptr%d[(offset + i)>>1];\n",
+ insn->dest_args[0], insn->src_args[0], insn->src_args[0],
insn->src_args[0]);
}
static void
+c_rule_storeX (OrcCompiler *p, void *user, OrcInstruction *insn)
+{
+ if (p->insn_flags[insn-p->insns] & ORC_INSN_FLAG_ADDED) {
+ ORC_ASM_CODE(p," ptr%d[i] = var%d;\n", insn->dest_args[0],
+ insn->src_args[0]);
+ } else {
+ ORC_ASM_CODE(p," ptr%d[offset + i] = var%d;\n", insn->dest_args[0],
+ insn->src_args[0]);
+ }
+}
+
+static void
c_rule_accw (OrcCompiler *p, void *user, OrcInstruction *insn)
{
char dest[20], src1[20];
orc_rule_register (rule_set, "loadb", c_rule_loadX, NULL);
orc_rule_register (rule_set, "loadw", c_rule_loadX, NULL);
orc_rule_register (rule_set, "loadl", c_rule_loadX, NULL);
+ orc_rule_register (rule_set, "loadoffb", c_rule_loadoffX, NULL);
+ orc_rule_register (rule_set, "loadoffw", c_rule_loadoffX, NULL);
+ orc_rule_register (rule_set, "loadoffl", c_rule_loadoffX, NULL);
+ orc_rule_register (rule_set, "loadupdb", c_rule_loadupdb, NULL);
+ orc_rule_register (rule_set, "loadupib", c_rule_loadupib, NULL);
orc_rule_register (rule_set, "storeb", c_rule_storeX, NULL);
orc_rule_register (rule_set, "storew", c_rule_storeX, NULL);
orc_rule_register (rule_set, "storel", c_rule_storeX, NULL);
#define ORC_STATIC_OPCODE_LOAD (1<<4)
#define ORC_STATIC_OPCODE_STORE (1<<5)
#define ORC_STATIC_OPCODE_INVARIANT (1<<6)
+#define ORC_STATIC_OPCODE_ITERATOR (1<<7)
struct _OrcStaticOpcode {
int allow_gp_on_stack;
int loop_counter;
int size_region;
+ int has_iterator_opcode;
int offset;
};
-#define ORC_INSN_FLAG_INVARIANT 1
+#define ORC_INSN_FLAG_INVARIANT (1<<0)
+#define ORC_INSN_FLAG_ADDED (1<<1)
#define ORC_SRC_ARG(p,i,n) ((p)->vars[(i)->src_args[(n)]].alloc)
#define ORC_DEST_ARG(p,i,n) ((p)->vars[(i)->dest_args[(n)]].alloc)