diff mbox series

[RFC,29/30] tests/test-softfloat: add f16_to_int16 conversion test

Message ID 20171013162438.32458-30-alex.bennee@linaro.org
State New
Headers show
Series v8.2 half-precision support (work-in-progress) | expand

Commit Message

Alex Bennée Oct. 13, 2017, 4:24 p.m. UTC
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
 tests/test-softfloat.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

-- 
2.14.1
diff mbox series

Patch

diff --git a/tests/test-softfloat.c b/tests/test-softfloat.c
index d7b740e1cb..e1f356572d 100644
--- a/tests/test-softfloat.c
+++ b/tests/test-softfloat.c
@@ -16,6 +16,31 @@  typedef struct {
     uint8_t final_exception_flags;
 } f16_test_data;
 
+static void test_f16_convert_to_int(void)
+{
+    int i;
+    float16 out;
+    float_status flags, *fp = &flags;
+    f16_test_data test_data[] = {
+        /* from risu fcvtps  v23.4h, v16.4h */
+        { { .float_rounding_mode = float_round_up}, 0xa619, 0xb860, 0 },
+        { { .float_rounding_mode = float_round_up}, 0x83c0, 0xff91, 0 },
+        { { .float_rounding_mode = float_round_up}, 0x6966, 0x0001, 0 },
+        { { .float_rounding_mode = float_round_up}, 0x06b1, 0x0001, 0 },
+    };
+
+    for (i = 0; i < ARRAY_SIZE(test_data); ++i) {
+        flags = test_data[i].initial_status;
+        out = float16_to_int16(test_data[i].in, fp);
+
+        if (!(test_data[i].out == out)) {
+            fprintf(stderr, "%s[%d]: expected %#04x got %#04x\n",
+                    __func__, i, test_data[i].out, out);
+            g_test_fail();
+        }
+    }
+}
+
 static void test_f16_round_to_int(void)
 {
     int i;
@@ -54,5 +79,6 @@  int main(int argc, char *argv[])
 {
     g_test_init(&argc, &argv, NULL);
     g_test_add_func("/softfloat/f16/round_to_int", test_f16_round_to_int);
+    g_test_add_func("/softfloat/f16/convert_to_int", test_f16_convert_to_int);
     return g_test_run();
 }