void DoMinus( void ) { stack_entry *left; left = StkEntry( 1 ); LRValue( left ); RValue( ExprSP ); AddOp( left, ExprSP ); switch( left->info.kind ) { case TK_BOOL: case TK_ENUM: case TK_CHAR: case TK_INTEGER: U64Sub( &left->v.uint, &ExprSP->v.uint, &left->v.uint ); left->info.modifier = TM_SIGNED; break; case TK_POINTER: case TK_ADDRESS: switch( ExprSP->info.kind ) { case TK_BOOL: case TK_CHAR: case TK_ENUM: case TK_INTEGER: //NYI: 64 bit offsets left->v.addr = AddrAdd( left->v.addr, -U32FetchTrunc( ExprSP->v.uint ) ); break; case TK_POINTER: case TK_ADDRESS: I32ToI64( AddrDiff( left->v.addr, ExprSP->v.addr ), &left->v.sint ); left->info.kind = TK_INTEGER; left->info.modifier = TM_SIGNED; left->info.size = sizeof( signed_64 ); left->th = NULL; break; default: Error( ERR_NONE, LIT_ENG( ERR_ILL_TYPE ) ); } break; case TK_REAL: LDSub( &left->v.real, &ExprSP->v.real, &left->v.real ); break; case TK_COMPLEX: LDSub( &left->v.cmplx.re, &ExprSP->v.cmplx.re, &left->v.cmplx.re ); LDSub( &left->v.cmplx.im, &ExprSP->v.cmplx.im, &left->v.cmplx.im ); break; default: Error( ERR_NONE, LIT_ENG( ERR_ILL_TYPE ) ); break; } CombineEntries( left, left, ExprSP ); }
int64 operator-( const int64 & a ) const { int64 res; U64Sub( &this->_d, &a._d, &res._d ); return( res ); }
static PTREE foldInt64( CGOP op, PTREE left, signed_64 v2 ) { signed_64 test; signed_64 v1; float_handle t0, t1, t2; v1 = left->u.int64_constant; switch( op ) { case CO_PLUS: U64Add( &v1, &v2, &left->u.int64_constant ); break; case CO_MINUS: U64Sub( &v1, &v2, &left->u.int64_constant ); break; case CO_TIMES: t0 = BFCnvI64F( v1 ); t1 = BFCnvI64F( v2 ); t2 = BFMul( t0, t1 ); test = BFCnvF64( t2 ); BFFree( t0 ); BFFree( t1 ); BFFree( t2 ); U64Mul( &v1, &v2, &left->u.int64_constant ); if( 0 != I64Cmp( &test, &left->u.int64_constant ) ) { CErr1( ANSI_ARITHMETIC_OVERFLOW ); } break; case CO_DIVIDE: { signed_64 rem; idiv64( &v1, &v2, &left->u.int64_constant, &rem ); } break; case CO_PERCENT: { signed_64 div; idiv64( &v1, &v2, &div, &left->u.int64_constant ); } break; case CO_AND: left->u.int64_constant.u._32[0] = v1.u._32[0] & v2.u._32[0]; left->u.int64_constant.u._32[1] = v1.u._32[1] & v2.u._32[1]; break; case CO_OR: left->u.int64_constant.u._32[0] = v1.u._32[0] | v2.u._32[0]; left->u.int64_constant.u._32[1] = v1.u._32[1] | v2.u._32[1]; break; case CO_XOR: left->u.int64_constant.u._32[0] = v1.u._32[0] ^ v2.u._32[0]; left->u.int64_constant.u._32[1] = v1.u._32[1] ^ v2.u._32[1]; break; case CO_RSHIFT: I64ShiftR( &v1, v2.u._32[ I64LO32 ], &left->u.int64_constant ); break; case CO_LSHIFT: U64ShiftL( &v1, v2.u._32[ I64LO32 ], &left->u.int64_constant ); break; case CO_EQ: left = makeBooleanConst( left, 0 == I64Cmp( &v1, &v2 ) ); return( left ); case CO_NE: left = makeBooleanConst( left, 0 != I64Cmp( &v1, &v2 ) ); return( left ); case CO_GT: left = makeBooleanConst( left, 0 < I64Cmp( &v1, &v2 )) ; return( left ); case CO_LE: left = makeBooleanConst( left, 0 >= I64Cmp( &v1, &v2 ) ); return( left ); case CO_LT: left = makeBooleanConst( left, 0 > I64Cmp( &v1, &v2 )) ; return( left ); case CO_GE: left = makeBooleanConst( left, 0 <= I64Cmp( &v1, &v2 ) ); return( left ); case CO_AND_AND: left = makeBooleanConst( left, !Zero64( &v1 ) && !Zero64( &v2 ) ); return( left ); case CO_OR_OR: left = makeBooleanConst( left, !Zero64( &v1) || !Zero64( &v2 ) ); return( left ); case CO_COMMA: left->u.int64_constant = v2; break; default: return( NULL ); } left->op = PT_INT_CONSTANT; return( left ); }
/* Take advantage of the SETcc instruction in cases such as * x = y ? 3 : 4; * by adding a constant to the result of SETcc to directly obtain * the result of the assignment. */ static bool FindFlowOut( block *blk ) { /*****************************************/ signed_64 false_cons; signed_64 true_cons; signed_64 one; signed_64 neg_one; signed_64 diff; instruction *ins; instruction *ins0; instruction *ins1; // instruction *prev; block *true_blk; block *false_blk; block *join_blk; block_edge *new_edge; bool reverse; name *u1temp; name *temp; name *result; name *konst; type_class_def class; for( ins = blk->ins.hd.prev; !_OpIsCondition( ins->head.opcode ); ) { ins = ins->head.prev; } // prev = ins->head.prev; if( TypeClassSize[ ins->type_class ] > WORD_SIZE ) return( FALSE ); true_blk = blk->edge[ _TrueIndex( ins ) ].destination.u.blk; if( true_blk->inputs != 1 ) return( FALSE ); if( true_blk->targets != 1 ) return( FALSE ); false_blk = blk->edge[ _FalseIndex( ins ) ].destination.u.blk; if( false_blk->inputs != 1 ) return( FALSE ); if( false_blk->targets != 1 ) return( FALSE ); join_blk = false_blk->edge[ 0 ].destination.u.blk; if( join_blk != true_blk->edge[ 0 ].destination.u.blk ) return( FALSE ); if( join_blk->inputs != 2 ) return( FALSE ); if( join_blk->class & UNKNOWN_DESTINATION ) return( FALSE ); ins0 = SetToConst( false_blk, &false_cons ); if( ins0 == NULL ) return( FALSE ); ins1 = SetToConst( true_blk, &true_cons ); if( ins1 == NULL ) return( FALSE ); I32ToI64( 1, &one ); I32ToI64( -1, &neg_one ); U64Sub( &true_cons, &false_cons, &diff ); if( U64Cmp( &diff, &neg_one ) == 0 ) { U64IncDec( &false_cons, -1 ); reverse = TRUE; } else { if( U64Cmp( &diff, &one ) != 0 ) return( FALSE ); reverse = FALSE; } result = ins0->result; if( result != ins1->result ) return( FALSE ); class = ins0->type_class; if( class != ins1->type_class ) return( FALSE ); if( reverse ) FlipCond( ins ); u1temp = AllocTemp( U1 ); temp = AllocTemp( class ); ins->result = u1temp; ins1 = MakeConvert( u1temp, temp, class, U1 ); SuffixIns( ins, ins1 ); ins = ins1; if( I64Test( &false_cons ) != 0 ) { konst = AllocS64Const( false_cons.u._32[I64LO32], false_cons.u._32[I64HI32] ); ins1 = MakeBinary( OP_ADD, temp, konst, result, class ); } else {