Skip to content

Commit c17a204

Browse files
committed
wasm2c: format source and regenerate tests and examples
1 parent 6d4abfd commit c17a204

File tree

11 files changed

+388
-443
lines changed

11 files changed

+388
-443
lines changed

src/prebuilt/wasm2c_source_declarations.cc

Lines changed: 37 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -624,24 +624,22 @@ R"w2c_template(
624624
#endif
625625
)w2c_template"
626626
R"w2c_template(
627-
#define DIV_S(ut, min, x, y) \
627+
#define DIV_S(ut, min, x, y) \
628628
)w2c_template"
629-
R"w2c_template( ((UNLIKELY((y) == 0)) \
629+
R"w2c_template( ((UNLIKELY((y) == 0)) ? TRAP(DIV_BY_ZERO) \
630630
)w2c_template"
631-
R"w2c_template( ? TRAP(DIV_BY_ZERO) \
631+
R"w2c_template( : (UNLIKELY((x) == min && (y) == -1)) ? TRAP(INT_OVERFLOW) \
632632
)w2c_template"
633-
R"w2c_template( : (UNLIKELY((x) == min && (y) == -1)) ? TRAP(INT_OVERFLOW) \
634-
)w2c_template"
635-
R"w2c_template( : (ut)((x) / (y)))
633+
R"w2c_template( : (ut)((x) / (y)))
636634
)w2c_template"
637635
R"w2c_template(
638-
#define REM_S(ut, min, x, y) \
636+
#define REM_S(ut, min, x, y) \
639637
)w2c_template"
640-
R"w2c_template( ((UNLIKELY((y) == 0)) \
638+
R"w2c_template( ((UNLIKELY((y) == 0)) ? TRAP(DIV_BY_ZERO) \
641639
)w2c_template"
642-
R"w2c_template( ? TRAP(DIV_BY_ZERO) \
640+
R"w2c_template( : (UNLIKELY((x) == min && (y) == -1)) ? 0 \
643641
)w2c_template"
644-
R"w2c_template( : (UNLIKELY((x) == min && (y) == -1)) ? 0 : (ut)((x) % (y)))
642+
R"w2c_template( : (ut)((x) % (y)))
645643
)w2c_template"
646644
R"w2c_template(
647645
#define I32_DIV_S(x, y) DIV_S(u32, INT32_MIN, (s32)x, (s32)y)
@@ -681,45 +679,39 @@ R"w2c_template(#define I32_ROTR(x, y) ROTR(x, y, 31)
681679
R"w2c_template(#define I64_ROTR(x, y) ROTR(x, y, 63)
682680
)w2c_template"
683681
R"w2c_template(
684-
#define FMIN(x, y) \
685-
)w2c_template"
686-
R"w2c_template( ((UNLIKELY((x) != (x))) \
682+
#define FMIN(x, y) \
687683
)w2c_template"
688-
R"w2c_template( ? NAN \
684+
R"w2c_template( ((UNLIKELY((x) != (x))) ? NAN \
689685
)w2c_template"
690-
R"w2c_template( : (UNLIKELY((y) != (y))) \
686+
R"w2c_template( : (UNLIKELY((y) != (y))) ? NAN \
691687
)w2c_template"
692-
R"w2c_template( ? NAN \
688+
R"w2c_template( : (UNLIKELY((x) == 0 && (y) == 0)) ? (signbit(x) ? x : y) \
693689
)w2c_template"
694-
R"w2c_template( : (UNLIKELY((x) == 0 && (y) == 0)) ? (signbit(x) ? x : y) \
690+
R"w2c_template( : (x < y) ? x \
695691
)w2c_template"
696-
R"w2c_template( : (x < y) ? x : y)
692+
R"w2c_template( : y)
697693
)w2c_template"
698694
R"w2c_template(
699-
#define FMAX(x, y) \
700-
)w2c_template"
701-
R"w2c_template( ((UNLIKELY((x) != (x))) \
695+
#define FMAX(x, y) \
702696
)w2c_template"
703-
R"w2c_template( ? NAN \
697+
R"w2c_template( ((UNLIKELY((x) != (x))) ? NAN \
704698
)w2c_template"
705-
R"w2c_template( : (UNLIKELY((y) != (y))) \
699+
R"w2c_template( : (UNLIKELY((y) != (y))) ? NAN \
706700
)w2c_template"
707-
R"w2c_template( ? NAN \
701+
R"w2c_template( : (UNLIKELY((x) == 0 && (y) == 0)) ? (signbit(x) ? y : x) \
708702
)w2c_template"
709-
R"w2c_template( : (UNLIKELY((x) == 0 && (y) == 0)) ? (signbit(x) ? y : x) \
703+
R"w2c_template( : (x > y) ? x \
710704
)w2c_template"
711-
R"w2c_template( : (x > y) ? x : y)
705+
R"w2c_template( : y)
712706
)w2c_template"
713707
R"w2c_template(
714-
#define TRUNC_S(ut, st, ft, min, minop, max, x) \
708+
#define TRUNC_S(ut, st, ft, min, minop, max, x) \
715709
)w2c_template"
716-
R"w2c_template( ((UNLIKELY((x) != (x))) \
710+
R"w2c_template( ((UNLIKELY((x) != (x))) ? TRAP(INVALID_CONVERSION) \
717711
)w2c_template"
718-
R"w2c_template( ? TRAP(INVALID_CONVERSION) \
712+
R"w2c_template( : (UNLIKELY(!((x)minop(min) && (x) < (max)))) ? TRAP(INT_OVERFLOW) \
719713
)w2c_template"
720-
R"w2c_template( : (UNLIKELY(!((x)minop(min) && (x) < (max)))) ? TRAP(INT_OVERFLOW) \
721-
)w2c_template"
722-
R"w2c_template( : (ut)(st)(x))
714+
R"w2c_template( : (ut)(st)(x))
723715
)w2c_template"
724716
R"w2c_template(
725717
#define I32_TRUNC_S_F32(x) \
@@ -739,15 +731,13 @@ R"w2c_template(#define I64_TRUNC_S_F64(x) \
739731
R"w2c_template( TRUNC_S(u64, s64, f64, (f64)INT64_MIN, >=, (f64)INT64_MAX, x)
740732
)w2c_template"
741733
R"w2c_template(
742-
#define TRUNC_U(ut, ft, max, x) \
743-
)w2c_template"
744-
R"w2c_template( ((UNLIKELY((x) != (x))) \
734+
#define TRUNC_U(ut, ft, max, x) \
745735
)w2c_template"
746-
R"w2c_template( ? TRAP(INVALID_CONVERSION) \
736+
R"w2c_template( ((UNLIKELY((x) != (x))) ? TRAP(INVALID_CONVERSION) \
747737
)w2c_template"
748-
R"w2c_template( : (UNLIKELY(!((x) > (ft)-1 && (x) < (max)))) ? TRAP(INT_OVERFLOW) \
738+
R"w2c_template( : (UNLIKELY(!((x) > (ft) - 1 && (x) < (max)))) ? TRAP(INT_OVERFLOW) \
749739
)w2c_template"
750-
R"w2c_template( : (ut)(x))
740+
R"w2c_template( : (ut)(x))
751741
)w2c_template"
752742
R"w2c_template(
753743
#define I32_TRUNC_U_F32(x) TRUNC_U(u32, f32, 4294967296.f, x)
@@ -761,15 +751,13 @@ R"w2c_template(#define I64_TRUNC_U_F64(x) TRUNC_U(u64, f64, (f64)UINT64_MAX, x)
761751
R"w2c_template(
762752
#define TRUNC_SAT_S(ut, st, ft, min, smin, minop, max, smax, x) \
763753
)w2c_template"
764-
R"w2c_template( ((UNLIKELY((x) != (x))) \
765-
)w2c_template"
766-
R"w2c_template( ? 0 \
754+
R"w2c_template( ((UNLIKELY((x) != (x))) ? 0 \
767755
)w2c_template"
768-
R"w2c_template( : (UNLIKELY(!((x)minop(min)))) \
756+
R"w2c_template( : (UNLIKELY(!((x)minop(min)))) ? smin \
769757
)w2c_template"
770-
R"w2c_template( ? smin \
758+
R"w2c_template( : (UNLIKELY(!((x) < (max)))) ? smax \
771759
)w2c_template"
772-
R"w2c_template( : (UNLIKELY(!((x) < (max)))) ? smax : (ut)(st)(x))
760+
R"w2c_template( : (ut)(st)(x))
773761
)w2c_template"
774762
R"w2c_template(
775763
#define I32_TRUNC_SAT_S_F32(x) \
@@ -797,15 +785,15 @@ R"w2c_template( TRUNC_SAT_S(u64, s64, f64, (f64)INT64_MIN, INT64_MIN, >=, (f64)
797785
R"w2c_template( INT64_MAX, x)
798786
)w2c_template"
799787
R"w2c_template(
800-
#define TRUNC_SAT_U(ut, ft, max, smax, x) \
788+
#define TRUNC_SAT_U(ut, ft, max, smax, x) \
801789
)w2c_template"
802-
R"w2c_template( ((UNLIKELY((x) != (x))) ? 0 \
790+
R"w2c_template( ((UNLIKELY((x) != (x))) ? 0 \
803791
)w2c_template"
804-
R"w2c_template( : (UNLIKELY(!((x) > (ft)-1))) \
792+
R"w2c_template( : (UNLIKELY(!((x) > (ft) - 1))) ? 0 \
805793
)w2c_template"
806-
R"w2c_template( ? 0 \
794+
R"w2c_template( : (UNLIKELY(!((x) < (max)))) ? smax \
807795
)w2c_template"
808-
R"w2c_template( : (UNLIKELY(!((x) < (max)))) ? smax : (ut)(x))
796+
R"w2c_template( : (ut)(x))
809797
)w2c_template"
810798
R"w2c_template(
811799
#define I32_TRUNC_SAT_U_F32(x) \

src/template/wasm2c.declarations.c

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,15 @@ POPCOUNT_DEFINE_PORTABLE(I64_POPCNT, u64)
332332

333333
#endif
334334

335-
#define DIV_S(ut, min, x, y) \
336-
((UNLIKELY((y) == 0)) \
337-
? TRAP(DIV_BY_ZERO) \
338-
: (UNLIKELY((x) == min && (y) == -1)) ? TRAP(INT_OVERFLOW) \
339-
: (ut)((x) / (y)))
335+
#define DIV_S(ut, min, x, y) \
336+
((UNLIKELY((y) == 0)) ? TRAP(DIV_BY_ZERO) \
337+
: (UNLIKELY((x) == min && (y) == -1)) ? TRAP(INT_OVERFLOW) \
338+
: (ut)((x) / (y)))
340339

341-
#define REM_S(ut, min, x, y) \
342-
((UNLIKELY((y) == 0)) \
343-
? TRAP(DIV_BY_ZERO) \
344-
: (UNLIKELY((x) == min && (y) == -1)) ? 0 : (ut)((x) % (y)))
340+
#define REM_S(ut, min, x, y) \
341+
((UNLIKELY((y) == 0)) ? TRAP(DIV_BY_ZERO) \
342+
: (UNLIKELY((x) == min && (y) == -1)) ? 0 \
343+
: (ut)((x) % (y)))
345344

346345
#define I32_DIV_S(x, y) DIV_S(u32, INT32_MIN, (s32)x, (s32)y)
347346
#define I64_DIV_S(x, y) DIV_S(u64, INT64_MIN, (s64)x, (s64)y)
@@ -364,27 +363,24 @@ POPCOUNT_DEFINE_PORTABLE(I64_POPCNT, u64)
364363
#define I32_ROTR(x, y) ROTR(x, y, 31)
365364
#define I64_ROTR(x, y) ROTR(x, y, 63)
366365

367-
#define FMIN(x, y) \
368-
((UNLIKELY((x) != (x))) \
369-
? NAN \
370-
: (UNLIKELY((y) != (y))) \
371-
? NAN \
372-
: (UNLIKELY((x) == 0 && (y) == 0)) ? (signbit(x) ? x : y) \
373-
: (x < y) ? x : y)
374-
375-
#define FMAX(x, y) \
376-
((UNLIKELY((x) != (x))) \
377-
? NAN \
378-
: (UNLIKELY((y) != (y))) \
379-
? NAN \
380-
: (UNLIKELY((x) == 0 && (y) == 0)) ? (signbit(x) ? y : x) \
381-
: (x > y) ? x : y)
382-
383-
#define TRUNC_S(ut, st, ft, min, minop, max, x) \
384-
((UNLIKELY((x) != (x))) \
385-
? TRAP(INVALID_CONVERSION) \
386-
: (UNLIKELY(!((x)minop(min) && (x) < (max)))) ? TRAP(INT_OVERFLOW) \
387-
: (ut)(st)(x))
366+
#define FMIN(x, y) \
367+
((UNLIKELY((x) != (x))) ? NAN \
368+
: (UNLIKELY((y) != (y))) ? NAN \
369+
: (UNLIKELY((x) == 0 && (y) == 0)) ? (signbit(x) ? x : y) \
370+
: (x < y) ? x \
371+
: y)
372+
373+
#define FMAX(x, y) \
374+
((UNLIKELY((x) != (x))) ? NAN \
375+
: (UNLIKELY((y) != (y))) ? NAN \
376+
: (UNLIKELY((x) == 0 && (y) == 0)) ? (signbit(x) ? y : x) \
377+
: (x > y) ? x \
378+
: y)
379+
380+
#define TRUNC_S(ut, st, ft, min, minop, max, x) \
381+
((UNLIKELY((x) != (x))) ? TRAP(INVALID_CONVERSION) \
382+
: (UNLIKELY(!((x)minop(min) && (x) < (max)))) ? TRAP(INT_OVERFLOW) \
383+
: (ut)(st)(x))
388384

389385
#define I32_TRUNC_S_F32(x) \
390386
TRUNC_S(u32, s32, f32, (f32)INT32_MIN, >=, 2147483648.f, x)
@@ -395,23 +391,21 @@ POPCOUNT_DEFINE_PORTABLE(I64_POPCNT, u64)
395391
#define I64_TRUNC_S_F64(x) \
396392
TRUNC_S(u64, s64, f64, (f64)INT64_MIN, >=, (f64)INT64_MAX, x)
397393

398-
#define TRUNC_U(ut, ft, max, x) \
399-
((UNLIKELY((x) != (x))) \
400-
? TRAP(INVALID_CONVERSION) \
401-
: (UNLIKELY(!((x) > (ft)-1 && (x) < (max)))) ? TRAP(INT_OVERFLOW) \
402-
: (ut)(x))
394+
#define TRUNC_U(ut, ft, max, x) \
395+
((UNLIKELY((x) != (x))) ? TRAP(INVALID_CONVERSION) \
396+
: (UNLIKELY(!((x) > (ft) - 1 && (x) < (max)))) ? TRAP(INT_OVERFLOW) \
397+
: (ut)(x))
403398

404399
#define I32_TRUNC_U_F32(x) TRUNC_U(u32, f32, 4294967296.f, x)
405400
#define I64_TRUNC_U_F32(x) TRUNC_U(u64, f32, (f32)UINT64_MAX, x)
406401
#define I32_TRUNC_U_F64(x) TRUNC_U(u32, f64, 4294967296., x)
407402
#define I64_TRUNC_U_F64(x) TRUNC_U(u64, f64, (f64)UINT64_MAX, x)
408403

409404
#define TRUNC_SAT_S(ut, st, ft, min, smin, minop, max, smax, x) \
410-
((UNLIKELY((x) != (x))) \
411-
? 0 \
412-
: (UNLIKELY(!((x)minop(min)))) \
413-
? smin \
414-
: (UNLIKELY(!((x) < (max)))) ? smax : (ut)(st)(x))
405+
((UNLIKELY((x) != (x))) ? 0 \
406+
: (UNLIKELY(!((x)minop(min)))) ? smin \
407+
: (UNLIKELY(!((x) < (max)))) ? smax \
408+
: (ut)(st)(x))
415409

416410
#define I32_TRUNC_SAT_S_F32(x) \
417411
TRUNC_SAT_S(u32, s32, f32, (f32)INT32_MIN, INT32_MIN, >=, 2147483648.f, \
@@ -426,11 +420,11 @@ POPCOUNT_DEFINE_PORTABLE(I64_POPCNT, u64)
426420
TRUNC_SAT_S(u64, s64, f64, (f64)INT64_MIN, INT64_MIN, >=, (f64)INT64_MAX, \
427421
INT64_MAX, x)
428422

429-
#define TRUNC_SAT_U(ut, ft, max, smax, x) \
430-
((UNLIKELY((x) != (x))) ? 0 \
431-
: (UNLIKELY(!((x) > (ft)-1))) \
432-
? 0 \
433-
: (UNLIKELY(!((x) < (max)))) ? smax : (ut)(x))
423+
#define TRUNC_SAT_U(ut, ft, max, smax, x) \
424+
((UNLIKELY((x) != (x))) ? 0 \
425+
: (UNLIKELY(!((x) > (ft) - 1))) ? 0 \
426+
: (UNLIKELY(!((x) < (max)))) ? smax \
427+
: (ut)(x))
434428

435429
#define I32_TRUNC_SAT_U_F32(x) \
436430
TRUNC_SAT_U(u32, f32, 4294967296.f, UINT32_MAX, x)

0 commit comments

Comments
 (0)