(no commit message)
[libreriscv.git] / HDL_workflow.mdwn
index f7f2ef87f210a6e4c9a780bb329690136c237c2b..9d7fb9ac1ff8dc4ced9d3a597178451cb2c1743a 100644 (file)
@@ -1,7 +1,7 @@
 # HDL workflow
 
 This section describes the workflow and some best practices for developing
-the Libre-SoC hardware. We use nmigen, yosys and symbiyosys, and this
+the Libre-SOC hardware. We use nmigen, yosys and symbiyosys, and this
 page is intended not just to help you get set up, it is intended to
 help advise you of some tricks and practices that will help you become
 effective team contributors.
@@ -17,6 +17,8 @@ transparency, readability, documentation, effective team communication
 and formal mathematical proofs for all code at all levels is therefore
 paramount.
 
+Therefore, we need not only to be "self-sufficient" (absolutely under no circumstances critically reliant on somebody else's servers **or protocols**) we also need to ensure that everything (including all communication such as the mailing list archives) are recorded, replicable, and accessible in perpetuity.  Use of slack or a "forum" either actively prevents or makes that much harder.
+
 # Collaboration resources
 
 The main message here: **use the right tool for the right job**.
@@ -28,7 +30,11 @@ The main message here: **use the right tool for the right job**.
 * ftp server (<http://ftp.libre-riscv.org>): large file store.
 
 we will add an IRC channel at some point when there are enough people
-to warrant having one.
+to warrant having one (and it will be publicly archived)
+
+note also the lack of a "forum" in the above list.  this is very deliberate.  forums are a serious distraction when it comes to technical heavily goal-orientated development. recent internet users may enjoy looking up the "AOL metoo postings" meme.
+
+note also the complete lack of "social platforms". if we wanted to tell everybody how much better each of us are than anyone else in the team, how many times we made a commit (look at me, look at me, i'm so clever), and how many times we went to the bathroom, we would have installed a social media based project "management" system.
 
 ## Main contact method: mailing list
 
@@ -46,7 +52,8 @@ minimum look up and understand the following:
   using phone at airport flight soon, v. quick reply: ....")
 * Always trim context but do not cut excessively to the point where people
   cannot follow the discussion.  Especially do not cut the attribution
-  ("On monday xxx wrote")
+  ("On monday xxx wrote") of something that you are actually replying
+  to.
 * Use inline replies i.e. reply at the point in the relevant part of
   the conversation, as if you were actually having a conversation.
 * Follow standard IETF reply formatting, using ">" for cascaded
@@ -158,7 +165,7 @@ mythic-beasts and means that the project is in no way dependent on anyone
 else - not microsoft, not google, not facebook, not amazon.
 
 we tried gitlab. it didn't go well. please don't ask to replace the
-above extremely resource-efficient resources with it.
+above extremely resource-efficient services with it.
 
 # Hardware
 
@@ -236,6 +243,13 @@ including its 80 character limit.  In short: not everyone has the same
 "modern" GUI workflow or has access to the same computing resources as
 you, so please do respect that.
 
+More on this concept is
+[here](https://www.linuxjournal.com/content/line-length-limits).
+Note *very pointedly* that Linus Torvalds *specifically* states that
+he does not want Linux kernel development to become the exclusive
+domain of the "wealthy".  That means **no** to assumptions about
+access to ultra-high resolution screens.
+
 # Software prerequisites
 
 Whilst many resources online advocate "sudo" in front of all root-level
@@ -247,6 +261,8 @@ root prompt, and save yourself some typing.
 * apt-get install build-essential
 * apt-get install git python3.7 python3.7-dev python-nosetest3
 * apt-get install graphviz xdot gtkwave
+* apt-get install python3-venv
+* apt-get install python-virtualenv  # this is an alternative to python3-venv
 * return to user prompt (ctrl-d)
 
 This will get you python3 and other tools that are needed. graphviz is
@@ -296,7 +312,7 @@ nmigen may be installed as follows:
 
 * mkdir ~/src
 * cd !$
-* git clone https://github.com/m-labs/nmigen.git
+* git clone https://github.com/nmigen/nmigen.git
 * cd nmigen
 * sudo bash
 * python3 setup.py develop
@@ -307,7 +323,7 @@ testing can then be carried out with "python3 setup.py test"
 ## Softfloat and sfpy
 
 These are a test suite dependency for the ieee754fpu library, and
-will be changed in the future to use Jacob's algorithmic numeric
+will be changed in the future to use Jacob's [simple-soft-float](https://crates.io/crates/simple-soft-float)
 library.  In the meantime, sfpy can be built as follows:
 
     git clone --recursive https://github.com/billzorn/sfpy.git
@@ -321,9 +337,14 @@ library.  In the meantime, sfpy can be built as follows:
     git apply /path/to/ieee754fpu/berkeley-softfloat.patch
     cd ..
 
-    # install dependencies    
+    # prepare a virtual environment for building
     python3 -m venv .env
-    . .env/bin/activate
+
+    # or, if you prefer the old way:
+    #    virtualenv -p python3 .env
+
+    # install dependencies
+    source .env/bin/activate
     pip3 install --upgrade -r requirements.txt
 
     # build
@@ -344,6 +365,28 @@ You can test your installation by doing the following:
 
 It should print out `Posit8(1.3125)`
 
+## qemu, cross-compilers, gdb
+
+As we are doing POWER ISA, POWER ISA compilers, toolchains and
+emulators are required.
+
+Install powerpc64 gcc:
+
+    apt-get install gcc-9-powerpc64-linux-gnu
+
+Install qemu:
+
+    apt-get install qemu-system-ppc
+
+Install gdb from source.  Obtain the latest tarball, unpack it, then:
+
+    cd gdb-9.1 (or other location)
+    mkdir build
+    cd build
+     ../configure --srcdir=.. --host=x86_64-linux --target=powerpc64-linux-gnu
+    make -j16
+    make install
+
 ## Coriolis2
 
 See [[coriolis2]] page, for those people doing layout work.
@@ -424,10 +467,12 @@ install. edit, then install. It gets extremely tedious, hence why
 
 team communication:
 
+* new members, add yourself to the [[about_us]] page and create yourself a home page using someone else's page as a template.
 * communicate on the mailing list or the bugtracker an intent to take
   responsibility for a particular task.
 * assign yourself as the bug's owner
 * *keep in touch* about what you are doing, and why you are doing it.
+* edit your home page regularly, particularly to track tasks so that they can be paid by NLNet.
 * if you cannot do something that you have taken responsibility for,
   then unless it is a dire personal emergency please say so, on-list. we
   won't mind. we'll help sort it out.
@@ -446,6 +491,9 @@ for actual code development
 * plan in advance to write not just code but a full test suite for
   that code.  **this is not optional**. large python projects that do not
   have unit tests **FAIL** (see separate section below).
+* Prioritise writing formal proofs and a single clear unit test that is more like a "worked example".
+  We receive NLNet funds for writing formal proofs, plus they
+cover corner cases and take far less time to write
 
 ### Commit tested or zero-dependent code
 
@@ -507,7 +555,7 @@ for actual code development
 
 ### Do not break existing code
 
-* keep working code working **at all times**. find ways to ensure that this is the case. examples include writing alternative classes that replace existing functionality and adding runtime optiobs to select between old and new code.
+* keep working code working **at all times**. find ways to ensure that this is the case. examples include writing alternative classes that replace existing functionality and adding runtime options to select between old and new code.
 
 ### Small commits with relevant commit message
 
@@ -534,7 +582,7 @@ and follow up the next day *after* running the full relevant unit tests.
 
 ### Why such strict rules?
 
-the reason for all the above is because python is a weakly typed language.
+the reason for all the above is because python is a dynamically typed language.
 make one tiny change at the base level of the class hierarchy and the
 effect may be disastrous.
 
@@ -600,6 +648,12 @@ than it should be, the reversion process becomes extremely painful.
   causes unnecessary resource utilisation, makes code readability and
   tracking extremely difficult, and results in unintended side-effects.
 
+example: often you want to find the code from which a class was imported.  nirmally you go to the top of the file, check the imports, and you know exactly which file has the class because of the import path.  by using wildcards, you have absolutely *no clue* which wildcard imported which class or classes.
+
+example: sometimes you may accidentally have duplicate code maintained in two or more places.  editing one of them you find, puzzlingly, that the code behaves in some files with the old behaviour, but in others it works.  after a nassive amount of investigation, you find that the working files happen to have a wildcard import of the newer accidental duplicate class **after** the wildcard import of the older class with exactly the same name.  if you had used explicit imports, you would have spotted the double import of the class from two separate locations, immediately.
+
+really.  don't.  use.  wildcards.
+
 ### Keep file and variables short but clear
 
 * try to keep both filenames and variable names short but not ridiculously
@@ -608,6 +662,12 @@ than it should be, the reversion process becomes extremely painful.
   m.d.comb" followed by multiple "comb += nmigen_stmt" lines is a good trick
   that can reduce code indentation by 6 characters without reducing clarity.
 
+Additionally, use comments just above an obtuse variable in order to help explain what it is for.  In combination with keeping the the module itself short, other readers will not need to scroll back several pages in order to understand the code.
+
+Yes it is tempting to actually use the variables as self-explanatory-comments and generally this can be extremely good practice.  the problem comes when the variable is so long that a function with several parameters csn no longer fit on a single line, and takes up five to ten lines rather than one or two. at that point, the length of the code is adversely affected and thus so is readability by forcing readers to scroll through reams of pages.
+
+it is a tricky balance: basically use your common sense, or just ask someone else, "can you understand this code?"
+
 ### Reasons for code structure
 
 regarding code structure: we decided to go with small modules that are
@@ -712,6 +772,21 @@ However it is appreciated that writing formal proofs is a bit of a
 black art.  This is where team collaboration particularly kicks in,
 so if you need help, ask on the mailing list.
 
+## Don't comment out unit tests: add them first (as failures) and fix code later
+
+Unit tests serve an additional critical purpose of keeping track of code
+that needs to be written.  In many cases, you write the unit test *first*,
+despite knowing full well that the code doesn't even exist or is completely
+broken.  The unit test then serves as a constant and important reminder
+to actually fix (or write) the code.
+
+Therefore, *do not* comment out unit tests just because they "don't work".
+If you absolutely must stop a unit test from running, **do not delete it**.
+Simply mark it with an appropriate
+["skip" decorator](https://docs.python.org/3/library/unittest.html#skipping-tests-and-expected-failures),
+preferably with a link to a URL in the [bugtracker](http://bugs.libre-riscv.org)
+with further details as to why the unit test should not be run.
+
 # TODO Tutorials
 
 Find appropriate tutorials for nmigen and yosys, as well as symbiyosys.
@@ -725,3 +800,5 @@ Find appropriate tutorials for nmigen and yosys, as well as symbiyosys.
 * There exist several nmigen examples which are also executable
   <https://github.com/m-labs/nmigen/tree/master/examples/> exactly as
   described in the above tutorial (python3 filename.py -h)
+* Robert Baruch's nmigen tutorials look really good:
+  <https://github.com/RobertBaruch/nmigen-tutorial>