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


Groups > sci.electronics.design > #473729 > unrolled thread

Microchip ICD4 ?

Started byMartin Riddle <martin_rid@verizon.net>
First post2017-08-17 13:45 -0400
Last post2017-08-18 12:10 +0100
Articles 20 on this page of 91 — 25 participants

Back to article view | Back to sci.electronics.design


Contents

  Microchip ICD4 ? Martin Riddle <martin_rid@verizon.net> - 2017-08-17 13:45 -0400
    Re: Microchip ICD4 ? DemonicTubes <tlackie@gmail.com> - 2017-08-17 12:17 -0700
      Re: Microchip ICD4 ? Martin Riddle <martin_rid@verizon.net> - 2017-08-17 15:32 -0400
      Re: Microchip ICD4 ? speff <spehro@gmail.com> - 2017-08-17 19:02 -0700
    Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-17 15:52 -0400
      Re: Microchip ICD4 ? piglet <erichpwagner@hotmail.com> - 2017-08-17 21:23 +0100
        Re: Microchip ICD4 ? boB <boB@k7iq.com> - 2017-08-17 13:42 -0700
        Re: Microchip ICD4 ? Lasse Langwadt Christensen <langwadt@fonz.dk> - 2017-08-17 14:23 -0700
          Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-17 17:46 -0400
        Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-17 17:44 -0400
          Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-17 18:40 -0400
            Re: Microchip ICD4 ? DemonicTubes <tlackie@gmail.com> - 2017-08-17 16:19 -0700
              Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-17 22:04 -0400
            Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-17 20:03 -0400
              Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-17 23:17 -0400
                Re: Microchip ICD4 ? "Michael A. Terrell" <mike.terrell@earthlink.net> - 2017-08-18 07:36 -0400
              Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-17 22:50 -0700
                Re: Microchip ICD4 ? Martin Brown <'''newspam'''@nezumi.demon.co.uk> - 2017-08-18 14:43 +0100
                Re: Microchip ICD4 ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-08-18 13:42 +0000
                  Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-18 12:49 -0400
                    Re: Microchip ICD4 ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-08-18 17:11 +0000
                      Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-18 16:22 -0400
                      Re: Microchip ICD4 ? Martin Brown <'''newspam'''@nezumi.demon.co.uk> - 2017-08-19 08:44 +0100
                  Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-18 23:19 -0700
                  Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-28 00:22 -0700
                    Re: Microchip ICD4 ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-09-02 16:35 +0000
                Re: Microchip ICD4 ? Cecil Bayona <cbayona@cbayona.com> - 2017-08-18 10:58 -0500
                  Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-18 09:34 -0700
              Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-18 13:22 +0200
                Re: Microchip ICD4 ? stephen@mpeforth.com (Stephen Pelc) - 2017-08-18 11:54 +0000
                  Re: Microchip ICD4 ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-08-18 14:40 +0000
                  Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-18 09:29 -0700
                    Re: Microchip ICD4 ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-08-18 17:06 +0000
                      Re: Microchip ICD4 ? Tom Gardner <spamjunk@blueyonder.co.uk> - 2017-08-18 19:59 +0100
                        Re: Microchip ICD4 ? dplatt@coop.radagast.org (Dave Platt) - 2017-08-18 12:49 -0700
                          Re: Microchip ICD4 ? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-08-19 01:52 +0200
                            Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-18 20:40 -0400
                              Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-18 20:43 -0400
                              Re: Microchip ICD4 ? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-08-19 13:03 +0200
                                Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-19 10:30 -0400
                                  Re: Microchip ICD4 ? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-08-19 21:03 +0200
                          Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-18 23:28 -0700
                          Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-21 16:49 +0200
                        Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-21 16:43 +0200
                      Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-18 23:26 -0700
                Re: Microchip ICD4 ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-08-18 14:11 +0000
                  Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-18 16:49 +0200
            Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-18 02:40 +0000
              Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-17 22:55 -0400
                Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-18 09:14 +0000
                  Re: Microchip ICD4 ? jack4747@gmail.com - 2017-08-18 03:10 -0700
                    Re: Microchip ICD4 ? Clive Arthur <cliveta@nowaytoday.co.uk> - 2017-08-18 11:38 +0100
                      Re: Microchip ICD4 ? Martin Brown <'''newspam'''@nezumi.demon.co.uk> - 2017-08-18 12:13 +0100
                      Re: Microchip ICD4 ? jack4747@gmail.com - 2017-08-18 04:25 -0700
                        Re: Microchip ICD4 ? Clive Arthur <cliveta@nowaytoday.co.uk> - 2017-08-18 13:43 +0100
                        Re: Microchip ICD4 ? Johann Klammer <klammerj@NOSPAM.a1.net> - 2017-08-18 23:40 +0200
                      Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-18 16:57 +0200
                        Re: Microchip ICD4 ? Przemek Klosowski <przemek@tux.dot.org> - 2017-08-22 03:24 +0000
                      Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-18 12:32 -0400
                  Re: Microchip ICD4 ? Neon John <no@never.com> - 2017-08-18 10:02 -0400
                    Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-18 11:02 -0400
                    Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-20 07:46 +0000
                      Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-21 16:57 +0200
                  Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-18 16:54 +0200
              Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-17 23:01 -0400
                Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-18 07:58 +0000
                  Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-18 01:19 -0700
                    Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-18 20:51 +0000
                      Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-18 23:35 -0700
                        Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-20 07:42 +0000
                          Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-20 19:49 -0700
                  Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-18 05:18 -0400
                    Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-20 07:22 +0000
                      Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-22 00:08 -0400
                        Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-21 22:41 -0700
                          Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-22 07:28 +0000
                            Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-23 16:52 -0400
              Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-17 22:54 -0700
              Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-18 16:36 +0200
                Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-20 08:49 +0000
                  Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-21 17:03 +0200
                Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-26 02:33 +0000
                  Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-26 01:55 -0400
                  Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-27 13:40 -0700
                    Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-09-02 12:58 -0400
                  Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-28 16:25 +0200
            Re: Microchip ICD4 ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-08-18 13:28 +0000
      Re: Microchip ICD4 ? speff <spehro@gmail.com> - 2017-08-17 19:09 -0700
      Re: Microchip ICD4 ? TTman <pcw1.cad@ntlworld.com> - 2017-08-18 10:12 +0100
        Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-18 05:21 -0400
          Re: Microchip ICD4 ? TTman <pcw1.cad@ntlworld.com> - 2017-08-18 12:10 +0100

Page 2 of 5 — ← Prev page 1 [2] 3 4 5  Next page →


#473894

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2017-08-18 17:11 +0000
Message-ID<2017Aug18.191138@mips.complang.tuwien.ac.at>
In reply to#473886
bitrex <bitrex@de.lete.earthlink.net> writes:
>On 08/18/2017 09:42 AM, Anton Ertl wrote:
>> Paul Rubin <no.email@nospam.invalid> writes:
>>> C++ will likely beat handwritten assembler for any sizeable program,
>>> because of the insane effort it would take to write and the maintain the
>>> asm code with the crazy contorted optimizations that the compiler puts
>>> in.
[...]
>> As an example, I know of a microprocessor simulator that was written
>> in C++, and it was, in a sense, well-written C++, using lots of
>> abstractions.  The resulting simulator worked, at 300 simulated cycles
>> per (wall-clock) second.  That was much too slow to be useful, so they
>> threw it away, wrote a simulator designed for efficiency (that ignored
>> all the great software engineering features in C++), and the result
>> simulated at 3M simulated cycles per second, which was good enough.
>
>That was silly, just profile the code to see where the bottlenecks are 
>and rewrite those parts. No point in rewriting code for efficiency that 
>the CPU is only spending 1% of its time executing (usually 90% of the 
>codebase)

Yeah, right.  Too bad you were not consulted when they made the
decision, you would have saved the company a lot of time and money.
Although, thinking about it, if, say, a 30M-cycle run takes 100,000s
on the first simulator, and 1,000s of that is spent in 90% of the
code, and you manage to speed up the other 10% by a factor of 99, the
result will still take 2,000s for the run, while the new simulator
takes 10s.

Anyway, with the "crazy contorted optimizations that the compiler puts
in", such that "C++ will likely beat handwritten assembler for any
sizeable program", the C++ compiler should have optimized the original
simulator to be as fast as the final simulator all by itself.  It
didn't, so the"crazy contorted optimizations" may be crazy and
contorted, but are not up to the task of competing with source-level
optimizations.

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2017: http://euro.theforth.net/

[toc] | [prev] | [next] | [standalone]


#473943

Frombitrex <bitrex@de.lete.earthlink.net>
Date2017-08-18 16:22 -0400
Message-ID<o0IlB.9587$TH2.1363@fx02.iad>
In reply to#473894
On 08/18/2017 01:11 PM, Anton Ertl wrote:

> Anyway, with the "crazy contorted optimizations that the compiler puts
> in", such that "C++ will likely beat handwritten assembler for any
> sizeable program", the C++ compiler should have optimized the original
> simulator to be as fast as the final simulator all by itself.  It
> didn't, so the"crazy contorted optimizations" may be crazy and
> contorted, but are not up to the task of competing with source-level
> optimizations.
> 
> - anton
> 

Those were someone else's words, not mine! ;-)

It's always possible to write inefficient algorithms in any compiled 
language that will compile to well-optimized (for the algorithm) but 
inefficient (for the application) code.

For the comparison to make any sense you have to make the assumption 
that the engineer is not doing bonehead things like say making thousands 
of superfluous copies of a large object per second when a simple move 
would suffice. Unfortunately in general that's easier to do in a 
language with OOP-features like C++ than straight asm. That particular 
problem has become less of an issue in the later versions of the 
standard with move constructors and copy elision/RVO.

[toc] | [prev] | [next] | [standalone]


#474024

FromMartin Brown <'''newspam'''@nezumi.demon.co.uk>
Date2017-08-19 08:44 +0100
Message-ID<on8q8a$ut6$1@gioia.aioe.org>
In reply to#473894
On 18/08/2017 18:11, Anton Ertl wrote:
> bitrex <bitrex@de.lete.earthlink.net> writes:
>> On 08/18/2017 09:42 AM, Anton Ertl wrote:
>>> Paul Rubin <no.email@nospam.invalid> writes:
>>>> C++ will likely beat handwritten assembler for any sizeable program,
>>>> because of the insane effort it would take to write and the maintain the
>>>> asm code with the crazy contorted optimizations that the compiler puts
>>>> in.
> [...]
>>> As an example, I know of a microprocessor simulator that was written
>>> in C++, and it was, in a sense, well-written C++, using lots of
>>> abstractions.  The resulting simulator worked, at 300 simulated cycles
>>> per (wall-clock) second.  That was much too slow to be useful, so they
>>> threw it away, wrote a simulator designed for efficiency (that ignored
>>> all the great software engineering features in C++), and the result
>>> simulated at 3M simulated cycles per second, which was good enough.
>>
>> That was silly, just profile the code to see where the bottlenecks are
>> and rewrite those parts. No point in rewriting code for efficiency that
>> the CPU is only spending 1% of its time executing (usually 90% of the
>> codebase)
> 
> Yeah, right.  Too bad you were not consulted when they made the
> decision, you would have saved the company a lot of time and money.

But he is right that profiling the code is an essential step to figuring 
out what is actually wrong with it. Most code spends a disproportionate 
amount of time in a few very heavily executed sections.

Assuming here that there wasn't a silly error involving copying a large 
structure somewhere. You can easily get an order of magnitude slow down 
by doing stupid things in a HLL.

> Although, thinking about it, if, say, a 30M-cycle run takes 100,000s
> on the first simulator, and 1,000s of that is spent in 90% of the
> code, and you manage to speed up the other 10% by a factor of 99, the
> result will still take 2,000s for the run, while the new simulator
> takes 10s.

It is quite likely that there was something unfortunate about the 
algorithm implementation in the HLL that made the speed difference quite 
so bad. That or learning from the initial approach the assembler version 
used an entirely different way of simulating decoding the instructions.

For most of the scientific code I do the compiler can sometimes do 
unexpected things that make it go faster and hand optimisation of the 
resulting code using well known heuristics may slow it down.

> Anyway, with the "crazy contorted optimizations that the compiler puts
> in", such that "C++ will likely beat handwritten assembler for any
> sizeable program", the C++ compiler should have optimized the original
> simulator to be as fast as the final simulator all by itself.  It
> didn't, so the"crazy contorted optimizations" may be crazy and
> contorted, but are not up to the task of competing with source-level
> optimizations.

I think it is more likely that the representation of the CPU being 
simulated was sub optimal in the first attempt (a common problem). They 
learned from the initial coding what not to do and didn't make the same 
mistakes when coding it in assembler.

-- 
Regards,
Martin Brown

[toc] | [prev] | [next] | [standalone]


#474016

FromPaul Rubin <no.email@nospam.invalid>
Date2017-08-18 23:19 -0700
Message-ID<87efs8nkpi.fsf@nightsong.com>
In reply to#473843
anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
> As an example, I know of a microprocessor simulator that was written
> in C++, and it was, in a sense, well-written C++, using lots of
> abstractions.  The resulting simulator worked, at 300 simulated cycles
> per (wall-clock) second.

One of the driving ideas of C++ is to provide useful abstractions at
essentially zero cost.  Evidently it wasn't used that way in that first
implementation.  Was it written in C++1x (i.e. C++11 or later)?  C++11
made it much easier to do certain important things efficently, by
introducing move constructors.  

> they threw it away, wrote a simulator designed for efficiency ...and
> the result simulated at 3M simulated cycles per second

It could be that the first implementation was intended as a prototype.
I probably would have done it in Python or Haskell, so it would have
been even slower, but allowed easier instrumentation and exploration.

Anyway, you can write bad code in any language.

[toc] | [prev] | [next] | [standalone]


#475088

FromPaul Rubin <no.email@nospam.invalid>
Date2017-08-28 00:22 -0700
Message-ID<87pobgqhq6.fsf@nightsong.com>
In reply to#473843
anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
> The source-level optimizations are from a book that was 33 years old
> at the time, and yet the optimizing compilers performed only one of
> these optimizations (inlining).

Is the code from the book available, or anyway your transliterations?
Thanks.

[toc] | [prev] | [next] | [standalone]


#475988

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2017-09-02 16:35 +0000
Message-ID<2017Sep2.183552@mips.complang.tuwien.ac.at>
In reply to#475088
Paul Rubin <no.email@nospam.invalid> writes:
>anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
>> The source-level optimizations are from a book that was 33 years old
>> at the time, and yet the optimizing compilers performed only one of
>> these optimizations (inlining).
>
>Is the code from the book available, or anyway your transliterations?

http://www.complang.tuwien.ac.at/anton/lvas/effizienz/tsp.html

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2017: http://euro.theforth.net/

[toc] | [prev] | [next] | [standalone]


#473873

FromCecil Bayona <cbayona@cbayona.com>
Date2017-08-18 10:58 -0500
Message-ID<on72k4$kl4$1@dont-email.me>
In reply to#473806
On 8/18/2017 12:50 AM, Paul Rubin wrote:
> rickman <gnuarm@gmail.com> writes:
>> What *is* C++1x and why do you think it would be faster than other
>> compiled languages?
> 
> C++1x = C++11, C++14, and C++17, three consecutive versions of the C++
> standard.  C++11 had large additions/changes over earlier versions, that
> enabled various significant optimizations.  C++14 and C++17 add
> comparatively smaller tweaks to C++11.
> 
> C++ will likely beat handwritten assembler for any sizeable program,
> because of the insane effort it would take to write and the maintain the
> asm code with the crazy contorted optimizations that the compiler puts
> in.  But, for a small tight loop where the human is willing to put in
> enough effort per instruction, the human can still beat the compiler.
> 
> See: https://cr.yp.to/talks/2015.04.16/slides-djb-20150416-a4.pdf
> 
On that link what an annoying writing style, same paragraph over an over 
making minor changes to the paragraph sometimes repeating minor 
variations of a paragraph ten times.

-- 
Cecil - k5nwa

[toc] | [prev] | [next] | [standalone]


#473882

FromPaul Rubin <no.email@nospam.invalid>
Date2017-08-18 09:34 -0700
Message-ID<87inhkomvi.fsf@nightsong.com>
In reply to#473873
Cecil Bayona <cbayona@cbayona.com> writes:
> On that link what an annoying writing style, same paragraph over an
> over making minor changes to the paragraph sometimes repeating minor
> variations of a paragraph ten times.

They are lecture slides.  The idea is the audience sees the paragraph
morphing on the screen while the speaker gives the talk.

[toc] | [prev] | [next] | [standalone]


#473831

FromDavid Brown <david.brown@hesbynett.no>
Date2017-08-18 13:22 +0200
Message-ID<on6ie0$jd$1@dont-email.me>
In reply to#473777
On 18/08/17 02:03, rickman wrote:
> bitrex wrote on 8/17/2017 6:40 PM:

>> My contention is that well-written modern C++1x will destroy any
>> handwritten
>> asm or compiled-Forth "macro assembler" program on both execution
>> speed and
>> code size for any nontrivial general computing task in all but the most
>> extreme edge-cases, even on say AVR 8 bit devices.
>>
>> There should be a contest! ;-)
> 
> What *is* C++1x and why do you think it would be faster than other
> compiled languages?
> 

C++1x is a generic term for C++11 onwards (C++14, the up-coming C++17,
and the future C++20).  C++ had a significant change with the 2011
standard, including "auto" type deduction, compile-time code evaluation,
lambdas, strongly typed enums, multithreading, etc.

Used well, this can let you get more code safety and code efficiency
than was possible before (with C++03, or C).  I don't know that it will
give you a lot more code efficiency, but I can imagine it helping somewhat.

I like to be a little careful about claims of greater efficiency than
assembly - after all, it is trivial to see that anything a compiler can
generate could also be written directly in assembly.  I prefer to say
that compilers can, in most circumstances, generate more efficient code
than assembly programmers when the code is to be maintainable, flexible,
understandable, somewhat portable (say, amongst different ARM chips or
different x86 chips - devices that share the same basic assembly, to
make the comparison fair), and developed in a sensible amount of time.

As a simple example, lets consider a scaling routine:


static const int divFactor = 2815;
static const int multFactor = 31214;

int scale(int x) {
    return (x * multFactor) / divFactor;
}

How should that be implemented on an ARM?

The obvious assembly for a Cortex-M4 would be:

scale:
        movw    r3, #31214
        muls    r0, r3, r0
        movw    r3, #2815
        sdiv    r0, r0, r3
        bx      lr


But is that the fastest method?  No, division is a slow instruction.  A
faster M4 version would be:

scale:
        movw    r3, #31214
        ldr     r2, .L2
        mul     r0, r3, r0
        smull   r3, r2, r2, r0
        add     r2, r2, r0
        asrs    r0, r0, #31
        rsb     r0, r0, r2, asr #11
        bx      lr
.L2:
        .word   -1170245085

The division has been turned into a collection of adds and shifts.

If you vary the constants even just a little, the assembly code here can
vary significantly.  Sometimes common factors can simplify the code.
The numbers, types and orders of the adds and shifts will vary.
Sometimes they are best replaced by another multiplication.  Sometimes
the original multiplication is best replaced by shifts and adds.  On
different ARM devices, details of the timings and the instructions
supported can mean that different choices are optimal.

And when this function is actually used in code, inlining, constant
propagation and other optimisations can mean that the ideal code could
be completely different - including being calculated at compile time.

So yes, an assembly programmer could write code for this function, using
either of these formulations.  But he/she has a choice between writing a
clear, flexible and maintainable version - or a faster version.  Only a
compiler can give you both.

(I cannot tell you if a Forth compiler can generate object code like
this - I know they can do /some/ optimisations, but I have no idea of
the details.)

[toc] | [prev] | [next] | [standalone]


#473836

Fromstephen@mpeforth.com (Stephen Pelc)
Date2017-08-18 11:54 +0000
Message-ID<5996d249.111613302@news.eternal-september.org>
In reply to#473831
On Fri, 18 Aug 2017 13:22:38 +0200, David Brown
<david.brown@hesbynett.no> wrote:

>(I cannot tell you if a Forth compiler can generate object code like
>this - I know they can do /some/ optimisations, but I have no idea of
>the details.)

In our VFX Forth compiler, there's only one algorithm that's not in
the compiler literature. Code generation is all about a myriad
of details. Where gcc (in particular) wins is in the huge amount
of time and money spent on the ARM and x86 versions (in particular).
There are algorithms for languages with static call trees, e.g. C, 
that do not apply for languages with dynamic call trees, e.g. Forth.

Stephen


-- 
Stephen Pelc, stephenXXX@mpeforth.com
MicroProcessor Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 (0)23 8063 1441
web: http://www.mpeforth.com - free VFX Forth downloads

[toc] | [prev] | [next] | [standalone]


#473852

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2017-08-18 14:40 +0000
Message-ID<2017Aug18.164009@mips.complang.tuwien.ac.at>
In reply to#473836
stephen@mpeforth.com (Stephen Pelc) writes:
>On Fri, 18 Aug 2017 13:22:38 +0200, David Brown
><david.brown@hesbynett.no> wrote:
>
>>(I cannot tell you if a Forth compiler can generate object code like
>>this - I know they can do /some/ optimisations, but I have no idea of
>>the details.)
>
>In our VFX Forth compiler, there's only one algorithm that's not in
>the compiler literature.

The other direction would be more interesting for the question he
asked.

>There are algorithms for languages with static call trees, e.g. C, 
>that do not apply for languages with dynamic call trees, e.g. Forth.

The call trees of C look every bit as dynamic or static as those of
Forth.  The major differences are that you may have to compile a part
of the code before seeing all of it, and that you cannot spend much
time on compilation (because it's part of the run-time).

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2017: http://euro.theforth.net/

[toc] | [prev] | [next] | [standalone]


#473880

FromPaul Rubin <no.email@nospam.invalid>
Date2017-08-18 09:29 -0700
Message-ID<87mv6won5c.fsf@nightsong.com>
In reply to#473836
stephen@mpeforth.com (Stephen Pelc) writes:
> Where gcc (in particular) wins is in the huge amount
> of time and money spent on the ARM and x86 versions

The type system also helps with alias analysis, getting rid of unneeded
loads and stores.  I don't see how a Forth compiler can do that.  

[toc] | [prev] | [next] | [standalone]


#473890

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2017-08-18 17:06 +0000
Message-ID<2017Aug18.190621@mips.complang.tuwien.ac.at>
In reply to#473880
Paul Rubin <no.email@nospam.invalid> writes:
>stephen@mpeforth.com (Stephen Pelc) writes:
>> Where gcc (in particular) wins is in the huge amount
>> of time and money spent on the ARM and x86 versions
>
>The type system also helps with alias analysis,

It doesn't.  What you mean is: By (often wrongly) assuming that C
programs don't access data through pointers of other types,
adversarial C compilers save themselves the trouble of trying to do
proper alias analysis.  But of course, the result is often wrong,
because the assumption is often wrong.

>getting rid of unneeded
>loads and stores.  I don't see how a Forth compiler can do that.

The Forth *programmer* gets rid of unneeded loads and stores by not
writing them.

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2017: http://euro.theforth.net/

[toc] | [prev] | [next] | [standalone]


#473928

FromTom Gardner <spamjunk@blueyonder.co.uk>
Date2017-08-18 19:59 +0100
Message-ID<mOGlB.665617$lQ6.78056@fx29.am4>
In reply to#473890
On 18/08/17 18:06, Anton Ertl wrote:
> Paul Rubin <no.email@nospam.invalid> writes:
>> stephen@mpeforth.com (Stephen Pelc) writes:
>>> Where gcc (in particular) wins is in the huge amount
>>> of time and money spent on the ARM and x86 versions
>>
>> The type system also helps with alias analysis,
>
> It doesn't.  What you mean is: By (often wrongly) assuming that C
> programs don't access data through pointers of other types,
> adversarial C compilers save themselves the trouble of trying to do
> proper alias analysis.  But of course, the result is often wrong,
> because the assumption is often wrong.

Too true :( Plus the programmer often lies.

What /is/ the consequence of one compilation unit
"casting away the constness" of something defined
in another compilation unit?

[toc] | [prev] | [next] | [standalone]


#473938

Fromdplatt@coop.radagast.org (Dave Platt)
Date2017-08-18 12:49 -0700
Message-ID<susj6e-4cl.ln1@coop.radagast.org>
In reply to#473928
In article <mOGlB.665617$lQ6.78056@fx29.am4>,
Tom Gardner  <spamjunk@blueyonder.co.uk> wrote:

>Too true :( Plus the programmer often lies.
>
>What /is/ the consequence of one compilation unit
>"casting away the constness" of something defined
>in another compilation unit?

"Undefined behavior" which is highly application-specific.  Anything
from no ill effect, to incorrect output (either immediately or at some
later time), to terrible data corruption, to a quick crash/segfault.

In extreme cases, things like "destruction of hardware" and "loss of
life" can occur.

I once took advantage of a compiler bug in a Univac FORTRAN system, to
demonostrate to my doubting FORTRAN instructor that the computer
believed that two plus two equals six.  I incremented the value of a
parameter which was passed into a FORTRAN function (and FORTRAN of the
era always passed all parameters by reference, not by value).  Since
I'd passed a constant "2", and since the compiler hadn't bothered
either to memory-protect the constant or provide an emphermeral
copy... foom.

The "all constants are variable" rule took hold.  :-)


[toc] | [prev] | [next] | [standalone]


#473972

Fromalbert@cherry.spenarnc.xs4all.nl (Albert van der Horst)
Date2017-08-19 01:52 +0200
Message-ID<on7ukk$jaf$1@cherry.spenarnc.xs4all.nl>
In reply to#473938
In article <susj6e-4cl.ln1@coop.radagast.org>,
Dave Platt <dplatt@coop.radagast.org> wrote:
>In article <mOGlB.665617$lQ6.78056@fx29.am4>,
>Tom Gardner  <spamjunk@blueyonder.co.uk> wrote:
>
>>Too true :( Plus the programmer often lies.
>>
>>What /is/ the consequence of one compilation unit
>>"casting away the constness" of something defined
>>in another compilation unit?
>
>"Undefined behavior" which is highly application-specific.  Anything
>from no ill effect, to incorrect output (either immediately or at some
>later time), to terrible data corruption, to a quick crash/segfault.
>
>In extreme cases, things like "destruction of hardware" and "loss of
>life" can occur.
>
>I once took advantage of a compiler bug in a Univac FORTRAN system, to
>demonostrate to my doubting FORTRAN instructor that the computer
>believed that two plus two equals six.  I incremented the value of a
>parameter which was passed into a FORTRAN function (and FORTRAN of the
>era always passed all parameters by reference, not by value).  Since
>I'd passed a constant "2", and since the compiler hadn't bothered
>either to memory-protect the constant or provide an emphermeral
>copy... foom.
>
>The "all constants are variable" rule took hold.  :-)

I once had a subroutine that was passed a boolean (LOGICAL as they call
it) , that I set to FALSE after inspection.
When I inadvertantly called this with a TRUE literal,
TRUE was turned into FALSE for all of FORTRAN and hell broke loose.

At the time it was considered a bug in the program not in the compiler.

Anyway the specification of C++ and its standard library is such
that no single expert is master of it all. Regularly
conflicts are detected between remote parts of it.
Bottomline, not a language for mission critical stuff or cancer
radiation equipment.

There are more important things than a little speed.

Groetjes Albert
>
>
>
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

[toc] | [prev] | [next] | [standalone]


#473982

Frombitrex <bitrex@de.lete.earthlink.net>
Date2017-08-18 20:40 -0400
Message-ID<0OLlB.7274$i03.4086@fx24.iad>
In reply to#473972
On 08/18/2017 07:52 PM, Albert van der Horst wrote:

> I once had a subroutine that was passed a boolean (LOGICAL as they call
> it) , that I set to FALSE after inspection.
> When I inadvertantly called this with a TRUE literal,
> TRUE was turned into FALSE for all of FORTRAN and hell broke loose.
> 
> At the time it was considered a bug in the program not in the compiler.
> 
> Anyway the specification of C++ and its standard library is such
> that no single expert is master of it all. Regularly
> conflicts are detected between remote parts of it.
> Bottomline, not a language for mission critical stuff or cancer
> radiation equipment.
> 
> There are more important things than a little speed.
> 
> Groetjes Albert

It's used in that stuff all the time, though. The list of 
undefined/implementation-defined behavior is not infinite.

And in 2k17 if one is consistently running into issues with undefined 
behavior it probably means You're Doing It Wrong, i.e. you're not really 
writing C++, you're trying to write "C with Classes." There's all kinds 
of stuff in C++1x to support backward compatibility that one should 
never actually use in new code.

i.e. memset is obsolete. memcpy is obsolete. all those "mem" functions 
are obsolete. Doing any kind of direct byte-for-byte copy of structures 
is pretty much obsolete.

C-style unions are pretty much obsolete, you use a std::variant type. 
C-style arrays are obsolete, I never use them. If you need a plain ol' 
const array you use a std::array. If you need a list of stuff you can 
modify you use a std::vector. Raw pointers are pretty much obsolete 
except for when you need to make a user-defined conversion to pass 
something to a C API call that can only accept pointers. "Naked" "new" 
and "delete" are obsolete unless you're writing a custom allocator.

"For" loops that increment counters are obsolete...etc.



[toc] | [prev] | [next] | [standalone]


#473983

Frombitrex <bitrex@de.lete.earthlink.net>
Date2017-08-18 20:43 -0400
Message-ID<WQLlB.13498$AK2.12530@fx34.iad>
In reply to#473982
On 08/18/2017 08:40 PM, bitrex wrote:
> On 08/18/2017 07:52 PM, Albert van der Horst wrote:
> 
>> I once had a subroutine that was passed a boolean (LOGICAL as they call
>> it) , that I set to FALSE after inspection.
>> When I inadvertantly called this with a TRUE literal,
>> TRUE was turned into FALSE for all of FORTRAN and hell broke loose.
>>
>> At the time it was considered a bug in the program not in the compiler.
>>
>> Anyway the specification of C++ and its standard library is such
>> that no single expert is master of it all. Regularly
>> conflicts are detected between remote parts of it.
>> Bottomline, not a language for mission critical stuff or cancer
>> radiation equipment.
>>
>> There are more important things than a little speed.
>>
>> Groetjes Albert
> 
> It's used in that stuff all the time, though. The list of 
> undefined/implementation-defined behavior is not infinite.
> 
> And in 2k17 if one is consistently running into issues with undefined 
> behavior it probably means You're Doing It Wrong, i.e. you're not really 
> writing C++, you're trying to write "C with Classes." There's all kinds 
> of stuff in C++1x to support backward compatibility that one should 
> never actually use in new code.
> 
> i.e. memset is obsolete. memcpy is obsolete. all those "mem" functions 
> are obsolete. Doing any kind of direct byte-for-byte copy of structures 
> is pretty much obsolete.
> 
> C-style unions are pretty much obsolete, you use a std::variant type. 
> C-style arrays are obsolete, I never use them. If you need a plain ol' 
> const array you use a std::array. If you need a list of stuff you can 
> modify you use a std::vector. Raw pointers are pretty much obsolete 
> except for when you need to make a user-defined conversion to pass 
> something to a C API call that can only accept pointers. "Naked" "new" 
> and "delete" are obsolete unless you're writing a custom allocator.
> 
> "For" loops that increment counters are obsolete...etc.

Part of the problem is that I think some coders think you still have to 
write C++ nowadays "sorta like C" to get C-like performance. Which is Wrong

[toc] | [prev] | [next] | [standalone]


#474033

Fromalbert@cherry.spenarnc.xs4all.nl (Albert van der Horst)
Date2017-08-19 13:03 +0200
Message-ID<on95to$o0u$1@cherry.spenarnc.xs4all.nl>
In reply to#473982
In article <0OLlB.7274$i03.4086@fx24.iad>,
bitrex  <bitrex@de.lete.earthlink.net> wrote:
>On 08/18/2017 07:52 PM, Albert van der Horst wrote:
>
>> I once had a subroutine that was passed a boolean (LOGICAL as they call
>> it) , that I set to FALSE after inspection.
>> When I inadvertantly called this with a TRUE literal,
>> TRUE was turned into FALSE for all of FORTRAN and hell broke loose.
>>
>> At the time it was considered a bug in the program not in the compiler.
>>
>> Anyway the specification of C++ and its standard library is such
>> that no single expert is master of it all. Regularly
>> conflicts are detected between remote parts of it.
>> Bottomline, not a language for mission critical stuff or cancer
>> radiation equipment.
>>
>> There are more important things than a little speed.
>>
>> Groetjes Albert
>
>It's used in that stuff all the time, though. The list of
>undefined/implementation-defined behavior is not infinite.
>
>And in 2k17 if one is consistently running into issues with undefined
>behavior it probably means You're Doing It Wrong, i.e. you're not really
>writing C++, you're trying to write "C with Classes."

Or you combine things that have never been combined before.

>There's all kinds
>of stuff in C++1x to support backward compatibility that one should
>never actually use in new code.
>
>i.e. memset is obsolete. memcpy is obsolete. all those "mem" functions
>are obsolete. Doing any kind of direct byte-for-byte copy of structures
>is pretty much obsolete.
>
>C-style unions are pretty much obsolete, you use a std::variant type.
>C-style arrays are obsolete, I never use them. If you need a plain ol'
>const array you use a std::array. If you need a list of stuff you can
>modify you use a std::vector. Raw pointers are pretty much obsolete
>except for when you need to make a user-defined conversion to pass
>something to a C API call that can only accept pointers. "Naked" "new"
>and "delete" are obsolete unless you're writing a custom allocator.
>
If you're planning on using a safe subset of c++ you should use
Ada in the first place. Please comment on the kind of C++ code
you find on mbed.

>"For" loops that increment counters are obsolete...etc.

And COBOL is obsolete... Do you think that declaring things obsolete
means that large bodies of software are converted in a eye blink.

Some say that in view of lisp C/C++ was obsolete the day it was invented.
That doesn't buy you much.

I've made some solid C++ code, but I shudder what remains of it
after a few years of "maintenance" by a novice.
See ssort.html on my site below as of 1993.

Groetjes Albert
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

[toc] | [prev] | [next] | [standalone]


#474048

Frombitrex <bitrex@de.lete.earthlink.net>
Date2017-08-19 10:30 -0400
Message-ID<XXXlB.4787$Pn2.200@fx37.iad>
In reply to#474033
On 08/19/2017 07:03 AM, Albert van der Horst wrote:

> I've made some solid C++ code, but I shudder what remains of it
> after a few years of "maintenance" by a novice.
> See ssort.html on my site below as of 1993.
> 
> Groetjes Albert

It looks very 1994. ;-) Large classes, lots of methods which look like 
straight-C internally.

Nowadays if you wanted to use a custom sorting algorithm on a custom 
buffer you'd probably subclass or composite one of the STL containers 
that implemented most of the "concepts" you wanted like say 
"SequenceContainer", BackInsertable", etc.; if you wanted custom memory 
allocator behavior you'd write a class conforming to the "Allocator" 
template (you can hot-plug any allocator policy into just about any 
conformant Container), and your algorithm would follow the "Algorithm" 
template. Then apply the algorithm to the objects in the container.

[toc] | [prev] | [next] | [standalone]


Page 2 of 5 — ← Prev page 1 [2] 3 4 5  Next page →

Back to top | Article view | sci.electronics.design


csiph-web