📄 ppc_dtoi.s
字号:
/* fpopt/ppc_dtoi.S, pl_FPE_common, pl_linux 11/24/03 16:17:24 */
/*----------------------------------------------------------------------------- */
/* Copyright (c) 2003, IBM Corporation */
/* All rights reserved. */
/* */
/* Redistribution and use in source and binary forms, with or */
/* without modification, are permitted provided that the following */
/* conditions are met: */
/* */
/* * Redistributions of source code must retain the above */
/* copyright notice, this list of conditions and the following */
/* disclaimer. */
/* * Redistributions in binary form must reproduce the above */
/* copyright notice, this list of conditions and the following */
/* disclaimer in the documentation and/or other materials */
/* provided with the distribution. */
/* * Neither the name of IBM nor the names of its contributors */
/* may be used to endorse or promote products derived from this */
/* software without specific prior written permission. */
/* */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, */
/* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, */
/* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR */
/* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
/* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE */
/* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/* */
/*----------------------------------------------------------------------------- */
/* */
/* Function: convert double floating point to 4-byte integer */
/* Input: r3,r4 */
/* Output: r3 */
/* Notes: 1. No stack frame is created for this function, so the following */
/* registers must be preserved, as required by ABI specification: */
/* LR, CR0, R1, R2, R13-R31 */
/* 2. operation performed according to IEEE754-1985 standard. */
/* 3. ISO/ANSI C requires that conversions to integers be rounded */
/* toward zero (in short, leftover fraction bits are truncated). */
/* */
/*----------------------------------------------------------------------------- */
#include <ppc4xx.inc>
#include "fpeLib.inc"
function_prolog(__fixdfsi)
/* Save CR in r6 */
mfcr r6
/* Load up registers with source double */
/* r8 = exp r9 = hifrac r10 = lofrac */
rlwinm r9,r3,0,0x000FFFFF /* extract hifrac */
rlwinm r8,r3,12,0x000007FF /* extract exponent */
/* exponent test for Infinity or xNAN */
cmpi cr0,0,r8,2047 /* test for Infinity or NAN */
beq Infinity_or_NAN
/* exponent test for large operand */
cmpi cr0,0,r8,1053 /* test for large operand */
bgt Large_operand
/* Normal operand processing here */
/* r9 is fraction, left justified */
rlwinm r9,r9,10,0x3FFFFc00 /* r9[1:20] = r9[12:31] */
rlwimi r9,r4,10,0x000003FF /* r9[21:31] = r4[0:10] */
cmpi cr0,0,r8,0 /* test exp for 0 */
addic. r8,r8,-1022 /* exp = exp - 1022 */
beq Zero_exp
addic. r8,r8,-1 /* exp = exp - 1023 */
oris r9,r9,0x4000 /* set hi order bit of r9 */
Zero_exp:
blt Zeros /* fraction only, return 0 */
subfic r0,r8,31
or. r0,r0,r0
mtctr r0
b ltest
cloop:
/* shift frac right by 1, zero fill */
rlwinm r9,r9,31,0x7FFFFFFF /* shift hifrac right by 1, zero fill */
ltest:
bdnz cloop
/* Form final result */
or. r3,r3,r3 /* set CR for sign bit */
bge fin_pos
/* sign is negative */
nand r9,r9,r9 /* ones comp of r9 */
addi r9,r9,1 /* now 2's complement */
fin_pos:
/* check size of result */
or. r3,r9,r9 /* check for zero and set return value */
beq Zeros
return_results: /* r3 contains signed integer result */
mtcr r6 /* restore CR */
blr
/* Infinity or a NAN */
Infinity_or_NAN:
or. r0,r9,r4 /* test rest for zero (infinity test) */
bne NAN
/* Infinity if here (also, Large operand) */
Large_operand:
or. r3,r3,r3
blt Neg_infinity
/* form value for converted positive infinity */
lis r3,0x7FFF
ori r3,r3,0xFFFF
b return_results
Neg_infinity:
lis r3,0x8000
b return_results
NAN:
lis r3,0x8000
b return_results
Zeros:
li r3,0 /* Store zero */
b return_results
function_epilog(__fixdfsi)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -