From patchwork Tue Apr 27 15:32:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Schmidt X-Patchwork-Id: 1470736 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=dDpa92a9; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FV5RK4vC5z9sxS for ; Wed, 28 Apr 2021 01:34:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9FAFA398EC20; Tue, 27 Apr 2021 15:34:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9FAFA398EC20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1619537661; bh=WMKmQjygxMpa0xyw0Z0ceXBgB9ue1iZufUPZteExI0A=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=dDpa92a9ZSxdEeENvy6K81QDuY+zsiKGQaOLySIHI2F9xvyDkQVvd1jUXwyjCmSFl jh6XUQ6Tbw2hKBySPYTsags9R1KQMaUm3w5N/alZJv0Tt5Zw2nL4mzBtPp5DbHRLIF b2faGKEldAPu1EFmei/vQPCixcTq9U33VpnexCog= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 1E21B398B89D for ; Tue, 27 Apr 2021 15:34:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1E21B398B89D Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13RFWi26156438; Tue, 27 Apr 2021 11:34:14 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 386muqs5xu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Apr 2021 11:34:14 -0400 Received: from m0098413.ppops.net (m0098413.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13RFY7eS163977; Tue, 27 Apr 2021 11:34:14 -0400 Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0b-001b2d01.pphosted.com with ESMTP id 386muqs5xg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Apr 2021 11:34:14 -0400 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13RFN4ta018518; Tue, 27 Apr 2021 15:34:13 GMT Received: from b01cxnp22034.gho.pok.ibm.com (b01cxnp22034.gho.pok.ibm.com [9.57.198.24]) by ppma01wdc.us.ibm.com with ESMTP id 384ay9edtd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Apr 2021 15:34:13 +0000 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13RFYCd938470028 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 27 Apr 2021 15:34:12 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4C3F7112062; Tue, 27 Apr 2021 15:34:12 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 28EF5112065; Tue, 27 Apr 2021 15:34:12 +0000 (GMT) Received: from ltcden2-lp1.aus.stglabs.ibm.com (unknown [9.53.174.68]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTPS; Tue, 27 Apr 2021 15:34:12 +0000 (GMT) Received: by ltcden2-lp1.aus.stglabs.ibm.com (Postfix, from userid 1006) id A670F41397AD; Tue, 27 Apr 2021 10:34:11 -0500 (CDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 07/57] rs6000: Add functions for matching types, part 1 of 3 Date: Tue, 27 Apr 2021 10:32:42 -0500 Message-Id: <7d8e91f0bb4a8677dad1570e1adbcfe6e469e2bf.1619537141.git.wschmidt@linux.ibm.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: -wuUYeQlZyT4p6X_XmWCzyb0LyGdM1b6 X-Proofpoint-ORIG-GUID: mMo-h1BMHV0w9EkI3REBJrQjJsGgUj3p X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-04-27_08:2021-04-27, 2021-04-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 impostorscore=0 mlxscore=0 suspectscore=0 priorityscore=1501 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104270108 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Bill Schmidt via Gcc-patches From: Bill Schmidt Reply-To: Bill Schmidt Cc: jakub@redhat.com, Bill Schmidt , jlaw@tachyum.com, dje.gcc@gmail.com, segher@kernel.crashing.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" 2021-04-02 Bill Schmidt gcc/ * config/rs6000/rs6000-gen-builtins.c (void_status): New enum. (basetype): Likewise. (typeinfo): New struct. (handle_pointer): New function. (match_basetype): New stub function. (match_const_restriction): Likewise. (match_type): New function. --- gcc/config/rs6000/rs6000-gen-builtins.c | 364 ++++++++++++++++++++++++ 1 file changed, 364 insertions(+) diff --git a/gcc/config/rs6000/rs6000-gen-builtins.c b/gcc/config/rs6000/rs6000-gen-builtins.c index f3e1d31c225..ac061d092e7 100644 --- a/gcc/config/rs6000/rs6000-gen-builtins.c +++ b/gcc/config/rs6000/rs6000-gen-builtins.c @@ -190,6 +190,49 @@ static char linebuf[LINELEN]; static int line; static int pos; +/* Used to determine whether a type can be void (only return types). */ +enum void_status { + VOID_NOTOK, + VOID_OK +}; + +/* Legal base types for an argument or return type. */ +enum basetype { + BT_CHAR, + BT_SHORT, + BT_INT, + BT_LONG, + BT_LONGLONG, + BT_FLOAT, + BT_DOUBLE, + BT_LONGDOUBLE, + BT_INT128, + BT_FLOAT128, + BT_BOOL, + BT_STRING, + BT_DECIMAL32, + BT_DECIMAL64, + BT_DECIMAL128, + BT_IBM128, + BT_VPAIR, + BT_VQUAD +}; + +/* Type modifiers for an argument or return type. */ +struct typeinfo { + char isvoid; + char isconst; + char isvector; + char issigned; + char isunsigned; + char isbool; + char ispixel; + char ispointer; + basetype base; + int val1; + int val2; +}; + /* Exit codes for the shell. */ enum exit_codes { EC_INTERR @@ -331,3 +374,324 @@ match_to_right_bracket () pos = lastpos + 1; return buf; } + +static inline void +handle_pointer (typeinfo *typedata) +{ + consume_whitespace (); + if (linebuf[pos] == '*') + { + typedata->ispointer = 1; + safe_inc_pos (); + } +} + +/* Match one of the allowable base types. Consumes one token unless the + token is "long", which must be paired with a second "long". Optionally + consumes a following '*' token for pointers. Return 1 for success, + 0 for failure. */ +static int +match_basetype (typeinfo *typedata) +{ + return 1; +} + +/* A const int argument may be restricted to certain values. This is + indicated by one of the following occurring after the "int' token: + + restricts the constant to x bits, interpreted as unsigned + restricts the constant to the inclusive range [x,y] + [x,y] restricts the constant to the inclusive range [x,y], + but only applies if the argument is constant. + {x,y} restricts the constant to one of two values, x or y. + + Here x and y are integer tokens. Note that the "const" token is a + lie when the restriction is [x,y], but this simplifies the parsing + significantly and is hopefully forgivable. + + Return 1 for success, else 0. */ +static int +match_const_restriction (typeinfo *typedata) +{ + return 1; +} + +/* Look for a type, which can be terminated by a token that is not part of + a type, a comma, or a closing parenthesis. Place information about the + type in TYPEDATA. Return 1 for success, 0 for failure. */ +static int +match_type (typeinfo *typedata, int voidok) +{ + /* A legal type is of the form: + + [const] [[signed|unsigned] | ] [*] + + Legal values of are (for now): + + char + short + int + long + long double + long long + float + double + __int128 + _Float128 + bool + string + _Decimal32 + _Decimal64 + _Decimal128 + __ibm128 + + Legal values of are as follows, and are shorthand for + the associated meaning: + + vsc vector signed char + vuc vector unsigned char + vbc vector bool char + vss vector signed short + vus vector unsigned short + vbs vector bool short + vsi vector signed int + vui vector unsigned int + vbi vector bool int + vsll vector signed long long + vull vector unsigned long long + vbll vector bool long long + vsq vector signed __int128 + vuq vector unsigned __int128 + vbq vector bool __int128 + vp vector pixel + vf vector float + vd vector double + v256 __vector_pair + v512 __vector_quad + + For simplicity, We don't support "short int" and "long long int". + We don't currently support a of "_Float16". "signed" + and "unsigned" only apply to integral base types. The optional * + indicates a pointer type. */ + + consume_whitespace (); + memset (typedata, 0, sizeof(*typedata)); + int oldpos = pos; + + char *token = match_identifier (); + if (!token) + return 0; + + if (!strcmp (token, "const")) + { + typedata->isconst = 1; + consume_whitespace (); + oldpos = pos; + token = match_identifier (); + } + + if (!strcmp (token, "void")) + typedata->isvoid = 1; + + if (!strcmp (token, "vsc")) + { + typedata->isvector = 1; + typedata->issigned = 1; + typedata->base = BT_CHAR; + handle_pointer (typedata); + return 1; + } + else if (!strcmp (token, "vuc")) + { + typedata->isvector = 1; + typedata->isunsigned = 1; + typedata->base = BT_CHAR; + handle_pointer (typedata); + return 1; + } + else if (!strcmp (token, "vbc")) + { + typedata->isvector = 1; + typedata->isbool = 1; + typedata->base = BT_CHAR; + handle_pointer (typedata); + return 1; + } + else if (!strcmp (token, "vss")) + { + typedata->isvector = 1; + typedata->issigned = 1; + typedata->base = BT_SHORT; + handle_pointer (typedata); + return 1; + } + else if (!strcmp (token, "vus")) + { + typedata->isvector = 1; + typedata->isunsigned = 1; + typedata->base = BT_SHORT; + handle_pointer (typedata); + return 1; + } + else if (!strcmp (token, "vbs")) + { + typedata->isvector = 1; + typedata->isbool = 1; + typedata->base = BT_SHORT; + handle_pointer (typedata); + return 1; + } + else if (!strcmp (token, "vsi")) + { + typedata->isvector = 1; + typedata->issigned = 1; + typedata->base = BT_INT; + handle_pointer (typedata); + return 1; + } + else if (!strcmp (token, "vui")) + { + typedata->isvector = 1; + typedata->isunsigned = 1; + typedata->base = BT_INT; + handle_pointer (typedata); + return 1; + } + else if (!strcmp (token, "vbi")) + { + typedata->isvector = 1; + typedata->isbool = 1; + typedata->base = BT_INT; + handle_pointer (typedata); + return 1; + } + else if (!strcmp (token, "vsll")) + { + typedata->isvector = 1; + typedata->issigned = 1; + typedata->base = BT_LONGLONG; + handle_pointer (typedata); + return 1; + } + else if (!strcmp (token, "vull")) + { + typedata->isvector = 1; + typedata->isunsigned = 1; + typedata->base = BT_LONGLONG; + handle_pointer (typedata); + return 1; + } + else if (!strcmp (token, "vbll")) + { + typedata->isvector = 1; + typedata->isbool = 1; + typedata->base = BT_LONGLONG; + handle_pointer (typedata); + return 1; + } + else if (!strcmp (token, "vsq")) + { + typedata->isvector = 1; + typedata->issigned = 1; + typedata->base = BT_INT128; + handle_pointer (typedata); + return 1; + } + else if (!strcmp (token, "vuq")) + { + typedata->isvector = 1; + typedata->isunsigned = 1; + typedata->base = BT_INT128; + handle_pointer (typedata); + return 1; + } + else if (!strcmp (token, "vbq")) + { + typedata->isvector = 1; + typedata->isbool = 1; + typedata->base = BT_INT128; + handle_pointer (typedata); + return 1; + } + else if (!strcmp (token, "vp")) + { + typedata->isvector = 1; + typedata->ispixel = 1; + typedata->base = BT_SHORT; + handle_pointer (typedata); + return 1; + } + else if (!strcmp (token, "vf")) + { + typedata->isvector = 1; + typedata->base = BT_FLOAT; + handle_pointer (typedata); + return 1; + } + else if (!strcmp (token, "vd")) + { + typedata->isvector = 1; + typedata->base = BT_DOUBLE; + handle_pointer (typedata); + return 1; + } + else if (!strcmp (token, "v256")) + { + typedata->isvector = 1; + typedata->base = BT_VPAIR; + handle_pointer (typedata); + return 1; + } + else if (!strcmp (token, "v512")) + { + typedata->isvector = 1; + typedata->base = BT_VQUAD; + handle_pointer (typedata); + return 1; + } + else if (!strcmp (token, "signed")) + typedata->issigned = 1; + else if (!strcmp (token, "unsigned")) + typedata->isunsigned = 1; + else if (!typedata->isvoid && !typedata->isconst) + { + /* Push back token. */ + pos = oldpos; + return match_basetype (typedata); + } + + if (typedata->isvoid) + { + consume_whitespace (); + if (linebuf[pos] == '*') + { + typedata->ispointer = 1; + safe_inc_pos (); + } + else if (!voidok) + return 0; + return 1; + } + + if (!typedata->issigned && !typedata->isunsigned) + pos = oldpos; + if (!match_basetype (typedata)) + return 0; + + if (typedata->isconst) + { + if (typedata->ispointer) + return 1; + if (typedata->base != BT_INT) + { + (*diag)("'const' at %d requires pointer or integer type", + oldpos + 1); + return 0; + } + consume_whitespace (); + if (linebuf[pos] == '<' || linebuf[pos] == '{' || linebuf[pos] == '[') + return match_const_restriction (typedata); + } + + return 1; +}