]>
Commit | Line | Data |
---|---|---|
3d9156a7 A |
1 | /* |
2 | * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. Please obtain a copy of the License at | |
10 | * http:www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
12 | * | |
13 | * The Original Code and all software distributed under the License are | |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
20 | * | |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | ||
24 | #include <sys/cdefs.h> | |
25 | #include <stdint.h> | |
26 | #include <strings.h> | |
27 | #include <float.h> | |
28 | #include <math.h> | |
29 | #include <alloca.h> | |
30 | ||
31 | #include "fpmath.h" | |
32 | ||
33 | #define BITS64 64 | |
34 | #define DBL_BIAS (DBL_MAX_EXP - 1) | |
35 | #define DBL_SUBEXP (-DBL_BIAS + 1) | |
36 | #define LL_BITS (8 * sizeof(int64_t)) | |
37 | #define LL_HIGHBIT (1LL << 63) | |
38 | ||
39 | __private_extern__ void | |
40 | _ldbl2array32dd(union IEEEl2bits u, uint32_t *a) | |
41 | { | |
42 | int bit, shift, highbit; | |
43 | uint64_t a64[2]; | |
44 | int64_t t64; | |
45 | ||
46 | bzero(a64, 2 * sizeof(*a64)); | |
47 | ||
48 | switch (__fpclassifyd(u.d[0])) { | |
49 | case FP_NORMAL: | |
50 | a64[1] = (1LL << (LDBL_MANT_DIG - BITS64 - 1)); | |
51 | /* drop through */ | |
52 | case FP_SUBNORMAL: | |
53 | a64[1] |= ((uint64_t)u.bits.manh >> (BITS64 - LDBL_MANL_SIZE)); | |
54 | a64[0] = ((uint64_t)u.bits.manh << LDBL_MANL_SIZE); | |
55 | break; | |
56 | default: | |
57 | goto done; | |
58 | } | |
59 | ||
60 | switch (__fpclassifyd(u.d[1])) { | |
61 | case FP_NORMAL: | |
62 | bit = LDBL_MANT_DIG - (int)u.bits.exp + (int)u.bits.exp2 - 1; | |
63 | t64 = (1LL << bit); | |
64 | break; | |
65 | case FP_SUBNORMAL: | |
66 | bit = LDBL_MANT_DIG - (int)u.bits.exp; | |
67 | t64 = 0; | |
68 | break; | |
69 | default: | |
70 | goto done; | |
71 | } | |
72 | shift = LDBL_MANL_SIZE - bit - 1; | |
73 | if (shift >= 0) | |
74 | t64 |= (u.bits.manl >> shift); | |
75 | else | |
76 | t64 |= (u.bits.manl << (-shift)); | |
77 | highbit = ((a64[0] & LL_HIGHBIT) != 0); | |
78 | if (u.bits.sign == u.bits.sign2) { | |
79 | a64[0] += t64; | |
80 | if (highbit && !(a64[0] & LL_HIGHBIT)) /* carry */ | |
81 | a64[1]++; | |
82 | } else { | |
83 | a64[0] -= t64; | |
84 | if (!highbit && (a64[0] & LL_HIGHBIT)) /* borrow */ | |
85 | a64[1]--; | |
86 | } | |
87 | ||
88 | done: | |
89 | a[0] = (uint32_t)a64[0]; | |
90 | a[1] = (uint32_t)(a64[0] >> 32); | |
91 | a[2] = (uint32_t)a64[1]; | |
92 | a[3] = (uint32_t)(a64[1] >> 32); | |
93 | } |