From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb35.google.com (mail-yb1-xb35.google.com [IPv6:2607:f8b0:4864:20::b35]) by sourceware.org (Postfix) with ESMTPS id 9EFAE3858D39 for ; Sun, 26 Dec 2021 10:12:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9EFAE3858D39 Received: by mail-yb1-xb35.google.com with SMTP id e136so38561777ybc.4 for ; Sun, 26 Dec 2021 02:12:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=Iyw1hKsbCJG7Kx68ljYbekB7/N29/KYvmmFTo38r/So=; b=XQ/LImT0ikm3O19m2lwXEHqQLkQxymZxOu6p3wR4p22QjBVD6F91tAiEYzH0+SdBZm aDsarFl8bKBJsSxEqCODtgpBl94ZDaNyTwwC9IK/qbB9BGqrgrGj/sjaaV30+OtmkQni WmW0JHNjDE6wc6Xw/OfjJYLavZ/ZKrHR3uDAFqxPKoT5Y101jE+oMlVcS99EMM1Xm3Xs HRXAXfjcHRy+Y3wZGhByqxDVWuQLuwAFPSMuG8XT4kojaLVSt6NfqSXvvDw4y/XnKIUL TY4bDoDEbkZzo2ZBOP4lZ8NZo5fdMrGVw1SaWaZlbCQeu3+6HASXyM9bj14XMG0Cubbl J/aw== X-Gm-Message-State: AOAM531D858zxpuANC4ud7ldGiAF/bNw2B5HRecXjEWS61wP4drz3/2W TirSYfXBQJpRY5DJXkzZvclSlEgPpe60xrBabVWvIkEvrgc= X-Google-Smtp-Source: ABdhPJwO7/TjI5fcuNS2+u5k/58g6GrzzteavZH6Q1eytkmjvwCGrrfOKeeWxAab3VrqJbJ9Z3n3GkKyYXveAyw+6kM= X-Received: by 2002:a25:ab4c:: with SMTP id u70mr5340366ybi.211.1640513568769; Sun, 26 Dec 2021 02:12:48 -0800 (PST) MIME-Version: 1.0 From: =?UTF-8?Q?Marc_Nieper=2DWi=C3=9Fkirchen?= Date: Sun, 26 Dec 2021 11:12:37 +0100 Message-ID: Subject: Pointer difference To: =?UTF-8?Q?Marc_Nieper=2DWi=C3=9Fkirchen_via_Jit?= Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: jit@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Jit mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Dec 2021 10:12:50 -0000 Using gcc_jit_context_new_binary_op together with GCC_JIT_BINARY_OP_MINUS, one can generate code to calculate the difference of two pointer rvalues P and Q. According to my experiments, however, the difference is not taken in the C sense where the difference is the number of units between the two pointers, which depends on the types of P and Q. Instead, libgccjit seems to calculate the equivalent of GCC's (void *) P - (void *) Q. It's probably worth noting this in the documentation. Thanks, Marc PS Coincidentally, libgccjit doesn't support the addition of an integral type to a pointer type using GCC_JIT_BINARY_OP_PLUS; for that one has to go through gcc_jit_context_new_array_access and then gcc_jit_lvalue_get_address.