<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 8/28/15 11:31 AM, devh8h wrote:<br>
    </div>
    <blockquote cite="mid:15FD05C4-C970-476D-BD77-0035D3DFCE40@free.fr"
      type="cite">
      <meta http-equiv="Context-Type" content="text/html; charset=utf-8">
      <div>
        <div class="">I had thought to use the memset
          intrinsic, unfortunately I did not succeed to cross compiling
          compiler-rt on my Mac.</div>
      </div>
    </blockquote>
    <br>
    I don't think you need compiler-rt to use the memset intrinsic.  I
    think the code generator will generate efficient inline code for it
    (though I'm not certain).<br>
    <br>
    In any event, Joerg's suggestion of making one external weak sounds
    a lot easier.<br>
    :)<br>
    <br>
    Regards,<br>
    <br>
    John Criswell<br>
    <br>
    <blockquote cite="mid:15FD05C4-C970-476D-BD77-0035D3DFCE40@free.fr"
      type="cite">
      <div>
        <div class=""><br class="">
        </div>
        <div class="">Regards,</div>
        <div class=""><br class="">
        </div>
        <div class="">Pierre Molinaro</div>
        <div class=""><br class="">
        </div>
        <div><br class="">
        </div>
        <br class="">
        <blockquote type="cite" class="">
          <div class="">Le 28 août 2015 à 17:22, John Criswell <<a
              moz-do-not-send="true" href="mailto:jtcriswel@gmail.com"
              class=""><a class="moz-txt-link-abbreviated" href="mailto:jtcriswel@gmail.com">jtcriswel@gmail.com</a></a>> a écrit :</div>
          <br class="Apple-interchange-newline">
          <div class="">On 8/28/15 11:20 AM, devh8h wrote:<br class="">
            <blockquote type="cite" class="">It is a very basic
              "blink-led" program, on a Teensy 3.1. There is no
              operating system. The BSS clear function is called at
              boot. I would write a general BSS clear function, that
              behaves correctly even if the BSS section is empty.<br
                class="">
            </blockquote>
            <br class="">
            I thought it was something like that.<br class="">
            <br class="">
            Let me know if the memset intrinsic approach works.<br
              class="">
            <br class="">
            Regards,<br class="">
            <br class="">
            John Criswell<br class="">
            <br class="">
            <blockquote type="cite" class=""><br class="">
              Thank,<br class="">
              <br class="">
              Pierre Molinaro<br class="">
              <br class="">
              <blockquote type="cite" class="">Le 28 août 2015 à 17:00,
                John Criswell <<a moz-do-not-send="true"
                  href="mailto:jtcriswel@gmail.com" class="">jtcriswel@gmail.com</a>>
                a écrit :<br class="">
                <br class="">
                On 8/28/15 10:52 AM, devh8h via llvm-dev wrote:<br
                  class="">
                <blockquote type="cite" class="">Hi,<br class="">
                  <br class="">
                  I am writing a function that clears the BSS section on
                  an Cortex-M4 embedded system.<br class="">
                </blockquote>
                I assume that, for some reason, the operating system is
                not demand-paging in zeroed memory.  Is that correct?<br
                  class="">
                <br class="">
                <blockquote type="cite" class="">The LLVM (version
                  3.7.0rc3) code I had wrote  is :<br class="">
                  ;------------<br class="">
                  target datalayout =
                  "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"<br
                    class="">
                  target triple = "thumbv7em-none--eabi"<br class="">
                  <br class="">
                  @__bss_start = external global i32<br class="">
                  @__bss_end   = external global i32<br class="">
                  <br class="">
                  define void @clearBSS () nounwind {<br class="">
                  entry:<br class="">
                    br label %bssLoopTest<br class="">
                   bssLoopTest:<br class="">
                    %p = phi i32* [@__bss_start, %entry], [%p.next,
                  %bssLoop]<br class="">
                    %completed = icmp eq i32* %p, @__bss_end<br class="">
                    br i1 %completed, label %clearCompleted, label
                  %bssLoop<br class="">
                   bssLoop:<br class="">
                    store i32 0, i32* %p, align 4<br class="">
                    %p.next = getelementptr inbounds i32, i32* %p, i32 1<br
                    class="">
                    br label %bssLoopTest<br class="">
                   clearCompleted:<br class="">
                    ret void<br class="">
                  }<br class="">
                  ;------------<br class="">
                  <br class="">
                  This code runs. But when I optimize it with :<br
                    class="">
                  <span class="Apple-tab-span"> </span>opt
                  -disable-simplify-libcalls -Os -S source.ll -o
                  optimized.ll<br class="">
                  <br class="">
                  I get the following code for the @clearBSS function :<br
                    class="">
                  ;------------<br class="">
                  define void @clearBSS() nounwind {<br class="">
                  entry:<br class="">
                    br label %bssLoop<br class="">
                  <br class="">
                  bssLoop:                                          ;
                  preds = %entry, %bssLoop<br class="">
                    %p1 = phi i32* [ @__bss_start, %entry ], [ %p.next,
                  %bssLoop ]<br class="">
                    store i32 0, i32* %p1, align 4<br class="">
                    %p.next = getelementptr inbounds i32, i32* %p1, i32
                  1<br class="">
                    %completed = icmp eq i32* %p.next, @__bss_end<br
                    class="">
                    br i1 %completed, label %clearCompleted, label
                  %bssLoop<br class="">
                  <br class="">
                  clearCompleted:                                   ;
                  preds = %bssLoop<br class="">
                    ret void<br class="">
                  }<br class="">
                  ;------------<br class="">
                  The optimizer has transformed the while loop into a
                  repeat until.<br class="">
                  <br class="">
                  I think it assumes the two variables @__bss_start and
                  @__bss_end are distinct. But they are solved at link
                  time, and they are the same if the BSS section is
                  empty : in this case, the optimized function fails.<br
                    class="">
                  <br class="">
                  Is there a way to prevent the optimizer to assume the
                  two variables are distinct ? Or what is the proper way
                  to deal with link time values ?<br class="">
                </blockquote>
                Have you tried using the memset intrinsic?  You could
                case bss_start and bss_end to integers, subtract them to
                find the length, and then use memset to zero the memory.
                 I would think memset should work if the length is zero.<br
                  class="">
                <br class="">
                Regards,<br class="">
                <br class="">
                John Criswell<br class="">
                <br class="">
                <blockquote type="cite" class="">Thanks,<br class="">
                  <br class="">
                  Pierre Molinaro<br class="">
                  <br class="">
                  _______________________________________________<br
                    class="">
                  LLVM Developers mailing list<br class="">
                  <a moz-do-not-send="true"
                    href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br
                    class="">
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class="">
                </blockquote>
                <br class="">
                -- <br class="">
                John Criswell<br class="">
                Assistant Professor<br class="">
                Department of Computer Science, University of Rochester<br
                  class="">
                <a moz-do-not-send="true"
                  href="http://www.cs.rochester.edu/u/criswell" class="">http://www.cs.rochester.edu/u/criswell</a><br
                  class="">
                <br class="">
              </blockquote>
            </blockquote>
            <br class="">
            <br class="">
            -- <br class="">
            John Criswell<br class="">
            Assistant Professor<br class="">
            Department of Computer Science, University of Rochester<br
              class="">
            <a moz-do-not-send="true"
              href="http://www.cs.rochester.edu/u/criswell" class="">http://www.cs.rochester.edu/u/criswell</a><br
              class="">
            <br class="">
          </div>
        </blockquote>
      </div>
      <br class="">
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a class="moz-txt-link-freetext" href="http://www.cs.rochester.edu/u/criswell">http://www.cs.rochester.edu/u/criswell</a></pre>
  </body>
</html>