{"id":810717,"url":"http://patchwork.ozlabs.org/api/patches/810717/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/1504715047.18797.12.camel@us.ibm.com/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1504715047.18797.12.camel@us.ibm.com>","list_archive_url":null,"date":"2017-09-06T16:24:07","name":"[rs6000] Add builtins to convert from float/double to int/long using current rounding mode","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"bbc4b0f9d1e85a86ff7f33ce6ec9545b0f64ea13","submitter":{"id":1003,"url":"http://patchwork.ozlabs.org/api/people/1003/?format=json","name":"Carl Love","email":"cel@us.ibm.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/1504715047.18797.12.camel@us.ibm.com/mbox/","series":[{"id":1849,"url":"http://patchwork.ozlabs.org/api/series/1849/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=1849","date":"2017-09-06T16:24:07","name":"[rs6000] Add builtins to convert from float/double to int/long using current rounding mode","version":1,"mbox":"http://patchwork.ozlabs.org/series/1849/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/810717/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/810717/checks/","tags":{},"related":[],"headers":{"Return-Path":"<gcc-patches-return-461630-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-461630-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"DUwfuf8n\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xnTT41803z9s7F\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu,  7 Sep 2017 02:25:11 +1000 (AEST)","(qmail 96122 invoked by alias); 6 Sep 2017 16:24:59 -0000","(qmail 96109 invoked by uid 89); 6 Sep 2017 16:24:58 -0000","from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com)\n\t(148.163.158.5) by sourceware.org\n\t(qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tWed, 06 Sep 2017 16:24:56 +0000","from pps.filterd (m0098419.ppops.net [127.0.0.1])\tby\n\tmx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id\n\tv86GOVs8103440\tfor <gcc-patches@gcc.gnu.org>;\n\tWed, 6 Sep 2017 12:24:55 -0400","from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150])\tby\n\tmx0b-001b2d01.pphosted.com with ESMTP id\n\t2cthjqmty5-1\t(version=TLSv1.2 cipher=AES256-SHA bits=256\n\tverify=NOT)\tfor <gcc-patches@gcc.gnu.org>;\n\tWed, 06 Sep 2017 12:24:34 -0400","from localhost\tby e32.co.us.ibm.com with IBM ESMTP SMTP Gateway:\n\tAuthorized Use Only! Violators will be prosecuted\tfor\n\t<gcc-patches@gcc.gnu.org> from <cel@us.ibm.com>;\n\tWed, 6 Sep 2017 10:24:12 -0600","from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19)\tby\n\te32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP\n\tGateway: Authorized Use Only! Violators will be prosecuted;\n\tWed, 6 Sep 2017 10:24:08 -0600","from b03ledav006.gho.boulder.ibm.com\n\t(b03ledav006.gho.boulder.ibm.com [9.17.130.237])\tby\n\tb03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0)\n\twith ESMTP id v86GO8Gw65667316; Wed, 6 Sep 2017 09:24:08 -0700","from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1])\tby\n\tIMSVA (Postfix) with ESMTP id 54E4DC603E;\n\tWed,  6 Sep 2017 10:24:08 -0600 (MDT)","from oc3304648336.ibm.com (unknown [9.70.82.190])\tby\n\tb03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id\n\tDB96FC603C; Wed,  6 Sep 2017 10:24:07 -0600 (MDT)"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender\n\t:subject:from:to:cc:date:content-type:mime-version\n\t:content-transfer-encoding:message-id; q=dns; s=default; b=Mt4bZ\n\tMQxuwbyw4r9GbLTJ0Kse/leYlRIHtateiuX9nYhAYa5jqMRLcu5sraszOfYFeTfv\n\tyb1bBHRhG7b4/qxKO3ciG30rHwiZyjJ127CiS6Fe+lpwZ6icMm1TZSdCPq0N8roJ\n\ttRLkssYQlOAHHcU1bQVbBr/H9nFuN32mx8OXXM=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender\n\t:subject:from:to:cc:date:content-type:mime-version\n\t:content-transfer-encoding:message-id; s=default; bh=hPmpri97ouo\n\tap0M4vaBaq8Hk7Bc=; b=DUwfuf8nGp8zR82jB3BF10uPMGVLZOMZtCU5TGVg8Vn\n\tlnWOKwBXReEKbPKGYyWRMuxBkXfM6ujLnuqMNHsM2rXHmGrLKTqTvL2KqYY+09h6\n\tIS3HiDTPLITfywLgLIZ5Nek+dkP63NhujK5eZD7r4K5IkqiDctpMkQNxUh/4+Nm4\n\t=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-26.8 required=5.0 tests=AWL, BAYES_00,\n\tGIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3,\n\tRCVD_IN_DNSWL_LOW,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=0001, 22318","X-HELO":"mx0a-001b2d01.pphosted.com","Subject":"[PATCH,\n\trs6000] Add builtins to convert from float/double to int/long using\n\tcurrent rounding mode","From":"Carl Love <cel@us.ibm.com>","To":"gcc-patches@gcc.gnu.org, David Edelsohn <dje.gcc@gmail.com>,\n\tSegher\tBoessenkool <segher@kernel.crashing.org>","Cc":"Bill Schmidt <wschmidt@linux.vnet.ibm.com>, cel@us.ibm.com","Date":"Wed, 06 Sep 2017 09:24:07 -0700","Content-Type":"text/plain; charset=\"UTF-8\"","Mime-Version":"1.0","Content-Transfer-Encoding":"7bit","X-TM-AS-GCONF":"00","x-cbid":"17090616-0004-0000-0000-000012E172E1","X-IBM-SpamModules-Scores":"","X-IBM-SpamModules-Versions":"BY=3.00007678; HX=3.00000241; KW=3.00000007;\n\tPH=3.00000004; SC=3.00000226; SDB=6.00913145; UDB=6.00458277;\n\tIPR=6.00693408; BA=6.00005574; NDR=6.00000001; ZLA=6.00000005;\n\tZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000;\n\tZU=6.00000002; MB=3.00017035; XFM=3.00000015;\n\tUTC=2017-09-06 16:24:10","X-IBM-AV-DETECTION":"SAVI=unused REMOTE=unused XFE=unused","x-cbparentid":"17090616-0005-0000-0000-000081024E8C","Message-Id":"<1504715047.18797.12.camel@us.ibm.com>","X-Proofpoint-Virus-Version":"vendor=fsecure engine=2.50.10432:, ,\n\tdefinitions=2017-09-06_06:, , signatures=0","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n\tspamscore=0 suspectscore=0 malwarescore=0 phishscore=0\n\tadultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx\n\tscancount=1 engine=8.0.1-1707230000\n\tdefinitions=main-1709060231","X-IsSubscribed":"yes"},"content":"GCC Maintainers:\n\nThe following patch adds support for a couple of requested builtins that\nconvert from float/double to int / long using the current rounding\nmode. \n\nThe patch has been tested on powerpc64le-unknown-linux-gnu (Power 8 LE).\n\nPlease let me know if the following patch is acceptable.  Thanks.\n\n                        Carl Love\n\n-----------------------------------------------------------------------\n\ngcc/ChangeLog:\n\n2017-09-06  Carl Love  <cel@us.ibm.com>\n\n\t* config/rs6000/rs6000-builtin.def (FCTID, FCTIW): Add BU_P7_MISC_1\n\tmacro expansion for builtins.\n\t* config/rs6000/rs6000.md (fctid, fctiw): Add define_insn for the\n\tfctid and fctiw instructions.\n\ngcc/testsuite/ChangeLog:\n\n2017-09-06 Carl Love  <cel@us.ibm.com>\n\t* gcc.target/powerpc/builtin-fctid-fctiw-runnable.c: New test file\n\tfor the __builtin_fctid and __builtin_fctiw builtins.\n---\n gcc/config/rs6000/rs6000-builtin.def               |   2 +\n gcc/config/rs6000/rs6000.md                        |  18 +++\n .../powerpc/builtin-fctid-fctiw-runnable.c         | 138 +++++++++++++++++++++\n 3 files changed, 158 insertions(+)\n create mode 100644 gcc/testsuite/gcc.target/powerpc/builtin-fctid-fctiw-runnable.c","diff":"diff --git a/gcc/config/rs6000/rs6000-builtin.def b/gcc/config/rs6000/rs6000-builtin.def\nindex 850164a..7affa30 100644\n--- a/gcc/config/rs6000/rs6000-builtin.def\n+++ b/gcc/config/rs6000/rs6000-builtin.def\n@@ -2231,6 +2231,8 @@ BU_DFP_MISC_2 (DSCRIQ,\t\t\"dscriq\",\tCONST,\tdfp_dscri_td)\n /* 1 argument BCD functions added in ISA 2.06.  */\n BU_P7_MISC_1 (CDTBCD,\t\t\"cdtbcd\",\tCONST,\tcdtbcd)\n BU_P7_MISC_1 (CBCDTD,\t\t\"cbcdtd\",\tCONST,\tcbcdtd)\n+BU_P7_MISC_1 (FCTID,\t\t\"fctid\",\tCONST,\tfctid)\n+BU_P7_MISC_1 (FCTIW,\t\t\"fctiw\",\tCONST,\tfctiw)\n \n /* 2 argument BCD functions added in ISA 2.06.  */\n BU_P7_MISC_2 (ADDG6S,\t\t\"addg6s\",\tCONST,\taddg6s)\ndiff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md\nindex 20873ac..a5cbef5 100644\n--- a/gcc/config/rs6000/rs6000.md\n+++ b/gcc/config/rs6000/rs6000.md\n@@ -14054,6 +14054,24 @@\n   [(set_attr \"type\" \"integer\")\n    (set_attr \"length\" \"4\")])\n \n+(define_insn \"fctid\"\n+  [(set (match_operand:DI 0 \"register_operand\" \"=r\")\n+\t(unspec:DI [(match_operand:DF 1 \"register_operand\" \"f\")]\n+\t\t   UNSPEC_FCTID))]\n+  \"\"\n+  \"fctid %1,%1; mfvsrd %0,%1\"\n+  [(set_attr \"type\" \"two\")\n+   (set_attr \"length\" \"8\")])\n+\n+(define_insn \"fctiw\"\n+  [(set (match_operand:SI 0 \"register_operand\" \"=r\")\n+\t(unspec:SI [(match_operand:DF 1 \"register_operand\" \"f\")]\n+\t\t   UNSPEC_FCTIW))]\n+  \"\"\n+  \"fctiw %1,%1; mfvsrd %0,%1; extsw %0,%0\"\n+  [(set_attr \"type\" \"integer\")\n+   (set_attr \"length\" \"4\")])\n+\n (define_int_iterator UNSPEC_DIV_EXTEND [UNSPEC_DIVE\n \t\t\t\t\tUNSPEC_DIVEO\n \t\t\t\t\tUNSPEC_DIVEU\ndiff --git a/gcc/testsuite/gcc.target/powerpc/builtin-fctid-fctiw-runnable.c b/gcc/testsuite/gcc.target/powerpc/builtin-fctid-fctiw-runnable.c\nnew file mode 100644\nindex 0000000..79c5341\n--- /dev/null\n+++ b/gcc/testsuite/gcc.target/powerpc/builtin-fctid-fctiw-runnable.c\n@@ -0,0 +1,138 @@\n+/* { dg-do run { target { powerpc*-*-linux* } } } */\n+/* { dg-require-effective-target powerpc_p8vector_ok } */\n+/* { dg-options \"-mcpu=power8\" } */\n+\n+#ifdef DEBUG\n+#include <stdio.h>\n+#endif\n+\n+void abort (void);\n+\n+long\n+test_bi_lrint_1 (float __A)\n+{\n+\treturn (__builtin_fctid (__A));\n+}\n+long\n+test_bi_lrint_2 (double __A)\n+{\n+\treturn (__builtin_fctid (__A));\n+}\n+\n+int\n+test_bi_rint_1 (float __A)\n+{\n+\treturn (__builtin_fctiw (__A));\n+}\n+\n+int\n+test_bi_rint_2 (double __A)\n+{\n+\treturn (__builtin_fctiw (__A));\n+}\n+\n+\n+int main( void)\n+{\n+  signed long lx, expected_l;\n+  double dy;\n+\n+  signed int x, expected_i;\n+  float y;\n+  \n+  dy = 1.45;\n+  expected_l = 1;\n+  lx = __builtin_fctid (dy);\n+\n+  if( lx != expected_l)\n+#ifdef DEBUG\n+    printf(\"ERROR: __builtin_fctid(dy= %f) = %ld, expected %ld\\n\",\n+\t   dy, lx, expected_l);\n+#else\n+    abort();\n+#endif\n+\n+  dy = 3.51;\n+  expected_l = 4;\n+  lx = __builtin_fctid (dy);\n+  \n+  if( lx != expected_l)\n+#ifdef DEBUG\n+    printf(\"ERROR: __builtin_fctid(dy= %f) = %ld, expected %ld\\n\",\n+\t   dy, lx, expected_l);\n+#else\n+    abort();\n+#endif\n+\n+  dy = 5.57;\n+  expected_i = 6;\n+  x = __builtin_fctiw (dy);\n+\n+  if( x != expected_i)\n+#ifdef DEBUG\n+    printf(\"ERROR: __builtin_fctiw(dy= %f) = %d, expected %d\\n\",\n+\t   dy, x, expected_i);\n+#else\n+    abort();\n+#endif\n+\n+  y = 11.47;\n+  expected_i = 11;\n+  x = __builtin_fctiw (y);\n+\n+  if( x != expected_i)\n+#ifdef DEBUG\n+    printf(\"ERROR: __builtin_fctiw(y = %f) = %d, expected %d\\n\",\n+\t   y, x, expected_i);\n+#else\n+    abort();\n+#endif\n+\n+  y = 17.77;\n+  expected_l = 18;\n+  lx = test_bi_lrint_1 (y);\n+\n+  if( lx != expected_l)\n+#ifdef DEBUG\n+    printf(\"ERROR: function call test_bi_lrint_1 (y = %f) = %ld, expected %ld\\n\",\n+\t   y, lx, expected_l);\n+#else\n+    abort();\n+#endif\n+\n+  dy = 7.1;\n+  expected_l = 7;\n+  lx = test_bi_lrint_2 (dy);\n+\n+  if( lx != expected_l)\n+#ifdef DEBUG\n+    printf(\"ERROR: function call test_bi_lrint_2 (dy = %f) = %ld, expected %ld\\n\",\n+\t   dy, lx, expected_l);\n+#else\n+    abort();\n+#endif\n+\n+  y = 0.001;\n+  expected_i = 0;\n+  x = test_bi_rint_1 (y);\n+\n+  if( x != expected_i)\n+#ifdef DEBUG\n+    printf(\"ERROR: function call test_bi_rint_1 (y = %f) = %d, expected %d\\n\",\n+\t   y, x, expected_i);\n+#else\n+    abort();\n+#endif\n+  \n+  dy = 0.9999;\n+  expected_i = 1;\n+  x = test_bi_rint_2 (dy);\n+\n+  if( x != expected_i)\n+#ifdef DEBUG\n+    printf(\"ERROR: function call test_bi_rint_2 (dy = %f) = %d, expected %d\\n\",\n+\t   dy, x, expected_i);\n+#else\n+    abort();\n+#endif\n+}\n","prefixes":["rs6000"]}