fpbits.h (9899:0392ef94d766) fpbits.h (10480:5d4ebc92d32e)
1/*
2 * Copyright (c) 2013, Andreas Sandberg
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *

--- 52 unchanged lines hidden (view full) ---

61#define BUILD_IFP64(sign, frac, exp) \
62 ((sign) ? FP64_SIGN_BIT : 0) | \
63 (((uint64_t)(exp) << FP64_EXP_SHIFT) & FP64_EXP_MASK) | \
64 ((frac) & FP64_FRAC_MASK)
65
66#define BUILD_FP64(sign, frac, exp) \
67 { .bits = BUILD_IFP64(sign, frac, exp) }
68
1/*
2 * Copyright (c) 2013, Andreas Sandberg
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *

--- 52 unchanged lines hidden (view full) ---

61#define BUILD_IFP64(sign, frac, exp) \
62 ((sign) ? FP64_SIGN_BIT : 0) | \
63 (((uint64_t)(exp) << FP64_EXP_SHIFT) & FP64_EXP_MASK) | \
64 ((frac) & FP64_FRAC_MASK)
65
66#define BUILD_FP64(sign, frac, exp) \
67 { .bits = BUILD_IFP64(sign, frac, exp) }
68
69static inline fp64_t
70build_fp64(int sign, uint64_t frac, int exp)
71{
72 const fp64_t f = BUILD_FP64(sign, frac, exp);
73
74 return f;
75}
76
69#define BUILD_FP80_SE(sign, exp) \
70 ((sign) ? FP80_SIGN_BIT : 0) | \
71 ((exp) & FP80_EXP_MASK)
72
73#define BUILD_FP80_FI(frac, exp) \
74 ((exp) ? FP80_INT_BIT : 0) | \
75 ((frac) & FP80_FRAC_MASK)
76
77#define BUILD_FP80(sign, frac, exp) \
78 { \
79 .repr.se = BUILD_FP80_SE(sign, exp), \
80 .repr.fi = BUILD_FP80_FI(frac, exp) \
81 }
82
77#define BUILD_FP80_SE(sign, exp) \
78 ((sign) ? FP80_SIGN_BIT : 0) | \
79 ((exp) & FP80_EXP_MASK)
80
81#define BUILD_FP80_FI(frac, exp) \
82 ((exp) ? FP80_INT_BIT : 0) | \
83 ((frac) & FP80_FRAC_MASK)
84
85#define BUILD_FP80(sign, frac, exp) \
86 { \
87 .repr.se = BUILD_FP80_SE(sign, exp), \
88 .repr.fi = BUILD_FP80_FI(frac, exp) \
89 }
90
91static inline fp80_t
92build_fp80(int sign, uint64_t frac, int exp)
93{
94 const fp80_t f = BUILD_FP80(sign, frac, exp);
95
96 return f;
97}
98
83#define FP80_FRAC(fp80) \
84 (fp80.repr.fi & FP80_FRAC_MASK)
85
86#define FP80_EXP(fp80) \
87 (fp80.repr.se & FP80_EXP_MASK)
88
89#define FP64_FRAC(fp64) \
90 (fp64.bits & FP64_FRAC_MASK)
91
92#define FP64_EXP(fp80) \
93 ((fp64.bits & FP64_EXP_MASK) >> FP64_EXP_SHIFT)
94
99#define FP80_FRAC(fp80) \
100 (fp80.repr.fi & FP80_FRAC_MASK)
101
102#define FP80_EXP(fp80) \
103 (fp80.repr.se & FP80_EXP_MASK)
104
105#define FP64_FRAC(fp64) \
106 (fp64.bits & FP64_FRAC_MASK)
107
108#define FP64_EXP(fp80) \
109 ((fp64.bits & FP64_EXP_MASK) >> FP64_EXP_SHIFT)
110
111
95#endif
112#endif