forked from libdfp/libdfp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdfptypeconv.c
104 lines (86 loc) · 2.56 KB
/
dfptypeconv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* DFP_C_TYPE to/from IEEE DFP type conversion routines definitions
Copyright (C) 2006 IBM Corporation.
Copyright (C) 2007-2014 Free Software Foundation.
This file is part of the Decimal Floating Point C Library.
Author(s): Pete Eberlein <[email protected]>
The Decimal Floating Point C Library is free software; you can
redistribute it and/or modify it under the terms of the GNU Lesser
General Public License version 2.1.
The Decimal Floating Point C Library is distributed in the hope that
it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU Lesser General Public License version 2.1 for more details.
You should have received a copy of the GNU Lesser General Public
License version 2.1 along with the Decimal Floating Point C Library;
if not, write to the Free Software Foundation, Inc., 59 Temple Place,
Suite 330, Boston, MA 02111-1307 USA.
Please see libdfp/COPYING.txt for more information. */
#include "dfptypeconv128.h"
#include "dfptypeconv64.h"
#include "dfptypeconv32.h"
#include <endian.h>
static inline void
__copy32 (uint32_t * src, uint32_t * dst)
{
#if __BYTE_ORDER == __BIG_ENDIAN
*dst = *src;
#else
*dst = __builtin_bswap32 (*src);
#endif
}
static inline void
__copy64 (uint64_t * src, uint64_t * dst)
{
#if __BYTE_ORDER == __BIG_ENDIAN
*dst = *src;
#else
*dst = __builtin_bswap64 (*src);
#endif
}
static inline void
__copy128 (uint64_t * src, uint64_t * dst)
{
#if __BYTE_ORDER == __BIG_ENDIAN
*dst = *src;
*(dst + 1) = *(src + 1);
#else
*dst = __builtin_bswap64 (*(src + 1));
*(dst + 1) = __builtin_bswap64 (*src);
#endif
}
void
___host_to_ieee_32 (_Decimal32 * src, decimal32 * dest)
{
__copy32 ((uint32_t *) src, (uint32_t *) dest);
}
void
___host_to_ieee_64 (_Decimal64 * src, decimal64 * dest)
{
__copy64 ((uint64_t *) src, (uint64_t *) dest);
}
void
___host_to_ieee_128 (_Decimal128 * src, decimal128 * dest)
{
__copy128 ((uint64_t *) src, (uint64_t *) dest);
}
void
___ieee_32_to_host (decimal32 * src, _Decimal32 * dest)
{
__copy32 ((uint32_t *) src, (uint32_t *) dest);
}
void
___ieee_64_to_host (decimal64 * src, _Decimal64 * dest)
{
__copy64 ((uint64_t *) src, (uint64_t *) dest);
}
void
___ieee_128_to_host (decimal128 * src, _Decimal128 * dest)
{
__copy128 ((uint64_t *) src, (uint64_t *) dest);
}
hidden_def (___host_to_ieee_32)
hidden_def (___host_to_ieee_64)
hidden_def (___host_to_ieee_128)
hidden_def (___ieee_32_to_host)
hidden_def (___ieee_64_to_host)
hidden_def (___ieee_128_to_host)