instrrules.c
// Comparison and assignment/jump rules for floating point numbers
Comparison and assignment/jump rules for floating point numbers
Comparison and assignment / jump rules for floating point numbers
static void add_long_double_comp_rules(int *ntc, int src1, int src2, char *src1_template, char *src2_template) {
    add_long_double_comp_assignment_rule(src1, src2, src1_template, src2_template, IR_LT, X_SETA,  "seta %vdb", 1);
    add_long_double_comp_assignment_rule(src1, src2, src1_template, src2_template, IR_GT, X_SETA,  "seta %vdb", 0);
    add_long_double_comp_assignment_rule(src1, src2, src1_template, src2_template, IR_LE, X_SETAE, "setae %vdb", 1);
    add_long_double_comp_assignment_rule(src1, src2, src1_template, src2_template, IR_GE, X_SETAE, "setae %vdb", 0);
    for (int i = 0; i < 2; i++) {
        Rule *r = add_rule(RI3, i == 0 ? IR_EQ : IR_NE, src1, src2, 15);
        add_long_double_comparison_instructions(r, src1, src2, src1_template, src2_template, "fucomip %%st(1), %%st", 1);
        add_op(r, X_CMP, DST, 0, 0, i == 0 ? "setnp %vdb" : "setp %vdb");
        add_op(r, X_LD_EQ_CMP, 0, 0, 0,  i == 0 ? "movl $0, %%edx" : "movl $1, %%edx");
        add_long_double_comparison_instructions(r, src1, src2, src1_template, src2_template, "fucomip %%st(1), %%st", 1);
        add_op(r, X_MOVC, DST, 0, 0, "cmovne %%edx, %vdl");
        add_op(r, X_MOVZ, DST, 0, 0, "movzbl %vdb, %vdl");
    }
    add_long_double_comp_cond_jmp_rule(ntc, src1, src2, src1_template, src2_template, IR_LT, X_JA,  "ja %v1" , X_JAE, "jbe %v1", 1);
    add_long_double_comp_cond_jmp_rule(ntc, src1, src2, src1_template, src2_template, IR_GT, X_JA,  "ja %v1",  X_JBE, "jbe %v1", 0);
    add_long_double_comp_cond_jmp_rule(ntc, src1, src2, src1_template, src2_template, IR_LE, X_JAE, "jae %v1", X_JA,  "jb %v1", 1);
    add_long_double_comp_cond_jmp_rule(ntc, src1, src2, src1_template, src2_template, IR_GE, X_JAE, "jae %v1", X_JB,  "jb %v1", 0);
}
static void add_long_double_comp_rules ( int * ntc , int src1 , int src2 , char * src1_template , char * src2_template ) { add_long_double_comp_assignment_rule ( src1 , src2 , src1_template , src2_template , IR_LT , X_SETA , " " , 1 ) ; add_long_double_comp_assignment_rule ( src1 , src2 , src1_template , src2_template , IR_GT , X_SETA , " " , 0 ) ; add_long_double_comp_assignment_rule ( src1 , src2 , src1_template , src2_template , IR_LE , X_SETAE , " " , 1 ) ; add_long_double_comp_assignment_rule ( src1 , src2 , src1_template , src2_template , IR_GE , X_SETAE , " " , 0 ) ; for ( int i = 0 ; i < 2 ; i ++ ) { Rule * r = add_rule ( RI3 , i == 0 ? IR_EQ : IR_NE , src1 , src2 , 15 ) ; add_long_double_comparison_instructions ( r , src1 , src2 , src1_template , src2_template , " " , 1 ) ; add_op ( r , X_CMP , DST , 0 , 0 , i == 0 ? " " : " " ) ; add_op ( r , X_LD_EQ_CMP , 0 , 0 , 0 , i == 0 ? " " : " " ) ; add_long_double_comparison_instructions ( r , src1 , src2 , src1_template , src2_template , " " , 1 ) ; add_op ( r , X_MOVC , DST , 0 , 0 , " " ) ; add_op ( r , X_MOVZ , DST , 0 , 0 , " " ) ; } add_long_double_comp_cond_jmp_rule ( ntc , src1 , src2 , src1_template , src2_template , IR_LT , X_JA , " " , X_JAE , " " , 1 ) ; add_long_double_comp_cond_jmp_rule ( ntc , src1 , src2 , src1_template , src2_template , IR_GT , X_JA , " " , X_JBE , " " , 0 ) ; add_long_double_comp_cond_jmp_rule ( ntc , src1 , src2 , src1_template , src2_template , IR_LE , X_JAE , " " , X_JA , " " , 1 ) ; add_long_double_comp_cond_jmp_rule ( ntc , src1 , src2 , src1_template , src2_template , IR_GE , X_JAE , " " , X_JB , " " , 0 ) ; }
Comparison and assignment/jump rules for floating point numbers
Comparison and assignment / jump rules for floating point numbers
// == and != comparison assignments // No rules are added for conditional jumps, for simplicty. // Inspired by the code that gcc generates