(no commit message)
[libreriscv.git] / ztrans_proposal.mdwn
1 # Ztrans - transcendental operations
2
3 See:
4
5 * <http://bugs.libre-riscv.org/show_bug.cgi?id=127>
6 * <https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.ExtendedInstructionSet.100.html>
7
8 Extension subsets:
9
10 * **Ztrans**: standard transcendentals (best suited to 3D)
11 * **ZtransExt**: extra functions (useful, not generally needed for 3D)
12 * Ztrigpi: trig. *-pi sinpi cospi tanpi
13 * Ztrignpi: trig non-*pi sin cos tan
14 * Zarctrigpi: arc-trig. *pi atan2pi asinpi acospi
15 * Zarctrignpi: arc-trig. non-*pi
16 * **ZtransAdv**: much more complex to implement in hardware
17
18 [[!toc levels=2]]
19
20 # List of 2-arg opcodes
21
22 [[!table data="""
23 opcode | Description | pseudo-code | Extension |
24 FATAN2 | atan2 arc tangent | rd = atan2(rs2, rs1) | Ztrans |
25 FATAN2PI | atan arc tangent / pi | rd = atan2(rs2, rs1) / pi | ZtransExt |
26 FPOW | x power of y | rd = pow(rs1, rs2) | ZtransAdv |
27 FROOT | x power 1/y | rd = pow(rs1, 1/rs2) | ZtransAdv |
28 """]]
29
30 # List of 1-arg opcodes
31
32 [[!table data="""
33 opcode | Description | pseudo-code | Extension |
34 FCBRT | Cube Root | rd = pow(rs1, 3) | Ztrans |
35 FEXP2 | power-of-2 | rd = pow(2, rs1) | Ztrans |
36 FLOG2 | log2 | rd = log2(rs1) | Ztrans |
37 FEXPM1 | exponent minus 1 | rd = pow(e, rs1) - 1.0 | Ztrans |
38 FLOG1P | log plus 1 | rd = log(e, 1 + rs1) | Ztrans |
39 FEXP | exponent | rd = pow(e, rs1) | ZtransExt |
40 FLOG | natural log (base e) | rd = log(e, rs1) | ZtransExt |
41 FEXP10 | power-of-10 | rd = pow(10, rs1) | ZtransExt |
42 FLOG10 | log base 10 | rd = log10(rs1) | ZtransExt |
43 FSIN | sin (radians) | | Ztrignpi |
44 FCOS | cos (radians) | | Ztrignpi |
45 FTAN | tan (radians) | | Ztrignpi |
46 FASIN | arcsin (radians) | rd = asin(rs1) | Zarctrignpi |
47 FACOS | arccos (radians) | rd = acos(rs1) | Zarctrignpi |
48 FSINPI | sin times pi | rd = sin(pi * rs1) | Ztrigpi |
49 FCOSPI | cos times pi | rd = cos(pi * rs1) | Ztrigpi |
50 FSINH | hyperbolic sin (radians) | | ZtransExt |
51 FCOSH | hyperbolic cos (radians) | | ZtransExt |
52 FTANH | hyperbolic tan (radians) | | ZtransExt |
53 FASINH | inverse hyperbolic sin | | ZtransExt |
54 FACOSH | inverse hyperbolic cos | | ZtransExt |
55 FATANH | inverse hyperbolic tan | | ZtransExt |
56 """]]
57
58 # Pseudo-code ops and macro-ops
59
60 * FRCP rd, rs1 - pseudo-code alias for rd = 1.0 / rs1
61 * FATAN - pseudo-code alias for rd = atan2(rs1, 1.0) - FATAN2
62 * FATANPI - pseudo alias for rd = atan2pi(rs1, 1.0) - FATAN2PI
63 * FSINCOS - fused macro-op between FSIN and FCOS (issued in that order).
64 * FSINCOSPI - fused macro-op between FSINPI and FCOSPI (issued in that order).
65
66 FATANPI example pseudo-code:
67
68 lui t0, 0x3F800 // upper bits of f32 1.0
69 fmv.x.s ft0, t0
70 fatan2pi.s rd, rs1, ft0
71