aboutsummaryrefslogtreecommitdiff
path: root/tests/fp/wrap.c.inc
blob: 9ff884c140be82487f4d63e585b6cfc092c6f230 (plain)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
/*
 * In this file we wrap QEMU FP functions to look like softfloat/testfloat's,
 * so that we can use the testfloat infrastructure as-is.
 *
 * This file must be included directly from fp-test.c. We could compile it
 * separately, but it would be tedious to add declarations for all the wrappers.
 */

static signed char sf_tininess_to_qemu(uint_fast8_t mode)
{
    switch (mode) {
    case softfloat_tininess_beforeRounding:
        return float_tininess_before_rounding;
    case softfloat_tininess_afterRounding:
        return float_tininess_after_rounding;
    default:
        g_assert_not_reached();
    }
}

static signed char sf_rounding_to_qemu(uint_fast8_t mode)
{
    switch (mode) {
    case softfloat_round_near_even:
        return float_round_nearest_even;
    case softfloat_round_minMag:
        return float_round_to_zero;
    case softfloat_round_min:
        return float_round_down;
    case softfloat_round_max:
        return float_round_up;
    case softfloat_round_near_maxMag:
        return float_round_ties_away;
    case softfloat_round_odd:
        return float_round_to_odd;
    default:
        g_assert_not_reached();
    }
}

static uint_fast8_t qemu_flags_to_sf(uint8_t qflags)
{
    uint_fast8_t ret = 0;

    if (qflags & float_flag_invalid) {
        ret |= softfloat_flag_invalid;
    }
    if (qflags & float_flag_divbyzero) {
        ret |= softfloat_flag_infinite;
    }
    if (qflags & float_flag_overflow) {
        ret |= softfloat_flag_overflow;
    }
    if (qflags & float_flag_underflow) {
        ret |= softfloat_flag_underflow;
    }
    if (qflags & float_flag_inexact) {
        ret |= softfloat_flag_inexact;
    }
    return ret;
}

/*
 * floatx80 and float128 cannot be cast between qemu and softfloat, because
 * in softfloat the order of the fields depends on the host's endianness.
 */
static extFloat80_t qemu_to_soft80(floatx80 a)
{
    extFloat80_t ret;

    ret.signif = a.low;
    ret.signExp = a.high;
    return ret;
}

static floatx80 soft_to_qemu80(extFloat80_t a)
{
    floatx80 ret;

    ret.low = a.signif;
    ret.high = a.signExp;
    return ret;
}

static float128_t qemu_to_soft128(float128 a)
{
    float128_t ret;
    struct uint128 *to = (struct uint128 *)&ret;

    to->v0 = a.low;
    to->v64 = a.high;
    return ret;
}

static float128 soft_to_qemu128(float128_t a)
{
    struct uint128 *from = (struct uint128 *)&a;
    float128 ret;

    ret.low = from->v0;
    ret.high = from->v64;
    return ret;
}

/* conversions */
#define WRAP_SF_TO_SF_IEEE(name, func, a_type, b_type)  \
    static b_type##_t name(a_type##_t a)                \
    {                                                   \
        a_type *ap = (a_type *)&a;                      \
        b_type ret;                                     \
                                                        \
        ret = func(*ap, true, &qsf);                    \
        return *(b_type##_t *)&ret;                     \
    }

WRAP_SF_TO_SF_IEEE(qemu_f16_to_f32, float16_to_float32, float16, float32)
WRAP_SF_TO_SF_IEEE(qemu_f16_to_f64, float16_to_float64, float16, float64)

WRAP_SF_TO_SF_IEEE(qemu_f32_to_f16, float32_to_float16, float32, float16)
WRAP_SF_TO_SF_IEEE(qemu_f64_to_f16, float64_to_float16, float64, float16)
#undef WRAP_SF_TO_SF_IEEE

#define WRAP_SF_TO_SF(name, func, a_type, b_type)       \
    static b_type##_t name(a_type##_t a)                \
    {                                                   \
        a_type *ap = (a_type *)&a;                      \
        b_type ret;                                     \
                                                        \
        ret = func(*ap, &qsf);                          \
        return *(b_type##_t *)&ret;                     \
    }

WRAP_SF_TO_SF(qemu_f32_to_f64, float32_to_float64, float32, float64)
WRAP_SF_TO_SF(qemu_f64_to_f32, float64_to_float32, float64, float32)
#undef WRAP_SF_TO_SF

#define WRAP_SF_TO_80(name, func, type)                 \
    static void name(type##_t a, extFloat80_t *res)     \
    {                                                   \
        floatx80 ret;                                   \
        type *ap = (type *)&a;                          \
                                                        \
        ret = func(*ap, &qsf);                          \
        *res = qemu_to_soft80(ret);                     \
    }

WRAP_SF_TO_80(qemu_f32_to_extF80M, float32_to_floatx80, float32)
WRAP_SF_TO_80(qemu_f64_to_extF80M, float64_to_floatx80, float64)
#undef WRAP_SF_TO_80

#define WRAP_SF_TO_128(name, func, type)                \
    static void name(type##_t a, float128_t *res)       \
    {                                                   \
        float128 ret;                                   \
        type *ap = (type *)&a;                          \
                                                        \
        ret = func(*ap, &qsf);                          \
        *res = qemu_to_soft128(ret);                    \
    }

WRAP_SF_TO_128(qemu_f32_to_f128M, float32_to_float128, float32)
WRAP_SF_TO_128(qemu_f64_to_f128M, float64_to_float128, float64)
#undef WRAP_SF_TO_128

/* Note: exact is ignored since qemu's softfloat assumes it is set */
#define WRAP_SF_TO_INT(name, func, type, fast_type)                     \
    static fast_type name(type##_t a, uint_fast8_t round, bool exact)   \
    {                                                                   \
        type *ap = (type *)&a;                                          \
                                                                        \
        qsf.float_rounding_mode = sf_rounding_to_qemu(round);           \
        return func(*ap, &qsf);                                         \
    }

WRAP_SF_TO_INT(qemu_f16_to_ui32, float16_to_uint32, float16, uint_fast32_t)
WRAP_SF_TO_INT(qemu_f16_to_ui64, float16_to_uint64, float16, uint_fast64_t)

WRAP_SF_TO_INT(qemu_f32_to_ui32, float32_to_uint32, float32, uint_fast32_t)
WRAP_SF_TO_INT(qemu_f32_to_ui64, float32_to_uint64, float32, uint_fast64_t)

WRAP_SF_TO_INT(qemu_f64_to_ui32, float64_to_uint32, float64, uint_fast32_t)
WRAP_SF_TO_INT(qemu_f64_to_ui64, float64_to_uint64, float64, uint_fast64_t)

WRAP_SF_TO_INT(qemu_f16_to_i32, float16_to_int32, float16, int_fast32_t)
WRAP_SF_TO_INT(qemu_f16_to_i64, float16_to_int64, float16, int_fast64_t)

WRAP_SF_TO_INT(qemu_f32_to_i32, float32_to_int32, float32, int_fast32_t)
WRAP_SF_TO_INT(qemu_f32_to_i64, float32_to_int64, float32, int_fast64_t)

WRAP_SF_TO_INT(qemu_f64_to_i32, float64_to_int32, float64, int_fast32_t)
WRAP_SF_TO_INT(qemu_f64_to_i64, float64_to_int64, float64, int_fast64_t)
#undef WRAP_SF_TO_INT

/* Note: exact is ignored since qemu's softfloat assumes it is set */
#define WRAP_SF_TO_INT_MINMAG(name, func, type, fast_type)      \
    static fast_type name(type##_t a, bool exact)               \
    {                                                           \
        type *ap = (type *)&a;                                  \
                                                                \
        return func(*ap, &qsf);                                 \
    }

WRAP_SF_TO_INT_MINMAG(qemu_f16_to_ui32_r_minMag,
                      float16_to_uint32_round_to_zero, float16, uint_fast32_t)
WRAP_SF_TO_INT_MINMAG(qemu_f16_to_ui64_r_minMag,
                      float16_to_uint64_round_to_zero, float16, uint_fast64_t)

WRAP_SF_TO_INT_MINMAG(qemu_f16_to_i32_r_minMag,
                      float16_to_int32_round_to_zero, float16, int_fast32_t)
WRAP_SF_TO_INT_MINMAG(qemu_f16_to_i64_r_minMag,
                      float16_to_int64_round_to_zero, float16, int_fast64_t)

WRAP_SF_TO_INT_MINMAG(qemu_f32_to_ui32_r_minMag,
                      float32_to_uint32_round_to_zero, float32, uint_fast32_t)
WRAP_SF_TO_INT_MINMAG(qemu_f32_to_ui64_r_minMag,
                      float32_to_uint64_round_to_zero, float32, uint_fast64_t)

WRAP_SF_TO_INT_MINMAG(qemu_f32_to_i32_r_minMag,
                      float32_to_int32_round_to_zero, float32, int_fast32_t)
WRAP_SF_TO_INT_MINMAG(qemu_f32_to_i64_r_minMag,
                      float32_to_int64_round_to_zero, float32, int_fast64_t)

WRAP_SF_TO_INT_MINMAG(qemu_f64_to_ui32_r_minMag,
                      float64_to_uint32_round_to_zero, float64, uint_fast32_t)
WRAP_SF_TO_INT_MINMAG(qemu_f64_to_ui64_r_minMag,
                      float64_to_uint64_round_to_zero, float64, uint_fast64_t)

WRAP_SF_TO_INT_MINMAG(qemu_f64_to_i32_r_minMag,
                      float64_to_int32_round_to_zero, float64, int_fast32_t)
WRAP_SF_TO_INT_MINMAG(qemu_f64_to_i64_r_minMag,
                      float64_to_int64_round_to_zero, float64, int_fast64_t)
#undef WRAP_SF_TO_INT_MINMAG

#define WRAP_80_TO_SF(name, func, type)                 \
    static type##_t name(const extFloat80_t *ap)        \
    {                                                   \
        floatx80 a;                                     \
        type ret;                                       \
                                                        \
        a = soft_to_qemu80(*ap);                        \
        ret = func(a, &qsf);                            \
        return *(type##_t *)&ret;                       \
    }

WRAP_80_TO_SF(qemu_extF80M_to_f32, floatx80_to_float32, float32)
WRAP_80_TO_SF(qemu_extF80M_to_f64, floatx80_to_float64, float64)
#undef WRAP_80_TO_SF

#define WRAP_128_TO_SF(name, func, type)        \
    static type##_t name(const float128_t *ap)  \
    {                                           \
        float128 a;                             \
        type ret;                               \
                                                \
        a = soft_to_qemu128(*ap);               \
        ret = func(a, &qsf);                    \
        return *(type##_t *)&ret;               \
    }

WRAP_128_TO_SF(qemu_f128M_to_f32, float128_to_float32, float32)
WRAP_128_TO_SF(qemu_f128M_to_f64, float128_to_float64, float64)
#undef WRAP_128_TO_SF

static void qemu_extF80M_to_f128M(const extFloat80_t *from, float128_t *to)
{
    floatx80 qfrom;
    float128 qto;

    qfrom = soft_to_qemu80(*from);
    qto = floatx80_to_float128(qfrom, &qsf);
    *to = qemu_to_soft128(qto);
}

static void qemu_f128M_to_extF80M(const float128_t *from, extFloat80_t *to)
{
    float128 qfrom;
    floatx80 qto;

    qfrom = soft_to_qemu128(*from);
    qto = float128_to_floatx80(qfrom, &qsf);
    *to = qemu_to_soft80(qto);
}

#define WRAP_INT_TO_SF(name, func, int_type, type)      \
    static type##_t name(int_type a)                    \
    {                                                   \
        type ret;                                       \
                                                        \
        ret = func(a, &qsf);                            \
        return *(type##_t *)&ret;                       \
    }

WRAP_INT_TO_SF(qemu_ui32_to_f16, uint32_to_float16, uint32_t, float16)
WRAP_INT_TO_SF(qemu_ui32_to_f32, uint32_to_float32, uint32_t, float32)
WRAP_INT_TO_SF(qemu_ui32_to_f64, uint32_to_float64, uint32_t, float64)

WRAP_INT_TO_SF(qemu_ui64_to_f16, uint64_to_float16, uint64_t, float16)
WRAP_INT_TO_SF(qemu_ui64_to_f32, uint64_to_float32, uint64_t, float32)
WRAP_INT_TO_SF(qemu_ui64_to_f64, uint64_to_float64, uint64_t, float64)

WRAP_INT_TO_SF(qemu_i32_to_f16, int32_to_float16, int32_t, float16)
WRAP_INT_TO_SF(qemu_i32_to_f32, int32_to_float32, int32_t, float32)
WRAP_INT_TO_SF(qemu_i32_to_f64, int32_to_float64, int32_t, float64)

WRAP_INT_TO_SF(qemu_i64_to_f16, int64_to_float16, int64_t, float16)
WRAP_INT_TO_SF(qemu_i64_to_f32, int64_to_float32, int64_t, float32)
WRAP_INT_TO_SF(qemu_i64_to_f64, int64_to_float64, int64_t, float64)
#undef WRAP_INT_TO_SF

#define WRAP_INT_TO_80(name, func, int_type)            \
    static void name(int_type a, extFloat80_t *res)     \
    {                                                   \
        floatx80 ret;                                   \
                                                        \
        ret = func(a, &qsf);                            \
        *res = qemu_to_soft80(ret);                     \
    }

WRAP_INT_TO_80(qemu_i32_to_extF80M, int32_to_floatx80, int32_t)
WRAP_INT_TO_80(qemu_i64_to_extF80M, int64_to_floatx80, int64_t)
#undef WRAP_INT_TO_80

/* Note: exact is ignored since qemu's softfloat assumes it is set */
#define WRAP_80_TO_INT(name, func, fast_type)                           \
    static fast_type name(const extFloat80_t *ap, uint_fast8_t round,   \
                          bool exact)                                   \
    {                                                                   \
        floatx80 a;                                                     \
                                                                        \
        a = soft_to_qemu80(*ap);                                        \
        qsf.float_rounding_mode = sf_rounding_to_qemu(round);           \
        return func(a, &qsf);                                           \
    }

WRAP_80_TO_INT(qemu_extF80M_to_i32, floatx80_to_int32, int_fast32_t)
WRAP_80_TO_INT(qemu_extF80M_to_i64, floatx80_to_int64, int_fast64_t)
#undef WRAP_80_TO_INT

/* Note: exact is ignored since qemu's softfloat assumes it is set */
#define WRAP_80_TO_INT_MINMAG(name, func, fast_type)            \
    static fast_type name(const extFloat80_t *ap, bool exact)   \
    {                                                           \
        floatx80 a;                                             \
                                                                \
        a = soft_to_qemu80(*ap);                                \
        return func(a, &qsf);                                   \
    }

WRAP_80_TO_INT_MINMAG(qemu_extF80M_to_i32_r_minMag,
                      floatx80_to_int32_round_to_zero, int_fast32_t)
WRAP_80_TO_INT_MINMAG(qemu_extF80M_to_i64_r_minMag,
                      floatx80_to_int64_round_to_zero, int_fast64_t)
#undef WRAP_80_TO_INT_MINMAG

/* Note: exact is ignored since qemu's softfloat assumes it is set */
#define WRAP_128_TO_INT(name, func, fast_type)                          \
    static fast_type name(const float128_t *ap, uint_fast8_t round,     \
                          bool exact)                                   \
    {                                                                   \
        float128 a;                                                     \
                                                                        \
        a = soft_to_qemu128(*ap);                                       \
        qsf.float_rounding_mode = sf_rounding_to_qemu(round);           \
        return func(a, &qsf);                                           \
    }

WRAP_128_TO_INT(qemu_f128M_to_i32, float128_to_int32, int_fast32_t)
WRAP_128_TO_INT(qemu_f128M_to_i64, float128_to_int64, int_fast64_t)

WRAP_128_TO_INT(qemu_f128M_to_ui32, float128_to_uint32, uint_fast32_t)
WRAP_128_TO_INT(qemu_f128M_to_ui64, float128_to_uint64, uint_fast64_t)
#undef WRAP_128_TO_INT

/* Note: exact is ignored since qemu's softfloat assumes it is set */
#define WRAP_128_TO_INT_MINMAG(name, func, fast_type)           \
    static fast_type name(const float128_t *ap, bool exact)     \
    {                                                           \
        float128 a;                                             \
                                                                \
        a = soft_to_qemu128(*ap);                               \
        return func(a, &qsf);                                   \
    }

WRAP_128_TO_INT_MINMAG(qemu_f128M_to_i32_r_minMag,
                       float128_to_int32_round_to_zero, int_fast32_t)
WRAP_128_TO_INT_MINMAG(qemu_f128M_to_i64_r_minMag,
                       float128_to_int64_round_to_zero, int_fast64_t)

WRAP_128_TO_INT_MINMAG(qemu_f128M_to_ui32_r_minMag,
                       float128_to_uint32_round_to_zero, uint_fast32_t)
WRAP_128_TO_INT_MINMAG(qemu_f128M_to_ui64_r_minMag,
                       float128_to_uint64_round_to_zero, uint_fast64_t)
#undef WRAP_128_TO_INT_MINMAG

#define WRAP_INT_TO_128(name, func, int_type)           \
    static void name(int_type a, float128_t *res)       \
    {                                                   \
        float128 ret;                                   \
                                                        \
        ret = func(a, &qsf);                            \
        *res = qemu_to_soft128(ret);                    \
    }

WRAP_INT_TO_128(qemu_ui64_to_f128M, uint64_to_float128, uint64_t)

WRAP_INT_TO_128(qemu_i32_to_f128M, int32_to_float128, int32_t)
WRAP_INT_TO_128(qemu_i64_to_f128M, int64_to_float128, int64_t)
#undef WRAP_INT_TO_128

/* Note: exact is ignored since qemu's softfloat assumes it is set */
#define WRAP_ROUND_TO_INT(name, func, type)                             \
    static type##_t name(type##_t a, uint_fast8_t round, bool exact)    \
    {                                                                   \
        type *ap = (type *)&a;                                          \
        type ret;                                                       \
                                                                        \
        qsf.float_rounding_mode = sf_rounding_to_qemu(round);           \
        ret = func(*ap, &qsf);                                          \
        return *(type##_t *)&ret;                                       \
    }

WRAP_ROUND_TO_INT(qemu_f16_roundToInt, float16_round_to_int, float16)
WRAP_ROUND_TO_INT(qemu_f32_roundToInt, float32_round_to_int, float32)
WRAP_ROUND_TO_INT(qemu_f64_roundToInt, float64_round_to_int, float64)
#undef WRAP_ROUND_TO_INT

static void qemu_extF80M_roundToInt(const extFloat80_t *ap, uint_fast8_t round,
                                    bool exact, extFloat80_t *res)
{
    floatx80 a;
    floatx80 ret;

    a = soft_to_qemu80(*ap);
    qsf.float_rounding_mode = sf_rounding_to_qemu(round);
    ret = floatx80_round_to_int(a, &qsf);
    *res = qemu_to_soft80(ret);
}

static void qemu_f128M_roundToInt(const float128_t *ap, uint_fast8_t round,
                                  bool exact, float128_t *res)
{
    float128 a;
    float128 ret;

    a = soft_to_qemu128(*ap);
    qsf.float_rounding_mode = sf_rounding_to_qemu(round);
    ret = float128_round_to_int(a, &qsf);
    *res = qemu_to_soft128(ret);
}

/* operations */
#define WRAP1(name, func, type)                 \
    static type##_t name(type##_t a)            \
    {                                           \
        type *ap = (type *)&a;                  \
        type ret;                               \
                                                \
        ret = func(*ap, &qsf);                  \
        return *(type##_t *)&ret;               \
    }

#define WRAP2(name, func, type)                         \
    static type##_t name(type##_t a, type##_t b)        \
    {                                                   \
        type *ap = (type *)&a;                          \
        type *bp = (type *)&b;                          \
        type ret;                                       \
                                                        \
        ret = func(*ap, *bp, &qsf);                     \
        return *(type##_t *)&ret;                       \
    }

#define WRAP_COMMON_OPS(b)                              \
    WRAP1(qemu_f##b##_sqrt, float##b##_sqrt, float##b)  \
    WRAP2(qemu_f##b##_add, float##b##_add, float##b)    \
    WRAP2(qemu_f##b##_sub, float##b##_sub, float##b)    \
    WRAP2(qemu_f##b##_mul, float##b##_mul, float##b)    \
    WRAP2(qemu_f##b##_div, float##b##_div, float##b)

WRAP_COMMON_OPS(16)
WRAP_COMMON_OPS(32)
WRAP_COMMON_OPS(64)
#undef WRAP_COMMON

WRAP2(qemu_f32_rem, float32_rem, float32)
WRAP2(qemu_f64_rem, float64_rem, float64)
#undef WRAP2
#undef WRAP1

#define WRAP1_80(name, func)                                    \
    static void name(const extFloat80_t *ap, extFloat80_t *res) \
    {                                                           \
        floatx80 a;                                             \
        floatx80 ret;                                           \
                                                                \
        a = soft_to_qemu80(*ap);                                \
        ret = func(a, &qsf);                                    \
        *res = qemu_to_soft80(ret);                             \
    }

WRAP1_80(qemu_extF80M_sqrt, floatx80_sqrt)
#undef WRAP1_80

#define WRAP1_128(name, func)                                   \
    static void name(const float128_t *ap, float128_t *res)     \
    {                                                           \
        float128 a;                                             \
        float128 ret;                                           \
                                                                \
        a = soft_to_qemu128(*ap);                               \
        ret = func(a, &qsf);                                    \
        *res = qemu_to_soft128(ret);                            \
    }

WRAP1_128(qemu_f128M_sqrt, float128_sqrt)
#undef WRAP1_128

#define WRAP2_80(name, func)                                            \
    static void name(const extFloat80_t *ap, const extFloat80_t *bp,    \
                     extFloat80_t *res)                                 \
    {                                                                   \
        floatx80 a;                                                     \
        floatx80 b;                                                     \
        floatx80 ret;                                                   \
                                                                        \
        a = soft_to_qemu80(*ap);                                        \
        b = soft_to_qemu80(*bp);                                        \
        ret = func(a, b, &qsf);                                         \
        *res = qemu_to_soft80(ret);                                     \
    }

WRAP2_80(qemu_extF80M_add, floatx80_add)
WRAP2_80(qemu_extF80M_sub, floatx80_sub)
WRAP2_80(qemu_extF80M_mul, floatx80_mul)
WRAP2_80(qemu_extF80M_div, floatx80_div)
WRAP2_80(qemu_extF80M_rem, floatx80_rem)
#undef WRAP2_80

#define WRAP2_128(name, func)                                           \
    static void name(const float128_t *ap, const float128_t *bp,        \
                     float128_t *res)                                   \
    {                                                                   \
        float128 a;                                                     \
        float128 b;                                                     \
        float128 ret;                                                   \
                                                                        \
        a = soft_to_qemu128(*ap);                                       \
        b = soft_to_qemu128(*bp);                                       \
        ret = func(a, b, &qsf);                                         \
        *res = qemu_to_soft128(ret);                                    \
    }

WRAP2_128(qemu_f128M_add, float128_add)
WRAP2_128(qemu_f128M_sub, float128_sub)
WRAP2_128(qemu_f128M_mul, float128_mul)
WRAP2_128(qemu_f128M_div, float128_div)
WRAP2_128(qemu_f128M_rem, float128_rem)
#undef WRAP2_128

#define WRAP_MULADD(name, func, type)                           \
    static type##_t name(type##_t a, type##_t b, type##_t c)    \
    {                                                           \
        type *ap = (type *)&a;                                  \
        type *bp = (type *)&b;                                  \
        type *cp = (type *)&c;                                  \
        type ret;                                               \
                                                                \
        ret = func(*ap, *bp, *cp, 0, &qsf);                     \
        return *(type##_t *)&ret;                               \
    }

WRAP_MULADD(qemu_f16_mulAdd, float16_muladd, float16)
WRAP_MULADD(qemu_f32_mulAdd, float32_muladd, float32)
WRAP_MULADD(qemu_f64_mulAdd, float64_muladd, float64)
#undef WRAP_MULADD

static void qemu_f128M_mulAdd(const float128_t *ap, const float128_t *bp,
                              const float128_t *cp, float128_t *res)
{
    float128 a, b, c, ret;

    a = soft_to_qemu128(*ap);
    b = soft_to_qemu128(*bp);
    c = soft_to_qemu128(*cp);
    ret = float128_muladd(a, b, c, 0, &qsf);
    *res = qemu_to_soft128(ret);
}

#define WRAP_CMP16(name, func, retcond)         \
    static bool name(float16_t a, float16_t b)  \
    {                                           \
        float16 *ap = (float16 *)&a;            \
        float16 *bp = (float16 *)&b;            \
        int ret;                                \
                                                \
        ret = func(*ap, *bp, &qsf);             \
        return retcond;                         \
    }

WRAP_CMP16(qemu_f16_eq_signaling, float16_compare, ret == 0)
WRAP_CMP16(qemu_f16_eq, float16_compare_quiet, ret == 0)
WRAP_CMP16(qemu_f16_le, float16_compare, ret <= 0)
WRAP_CMP16(qemu_f16_lt, float16_compare, ret < 0)
WRAP_CMP16(qemu_f16_le_quiet, float16_compare_quiet, ret <= 0)
WRAP_CMP16(qemu_f16_lt_quiet, float16_compare_quiet, ret < 0)
#undef WRAP_CMP16

#define WRAP_CMP(name, func, type)              \
    static bool name(type##_t a, type##_t b)    \
    {                                           \
        type *ap = (type *)&a;                  \
        type *bp = (type *)&b;                  \
                                                \
        return !!func(*ap, *bp, &qsf);          \
    }

#define GEN_WRAP_CMP(b)                                                 \
    WRAP_CMP(qemu_f##b##_eq_signaling, float##b##_eq, float##b)         \
    WRAP_CMP(qemu_f##b##_eq, float##b##_eq_quiet, float##b)             \
    WRAP_CMP(qemu_f##b##_le, float##b##_le, float##b)                   \
    WRAP_CMP(qemu_f##b##_lt, float##b##_lt, float##b)                   \
    WRAP_CMP(qemu_f##b##_le_quiet, float##b##_le_quiet, float##b)       \
    WRAP_CMP(qemu_f##b##_lt_quiet, float##b##_lt_quiet, float##b)

GEN_WRAP_CMP(32)
GEN_WRAP_CMP(64)
#undef GEN_WRAP_CMP
#undef WRAP_CMP

#define WRAP_CMP80(name, func)                                          \
    static bool name(const extFloat80_t *ap, const extFloat80_t *bp)    \
    {                                                                   \
        floatx80 a;                                                     \
        floatx80 b;                                                     \
                                                                        \
        a = soft_to_qemu80(*ap);                                        \
        b = soft_to_qemu80(*bp);                                        \
        return !!func(a, b, &qsf);                                      \
    }

WRAP_CMP80(qemu_extF80M_eq_signaling, floatx80_eq)
WRAP_CMP80(qemu_extF80M_eq, floatx80_eq_quiet)
WRAP_CMP80(qemu_extF80M_le, floatx80_le)
WRAP_CMP80(qemu_extF80M_lt, floatx80_lt)
WRAP_CMP80(qemu_extF80M_le_quiet, floatx80_le_quiet)
WRAP_CMP80(qemu_extF80M_lt_quiet, floatx80_lt_quiet)
#undef WRAP_CMP80

#define WRAP_CMP128(name, func)                                         \
    static bool name(const float128_t *ap, const float128_t *bp)        \
    {                                                                   \
        float128 a;                                                     \
        float128 b;                                                     \
                                                                        \
        a = soft_to_qemu128(*ap);                                       \
        b = soft_to_qemu128(*bp);                                       \
        return !!func(a, b, &qsf);                                      \
    }

WRAP_CMP128(qemu_f128M_eq_signaling, float128_eq)
WRAP_CMP128(qemu_f128M_eq, float128_eq_quiet)
WRAP_CMP128(qemu_f128M_le, float128_le)
WRAP_CMP128(qemu_f128M_lt, float128_lt)
WRAP_CMP128(qemu_f128M_le_quiet, float128_le_quiet)
WRAP_CMP128(qemu_f128M_lt_quiet, float128_lt_quiet)
#undef WRAP_CMP128