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_BB 1, %eax # %eax<- BB 36 FETCH_CCs 1, %ecx # %ecx<- +CC, sign-extended literal 37 cmp $$0, %ecx # check for divide by zero 38 GET_VREG %eax # %eax<- vBB 39 je common_errDivideByZero # handle divide by zero 40 41 cmpl $$-1, %ecx # handle -1 special case divide error 42 jne .L${opcode}_noerror 43 cmpl $$0x80000000,%eax # handle min int special case divide error 44 je .L${opcode}_break 45.L${opcode}_noerror: 46 cdq # sign-extend %eax to %edx 47 idiv %ecx # divide %edx:%eax by %ecx 48 #FFETCH_ADV 2, %ecx # %ecx<- next instruction hi; fetch, advance 49 .if $div 50 SET_VREG %eax rINST # vAA<- %eax (quotient) 51 .else 52 SET_VREG %edx rINST # vAA<- %edx (remainder) 53 .endif 54 jmp .L${opcode}_break2 55%break 56.L${opcode}_break: 57 .if $div 58 movl $$0x80000000, (rFP, rINST, 4) # vAA<- min int 59 .else 60 movl $$0, (rFP, rINST, 4) # vAA<- 0 61 .endif 62 63.L${opcode}_break2: 64 FINISH 2 # jump to next instruction 65 #FGETOP_JMP 2, %ecx # jump to next instruction; getop, jmp 66