2 * wrappers.c - wrappers to modify output of MPFR/MPC test functions
4 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 * See https://llvm.org/LICENSE.txt for license information.
6 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
15 void wrapper_init(wrapperctx
*ctx
)
18 ctx
->nops
= ctx
->nresults
= 0;
19 for (i
= 0; i
< 2; i
++) {
20 ctx
->mpfr_ops
[i
] = NULL
;
21 ctx
->mpc_ops
[i
] = NULL
;
22 ctx
->ieee_ops
[i
] = NULL
;
24 ctx
->mpfr_result
= NULL
;
25 ctx
->mpc_result
= NULL
;
26 ctx
->ieee_result
= NULL
;
30 void wrapper_op_real(wrapperctx
*ctx
, const mpfr_t r
,
31 int size
, const uint32
*ieee
)
33 assert(ctx
->nops
< 2);
34 ctx
->mpfr_ops
[ctx
->nops
] = r
;
35 ctx
->ieee_ops
[ctx
->nops
] = ieee
;
36 ctx
->size_ops
[ctx
->nops
] = size
;
40 void wrapper_op_complex(wrapperctx
*ctx
, const mpc_t c
,
41 int size
, const uint32
*ieee
)
43 assert(ctx
->nops
< 2);
44 ctx
->mpc_ops
[ctx
->nops
] = c
;
45 ctx
->ieee_ops
[ctx
->nops
] = ieee
;
46 ctx
->size_ops
[ctx
->nops
] = size
;
50 void wrapper_result_real(wrapperctx
*ctx
, mpfr_t r
,
51 int size
, uint32
*ieee
)
53 assert(ctx
->nresults
< 1);
55 ctx
->ieee_result
= ieee
;
56 ctx
->size_result
= size
;
60 void wrapper_result_complex(wrapperctx
*ctx
, mpc_t c
,
61 int size
, uint32
*ieee
)
63 assert(ctx
->nresults
< 1);
65 ctx
->ieee_result
= ieee
;
66 ctx
->size_result
= size
;
70 int wrapper_run(wrapperctx
*ctx
, wrapperfunc wrappers
[MAXWRAPPERS
])
73 for (i
= 0; i
< MAXWRAPPERS
&& wrappers
[i
]; i
++)
75 universal_wrapper(ctx
);
76 return ctx
->need_regen
;
79 mpfr_srcptr
wrapper_get_mpfr(wrapperctx
*ctx
, int op
)
82 assert(ctx
->mpfr_result
);
83 return ctx
->mpfr_result
;
85 assert(ctx
->mpfr_ops
[op
]);
86 return ctx
->mpfr_ops
[op
];
90 const uint32
*wrapper_get_ieee(wrapperctx
*ctx
, int op
)
93 assert(ctx
->mpfr_result
);
94 return ctx
->ieee_result
;
96 assert(ctx
->mpfr_ops
[op
]);
97 return ctx
->ieee_ops
[op
];
101 int wrapper_get_nops(wrapperctx
*ctx
)
106 int wrapper_get_size(wrapperctx
*ctx
, int op
)
109 assert(ctx
->mpfr_result
|| ctx
->mpc_result
);
110 return ctx
->size_result
;
112 assert(ctx
->mpfr_ops
[op
] || ctx
->mpc_ops
[op
]);
113 return ctx
->size_ops
[op
];
117 int wrapper_is_complex(wrapperctx
*ctx
, int op
)
120 assert(ctx
->mpfr_result
|| ctx
->mpc_result
);
121 return ctx
->mpc_result
!= NULL
;
123 assert(ctx
->mpfr_ops
[op
] || ctx
->mpc_ops
[op
]);
124 return ctx
->mpc_ops
[op
] != NULL
;
128 mpc_srcptr
wrapper_get_mpc(wrapperctx
*ctx
, int op
)
131 assert(ctx
->mpc_result
);
132 return ctx
->mpc_result
;
134 assert(ctx
->mpc_ops
[op
]);
135 return ctx
->mpc_ops
[op
];
139 mpfr_srcptr
wrapper_get_mpfr_r(wrapperctx
*ctx
, int op
)
142 assert(ctx
->mpc_result
);
143 return mpc_realref(ctx
->mpc_result
);
145 assert(ctx
->mpc_ops
[op
]);
146 return mpc_realref(ctx
->mpc_ops
[op
]);
150 mpfr_srcptr
wrapper_get_mpfr_i(wrapperctx
*ctx
, int op
)
153 assert(ctx
->mpc_result
);
154 return mpc_imagref(ctx
->mpc_result
);
156 assert(ctx
->mpc_ops
[op
]);
157 return mpc_imagref(ctx
->mpc_ops
[op
]);
161 const uint32
*wrapper_get_ieee_r(wrapperctx
*ctx
, int op
)
164 assert(ctx
->mpc_result
);
165 return ctx
->ieee_result
;
167 assert(ctx
->mpc_ops
[op
]);
168 return ctx
->ieee_ops
[op
];
172 const uint32
*wrapper_get_ieee_i(wrapperctx
*ctx
, int op
)
175 assert(ctx
->mpc_result
);
176 return ctx
->ieee_result
+ 4;
178 assert(ctx
->mpc_ops
[op
]);
179 return ctx
->ieee_ops
[op
] + 2;
183 void wrapper_set_sign(wrapperctx
*ctx
, uint32 sign
)
185 assert(ctx
->mpfr_result
);
186 ctx
->ieee_result
[0] |= (sign
& 0x80000000U
);
189 void wrapper_set_sign_r(wrapperctx
*ctx
, uint32 sign
)
191 assert(ctx
->mpc_result
);
192 ctx
->ieee_result
[0] |= (sign
& 0x80000000U
);
195 void wrapper_set_sign_i(wrapperctx
*ctx
, uint32 sign
)
197 assert(ctx
->mpc_result
);
198 ctx
->ieee_result
[4] |= (sign
& 0x80000000U
);
201 void wrapper_set_nan(wrapperctx
*ctx
)
203 assert(ctx
->mpfr_result
);
204 mpfr_set_nan(ctx
->mpfr_result
);
208 void wrapper_set_nan_r(wrapperctx
*ctx
)
210 assert(ctx
->mpc_result
);
211 mpfr_set_nan(mpc_realref(ctx
->mpc_result
)); /* FIXME: better way? */
215 void wrapper_set_nan_i(wrapperctx
*ctx
)
217 assert(ctx
->mpc_result
);
218 mpfr_set_nan(mpc_imagref(ctx
->mpc_result
)); /* FIXME: better way? */
222 void wrapper_set_int(wrapperctx
*ctx
, int val
)
224 assert(ctx
->mpfr_result
);
225 mpfr_set_si(ctx
->mpfr_result
, val
, GMP_RNDN
);
229 void wrapper_set_int_r(wrapperctx
*ctx
, int val
)
231 assert(ctx
->mpc_result
);
232 mpfr_set_si(mpc_realref(ctx
->mpc_result
), val
, GMP_RNDN
);
236 void wrapper_set_int_i(wrapperctx
*ctx
, int val
)
238 assert(ctx
->mpc_result
);
239 mpfr_set_si(mpc_realref(ctx
->mpc_result
), val
, GMP_RNDN
);
243 void wrapper_set_mpfr(wrapperctx
*ctx
, const mpfr_t val
)
245 assert(ctx
->mpfr_result
);
246 mpfr_set(ctx
->mpfr_result
, val
, GMP_RNDN
);
250 void wrapper_set_mpfr_r(wrapperctx
*ctx
, const mpfr_t val
)
252 assert(ctx
->mpc_result
);
253 mpfr_set(mpc_realref(ctx
->mpc_result
), val
, GMP_RNDN
);
257 void wrapper_set_mpfr_i(wrapperctx
*ctx
, const mpfr_t val
)
259 assert(ctx
->mpc_result
);
260 mpfr_set(mpc_realref(ctx
->mpc_result
), val
, GMP_RNDN
);