blob: e1a53bc74544df0c6cbf22b31652ccc337b56696 [file] [log] [blame]
Duane Sandb43722c2013-03-27 10:53:14 -07001/* libs/opengles/arch-mips/fixed_asm.S
2**
3** Copyright 2012, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18
19 .text
20 .align
21
22/*
23 * this version rounds-to-nearest and saturates numbers
24 * outside the range (but not NaNs).
25 */
26
27 .global gglFloatToFixed
28 .ent gglFloatToFixed
29 .type gglFloatToFixed, @function
30gglFloatToFixed:
31#if !defined(__mips_soft_float)
32 mfc1 $a0,$f12
33#endif
34 srl $t0,$a0,31 /* t0 <- sign bit */
35 srl $t1,$a0,23
36 andi $t1,$t1,0xff /* get the e */
37 li $t2,0x8e
38 subu $t1,$t2,$t1 /* t1=127+15-e */
39 blez $t1,0f /* t1<=0? */
40 sll $t2,$a0,8 /* mantissa<<8 */
41 lui $t3,0x8000
42 or $t2,$t2,$t3 /* add the missing 1 */
43 subu $t1,$t1,1
44 srl $v0,$t2,$t1
45 sltiu $t3,$t1,32 /* t3=1 if t1<32, else t3=0. t1>=32 means the float value is too small. */
46 andi $t4,$v0,0x1
47 srl $v0,$v0,1 /* scale to 16.16 */
48 addu $v0,$v0,$t4 /* round-to-nearest */
49 subu $t2,$zero,$v0
50 movn $v0,$t2,$t0 /* if negative? */
51 or $t1,$a0,$zero /* a0=0? */
52 movz $v0,$zero,$t1
53 movz $v0,$zero,$t3 /* t3=0 then res=0 */
54 jr $ra
550:
56 lui $t1,0x8000
57 and $v0,$a0,$t1 /* keep only the sign bit */
58 li $t1,0x7fffffff
59 movz $v0,$t1,$t0 /* positive, maximum value */
60 jr $ra
61 .end gglFloatToFixed