Bug 766 - Justify log2 addition as helper for pseudo-code
Summary: Justify log2 addition as helper for pseudo-code
Status: RESOLVED WORKSFORME
Alias: None
Product: Libre-SOC's first SoC
Classification: Unclassified
Component: Specification (show other bugs)
Version: unspecified
Hardware: Other Linux
: --- enhancement
Assignee: Luke Kenneth Casson Leighton
URL:
Depends on:
Blocks:
 
Reported: 2022-01-18 07:59 GMT by Jacob Lifshay
Modified: 2022-01-18 18:31 GMT (History)
1 user (show)

See Also:
NLnet milestone: ---
total budget (EUR) for completion of task and all subtasks: 0
budget (EUR) for this task, excluding subtasks' budget: 0
parent task for budget allocation:
child tasks for budget allocation:
The table of payments (in EUR) for this task; TOML format:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jacob Lifshay 2022-01-18 07:59:24 GMT
log2 is needed by a large group of instructions: shifts, rotates, grev, all others that address individual bits in an XLEN-sized word.

https://git.libre-soc.org/?p=openpower-isa.git;a=commitdiff;h=4386dd8bb2d41db227263a947bface79d5acaf0c

Example of expected semantics:
we need to extract a log2(XLEN)-bit wide uint from the LSB end of RB, and shift by that uint (remember RA and RB are XLEN-bit wide and MSB0 bit numbering is used):
8-bit shift: RA << RB[8-log2(8):8-1]
16-bit shift: RA << RB[16-log2(16):16-1]
32-bit shift: RA << RB[32-log2(32):32-1]
64-bit shift: RA << RB[64-log2(64):64-1]

similarly for grev, rotate, etc.


if we require log2 to only be used in pseudo-code where its results are always integers (so the inputs are powers of 2), then it should be entirely unambiguous when used. it greatly improves pseudo-code clarity over writing out a log2 definition by hand each place we want to use log2.

imho that should be sufficient justification for its inclusion.

I don't think a separate RFC is necessary, we would just include log2 in whatever RFC we're writing that uses log2, e.g. we'd just include log2 in the XLEN-ification RFC.

Because I think we should just include it in some other RFC, rather than have a whole RFC dedicated to log2, I think trying to rewrite our existing pseudo-code to remove all references to log2 is counterproductive -- we'd just include log2 in whatever RFCs include its uses in our current pseudo-code in openpower-isa.git.
Comment 1 Jacob Lifshay 2022-01-18 18:23:22 GMT
Well, log2 is already used in the OpenPower ISA v3.1 specification, in the dcbz instruction's pseudo-code (ignore messy character set, I'm too lazy to fix it rn):
if RA = 0 then b  0
else b  (RA)
EA  b + (RB)
n  block size (bytes)
m  log2(n)
ea  EA0:63-m || m0
MEM(ea, n)  n0x00
Comment 2 Luke Kenneth Casson Leighton 2022-01-18 18:31:53 GMT
(In reply to Jacob Lifshay from comment #1)
> Well, log2 is already used in the OpenPower ISA v3.1 specification, in the
> dcbz instruction's pseudo-code (ignore messy character set, I'm too lazy to

ahh, niiice, good find.

then that easily justifies using it, in fact it should be raised as
a bug with the OPF ISA WG that the function is "not defined" in Section
1.3.4 (and must be added)