Skip to contentSkip to conversation

tests/tcg/s390x: Test overflow conditions

PATCH Superseded Gautam Agrawal 4 participants 5 messages May 27, 2022 – May 30, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/tcg/s390x: Test overflow conditions

Add a test to check for overflow conditions in s390x. This patch is based on the following patches :
* https://git.qemu.org/?p=qemu.git;a=commitdiff;h=5a2e67a691501
* https://git.qemu.org/?p=qemu.git;a=commitdiff;h=fc6e0d0f2db51

---
 tests/tcg/s390x/Makefile.target |  1 +
 tests/tcg/s390x/overflow.c      | 58 +++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)
 create mode 100644 tests/tcg/s390x/overflow.c
tests/tcg/s390x/Makefile.target +1 -0
index 3124172736..7f86de85b9 100644
@@ -16,6 +16,7 @@ TESTS+=shift
 TESTS+=trap
 TESTS+=signals-s390x
 TESTS+=branch-relative-long
+TESTS+=overflow
 
 VECTOR_TESTS=vxeh2_vs
 VECTOR_TESTS+=vxeh2_vcvt
tests/tcg/s390x/overflow.c new file +58 -0

58 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw
In reply to Gautam Agrawal
Quoted 31 lines · Gautam Agrawal

Add a test to check for overflow conditions in s390x. This patch is based on the following patches :
* https://git.qemu.org/?p=qemu.git;a=commitdiff;h=5a2e67a691501
* https://git.qemu.org/?p=qemu.git;a=commitdiff;h=fc6e0d0f2db51

---
 tests/tcg/s390x/Makefile.target |  1 +
 tests/tcg/s390x/overflow.c      | 58 +++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)
 create mode 100644 tests/tcg/s390x/overflow.c
tests/tcg/s390x/Makefile.target +1 -0
index 3124172736..7f86de85b9 100644
@@ -16,6 +16,7 @@ TESTS+=shift
 TESTS+=trap
 TESTS+=signals-s390x
 TESTS+=branch-relative-long
+TESTS+=overflow
 
 VECTOR_TESTS=vxeh2_vs
 VECTOR_TESTS+=vxeh2_vcvt
tests/tcg/s390x/overflow.c new file +1 -0
new file mode 100644
index 0000000000..ea8a410b1a
@@ -0,0 +1,58 @@
+#include <stdio.h>

tests/tcg/s390x/overflow.c line 11

Quoted 10 lines
tests/tcg/s390x/overflow.c new file +10 -0
+
+int overflow_add_32(int x, int y)
+{
+    int sum;
+    return __builtin_add_overflow(x, y, &sum);
+}
+
+int overflow_add_64(long long x, long long y)
+{
+    long sum;

Just wondering, why "long long" in input and "long" in output?

tests/tcg/s390x/overflow.c line 24

Quoted 13 lines
tests/tcg/s390x/overflow.c new file +13 -0
+    return __builtin_add_overflow(x, y, &sum);
+}
+
+int overflow_sub_32(int x, int y)
+{
+    int sum;
+    return __builtin_sub_overflow(x, y, &sum);
+}
+
+int overflow_sub_64(long long x, long long y)
+{
+    long sum;
+    return __builtin_sub_overflow(x, y, &sum);

nit: I'd call all local variables "ret" or "res".

Apart from that LGTM.

Signature · 3 lines
Thanks,

David / dhildenb
#3 lore raw

Hi!

Quoted 36 lines · David Hildenbrand
Quoted 35 lines · Gautam Agrawal

Add a test to check for overflow conditions in s390x. This patch is based on the following patches :
* https://git.qemu.org/?p=qemu.git;a=commitdiff;h=5a2e67a691501
* https://git.qemu.org/?p=qemu.git;a=commitdiff;h=fc6e0d0f2db51

---
  tests/tcg/s390x/Makefile.target |  1 +
  tests/tcg/s390x/overflow.c      | 58 +++++++++++++++++++++++++++++++++
  2 files changed, 59 insertions(+)

create mode 100644 tests/tcg/s390x/overflow.c

tests/tcg/s390x/Makefile.target +1 -0
index 3124172736..7f86de85b9 100644
@@ -16,6 +16,7 @@ TESTS+=shift
  TESTS+=trap
  TESTS+=signals-s390x
  TESTS+=branch-relative-long
+TESTS+=overflow
 
  VECTOR_TESTS=vxeh2_vs
  VECTOR_TESTS+=vxeh2_vcvt
tests/tcg/s390x/overflow.c new file +5 -0
new file mode 100644
index 0000000000..ea8a410b1a
@@ -0,0 +1,58 @@
+#include <stdio.h>
+
+int overflow_add_32(int x, int y)
+{
+    int sum;
Quoted 8 lines

tests/tcg/s390x/overflow.c line 11

Quoted 6 lines
tests/tcg/s390x/overflow.c new file +6 -0
+    return __builtin_add_overflow(x, y, &sum);
+}
+
+int overflow_add_64(long long x, long long y)
+{
+    long sum;

Just wondering, why "long long" in input and "long" in output?

It's been like this in the original test program that has been supplied in https://gitlab.com/qemu-project/qemu/-/issues/616 and .../618 - but I agree it likely makes more sense to use the same type everywhere (i.e. switch sum from long to long long).

Quoted 7 lines
Quoted 7 lines
tests/tcg/s390x/overflow.c new file +7 -0
+    return __builtin_add_overflow(x, y, &sum);
+}
+
+int overflow_sub_32(int x, int y)
+{
+    int sum;
+    return __builtin_sub_overflow(x, y, &sum);
Quoted 8 lines

tests/tcg/s390x/overflow.c line 24

Quoted 6 lines
tests/tcg/s390x/overflow.c new file +6 -0
+}
+
+int overflow_sub_64(long long x, long long y)
+{
+    long sum;
+    return __builtin_sub_overflow(x, y, &sum);

nit: I'd call all local variables "ret" or "res".

Well, "sum" is not the return value here, so "ret" could be confusing, too. "res" or "diff" might be a good choice here, though. Gautam, what do you think?

Thomas

#4 lore raw

Hi,

Quoted 49 lines · Thomas Huth

Hi!

Quoted 36 lines · David Hildenbrand
Quoted 35 lines · Gautam Agrawal

Add a test to check for overflow conditions in s390x. This patch is based on the following patches :
* https://git.qemu.org/?p=qemu.git;a=commitdiff;h=5a2e67a691501
* https://git.qemu.org/?p=qemu.git;a=commitdiff;h=fc6e0d0f2db51

---
  tests/tcg/s390x/Makefile.target |  1 +
  tests/tcg/s390x/overflow.c      | 58 +++++++++++++++++++++++++++++++++
  2 files changed, 59 insertions(+)

create mode 100644 tests/tcg/s390x/overflow.c

tests/tcg/s390x/Makefile.target +1 -0
index 3124172736..7f86de85b9 100644
@@ -16,6 +16,7 @@ TESTS+=shift
  TESTS+=trap
  TESTS+=signals-s390x
  TESTS+=branch-relative-long
+TESTS+=overflow
 
  VECTOR_TESTS=vxeh2_vs
  VECTOR_TESTS+=vxeh2_vcvt
tests/tcg/s390x/overflow.c new file +5 -0
new file mode 100644
index 0000000000..ea8a410b1a
@@ -0,0 +1,58 @@
+#include <stdio.h>
+
+int overflow_add_32(int x, int y)
+{
+    int sum;
Quoted 8 lines

tests/tcg/s390x/overflow.c line 11

Quoted 6 lines
tests/tcg/s390x/overflow.c new file +6 -0
+    return __builtin_add_overflow(x, y, &sum);
+}
+
+int overflow_add_64(long long x, long long y)
+{
+    long sum;

Just wondering, why "long long" in input and "long" in output?

Quoted 4 lines

It's been like this in the original test program that has been supplied in
https://gitlab.com/qemu-project/qemu/-/issues/616 and .../618 - but I agree it likely makes more sense to use the same type everywhere (i.e. switch sum from long to long long).

I will correct the type in next patch.

Quoted 17 lines
Quoted 16 lines
Quoted 4 lines
tests/tcg/s390x/overflow.c new file +3 -0
+    return __builtin_add_overflow(x, y, &sum);
+}
+

tests/tcg/s390x/overflow.c line 24

Quoted 10 lines
tests/tcg/s390x/overflow.c new file +10 -0
+int overflow_sub_32(int x, int y)
+{
+    int sum;
+    return __builtin_sub_overflow(x, y, &sum);
+}
+
+int overflow_sub_64(long long x, long long y)
+{
+    long sum;
+    return __builtin_sub_overflow(x, y, &sum);

nit: I'd call all local variables "ret" or "res".

Quoted 2 lines

Well, "sum" is not the return value here, so "ret" could be confusing, too. "res" or "diff" might be a good choice here, though. Gautam, what do you think?

I agree "res" sounds better.

Regards,
Gautam Agrawal