1 /* Copyright (C) 2008 The Android Open Source Project 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /* 17 * File: binopDLit8.S 18 * 19 * Code: 32-bit "lit8" divide operation. If "div" is set, the code 20 * returns the quotient, else it returns the remainder. 21 * Also, a divide-by-zero check is done. 22 * 23 * For: div-int/lit8, rem-int/lit8 24 * 25 * Description: Perform a binary operation on a register and a 26 * signe extended 8-bit literal value 27 * 28 * Format: AA|op CC|BB (22b) 29 * 30 * Syntax: op vAA, vBB, #+CC 31 */ 32 33%default {"div":"1"} 34 35 FETCH_CCs 1, %ecx # %ecx<- +CC, sign-extended literal 36 testl %ecx, %ecx # handle -1 special case divide error 37 FETCH_BB 1, %eax # %eax<- BB 38 jz common_errDivideByZero # handle divide by zero 39 addl $$4, rPC # update PC 40 cmpl $$-1, %ecx 41 GET_VREG %eax # %eax<- vBB 42 jnz .L${opcode}_continue 43 cmpl $$0x80000000,%eax # handle min int special case divide error 44 je .L${opcode}_break 45.L${opcode}_continue: 46 cdq # sign-extend %eax to %edx 47 idiv %ecx # divide %edx:%eax by %ecx 48 .if $div 49 movzbl (rPC), %edx 50 SET_VREG %eax, rINST # vA<- %eax (quotient) 51 movzbl 1(rPC), rINST 52 jmp *dvmAsmInstructionJmpTable(, %edx, 4) 53 .else 54 movzbl (rPC), %eax 55 SET_VREG %edx, rINST # vA<- %edx (remainder) 56 movzbl 1(rPC), rINST 57 jmp *dvmAsmInstructionJmpTable(, %eax, 4) 58 .endif 59%break 60.L${opcode}_break: 61 movzbl (rPC), %edx 62 .if $div 63 movl $$0x80000000, (rFP, rINST, 4) # vAA<- min int 64 .else 65 movl $$0, (rFP, rINST, 4) # vAA<- 0 66 .endif 67 movzbl 1(rPC), rINST 68 jmp *dvmAsmInstructionJmpTable(, %edx, 4) 69