Heater
Posts: 10248
Joined: Tue Jul 17, 2012 3:02 pm

Re: What Does Hiding the Details of I/O in Library Calls Teach?

Thu Jul 19, 2018 2:35 pm

Excellent. Because I was just thinking about all this...

The whole stack of technology we are talking about is enormously deep and wide. From the physics of the transistors at the bottom to the application software at the top. Passing through logic gates, digital circuits, processor design, compiler construction, operating systems, editors, etc, etc. Each layer of that stack is a life times work for the people involved in it.

There is a razor sharp dividing line between the hardware and the software layers. That is the processors instruction set architecture. Typically below that line is a black hole containing all manner of things we cannot know about. Intel, ARM and co. are not about to let us know exactly.

Now, many people are comfortable writing software up at the top end. They get things done even if they don't know much of the intricacies of the layers below them.

Similarly at the bottom end many people are comfortable with stitching together circuits with transistors, or digital logic chips or micro-controllers etc.

But, there is a very dense cloud surrounding that Instruction Set Architecture dividing line. Mostly impossible to see through.

Looking down from the software end we see the compilers and interpreters that software people use. We see the operating system. Layers of extremely complicated stuff that most software engineers know very little about in detail. Such a dense cloud of complexity that we rarely see down as far as the ISA dividing line.

I suspect that most software engineers could not create a compiler that is fit for real use. Comparable to GCC say.

Looking up from the bottom we have an impenetrable black cloud of complexity that is the processor design.

I suspect that most hardware engineers could not design a processor that is fit for real use. Comparable to an Intel or ARM say.

Me, I started with transistor circuits when I was 10. Even if I did not have much of a grasp as to how they worked. Got to designing and building logic circuits, with TTL chips, in my teens. Meanwhile in a separate stream of activity I learned programming in my late teens with BASIC then Algol run on mainframes we knew nothing about.

This all came together in my twenties with the arrival of the first 8 bit microcontroller chips.

But still, the inner workings of those processors was a mystery to me for decades. As was the magic by which a compiler turned text into code.

Which brings me back to Per Vognsen and his ongoing Bitwise project. Per is showing that those impenetrably complex layers of the stack between source code and logic gates need not be so huge and need not be so complicated. He already has a compiler for his own C like language that is small and simple enough that one could sit and read it all, and understand it. I suspect when his RISC V code generation is done it will be as good as GCC with optimizations turned off. He's about to get down to designing that RISC V processor core. Which again need not be huge and complex.

Bitwise is an interesting project to follow as it shows off a lot of cool tricks for software creation and hardware design which can be useful even if you don't want to build your own computer from scratch.

Bitwise: https://www.youtube.com/watch?v=ZjwvMcP ... wMSDM3aTtX

User avatar
The Traveler
Posts: 361
Joined: Sat Oct 21, 2017 3:48 pm

Re: What Does Hiding the Details of I/O in Library Calls Teach?

Thu Jul 19, 2018 3:08 pm

Our mission is to put the power of computing and digital making into the hands of people all over the world.
Have you ever read Stephen Hawking's #1 New York TImes Bestseller, "A Brief History of Time"?

It's sort of like that.
Retired IT professional, C programmer and "beardie weirdie".
RPi interests: Developing an Infinite Improbability Drive
“Thinking outside of the box allows you to get rewards outside of your reach.” Matshona Dhliwayo

ejolson
Posts: 2159
Joined: Tue Mar 18, 2014 11:47 am

Re: What Does Hiding the Details of I/O in Library Calls Teach?

Thu Jul 19, 2018 6:28 pm

Heater wrote:
Thu Jul 19, 2018 2:35 pm
I suspect that most software engineers could not create a compiler that is fit for real use. Comparable to GCC say.
The current state of the GNU C compiler as well as the Intel C compiler, C language LLVM and the IBM X LC compiler are the results of huge teams. No single software engineer could create such complexity on their own, though many might submit patches. At the same time I believe many should be able to create a compiler at the level of Stallman's original gcc, Davis's Holy C or even Kernighan and Ritchie's C compiler.

As Google and others have demonstrated with Meltdown, Spectre, row-hammer and other side-channel vulnerabilities, software engineers need to know deep-level hardware to write secure code. For different reasons, practitioners of high-performance computing also need a reasonably accurate view of the underlying hardware.

Compared to cloud-driven web-based programming environments with lessons that careful meet the requirements of a particular curriculum, the fact that children can afford full ownership of a Raspberry Pi leads to an open-ended learning environment suitable for creating games, mouse applications, parallel programs, networks, operating systems and hardware interfaces among others. This flexibility doesn't hold anyone back and is how the Pi makes computing fun again.

Note that suitable learning materials are essential for effective interest-directed ability-adapted learning to happen. To this end, it would be nice to have a short tutorial on how to create a custom GPIO routines in C using low-level constructs.

hippy
Posts: 4020
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: What Does Hiding the Details of I/O in Library Calls Teach?

Thu Jul 19, 2018 7:15 pm

Heater wrote:
Thu Jul 19, 2018 2:35 pm
Bitwise is an interesting project to follow as it shows off a lot of cool tricks for software creation and hardware design which can be useful even if you don't want to build your own computer from scratch.

Bitwise: https://www.youtube.com/watch?v=ZjwvMcP ... wMSDM3aTtX
Do you have a link to some home page or written text rather than an hour long video ?

Googling "bitwise", even with "risc-v", didn't turn up anything for me.

Heater
Posts: 10248
Joined: Tue Jul 17, 2012 3:02 pm

Re: What Does Hiding the Details of I/O in Library Calls Teach?

Thu Jul 19, 2018 7:48 pm

hippy,

All the Bitwise source code and documentation (such as it is) is in github:
https://github.com/pervognsen/bitwise/

There is also a Bitwise forum:
https://bitwise.handmade.network/forums

In github you will find links to twitter and whever other media Per Vognsen is using.

Never mind the hour long intro video. Per has been churning out a Bitwise video every other day or so since March. A lot of it being live coding sessions. Then there is the Bitwise "extras" channel on youtube with even longer live coding sessions.

Since March Per has created:

A RISC V simulator.
A RISC V assembler.
A compiler for a C like language he calls Ion.
A Forth implementation. Written in Ion.

This last week or so he started on the RISC V processor implementation for FPGA. But of course he has to show how to create your own Hardware Description Language in Python before starting on the actual RISC V design.

His Ion language idea is interesting. Basically it is, intentionally, very similar to C. Except he has cleaned up the syntax and semantics a little bit with the objectives:

1) To make creating a compiler much simpler. That results in a small (source code wise) simpler compiler that people can actually understand.

2) To make that compiler very fast. The Ion compiler can compile a million lines of code in a handful of seconds whereas GCC takes half an hour for similar input.

3) To make things a bit simpler for the programmer. For example the Ion declaration syntax can do everything the C declaration syntax does, but it's a lot easier to write and read. For example, no more header files and make files etc, Ion has a nice simple package system.

So far the Ion compiler compiles the Ion language into C. Actual RISC V code generation will come when he has done the RISC V implementation. But a year ago or so he did a similar compiler that generated x86 code directly. Blinding fast. So I have high hopes for Ion.

Anyway, as I said, even if you don't want to write your own compiler or build your own CPU Per has a ton of useful tricks up his sleeve that can be used in creating all kind of software. In C or in Python.

hippy
Posts: 4020
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: What Does Hiding the Details of I/O in Library Calls Teach?

Thu Jul 19, 2018 8:30 pm

Heater wrote:
Thu Jul 19, 2018 7:48 pm
All the Bitwise source code and documentation (such as it is) is in github:
https://github.com/pervognsen/bitwise/

There is also a Bitwise forum:
https://bitwise.handmade.network/forums
Thanks. It all seems a bit like "here it is" rather than "what it's about". Feels a bit like the ivory tower attitudes in computing of old; you either know and are in or you can stay outside. In that respect it's a sort of inverse of what Z80 Refugee has a problem with.

Heater
Posts: 10248
Joined: Tue Jul 17, 2012 3:02 pm

Re: What Does Hiding the Details of I/O in Library Calls Teach?

Thu Jul 19, 2018 9:38 pm

hippy,
Feels a bit like the ivory tower attitudes in computing of old; you either know and are in or you can stay outside.
Wow, that is totally the opposite view of what Per Vognsen is doing in his Bitwise project than the one I take away from it.

He is really practical in his approach. He is not into big theoretical discussions about grammars and parsers and compiler design in an academic way. No, he says this is how we are going to do it, rolls his sleeves up and starts coding, in real time, live streamed.

His intention is to do everything in a simple way that any regular programmer can follow. And, being a being a regular programmer myself, with no formal CS education, I think he is doing a very good job at that.

He has a thing about "power to weight ratio" when programming. That is to say, what is the smallest simplest thing you can do to get the most of what you want done, without having to be a genius to understand it.

Totally the opposite to the approach of the famous textbooks on such things.

Admittedly he does assume that Bitwise followers are familiar with C and Python programming. I think that is fair enough.

And admittedly he does not write so much documentation. If you want to see what is going on you need to watch the vids.

Per is not an ivory tower kind of guy. By all accounts he started learning C at age 12 by hacking on same game or whatever he had source code to. Just like a young Pi user might today.

I suspect one would learn more about programming by spending 40 hours watching his videos than the same 40 hours spent in lectures at a university CS course.

The Bitwise project is exactly tackling the problem Z80 Refugee has described.

ejolson
Posts: 2159
Joined: Tue Mar 18, 2014 11:47 am

Re: What Does Hiding the Details of I/O in Library Calls Teach?

Thu Jul 19, 2018 10:07 pm

Heater wrote:
Thu Jul 19, 2018 7:48 pm
The Ion compiler can compile a million lines of code in a handful of seconds whereas GCC takes half an hour for similar input.
The Bitwise project sounds nice. It is a little unfair, however, to compare the speed of a compiler which emits C code to a tool chain which creates linked optimized executables. For a fairer comparison, note that Raspbian already comes with a really fast C compiler that emits C code for its output. It is called cat.

Videos are different than a written explanation. The depth, level of detail and clarity demonstrated by typical documentation for common 8-bit home computers of the past is surprisingly absent for today's personal computers and even the Raspberry Pi. It seems difficult to remedy this situation, because the hardware changes every year and the software even more frequently.

hippy
Posts: 4020
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: What Does Hiding the Details of I/O in Library Calls Teach?

Fri Jul 20, 2018 12:27 am

Heater wrote:
Thu Jul 19, 2018 9:38 pm
He is not into big theoretical discussions about grammars and parsers and compiler design in an academic way. No, he says this is how we are going to do it, rolls his sleeves up and starts coding, in real time, live streamed.
I guess that's the problem I have. In fairness it's probably mostly that I don't like his approach. It feels like walking in on a lecture about something I have no idea about, watching an episode of something mid-series and not having a clue. The introduction, the big picture is missing. It's not inviting me in. Which I guess is somewhat on topic, but we may be going off at a tangent.

Heater
Posts: 10248
Joined: Tue Jul 17, 2012 3:02 pm

Re: What Does Hiding the Details of I/O in Library Calls Teach?

Fri Jul 20, 2018 8:59 am

ejolson,
It is a little unfair, however, to compare the speed of a compiler which emits C code to a tool chain which creates linked optimized executables. For a fairer comparison, note that Raspbian already comes with a really fast C compiler that emits C code for its output. It is called cat.
Ah!

You seriously underestimate what is in the Ion compiler at this time:

1) It does lexical analysis and tokenization of Ion source text, just like a real compiler.

2) It does syntax parsing into an abstract syntax tree structure, just like a real compiler.

3) It does symbol resolution, type checking, type conversion etc, just like a real compiler.

4) It builds the final program out of multiple input modules, just like a real compiler.

4) It generates C code you can run. That's just like a real compiler as well. Emscripten uses LLVM to compile Javascript into C for example. Even GCC produces assembler source output.

Heck, it is a real compiler!

As to your points:

a) Code generation: Yes of course we would like to compare GCC/Clang to Ion producing real executable code. Per will be adding a generator for RISC V binaries when he is good and ready. He did an x64 generating compiler a couple of years ago that compiled blindingly fast. https://www.youtube.com/watch?v=N9B2KeA ... 7&index=12

Is suspect that the Ion RISC V generator will be similarly hundreds of times faster than GCC or Clang.

b) Optimization: I suspect that Per's finished compiler will generate code that is as efficient as GCC with optimization off (-O0). That is pretty good in my book. i would not be surprised if he does better.

c) Linked executables: Well, has it ever occurred to anyone that separately compiling source files into binary object modules and then linking those modules into an executable is not required and a complete waste of time and effort?

In the modern world where even the smallest machines have a gig of RAM why not just compile all the sources together in one go? Boom, lightning fast, job done.

That is what Ion does with it's package system. No more wasting time and effort with all those include files and other junk.

I think this is a very good choice for a compiler designed as a pedagogical tool whilst at the same time being fit for real uses, not just a toy compiler as students often build in CS classes.

Still, Ion won't beat the speed of cat :)



I do take you point about videos and the good old documentation of yore. However, in this case there are already many books on compiler construction. For example the famous "Dragon" book: Compilers: Principles, Techniques, and Tools: https://www.amazon.com/Compilers-Princi ... 0321486811. I have stuck my head in such books over the years. Mostly I did not make any sense out of them.

In fact Per recomends we read Niklaus Wirth's books on the Oberon language and system https://www.inf.ethz.ch/personal/wirth/ ... Report.pdf. A lot of what Per does in his videos is inspired by Wirth.

There is something about watching a master of his craft creating something in front of you in real time whilst he talks about the problems and the possible solutions. A lot of little insights and glimpses into the thought processes to be gained there that you will never get from a book that just dumps out a ready made solution.

It's not for everyone but I find it fascinating.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 20917
Joined: Sat Jul 30, 2011 7:41 pm

Re: What Does Hiding the Details of I/O in Library Calls Teach?

Fri Jul 20, 2018 9:37 am

Can it be fascinating in another thread? It's off topic for this one.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

Heater
Posts: 10248
Joined: Tue Jul 17, 2012 3:02 pm

Re: What Does Hiding the Details of I/O in Library Calls Teach?

Fri Jul 20, 2018 2:56 pm

Oh James, we were having such fun.

And just getting to the interesting part...

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 20917
Joined: Sat Jul 30, 2011 7:41 pm

Re: What Does Hiding the Details of I/O in Library Calls Teach?

Fri Jul 20, 2018 3:07 pm

Heater wrote:
Fri Jul 20, 2018 2:56 pm
Oh James, we were having such fun.

And just getting to the interesting part...
Feel free to start another thread in Off Topic. It is interesting enough for me not to delete it!
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

Heater
Posts: 10248
Joined: Tue Jul 17, 2012 3:02 pm

Re: What Does Hiding the Details of I/O in Library Calls Teach?

Fri Jul 20, 2018 4:36 pm

Actually James, I was wondering how it was you decided this is off topic for this thread.

This is Z80 Refugee's thread and he opened it with thoughts of "lifting the lid" on the libraries and such that application programmers use. Getting down to the hardware registers and such.

When I asked "How far down this rabbit hole should we go?" he replied "As far as you like. That's the point of opening a debate"

Well, the Bitwise project is exactly about that "lifting the lid" thing. It's an educational project. Seems to fit right in here.

Anyway, at your request I'm done with that. Should I get round to doing something Pi related and interesting with Bitwise perhaps I'll resurface it some place else.

Return to “General programming discussion”