added addtional nodes needed for psi transformation
[libfirm] / ir / be / ia32 / ia32_emitter.c
index 26bbb65..1540095 100644 (file)
@@ -334,7 +334,7 @@ const lc_arg_env_t *ia32_get_arg_env(void) {
        return env;
 }
 
-static char *ia32_get_reg_name_for_mode(ia32_emit_env_t *env, ir_mode *mode, const arch_register_t *reg) {
+static const char *ia32_get_reg_name_for_mode(ia32_emit_env_t *env, ir_mode *mode, const arch_register_t *reg) {
        switch(get_mode_size_bits(mode)) {
                case 8:
                        return ia32_get_mapped_reg_name(env->isa->regs_8bit, reg);
@@ -974,7 +974,7 @@ static void emit_ia32_x87CondJmp(ir_node *irn, ia32_emit_env_t *env) {
        finish_CondJmp(F, irn, mode_Is);
 }
 
-static void emit_ia32_CMov(ir_node *irn, ia32_emit_env_t *env) {
+static void CMov_emitter(ir_node *irn, ia32_emit_env_t *env) {
        FILE               *F       = env->out;
        const lc_arg_env_t *arg_env = ia32_get_arg_env();
        const char *cmp_suffix = get_cmp_suffix(get_ia32_pncode(irn), ! mode_is_signed(get_irn_mode(get_irn_n(irn, 0))));
@@ -989,7 +989,15 @@ static void emit_ia32_CMov(ir_node *irn, ia32_emit_env_t *env) {
 
        /* we have to emit the cmp first, because the destination register */
        /* could be one of the compare registers                           */
-       lc_esnprintf(arg_env, cmd_buf, SNPRINTF_BUF_LEN, "cmp %1S, %2S", irn, irn);
+       if (is_ia32_CMov(irn)) {
+               lc_esnprintf(arg_env, cmd_buf, SNPRINTF_BUF_LEN, "cmp %1S, %2S", irn, irn);
+       }
+       else if (is_ia32_xCmpCMov(irn)) {
+               lc_esnprintf(arg_env, cmd_buf, SNPRINTF_BUF_LEN, "ucomis%M %1S, %2S", get_irn_n(irn, 0), irn, irn);
+       }
+       else {
+               assert(0 && "unsupported CMov");
+       }
        lc_esnprintf(arg_env, cmnt_buf, SNPRINTF_BUF_LEN, "/* Psi condition */" );
        IA32_DO_EMIT(irn);
 
@@ -1017,7 +1025,15 @@ static void emit_ia32_CMov(ir_node *irn, ia32_emit_env_t *env) {
        IA32_DO_EMIT(irn);
 }
 
-static void emit_ia32_Set(ir_node *irn, ia32_emit_env_t *env) {
+static void emit_ia32_CMov(ir_node *irn, ia32_emit_env_t *env) {
+       CMov_emitter(irn, env);
+}
+
+static void emit_ia32_xCmpCMov(ir_node *irn, ia32_emit_env_t *env) {
+       CMov_emitter(irn, env);
+}
+
+static void Set_emitter(ir_node *irn, ia32_emit_env_t *env) {
        FILE               *F       = env->out;
        const lc_arg_env_t *arg_env = ia32_get_arg_env();
        const char *cmp_suffix = get_cmp_suffix(get_ia32_pncode(irn), ! mode_is_signed(get_irn_mode(get_irn_n(irn, 0))));
@@ -1040,7 +1056,15 @@ static void emit_ia32_Set(ir_node *irn, ia32_emit_env_t *env) {
        snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* clear target as set modifies only lower 8 bit */");
        IA32_DO_EMIT(irn);
 
-       lc_esnprintf(arg_env, cmd_buf, SNPRINTF_BUF_LEN, "cmp %1S, %2S", irn, irn);
+       if (is_ia32_Set(irn)) {
+               lc_esnprintf(arg_env, cmd_buf, SNPRINTF_BUF_LEN, "cmp %1S, %2S", irn, irn);
+       }
+       else if (is_ia32_xCmpSet(irn)) {
+               lc_esnprintf(arg_env, cmd_buf, SNPRINTF_BUF_LEN, "ucomis%M %1S, %2S", get_irn_n(irn, 0), irn, irn);
+       }
+       else {
+               assert(0 && "unsupported Set");
+       }
        snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* calculate Psi condition */" );
        IA32_DO_EMIT(irn);
 
@@ -1049,6 +1073,55 @@ static void emit_ia32_Set(ir_node *irn, ia32_emit_env_t *env) {
        IA32_DO_EMIT(irn);
 }
 
+static void emit_ia32_Set(ir_node *irn, ia32_emit_env_t *env) {
+       Set_emitter(irn, env);
+}
+
+static void emit_ia32_xCmpSet(ir_node *irn, ia32_emit_env_t *env) {
+       Set_emitter(irn, env);
+}
+
+static void emit_ia32_xCmp(ir_node *irn, ia32_emit_env_t *env) {
+       FILE               *F       = env->out;
+       const lc_arg_env_t *arg_env = ia32_get_arg_env();
+       int                sse_pnc  = -1;
+       char cmd_buf[SNPRINTF_BUF_LEN];
+       char cmnt_buf[SNPRINTF_BUF_LEN];
+
+       switch (get_ia32_pncode(irn)) {
+               case pn_Cmp_Leg: /* odered */
+                       sse_pnc = 7;
+                       break;
+               case pn_Cmp_Uo:  /* unordered */
+                       sse_pnc = 3;
+                       break;
+               case pn_Cmp_Ue:  /* == */
+                       sse_pnc = 0;
+                       break;
+               case pn_Cmp_Ul:  /* < */
+                       sse_pnc = 1;
+                       break;
+               case pn_Cmp_Ule: /* <= */
+                       sse_pnc = 2;
+                       break;
+               case pn_Cmp_Ug:  /* > */
+                       sse_pnc = 6;
+                       break;
+               case pn_Cmp_Uge: /* >= */
+                       sse_pnc = 5;
+                       break;
+               case pn_Cmp_Ne:  /* != */
+                       sse_pnc = 4;
+                       break;
+       }
+
+       assert(sse_pnc >= 0 && "unsupported floating point compare");
+
+       lc_esnprintf(arg_env, cmd_buf, SNPRINTF_BUF_LEN, "cmps%M %s, %d", irn, ia32_emit_binop(irn, env), sse_pnc);
+       lc_esnprintf(arg_env, cmnt_buf, SNPRINTF_BUF_LEN, "/* SSE compare with result in %1D */", irn);
+       IA32_DO_EMIT(irn);
+}
+
 /*********************************************************
  *                 _ _       _
  *                (_) |     (_)
@@ -1643,6 +1716,9 @@ static void ia32_register_emitters(void) {
        IA32_EMIT(Conv_I2I);
        IA32_EMIT(Conv_I2I8Bit);
        IA32_EMIT(Const);
+       IA32_EMIT(xCmp);
+       IA32_EMIT(xCmpSet);
+       IA32_EMIT(xCmpCMov);
        IA32_EMIT2(fcomJmp, x87CondJmp);
        IA32_EMIT2(fcompJmp, x87CondJmp);
        IA32_EMIT2(fcomppJmp, x87CondJmp);