Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109847 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 50329 invoked from network); 25 Apr 2020 18:11:20 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Apr 2020 18:11:20 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 63920180088 for ; Sat, 25 Apr 2020 09:43:48 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS8075 40.64.0.0/10 X-Spam-Virus: No X-Envelope-From: Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12olkn2053.outbound.protection.outlook.com [40.92.23.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 25 Apr 2020 09:43:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZiyJ0/bgVgwingMk2dYzclQUnUEDrzhzro2529Q2gF+wTW6AqUss4KGAtnxqxQ1BdCkfqH5fE3r8pgT8mqbBntoeGKsTmp7b0cPuDuvwfrXNRbxf8Hsau5gZVPHhszXqQJmCoENnT1qVwWWDLHP+QsJnj/fC8xYhpS1H25cNZhzmYwM3/3KpWFBmsntlh/w4o5OXGsuSM1DwmMtGoZuu9To3hPIcVlgZNNODWrtVYDweYdfewLVPQ1XD250QQNV9+v6C01KE5D0iwNQgd1Og0OMpcXOwrjojAVYzMdGXf51eWi3F7emFBBaqGTZUZKu1gUk1kR7yVmun4Cw4rafiMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mZt2TSr1iN5pQCsAU/gybyxbU8R+UrsoCzEwH77GU0U=; b=OXLzCnOFB8DEwnqVMxEAuSkN29f53vWTqIvjlzVZsVfQvrq+FKYFKrLhOklg1Y8zBGVY1vTeaZcWxAS/c1xCnkMwKVJRBAaiF1yCdqi9PY+SagNSD4+pguEYG/PsHeF3RPTkFx2JfPcLI9eSfYZBYgr9Z/LilynGd0XSJXf60lVm3scmpTOsttWJxZpAQQ/w0jhKjztJaIg0HRzPQyadyevtjJ7TGRBTx5KTc6PFDnaHi1WAR5yAamq0GPgGWoSNUFohHsQ/zfj+C1EulqyTARaf8WWUJGq2FsMNX67ssmGtgFeb1JRqGx8U5wU0EmCs9IYHZB6TxJZ+iylB6IjWbA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mZt2TSr1iN5pQCsAU/gybyxbU8R+UrsoCzEwH77GU0U=; b=P0lqyvkN7ik1KhXfXtbK8kfJcCjSqnuRC5pD+qD8fUgjPYpmJv29uzlvnilfrjnQ/bA0wYlPw1C5q6dYPU3eACBRhG5fptLxFNUNZ+r8eGX9Zfuyemm3aGlCrfiC8peVvCsWQnZe6yioZM238uXMa+MT5kLCX8DjCVthLui5HCjU4cuh1qiUzERQC0o7epWfyNLV5AxAhczps8eTnSiwbO+AKIMDf90tyCaLHMd4dLOWMdpt28hkAYfVaAtvLCF3J2llOayaO0aZQICWfhBelBYqvL812i6IcS/SjYZqkF8ZNooeYK7AcgN5ffQQJKeUMV8Fz/TmfWEE6bQxvqRxVQ== Received: from BN8NAM12FT034.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc66::41) by BN8NAM12HT032.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc66::251) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2921.12; Sat, 25 Apr 2020 16:43:46 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:fc66::52) by BN8NAM12FT034.mail.protection.outlook.com (2a01:111:e400:fc66::260) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2921.12 via Frontend Transport; Sat, 25 Apr 2020 16:43:46 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::e553:b74f:bf64:30c5]) by DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::e553:b74f:bf64:30c5%4]) with mapi id 15.20.2921.036; Sat, 25 Apr 2020 16:43:46 +0000 To: "internals@lists.php.net" Thread-Topic: Optimizing assembly for spl_object_id(), fdiv(), etc in the JIT? Thread-Index: AQHWGxz5+Txr028sTUe2R2cg2slM+A== Date: Sat, 25 Apr 2020 16:43:46 +0000 Message-ID: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:6C141C33FD2613129E3A3B20C58AFA80F32BE05317B4ED81B6EB635F5A1F8748;UpperCasedChecksum:4C42C81241D0AEFEBC41864515445C0355FA96E9D83E41C16AF81BC3339F9213;SizeAsReceived:6752;Count:42 x-tmn: [lSj9QZXl3Qui0F1eqlR2LH4TUR+fm9cf] x-ms-publictraffictype: Email x-incomingheadercount: 42 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: c5f373c9-d987-4dbe-df83-08d7e937d2a7 x-ms-traffictypediagnostic: BN8NAM12HT032: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 3RFVMdlt5nt/z3pIEg2KY3Wl9TdqAS2yb9CP8tb9ljHgYMv/328k/amqBQnSZYdmm7U9B6O/agxcpu00/znib8Srd3nPjAy2WOvAwMgOKYK71OCci/OvHhYrPySV9y3oDcjT5NqQuNuHbtA7CENvTWAw4/MQhV9C+dpft+fOHRlQraakUpDtZhwwgqPHFSLgDpE916tMSGQ4G6PcSxNSC3Ubq5EvD+9yPKAOo9OEHjw946/LRrUR7+Ktfjs+x1VR x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:0;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR07MB6618.namprd07.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:;DIR:OUT;SFP:1901; x-ms-exchange-antispam-messagedata: a6EpwuW+oc3wnOwEF2WM6CdV4ra2rdakSzeQI6fAK9mxaDVqjoZBGolvtNJd31l5YRT5VDjtj666/Gb02p75hf9Q7i1zcJ2YPHlMHDR8bPbc4bissiAkeneMGKfZohB5TutADB/5aTi1VBahLSIKuQ== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: c5f373c9-d987-4dbe-df83-08d7e937d2a7 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Apr 2020 16:43:46.2474 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8NAM12HT032 Subject: Optimizing assembly for spl_object_id(), fdiv(), etc in the JIT? From: tysonandre775@hotmail.com (tyson andre) Hi internals,=0A= =0A= I was wondering if the maintainers of the Opcache Jit would be open to work= on optimizing functions such as intdiv(), fdiv(), and spl_object_id() in t= he JIT to assembly code when it was safe to do so.=0A= These functions have simple C implementations, so the performance overhead = of calling PHP functions in the generated assembly=0A= would be noticeable compared to emitting optimized assembly.=0A= =0A= I'd expect that it'd be safe to do so under the following circumstances:=0A= =0A= - All arguments are Compiled Variables(CV) in the opcodes (i.e. $var)=0A= (http://nikic.github.io/2017/04/14/PHP-7-Virtual-machine.html#variable-ty= pes)=0A= - The types and count of the function arguments are known to be strictly co= rrect, e.g.=0A= - Opcache infers they will not throw a TypeError or emit undefined variab= le warnings=0A= - maybe strictly accept floats but not integers for fdiv=0A= - The return value of the expression won't throw=0A= (e.g. don't perform this optimization for `$y =3D spl_object_id($x)` when= a CV is the return value)=0A= - The function in question exists and is not disabled.=0A= =0A= For example, these operands would be seen by the JIT for this sequence of o= pcodes=0A= =0A= ```php=0A= /*=0A= 0000 CV0($x) =3D RECV 1=0A= 0001 INIT_FCALL 1 96 string("spl_object_id")=0A= 0002 SEND_VAR CV0($x) 1=0A= 0003 V2 =3D DO_ICALL=0A= 0004 T1 =3D INIT_ARRAY 1 (packed) CV0($x) V2=0A= 0005 RETURN T1=0A= */=0A= function create_set(stdClass $x) : array {=0A= return [spl_object_id($x) =3D> $x];=0A= }=0A= ```=0A= =0A= I expect it to be technically feasible to check for the sequence of opcodes= INIT_FCALL, SEND_VAR (repeated), and DO_ICALL, in ext/opcache/jit/zend_jit= .c. The resulting assembly would be smaller and much faster.=0A= (this would be done before emitting any assembly - skip over the opcodes fo= r INIT_ARRAY and SEND_VAR and DO_ICALL)=0A= =0A= - What do the maintainers of the JIT module think of this idea?=0A= (e.g. are there concerns about this making it harder to understand the JI= T codebase, adding potential bugs, or slowing down the generation of assemb= ly)=0A= - Are there any general guidelines (or talks/articles) you'd recommend for = new contributors to the Opcache JIT? I couldn't find a README and https://w= iki.php.net/rfc/jit doesn't seem to make recommendations that apply to my q= uestion.=0A= =0A= ```=0A= // core fdiv C implementation (does not throw for a divisor of 0)=0A= RETURN_DOUBLE(dividend / divisor);=0A= // core of spl_object_id C implementation=0A= RETURN_LONG((zend_long)Z_OBJ_HANDLE_P(obj));=0A= ```=0A= =0A= I started looking into this because I work on an application that heavily u= ses spl_object_id()=0A= and would see a small performance benefit from this,=0A= and was reminded of this when looking at the get_resource_id() proposal.=0A= (https://github.com/phan/phan/search?q=3Dspl_object_id&unscoped_q=3Dspl_obj= ect_id)=0A= =0A= Thanks,=0A= - Tyson=