comp.lang.ada
 help / color / mirror / Atom feed
From: Jere <jhb.chat@gmail.com>
Subject: avoiding builtin memset
Date: Mon, 24 Apr 2017 09:06:10 -0700 (PDT)
Date: 2017-04-24T09:06:10-07:00	[thread overview]
Message-ID: <c298b2db-ecfe-4597-8eec-7b69650dcc85@googlegroups.com> (raw)

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.

             reply	other threads:[~2017-04-24 16:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-24 16:06 Jere [this message]
2017-04-24 16:56 ` avoiding builtin memset Shark8
2017-04-25  1:21   ` Anh Vo
2017-04-25  2:57     ` Luke A. Guest
2017-04-25 18:43       ` Shark8
2017-04-25 22:18         ` Luke A. Guest
2017-04-26  7:35           ` Simon Wright
2017-04-26 13:44             ` Lucretia
2017-04-26 15:22               ` Simon Wright
2017-04-27  0:22   ` Jere
2017-04-27  4:35     ` J-P. Rosen
2017-04-27  7:09       ` Simon Wright
2017-05-24 15:08 ` Frédéric PRACA
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox