Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116075 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 7768 invoked from network); 17 Sep 2021 13:38:18 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Sep 2021 13:38:18 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2DC6D1804C8 for ; Fri, 17 Sep 2021 07:18:17 -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=-0.7 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 17 Sep 2021 07:18:16 -0700 (PDT) Received: by mail-oo1-f51.google.com with SMTP id b5-20020a4ac285000000b0029038344c3dso3242582ooq.8 for ; Fri, 17 Sep 2021 07:18:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=W31SL8zKrEszWedoXdSWXSl+1Zhv0DNW+UewDvEjA80=; b=JCj3twnogLOctRVWivlcaEBdGn0smWPb0VzVayzXnL8PFfE7Xvn0Gh+LoZMJBPg1BZ 7ec2Zu08duGTdJz8iypN6AfPZ3BWkRoPkT6Uu/P7GNwsi3jOL+qkq0REpID2EjcX8oCl JDKES5lwu/a5bqo19xkKqbjsEWB7PNHjRA5SXc5NfGxynDuCGSQZGe/ki0RKpwa47Wrv D+c55Y3xNHY+3gF3H7RXmqL89Nm+yqWLnErL0K1G8TaWv4an5RbbL9/mYgQ7OD6vH6wR 0RdYCcksusLv9l7JUxaHC3bmTHFPPLTr/nm4jMhFI95P3F4NQ4IpHFLHUlk0BKxvwbYf 4Qcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=W31SL8zKrEszWedoXdSWXSl+1Zhv0DNW+UewDvEjA80=; b=GB48kVGWwgBzcv2azguPc59FM7rP47738+10fb4fWkCNHYZVSNljEPqakWY3jJYTRf VAk2ZNk+o1gNnD09/mwszkVtsk3HKMlw/Luz6i23pDFpJF5HrPBLo+5hEv2dwcXnO4N9 6eQ3i9A8Fk1VaRcgHhDp79k5PpaflMCU4tRShphUXKveSY8yetSfoY42uOmWZNuPLvBy FvDl5fvndoxLj1Nsa9ZzeQ0bWeTJap55ddODStYgXpfQsglblC0wwUX/mw4o/PyiTaJL LUy/qQm61MYuFKpSBeEGB20SJzGhly7qryvOalGv3mbsXoyJbs8k+FXOODtQW8c/CO2O TnVg== X-Gm-Message-State: AOAM5320Iu+cc445exrywiN9VnFRw985vwp6sSWDSuXw9+BDZeUmYFsk 9WUoDMscLVQFvyCq32/uX/CnbZ9Smr6BaIxavcI= X-Google-Smtp-Source: ABdhPJxo0ppGwKG7YmAgAQ/HsErZRZAHZ8va9QVgNmQy6dcpwhBY00l9jzXwBLOgPHQ3zMuZAXLCSj4M9yKlNuH/pkc= X-Received: by 2002:a4a:ba0f:: with SMTP id b15mr9005005oop.31.1631888293679; Fri, 17 Sep 2021 07:18:13 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 17 Sep 2021 21:18:01 +0700 Message-ID: To: tyson andre Cc: "internals@lists.php.net" Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] RFC: Add `final class Vector` to PHP From: pierre.php@gmail.com (Pierre Joye) Hi Tyson, Back on my laptop so I will answer my question myself as I read the source code. Please, really, that should be part of the RFC content. Half of the questions here are about APIs, goals, etc. RFC should be specifications as much as possible. On Fri, Sep 17, 2021 at 12:43 PM Pierre Joye wrote: > > Hello Tyson, > > Vector support would be very good. JIT can do a lot with them if we > have a clean Vector implementation, or even without JIT. Teds\Vector is named as Vector however I am afraid it is not, it is a fixed array implementation. A vector, as in all other languages are, for the definition, , fixed or variable sizes, of element of the same type, The same type is absolutely key here.The reason to require the same type is the core principle of vector (and vectorization), structure of arrays rather than array of structs. The latter are hard (or pointless) to parallelize and hard to optimize. An easy way to play with Vector would be to try out numpy's Vector, which is by far one of the best (and fastest) scripting language implementations of Vector. I did not spend enough time on the code, but I would by deconstructing: typedef struct _teds_vector_entries { size_t size; size_t capacity; zval *entries; } teds_vector_entries; to different types (or using multiple entries with a zval_type entry. ie. for a zval float Vector: typedef struct _teds_vector_entries { size_t size; size_t capacity; double float; } teds_vector_entries; Alternatively, common C port of C++ Vector do something along this line: typedef struct _cVector{ unsigned int size; unsigned int cnt_elements; unsigned int element_size; void *elements; } cVector; where the initialization is: void cVectorInit (cVector *array, unsigned int element_size); where element_size is sizeof(double) f.e. so any append, truncate, etc. are aware of the size to be (re)allocated, if needed. The only addition to handle zval would be: typedef struct _cVector{ unsigned int size; unsigned int cnt_elements; zval_enum type zval_type; unsigned int element_size; void *elements; } cVector; Doing so will drastically help to finally have a simple, by usage and implementation/api, way to implement vectorization using PHP. I would also like to suggest having it in the engine somehow, if it is not possible to have JIT jump in here if it is not an actual type in the engine. While it is possible to have intrinsics implementations in any extension, it won't be as good or efficient as an engine type with JIT support. Also, as it stands, I do not think it can be called a Vector. So I am not too keen for it as I don't think we need another SplFixed*Array implementation, as simple as it could be. The RFC needs some work anyway before any vote can be taken. In any case, if the above would be something you may consider (to implement an actual vector), I can help and would be happy too if you need/like to. Best, -- Pierre @pierrejoye | http://www.libgd.org