Deutsch English Français Italiano |
<20240929131326.00001bdf@yahoo.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Michael S <already5chosen@yahoo.com> Newsgroups: comp.arch Subject: Re: is Vax addressing sane today Date: Sun, 29 Sep 2024 13:13:26 +0300 Organization: A noiseless patient Spider Lines: 73 Message-ID: <20240929131326.00001bdf@yahoo.com> References: <vbd6b9$g147$1@dont-email.me> <2024Sep10.094353@mips.complang.tuwien.ac.at> <vckf9d$178f2$1@dont-email.me> <O2DHO.184073$kxD8.113118@fx11.iad> <vcso7k$2s2da$1@dont-email.me> <vctke1$33me0$1@dont-email.me> <S9YIO.47284$xO0f.16227@fx48.iad> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Date: Sun, 29 Sep 2024 12:12:58 +0200 (CEST) Injection-Info: dont-email.me; posting-host="b1c937c2e7b01fb16cab4b41feb8475c"; logging-data="1802069"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+GhNyh2MfLZSd8j4j/I4oBRti+DwcRfck=" Cancel-Lock: sha1:5jyrlILMbg5TpqGRKq5QhF/gR4w= X-Newsreader: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-w64-mingw32) Bytes: 3383 On Wed, 25 Sep 2024 13:56:40 -0400 EricP <ThatWouldBeTelling@thevillage.com> wrote: > Terje Mathisen wrote: > > Kent Dickey wrote: > >> > >> Look at: > >> https://godbolt.org/z/oMhW55YsK > >> > >> Which is this code: > >> > >> int add2(int num, int other) { > >> return num + other; > >> } > >> > >> Compiled with these options: -O2 -ftrapv > >> (-ftrapv is the GCC argument for detect signed overflows and > >> crash). > >> > >> For x86-64 clang 19.1.0: > >> > >> add2: > >> add edi, esi > >> jo .LBB0_1 > >> mov eax, edi > >> ret > >> .LBB0_1: > >> ud1 eax, dword ptr [eax] > >> > >> This looks OK: it does a normal add, then branches-on-overflow to > >> an undefined instruction. > >> > >> But x86 has an instruction to trap on overflow directly: INTO. > >> It's one byte. > >> And it doesn't use it. > >> > >> GCC x86-64 14.2 is even worse: > >> > >> add2: > >> sub rsp, 8 > >> call __addvsi3 > >> add rsp, 8 > >> ret > >> > >> It calls a routine to do all additions which might overflow, and > >> that routine calls assert() if an overflow occurs. > >> > >> The CPU has a trap-on-overflow instruction exactly for this case > >> (to crash > >> on detecting an overflow), and compilers don't even use it. > >> > >> So even on architectures which have a trap-on-overflow instruction, > >> compilers don't use it. > > > > You can only compile in INTO opcodes if you can guarantee that the > > INT 4 (INTO) trap vector will always be set to a proper handler, > > and since that isn't part of the ABI, compilers can't depend on it? > > > > I do agree that it would be nice if it did work, barring that clang > > is doing the best possible alternative, at close to zero cost > > except for the useless branch predictor table entry wastage. > > > > Terje > > On x64 in 64-bit mode INTO is among 21 opcodes reassigned as invalid. > One must use JO to detect signed overflow. > Others were repurposed, 1-byte INC and DEC 40..4F became the REX > prefix. > > Single-byte form of INTO reassigned. Dual-byte form (CD 04) is here.