comparison gen/asm-x86-64.h @ 962:a415d305477f

Fix 32 bit truncation of 'asm { movq RAX, 0xAA_1234_5678; }'...ie. move constant larger than 32 bits
author Kelly Wilson <wilsonk cpsc.ucalgary.ca>
date Sun, 15 Feb 2009 16:30:15 -0700
parents f33413a955fa
children fa21062b6948
comparison
equal deleted inserted replaced
961:f33413a955fa 962:a415d305477f
1710 { 1710 {
1711 if ( operand->constDisplacement < 0x100 ) 1711 if ( operand->constDisplacement < 0x100 )
1712 operand->dataSize = Byte_Ptr; 1712 operand->dataSize = Byte_Ptr;
1713 else if ( operand->constDisplacement < 0x10000 ) 1713 else if ( operand->constDisplacement < 0x10000 )
1714 operand->dataSize = Short_Ptr; 1714 operand->dataSize = Short_Ptr;
1715 else if ( operand->constDisplacement < 0x100000000 )
1716 operand->dataSize = Int_Ptr;
1715 else 1717 else
1716 operand->dataSize = Int_Ptr; 1718 //This could be possible since we are using 48 bits
1719 operand->dataSize = QWord_Ptr;
1717 } 1720 }
1718 return Opr_Immediate; 1721 return Opr_Immediate;
1719 } 1722 }
1720 1723
1721 // probably a bug,? 1724 // probably a bug,?
1756 switch ( ptrtype ) 1759 switch ( ptrtype )
1757 { 1760 {
1758 case Byte_Ptr: type_char = 'b'; break; 1761 case Byte_Ptr: type_char = 'b'; break;
1759 case Short_Ptr: type_char = 'w'; break; 1762 case Short_Ptr: type_char = 'w'; break;
1760 case Int_Ptr: type_char = 'l'; break; 1763 case Int_Ptr: type_char = 'l'; break;
1764 case QWord_Ptr: type_char = 'q'; break;
1761 default: 1765 default:
1762 // %% these may be too strict 1766 // %% these may be too strict
1763 return false; 1767 return false;
1764 } 1768 }
1765 break; 1769 break;
1823 min_type = Short_Ptr; 1827 min_type = Short_Ptr;
1824 break; 1828 break;
1825 case FP_Types: min_type = Float_Ptr; break; 1829 case FP_Types: min_type = Float_Ptr; break;
1826 } 1830 }
1827 if ( op == Op_push && operands[0].cls == Opr_Immediate ) 1831 if ( op == Op_push && operands[0].cls == Opr_Immediate )
1828 min_type = Int_Ptr; 1832 min_type = QWord_Ptr;
1829 1833
1830 for ( int i = 0; i < nOperands; i++ ) 1834 for ( int i = 0; i < nOperands; i++ )
1831 { 1835 {
1832 if ( hint_type == Default_Ptr && 1836 if ( hint_type == Default_Ptr &&
1833 ! ( opInfo->operands[i] & Opr_NoType ) ) 1837 ! ( opInfo->operands[i] & Opr_NoType ) )
2135 */ 2139 */
2136 2140
2137 if ( operand->indexReg == Reg_Invalid && 2141 if ( operand->indexReg == Reg_Invalid &&
2138 decl->isVarDeclaration() && 2142 decl->isVarDeclaration() &&
2139 ( ( ( operand->baseReg == Reg_EBP || ( operand->baseReg == Reg_RBP ) ) && ! sc->func->naked ) || 2143 ( ( ( operand->baseReg == Reg_EBP || ( operand->baseReg == Reg_RBP ) ) && ! sc->func->naked ) ||
2140 ( ( operand->baseReg == Reg_ESP || ( operand->baseReg == Reg_RSP ) ) && sc->func->naked ) ) ) 2144 ( ( operand->baseReg == Reg_ESP || ( operand->baseReg == Reg_RSP ) ) && ! sc->func->naked ) ) )
2141 { 2145 {
2142 2146
2143 if ( mode == Mode_Output ) 2147 if ( mode == Mode_Output )
2144 { 2148 {
2145 e = new AddrExp ( 0, e ); 2149 e = new AddrExp ( 0, e );
2153 2157
2154 if ( operand->constDisplacement ) 2158 if ( operand->constDisplacement )
2155 { 2159 {
2156 e = new AddExp ( 0, e, 2160 e = new AddExp ( 0, e,
2157 new IntegerExp ( 0, operand->constDisplacement, 2161 new IntegerExp ( 0, operand->constDisplacement,
2158 Type::tint32 ) ); 2162 Type::tint64 ) );
2159 e->type = decl->type->pointerTo(); 2163 e->type = decl->type->pointerTo();
2160 } 2164 }
2161 e = new PtrExp ( 0, e ); 2165 e = new PtrExp ( 0, e );
2162 e->type = decl->type; 2166 e->type = decl->type;
2163 #endif 2167 #endif
2295 IntegerExp * e = new IntegerExp ( regno ); 2299 IntegerExp * e = new IntegerExp ( regno );
2296 e->op = TOKmod; 2300 e->op = TOKmod;
2297 return e; 2301 return e;
2298 } 2302 }
2299 2303
2300 Expression * newIntExp ( int v /* %% type */ ) 2304 Expression * newIntExp ( long v /* %% type */ )
2301 { 2305 {
2302 // Only handles 32-bit numbers as this is IA-32. 2306 // Handle 64 bit ... incoming long may need to be 'long long' for Windows???
2303 return new IntegerExp ( stmt->loc, v, Type::tint32 ); 2307 return new IntegerExp ( stmt->loc, v, Type::tint64 );
2304 } 2308 }
2305 2309
2306 void slotExp ( Expression * exp ) 2310 void slotExp ( Expression * exp )
2307 { 2311 {
2308 /* 2312 /*
2674 switch ( tok->value ) 2678 switch ( tok->value )
2675 { 2679 {
2676 case TOKint8: return Byte_Ptr; 2680 case TOKint8: return Byte_Ptr;
2677 case TOKint16: return Short_Ptr; 2681 case TOKint16: return Short_Ptr;
2678 case TOKint32: return Int_Ptr; 2682 case TOKint32: return Int_Ptr;
2679 // 'long ptr' isn't accepted? 2683 case TOKint64: return QWord_Ptr;
2684 // 'long ptr' isn't accepted? (it is now for x64 - qword)
2680 case TOKfloat32: return Float_Ptr; 2685 case TOKfloat32: return Float_Ptr;
2681 case TOKfloat64: return Double_Ptr; 2686 case TOKfloat64: return Double_Ptr;
2682 case TOKfloat80: return Extended_Ptr; 2687 case TOKfloat80: return Extended_Ptr;
2683 case TOKidentifier: 2688 case TOKidentifier:
2684 for ( int i = 0; i < N_PtrNames; i++ ) 2689 for ( int i = 0; i < N_PtrNames; i++ )
2767 case TOKuns32v: 2772 case TOKuns32v:
2768 case TOKint64v: 2773 case TOKint64v:
2769 case TOKuns64v: 2774 case TOKuns64v:
2770 // semantic here? 2775 // semantic here?
2771 // %% for tok64 really should use 64bit type 2776 // %% for tok64 really should use 64bit type
2772 e = new IntegerExp ( stmt->loc, token->uns64value, Type::tint32 ); 2777 e = new IntegerExp ( stmt->loc, token->uns64value, Type::tint64 );
2773 nextToken(); 2778 nextToken();
2774 break; 2779 break;
2775 case TOKfloat32v: 2780 case TOKfloat32v:
2776 case TOKfloat64v: 2781 case TOKfloat64v:
2777 case TOKfloat80v: 2782 case TOKfloat80v: