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: binopD.S 18 * 19 * Code: 32-bit integer 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, rem-int 24 * 25 * Description: Perform a binary operation on two source 26 * 27 * Format: AA|op CC|BB (23x) 28 * 29 * Syntax: op vAA, vBB, vCC 30 */ 31 32 %default {"div":"1"} 33 34 FETCH_BB 1, %eax # %eax<- BB 35 FETCH_CC 1, %ecx # %ecx<- CC 36 GET_VREG %eax # %eax<- vBB 37 GET_VREG %ecx # %ecx<- vCC 38 cmp $$0, %ecx # check for divide by zero 39 je common_errDivideByZero # handle divide by zero 40 cmpl $$-1, %ecx # handle -1 special case divide error 41 jne .L${opcode}_noerror 42 cmpl $$0x80000000,%eax # handle min int special case divide error 43 je .L${opcode}_break 44 .L${opcode}_noerror: 45 cdq # sign-extend %eax to %edx 46 idiv %ecx # divide %edx:%eax by %ecx 47 .if $div 48 SET_VREG %eax rINST # vAA<- %eax (quotient) 49 .else 50 SET_VREG %edx rINST # vAA<- %edx (remainder) 51 .endif 52 jmp .L${opcode}_break2 53 %break 54 .L${opcode}_break: 55 .if $div 56 movl $$0x80000000, (rFP, rINST, 4) # vAA<- min int 57 .else 58 movl $$0, (rFP, rINST, 4) # vAA<- 0 59 .endif 60 .L${opcode}_break2: 61 FINISH 2 # jump to next instruction 62