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 SVP64 tree reduction needs a single instruction to work properly.
65 2. if you implement any of the FP min/max modes, the rest are not much more hardware.
66 3. FP min/max are rather complex to implement in software, the most commonly used FP max function `fmax` from glibc compiled for SFFS is 32 (!) instructions.
68 https://gcc.godbolt.org/z/6xba61To6
109 .byte 0,9,0,0,0,0,0,0
114 Add the following entries to:
116 * the Appendices of Book I
117 * Book I 3.3.9 Fixed-Point Arithmetic Instructions
118 * Book I 4.6.6.1 Floating-Point Elementary Arithmetic Instructions
119 * Book I 1.6.1 and 1.6.2
125 ## `FMM` -- Floating Min/Max Mode
127 <a id="fmm-floating-min-max-mode"></a>
129 | `FMM` | Assembly Alias | Origin | Semantics |
130 |-------|-------------------------------|--------------------------------|-------------------------------------------------|
131 | 0000 | fminnum08[s] FRT, FRA, FRB | IEEE 754-2008 | FRT = minNum(FRA, FRB) (1) |
132 | 0001 | fmin19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = minimum(FRA, FRB) |
133 | 0010 | fminnum19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = minimumNumber(FRA, FRB) |
134 | 0011 | fminc[s] FRT, FRA, FRB | x86 minss or Win32's min macro | FRT = FRA \< FRB ? FRA : FRB |
135 | 0100 | fminmagnum08[s] FRT, FRA, FRB | IEEE 754-2008 (TODO: (3)) | FRT = minmaxmag(FRA, FRB, False, fminnum08) (2) |
136 | 0101 | fminmag19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = minmaxmag(FRA, FRB, False, fmin19) (2) |
137 | 0110 | fminmagnum19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = minmaxmag(FRA, FRB, False, fminnum19) (2) |
138 | 0111 | fminmagc[s] FRT, FRA, FRB | - | FRT = minmaxmag(FRA, FRB, False, fminc) (2) |
139 | 1000 | fmaxnum08[s] FRT, FRA, FRB | IEEE 754-2008 | FRT = maxNum(FRA, FRB) (1) |
140 | 1001 | fmax19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = maximum(FRA, FRB) |
141 | 1010 | fmaxnum19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = maximumNumber(FRA, FRB) |
142 | 1011 | fmaxc[s] FRT, FRA, FRB | x86 maxss or Win32's max macro | FRT = FRA > FRB ? FRA : FRB |
143 | 1100 | fmaxmagnum08[s] FRT, FRA, FRB | IEEE 754-2008 (TODO: (3)) | FRT = minmaxmag(FRA, FRB, True, fmaxnum08) (2) |
144 | 1101 | fmaxmag19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = minmaxmag(FRA, FRB, True, fmax19) (2) |
145 | 1110 | fmaxmagnum19[s] FRT, FRA, FRB | IEEE 754-2019 | FRT = minmaxmag(FRA, FRB, True, fmaxnum19) (2) |
146 | 1111 | fmaxmagc[s] FRT, FRA, FRB | - | FRT = minmaxmag(FRA, FRB, True, fmaxc) (2) |
148 Note (1): for the purposes of minNum/maxNum, -0.0 is defined to be less than +0.0. This is left unspecified in IEEE 754-2008.
150 Note (2): minmaxmag(x, y, cmp, fallback) is defined as:
153 def minmaxmag(x, y, is_max, fallback):
162 # equal magnitudes, or NaN input(s)
163 return fallback(x, y)
166 Note (3): TODO: icr if IEEE 754-2008 has min/maxMagNum like IEEE 754-2019's minimum/maximumMagnitudeNumber
172 ## Floating Minimum/Maximum X-Form
175 fminmax FRT, FRA, FRB, FMM
179 |0 |6 |11 |16 |21 |24 |31 |
180 | PO | FRT | FRA | FRB | FMM[0:2] | XO | FMM[3] |
183 Compute the minimum/maximum of FRA and FRB, according to FMM, and store the result in FRT.
185 Assembly Aliases: see [`FMM` -- Floating Min/Max Mode](#fmm-floating-min-max-mode)
189 ## Floating Minimum/Maximum Single X-Form
192 fminmaxs FRT, FRA, FRB, FMM
196 |0 |6 |11 |16 |21 |24 |31 |
197 | PO | FRT | FRA | FRB | FMM[0:2] | XO | FMM[3] |
200 Compute the minimum/maximum of FRA and FRB, according to FMM, and store the result in FRT.
202 Assembly Aliases: see [`FMM` -- Floating Min/Max Mode](#fmm-floating-min-max-mode)
208 ## Minimum Unsigned X-Form
216 |0 |6 |11 |16 |21 |31 |
217 | PO | RT | RA | RB | XO | Rc |
227 Compute the unsigned minimum of RA and RB and store the result in RT.
229 Special Registers altered:
237 ## Maximum Unsigned X-Form
245 |0 |6 |11 |16 |21 |31 |
246 | PO | RT | RA | RB | XO | Rc |
256 Compute the unsigned maximum of RA and RB and store the result in RT.
258 Special Registers altered:
276 |0 |6 |11 |16 |21 |31 |
277 | PO | RT | RA | RB | XO | Rc |
287 Compute the signed minimum of RA and RB and store the result in RT.
289 Special Registers altered:
305 |0 |6 |11 |16 |21 |31 |
306 | PO | RT | RA | RB | XO | Rc |
316 Compute the signed maximum of RA and RB and store the result in RT.
318 Special Registers altered:
328 # Instruction Formats
330 Add the following entries to Book I 1.6.1.15 X-FORM:
333 |0 |6 |11 |16 |21 |24 |31 |
334 | PO | FRT | FRA | FRB | FMM[0:2] | XO | FMM[3] |
337 Add a new field to Book I 1.6.2 Word Instruction Fields:
341 Field used to specify minimum/maximum mode for fminmax[s].
352 Appendix E Power ISA sorted by opcode
353 Appendix F Power ISA sorted by version
354 Appendix G Power ISA sorted by Compliancy Subset
355 Appendix H Power ISA sorted by mnemonic
357 | Form | Book | Page | Version | mnemonic | Description |
358 |------|------|------|---------|----------|-------------|
359 | X | I | # | 3.2B | fminmax | Floating Minimum/Maximum |
360 | X | I | # | 3.2B | fminmaxs | Floating Minimum/Maximum Single |
361 | X | I | # | 3.2B | minu | Minimum Unsigned |
362 | X | I | # | 3.2B | maxu | Maximum Unsigned |
363 | X | I | # | 3.2B | min | Minimum |
364 | X | I | # | 3.2B | max | Maximum |