1 /**
2 University of Illinois/NCSA
3 Open Source License
4
5 Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT
6
7 All rights reserved.
8
9 Developed by:
10
11 LLVM Team
12
13 University of Illinois at Urbana-Champaign
14
15 http://llvm.org
16
17 Permission is hereby granted, free of charge, to any person obtaining a copy of
18 this software and associated documentation files (the "Software"), to deal with
19 the Software without restriction, including without limitation the rights to
20 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
21 of the Software, and to permit persons to whom the Software is furnished to do
22 so, subject to the following conditions:
23
24 * Redistributions of source code must retain the above copyright notice,
25 this list of conditions and the following disclaimers.
26
27 * Redistributions in binary form must reproduce the above copyright notice,
28 this list of conditions and the following disclaimers in the
29 documentation and/or other materials provided with the distribution.
30
31 * Neither the names of the LLVM Team, University of Illinois at
32 Urbana-Champaign, nor the names of its contributors may be used to
33 endorse or promote products derived from this Software without specific
34 prior written permission.
35
36 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
37 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
38 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
39 CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
40 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
41 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
42 SOFTWARE.
43 **/
44
45 #include "int_lib.h"
46
47 /* Returns: convert a to a unsigned int, rounding toward zero.
48 * Negative values all become zero.
49 */
50
51 /* Assumption: double is a IEEE 64 bit floating point type
52 * su_int is a 32 bit integral type
53 * value in double is representable in su_int or is negative
54 * (no range checking performed)
55 */
56
57 /* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */
58
ARM_EABI_FNALIAS(d2uiz,fixunsdfsi)59 ARM_EABI_FNALIAS(d2uiz, fixunsdfsi)
60
61 COMPILER_RT_ABI su_int
62 __fixunsdfsi(double a)
63 {
64 double_bits fb;
65 fb.f = a;
66 int e = ((fb.u.s.high & 0x7FF00000) >> 20) - 1023;
67 if (e < 0 || (fb.u.s.high & 0x80000000))
68 return 0;
69 return (
70 0x80000000u |
71 ((fb.u.s.high & 0x000FFFFF) << 11) |
72 (fb.u.s.low >> 21)
73 ) >> (31 - e);
74 }
75