RFC 401
Conversion of NGP-0 Coordinates to Device Specific Coordinates
Conversion of NGP-0 Coordinates to Device Specific Coordinates β¨
okay bestie, this one is from Jim Hansen at the Center for Advanced Computation, University of Illinois π It's NIC #11923, dated October 23, 1972, and it's Category D.6. It Updates RFC #387 and Obsoletes None π§ It's part of the Network Working Group crew, so get ready to level up π
Okay so RFC #387 already talked about turning NGP-0 coordinates into floating point PDP-10 coordinates π But ngl, floating point is usually a bad look here, because real devices need integer addressing π So this RFC shows how to turn NGP coordinates into integer coordinates from zero to M, where M is the maximum address of the device screen on a machine using 2's complement arithmetic β¨ It wouldn't be hard to tweak this for machines using one's complement or sign-magnitude arithmetic either π«Ά
First, the NGP coordinate format π¦
Here's the vibe:
+--+-----------+
| | n |
+--+-----------+
s ^ FRACTION
i
g
n
The sign lives in the most significant bit, and the rest is numerical info. The initial NGP implementation uses N=15 π₯ Negative numbers are stored in 2's complement π
The big conversion formula π
To get to device coordinates, you do this:
D = S * f + S
Where D =>integer device coordinate
S =>scaling factor (typically M/2)
f =>NGP fractional coordinate
Let's rewrite it as:
n n
D = S*(2 *f)/2 +S
Now we split up S into two terms:
I
S= Q * 2
where Q is an odd integer and I is an integer π
Plug that in and you get:
When: I n n
D = Q * 2 *(2 *f)/2 +S
I-n n
= Q * 2 *(2 *f) +S
n
The (2 *f) factor is in 2's complement because you just extend the sign bit of f into the upper part of the computer word π§ If Q = 1 (which is what a lot of devices use), you can skip it. If Q >< 1, the consolation prize is that an integer multiply is usually faster than a floating point multiply on most machines π On a PDP-10, this multiply can often happen with no memory access, since Q is usually small π
Now we're left with the 2^(I-n) factor:
I-n
This can be done with an arithmetic shift left by (I-n), or an arithmetic shift right by (n-I), whichever fits π Then S gets added with an integer add. Iconic. β¨
The step-by-step procedure π
So the full procedure for turning NGP coordinates into integer device coordinates goes:
- move coordinate to a register and extend sign
- integer multiply by Q (if necessary)
- arithmetic shift left by (I-n)
- integer add S
This procedure is generally way faster than the float route π
Here's that float route, for comparison:
- move coordinate to register and extend sign
- float fractional coordinate
- floating point multiply
- floating point add
- conversion to fixed point
Literally the integer way is the main character here ππ«Ά
[ This RFC was put into machine readable form for entry ]
[ into the online RFC archives by BBN Corp. under the ]
[ direction of Alex McKenzie. 1/97 ]
π¦ where this page comes from
- ietf: rfc401 1972-10
- π girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms