From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id DD7CB3858D28; Tue, 29 Aug 2023 07:25:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DD7CB3858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0353726.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37T6aleR001370; Tue, 29 Aug 2023 07:25:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : references : date : in-reply-to : message-id : content-type : mime-version; s=pp1; bh=Pgw5iHcurlvlgibSu7op/H4rZjHhrsU761lsppAbIoQ=; b=sCP//7i0+wQg2nWAYPjTMU9qITmxGieNnUJhwqwGPubRfEDFuYFKj3TkiWymUBAf3aPM 4OOPNduWGSCIKRtqSMzb0MAPIdOJ965+fmatC0pSqe/ewPa7pcoSbT4NT3j3pjrCjF5C 5pBSQnq9vM9FPsqz1Xvf6Qw2Skrsbl+aqFknChusNL1FdS0+q+S3ZNUFUeWEhyIpDXaT 7Z2Ut7pI1xXoPx4C+eTcoj+t66ZMfYt8Xwiz94rWSlRTZC92JHGHanGLWLIrD1pFwu7l C074KGiacRkrYmhMLcbvGgQJO+CkihwmS4nWGTQequxtcvhzm5kBp3CTTbjtQsqs14An 7w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3sr7vymwx2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Aug 2023 07:25:07 +0000 Received: from m0353726.ppops.net (m0353726.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 37T7Dw8p019729; Tue, 29 Aug 2023 07:25:07 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3sr7vymwwq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Aug 2023 07:25:07 +0000 Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37T6Kg6Q014107; Tue, 29 Aug 2023 07:25:06 GMT Received: from smtprelay06.dal12v.mail.ibm.com ([172.16.1.8]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3sqwxjs557-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Aug 2023 07:25:06 +0000 Received: from smtpav03.dal12v.mail.ibm.com (smtpav03.dal12v.mail.ibm.com [10.241.53.102]) by smtprelay06.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37T7P52Q39977378 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Aug 2023 07:25:05 GMT Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9130F5805A; Tue, 29 Aug 2023 07:25:05 +0000 (GMT) Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3922358056; Tue, 29 Aug 2023 07:25:05 +0000 (GMT) Received: from genoa (unknown [9.40.192.157]) by smtpav03.dal12v.mail.ibm.com (Postfix) with ESMTPS; Tue, 29 Aug 2023 07:25:05 +0000 (GMT) From: Jiufu Guo To: Richard Biener Cc: jeffreyalaw@gmail.com, richard.sandiford@arm.com, gcc-patches@gcc.gnu.org, amacleod@redhat.com, aldyh@redhat.com, segher@kernel.crashing.org, dje.gcc@gmail.com, linkw@gcc.gnu.org, bergner@linux.ibm.com Subject: Re: Ping^^ [PATCH V5 2/2] Optimize '(X - N * M) / N' to 'X / N - M' if valid References: <20230718140544.3497370-1-guojiufu@linux.ibm.com> <20230718140544.3497370-2-guojiufu@linux.ibm.com> <11eab982cf225b32e34e8d9c5f7f1947@linux.ibm.com> Date: Tue, 29 Aug 2023 15:25:02 +0800 In-Reply-To: (Richard Biener's message of "Mon, 28 Aug 2023 13:14:57 +0000 (UTC)") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Content-Type: text/plain X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: BzqTjWzUtDW9dwsMh8u_AE5dm7TqeYnd X-Proofpoint-GUID: BxCmS2GFHXQbLuQ9UemEIAdTw_dTn_98 X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_03,2023-08-28_04,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 spamscore=0 lowpriorityscore=0 adultscore=0 mlxlogscore=867 priorityscore=1501 suspectscore=0 bulkscore=0 impostorscore=0 clxscore=1011 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308290061 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Richard, Thanks a lot for your review! Richard Biener writes: > On Wed, 23 Aug 2023, guojiufu wrote: > >> Hi, >> >> I would like to have a gentle ping... >> >> BR, >> Jeff (Jiufu Guo) >> >> On 2023-08-07 10:45, guojiufu via Gcc-patches wrote: >> > Hi, >> > >> > Gentle ping... >> > >> > On 2023-07-18 22:05, Jiufu Guo wrote: >> >> Hi, >> >> >> >> Integer expression "(X - N * M) / N" can be optimized to "X / N - M" >> >> if there is no wrap/overflow/underflow and "X - N * M" has the same >> >> sign with "X". >> >> >> >> Compare the previous version: >> >> https://gcc.gnu.org/pipermail/gcc-patches/2023-July/624067.html >> >> - APIs: overflow, nonnegative_p and nonpositive_p are moved close >> >> to value range. >> >> - Use above APIs in match.pd. >> >> >> >> Bootstrap & regtest pass on ppc64{,le} and x86_64. >> >> Is this patch ok for trunk? >> >> >> >> BR, >> >> Jeff (Jiufu Guo) >> >> >> >> PR tree-optimization/108757 >> >> >> >> gcc/ChangeLog: >> >> >> >> * match.pd ((X - N * M) / N): New pattern. >> >> ((X + N * M) / N): New pattern. >> >> ((X + C) div_rshift N): New pattern. >> >> >> >> gcc/testsuite/ChangeLog: >> >> >> >> * gcc.dg/pr108757-1.c: New test. >> >> * gcc.dg/pr108757-2.c: New test. >> >> * gcc.dg/pr108757.h: New test. >> >> >> >> --- >> >> gcc/match.pd | 85 +++++++++++ >> >> gcc/testsuite/gcc.dg/pr108757-1.c | 18 +++ >> >> gcc/testsuite/gcc.dg/pr108757-2.c | 19 +++ >> >> gcc/testsuite/gcc.dg/pr108757.h | 233 >> >> ++++++++++++++++++++++++++++++ >> >> 4 files changed, 355 insertions(+) >> >> create mode 100644 gcc/testsuite/gcc.dg/pr108757-1.c >> >> create mode 100644 gcc/testsuite/gcc.dg/pr108757-2.c >> >> create mode 100644 gcc/testsuite/gcc.dg/pr108757.h >> >> >> >> diff --git a/gcc/match.pd b/gcc/match.pd >> >> index 8543f777a28..39dbb0567dc 100644 >> >> --- a/gcc/match.pd >> >> +++ b/gcc/match.pd >> >> @@ -942,6 +942,91 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) >> >> #endif >> >> )))) >> >> >> >> +#if GIMPLE >> >> +(for div (trunc_div exact_div) >> >> + /* Simplify (t + M*N) / N -> t / N + M. */ >> >> + (simplify >> >> + (div (plus:c@4 @0 (mult:c@3 @1 @2)) @2) > > The :c on the plus isn't necessary? ":c" would be needed. Because when the pattern is matched in gimple passes(e.g. vrp), the insn sequences would looks like: "%_6 = N * M; %_7 = %_6 + t": "%_6" is leading "t". Without ":c", the pattern may need write as: (plus@4 (mult:c@3 @1 @2) $0). > >> >> + (with {value_range vr0, vr1, vr2, vr3, vr4;} >> >> + (if (INTEGRAL_TYPE_P (type) >> >> + && get_range_query (cfun)->range_of_expr (vr1, @1) >> >> + && get_range_query (cfun)->range_of_expr (vr2, @2) >> >> + && range_op_handler (MULT_EXPR).overflow_free_p (vr1, vr2) > > the multiplication doesn't overflow Yes, this is checking no overflow on mult. > >> >> + && get_range_query (cfun)->range_of_expr (vr0, @0) >> >> + && get_range_query (cfun)->range_of_expr (vr3, @3) >> >> + && range_op_handler (PLUS_EXPR).overflow_free_p (vr0, vr3) > > the add doesn't overflow Yes, this is checking no overflow on add. > >> >> + && get_range_query (cfun)->range_of_expr (vr4, @4) >> >> + && (TYPE_UNSIGNED (type) >> >> + || (vr0.nonnegative_p () && vr4.nonnegative_p ()) >> >> + || (vr0.nonpositive_p () && vr4.nonpositive_p ()))) > > I don't know what this checks - the add result and the add first > argument are not of opposite sign. Huh. At least this part > needs an explaining comment. Right, "X-N*M" is not with opposite sign of "X". Because it is trunc_div in this pattern. Which cutting towards zero, if "X-N*M" changes the sign of "X", then "(X-N*M)/N" and "X/N" cut mod to different direction. A comment is needed, I will add. > > Sorry if we hashed this out before, but you can see I forgot > and it's not obvious. > >> >> + (plus (div @0 @2) @1)))) >> >> + >> >> + /* Simplify (t - M*N) / N -> t / N - M. */ >> >> + (simplify >> >> + (div (minus@4 @0 (mult:c@3 @1 @2)) @2) >> >> + (with {value_range vr0, vr1, vr2, vr3, vr4;} >> >> + (if (INTEGRAL_TYPE_P (type) >> >> + && get_range_query (cfun)->range_of_expr (vr1, @1) >> >> + && get_range_query (cfun)->range_of_expr (vr2, @2) >> >> + && range_op_handler (MULT_EXPR).overflow_free_p (vr1, vr2) >> >> + && get_range_query (cfun)->range_of_expr (vr0, @0) >> >> + && get_range_query (cfun)->range_of_expr (vr3, @3) >> >> + && range_op_handler (MINUS_EXPR).overflow_free_p (vr0, vr3) >> >> + && get_range_query (cfun)->range_of_expr (vr4, @4) >> >> + && (TYPE_UNSIGNED (type) >> >> + || (vr0.nonnegative_p () && vr4.nonnegative_p ()) >> >> + || (vr0.nonpositive_p () && vr4.nonpositive_p ()))) >> >> + (minus (div @0 @2) @1))))) > > looks like exactly the same - if you use a > > (for addsub (plus minus) I also tried to use this. But fail, the reason is similar with adding ":c" for "plus". For "plus", the insn sequences would like: "%_6 = N * M; %_7 = %_6 + t": "%_6" is leading "t". (plus@4 (mult:c@3 @1 @2) $0). But for "sub", the insn sequence would be: "%_6 = N * M; %_7 = t - %_6": "t" is leading "%6". (sub@4 $0 (mult:c@3 @1 @2)). So, I fail to combine these two patterns into one. > > you should be able to do range_op_handler (addsub). > >> >> + >> >> +/* Simplify >> >> + (t + C) / N -> t / N + C / N where C is multiple of N. >> >> + (t + C) >> N -> t >> N + C>>N if low N bits of C is 0. */ >> >> +(for op (trunc_div exact_div rshift) >> >> + (simplify >> >> + (op (plus@3 @0 INTEGER_CST@1) INTEGER_CST@2) >> >> + (with >> >> + { >> >> + wide_int c = wi::to_wide (@1); >> >> + wide_int n = wi::to_wide (@2); >> >> + bool is_rshift = op == RSHIFT_EXPR; >> >> + bool neg_c = false; >> >> + bool ok = false; >> >> + value_range vr0; >> >> + if (INTEGRAL_TYPE_P (type) >> >> + && get_range_query (cfun)->range_of_expr (vr0, @0)) >> >> + { >> >> + ok = is_rshift ? wi::ctz (c) >= n.to_shwi () >> >> + : wi::multiple_of_p (c, n, TYPE_SIGN (type)); >> >> + value_range vr1, vr3; >> >> + ok = ok && get_range_query (cfun)->range_of_expr (vr1, @1) >> >> + && range_op_handler (PLUS_EXPR).overflow_free_p (vr0, vr1) >> >> + && get_range_query (cfun)->range_of_expr (vr3, @3) >> >> + && (TYPE_UNSIGNED (type) >> >> + || (vr0.nonnegative_p () && vr3.nonnegative_p ()) >> >> + || (vr0.nonpositive_p () && vr3.nonpositive_p ())); >> >> + >> >> + /* Try check 'X + C' as 'X - -C' for unsigned. */ >> >> + if (!ok && TYPE_UNSIGNED (type) && c.sign_mask () < 0) >> >> + { >> >> + neg_c = true; >> >> + c = -c; >> >> + ok = is_rshift ? wi::ctz (c) >= n.to_shwi () >> >> + : wi::multiple_of_p (c, n, UNSIGNED); >> >> + ok = ok && wi::geu_p (vr0.lower_bound (), c); >> >> + } >> >> + } >> >> + } >> >> + (if (ok) >> >> + (with >> >> + { >> >> + wide_int m; >> >> + m = is_rshift ? wi::rshift (c, n, TYPE_SIGN (type)) >> >> + : wi::div_trunc (c, n, TYPE_SIGN (type)); >> >> + m = neg_c ? -m : m; >> >> + } > > why doesn't this look as nice as the other pattern? I'd put > > (if (wi::multiple_of_p ( ....)) > > for @1 and @2 outside, then the rest should follow the pattern > of the above patterns? Thanks, I would try to refactor the pattern. BR, Jeff (Jiufu Guo) > > Thanks, > Richard. > >> >> + (plus (op @0 @2) { wide_int_to_tree(type, m); })))))) >> >> +#endif >> >> + >> >> (for op (negate abs) >> >> /* Simplify cos(-x) and cos(|x|) -> cos(x). Similarly for cosh. */ >> >> (for coss (COS COSH) >> >> diff --git a/gcc/testsuite/gcc.dg/pr108757-1.c >> >> b/gcc/testsuite/gcc.dg/pr108757-1.c >> >> new file mode 100644 >> >> index 00000000000..7908f4bdcb8 >> >> --- /dev/null >> >> +++ b/gcc/testsuite/gcc.dg/pr108757-1.c >> >> @@ -0,0 +1,18 @@ >> >> +/* PR tree-optimization/108757 */ >> >> +/* { dg-do compile } */ >> >> +/* { dg-options "-O2 -fdump-tree-optimized" } */ >> >> + >> >> +#include >> >> +#define N 5 >> >> +#define M 3 >> >> +#define GAP 0 >> >> +typedef unsigned int UINT; >> >> +typedef int INT; >> >> +#define UMAX UINT_MAX >> >> +#define IMAX INT_MAX >> >> +#define IMIN INT_MIN >> >> +#include "pr108757.h" >> >> + >> >> +/* { dg-final { scan-tree-dump-not " = x_\[0-9\]+\\(D\\) \\+ " >> >> "optimized" } } * >> >> +/* { dg-final { scan-tree-dump-not " = x_\[0-9\]+\\(D\\) \\- " >> >> "optimized" } } */ >> >> +/* { dg-final { scan-tree-dump-not " = b_\[0-9\]+ \\+ " "optimized" } } */ >> >> diff --git a/gcc/testsuite/gcc.dg/pr108757-2.c >> >> b/gcc/testsuite/gcc.dg/pr108757-2.c >> >> new file mode 100644 >> >> index 00000000000..82bebd09944 >> >> --- /dev/null >> >> +++ b/gcc/testsuite/gcc.dg/pr108757-2.c >> >> @@ -0,0 +1,19 @@ >> >> +/* PR tree-optimization/108757 */ >> >> +/* { dg-do compile } */ >> >> +/* { dg-options "-O2 -fdump-tree-optimized -fwrapv" } */ >> >> + >> >> +#include >> >> +#define N 4 >> >> +#define M 3 >> >> +#define GAP 2 >> >> +typedef unsigned int UINT; >> >> +typedef int INT; >> >> +#define UMAX UINT_MAX >> >> +#define IMAX INT_MAX >> >> +#define IMIN INT_MIN >> >> +#include "pr108757.h" >> >> + >> >> +/* { dg-final { scan-tree-dump-times " = x_\[0-9\]+\\(D\\) \\+ " 16 >> >> "optimized" } } */ >> >> +/* { dg-final { scan-tree-dump-times " = x_\[0-9\]+\\(D\\) \\- " 3 >> >> "optimized" } } */ >> >> +/* { dg-final { scan-tree-dump-times " \\+ x_\[0-9\]+\\(D\\)" 3 >> >> "optimized" } } */ >> >> + >> >> diff --git a/gcc/testsuite/gcc.dg/pr108757.h >> >> b/gcc/testsuite/gcc.dg/pr108757.h >> >> new file mode 100644 >> >> index 00000000000..5550199c1ef >> >> --- /dev/null >> >> +++ b/gcc/testsuite/gcc.dg/pr108757.h >> >> @@ -0,0 +1,233 @@ >> >> +#define NOINLINE __attribute__ ((noinline)) >> >> +UINT NOINLINE >> >> +opt_u1 (UINT x) >> >> +{ >> >> + if (x < (M * N) - GAP) >> >> + return 0; >> >> + UINT a = x - (M * N); >> >> + UINT b = a / N; >> >> + return b + M; >> >> +} >> >> + >> >> +UINT NOINLINE >> >> +opt_u2 (UINT x) >> >> +{ >> >> + if (x > (UMAX - (M * N) + GAP)) >> >> + return 0; >> >> + UINT a = x + (M * N); >> >> + UINT b = a / N; >> >> + return b - M; >> >> +} >> >> + >> >> +INT NOINLINE >> >> +opt_s1 (INT x) >> >> +{ >> >> + if (x < (M * N) - GAP) >> >> + return 0; >> >> + INT a = x - (M * N); >> >> + INT b = a / N; >> >> + return b + M; >> >> +} >> >> + >> >> +INT NOINLINE >> >> +opt_s2 (INT x) >> >> +{ >> >> + if (x < IMIN + (M * N) - GAP || x > 0) >> >> + return 0; >> >> + INT a = x - (M * N); >> >> + INT b = a / N; >> >> + return b + M; >> >> +} >> >> + >> >> +INT NOINLINE >> >> +opt_s3 (INT x) >> >> +{ >> >> + if (x < (M * N) - GAP) >> >> + return 0; >> >> + INT a = x - (M * N); >> >> + INT b = a / -N; >> >> + return b + -M; >> >> +} >> >> + >> >> +INT NOINLINE >> >> +opt_s4 (INT x) >> >> +{ >> >> + if (x < IMIN + (M * N) - GAP || x > 0) >> >> + return 0; >> >> + INT a = x - (M * N); >> >> + INT b = a / -N; >> >> + return b + -M; >> >> +} >> >> + >> >> +INT NOINLINE >> >> +opt_s5 (INT x) >> >> +{ >> >> + if (x > (-M * N) + GAP) >> >> + return 0; >> >> + INT a = x - (-M * N); >> >> + INT b = a / N; >> >> + return b + -M; >> >> +} >> >> + >> >> +INT NOINLINE >> >> +opt_s6 (INT x) >> >> +{ >> >> + if (x > IMAX - (M * N) + GAP || x < 0) >> >> + return 0; >> >> + INT a = x - (-M * N); >> >> + INT b = a / N; >> >> + return b + -M; >> >> +} >> >> + >> >> +INT NOINLINE >> >> +opt_s7 (INT x) >> >> +{ >> >> + if (x > (M * -N) + GAP) >> >> + return 0; >> >> + INT a = x - (M * -N); >> >> + INT b = a / -N; >> >> + return b + M; >> >> +} >> >> + >> >> +INT NOINLINE >> >> +opt_s8 (INT x) >> >> +{ >> >> + if (x > IMAX - (M * N) + GAP || x < 0) >> >> + return 0; >> >> + INT a = x - (M * -N); >> >> + INT b = a / -N; >> >> + return b + M; >> >> +} >> >> + >> >> +UINT NOINLINE >> >> +opt_u3 (UINT x) >> >> +{ >> >> + if (x < (M << N) - GAP) >> >> + return 0; >> >> + UINT a = x - (M << N); >> >> + UINT b = a >> N; >> >> + return b + M; >> >> +} >> >> + >> >> +UINT NOINLINE >> >> +opt_u4 (UINT x) >> >> +{ >> >> + if (x > (UMAX - (M << N)) + GAP) >> >> + return 0; >> >> + UINT a = x + (M << N); >> >> + UINT b = a >> N; >> >> + return b - M; >> >> +} >> >> + >> >> +INT NOINLINE >> >> +opt_s9 (INT x) >> >> +{ >> >> + if (x < (M << N) - GAP) >> >> + return 0; >> >> + INT a = x - (M << N); >> >> + INT b = a >> N; >> >> + return b + M; >> >> +} >> >> + >> >> +INT NOINLINE >> >> +opt_s10 (INT x) >> >> +{ >> >> + if (x < IMIN + (M << N) - GAP || x > 0) >> >> + return 0; >> >> + INT a = x - (M << N); >> >> + INT b = a >> N; >> >> + return b + M; >> >> +} >> >> + >> >> +INT NOINLINE >> >> +opt_s11 (INT x) >> >> +{ >> >> + if (x > (-M << N) + GAP) >> >> + return 0; >> >> + INT a = x - (-M << N); >> >> + INT b = a >> N; >> >> + return b + -M; >> >> +} >> >> + >> >> +INT NOINLINE >> >> +opt_s12 (INT x) >> >> +{ >> >> + if (x > IMAX - (M << N) + GAP || x < 0) >> >> + return 0; >> >> + INT a = x - (-M << N); >> >> + INT b = a >> N; >> >> + return b + -M; >> >> +} >> >> + >> >> +UINT NOINLINE >> >> +opt_u5 (UINT x, UINT n, UINT m) >> >> +{ >> >> + if (n > N || m > M) >> >> + return 0; >> >> + if (x < (M*N) - GAP) >> >> + return 0; >> >> + UINT a = x - (m * n); >> >> + UINT b = a / n; >> >> + return b + m; >> >> +} >> >> + >> >> +UINT NOINLINE >> >> +opt_u6 (UINT x, UINT n, UINT m) >> >> +{ >> >> + if (n > N || m > M) >> >> + return 0; >> >> + if (x > (UMAX - M*N) + GAP) >> >> + return 0; >> >> + UINT a = x + (m * n); >> >> + UINT b = a / n; >> >> + return b - m; >> >> +} >> >> + >> >> +INT NOINLINE >> >> +opt_s13 (INT x, INT n, INT m) >> >> +{ >> >> + if (n > N || m > M || n < 0 || m < 0) >> >> + return 0; >> >> + if (x < (M*N) - GAP) >> >> + return 0; >> >> + INT a = x - (m * n); >> >> + INT b = a / n; >> >> + return b + m; >> >> +} >> >> + >> >> +INT NOINLINE >> >> +opt_s14 (INT x, INT n, INT m) >> >> +{ >> >> + if (n > N || m > M || n < 0 || m < 0) >> >> + return 0; >> >> + if (x > -M*N + GAP) >> >> + return 0; >> >> + INT a = x + (m * n); >> >> + INT b = a / n; >> >> + return b - m; >> >> +} >> >> + >> >> +INT >> >> +opt_s15 (INT x, INT n, INT m) >> >> +{ >> >> + if (n > 0 || m > 0 || n < -N || m < -M) >> >> + return 0; >> >> + if (x < (M*N) - GAP) >> >> + return 0; >> >> + INT a = x - (m * n); >> >> + INT b = a / n; >> >> + return b + m; >> >> +} >> >> + >> >> +INT NOINLINE >> >> +opt_s16 (INT x, INT n, INT m) >> >> +{ >> >> + if (n > 0 || m > 0 || n < -N || m < -M) >> >> + return 0; >> >> + if (x < 0 || x > (IMAX - M*N) + GAP) >> >> + return 0; >> >> + INT a = x + (m * n); >> >> + INT b = a / n; >> >> + return b - m; >> >> +} >> >> + >>