From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,6b8760de26d569f1,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!94.75.214.39.MISMATCH!aioe.org!.POSTED!not-for-mail From: =?ISO-8859-15?Q?Markus_Sch=F6pflin?= Newsgroups: comp.lang.ada Subject: gnat 4.4.5 generates surprising code when enabling FP checks Date: Thu, 07 Apr 2011 17:48:02 +0200 Organization: Aioe.org NNTP Server Message-ID: NNTP-Posting-Host: MdpKeRr+sx3LK7JQiK5aNw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.15) Gecko/20110303 Lightning/1.0b2 Thunderbird/3.1.9 X-Notice: Filtered by postfilter v. 0.8.2 Xref: g2news2.google.com comp.lang.ada:19676 Date: 2011-04-07T17:48:02+02:00 List-Id: The behaviour described below has been observed for gcc 4.3.5, 4.4.5, and gnatpro 6.3.2, maybe someone here has any insight on this. Given the following short code snippet: procedure FLOAT_CHECKS is F1, F2, F3 : SHORT_FLOAT; begin for I in 1..100_000 loop for J in 1..10_000 loop F1 := SHORT_FLOAT(I); -- * F2 := SHORT_FLOAT(J); -- * F3 := F1 * F2; -- * end loop; end loop; end FLOAT_CHECKS; Compiling with gnatmake -O3 -gnatDG -gnatVa float_checks.adb gives the following intermediate code for the lines marked with '*': f1 := short_float({i}); f2 := short_float({j}); [constraint_error when not boolean!($system__fat_sflt__attr_short_float. system__fat_sflt__attr_short_float__valid (f1' unrestricted_access, xF => 0)) "invalid data"] [constraint_error when not boolean!($system__fat_sflt__attr_short_float. system__fat_sflt__attr_short_float__valid (f2' unrestricted_access, xF => 0)) "invalid data"] [constraint_error when not boolean!($system__fat_sflt__attr_short_float. system__fat_sflt__attr_short_float__valid (f1 * f2' unrestricted_access, xF => 0)) "invalid data"] f3 := f1 * f2; So far so good. What really surprises me is that in the resulting assembler code the last multiplication is actually performed twice, the disassembled object code looks like this (for the last check and multiplication only): 8048ed6: d9 45 e4 flds -0x1c(%ebp) 8048ed9: d8 4d e0 fmuls -0x20(%ebp) 8048edc: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp) 8048ee3: 00 8048ee4: 89 3c 24 mov %edi,(%esp) 8048ee7: d9 5d dc fstps -0x24(%ebp) 8048eea: e8 61 fc ff ff call 8048b50 8048eef: 84 c0 test %al,%al 8048ef1: 74 2c je 8048f1f <_ada_float_checks+0xaf> 8048ef3: 83 c3 01 add $0x1,%ebx 8048ef6: d9 45 e4 flds -0x1c(%ebp) 8048ef9: 81 fb 11 27 00 00 cmp $0x2711,%ebx 8048eff: d8 4d e0 fmuls -0x20(%ebp) 8048f02: dd d8 fstp %st(0) Is the second multiplication to be expected? Does anybody know if there is an optimizer option which would eliminate the second multiplication? Regards, Markus