122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch   /* Copyright (C) 2008 The Android Open Source Project
222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * Licensed under the Apache License, Version 2.0 (the "License");
422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * you may not use this file except in compliance with the License.
522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * You may obtain a copy of the License at
622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * http://www.apache.org/licenses/LICENSE-2.0
822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * Unless required by applicable law or agreed to in writing, software
1022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * distributed under the License is distributed on an "AS IS" BASIS,
1122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * See the License for the specific language governing permissions and
1322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * limitations under the License.
1422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    */
1522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
1622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch   /*
1722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * File: OP_DOUBLE_TO_INT.S
1822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
1922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * Code: Converts a double to an integer. Uses no substitutions.
2022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
2122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * For: double-to-int
2222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
2322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * Description: Convert the source register (a double) to an integer
2422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *              and store the result in the destination register
2522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
2622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * Format: B|A|op (12x)
2722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    *
2822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    * Syntax: op vA, vB
2922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    */
3022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
3122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        rINST, %edx             # %edx<- BA
3222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    shr         $$4, rINST              # rINST<- B
3322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    and         $$15, %edx              # %edx<- A
3422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    fldl        (rFP, rINST, 4)         # load &vB
3522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    fildl       .LintMax                # push max int value
3622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    fildl       .LintMin                # push min int value
3722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    fucomip     %st(2), %st(0)          # check for negInf
3822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    jae         .L${opcode}_negInf      # handle negInf
3922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    fucomip     %st(1), %st(0)          # check for posInf or NaN
4022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    jc          .L${opcode}_nanInf      # handle posInf or NaN
4122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    jmp         .L${opcode}_break       # do conversion
4222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch%break
4322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
4422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch.L${opcode}_break:
4522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    fnstcw      -2(%esp)                # save control word
4622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    orl         $$0xc00, -2(%esp)       # reset control
4722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    fldcw       -2(%esp)                # load control word
4822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    xorl        $$0xc00, -2(%esp)       # reset control
4922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    fistpl      (rFP, %edx, 4)          # move converted int
5022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    fldcw       -2(%esp)                # load saved control word
5122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    FINISH      1                       # jump to next instruction
5222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
5322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch.L${opcode}_nanInf:
5422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    jnp         .L${opcode}_posInf
5522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    fstps       (rFP, %edx, 4)
5622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        $$0x00000000,  (rFP, %edx, 4) # vA<- NaN
5722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    FINISH      1                       # jump to next instruction
5822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
5922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch.L${opcode}_posInf:
6022d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    fstps       (rFP, %edx, 4)
6122d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        $$0x7FFFFFFF,  (rFP, %edx, 4) # vA<- posInf
6222d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    FINISH      1                       # jump to next instruction
6322d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
6422d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch.L${opcode}_negInf:
6522d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    fstps       (rFP, %edx, 4)
6622d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    fstps       (rFP, %edx, 4)
6722d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    movl        $$0x80000000,  (rFP, %edx, 4) # vA<- negInf
6822d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch    FINISH      1                       # jump to next instruction
6922d404a75a00cda0b0ebed1034c2808ba060b05fJohnnie Birch
70