From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 160F12242383F for ; Thu, 1 Mar 2018 02:33:35 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A52CB4084FEF; Thu, 1 Mar 2018 10:39:42 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-4.rdu2.redhat.com [10.10.120.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id B73DB10AF9F0; Thu, 1 Mar 2018 10:39:41 +0000 (UTC) To: =?UTF-8?Q?Marvin_H=c3=a4user?= , "edk2-devel@lists.01.org" Cc: "michael.d.kinney@intel.com" , "liming.gao@intel.com" References: <62c9363b-7f27-cfff-492a-560660727b86@redhat.com> <366ffc0c-b55f-a3c1-973e-b80d3dd07d26@redhat.com> <2b22bfbd-24ce-e26c-9f1c-e5ba2816b48f@redhat.com> From: Laszlo Ersek Message-ID: <2d9e3ddc-9832-417f-8d40-65af1e24edc3@redhat.com> Date: Thu, 1 Mar 2018 11:39:35 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 01 Mar 2018 10:39:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 01 Mar 2018 10:39:42 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: Re: [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise operations. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Mar 2018 10:33:35 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit On 02/28/18 22:07, Marvin Häuser wrote: > One comment is inline. > > Thank you in advance, > Marvin. > >> -----Original Message----- >> From: edk2-devel On Behalf Of Marvin >> Häuser >> Sent: Wednesday, February 28, 2018 7:46 PM >> To: edk2-devel@lists.01.org; Laszlo Ersek >> Cc: michael.d.kinney@intel.com; liming.gao@intel.com >> Subject: Re: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise >> operations. >> >> I have just locally updated all BIT defines to use the ULL prefix and added >> casts to defines using them. >> I did that to ensure that 1) inversions always produce the correct value and 2) >> assignments never result in implicit casts to a smaller int, which would raise a >> warning. >> >> After I was done doing it for MdePkg, a build showed that (N)ASM files >> consumed these definitions. >> >> I only see a bunch of possible solutions to that: >> * Prohibit the usage of such defines in assembly code (which I would strongly >> dislike). >> * Introduce a "DEFINE_BIT" macro which produces one definition for C code >> and one for assembly. > > I only just realized that including C headers was not a NASM feature, but it is actually edk2 invoking the PP. > Might the best solution just be to introduce a casting macro, which casts when it's invoked for a C compiler and doesn't when it's invoked for an assembler? > Basically would require nothing else than adding a "-D__EDK2_ASSEMBLER__" or something alike to the PP flags when applicable. > > Any opinion on that? Sigh, I don't know what to answer. On one hand (if we can get it to work without regressions) I like the idea of making all BITx macros ULL. On the other hand, defining the same macro with different replacement text, dependent on whether the including source code is assembly or C, looks dirty. I can't really put my finger on it, but I feel such dual definitions could cause issues or confusion. If BaseTools people are OK with the dual definition, I guess I could live with it. Thanks, Laszlo > >> * Rely on 'ULL' always producing the biggest possible value (including the 128- >> bit range new to the spec) or documenting an exception for it, and insist on >> the caller casting (which I would find quite ugly). >> * Scrap the patch and continue to rely on compiler-/architecture-specific >> behavior, which could cause issues seemingly randomly. >> >> Thanks, >> Marvin. >> >>> -----Original Message----- >>> From: edk2-devel On Behalf Of Marvin >>> Häuser >>> Sent: Wednesday, February 28, 2018 3:21 PM >>> To: edk2-devel@lists.01.org; Laszlo Ersek >>> Cc: michael.d.kinney@intel.com; liming.gao@intel.com >>> Subject: Re: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise >>> operations. >>> >>> Hey Laszlo, >>> >>> I cut your rant because it is not strictly related to this patch. >>> However, thank you for composing it nevertheless because it was an >> interesting read! >>> Comments are inline. >>> >>> Michael, Liming, >>> Do you have any comments regarding the discussion? Thanks in advance. >>> >>> Best regards, >>> Marvin. >>> >>>> -----Original Message----- >>>> From: Laszlo Ersek >>>> Sent: Wednesday, February 28, 2018 2:57 PM >>>> To: Marvin Häuser ; edk2- >>>> devel@lists.01.org >>>> Cc: michael.d.kinney@intel.com; liming.gao@intel.com >>>> Subject: Re: [edk2] [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise >>>> operations. >>>> >>>> On 02/28/18 12:43, Marvin Häuser wrote: >>> [...] >>>>> as edk2 does not support vendor extensions such as __int128 anyway. >>>> >>>> Not *yet*, I guess :) UEFI 2.7 does list UINT128 / INT128, in table >>>> 5, "Common UEFI Data Types". I believe those typedefs may have been >>> added for RISC-V. >>> >>> Oh yikes, I have not noticed that before. Besides that I wonder how >>> that will be implemented by edk2 for non-RISC-V platforms, maybe that >>> should be considered? >>> As ridiculous as it sounds, maybe some kind of UINT_MAX type (now >>> UINT64, later UINT128) should be introduced and any BIT or bitmask >>> definition being explicitly casted to that? >>> Are BIT definitions or masks occasionally used in preprocessor operations? >>> That might break after all. >>> Anyway, if that idea would be approved, there really would have to be >>> a note regarding this design in some of the EDK2 specifications, >>> probably C Code Style. >>> >>> [...] >>>> >>>>> -1) The 'truncating constant value' warning would probably need to >>>>> be disabled globally, however I don't understand how an explicit >>>>> cast is a problem anyway. >>>>> >>>>> Did I overlook anything contra regarding that? >>>> >>>> Hmmm... Do you think it could have a performance impact on 32-bit >>>> platforms? (I don't think so, at least not in optimized / RELEASE >>>> builds.) >>> >>> I don't think any proper optimizer would not optimize this. After all, >>> it can not only evaluate the value directly and notice that the value >>> does not reach into the 'long long range', but also consider the type of the >> other operand. >>> >>> [...] >>> >>> _______________________________________________ >>> edk2-devel mailing list >>> edk2-devel@lists.01.org >>> https://lists.01.org/mailman/listinfo/edk2-devel >> _______________________________________________ >> edk2-devel mailing list >> edk2-devel@lists.01.org >> https://lists.01.org/mailman/listinfo/edk2-devel