buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
buzbee | 1bc37c6 | 2012-11-20 13:35:41 -0800 | [diff] [blame] | 17 | #include "x86_lir.h" |
| 18 | #include "../codegen_util.h" |
| 19 | #include "../ralloc_util.h" |
| 20 | |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 21 | namespace art { |
| 22 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 23 | bool GenArithOpFloat(CompilationUnit *cu, Instruction::Code opcode, |
| 24 | RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2) { |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 25 | X86OpCode op = kX86Nop; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 26 | RegLocation rl_result; |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 27 | |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 28 | /* |
| 29 | * Don't attempt to optimize register usage since these opcodes call out to |
| 30 | * the handlers. |
| 31 | */ |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 32 | switch (opcode) { |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 33 | case Instruction::ADD_FLOAT_2ADDR: |
| 34 | case Instruction::ADD_FLOAT: |
| 35 | op = kX86AddssRR; |
| 36 | break; |
| 37 | case Instruction::SUB_FLOAT_2ADDR: |
| 38 | case Instruction::SUB_FLOAT: |
| 39 | op = kX86SubssRR; |
| 40 | break; |
| 41 | case Instruction::DIV_FLOAT_2ADDR: |
| 42 | case Instruction::DIV_FLOAT: |
| 43 | op = kX86DivssRR; |
| 44 | break; |
| 45 | case Instruction::MUL_FLOAT_2ADDR: |
| 46 | case Instruction::MUL_FLOAT: |
| 47 | op = kX86MulssRR; |
| 48 | break; |
jeffhao | babda95 | 2012-08-02 15:55:30 -0700 | [diff] [blame] | 49 | case Instruction::NEG_FLOAT: |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 50 | case Instruction::REM_FLOAT_2ADDR: |
jeffhao | babda95 | 2012-08-02 15:55:30 -0700 | [diff] [blame] | 51 | case Instruction::REM_FLOAT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 52 | return GenArithOpFloatPortable(cu, opcode, rl_dest, rl_src1, rl_src2); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 53 | default: |
| 54 | return true; |
| 55 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 56 | rl_src1 = LoadValue(cu, rl_src1, kFPReg); |
| 57 | rl_src2 = LoadValue(cu, rl_src2, kFPReg); |
| 58 | rl_result = EvalLoc(cu, rl_dest, kFPReg, true); |
| 59 | int r_dest = rl_result.low_reg; |
| 60 | int r_src1 = rl_src1.low_reg; |
| 61 | int r_src2 = rl_src2.low_reg; |
| 62 | if (r_dest == r_src2) { |
| 63 | r_src2 = AllocTempFloat(cu); |
| 64 | OpRegCopy(cu, r_src2, r_dest); |
jeffhao | 4abb1a9 | 2012-06-08 17:02:08 -0700 | [diff] [blame] | 65 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 66 | OpRegCopy(cu, r_dest, r_src1); |
| 67 | NewLIR2(cu, op, r_dest, r_src2); |
| 68 | StoreValue(cu, rl_dest, rl_result); |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 69 | |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 70 | return false; |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 71 | } |
| 72 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 73 | bool GenArithOpDouble(CompilationUnit *cu, Instruction::Code opcode, |
| 74 | RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2) { |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 75 | X86OpCode op = kX86Nop; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 76 | RegLocation rl_result; |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 77 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 78 | switch (opcode) { |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 79 | case Instruction::ADD_DOUBLE_2ADDR: |
| 80 | case Instruction::ADD_DOUBLE: |
| 81 | op = kX86AddsdRR; |
| 82 | break; |
| 83 | case Instruction::SUB_DOUBLE_2ADDR: |
| 84 | case Instruction::SUB_DOUBLE: |
| 85 | op = kX86SubsdRR; |
| 86 | break; |
| 87 | case Instruction::DIV_DOUBLE_2ADDR: |
| 88 | case Instruction::DIV_DOUBLE: |
| 89 | op = kX86DivsdRR; |
| 90 | break; |
| 91 | case Instruction::MUL_DOUBLE_2ADDR: |
| 92 | case Instruction::MUL_DOUBLE: |
| 93 | op = kX86MulsdRR; |
| 94 | break; |
jeffhao | babda95 | 2012-08-02 15:55:30 -0700 | [diff] [blame] | 95 | case Instruction::NEG_DOUBLE: |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 96 | case Instruction::REM_DOUBLE_2ADDR: |
jeffhao | babda95 | 2012-08-02 15:55:30 -0700 | [diff] [blame] | 97 | case Instruction::REM_DOUBLE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 98 | return GenArithOpDoublePortable(cu, opcode, rl_dest, rl_src1, rl_src2); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 99 | default: |
| 100 | return true; |
| 101 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 102 | rl_src1 = LoadValueWide(cu, rl_src1, kFPReg); |
| 103 | DCHECK(rl_src1.wide); |
| 104 | rl_src2 = LoadValueWide(cu, rl_src2, kFPReg); |
| 105 | DCHECK(rl_src2.wide); |
| 106 | rl_result = EvalLoc(cu, rl_dest, kFPReg, true); |
| 107 | DCHECK(rl_dest.wide); |
| 108 | DCHECK(rl_result.wide); |
| 109 | int r_dest = S2d(rl_result.low_reg, rl_result.high_reg); |
| 110 | int r_src1 = S2d(rl_src1.low_reg, rl_src1.high_reg); |
| 111 | int r_src2 = S2d(rl_src2.low_reg, rl_src2.high_reg); |
| 112 | if (r_dest == r_src2) { |
| 113 | r_src2 = AllocTempDouble(cu) | X86_FP_DOUBLE; |
| 114 | OpRegCopy(cu, r_src2, r_dest); |
jeffhao | 4abb1a9 | 2012-06-08 17:02:08 -0700 | [diff] [blame] | 115 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 116 | OpRegCopy(cu, r_dest, r_src1); |
| 117 | NewLIR2(cu, op, r_dest, r_src2); |
| 118 | StoreValueWide(cu, rl_dest, rl_result); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 119 | return false; |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 120 | } |
| 121 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 122 | bool GenConversion(CompilationUnit *cu, Instruction::Code opcode, |
| 123 | RegLocation rl_dest, RegLocation rl_src) { |
jeffhao | 5121e0b | 2012-05-08 18:23:38 -0700 | [diff] [blame] | 124 | RegisterClass rcSrc = kFPReg; |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 125 | X86OpCode op = kX86Nop; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 126 | int src_reg; |
| 127 | RegLocation rl_result; |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 128 | switch (opcode) { |
| 129 | case Instruction::INT_TO_FLOAT: |
jeffhao | 5121e0b | 2012-05-08 18:23:38 -0700 | [diff] [blame] | 130 | rcSrc = kCoreReg; |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 131 | op = kX86Cvtsi2ssRR; |
| 132 | break; |
| 133 | case Instruction::DOUBLE_TO_FLOAT: |
jeffhao | 5121e0b | 2012-05-08 18:23:38 -0700 | [diff] [blame] | 134 | rcSrc = kFPReg; |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 135 | op = kX86Cvtsd2ssRR; |
| 136 | break; |
| 137 | case Instruction::FLOAT_TO_DOUBLE: |
jeffhao | 5121e0b | 2012-05-08 18:23:38 -0700 | [diff] [blame] | 138 | rcSrc = kFPReg; |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 139 | op = kX86Cvtss2sdRR; |
| 140 | break; |
| 141 | case Instruction::INT_TO_DOUBLE: |
jeffhao | 5121e0b | 2012-05-08 18:23:38 -0700 | [diff] [blame] | 142 | rcSrc = kCoreReg; |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 143 | op = kX86Cvtsi2sdRR; |
| 144 | break; |
jeffhao | 292188d | 2012-05-17 15:45:04 -0700 | [diff] [blame] | 145 | case Instruction::FLOAT_TO_INT: { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 146 | rl_src = LoadValue(cu, rl_src, kFPReg); |
| 147 | src_reg = rl_src.low_reg; |
| 148 | ClobberSReg(cu, rl_dest.s_reg_low); |
| 149 | rl_result = EvalLoc(cu, rl_dest, kCoreReg, true); |
| 150 | int temp_reg = AllocTempFloat(cu); |
jeffhao | 41005dd | 2012-05-09 17:58:52 -0700 | [diff] [blame] | 151 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 152 | LoadConstant(cu, rl_result.low_reg, 0x7fffffff); |
| 153 | NewLIR2(cu, kX86Cvtsi2ssRR, temp_reg, rl_result.low_reg); |
| 154 | NewLIR2(cu, kX86ComissRR, src_reg, temp_reg); |
| 155 | LIR* branch_pos_overflow = NewLIR2(cu, kX86Jcc8, 0, kX86CondA); |
| 156 | LIR* branch_na_n = NewLIR2(cu, kX86Jcc8, 0, kX86CondP); |
| 157 | NewLIR2(cu, kX86Cvttss2siRR, rl_result.low_reg, src_reg); |
| 158 | LIR* branch_normal = NewLIR1(cu, kX86Jmp8, 0); |
| 159 | branch_na_n->target = NewLIR0(cu, kPseudoTargetLabel); |
| 160 | NewLIR2(cu, kX86Xor32RR, rl_result.low_reg, rl_result.low_reg); |
| 161 | branch_pos_overflow->target = NewLIR0(cu, kPseudoTargetLabel); |
| 162 | branch_normal->target = NewLIR0(cu, kPseudoTargetLabel); |
| 163 | StoreValue(cu, rl_dest, rl_result); |
jeffhao | 41005dd | 2012-05-09 17:58:52 -0700 | [diff] [blame] | 164 | return false; |
jeffhao | 292188d | 2012-05-17 15:45:04 -0700 | [diff] [blame] | 165 | } |
| 166 | case Instruction::DOUBLE_TO_INT: { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 167 | rl_src = LoadValueWide(cu, rl_src, kFPReg); |
| 168 | src_reg = rl_src.low_reg; |
| 169 | ClobberSReg(cu, rl_dest.s_reg_low); |
| 170 | rl_result = EvalLoc(cu, rl_dest, kCoreReg, true); |
| 171 | int temp_reg = AllocTempDouble(cu) | X86_FP_DOUBLE; |
jeffhao | 41005dd | 2012-05-09 17:58:52 -0700 | [diff] [blame] | 172 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 173 | LoadConstant(cu, rl_result.low_reg, 0x7fffffff); |
| 174 | NewLIR2(cu, kX86Cvtsi2sdRR, temp_reg, rl_result.low_reg); |
| 175 | NewLIR2(cu, kX86ComisdRR, src_reg, temp_reg); |
| 176 | LIR* branch_pos_overflow = NewLIR2(cu, kX86Jcc8, 0, kX86CondA); |
| 177 | LIR* branch_na_n = NewLIR2(cu, kX86Jcc8, 0, kX86CondP); |
| 178 | NewLIR2(cu, kX86Cvttsd2siRR, rl_result.low_reg, src_reg); |
| 179 | LIR* branch_normal = NewLIR1(cu, kX86Jmp8, 0); |
| 180 | branch_na_n->target = NewLIR0(cu, kPseudoTargetLabel); |
| 181 | NewLIR2(cu, kX86Xor32RR, rl_result.low_reg, rl_result.low_reg); |
| 182 | branch_pos_overflow->target = NewLIR0(cu, kPseudoTargetLabel); |
| 183 | branch_normal->target = NewLIR0(cu, kPseudoTargetLabel); |
| 184 | StoreValue(cu, rl_dest, rl_result); |
jeffhao | 41005dd | 2012-05-09 17:58:52 -0700 | [diff] [blame] | 185 | return false; |
jeffhao | 292188d | 2012-05-17 15:45:04 -0700 | [diff] [blame] | 186 | } |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 187 | case Instruction::LONG_TO_DOUBLE: |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 188 | case Instruction::LONG_TO_FLOAT: |
jeffhao | babda95 | 2012-08-02 15:55:30 -0700 | [diff] [blame] | 189 | // TODO: inline by using memory as a 64-bit source. Be careful about promoted registers. |
jeffhao | 41005dd | 2012-05-09 17:58:52 -0700 | [diff] [blame] | 190 | case Instruction::FLOAT_TO_LONG: |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 191 | case Instruction::DOUBLE_TO_LONG: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 192 | return GenConversionPortable(cu, opcode, rl_dest, rl_src); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 193 | default: |
| 194 | return true; |
| 195 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 196 | if (rl_src.wide) { |
| 197 | rl_src = LoadValueWide(cu, rl_src, rcSrc); |
| 198 | src_reg = S2d(rl_src.low_reg, rl_src.high_reg); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 199 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 200 | rl_src = LoadValue(cu, rl_src, rcSrc); |
| 201 | src_reg = rl_src.low_reg; |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 202 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 203 | if (rl_dest.wide) { |
| 204 | rl_result = EvalLoc(cu, rl_dest, kFPReg, true); |
| 205 | NewLIR2(cu, op, S2d(rl_result.low_reg, rl_result.high_reg), src_reg); |
| 206 | StoreValueWide(cu, rl_dest, rl_result); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 207 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 208 | rl_result = EvalLoc(cu, rl_dest, kFPReg, true); |
| 209 | NewLIR2(cu, op, rl_result.low_reg, src_reg); |
| 210 | StoreValue(cu, rl_dest, rl_result); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 211 | } |
| 212 | return false; |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 213 | } |
| 214 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 215 | bool GenCmpFP(CompilationUnit *cu, Instruction::Code code, RegLocation rl_dest, |
| 216 | RegLocation rl_src1, RegLocation rl_src2) { |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 217 | bool single = (code == Instruction::CMPL_FLOAT) || (code == Instruction::CMPG_FLOAT); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 218 | bool unordered_gt = (code == Instruction::CMPG_DOUBLE) || (code == Instruction::CMPG_FLOAT); |
| 219 | int src_reg1; |
| 220 | int src_reg2; |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 221 | if (single) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 222 | rl_src1 = LoadValue(cu, rl_src1, kFPReg); |
| 223 | src_reg1 = rl_src1.low_reg; |
| 224 | rl_src2 = LoadValue(cu, rl_src2, kFPReg); |
| 225 | src_reg2 = rl_src2.low_reg; |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 226 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 227 | rl_src1 = LoadValueWide(cu, rl_src1, kFPReg); |
| 228 | src_reg1 = S2d(rl_src1.low_reg, rl_src1.high_reg); |
| 229 | rl_src2 = LoadValueWide(cu, rl_src2, kFPReg); |
| 230 | src_reg2 = S2d(rl_src2.low_reg, rl_src2.high_reg); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 231 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 232 | ClobberSReg(cu, rl_dest.s_reg_low); |
| 233 | RegLocation rl_result = EvalLoc(cu, rl_dest, kCoreReg, true); |
| 234 | LoadConstantNoClobber(cu, rl_result.low_reg, unordered_gt ? 1 : 0); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 235 | if (single) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 236 | NewLIR2(cu, kX86UcomissRR, src_reg1, src_reg2); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 237 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 238 | NewLIR2(cu, kX86UcomisdRR, src_reg1, src_reg2); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 239 | } |
| 240 | LIR* branch = NULL; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 241 | if (unordered_gt) { |
| 242 | branch = NewLIR2(cu, kX86Jcc8, 0, kX86CondPE); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 243 | } |
jeffhao | 703f2cd | 2012-07-13 17:25:52 -0700 | [diff] [blame] | 244 | // If the result reg can't be byte accessed, use a jump and move instead of a set. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 245 | if (rl_result.low_reg >= 4) { |
jeffhao | 703f2cd | 2012-07-13 17:25:52 -0700 | [diff] [blame] | 246 | LIR* branch2 = NULL; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 247 | if (unordered_gt) { |
| 248 | branch2 = NewLIR2(cu, kX86Jcc8, 0, kX86CondA); |
| 249 | NewLIR2(cu, kX86Mov32RI, rl_result.low_reg, 0x0); |
jeffhao | 703f2cd | 2012-07-13 17:25:52 -0700 | [diff] [blame] | 250 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 251 | branch2 = NewLIR2(cu, kX86Jcc8, 0, kX86CondBe); |
| 252 | NewLIR2(cu, kX86Mov32RI, rl_result.low_reg, 0x1); |
jeffhao | 703f2cd | 2012-07-13 17:25:52 -0700 | [diff] [blame] | 253 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 254 | branch2->target = NewLIR0(cu, kPseudoTargetLabel); |
jeffhao | 703f2cd | 2012-07-13 17:25:52 -0700 | [diff] [blame] | 255 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 256 | NewLIR2(cu, kX86Set8R, rl_result.low_reg, kX86CondA /* above - unsigned > */); |
jeffhao | 703f2cd | 2012-07-13 17:25:52 -0700 | [diff] [blame] | 257 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 258 | NewLIR2(cu, kX86Sbb32RI, rl_result.low_reg, 0); |
| 259 | if (unordered_gt) { |
| 260 | branch->target = NewLIR0(cu, kPseudoTargetLabel); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 261 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 262 | StoreValue(cu, rl_dest, rl_result); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 263 | return false; |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 264 | } |
| 265 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 266 | void GenFusedFPCmpBranch(CompilationUnit* cu, BasicBlock* bb, MIR* mir, |
| 267 | bool gt_bias, bool is_double) { |
| 268 | LIR* label_list = cu->block_label_list; |
| 269 | LIR* taken = &label_list[bb->taken->id]; |
| 270 | LIR* not_taken = &label_list[bb->fall_through->id]; |
jeffhao | 4b771a0 | 2012-07-25 15:07:21 -0700 | [diff] [blame] | 271 | LIR* branch = NULL; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 272 | RegLocation rl_src1; |
| 273 | RegLocation rl_src2; |
| 274 | if (is_double) { |
| 275 | rl_src1 = GetSrcWide(cu, mir, 0); |
| 276 | rl_src2 = GetSrcWide(cu, mir, 2); |
| 277 | rl_src1 = LoadValueWide(cu, rl_src1, kFPReg); |
| 278 | rl_src2 = LoadValueWide(cu, rl_src2, kFPReg); |
| 279 | NewLIR2(cu, kX86UcomisdRR, S2d(rl_src1.low_reg, rl_src1.high_reg), |
| 280 | S2d(rl_src2.low_reg, rl_src2.high_reg)); |
jeffhao | 4b771a0 | 2012-07-25 15:07:21 -0700 | [diff] [blame] | 281 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 282 | rl_src1 = GetSrc(cu, mir, 0); |
| 283 | rl_src2 = GetSrc(cu, mir, 1); |
| 284 | rl_src1 = LoadValue(cu, rl_src1, kFPReg); |
| 285 | rl_src2 = LoadValue(cu, rl_src2, kFPReg); |
| 286 | NewLIR2(cu, kX86UcomissRR, rl_src1.low_reg, rl_src2.low_reg); |
jeffhao | 4b771a0 | 2012-07-25 15:07:21 -0700 | [diff] [blame] | 287 | } |
| 288 | ConditionCode ccode = static_cast<ConditionCode>(mir->dalvikInsn.arg[0]); |
| 289 | switch (ccode) { |
| 290 | case kCondEq: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 291 | if (!gt_bias) { |
| 292 | branch = NewLIR2(cu, kX86Jcc8, 0, kX86CondPE); |
| 293 | branch->target = not_taken; |
jeffhao | 4b771a0 | 2012-07-25 15:07:21 -0700 | [diff] [blame] | 294 | } |
| 295 | break; |
| 296 | case kCondNe: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 297 | if (!gt_bias) { |
| 298 | branch = NewLIR2(cu, kX86Jcc8, 0, kX86CondPE); |
jeffhao | 4b771a0 | 2012-07-25 15:07:21 -0700 | [diff] [blame] | 299 | branch->target = taken; |
| 300 | } |
| 301 | break; |
| 302 | case kCondLt: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 303 | if (gt_bias) { |
| 304 | branch = NewLIR2(cu, kX86Jcc8, 0, kX86CondPE); |
| 305 | branch->target = not_taken; |
jeffhao | 4b771a0 | 2012-07-25 15:07:21 -0700 | [diff] [blame] | 306 | } |
| 307 | ccode = kCondCs; |
| 308 | break; |
| 309 | case kCondLe: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 310 | if (gt_bias) { |
| 311 | branch = NewLIR2(cu, kX86Jcc8, 0, kX86CondPE); |
| 312 | branch->target = not_taken; |
jeffhao | 4b771a0 | 2012-07-25 15:07:21 -0700 | [diff] [blame] | 313 | } |
| 314 | ccode = kCondLs; |
| 315 | break; |
| 316 | case kCondGt: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 317 | if (gt_bias) { |
| 318 | branch = NewLIR2(cu, kX86Jcc8, 0, kX86CondPE); |
jeffhao | 4b771a0 | 2012-07-25 15:07:21 -0700 | [diff] [blame] | 319 | branch->target = taken; |
| 320 | } |
| 321 | ccode = kCondHi; |
| 322 | break; |
| 323 | case kCondGe: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 324 | if (gt_bias) { |
| 325 | branch = NewLIR2(cu, kX86Jcc8, 0, kX86CondPE); |
jeffhao | 4b771a0 | 2012-07-25 15:07:21 -0700 | [diff] [blame] | 326 | branch->target = taken; |
| 327 | } |
| 328 | ccode = kCondCc; |
| 329 | break; |
| 330 | default: |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 331 | LOG(FATAL) << "Unexpected ccode: " << ccode; |
jeffhao | 4b771a0 | 2012-07-25 15:07:21 -0700 | [diff] [blame] | 332 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 333 | OpCondBranch(cu, ccode, taken); |
jeffhao | 4b771a0 | 2012-07-25 15:07:21 -0700 | [diff] [blame] | 334 | } |
| 335 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 336 | void GenNegFloat(CompilationUnit *cu, RegLocation rl_dest, RegLocation rl_src) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 337 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 338 | RegLocation rl_result; |
| 339 | rl_src = LoadValue(cu, rl_src, kCoreReg); |
| 340 | rl_result = EvalLoc(cu, rl_dest, kCoreReg, true); |
| 341 | OpRegRegImm(cu, kOpAdd, rl_result.low_reg, rl_src.low_reg, 0x80000000); |
| 342 | StoreValue(cu, rl_dest, rl_result); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 343 | } |
| 344 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 345 | void GenNegDouble(CompilationUnit *cu, RegLocation rl_dest, RegLocation rl_src) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 346 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 347 | RegLocation rl_result; |
| 348 | rl_src = LoadValueWide(cu, rl_src, kCoreReg); |
| 349 | rl_result = EvalLoc(cu, rl_dest, kCoreReg, true); |
| 350 | OpRegRegImm(cu, kOpAdd, rl_result.high_reg, rl_src.high_reg, 0x80000000); |
| 351 | OpRegCopy(cu, rl_result.low_reg, rl_src.low_reg); |
| 352 | StoreValueWide(cu, rl_dest, rl_result); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 353 | } |
| 354 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame^] | 355 | bool GenInlinedSqrt(CompilationUnit* cu, CallInfo* info) { |
| 356 | DCHECK_NE(cu->instruction_set, kThumb2); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 357 | return false; |
| 358 | } |
| 359 | |
| 360 | |
| 361 | |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 362 | } // namespace art |