1 /* SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0 */
2 #include <linux/linkage.h>
3 #include <asm/asmmacro.h>
6 #if XCHAL_HAVE_MUL16 || XCHAL_HAVE_MUL32 || XCHAL_HAVE_MAC16
14 #ifdef __XTENSA_CALL0_ABI__
21 /* This is not really a leaf function; allocate enough stack space
22 to allow CALL12s to a helper function. */
34 #endif /* __XTENSA_EB__ */
36 /* This code is taken from the mulsf3 routine in ieee754-sf.S.
37 See more comments there. */
39 #if XCHAL_HAVE_MUL32_HIGH
44 #else /* ! MUL32_HIGH */
46 #if defined(__XTENSA_CALL0_ABI__) && XCHAL_NO_MUL
47 /* a0 and a8 will be clobbered by calling the multiply function
48 but a8 is not used here and need not be saved. */
52 #if XCHAL_HAVE_MUL16 || XCHAL_HAVE_MUL32
57 /* Get the high halves of the inputs into registers. */
64 #if XCHAL_HAVE_MUL32 && !XCHAL_HAVE_MUL16
65 /* Clear the high halves of the inputs. This does not matter
66 for MUL16 because the high bits are ignored. */
70 #endif /* MUL16 || MUL32 */
75 #define do_mul(dst, xreg, xhalf, yreg, yhalf) \
76 mul16u dst, xreg ## xhalf, yreg ## yhalf
78 #elif XCHAL_HAVE_MUL32
80 #define do_mul(dst, xreg, xhalf, yreg, yhalf) \
81 mull dst, xreg ## xhalf, yreg ## yhalf
83 #elif XCHAL_HAVE_MAC16
85 /* The preprocessor insists on inserting a space when concatenating after
86 a period in the definition of do_mul below. These macros are a workaround
87 using underscores instead of periods when doing the concatenation. */
88 #define umul_aa_ll umul.aa.ll
89 #define umul_aa_lh umul.aa.lh
90 #define umul_aa_hl umul.aa.hl
91 #define umul_aa_hh umul.aa.hh
93 #define do_mul(dst, xreg, xhalf, yreg, yhalf) \
94 umul_aa_ ## xhalf ## yhalf xreg, yreg; \
97 #else /* no multiply hardware */
99 #define set_arg_l(dst, src) \
100 extui dst, src, 0, 16
101 #define set_arg_h(dst, src) \
104 #ifdef __XTENSA_CALL0_ABI__
105 #define do_mul(dst, xreg, xhalf, yreg, yhalf) \
106 set_arg_ ## xhalf (a13, xreg); \
107 set_arg_ ## yhalf (a14, yreg); \
108 call0 .Lmul_mulsi3; \
111 #define do_mul(dst, xreg, xhalf, yreg, yhalf) \
112 set_arg_ ## xhalf (a14, xreg); \
113 set_arg_ ## yhalf (a15, yreg); \
114 call12 .Lmul_mulsi3; \
116 #endif /* __XTENSA_CALL0_ABI__ */
118 #endif /* no multiply hardware */
120 /* Add pp1 and pp2 into a6 with carry-out in a9. */
121 do_mul(a6, a2, l, a3, h) /* pp 1 */
122 do_mul(a11, a2, h, a3, l) /* pp 2 */
128 /* Shift the high half of a9/a6 into position in a9. Note that
129 this value can be safely incremented without any carry-outs. */
133 /* Compute the low word into a6. */
134 do_mul(a11, a2, l, a3, l) /* pp 0 */
140 /* Compute the high word into wh. */
141 do_mul(wh, a2, h, a3, h) /* pp 3 */
145 #endif /* !MUL32_HIGH */
147 #if defined(__XTENSA_CALL0_ABI__) && XCHAL_NO_MUL
148 /* Restore the original return address. */
151 #ifdef __XTENSA_CALL0_ABI__
163 .macro do_addx2 dst, as, at, tmp
172 .macro do_addx4 dst, as, at, tmp
181 .macro do_addx8 dst, as, at, tmp
190 /* For Xtensa processors with no multiply hardware, this simplified
191 version of _mulsi3 is used for multiplying 16-bit chunks of
192 the floating-point mantissas. When using CALL0, this function
193 uses a custom ABI: the inputs are passed in a13 and a14, the
194 result is returned in a12, and a8 and a15 are clobbered. */
199 .macro mul_mulsi3_body dst, src1, src2, tmp1, tmp2
201 1: add \tmp1, \src2, \dst
202 extui \tmp2, \src1, 0, 1
203 movnez \dst, \tmp1, \tmp2
205 do_addx2 \tmp1, \src2, \dst, \tmp1
206 extui \tmp2, \src1, 1, 1
207 movnez \dst, \tmp1, \tmp2
209 do_addx4 \tmp1, \src2, \dst, \tmp1
210 extui \tmp2, \src1, 2, 1
211 movnez \dst, \tmp1, \tmp2
213 do_addx8 \tmp1, \src2, \dst, \tmp1
214 extui \tmp2, \src1, 3, 1
215 movnez \dst, \tmp1, \tmp2
222 #ifdef __XTENSA_CALL0_ABI__
223 mul_mulsi3_body a12, a13, a14, a15, a8
225 /* The result will be written into a2, so save that argument in a4. */
227 mul_mulsi3_body a2, a4, a3, a5, a6
230 #endif /* XCHAL_NO_MUL */
233 EXPORT_SYMBOL(__umulsidi3)