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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.157.41.167 with SMTP id n36mr4023682otb.106.1493049970775; Mon, 24 Apr 2017 09:06:10 -0700 (PDT) X-Received: by 10.157.37.213 with SMTP id q79mr223367ota.11.1493049970739; Mon, 24 Apr 2017 09:06:10 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!c26no1032249itd.0!news-out.google.com!v18ni3241ita.0!nntp.google.com!c26no1032247itd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 24 Apr 2017 09:06:10 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.71.201.205; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 173.71.201.205 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: avoiding builtin memset From: Jere Injection-Date: Mon, 24 Apr 2017 16:06:10 +0000 Content-Type: text/plain; charset=UTF-8 Xref: news.eternal-september.org comp.lang.ada:46619 Date: 2017-04-24T09:06:10-07:00 List-Id: GNAT GPL 2016 Windows 10 Cross compiled to arm cortex m0+ Full Optimization With a small runtime that I am modifying, I am not linking in the standard c libraries. This means whenever I do an array initialize, gcc tries to link in a non existent memset call. I started working on an Ada version of memset which I export out. The problem comes when memset tries to recursively call itself. The compiler is too smart for me. At the end of my memset I have a simple loop: while Current_Address < End_Address loop Convert_8.To_Pointer (Current_Address).all := Uint8_Value; Current_Address := Current_Address + 1; end loop; It serves two purposes: 1. It finishes up any leftover bytes on an unaligned array 2. If the data set is small enough (<= 16), the function skips immediately to this loop and just does a byte copy on the whole thing rather than try and do all the extra logic for an aligned copy However GNAT tries to convert that to another memset call, which doesn't work well, since I am in memset. My immediate workaround is to make the loop more complex: Count := Count * 2; -- To avod recursive memset call while Count > 0 loop Convert_8.To_Pointer (Current_Address).all := Uint8_Value; Current_Address := Current_Address + 1; Count := Count - 2; end loop; But I don't really like this as it adds unnecessary overhead. I looked around for gcc switches to inhibit calls to memset, but the only one I found ( -fno-builtins ) only works on C files. I really don't want to write it in C (or assembly for that matter). I think I can also do ASM statements, but I would hate to have to do ASM if there is an Ada solution. I also don't know if GCC would just optimize the ASM to a memset call anyways. Do I have any other options that would let me do it in Ada? I didn't see pragmas that jumped out at me.