From patchwork Wed Oct 25 15:57:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 117131 Delivered-To: patch@linaro.org Received: by 10.80.245.45 with SMTP id t42csp1892454edm; Wed, 25 Oct 2017 08:58:15 -0700 (PDT) X-Google-Smtp-Source: ABhQp+Rj0axJPfgoltOdoXbZlkZUa4/++yQgPWyfVUOiST/8prRwabHvXTM4lJOrsTPY8XRVnarl X-Received: by 10.101.71.135 with SMTP id e7mr2439988pgs.112.1508947095441; Wed, 25 Oct 2017 08:58:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508947095; cv=none; d=google.com; s=arc-20160816; b=ama8Jps6ZwCriCTv74MUKKU+RT+zit2aKdbtLRvoek56tcDQrSP3qPJclmazH2PW6Y gq8/eu0jLB7RB1RwEV4S8be825CGibn2Dy288Or/jXQoOItaSkf0v7ZDvz+Qcqr26Ol5 /taS6DFHrzPtG+7ePMRJm145ChFKcRQFnMy/2cbhZn+tsbblbMXe4IMlt1l2co6GTFbW QgNddM3GJ8d25EQY2spz4SG5r+KYUGJdwL8o0TUGOyYzKIVL8YGxU0mo7CZm/TSiDe11 8ehJayCc+A8Py/VzVVju53EoHOg/1pCq9Qbu75mnEPPcl7n7DY90wWz9KB1Yk+duUTNy 5G3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:date:subject:mail-followup-to:to :from:delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=IGxwz/tgHVBbEzfhrHwkxHCmO+B+U/aPuCiHmiVycQc=; b=UC2bs6TGFejIKI6mPy2Jon9gSDEYfRY2IYSuF4wbV00Tdks932Q68zzigOtpW/ZIYe WJWgtzn4eNH7yh/PGbM5EBODCFsFn0EPbonKA6tEbimvCSywLk0xy1ir/QrcZp9yz7o3 R5aCqhtewibVByXICz+UHBMLVsEgretNP1+DrmKRcYCJlsPoBDKm6893CxsZ+VGpbJop 3QeKAR1aBa3g4UqIovzQCuFrPYizJxOuo21QNenLB8VFboG475idWox+mS7HXW+GFnbO jIBdjVO1343POP0hVm0VvBfyahJZf+IE6hZsL0YQcrv5xsvbAWfO+QLioqgE7CEvcU5X eq0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=oCZ+sEMs; spf=pass (google.com: domain of gcc-patches-return-465092-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-465092-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id d125si1974793pgc.444.2017.10.25.08.58.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Oct 2017 08:58:15 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-465092-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=oCZ+sEMs; spf=pass (google.com: domain of gcc-patches-return-465092-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-465092-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=fxmwGN5cXHOt4CcgKOydlTInop7sqAG7m6wwd0va3sRsIscgPh25n i72SvsKSKKvAeNJW2kY9Y8ShpPij1dBaLhww2eFTnGUReyUmXndJ6I+gsSejodux LyMtND7O4LtfuuiGH+kFjqC2Cr0v//qzFqEn8SLUagsix6NLEAOreI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=oTzbz0irgLbd+Q3biBgDwvH8fXw=; b=oCZ+sEMsCB/vq73AEhsc qGhCh7Zxqp6NjqS1bRZMNxmiB+xJJa2A07TCHbC19KCTcodxlpTiLE0XcZcYSbu+ edgEdmFGXkieS+UscJebKVS0rsauzXcNs/x8YKjBBxWwyw8us6h1rhkeHeM927Xu fillR9/x5q0cDnw/l/uqNyE= Received: (qmail 19382 invoked by alias); 25 Oct 2017 15:58:00 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 18630 invoked by uid 89); 25 Oct 2017 15:57:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f49.google.com Received: from mail-wm0-f49.google.com (HELO mail-wm0-f49.google.com) (74.125.82.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 25 Oct 2017 15:57:57 +0000 Received: by mail-wm0-f49.google.com with SMTP id r196so2825352wmf.2 for ; Wed, 25 Oct 2017 08:57:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:date:message-id :user-agent:mime-version; bh=IGxwz/tgHVBbEzfhrHwkxHCmO+B+U/aPuCiHmiVycQc=; b=OxKozTAMwyHpQkEoLuNW/2MsQk1f/Q9oss+uHEFORTr53eS74pV9ZEYb+H1+6lWDxf aedbCIbOy4qFeoFR0fMBAu1PAazrURYiyXngCXvOuK2cmFLRIGJ/dj5Aoec0DfFlhdCw Gjf70ikveKL/fc7Jyuo2idraXgpNxamNY32b6tPXkUtnAu8cVX1VrEotQOpZemtOlMjv lk6fGPVxJgOpVt0EdQ0GBaJNLQH1tlX2nepsr2kd5XVSxDfgf55trsyZD87KvesG/5sg SZf/FQSH13szWU6Uh6bzvFuMcNVNpRrySwkjVr9IBENknkI227htzUREHidGxzKAlGrg uefg== X-Gm-Message-State: AMCzsaULcCKZ4qZFIolVBo83/yY2Z6OFrMXH4WaOykMUtfoJm1mWTxqQ kLtDDMWiubrmKeK3XXlVDMpQVF2tncY= X-Received: by 10.28.209.132 with SMTP id i126mr2165980wmg.65.1508947074924; Wed, 25 Oct 2017 08:57:54 -0700 (PDT) Received: from localhost (92.40.249.12.threembb.co.uk. [92.40.249.12]) by smtp.gmail.com with ESMTPSA id 92sm2782798wrd.15.2017.10.25.08.57.53 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 25 Oct 2017 08:57:54 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Add support for adjusting the number of units in a mode Date: Wed, 25 Oct 2017 16:57:52 +0100 Message-ID: <87k1zjte2n.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 We already allow the target to change the size and alignment of a mode. This patch does the same thing for the number of units, which is needed to give command-line control of the SVE vector length. Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linux-gnu, on top of the poly_int series. I think I can approve this under the gen* maintainership, so if there are no comments in the menatime, I'll apply it if the prerequisites are approved. Thanks, Richard 2017-10-25 Richard Sandiford Alan Hayward David Sherwood gcc/ * machmode.h (mode_precision): Prefix with CONST_MODE_PRECISION. (mode_nunits): Likewise CONST_MODE_NUNITS. * machmode.def (ADJUST_NUNITS): Document. * genmodes.c (mode_data::need_nunits_adj): New field. (blank_mode): Update accordingly. (adj_nunits): New variable. (print_maybe_const_decl): Replace CATEGORY with a NEEDS_ADJ parameter. (emit_mode_size_inline): Set need_bytesize_adj for all modes listed in adj_nunits. (emit_mode_nunits_inline): Set need_nunits_adj for all modes listed in adj_nunits. Don't emit case statements for such modes. (emit_insn_modes_h): Emit definitions of CONST_MODE_NUNITS and CONST_MODE_PRECISION. Make CONST_MODE_SIZE expand to nothing if adj_nunits is nonnull. (emit_mode_precision, emit_mode_nunits): Use print_maybe_const_decl. (emit_mode_unit_size, emit_mode_base_align, emit_mode_ibit) (emit_mode_fbit): Update use of print_maybe_const_decl. (emit_move_size): Likewise. Treat the array as non-const if adj_nunits. (emit_mode_adjustments): Handle adj_nunits. Index: gcc/machmode.h =================================================================== --- gcc/machmode.h 2017-10-25 16:50:35.628184659 +0100 +++ gcc/machmode.h 2017-10-25 16:55:00.469175980 +0100 @@ -23,9 +23,9 @@ #define HAVE_MACHINE_MODES typedef opt_mode opt_machine_mode; extern CONST_MODE_SIZE poly_uint16_pod mode_size[NUM_MACHINE_MODES]; -extern const poly_uint16_pod mode_precision[NUM_MACHINE_MODES]; +extern CONST_MODE_PRECISION poly_uint16_pod mode_precision[NUM_MACHINE_MODES]; extern const unsigned char mode_inner[NUM_MACHINE_MODES]; -extern const poly_uint16_pod mode_nunits[NUM_MACHINE_MODES]; +extern CONST_MODE_NUNITS poly_uint16_pod mode_nunits[NUM_MACHINE_MODES]; extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES]; extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES]; extern const unsigned char mode_wider[NUM_MACHINE_MODES]; Index: gcc/machmode.def =================================================================== --- gcc/machmode.def 2017-10-25 16:50:35.628184659 +0100 +++ gcc/machmode.def 2017-10-25 16:55:00.468176022 +0100 @@ -169,6 +169,12 @@ along with GCC; see the file COPYING3. Unlike a FORMAT argument, if you are adjusting a float format you must put an & in front of the name of each format structure. + ADJUST_NUNITS (MODE, EXPR); + Like the above, but set the number of nunits of MODE to EXPR. + This changes the size and precision of the mode in proportion + to the change in the number of units; for example, doubling + the number of units doubles the size and precision as well. + Note: If a mode is ever made which is more than 255 bytes wide, machmode.h and genmodes.c will have to be changed to allocate more space for the mode_size and mode_alignment arrays. */ Index: gcc/genmodes.c =================================================================== --- gcc/genmodes.c 2017-10-25 16:50:35.627184698 +0100 +++ gcc/genmodes.c 2017-10-25 16:55:00.468176022 +0100 @@ -72,7 +72,9 @@ struct mode_data unsigned int counter; /* Rank ordering of modes */ unsigned int ibit; /* the number of integral bits */ unsigned int fbit; /* the number of fractional bits */ - bool need_bytesize_adj; /* true if this mode need dynamic size + bool need_nunits_adj; /* true if this mode needs dynamic nunits + adjustment */ + bool need_bytesize_adj; /* true if this mode needs dynamic size adjustment */ unsigned int int_n; /* If nonzero, then __int will be defined */ }; @@ -85,7 +87,7 @@ static const struct mode_data blank_mode 0, "", MAX_MODE_CLASS, -1U, -1U, -1U, -1U, 0, 0, 0, 0, 0, 0, - "", 0, 0, 0, 0, false, 0 + "", 0, 0, 0, 0, false, false, 0 }; static htab_t modes_by_name; @@ -103,6 +105,7 @@ struct mode_adjust unsigned int line; }; +static struct mode_adjust *adj_nunits; static struct mode_adjust *adj_bytesize; static struct mode_adjust *adj_alignment; static struct mode_adjust *adj_format; @@ -786,6 +789,7 @@ make_vector_mode (enum mode_class bclass #define _ADD_ADJUST(A, M, X, C1, C2) \ new_adjust (#M, &adj_##A, #A, #X, MODE_##C1, MODE_##C2, __FILE__, __LINE__) +#define ADJUST_NUNITS(M, X) _ADD_ADJUST (nunits, M, X, RANDOM, RANDOM) #define ADJUST_BYTESIZE(M, X) _ADD_ADJUST (bytesize, M, X, RANDOM, RANDOM) #define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST (alignment, M, X, RANDOM, RANDOM) #define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST (format, M, X, FLOAT, FLOAT) @@ -955,9 +959,9 @@ #define tagged_printf(FMT, ARG, TAG) do #define print_decl(TYPE, NAME, ASIZE) \ puts ("\nconst " TYPE " " NAME "[" ASIZE "] =\n{"); -#define print_maybe_const_decl(TYPE, NAME, ASIZE, CATEGORY) \ +#define print_maybe_const_decl(TYPE, NAME, ASIZE, NEEDS_ADJ) \ printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \ - adj_##CATEGORY ? "" : "const ") + NEEDS_ADJ ? "" : "const ") #define print_closer() puts ("};") @@ -1015,6 +1019,11 @@ emit_mode_size_inline (void) m->need_bytesize_adj = true; } + /* Changing the number of units by a factor of X also changes the size + by a factor of X. */ + for (mode_adjust *a = adj_nunits; a; a = a->next) + a->mode->need_bytesize_adj = true; + printf ("\ #ifdef __cplusplus\n\ inline __attribute__((__always_inline__))\n\ @@ -1027,7 +1036,7 @@ mode_size_inline (machine_mode mode)\n\ extern %spoly_uint16_pod mode_size[NUM_MACHINE_MODES];\n\ gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\ switch (mode)\n\ - {\n", adj_bytesize ? "" : "const "); + {\n", adj_nunits || adj_bytesize ? "" : "const "); for_all_modes (c, m) if (!m->need_bytesize_adj) @@ -1046,7 +1055,10 @@ emit_mode_nunits_inline (void) int c; struct mode_data *m; - puts ("\ + for (mode_adjust *a = adj_nunits; a; a = a->next) + a->mode->need_nunits_adj = true; + + printf ("\ #ifdef __cplusplus\n\ inline __attribute__((__always_inline__))\n\ #else\n\ @@ -1055,12 +1067,13 @@ extern __inline__ __attribute__((__alway poly_uint16\n\ mode_nunits_inline (machine_mode mode)\n\ {\n\ - extern poly_uint16_pod mode_nunits[NUM_MACHINE_MODES];\n\ + extern %spoly_uint16_pod mode_nunits[NUM_MACHINE_MODES];\n\ switch (mode)\n\ - {"); + {\n", adj_nunits ? "" : "const "); for_all_modes (c, m) - printf (" case E_%smode: return %u;\n", m->name, m->ncomponents); + if (!m->need_nunits_adj) + printf (" case E_%smode: return %u;\n", m->name, m->ncomponents); puts ("\ default: return mode_nunits[mode];\n\ @@ -1277,7 +1290,10 @@ enum machine_mode\n{"); };\n"); /* I can't think of a better idea, can you? */ - printf ("#define CONST_MODE_SIZE%s\n", adj_bytesize ? "" : " const"); + printf ("#define CONST_MODE_NUNITS%s\n", adj_nunits ? "" : " const"); + printf ("#define CONST_MODE_PRECISION%s\n", adj_nunits ? "" : " const"); + printf ("#define CONST_MODE_SIZE%s\n", + adj_bytesize || adj_nunits ? "" : " const"); printf ("#define CONST_MODE_UNIT_SIZE%s\n", adj_bytesize ? "" : " const"); printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment ? "" : " const"); #if 0 /* disabled for backward compatibility, temporary */ @@ -1392,7 +1408,8 @@ emit_mode_precision (void) int c; struct mode_data *m; - print_decl ("poly_uint16_pod", "mode_precision", "NUM_MACHINE_MODES"); + print_maybe_const_decl ("%spoly_uint16_pod", "mode_precision", + "NUM_MACHINE_MODES", adj_nunits); for_all_modes (c, m) if (m->precision != (unsigned int)-1) @@ -1411,7 +1428,7 @@ emit_mode_size (void) struct mode_data *m; print_maybe_const_decl ("%spoly_uint16_pod", "mode_size", - "NUM_MACHINE_MODES", bytesize); + "NUM_MACHINE_MODES", adj_nunits || adj_bytesize); for_all_modes (c, m) tagged_printf ("{ %u" ZERO_COEFFS " }", m->bytesize, m->name); @@ -1425,7 +1442,8 @@ emit_mode_nunits (void) int c; struct mode_data *m; - print_decl ("poly_uint16_pod", "mode_nunits", "NUM_MACHINE_MODES"); + print_maybe_const_decl ("%spoly_uint16_pod", "mode_nunits", + "NUM_MACHINE_MODES", adj_nunits); for_all_modes (c, m) tagged_printf ("{ %u" ZERO_COEFFS " }", m->ncomponents, m->name); @@ -1563,7 +1581,7 @@ emit_mode_unit_size (void) struct mode_data *m; print_maybe_const_decl ("%sunsigned char", "mode_unit_size", - "NUM_MACHINE_MODES", bytesize); + "NUM_MACHINE_MODES", adj_bytesize); for_all_modes (c, m) tagged_printf ("%u", @@ -1604,7 +1622,7 @@ emit_mode_base_align (void) print_maybe_const_decl ("%sunsigned short", "mode_base_align", "NUM_MACHINE_MODES", - alignment); + adj_alignment); for_all_modes (c, m) tagged_printf ("%u", m->alignment, m->name); @@ -1685,6 +1703,23 @@ emit_mode_adjustments (void) \n poly_uint16 ps ATTRIBUTE_UNUSED;\n\ size_t s ATTRIBUTE_UNUSED;"); + for (a = adj_nunits; a; a = a->next) + { + m = a->mode; + printf ("\n" + " {\n" + " /* %s:%d */\n ps = %s;\n", + a->file, a->line, a->adjustment); + printf (" int old_factor = vector_element_size" + " (mode_precision[E_%smode], mode_nunits[E_%smode]);\n", + m->name, m->name); + printf (" mode_precision[E_%smode] = ps * old_factor;\n", m->name); + printf (" mode_size[E_%smode] = exact_div (mode_precision[E_%smode]," + " BITS_PER_UNIT);\n", m->name, m->name); + printf (" mode_nunits[E_%smode] = ps;\n", m->name); + printf (" }\n"); + } + /* Size adjustments must be propagated to all containing modes. A size adjustment forces us to recalculate the alignment too. */ for (a = adj_bytesize; a; a = a->next) @@ -1825,7 +1860,7 @@ emit_mode_ibit (void) print_maybe_const_decl ("%sunsigned char", "mode_ibit", "NUM_MACHINE_MODES", - ibit); + adj_ibit); for_all_modes (c, m) tagged_printf ("%u", m->ibit, m->name); @@ -1843,7 +1878,7 @@ emit_mode_fbit (void) print_maybe_const_decl ("%sunsigned char", "mode_fbit", "NUM_MACHINE_MODES", - fbit); + adj_fbit); for_all_modes (c, m) tagged_printf ("%u", m->fbit, m->name);