1 # RFC ls013 Min/Max GPR/FPR
5 * <https://libre-soc.org/openpower/sv/rfc/ls013/>
6 * <https://git.openpower.foundation/isa/PowerISA/issues/TODO>
7 * <https://bugs.libre-soc.org/show_bug.cgi?id=1057>
19 **Books and Section affected**:
22 Book I Fixed-Point Instructions
23 Appendix E Power ISA sorted by opcode
24 Appendix F Power ISA sorted by version
25 Appendix G Power ISA sorted by Compliancy Subset
26 Appendix H Power ISA sorted by mnemonic
35 **Submitter**: Luke Leighton (Libre-SOC)
37 **Requester**: Libre-SOC
39 **Impact on processor**:
42 Addition of new GPR-based instructions
45 **Impact on software**:
48 Requires support for new instructions in assembler, debuggers,
55 GPR, FPR, min, max, fmin, fmax
62 **Notes and Observations**:
64 1. minimum/maximum instructions are needed for vector reductions, where the
65 SVP64 tree reduction needs a single instruction to work properly.
66 2. if you implement any of the FP min/max modes, the rest are not much more
68 3. TODO(lkcl): fill out: that using VSX may have different meaning (SVP64/VSX)
69 so it is *really* crucial to have SVP64/SFFS ops.
70 4. FP min/max are rather complex to implement in software, the most commonly
71 used FP max function `fmax` from glibc compiled for SFFS is 32 (!)
74 https://gcc.godbolt.org/z/6xba61To6
115 .byte 0,9,0,0,0,0,0,0
120 Add the following entries to:
122 * the Appendices of Book I
123 * Book I 3.3.9 Fixed-Point Arithmetic Instructions
124 * Book I 4.6.6.1 Floating-Point Elementary Arithmetic Instructions
125 * Book I 1.6.1 and 1.6.2
131 ## `FMM` -- Floating Min/Max Mode
133 <a id="fmm-floating-min-max-mode"></a>
135 | `FMM` | Assembly Alias | Origin | Semantics |
136 |-------|-------------------------------|--------------------------------|-------------------------------------------------|
137 | 0000 | fminnum08[s] FRT, FRA, FRB | IEEE 754-2008 | FRT = minNum(FRA, FRB) (1) |
138 | 0001 | fmin19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = minimum(FRA, FRB) |
139 | 0010 | fminnum19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = minimumNumber(FRA, FRB) |
140 | 0011 | fminc[s] FRT, FRA, FRB | x86 minss or Win32's min macro | FRT = FRA \< FRB ? FRA : FRB |
141 | 0100 | fminmagnum08[s] FRT, FRA, FRB | IEEE 754-2008 (TODO: (3)) | FRT = minmaxmag(FRA, FRB, False, fminnum08) (2) |
142 | 0101 | fminmag19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = minmaxmag(FRA, FRB, False, fmin19) (2) |
143 | 0110 | fminmagnum19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = minmaxmag(FRA, FRB, False, fminnum19) (2) |
144 | 0111 | fminmagc[s] FRT, FRA, FRB | - | FRT = minmaxmag(FRA, FRB, False, fminc) (2) |
145 | 1000 | fmaxnum08[s] FRT, FRA, FRB | IEEE 754-2008 | FRT = maxNum(FRA, FRB) (1) |
146 | 1001 | fmax19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = maximum(FRA, FRB) |
147 | 1010 | fmaxnum19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = maximumNumber(FRA, FRB) |
148 | 1011 | fmaxc[s] FRT, FRA, FRB | x86 maxss or Win32's max macro | FRT = FRA > FRB ? FRA : FRB |
149 | 1100 | fmaxmagnum08[s] FRT, FRA, FRB | IEEE 754-2008 (TODO: (3)) | FRT = minmaxmag(FRA, FRB, True, fmaxnum08) (2) |
150 | 1101 | fmaxmag19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = minmaxmag(FRA, FRB, True, fmax19) (2) |
151 | 1110 | fmaxmagnum19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = minmaxmag(FRA, FRB, True, fmaxnum19) (2) |
152 | 1111 | fmaxmagc[s] FRT, FRA, FRB | - | FRT = minmaxmag(FRA, FRB, True, fmaxc) (2) |
154 Note (1): for the purposes of minNum/maxNum, -0.0 is defined to be less than
155 +0.0. This is left unspecified in IEEE 754-2008.
157 Note (2): minmaxmag(x, y, cmp, fallback) is defined as:
160 def minmaxmag(x, y, is_max, fallback):
169 # equal magnitudes, or NaN input(s)
170 return fallback(x, y)
173 Note (3): TODO: icr if IEEE 754-2008 has min/maxMagNum like IEEE 754-2019's
174 minimum/maximumMagnitudeNumber
180 ## Floating Minimum/Maximum X-Form
183 fminmax FRT, FRA, FRB, FMM
187 |0 |6 |11 |16 |21 |24 |31 |
188 | PO | FRT | FRA | FRB | FMM[0:2] | XO | FMM[3] |
191 Compute the minimum/maximum of FRA and FRB, according to FMM, and store the
194 Assembly Aliases: see
195 [`FMM` -- Floating Min/Max Mode](#fmm-floating-min-max-mode)
199 ## Floating Minimum/Maximum Single X-Form
202 fminmaxs FRT, FRA, FRB, FMM
206 |0 |6 |11 |16 |21 |24 |31 |
207 | PO | FRT | FRA | FRB | FMM[0:2] | XO | FMM[3] |
210 Compute the minimum/maximum of FRA and FRB, according to FMM, and store the
213 Assembly Aliases: see
214 [`FMM` -- Floating Min/Max Mode](#fmm-floating-min-max-mode)
220 ## Minimum Unsigned X-Form
228 |0 |6 |11 |16 |21 |31 |
229 | PO | RT | RA | RB | XO | Rc |
239 Compute the unsigned minimum of RA and RB and store the result in RT.
241 Special Registers altered:
249 ## Maximum Unsigned X-Form
257 |0 |6 |11 |16 |21 |31 |
258 | PO | RT | RA | RB | XO | Rc |
268 Compute the unsigned maximum of RA and RB and store the result in RT.
270 Special Registers altered:
288 |0 |6 |11 |16 |21 |31 |
289 | PO | RT | RA | RB | XO | Rc |
299 Compute the signed minimum of RA and RB and store the result in RT.
301 Special Registers altered:
317 |0 |6 |11 |16 |21 |31 |
318 | PO | RT | RA | RB | XO | Rc |
328 Compute the signed maximum of RA and RB and store the result in RT.
330 Special Registers altered:
340 # Instruction Formats
342 Add the following entries to Book I 1.6.1.15 X-FORM:
345 |0 |6 |11 |16 |21 |24 |31 |
346 | PO | FRT | FRA | FRB | FMM[0:2] | XO | FMM[3] |
349 Add a new field to Book I 1.6.2 Word Instruction Fields:
353 Field used to specify minimum/maximum mode for fminmax[s].
364 Appendix E Power ISA sorted by opcode
365 Appendix F Power ISA sorted by version
366 Appendix G Power ISA sorted by Compliancy Subset
367 Appendix H Power ISA sorted by mnemonic
369 | Form | Book | Page | Version | mnemonic | Description |
370 |------|------|------|---------|----------|-------------|
371 | X | I | # | 3.2B | fminmax | Floating Minimum/Maximum |
372 | X | I | # | 3.2B | fminmaxs | Floating Minimum/Maximum Single |
373 | X | I | # | 3.2B | minu | Minimum Unsigned |
374 | X | I | # | 3.2B | maxu | Maximum Unsigned |
375 | X | I | # | 3.2B | min | Minimum |
376 | X | I | # | 3.2B | max | Maximum |