diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2019-09-27 15:43:41 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2019-09-27 15:43:41 +0100 |
commit | c6f5012ba5fa834cbd5274b1b8369e2c5d2f5933 (patch) | |
tree | 916817555b31f747fc4046728c8c68af157f6965 /tests/tcg/multiarch/float_convs.c | |
parent | deee6ff7b74799b6233573eca4114ecf7b30b20c (diff) | |
parent | 80394ccf216da9ff48f23b9b8dab65ef809b7870 (diff) |
Merge remote-tracking branch 'remotes/stsquad/tags/pull-testing-next-260919-1' into staging
Testing updates plus alpha FP fixes:
- fix alpha handling of FtoI overflow
- various docker cleanups
- fix docker.py cleanup race
- fix podman invocation
- tests/tcg: add float and record/replay tests
- remove unused docker images
- expand documentation for check-tcg
# gpg: Signature made Thu 26 Sep 2019 19:33:38 BST
# gpg: using RSA key 6685AE99E75167BCAFC8DF35FBD0DB095A9E2A44
# gpg: Good signature from "Alex Bennée (Master Work Key) <alex.bennee@linaro.org>" [full]
# Primary key fingerprint: 6685 AE99 E751 67BC AFC8 DF35 FBD0 DB09 5A9E 2A44
* remotes/stsquad/tags/pull-testing-next-260919-1: (28 commits)
tests/docker: remove debian-powerpc-user-cross
docker: move tests from python2 to python3
docker: remove unused debian-sid
docker: remove unused debian-ports
docker: remove 'deprecated' image definitions
docker: remove unused debian8 partial image
docker: remove debian8-mxe definitions
target/i386: Fix broken build with WHPX enabled
docs/devel: add "check-tcg" to testing.rst
configure: preserve PKG_CONFIG for subdir builds
tests/tcg: add simple record/replay smoke test for aarch64
tests/tcg: add generic version of float_convs
tests/tcg: add float_madds test to multiarch
tests/tcg: re-enable linux-test for ppc64abi32
tests/tcg: clean-up some comments after the de-tangling
podman: fix command invocation
tests/docker: reduce scary warnings by cleaning up clean up
tests/docker: remove python2.7 from debian9-mxe
tests/docker: fix DOCKER_PARTIAL_IMAGES
tests/docker: add sanitizers back to clang build
...
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests/tcg/multiarch/float_convs.c')
-rw-r--r-- | tests/tcg/multiarch/float_convs.c | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/tests/tcg/multiarch/float_convs.c b/tests/tcg/multiarch/float_convs.c new file mode 100644 index 0000000000..47e24b8b16 --- /dev/null +++ b/tests/tcg/multiarch/float_convs.c @@ -0,0 +1,105 @@ +/* + * Floating Point Convert Single to Various + * + * Copyright (c) 2019 Linaro + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <float.h> +#include <fenv.h> + + +#include "float_helpers.h" + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +typedef struct { + int flag; + char *desc; +} float_mapping; + +float_mapping round_flags[] = { + { FE_TONEAREST, "to nearest" }, +#ifdef FE_UPWARD + { FE_UPWARD, "upwards" }, +#endif +#ifdef FE_DOWNWARD + { FE_DOWNWARD, "downwards" }, +#endif + { FE_TOWARDZERO, "to zero" } +}; + +static void print_input(float input) +{ + char *in_fmt = fmt_f32(input); + printf("from single: %s\n", in_fmt); + free(in_fmt); +} + +static void convert_single_to_double(float input) +{ + double output; + char *out_fmt, *flag_fmt; + + feclearexcept(FE_ALL_EXCEPT); + + output = input; + + out_fmt = fmt_f64(output); + flag_fmt = fmt_flags(); + printf(" to double: %s (%s)\n", out_fmt, flag_fmt); + free(out_fmt); + free(flag_fmt); +} + +#define xstr(a) str(a) +#define str(a) #a + +#define CONVERT_SINGLE_TO_INT(TYPE, FMT) \ + static void convert_single_to_ ## TYPE(float input) \ + { \ + TYPE ## _t output; \ + char *flag_fmt; \ + const char to[] = "to " xstr(TYPE); \ + feclearexcept(FE_ALL_EXCEPT); \ + output = input; \ + flag_fmt = fmt_flags(); \ + printf("%11s: %" FMT " (%s)\n", to, output, flag_fmt); \ + free(flag_fmt); \ + } + +CONVERT_SINGLE_TO_INT( int32, PRId32) +CONVERT_SINGLE_TO_INT(uint32, PRId32) +CONVERT_SINGLE_TO_INT( int64, PRId64) +CONVERT_SINGLE_TO_INT(uint64, PRId64) + +int main(int argc, char *argv[argc]) +{ + int i, j, nums; + + nums = get_num_f32(); + + for (i = 0; i < ARRAY_SIZE(round_flags); ++i) { + if (fesetround(round_flags[i].flag) != 0) { + printf("### Rounding %s skipped\n", round_flags[i].desc); + continue; + } + printf("### Rounding %s\n", round_flags[i].desc); + for (j = 0; j < nums; j++) { + float input = get_f32(j); + print_input(input); + /* convert_single_to_half(input); */ + convert_single_to_double(input); + convert_single_to_int32(input); + convert_single_to_int64(input); + convert_single_to_uint32(input); + convert_single_to_uint64(input); + } + } + + return 0; +} |