• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/* libs/opengles/fixed_asm.S
2**
3** Copyright 2006, 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    .global gglFloatToFixed
23    .global gglFloatToFixedFast
24
25
26/*
27 * Converts a float to a s15.16 fixed-point number.
28 * this doesn't handle floats out of the [-32768, +32768[ range
29 * and doesn't performs round-to-nearest.
30 * however, it's very fast :-)
31 */
32
33gglFloatToFixedFast:
34        movs    r1, r0, lsl #1          /* remove bit sign */
35        mov     r2, #0x8E               /* 127 + 15 */
36        sub     r1, r2, r1, lsr #24     /* compute shift */
37        mov     r2, r0, lsl #8          /* mantissa<<8 */
38        orr     r2, r2, #0x80000000     /* add the missing 1 */
39        mov     r0, r2, lsr r1          /* scale to 16.16 */
40        rsbcs   r0, r0, #0              /* negate if needed */
41        bx      lr
42
43/*
44 * this version rounds-to-nearest and saturates numbers
45 * outside the range (but not NaNs).
46 */
47
48gglFloatToFixed:
49        mov     r1, r0, lsl #1          /* remove bit sign */
50        mov     r2, #0x8E               /* 127 + 15 */
51        subs    r1, r2, r1, lsr #24     /* compute shift */
52        bls     0f                      /* too big */
53        mov     r2, r0, lsl #8          /* mantissa<<8 */
54        orr     r2, r2, #0x80000000     /* add the missing 1 */
55        mov     r3, r0
56        movs    r0, r2, lsr r1          /* scale to 16.16 */
57        addcs   r0, r0, #1              /* round-to-nearest */
58        tst     r3, #0x80000000         /* negative? */
59        rsbne   r0, r0, #0              /* negate if needed */
60        bx      lr
61
620:      ands    r0, r0, #0x80000000     /* keep only the sign bit */
63        moveq   r0, #0x7fffffff         /* positive, maximum value */
64        bx      lr
65
66