comparison src/cpu/sparc/vm/assembler_sparc.hpp @ 3839:3d42f82cd811

7063628: Use cbcond on T4 Summary: Add new short branch instruction to Hotspot sparc assembler. Reviewed-by: never, twisti, jrose
author kvn
date Thu, 21 Jul 2011 11:25:07 -0700
parents faa472957b38
children 95134e034042
comparison
equal deleted inserted replaced
3838:6a991dcb52bb 3839:3d42f82cd811
759 mstosw_opf = 0x113, 759 mstosw_opf = 0x113,
760 mxtod_opf = 0x118, 760 mxtod_opf = 0x118,
761 mwtos_opf = 0x119 761 mwtos_opf = 0x119
762 }; 762 };
763 763
764 enum RCondition { rc_z = 1, rc_lez = 2, rc_lz = 3, rc_nz = 5, rc_gz = 6, rc_gez = 7 }; 764 enum RCondition { rc_z = 1, rc_lez = 2, rc_lz = 3, rc_nz = 5, rc_gz = 6, rc_gez = 7, rc_last = rc_gez };
765 765
766 enum Condition { 766 enum Condition {
767 // for FBfcc & FBPfcc instruction 767 // for FBfcc & FBPfcc instruction
768 f_never = 0, 768 f_never = 0,
769 f_notEqual = 1, 769 f_notEqual = 1,
864 static bool is_in_wdisp_range(address a, address b, int nbits) { 864 static bool is_in_wdisp_range(address a, address b, int nbits) {
865 intptr_t d = intptr_t(b) - intptr_t(a); 865 intptr_t d = intptr_t(b) - intptr_t(a);
866 return is_simm(d, nbits + 2); 866 return is_simm(d, nbits + 2);
867 } 867 }
868 868
869 address target_distance(Label& L) {
870 // Assembler::target(L) should be called only when
871 // a branch instruction is emitted since non-bound
872 // labels record current pc() as a branch address.
873 if (L.is_bound()) return target(L);
874 // Return current address for non-bound labels.
875 return pc();
876 }
877
869 // test if label is in simm16 range in words (wdisp16). 878 // test if label is in simm16 range in words (wdisp16).
870 bool is_in_wdisp16_range(Label& L) { 879 bool is_in_wdisp16_range(Label& L) {
871 return is_in_wdisp_range(target(L), pc(), 16); 880 return is_in_wdisp_range(target_distance(L), pc(), 16);
872 } 881 }
873 // test if the distance between two addresses fits in simm30 range in words 882 // test if the distance between two addresses fits in simm30 range in words
874 static bool is_in_wdisp30_range(address a, address b) { 883 static bool is_in_wdisp30_range(address a, address b) {
875 return is_in_wdisp_range(a, b, 30); 884 return is_in_wdisp_range(a, b, 30);
876 } 885 }
973 static int opf_low5( int w) { return u_field(w, 9, 5); } 982 static int opf_low5( int w) { return u_field(w, 9, 5); }
974 static int trapcc( CC cc) { return u_field(cc, 12, 11); } 983 static int trapcc( CC cc) { return u_field(cc, 12, 11); }
975 static int sx( int i) { return u_field(i, 12, 12); } // shift x=1 means 64-bit 984 static int sx( int i) { return u_field(i, 12, 12); } // shift x=1 means 64-bit
976 static int opf( int x) { return u_field(x, 13, 5); } 985 static int opf( int x) { return u_field(x, 13, 5); }
977 986
987 static bool is_cbcond( int x ) {
988 return (VM_Version::has_cbcond() && (inv_cond(x) > rc_last) &&
989 inv_op(x) == branch_op && inv_op2(x) == bpr_op2);
990 }
991 static bool is_cxb( int x ) {
992 assert(is_cbcond(x), "wrong instruction");
993 return (x & (1<<21)) != 0;
994 }
995 static int cond_cbcond( int x) { return u_field((((x & 8)<<1) + 8 + (x & 7)), 29, 25); }
996 static int inv_cond_cbcond(int x) {
997 assert(is_cbcond(x), "wrong instruction");
998 return inv_u_field(x, 27, 25) | (inv_u_field(x, 29, 29)<<3);
999 }
1000
978 static int opf_cc( CC c, bool useFloat ) { return u_field((useFloat ? 0 : 4) + c, 13, 11); } 1001 static int opf_cc( CC c, bool useFloat ) { return u_field((useFloat ? 0 : 4) + c, 13, 11); }
979 static int mov_cc( CC c, bool useFloat ) { return u_field(useFloat ? 0 : 1, 18, 18) | u_field(c, 12, 11); } 1002 static int mov_cc( CC c, bool useFloat ) { return u_field(useFloat ? 0 : 1, 18, 18) | u_field(c, 12, 11); }
980 1003
981 static int fd( FloatRegister r, FloatRegisterImpl::Width fwa) { return u_field(r->encoding(fwa), 29, 25); }; 1004 static int fd( FloatRegister r, FloatRegisterImpl::Width fwa) { return u_field(r->encoding(fwa), 29, 25); };
982 static int fs1(FloatRegister r, FloatRegisterImpl::Width fwa) { return u_field(r->encoding(fwa), 18, 14); }; 1005 static int fs1(FloatRegister r, FloatRegisterImpl::Width fwa) { return u_field(r->encoding(fwa), 18, 14); };
1024 | ( ( (xx>>(2+14)) & 3 ) << 20 ); 1047 | ( ( (xx>>(2+14)) & 3 ) << 20 );
1025 assert( inv_wdisp16(r, off) == x, "inverse is not inverse"); 1048 assert( inv_wdisp16(r, off) == x, "inverse is not inverse");
1026 return r; 1049 return r;
1027 } 1050 }
1028 1051
1052 // compute inverse of wdisp10
1053 static intptr_t inv_wdisp10(int x, intptr_t pos) {
1054 assert(is_cbcond(x), "wrong instruction");
1055 int lo = inv_u_field(x, 12, 5);
1056 int hi = (x >> 19) & 3;
1057 if (hi >= 2) hi |= ~1;
1058 return (((hi << 8) | lo) << 2) + pos;
1059 }
1060
1061 // word offset for cbcond, 8 bits at [B12,B5], 2 bits at [B20,B19]
1062 static int wdisp10(intptr_t x, intptr_t off) {
1063 assert(VM_Version::has_cbcond(), "This CPU does not have CBCOND instruction");
1064 intptr_t xx = x - off;
1065 assert_signed_word_disp_range(xx, 10);
1066 int r = ( ( (xx >> 2 ) & ((1 << 8) - 1) ) << 5 )
1067 | ( ( (xx >> (2+8)) & 3 ) << 19 );
1068 // Have to fake cbcond instruction to pass assert in inv_wdisp10()
1069 assert(inv_wdisp10((r | op(branch_op) | cond_cbcond(rc_last+1) | op2(bpr_op2)), off) == x, "inverse is not inverse");
1070 return r;
1071 }
1029 1072
1030 // word displacement in low-order nbits bits 1073 // word displacement in low-order nbits bits
1031 1074
1032 static intptr_t inv_wdisp( int x, intptr_t pos, int nbits ) { 1075 static intptr_t inv_wdisp( int x, intptr_t pos, int nbits ) {
1033 int pre_sign_extend = x & (( 1 << nbits ) - 1); 1076 int pre_sign_extend = x & (( 1 << nbits ) - 1);
1136 assert_not_delayed("just checking"); 1179 assert_not_delayed("just checking");
1137 delay_state = at_delay_slot; 1180 delay_state = at_delay_slot;
1138 #endif 1181 #endif
1139 } 1182 }
1140 1183
1184 // cbcond instruction should not be generated one after an other
1185 bool cbcond_before() {
1186 if (offset() == 0) return false; // it is first instruction
1187 int x = *(int*)(intptr_t(pc()) - 4); // previous instruction
1188 return is_cbcond(x);
1189 }
1190
1191 void no_cbcond_before() {
1192 assert(offset() == 0 || !cbcond_before(), "cbcond should not follow an other cbcond");
1193 }
1194
1195 bool use_cbcond(Label& L) {
1196 if (!UseCBCond || cbcond_before()) return false;
1197 intptr_t x = intptr_t(target_distance(L)) - intptr_t(pc());
1198 assert( (x & 3) == 0, "not word aligned");
1199 return is_simm(x, 12);
1200 }
1201
1141 public: 1202 public:
1142 // Tells assembler you know that next instruction is delayed 1203 // Tells assembler you know that next instruction is delayed
1143 Assembler* delayed() { 1204 Assembler* delayed() {
1144 #ifdef CHECK_DELAY 1205 #ifdef CHECK_DELAY
1145 assert ( delay_state == at_delay_slot, "delayed instruction is not in delay slot"); 1206 assert ( delay_state == at_delay_slot, "delayed instruction is not in delay slot");
1179 void addc( Register s1, Register s2, Register d ) { emit_long( op(arith_op) | rd(d) | op3(addc_op3 ) | rs1(s1) | rs2(s2) ); } 1240 void addc( Register s1, Register s2, Register d ) { emit_long( op(arith_op) | rd(d) | op3(addc_op3 ) | rs1(s1) | rs2(s2) ); }
1180 void addc( Register s1, int simm13a, Register d ) { emit_long( op(arith_op) | rd(d) | op3(addc_op3 ) | rs1(s1) | immed(true) | simm(simm13a, 13) ); } 1241 void addc( Register s1, int simm13a, Register d ) { emit_long( op(arith_op) | rd(d) | op3(addc_op3 ) | rs1(s1) | immed(true) | simm(simm13a, 13) ); }
1181 void addccc( Register s1, Register s2, Register d ) { emit_long( op(arith_op) | rd(d) | op3(addc_op3 | cc_bit_op3) | rs1(s1) | rs2(s2) ); } 1242 void addccc( Register s1, Register s2, Register d ) { emit_long( op(arith_op) | rd(d) | op3(addc_op3 | cc_bit_op3) | rs1(s1) | rs2(s2) ); }
1182 void addccc( Register s1, int simm13a, Register d ) { emit_long( op(arith_op) | rd(d) | op3(addc_op3 | cc_bit_op3) | rs1(s1) | immed(true) | simm(simm13a, 13) ); } 1243 void addccc( Register s1, int simm13a, Register d ) { emit_long( op(arith_op) | rd(d) | op3(addc_op3 | cc_bit_op3) | rs1(s1) | immed(true) | simm(simm13a, 13) ); }
1183 1244
1245
1184 // pp 136 1246 // pp 136
1185 1247
1186 inline void bpr( RCondition c, bool a, Predict p, Register s1, address d, relocInfo::relocType rt = relocInfo::none ); 1248 inline void bpr(RCondition c, bool a, Predict p, Register s1, address d, relocInfo::relocType rt = relocInfo::none);
1187 inline void bpr( RCondition c, bool a, Predict p, Register s1, Label& L); 1249 inline void bpr(RCondition c, bool a, Predict p, Register s1, Label& L);
1188 1250
1189 protected: // use MacroAssembler::br instead 1251 protected: // use MacroAssembler::br instead
1190 1252
1191 // pp 138 1253 // pp 138
1192 1254
1196 // pp 141 1258 // pp 141
1197 1259
1198 inline void fbp( Condition c, bool a, CC cc, Predict p, address d, relocInfo::relocType rt = relocInfo::none ); 1260 inline void fbp( Condition c, bool a, CC cc, Predict p, address d, relocInfo::relocType rt = relocInfo::none );
1199 inline void fbp( Condition c, bool a, CC cc, Predict p, Label& L ); 1261 inline void fbp( Condition c, bool a, CC cc, Predict p, Label& L );
1200 1262
1201 public:
1202
1203 // pp 144 1263 // pp 144
1204 1264
1205 inline void br( Condition c, bool a, address d, relocInfo::relocType rt = relocInfo::none ); 1265 inline void br( Condition c, bool a, address d, relocInfo::relocType rt = relocInfo::none );
1206 inline void br( Condition c, bool a, Label& L ); 1266 inline void br( Condition c, bool a, Label& L );
1207 1267
1213 // pp 121 (V8) 1273 // pp 121 (V8)
1214 1274
1215 inline void cb( Condition c, bool a, address d, relocInfo::relocType rt = relocInfo::none ); 1275 inline void cb( Condition c, bool a, address d, relocInfo::relocType rt = relocInfo::none );
1216 inline void cb( Condition c, bool a, Label& L ); 1276 inline void cb( Condition c, bool a, Label& L );
1217 1277
1278 // compare and branch
1279 inline void cbcond(Condition c, CC cc, Register s1, Register s2, Label& L);
1280 inline void cbcond(Condition c, CC cc, Register s1, int simm5, Label& L);
1281
1218 // pp 149 1282 // pp 149
1219 1283
1220 inline void call( address d, relocInfo::relocType rt = relocInfo::runtime_call_type ); 1284 inline void call( address d, relocInfo::relocType rt = relocInfo::runtime_call_type );
1221 inline void call( Label& L, relocInfo::relocType rt = relocInfo::runtime_call_type ); 1285 inline void call( Label& L, relocInfo::relocType rt = relocInfo::runtime_call_type );
1286
1287 public:
1222 1288
1223 // pp 150 1289 // pp 150
1224 1290
1225 // These instructions compare the contents of s2 with the contents of 1291 // These instructions compare the contents of s2 with the contents of
1226 // memory at address in s1. If the values are equal, the contents of memory 1292 // memory at address in s1. If the values are equal, the contents of memory
1860 inline void br( Condition c, bool a, Predict p, Label& L ); 1926 inline void br( Condition c, bool a, Predict p, Label& L );
1861 1927
1862 inline void fb( Condition c, bool a, Predict p, address d, relocInfo::relocType rt = relocInfo::none ); 1928 inline void fb( Condition c, bool a, Predict p, address d, relocInfo::relocType rt = relocInfo::none );
1863 inline void fb( Condition c, bool a, Predict p, Label& L ); 1929 inline void fb( Condition c, bool a, Predict p, Label& L );
1864 1930
1865 // compares register with zero and branches (V9 and V8 instructions) 1931 // compares register with zero (32 bit) and branches (V9 and V8 instructions)
1866 void br_zero( Condition c, bool a, Predict p, Register s1, Label& L); 1932 void cmp_zero_and_br( Condition c, Register s1, Label& L, bool a = false, Predict p = pn );
1867 // Compares a pointer register with zero and branches on (not)null. 1933 // Compares a pointer register with zero and branches on (not)null.
1868 // Does a test & branch on 32-bit systems and a register-branch on 64-bit. 1934 // Does a test & branch on 32-bit systems and a register-branch on 64-bit.
1869 void br_null ( Register s1, bool a, Predict p, Label& L ); 1935 void br_null ( Register s1, bool a, Predict p, Label& L );
1870 void br_notnull( Register s1, bool a, Predict p, Label& L ); 1936 void br_notnull( Register s1, bool a, Predict p, Label& L );
1871 1937
1873 // this is what the routine above was meant to do, but it didn't (and 1939 // this is what the routine above was meant to do, but it didn't (and
1874 // didn't cover both target address kinds.) 1940 // didn't cover both target address kinds.)
1875 void br_on_reg_cond( RCondition c, bool a, Predict p, Register s1, address d, relocInfo::relocType rt = relocInfo::none ); 1941 void br_on_reg_cond( RCondition c, bool a, Predict p, Register s1, address d, relocInfo::relocType rt = relocInfo::none );
1876 void br_on_reg_cond( RCondition c, bool a, Predict p, Register s1, Label& L); 1942 void br_on_reg_cond( RCondition c, bool a, Predict p, Register s1, Label& L);
1877 1943
1944 //
1945 // Compare registers and branch with nop in delay slot or cbcond without delay slot.
1946 //
1947 // ATTENTION: use these instructions with caution because cbcond instruction
1948 // has very short distance: 512 instructions (2Kbyte).
1949
1950 // Compare integer (32 bit) values (icc only).
1951 void cmp_and_br_short(Register s1, Register s2, Condition c, Predict p, Label& L);
1952 void cmp_and_br_short(Register s1, int simm13a, Condition c, Predict p, Label& L);
1953 // Platform depending version for pointer compare (icc on !LP64 and xcc on LP64).
1954 void cmp_and_brx_short(Register s1, Register s2, Condition c, Predict p, Label& L);
1955 void cmp_and_brx_short(Register s1, int simm13a, Condition c, Predict p, Label& L);
1956
1957 // Short branch version for compares a pointer pwith zero.
1958 void br_null_short ( Register s1, Predict p, Label& L );
1959 void br_notnull_short( Register s1, Predict p, Label& L );
1960
1961 // unconditional short branch
1962 void ba_short(Label& L);
1963
1878 inline void bp( Condition c, bool a, CC cc, Predict p, address d, relocInfo::relocType rt = relocInfo::none ); 1964 inline void bp( Condition c, bool a, CC cc, Predict p, address d, relocInfo::relocType rt = relocInfo::none );
1879 inline void bp( Condition c, bool a, CC cc, Predict p, Label& L ); 1965 inline void bp( Condition c, bool a, CC cc, Predict p, Label& L );
1880 1966
1881 // Branch that tests xcc in LP64 and icc in !LP64 1967 // Branch that tests xcc in LP64 and icc in !LP64
1882 inline void brx( Condition c, bool a, Predict p, address d, relocInfo::relocType rt = relocInfo::none ); 1968 inline void brx( Condition c, bool a, Predict p, address d, relocInfo::relocType rt = relocInfo::none );
1883 inline void brx( Condition c, bool a, Predict p, Label& L ); 1969 inline void brx( Condition c, bool a, Predict p, Label& L );
1884 1970
1885 // unconditional short branch 1971 // unconditional branch
1886 inline void ba( bool a, Label& L ); 1972 inline void ba( Label& L );
1887 1973
1888 // Branch that tests fp condition codes 1974 // Branch that tests fp condition codes
1889 inline void fbp( Condition c, bool a, CC cc, Predict p, address d, relocInfo::relocType rt = relocInfo::none ); 1975 inline void fbp( Condition c, bool a, CC cc, Predict p, address d, relocInfo::relocType rt = relocInfo::none );
1890 inline void fbp( Condition c, bool a, CC cc, Predict p, Label& L ); 1976 inline void fbp( Condition c, bool a, CC cc, Predict p, Label& L );
1891 1977
2165 // These are idioms to flag the need for care with accessing bools but on 2251 // These are idioms to flag the need for care with accessing bools but on
2166 // this platform we assume byte size 2252 // this platform we assume byte size
2167 2253
2168 inline void stbool(Register d, const Address& a) { stb(d, a); } 2254 inline void stbool(Register d, const Address& a) { stb(d, a); }
2169 inline void ldbool(const Address& a, Register d) { ldsb(a, d); } 2255 inline void ldbool(const Address& a, Register d) { ldsb(a, d); }
2170 inline void tstbool( Register s ) { tst(s); }
2171 inline void movbool( bool boolconst, Register d) { mov( (int) boolconst, d); } 2256 inline void movbool( bool boolconst, Register d) { mov( (int) boolconst, d); }
2172 2257
2173 // klass oop manipulations if compressed 2258 // klass oop manipulations if compressed
2174 void load_klass(Register src_oop, Register klass); 2259 void load_klass(Register src_oop, Register klass);
2175 void store_klass(Register klass, Register dst_oop); 2260 void store_klass(Register klass, Register dst_oop);
2467 Register temp_reg, 2552 Register temp_reg,
2468 Register temp2_reg, 2553 Register temp2_reg,
2469 Label* L_success, 2554 Label* L_success,
2470 Label* L_failure, 2555 Label* L_failure,
2471 Label* L_slow_path, 2556 Label* L_slow_path,
2472 RegisterOrConstant super_check_offset = RegisterOrConstant(-1), 2557 RegisterOrConstant super_check_offset = RegisterOrConstant(-1));
2473 Register instanceof_hack = noreg);
2474 2558
2475 // The rest of the type check; must be wired to a corresponding fast path. 2559 // The rest of the type check; must be wired to a corresponding fast path.
2476 // It does not repeat the fast path logic, so don't use it standalone. 2560 // It does not repeat the fast path logic, so don't use it standalone.
2477 // The temp_reg can be noreg, if no temps are available. 2561 // The temp_reg can be noreg, if no temps are available.
2478 // It can also be sub_klass or super_klass, meaning it's OK to kill that one. 2562 // It can also be sub_klass or super_klass, meaning it's OK to kill that one.