Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > sci.electronics.design > #480559

Re: Ping Tom Gardner et. al.

Subject Re: Ping Tom Gardner et. al.
Newsgroups sci.electronics.design
References <kqABB.142601$po2.80988@fx36.iad> <or7bpu$efd$1@dont-email.me> <or7hpn$mdb$1@dont-email.me>
From bitrex <bitrex@de.lete.earthlink.net>
Message-ID <duIBB.11$m83.3@fx03.iad> (permalink)
Organization frugalusenet - www.frugalusenet.com
Date 2017-10-06 05:59 -0400

Show all headers | View raw


On 10/06/2017 05:18 AM, David Brown wrote:
> On 06/10/17 09:36, David Brown wrote:
>> On 06/10/17 02:49, bitrex wrote:
>>> In case you aren't checking the other big thread I started, one more fun
>>> use of modern C++ on embedded processors I thought might be of interest
>>> is doing lookup table generation at compile time. Here's some code that
>>> generates a table for some weird function:
>>>
>>> <https://pastebin.com/5jB4RRz4>
>>>
>>> (source:
>>> <http://cplusadd.blogspot.com/2013/02/c11-compile-time-lookup-tablearray-with.html>)
>>>
>>
>> C++14 allows a lot more freedom in constexpr functions.  In particular,
>> it lets you write loops.  That means you can do the same sort of thing
>> with much simpler and clearer code, and with much greater compile-time
>> efficiency.  These recursive template solutions avoid run-time costs,
>> but scale very badly when you want larger tables.  You then find
>> yourself using binary recursion instead of linear recursion, and while
>> everything works correctly (it's easy to check), your code review folks
>> are sticking hot pokers in their eyes to avoid looking at it.
>>
>> So C++11 allows some fancy tricks like, but they should not be used
>> until C++14 and generalised constexpr functions.  (I can't remember
>> off-hand if gcc 5.3 supports that - I /think/ it does.)
>>
>> For lower than C++14, write your table generators in Python - simple,
>> clear, and you can output a table in C or C++ formats.
>>
>>>
>>> Here's the asm output with gcc 5.3.0 with flags -std=c++11 -Os for the
>>> MSP430:
>>>
>>> <https://pastebin.com/NYkjV9Ra>
>>>
>>> Look ma, no code! The compiler just puts a lookup table in the data
>>> section.
>>>
>>> The output for x86 is even more compact using 64 bit magic numbers and
>>> offsets. No math.h functions called anywhere:
>>>
>>> <https://pastebin.com/4vg0Y49S>
>>
> 
> When you are trying to look at the code generated for things like this,
> avoid std::cout like the plague - it clutters everything up.

The problem is at high optimization levels unless you actually _do_ 
something with the table in "main" that has some kind of side-effect the 
compiler just expunges it as well. The most efficient code is nothing!

IDK if there's some way to modify the sources you or I pasted using say 
"volatile" to avoid that and still have it apply heavy optimization

Back to sci.electronics.design | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Ping Tom Gardner et. al. bitrex <bitrex@de.lete.earthlink.net> - 2017-10-05 20:49 -0400
  Re: Ping Tom Gardner et. al. David Brown <david.brown@hesbynett.no> - 2017-10-06 09:36 +0200
    Re: Ping Tom Gardner et. al. David Brown <david.brown@hesbynett.no> - 2017-10-06 11:18 +0200
      Re: Ping Tom Gardner et. al. bitrex <bitrex@de.lete.earthlink.net> - 2017-10-06 05:59 -0400
        Re: Ping Tom Gardner et. al. bitrex <bitrex@de.lete.earthlink.net> - 2017-10-06 06:05 -0400
          Re: Ping Tom Gardner et. al. David Brown <david.brown@hesbynett.no> - 2017-10-06 12:20 +0200
    Re: Ping Tom Gardner et. al. Tom Gardner <spamjunk@blueyonder.co.uk> - 2017-10-06 11:47 +0100
      Re: Ping Tom Gardner et. al. David Brown <david.brown@hesbynett.no> - 2017-10-06 14:24 +0200
        Re: Ping Tom Gardner et. al. Tom Gardner <spamjunk@blueyonder.co.uk> - 2017-10-06 13:55 +0100
          Re: Ping Tom Gardner et. al. bitrex <bitrex@de.lete.earthlink.net> - 2017-10-06 09:12 -0400
            Re: Ping Tom Gardner et. al. David Brown <david.brown@hesbynett.no> - 2017-10-06 16:37 +0200
            Re: Ping Tom Gardner et. al. Tom Gardner <spamjunk@blueyonder.co.uk> - 2017-10-06 15:50 +0100
              Re: Ping Tom Gardner et. al. bitrex <bitrex@de.lete.earthlink.net> - 2017-10-06 14:02 -0400
          Re: Ping Tom Gardner et. al. David Brown <david.brown@hesbynett.no> - 2017-10-06 16:32 +0200
            Re: Ping Tom Gardner et. al. Tom Gardner <spamjunk@blueyonder.co.uk> - 2017-10-06 17:44 +0100
              Re: Ping Tom Gardner et. al. David Brown <david.brown@hesbynett.no> - 2017-10-16 11:18 +0200
          Re: Ping Tom Gardner et. al. Jasen Betts <jasen@xnet.co.nz> - 2017-10-09 07:58 +0000
            Re: Ping Tom Gardner et. al. David Brown <david.brown@hesbynett.no> - 2017-10-16 11:23 +0200

csiph-web