B side: Working with many values

B B side · Fortran · The language that speaks maths
How do you do one thing to a long list of values?
15 Fortran words in this segment
8 Assembly words for the same job
What Fortran says well here
- One line does arithmetic on a full array: x = x + v*dt.
- Idioms such as SUM, MAXVAL and MATMUL do a full job in one word.
- When a routine has few inputs, the laboratory checks all of them in one line: count(got /= expected). The game checks 256 of 256 angles and 4096 of 4096 points. A decimal counter has 10,000 values, and the check can run all of them.
What is hard to say
- FORTRAN 77, the old dialect of DOS compilers, does not have full-array arithmetic.
One sentence in Fortran
screen = 1It says: Make every value in the array screen equal to 1.
The words, by part of speech
Verbs (1) · A statement that does something, for example PRINT, CALL or ALLOCATE.
| Word | Meaning | Example |
|---|---|---|
| WHERE | Change only the values that meet a condition. | where (x < 0.0) x = 0.0 |
Adverbs (1) · A word that changes a loop, for example CONCURRENT in DO CONCURRENT.
| Word | Meaning | Example |
|---|---|---|
| CONCURRENT | In DO CONCURRENT: the steps can happen in any order, so the compiler can do them at the same time. | do concurrent (i = 1:n) |
Idioms (11) · A built-in function or subroutine, for example SQRT or MATMUL.
| Word | Meaning | Example |
|---|---|---|
| SUM | Add all the values. | total = sum(scores) |
| PRODUCT | Multiply all the values. | p = product(x) |
| MAXVAL / MINVAL | The largest / smallest value. | best = maxval(scores) |
| MAXLOC | The position of the largest value. | i = maxloc(scores, 1) |
| COUNT | How many values meet a condition. | n = count(alive) |
| ANY / ALL | True if one value / all values meet a condition. | if (any(hit)) then |
| SIZE | How many values an array holds. | n = size(x) |
| DOT_PRODUCT | Multiply two lists value by value, then add the results. | d = dot_product(a, b) |
| MATMUL | Multiply two matrices (tables of numbers). | p2 = matmul(rot, p) |
| TRANSPOSE | Turn the rows of a table into columns. | t = transpose(m) |
| RESHAPE | Give the same values a different shape. | m = reshape(v, [2, 2]) |
Grammar marks (2) · Maths signs (+ - * / **), the = sign, and (:) for part of an array.
| Word | Meaning | Example |
|---|---|---|
| x(:) | All the values of the array x. | x(:) = 0.0 |
| x(2:5) | The values of x from position 2 to position 5. | y = x(2:5) |
Watch out: what the review found
These notes come from the review of the AI-written guides. They show traps that are easy to miss.
- D02-C1 critical FORTRAN 77 has no array syntax. Whole-array expressions and slices came in Fortran 90. 8086 to 486 CPUs have no SIMD, thus the compiler has nothing to auto-vectorize. MMX came in 1997, and x87 is scalar. The primary Fortran advantages in the document do not exist on its own target.
- D01-M4 major The claim is too strong. The standard gives the rule to the programmer, and compilers do not check it.
POINTER/TARGETarguments can alias. A violation gives silent wrong results, and that is itself a pedagogical hazard. - D01-m2 minor "Column-major storage ensures contiguous sweeps". This is true only if the loop order matches (the innermost loop runs on the first index). Beginners often get this wrong.
- D14-C2 critical The video says the opposite. At 28:34 the five unused sprites of each coin already point to transparent tile zero. The PPU "still counts those transparent sprites" toward the 32 per line, so tile zero is the problem. The fix moves a tile-zero sprite "down to an offscreen value" (28:55). At 30:08 Inkbox says that registers exist to rotate sprites in OAM, but he decides to "leave it as is for now". At 30:55 he says that the objects are "not organized by X or Y". The value "Y = 224" in image 3 is not in the video.
- D14-M9 major The limit is 32 sprites per line and also 34 slivers of 8 pixels per line (29:38 to 29:59). With 16 x 16 sprites, 24 objects plus the player give 48 slivers, so only 17 objects drew. The document omits the sliver rule, which was the real cause of the lost player sprite.