comparison graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCBitManipulationOp.java @ 9949:41511d78546a

SPARC UA 2011 assembler changes, bit manipulation synthetics
author Morris Meyer <morris.meyer@oracle.com>
date Sat, 08 Jun 2013 16:54:41 -0400
parents fbeda9df497d
children f78079947084
comparison
equal deleted inserted replaced
9948:b4325bc087c4 9949:41511d78546a
20 * or visit www.oracle.com if you need additional information or have any 20 * or visit www.oracle.com if you need additional information or have any
21 * questions. 21 * questions.
22 */ 22 */
23 package com.oracle.graal.lir.sparc; 23 package com.oracle.graal.lir.sparc;
24 24
25 import static com.oracle.graal.asm.sparc.SPARCAssembler.Andn;
26 import static com.oracle.graal.asm.sparc.SPARCAssembler.Ldsw;
27 import static com.oracle.graal.asm.sparc.SPARCAssembler.Ldx;
28 import static com.oracle.graal.asm.sparc.SPARCAssembler.Or;
25 import static com.oracle.graal.asm.sparc.SPARCAssembler.Popc; 29 import static com.oracle.graal.asm.sparc.SPARCAssembler.Popc;
26 import static com.oracle.graal.asm.sparc.SPARCAssembler.Srl; 30 import static com.oracle.graal.asm.sparc.SPARCAssembler.Srl;
31 import static com.oracle.graal.asm.sparc.SPARCAssembler.Srlx;
32 import static com.oracle.graal.asm.sparc.SPARCAssembler.Sub;
27 import static com.oracle.graal.asm.sparc.SPARCAssembler.isSimm13; 33 import static com.oracle.graal.asm.sparc.SPARCAssembler.isSimm13;
34 import static com.oracle.graal.asm.sparc.SPARCMacroAssembler.Mov;
28 35
29 import com.oracle.graal.api.code.*; 36 import com.oracle.graal.api.code.*;
30 import com.oracle.graal.api.meta.*; 37 import com.oracle.graal.api.meta.*;
31 import com.oracle.graal.asm.sparc.*; 38 import com.oracle.graal.asm.sparc.*;
32 import com.oracle.graal.graph.*; 39 import com.oracle.graal.graph.*;
52 59
53 @Override 60 @Override
54 @SuppressWarnings("unused") 61 @SuppressWarnings("unused")
55 public void emitCode(TargetMethodAssembler tasm, SPARCAssembler masm) { 62 public void emitCode(TargetMethodAssembler tasm, SPARCAssembler masm) {
56 Register dst = ValueUtil.asIntReg(result); 63 Register dst = ValueUtil.asIntReg(result);
64 Register tmp = null; // ??
57 if (ValueUtil.isRegister(input)) { 65 if (ValueUtil.isRegister(input)) {
58 Register src = ValueUtil.asRegister(input); 66 Register src = ValueUtil.asRegister(input);
59 switch (opcode) { 67 switch (opcode) {
60 case IPOPCNT: 68 case IPOPCNT:
61 // clear upper word for 64 bit POPC 69 // clear upper word for 64 bit POPC
63 new Popc(masm, src, dst); 71 new Popc(masm, src, dst);
64 break; 72 break;
65 case LPOPCNT: 73 case LPOPCNT:
66 new Popc(masm, src, dst); 74 new Popc(masm, src, dst);
67 break; 75 break;
68 case BSF: // masm.bsfq(dst, src); 76 case BSF:
69 case IBSR: // masm.bsrl(dst, src); 77 // countTrailingZerosI - bsfl
70 case LBSR: // masm.bsrq(dst, src); 78 // countTrailingZerosL - masm.bsfq(dst, src);
79 Kind tkind = input.getKind();
80 if (tkind == Kind.Int) {
81 new Sub(masm, src, 1, dst);
82 new Andn(masm, dst, src, dst);
83 new Srl(masm, dst, SPARC.g0, dst);
84 new Popc(masm, dst, dst);
85 } else if (tkind == Kind.Long) {
86 new Sub(masm, src, 1, dst);
87 new Andn(masm, dst, src, dst);
88 new Popc(masm, dst, dst);
89 } else {
90 throw GraalInternalError.shouldNotReachHere("missing: " + tkind);
91 }
92 break;
93 case IBSR:
94 // countLeadingZerosI_bsr masm.bsrq(dst, src);
95 // masm.bsrl(dst, src);
96 Kind ikind = input.getKind();
97 assert ikind == Kind.Int;
98 new Srl(masm, src, 1, tmp);
99 new Srl(masm, src, 0, dst);
100 new Or(masm, src, tmp, dst);
101 new Srl(masm, dst, 2, tmp);
102 new Or(masm, dst, tmp, dst);
103 new Srl(masm, dst, 4, tmp);
104 new Or(masm, dst, tmp, dst);
105 new Srl(masm, dst, 8, tmp);
106 new Or(masm, dst, tmp, dst);
107 new Srl(masm, dst, 16, tmp);
108 new Or(masm, dst, tmp, dst);
109 new Popc(masm, dst, dst);
110 new Mov(masm, ikind.getBitCount(), tmp);
111 new Sub(masm, tmp, dst, dst);
112 break;
113 case LBSR:
114 // countLeadingZerosL_bsr masm.bsrq(dst, src);
115 // masm.bsrq(dst, src);
116 Kind lkind = input.getKind();
117 assert lkind == Kind.Int;
118 new Srlx(masm, src, 1, tmp);
119 new Or(masm, src, tmp, dst);
120 new Srlx(masm, dst, 2, tmp);
121 new Or(masm, dst, tmp, dst);
122 new Srlx(masm, dst, 4, tmp);
123 new Or(masm, dst, tmp, dst);
124 new Srlx(masm, dst, 8, tmp);
125 new Or(masm, dst, tmp, dst);
126 new Srlx(masm, dst, 16, tmp);
127 new Or(masm, dst, tmp, dst);
128 new Srlx(masm, dst, 32, tmp);
129 new Or(masm, dst, tmp, dst);
130 new Popc(masm, dst, dst);
131 new Mov(masm, lkind.getBitCount(), tmp);
132 new Sub(masm, tmp, dst, dst);
133 break;
71 default: 134 default:
72 throw GraalInternalError.shouldNotReachHere("missing: " + opcode); 135 throw GraalInternalError.shouldNotReachHere("missing: " + opcode);
73 136
74 } 137 }
75 } else if (ValueUtil.isConstant(input) && isSimm13(tasm.asIntConst(input))) { 138 } else if (ValueUtil.isConstant(input) && isSimm13(tasm.asIntConst(input))) {
85 } 148 }
86 } else { 149 } else {
87 SPARCAddress src = (SPARCAddress) tasm.asAddress(input); 150 SPARCAddress src = (SPARCAddress) tasm.asAddress(input);
88 switch (opcode) { 151 switch (opcode) {
89 case IPOPCNT: 152 case IPOPCNT:
90 // masm.popcntl(dst, src); 153 new Ldsw(masm, src, tmp);
154 // clear upper word for 64 bit POPC
155 new Srl(masm, tmp, SPARC.g0, dst);
156 new Popc(masm, tmp, dst);
91 break; 157 break;
92 case LPOPCNT: 158 case LPOPCNT:
93 // masm.popcntq(dst, src); 159 new Ldx(masm, src, tmp);
160 new Popc(masm, tmp, dst);
94 break; 161 break;
95 case BSF: 162 case BSF:
96 // masm.bsfq(dst, src); 163 assert input.getKind() == Kind.Int;
164 new Ldsw(masm, src, tmp);
165 new Srl(masm, tmp, 1, tmp);
166 new Srl(masm, tmp, 0, dst);
167 new Or(masm, tmp, tmp, dst);
168 new Srl(masm, dst, 2, tmp);
169 new Or(masm, dst, tmp, dst);
170 new Srl(masm, dst, 4, tmp);
171 new Or(masm, dst, tmp, dst);
172 new Srl(masm, dst, 8, tmp);
173 new Or(masm, dst, tmp, dst);
174 new Srl(masm, dst, 16, tmp);
175 new Or(masm, dst, tmp, dst);
176 new Popc(masm, dst, dst);
177 new Mov(masm, Kind.Int.getBitCount(), tmp);
178 new Sub(masm, tmp, dst, dst);
97 break; 179 break;
98 case IBSR: 180 case IBSR:
99 // masm.bsrl(dst, src); 181 // masm.bsrl(dst, src);
100 break; 182 // countLeadingZerosI_bsr masm.bsrq(dst, src);
183 // masm.bsrl(dst, src);
101 case LBSR: 184 case LBSR:
102 // masm.bsrq(dst, src); 185 // masm.bsrq(dst, src);
103 break; 186 default:
187 throw GraalInternalError.shouldNotReachHere("missing: " + opcode);
104 } 188 }
105 } 189 }
106 } 190 }
107 191
108 } 192 }