0007-target-riscv-Fixup-saturate-subtract-function.patch 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. From cf90aa93ab52ea954d20734e7d8df906433636e5 Mon Sep 17 00:00:00 2001
  2. From: LIU Zhiwei <zhiwei_liu@c-sky.com>
  3. Date: Fri, 12 Feb 2021 23:02:21 +0800
  4. Subject: [PATCH 007/107] target/riscv: Fixup saturate subtract function
  5. The overflow predication ((a - b) ^ a) & (a ^ b) & INT64_MIN is right.
  6. However, when the predication is ture and a is 0, it should return maximum.
  7. Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
  8. Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
  9. Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
  10. Message-id: 20210212150256.885-4-zhiwei_liu@c-sky.com
  11. Message-Id: <20210212150256.885-4-zhiwei_liu@c-sky.com>
  12. ---
  13. target/riscv/vector_helper.c | 8 ++++----
  14. 1 file changed, 4 insertions(+), 4 deletions(-)
  15. diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
  16. index a156573d28..356cef8a09 100644
  17. --- a/target/riscv/vector_helper.c
  18. +++ b/target/riscv/vector_helper.c
  19. @@ -2451,7 +2451,7 @@ static inline int8_t ssub8(CPURISCVState *env, int vxrm, int8_t a, int8_t b)
  20. {
  21. int8_t res = a - b;
  22. if ((res ^ a) & (a ^ b) & INT8_MIN) {
  23. - res = a > 0 ? INT8_MAX : INT8_MIN;
  24. + res = a >= 0 ? INT8_MAX : INT8_MIN;
  25. env->vxsat = 0x1;
  26. }
  27. return res;
  28. @@ -2461,7 +2461,7 @@ static inline int16_t ssub16(CPURISCVState *env, int vxrm, int16_t a, int16_t b)
  29. {
  30. int16_t res = a - b;
  31. if ((res ^ a) & (a ^ b) & INT16_MIN) {
  32. - res = a > 0 ? INT16_MAX : INT16_MIN;
  33. + res = a >= 0 ? INT16_MAX : INT16_MIN;
  34. env->vxsat = 0x1;
  35. }
  36. return res;
  37. @@ -2471,7 +2471,7 @@ static inline int32_t ssub32(CPURISCVState *env, int vxrm, int32_t a, int32_t b)
  38. {
  39. int32_t res = a - b;
  40. if ((res ^ a) & (a ^ b) & INT32_MIN) {
  41. - res = a > 0 ? INT32_MAX : INT32_MIN;
  42. + res = a >= 0 ? INT32_MAX : INT32_MIN;
  43. env->vxsat = 0x1;
  44. }
  45. return res;
  46. @@ -2481,7 +2481,7 @@ static inline int64_t ssub64(CPURISCVState *env, int vxrm, int64_t a, int64_t b)
  47. {
  48. int64_t res = a - b;
  49. if ((res ^ a) & (a ^ b) & INT64_MIN) {
  50. - res = a > 0 ? INT64_MAX : INT64_MIN;
  51. + res = a >= 0 ? INT64_MAX : INT64_MIN;
  52. env->vxsat = 0x1;
  53. }
  54. return res;
  55. --
  56. 2.33.1