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. FP min/max are rather complex to implement in software, the most commonly
69 used FP max function `fmax` from glibc compiled for SFFS is 32 (!)
72 https://gcc.godbolt.org/z/6xba61To6
113 .byte 0,9,0,0,0,0,0,0
118 Add the following entries to:
120 * the Appendices of Book I
121 * Book I 3.3.9 Fixed-Point Arithmetic Instructions
122 * Book I 4.6.6.1 Floating-Point Elementary Arithmetic Instructions
123 * Book I 1.6.1 and 1.6.2
129 ## `FMM` -- Floating Min/Max Mode
131 <a id="fmm-floating-min-max-mode"></a>
133 | `FMM` | Assembly Alias | Origin | Semantics |
134 |-------|-------------------------------|--------------------------------|-------------------------------------------------|
135 | 0000 | fminnum08[s] FRT, FRA, FRB | IEEE 754-2008 | FRT = minNum(FRA, FRB) (1) |
136 | 0001 | fmin19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = minimum(FRA, FRB) |
137 | 0010 | fminnum19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = minimumNumber(FRA, FRB) |
138 | 0011 | fminc[s] FRT, FRA, FRB | x86 minss or Win32's min macro | FRT = FRA \< FRB ? FRA : FRB |
139 | 0100 | fminmagnum08[s] FRT, FRA, FRB | IEEE 754-2008 (TODO: (3)) | FRT = minmaxmag(FRA, FRB, False, fminnum08) (2) |
140 | 0101 | fminmag19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = minmaxmag(FRA, FRB, False, fmin19) (2) |
141 | 0110 | fminmagnum19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = minmaxmag(FRA, FRB, False, fminnum19) (2) |
142 | 0111 | fminmagc[s] FRT, FRA, FRB | - | FRT = minmaxmag(FRA, FRB, False, fminc) (2) |
143 | 1000 | fmaxnum08[s] FRT, FRA, FRB | IEEE 754-2008 | FRT = maxNum(FRA, FRB) (1) |
144 | 1001 | fmax19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = maximum(FRA, FRB) |
145 | 1010 | fmaxnum19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = maximumNumber(FRA, FRB) |
146 | 1011 | fmaxc[s] FRT, FRA, FRB | x86 maxss or Win32's max macro | FRT = FRA > FRB ? FRA : FRB |
147 | 1100 | fmaxmagnum08[s] FRT, FRA, FRB | IEEE 754-2008 (TODO: (3)) | FRT = minmaxmag(FRA, FRB, True, fmaxnum08) (2) |
148 | 1101 | fmaxmag19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = minmaxmag(FRA, FRB, True, fmax19) (2) |
149 | 1110 | fmaxmagnum19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = minmaxmag(FRA, FRB, True, fmaxnum19) (2) |
150 | 1111 | fmaxmagc[s] FRT, FRA, FRB | - | FRT = minmaxmag(FRA, FRB, True, fmaxc) (2) |
152 Note (1): for the purposes of minNum/maxNum, -0.0 is defined to be less than
153 +0.0. This is left unspecified in IEEE 754-2008.
155 Note (2): minmaxmag(x, y, cmp, fallback) is defined as:
158 def minmaxmag(x, y, is_max, fallback):
167 # equal magnitudes, or NaN input(s)
168 return fallback(x, y)
171 Note (3): TODO: icr if IEEE 754-2008 has min/maxMagNum like IEEE 754-2019's
172 minimum/maximumMagnitudeNumber
178 ## Floating Minimum/Maximum X-Form
181 fminmax FRT, FRA, FRB, FMM
185 |0 |6 |11 |16 |21 |24 |31 |
186 | PO | FRT | FRA | FRB | FMM[0:2] | XO | FMM[3] |
189 Compute the minimum/maximum of FRA and FRB, according to FMM, and store the
192 Assembly Aliases: see
193 [`FMM` -- Floating Min/Max Mode](#fmm-floating-min-max-mode)
197 ## Floating Minimum/Maximum Single X-Form
200 fminmaxs FRT, FRA, FRB, FMM
204 |0 |6 |11 |16 |21 |24 |31 |
205 | PO | FRT | FRA | FRB | FMM[0:2] | XO | FMM[3] |
208 Compute the minimum/maximum of FRA and FRB, according to FMM, and store the
211 Assembly Aliases: see
212 [`FMM` -- Floating Min/Max Mode](#fmm-floating-min-max-mode)
218 ## Minimum Unsigned X-Form
226 |0 |6 |11 |16 |21 |31 |
227 | PO | RT | RA | RB | XO | Rc |
237 Compute the unsigned minimum of RA and RB and store the result in RT.
239 Special Registers altered:
247 ## Maximum Unsigned X-Form
255 |0 |6 |11 |16 |21 |31 |
256 | PO | RT | RA | RB | XO | Rc |
266 Compute the unsigned maximum of RA and RB and store the result in RT.
268 Special Registers altered:
286 |0 |6 |11 |16 |21 |31 |
287 | PO | RT | RA | RB | XO | Rc |
297 Compute the signed minimum of RA and RB and store the result in RT.
299 Special Registers altered:
315 |0 |6 |11 |16 |21 |31 |
316 | PO | RT | RA | RB | XO | Rc |
326 Compute the signed maximum of RA and RB and store the result in RT.
328 Special Registers altered:
338 # Instruction Formats
340 Add the following entries to Book I 1.6.1.15 X-FORM:
343 |0 |6 |11 |16 |21 |24 |31 |
344 | PO | FRT | FRA | FRB | FMM[0:2] | XO | FMM[3] |
347 Add a new field to Book I 1.6.2 Word Instruction Fields:
351 Field used to specify minimum/maximum mode for fminmax[s].
362 Appendix E Power ISA sorted by opcode
363 Appendix F Power ISA sorted by version
364 Appendix G Power ISA sorted by Compliancy Subset
365 Appendix H Power ISA sorted by mnemonic
367 | Form | Book | Page | Version | mnemonic | Description |
368 |------|------|------|---------|----------|-------------|
369 | X | I | # | 3.2B | fminmax | Floating Minimum/Maximum |
370 | X | I | # | 3.2B | fminmaxs | Floating Minimum/Maximum Single |
371 | X | I | # | 3.2B | minu | Minimum Unsigned |
372 | X | I | # | 3.2B | maxu | Maximum Unsigned |
373 | X | I | # | 3.2B | min | Minimum |
374 | X | I | # | 3.2B | max | Maximum |