From: Mike Frysinger Date: Fri, 12 Nov 2021 00:30:41 +0000 (-0500) Subject: sim: sh: rework carry checks to not rely on integer overflows X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=dc5a4621600e650b89deb92c79eaacc73fcc767a;p=binutils-gdb.git sim: sh: rework carry checks to not rely on integer overflows In <=gcc-7 versions, -fstrict-overflow is enabled by default, and that triggers warnings in this code that relies on integer overflows to test for carries. Change the logic to test against the limit directly. --- diff --git a/sim/sh/gencode.c b/sim/sh/gencode.c index 80eecfdf1d3..5eb7caf2589 100644 --- a/sim/sh/gencode.c +++ b/sim/sh/gencode.c @@ -2266,7 +2266,7 @@ op ppi_tab[] = "int Sx_grd = GET_DSP_GRD (x);", "", "res = Sx - 0x10000;", - "carry = res > Sx;", + "carry = Sx < (INT_MIN + 0x10000);", "res_grd = Sx_grd - carry;", "COMPUTE_OVERFLOW;", "ADD_SUB_GE;", @@ -2277,7 +2277,7 @@ op ppi_tab[] = "int Sx_grd = GET_DSP_GRD (x);", "", "res = Sx + 0x10000;", - "carry = res < Sx;", + "carry = Sx > (INT_MAX - 0x10000);", "res_grd = Sx_grd + carry;", "COMPUTE_OVERFLOW;", "ADD_SUB_GE;", @@ -2288,7 +2288,7 @@ op ppi_tab[] = "int Sy_grd = SIGN32 (Sy);", "", "res = Sy - 0x10000;", - "carry = res > Sy;", + "carry = Sy < (INT_MIN + 0x10000);", "res_grd = Sy_grd - carry;", "COMPUTE_OVERFLOW;", "ADD_SUB_GE;", @@ -2299,7 +2299,7 @@ op ppi_tab[] = "int Sy_grd = SIGN32 (Sy);", "", "res = Sy + 0x10000;", - "carry = res < Sy;", + "carry = Sy > (INT_MAX - 0x10000);", "res_grd = Sy_grd + carry;", "COMPUTE_OVERFLOW;", "ADD_SUB_GE;",