| 1 |
/* Assembly functions for the Xtensa version of libgcc1. |
| 2 |
Copyright (C) 2001-2025 Free Software Foundation, Inc. |
| 3 |
Contributed by Bob Wilson ([email protected]) at Tensilica. |
| 4 |
|
| 5 |
This file is part of GCC. |
| 6 |
|
| 7 |
GCC is free software; you can redistribute it and/or modify it under |
| 8 |
the terms of the GNU General Public License as published by the Free |
| 9 |
Software Foundation; either version 3, or (at your option) any later |
| 10 |
version. |
| 11 |
|
| 12 |
GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
| 13 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 15 |
for more details. |
| 16 |
|
| 17 |
Under Section 7 of GPL version 3, you are granted additional |
| 18 |
permissions described in the GCC Runtime Library Exception, version |
| 19 |
3.1, as published by the Free Software Foundation. |
| 20 |
|
| 21 |
You should have received a copy of the GNU General Public License and |
| 22 |
a copy of the GCC Runtime Library Exception along with this program; |
| 23 |
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 24 |
<http://www.gnu.org/licenses/>. */ |
| 25 |
|
| 26 |
#include "xtensa-config-builtin.h" |
| 27 |
|
| 28 |
/* An executable stack is *not* required for these functions. */ |
| 29 |
#if defined(__ELF__) && defined(__linux__) |
| 30 |
.section .note.GNU-stack,"",%progbits |
| 31 |
.previous |
| 32 |
#endif |
| 33 |
|
| 34 |
/* Define macros for the ABS and ADDX* instructions to handle cases |
| 35 |
where they are not included in the Xtensa processor configuration. */ |
| 36 |
|
| 37 |
.macro do_abs dst, src, tmp |
| 38 |
#if XCHAL_HAVE_ABS |
| 39 |
abs \dst, \src |
| 40 |
#else |
| 41 |
neg \tmp, \src |
| 42 |
movgez \tmp, \src, \src |
| 43 |
mov \dst, \tmp |
| 44 |
#endif |
| 45 |
.endm |
| 46 |
|
| 47 |
.macro do_addx2 dst, as, at, tmp |
| 48 |
#if XCHAL_HAVE_ADDX |
| 49 |
addx2 \dst, \as, \at |
| 50 |
#else |
| 51 |
slli \tmp, \as, 1 |
| 52 |
add \dst, \tmp, \at |
| 53 |
#endif |
| 54 |
.endm |
| 55 |
|
| 56 |
.macro do_addx4 dst, as, at, tmp |
| 57 |
#if XCHAL_HAVE_ADDX |
| 58 |
addx4 \dst, \as, \at |
| 59 |
#else |
| 60 |
slli \tmp, \as, 2 |
| 61 |
add \dst, \tmp, \at |
| 62 |
#endif |
| 63 |
.endm |
| 64 |
|
| 65 |
.macro do_addx8 dst, as, at, tmp |
| 66 |
#if XCHAL_HAVE_ADDX |
| 67 |
addx8 \dst, \as, \at |
| 68 |
#else |
| 69 |
slli \tmp, \as, 3 |
| 70 |
add \dst, \tmp, \at |
| 71 |
#endif |
| 72 |
.endm |
| 73 |
|
| 74 |
/* Define macros for leaf function entry and return, supporting either the |
| 75 |
standard register windowed ABI or the non-windowed call0 ABI. These |
| 76 |
macros do not allocate any extra stack space, so they only work for |
| 77 |
leaf functions that do not need to spill anything to the stack. */ |
| 78 |
|
| 79 |
.macro leaf_entry reg, size |
| 80 |
#if XCHAL_HAVE_WINDOWED && !__XTENSA_CALL0_ABI__ |
| 81 |
entry \reg, \size |
| 82 |
#else |
| 83 |
/* do nothing */ |
| 84 |
#endif |
| 85 |
.endm |
| 86 |
|
| 87 |
.macro leaf_return |
| 88 |
#if XCHAL_HAVE_WINDOWED && !__XTENSA_CALL0_ABI__ |
| 89 |
retw |
| 90 |
#else |
| 91 |
ret |
| 92 |
#endif |
| 93 |
.endm |
| 94 |
|
| 95 |
|
| 96 |
#ifdef L_mulsi3 |
| 97 |
.align 4 |
| 98 |
.global __mulsi3 |
| 99 |
.type __mulsi3, @function |
| 100 |
__mulsi3: |
| 101 |
leaf_entry sp, 16 |
| 102 |
|
| 103 |
#if XCHAL_HAVE_MUL32 |
| 104 |
mull a2, a2, a3 |
| 105 |
|
| 106 |
#elif XCHAL_HAVE_MUL16 |
| 107 |
or a4, a2, a3 |
| 108 |
srai a4, a4, 16 |
| 109 |
bnez a4, .LMUL16 |
| 110 |
mul16u a2, a2, a3 |
| 111 |
leaf_return |
| 112 |
.LMUL16: |
| 113 |
srai a4, a2, 16 |
| 114 |
srai a5, a3, 16 |
| 115 |
mul16u a7, a4, a3 |
| 116 |
mul16u a6, a5, a2 |
| 117 |
mul16u a4, a2, a3 |
| 118 |
add a7, a7, a6 |
| 119 |
slli a7, a7, 16 |
| 120 |
add a2, a7, a4 |
| 121 |
|
| 122 |
#elif XCHAL_HAVE_MAC16 |
| 123 |
mul.aa.hl a2, a3 |
| 124 |
mula.aa.lh a2, a3 |
| 125 |
rsr a5, ACCLO |
| 126 |
umul.aa.ll a2, a3 |
| 127 |
rsr a4, ACCLO |
| 128 |
slli a5, a5, 16 |
| 129 |
add a2, a4, a5 |
| 130 |
|
| 131 |
#else /* !MUL32 && !MUL16 && !MAC16 */ |
| 132 |
|
| 133 |
/* Multiply one bit at a time, but unroll the loop 4x to better |
| 134 |
exploit the addx instructions and avoid overhead. |
| 135 |
Peel the first iteration to save a cycle on init. */ |
| 136 |
|
| 137 |
/* Avoid negative numbers. */ |
| 138 |
xor a5, a2, a3 /* Top bit is 1 if one input is negative. */ |
| 139 |
do_abs a3, a3, a6 |
| 140 |
do_abs a2, a2, a6 |
| 141 |
|
| 142 |
/* Swap so the second argument is smaller. */ |
| 143 |
sub a7, a2, a3 |
| 144 |
mov a4, a3 |
| 145 |
movgez a4, a2, a7 /* a4 = max (a2, a3) */ |
| 146 |
movltz a3, a2, a7 /* a3 = min (a2, a3) */ |
| 147 |
|
| 148 |
movi a2, 0 |
| 149 |
extui a6, a3, 0, 1 |
| 150 |
movnez a2, a4, a6 |
| 151 |
|
| 152 |
do_addx2 a7, a4, a2, a7 |
| 153 |
extui a6, a3, 1, 1 |
| 154 |
movnez a2, a7, a6 |
| 155 |
|
| 156 |
do_addx4 a7, a4, a2, a7 |
| 157 |
extui a6, a3, 2, 1 |
| 158 |
movnez a2, a7, a6 |
| 159 |
|
| 160 |
do_addx8 a7, a4, a2, a7 |
| 161 |
extui a6, a3, 3, 1 |
| 162 |
movnez a2, a7, a6 |
| 163 |
|
| 164 |
bgeui a3, 16, .Lmult_main_loop |
| 165 |
neg a3, a2 |
| 166 |
movltz a2, a3, a5 |
| 167 |
leaf_return |
| 168 |
|
| 169 |
.align 4 |
| 170 |
.Lmult_main_loop: |
| 171 |
srli a3, a3, 4 |
| 172 |
slli a4, a4, 4 |
| 173 |
|
| 174 |
add a7, a4, a2 |
| 175 |
extui a6, a3, 0, 1 |
| 176 |
movnez a2, a7, a6 |
| 177 |
|
| 178 |
do_addx2 a7, a4, a2, a7 |
| 179 |
extui a6, a3, 1, 1 |
| 180 |
movnez a2, a7, a6 |
| 181 |
|
| 182 |
do_addx4 a7, a4, a2, a7 |
| 183 |
extui a6, a3, 2, 1 |
| 184 |
movnez a2, a7, a6 |
| 185 |
|
| 186 |
do_addx8 a7, a4, a2, a7 |
| 187 |
extui a6, a3, 3, 1 |
| 188 |
movnez a2, a7, a6 |
| 189 |
|
| 190 |
bgeui a3, 16, .Lmult_main_loop |
| 191 |
|
| 192 |
neg a3, a2 |
| 193 |
movltz a2, a3, a5 |
| 194 |
|
| 195 |
#endif /* !MUL32 && !MUL16 && !MAC16 */ |
| 196 |
|
| 197 |
leaf_return |
| 198 |
.size __mulsi3, . - __mulsi3 |
| 199 |
|
| 200 |
#endif /* L_mulsi3 */ |
| 201 |
|
| 202 |
|
| 203 |
#ifdef L_umulsidi3 |
| 204 |
|
| 205 |
#if !XCHAL_HAVE_MUL16 && !XCHAL_HAVE_MUL32 && !XCHAL_HAVE_MAC16 |
| 206 |
#define XCHAL_NO_MUL 1 |
| 207 |
#endif |
| 208 |
|
| 209 |
.align 4 |
| 210 |
.global __umulsidi3 |
| 211 |
.type __umulsidi3, @function |
| 212 |
__umulsidi3: |
| 213 |
#if __XTENSA_CALL0_ABI__ |
| 214 |
leaf_entry sp, 32 |
| 215 |
addi sp, sp, -32 |
| 216 |
s32i a12, sp, 16 |
| 217 |
s32i a13, sp, 20 |
| 218 |
s32i a14, sp, 24 |
| 219 |
s32i a15, sp, 28 |
| 220 |
#elif XCHAL_NO_MUL |
| 221 |
/* This is not really a leaf function; allocate enough stack space |
| 222 |
to allow CALL12s to a helper function. */ |
| 223 |
leaf_entry sp, 48 |
| 224 |
#else |
| 225 |
leaf_entry sp, 16 |
| 226 |
#endif |
| 227 |
|
| 228 |
#ifdef __XTENSA_EB__ |
| 229 |
#define wh a2 |
| 230 |
#define wl a3 |
| 231 |
#else |
| 232 |
#define wh a3 |
| 233 |
#define wl a2 |
| 234 |
#endif /* __XTENSA_EB__ */ |
| 235 |
|
| 236 |
/* This code is taken from the mulsf3 routine in ieee754-sf.S. |
| 237 |
See more comments there. */ |
| 238 |
|
| 239 |
#if XCHAL_HAVE_MUL32_HIGH |
| 240 |
mull a6, a2, a3 |
| 241 |
muluh wh, a2, a3 |
| 242 |
mov wl, a6 |
| 243 |
|
| 244 |
#else /* ! MUL32_HIGH */ |
| 245 |
|
| 246 |
#if __XTENSA_CALL0_ABI__ && XCHAL_NO_MUL |
| 247 |
/* a0 and a8 will be clobbered by calling the multiply function |
| 248 |
but a8 is not used here and need not be saved. */ |
| 249 |
s32i a0, sp, 0 |
| 250 |
#endif |
| 251 |
|
| 252 |
#if XCHAL_HAVE_MUL16 || XCHAL_HAVE_MUL32 |
| 253 |
|
| 254 |
#define a2h a4 |
| 255 |
#define a3h a5 |
| 256 |
|
| 257 |
/* Get the high halves of the inputs into registers. */ |
| 258 |
srli a2h, a2, 16 |
| 259 |
srli a3h, a3, 16 |
| 260 |
|
| 261 |
#define a2l a2 |
| 262 |
#define a3l a3 |
| 263 |
|
| 264 |
#if XCHAL_HAVE_MUL32 && !XCHAL_HAVE_MUL16 |
| 265 |
/* Clear the high halves of the inputs. This does not matter |
| 266 |
for MUL16 because the high bits are ignored. */ |
| 267 |
extui a2, a2, 0, 16 |
| 268 |
extui a3, a3, 0, 16 |
| 269 |
#endif |
| 270 |
#endif /* MUL16 || MUL32 */ |
| 271 |
|
| 272 |
|
| 273 |
#if XCHAL_HAVE_MUL16 |
| 274 |
|
| 275 |
#define do_mul(dst, xreg, xhalf, yreg, yhalf) \ |
| 276 |
mul16u dst, xreg ## xhalf, yreg ## yhalf |
| 277 |
|
| 278 |
#elif XCHAL_HAVE_MUL32 |
| 279 |
|
| 280 |
#define do_mul(dst, xreg, xhalf, yreg, yhalf) \ |
| 281 |
mull dst, xreg ## xhalf, yreg ## yhalf |
| 282 |
|
| 283 |
#elif XCHAL_HAVE_MAC16 |
| 284 |
|
| 285 |
/* The preprocessor insists on inserting a space when concatenating after |
| 286 |
a period in the definition of do_mul below. These macros are a workaround |
| 287 |
using underscores instead of periods when doing the concatenation. */ |
| 288 |
#define umul_aa_ll umul.aa.ll |
| 289 |
#define umul_aa_lh umul.aa.lh |
| 290 |
#define umul_aa_hl umul.aa.hl |
| 291 |
#define umul_aa_hh umul.aa.hh |
| 292 |
|
| 293 |
#define do_mul(dst, xreg, xhalf, yreg, yhalf) \ |
| 294 |
umul_aa_ ## xhalf ## yhalf xreg, yreg; \ |
| 295 |
rsr dst, ACCLO |
| 296 |
|
| 297 |
#else /* no multiply hardware */ |
| 298 |
|
| 299 |
#define set_arg_l(dst, src) \ |
| 300 |
extui dst, src, 0, 16 |
| 301 |
#define set_arg_h(dst, src) \ |
| 302 |
srli dst, src, 16 |
| 303 |
|
| 304 |
#if __XTENSA_CALL0_ABI__ |
| 305 |
#define do_mul(dst, xreg, xhalf, yreg, yhalf) \ |
| 306 |
set_arg_ ## xhalf (a13, xreg); \ |
| 307 |
set_arg_ ## yhalf (a14, yreg); \ |
| 308 |
call0 .Lmul_mulsi3; \ |
| 309 |
mov dst, a12 |
| 310 |
#else |
| 311 |
#define do_mul(dst, xreg, xhalf, yreg, yhalf) \ |
| 312 |
set_arg_ ## xhalf (a14, xreg); \ |
| 313 |
set_arg_ ## yhalf (a15, yreg); \ |
| 314 |
call12 .Lmul_mulsi3; \ |
| 315 |
mov dst, a14 |
| 316 |
#endif /* __XTENSA_CALL0_ABI__ */ |
| 317 |
|
| 318 |
#endif /* no multiply hardware */ |
| 319 |
|
| 320 |
/* Add pp1 and pp2 into a6 with carry-out in a9. */ |
| 321 |
do_mul(a6, a2, l, a3, h) /* pp 1 */ |
| 322 |
do_mul(a11, a2, h, a3, l) /* pp 2 */ |
| 323 |
movi a9, 0 |
| 324 |
add a6, a6, a11 |
| 325 |
bgeu a6, a11, 1f |
| 326 |
addi a9, a9, 1 |
| 327 |
1: |
| 328 |
/* Shift the high half of a9/a6 into position in a9. Note that |
| 329 |
this value can be safely incremented without any carry-outs. */ |
| 330 |
ssai 16 |
| 331 |
src a9, a9, a6 |
| 332 |
|
| 333 |
/* Compute the low word into a6. */ |
| 334 |
do_mul(a11, a2, l, a3, l) /* pp 0 */ |
| 335 |
sll a6, a6 |
| 336 |
add a6, a6, a11 |
| 337 |
bgeu a6, a11, 1f |
| 338 |
addi a9, a9, 1 |
| 339 |
1: |
| 340 |
/* Compute the high word into wh. */ |
| 341 |
do_mul(wh, a2, h, a3, h) /* pp 3 */ |
| 342 |
add wh, wh, a9 |
| 343 |
mov wl, a6 |
| 344 |
|
| 345 |
#endif /* !MUL32_HIGH */ |
| 346 |
|
| 347 |
#if __XTENSA_CALL0_ABI__ && XCHAL_NO_MUL |
| 348 |
/* Restore the original return address. */ |
| 349 |
l32i a0, sp, 0 |
| 350 |
#endif |
| 351 |
#if __XTENSA_CALL0_ABI__ |
| 352 |
l32i a12, sp, 16 |
| 353 |
l32i a13, sp, 20 |
| 354 |
l32i a14, sp, 24 |
| 355 |
l32i a15, sp, 28 |
| 356 |
addi sp, sp, 32 |
| 357 |
#endif |
| 358 |
leaf_return |
| 359 |
|
| 360 |
#if XCHAL_NO_MUL |
| 361 |
|
| 362 |
/* For Xtensa processors with no multiply hardware, this simplified |
| 363 |
version of _mulsi3 is used for multiplying 16-bit chunks of |
| 364 |
the floating-point mantissas. When using CALL0, this function |
| 365 |
uses a custom ABI: the inputs are passed in a13 and a14, the |
| 366 |
result is returned in a12, and a8 and a15 are clobbered. */ |
| 367 |
.align 4 |
| 368 |
.Lmul_mulsi3: |
| 369 |
leaf_entry sp, 16 |
| 370 |
.macro mul_mulsi3_body dst, src1, src2, tmp1, tmp2 |
| 371 |
movi \dst, 0 |
| 372 |
1: add \tmp1, \src2, \dst |
| 373 |
extui \tmp2, \src1, 0, 1 |
| 374 |
movnez \dst, \tmp1, \tmp2 |
| 375 |
|
| 376 |
do_addx2 \tmp1, \src2, \dst, \tmp1 |
| 377 |
extui \tmp2, \src1, 1, 1 |
| 378 |
movnez \dst, \tmp1, \tmp2 |
| 379 |
|
| 380 |
do_addx4 \tmp1, \src2, \dst, \tmp1 |
| 381 |
extui \tmp2, \src1, 2, 1 |
| 382 |
movnez \dst, \tmp1, \tmp2 |
| 383 |
|
| 384 |
do_addx8 \tmp1, \src2, \dst, \tmp1 |
| 385 |
extui \tmp2, \src1, 3, 1 |
| 386 |
movnez \dst, \tmp1, \tmp2 |
| 387 |
|
| 388 |
srli \src1, \src1, 4 |
| 389 |
slli \src2, \src2, 4 |
| 390 |
bnez \src1, 1b |
| 391 |
.endm |
| 392 |
#if __XTENSA_CALL0_ABI__ |
| 393 |
mul_mulsi3_body a12, a13, a14, a15, a8 |
| 394 |
#else |
| 395 |
/* The result will be written into a2, so save that argument in a4. */ |
| 396 |
mov a4, a2 |
| 397 |
mul_mulsi3_body a2, a4, a3, a5, a6 |
| 398 |
#endif |
| 399 |
leaf_return |
| 400 |
#endif /* XCHAL_NO_MUL */ |
| 401 |
|
| 402 |
.size __umulsidi3, . - __umulsidi3 |
| 403 |
|
| 404 |
#endif /* L_umulsidi3 */ |
| 405 |
|
| 406 |
|
| 407 |
/* Define a macro for the NSAU (unsigned normalize shift amount) |
| 408 |
instruction, which computes the number of leading zero bits, |
| 409 |
to handle cases where it is not included in the Xtensa processor |
| 410 |
configuration. */ |
| 411 |
|
| 412 |
.macro do_nsau cnt, val, tmp, a |
| 413 |
#if XCHAL_HAVE_NSA |
| 414 |
nsau \cnt, \val |
| 415 |
#else |
| 416 |
mov \a, \val |
| 417 |
movi \cnt, 0 |
| 418 |
extui \tmp, \a, 16, 16 |
| 419 |
bnez \tmp, 0f |
| 420 |
movi \cnt, 16 |
| 421 |
slli \a, \a, 16 |
| 422 |
0: |
| 423 |
extui \tmp, \a, 24, 8 |
| 424 |
bnez \tmp, 1f |
| 425 |
addi \cnt, \cnt, 8 |
| 426 |
slli \a, \a, 8 |
| 427 |
1: |
| 428 |
movi \tmp, __nsau_data |
| 429 |
extui \a, \a, 24, 8 |
| 430 |
add \tmp, \tmp, \a |
| 431 |
l8ui \tmp, \tmp, 0 |
| 432 |
add \cnt, \cnt, \tmp |
| 433 |
#endif /* !XCHAL_HAVE_NSA */ |
| 434 |
.endm |
| 435 |
|
| 436 |
#ifdef L_clz |
| 437 |
.section .rodata |
| 438 |
.align 4 |
| 439 |
.global __nsau_data |
| 440 |
.type __nsau_data, @object |
| 441 |
__nsau_data: |
| 442 |
#if !XCHAL_HAVE_NSA |
| 443 |
.byte 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4 |
| 444 |
.byte 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 |
| 445 |
.byte 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 |
| 446 |
.byte 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 |
| 447 |
.byte 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 |
| 448 |
.byte 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 |
| 449 |
.byte 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 |
| 450 |
.byte 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 |
| 451 |
.byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 452 |
.byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 453 |
.byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 454 |
.byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 455 |
.byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 456 |
.byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 457 |
.byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 458 |
.byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 459 |
#endif /* !XCHAL_HAVE_NSA */ |
| 460 |
.size __nsau_data, . - __nsau_data |
| 461 |
.hidden __nsau_data |
| 462 |
#endif /* L_clz */ |
| 463 |
|
| 464 |
|
| 465 |
#ifdef L_clrsbsi2 |
| 466 |
.align 4 |
| 467 |
.global __clrsbsi2 |
| 468 |
.type __clrsbsi2, @function |
| 469 |
__clrsbsi2: |
| 470 |
leaf_entry sp, 16 |
| 471 |
#if XCHAL_HAVE_NSA |
| 472 |
nsa a2, a2 |
| 473 |
#else |
| 474 |
srai a3, a2, 31 |
| 475 |
xor a3, a3, a2 |
| 476 |
movi a2, 31 |
| 477 |
beqz a3, .Lreturn |
| 478 |
do_nsau a2, a3, a4, a5 |
| 479 |
addi a2, a2, -1 |
| 480 |
.Lreturn: |
| 481 |
#endif |
| 482 |
leaf_return |
| 483 |
.size __clrsbsi2, . - __clrsbsi2 |
| 484 |
|
| 485 |
#endif /* L_clrsbsi2 */ |
| 486 |
|
| 487 |
|
| 488 |
#ifdef L_clzsi2 |
| 489 |
.align 4 |
| 490 |
.global __clzsi2 |
| 491 |
.type __clzsi2, @function |
| 492 |
__clzsi2: |
| 493 |
leaf_entry sp, 16 |
| 494 |
do_nsau a2, a2, a3, a4 |
| 495 |
leaf_return |
| 496 |
.size __clzsi2, . - __clzsi2 |
| 497 |
|
| 498 |
#endif /* L_clzsi2 */ |
| 499 |
|
| 500 |
|
| 501 |
#ifdef L_ctzsi2 |
| 502 |
.align 4 |
| 503 |
.global __ctzsi2 |
| 504 |
.type __ctzsi2, @function |
| 505 |
__ctzsi2: |
| 506 |
leaf_entry sp, 16 |
| 507 |
neg a3, a2 |
| 508 |
and a3, a3, a2 |
| 509 |
do_nsau a2, a3, a4, a5 |
| 510 |
neg a2, a2 |
| 511 |
addi a2, a2, 31 |
| 512 |
leaf_return |
| 513 |
.size __ctzsi2, . - __ctzsi2 |
| 514 |
|
| 515 |
#endif /* L_ctzsi2 */ |
| 516 |
|
| 517 |
|
| 518 |
#ifdef L_ffssi2 |
| 519 |
.align 4 |
| 520 |
.global __ffssi2 |
| 521 |
.type __ffssi2, @function |
| 522 |
__ffssi2: |
| 523 |
leaf_entry sp, 16 |
| 524 |
neg a3, a2 |
| 525 |
and a3, a3, a2 |
| 526 |
do_nsau a2, a3, a4, a5 |
| 527 |
neg a2, a2 |
| 528 |
addi a2, a2, 32 |
| 529 |
leaf_return |
| 530 |
.size __ffssi2, . - __ffssi2 |
| 531 |
|
| 532 |
#endif /* L_ffssi2 */ |
| 533 |
|
| 534 |
|
| 535 |
#ifdef L_udivsi3 |
| 536 |
.align 4 |
| 537 |
.global __udivsi3 |
| 538 |
.type __udivsi3, @function |
| 539 |
__udivsi3: |
| 540 |
leaf_entry sp, 16 |
| 541 |
#if XCHAL_HAVE_DIV32 |
| 542 |
quou a2, a2, a3 |
| 543 |
#else |
| 544 |
bltui a3, 2, .Lle_one /* check if the divisor <= 1 */ |
| 545 |
|
| 546 |
mov a6, a2 /* keep dividend in a6 */ |
| 547 |
do_nsau a5, a6, a2, a7 /* dividend_shift = nsau (dividend) */ |
| 548 |
do_nsau a4, a3, a2, a7 /* divisor_shift = nsau (divisor) */ |
| 549 |
bgeu a5, a4, .Lspecial |
| 550 |
|
| 551 |
sub a4, a4, a5 /* count = divisor_shift - dividend_shift */ |
| 552 |
ssl a4 |
| 553 |
sll a3, a3 /* divisor <<= count */ |
| 554 |
movi a2, 0 /* quotient = 0 */ |
| 555 |
|
| 556 |
/* test-subtract-and-shift loop; one quotient bit on each iteration */ |
| 557 |
#if XCHAL_HAVE_LOOPS |
| 558 |
loopnez a4, .Lloopend |
| 559 |
#endif /* XCHAL_HAVE_LOOPS */ |
| 560 |
.Lloop: |
| 561 |
bltu a6, a3, .Lzerobit |
| 562 |
sub a6, a6, a3 |
| 563 |
addi a2, a2, 1 |
| 564 |
.Lzerobit: |
| 565 |
slli a2, a2, 1 |
| 566 |
srli a3, a3, 1 |
| 567 |
#if !XCHAL_HAVE_LOOPS |
| 568 |
addi a4, a4, -1 |
| 569 |
bnez a4, .Lloop |
| 570 |
#endif /* !XCHAL_HAVE_LOOPS */ |
| 571 |
.Lloopend: |
| 572 |
|
| 573 |
bltu a6, a3, .Lreturn |
| 574 |
addi a2, a2, 1 /* increment quotient if dividend >= divisor */ |
| 575 |
.Lreturn: |
| 576 |
leaf_return |
| 577 |
|
| 578 |
.Lle_one: |
| 579 |
beqz a3, .Lerror /* if divisor == 1, return the dividend */ |
| 580 |
leaf_return |
| 581 |
|
| 582 |
.Lspecial: |
| 583 |
/* return dividend >= divisor */ |
| 584 |
bltu a6, a3, .Lreturn0 |
| 585 |
movi a2, 1 |
| 586 |
leaf_return |
| 587 |
|
| 588 |
.Lerror: |
| 589 |
/* Divide by zero: Use an illegal instruction to force an exception. |
| 590 |
The subsequent "DIV0" string can be recognized by the exception |
| 591 |
handler to identify the real cause of the exception. */ |
| 592 |
ill |
| 593 |
.ascii "DIV0" |
| 594 |
|
| 595 |
.Lreturn0: |
| 596 |
movi a2, 0 |
| 597 |
#endif /* XCHAL_HAVE_DIV32 */ |
| 598 |
leaf_return |
| 599 |
.size __udivsi3, . - __udivsi3 |
| 600 |
|
| 601 |
#endif /* L_udivsi3 */ |
| 602 |
|
| 603 |
|
| 604 |
#ifdef L_divsi3 |
| 605 |
.align 4 |
| 606 |
.global __divsi3 |
| 607 |
.type __divsi3, @function |
| 608 |
__divsi3: |
| 609 |
leaf_entry sp, 16 |
| 610 |
#if XCHAL_HAVE_DIV32 |
| 611 |
quos a2, a2, a3 |
| 612 |
#else |
| 613 |
xor a7, a2, a3 /* sign = dividend ^ divisor */ |
| 614 |
do_abs a6, a2, a4 /* udividend = abs (dividend) */ |
| 615 |
do_abs a3, a3, a4 /* udivisor = abs (divisor) */ |
| 616 |
bltui a3, 2, .Lle_one /* check if udivisor <= 1 */ |
| 617 |
do_nsau a5, a6, a2, a8 /* udividend_shift = nsau (udividend) */ |
| 618 |
do_nsau a4, a3, a2, a8 /* udivisor_shift = nsau (udivisor) */ |
| 619 |
bgeu a5, a4, .Lspecial |
| 620 |
|
| 621 |
sub a4, a4, a5 /* count = udivisor_shift - udividend_shift */ |
| 622 |
ssl a4 |
| 623 |
sll a3, a3 /* udivisor <<= count */ |
| 624 |
movi a2, 0 /* quotient = 0 */ |
| 625 |
|
| 626 |
/* test-subtract-and-shift loop; one quotient bit on each iteration */ |
| 627 |
#if XCHAL_HAVE_LOOPS |
| 628 |
loopnez a4, .Lloopend |
| 629 |
#endif /* XCHAL_HAVE_LOOPS */ |
| 630 |
.Lloop: |
| 631 |
bltu a6, a3, .Lzerobit |
| 632 |
sub a6, a6, a3 |
| 633 |
addi a2, a2, 1 |
| 634 |
.Lzerobit: |
| 635 |
slli a2, a2, 1 |
| 636 |
srli a3, a3, 1 |
| 637 |
#if !XCHAL_HAVE_LOOPS |
| 638 |
addi a4, a4, -1 |
| 639 |
bnez a4, .Lloop |
| 640 |
#endif /* !XCHAL_HAVE_LOOPS */ |
| 641 |
.Lloopend: |
| 642 |
|
| 643 |
bltu a6, a3, .Lreturn |
| 644 |
addi a2, a2, 1 /* increment if udividend >= udivisor */ |
| 645 |
.Lreturn: |
| 646 |
neg a5, a2 |
| 647 |
movltz a2, a5, a7 /* return (sign < 0) ? -quotient : quotient */ |
| 648 |
leaf_return |
| 649 |
|
| 650 |
.Lle_one: |
| 651 |
beqz a3, .Lerror |
| 652 |
neg a2, a6 /* if udivisor == 1, then return... */ |
| 653 |
movgez a2, a6, a7 /* (sign < 0) ? -udividend : udividend */ |
| 654 |
leaf_return |
| 655 |
|
| 656 |
.Lspecial: |
| 657 |
bltu a6, a3, .Lreturn0 /* if dividend < divisor, return 0 */ |
| 658 |
movi a2, 1 |
| 659 |
movi a4, -1 |
| 660 |
movltz a2, a4, a7 /* else return (sign < 0) ? -1 : 1 */ |
| 661 |
leaf_return |
| 662 |
|
| 663 |
.Lerror: |
| 664 |
/* Divide by zero: Use an illegal instruction to force an exception. |
| 665 |
The subsequent "DIV0" string can be recognized by the exception |
| 666 |
handler to identify the real cause of the exception. */ |
| 667 |
ill |
| 668 |
.ascii "DIV0" |
| 669 |
|
| 670 |
.Lreturn0: |
| 671 |
movi a2, 0 |
| 672 |
#endif /* XCHAL_HAVE_DIV32 */ |
| 673 |
leaf_return |
| 674 |
.size __divsi3, . - __divsi3 |
| 675 |
|
| 676 |
#endif /* L_divsi3 */ |
| 677 |
|
| 678 |
|
| 679 |
#ifdef L_umodsi3 |
| 680 |
.align 4 |
| 681 |
.global __umodsi3 |
| 682 |
.type __umodsi3, @function |
| 683 |
__umodsi3: |
| 684 |
leaf_entry sp, 16 |
| 685 |
#if XCHAL_HAVE_DIV32 |
| 686 |
remu a2, a2, a3 |
| 687 |
#else |
| 688 |
bltui a3, 2, .Lle_one /* check if the divisor is <= 1 */ |
| 689 |
|
| 690 |
do_nsau a5, a2, a6, a7 /* dividend_shift = nsau (dividend) */ |
| 691 |
do_nsau a4, a3, a6, a7 /* divisor_shift = nsau (divisor) */ |
| 692 |
bgeu a5, a4, .Lspecial |
| 693 |
|
| 694 |
sub a4, a4, a5 /* count = divisor_shift - dividend_shift */ |
| 695 |
ssl a4 |
| 696 |
sll a3, a3 /* divisor <<= count */ |
| 697 |
|
| 698 |
/* test-subtract-and-shift loop */ |
| 699 |
#if XCHAL_HAVE_LOOPS |
| 700 |
loopnez a4, .Lloopend |
| 701 |
#endif /* XCHAL_HAVE_LOOPS */ |
| 702 |
.Lloop: |
| 703 |
bltu a2, a3, .Lzerobit |
| 704 |
sub a2, a2, a3 |
| 705 |
.Lzerobit: |
| 706 |
srli a3, a3, 1 |
| 707 |
#if !XCHAL_HAVE_LOOPS |
| 708 |
addi a4, a4, -1 |
| 709 |
bnez a4, .Lloop |
| 710 |
#endif /* !XCHAL_HAVE_LOOPS */ |
| 711 |
.Lloopend: |
| 712 |
|
| 713 |
.Lspecial: |
| 714 |
bltu a2, a3, .Lreturn |
| 715 |
sub a2, a2, a3 /* subtract once more if dividend >= divisor */ |
| 716 |
.Lreturn: |
| 717 |
leaf_return |
| 718 |
|
| 719 |
.Lle_one: |
| 720 |
bnez a3, .Lreturn0 |
| 721 |
|
| 722 |
/* Divide by zero: Use an illegal instruction to force an exception. |
| 723 |
The subsequent "DIV0" string can be recognized by the exception |
| 724 |
handler to identify the real cause of the exception. */ |
| 725 |
ill |
| 726 |
.ascii "DIV0" |
| 727 |
|
| 728 |
.Lreturn0: |
| 729 |
movi a2, 0 |
| 730 |
#endif /* XCHAL_HAVE_DIV32 */ |
| 731 |
leaf_return |
| 732 |
.size __umodsi3, . - __umodsi3 |
| 733 |
|
| 734 |
#endif /* L_umodsi3 */ |
| 735 |
|
| 736 |
|
| 737 |
#ifdef L_modsi3 |
| 738 |
.align 4 |
| 739 |
.global __modsi3 |
| 740 |
.type __modsi3, @function |
| 741 |
__modsi3: |
| 742 |
leaf_entry sp, 16 |
| 743 |
#if XCHAL_HAVE_DIV32 |
| 744 |
rems a2, a2, a3 |
| 745 |
#else |
| 746 |
mov a7, a2 /* save original (signed) dividend */ |
| 747 |
do_abs a2, a2, a4 /* udividend = abs (dividend) */ |
| 748 |
do_abs a3, a3, a4 /* udivisor = abs (divisor) */ |
| 749 |
bltui a3, 2, .Lle_one /* check if udivisor <= 1 */ |
| 750 |
do_nsau a5, a2, a6, a8 /* udividend_shift = nsau (udividend) */ |
| 751 |
do_nsau a4, a3, a6, a8 /* udivisor_shift = nsau (udivisor) */ |
| 752 |
bgeu a5, a4, .Lspecial |
| 753 |
|
| 754 |
sub a4, a4, a5 /* count = udivisor_shift - udividend_shift */ |
| 755 |
ssl a4 |
| 756 |
sll a3, a3 /* udivisor <<= count */ |
| 757 |
|
| 758 |
/* test-subtract-and-shift loop */ |
| 759 |
#if XCHAL_HAVE_LOOPS |
| 760 |
loopnez a4, .Lloopend |
| 761 |
#endif /* XCHAL_HAVE_LOOPS */ |
| 762 |
.Lloop: |
| 763 |
bltu a2, a3, .Lzerobit |
| 764 |
sub a2, a2, a3 |
| 765 |
.Lzerobit: |
| 766 |
srli a3, a3, 1 |
| 767 |
#if !XCHAL_HAVE_LOOPS |
| 768 |
addi a4, a4, -1 |
| 769 |
bnez a4, .Lloop |
| 770 |
#endif /* !XCHAL_HAVE_LOOPS */ |
| 771 |
.Lloopend: |
| 772 |
|
| 773 |
.Lspecial: |
| 774 |
bltu a2, a3, .Lreturn |
| 775 |
sub a2, a2, a3 /* subtract again if udividend >= udivisor */ |
| 776 |
.Lreturn: |
| 777 |
bgez a7, .Lpositive |
| 778 |
neg a2, a2 /* if (dividend < 0), return -udividend */ |
| 779 |
.Lpositive: |
| 780 |
leaf_return |
| 781 |
|
| 782 |
.Lle_one: |
| 783 |
bnez a3, .Lreturn0 |
| 784 |
|
| 785 |
/* Divide by zero: Use an illegal instruction to force an exception. |
| 786 |
The subsequent "DIV0" string can be recognized by the exception |
| 787 |
handler to identify the real cause of the exception. */ |
| 788 |
ill |
| 789 |
.ascii "DIV0" |
| 790 |
|
| 791 |
.Lreturn0: |
| 792 |
movi a2, 0 |
| 793 |
#endif /* XCHAL_HAVE_DIV32 */ |
| 794 |
leaf_return |
| 795 |
.size __modsi3, . - __modsi3 |
| 796 |
|
| 797 |
#endif /* L_modsi3 */ |
| 798 |
|
| 799 |
|
| 800 |
#ifdef __XTENSA_EB__ |
| 801 |
#define uh a2 |
| 802 |
#define ul a3 |
| 803 |
#else |
| 804 |
#define uh a3 |
| 805 |
#define ul a2 |
| 806 |
#endif /* __XTENSA_EB__ */ |
| 807 |
|
| 808 |
|
| 809 |
#ifdef L_ashldi3 |
| 810 |
.align 4 |
| 811 |
.global __ashldi3 |
| 812 |
.type __ashldi3, @function |
| 813 |
__ashldi3: |
| 814 |
leaf_entry sp, 16 |
| 815 |
ssl a4 |
| 816 |
bgei a4, 32, .Llow_only |
| 817 |
src uh, uh, ul |
| 818 |
sll ul, ul |
| 819 |
leaf_return |
| 820 |
|
| 821 |
.Llow_only: |
| 822 |
sll uh, ul |
| 823 |
movi ul, 0 |
| 824 |
leaf_return |
| 825 |
.size __ashldi3, . - __ashldi3 |
| 826 |
|
| 827 |
#endif /* L_ashldi3 */ |
| 828 |
|
| 829 |
|
| 830 |
#ifdef L_ashrdi3 |
| 831 |
.align 4 |
| 832 |
.global __ashrdi3 |
| 833 |
.type __ashrdi3, @function |
| 834 |
__ashrdi3: |
| 835 |
leaf_entry sp, 16 |
| 836 |
ssr a4 |
| 837 |
bgei a4, 32, .Lhigh_only |
| 838 |
src ul, uh, ul |
| 839 |
sra uh, uh |
| 840 |
leaf_return |
| 841 |
|
| 842 |
.Lhigh_only: |
| 843 |
sra ul, uh |
| 844 |
srai uh, uh, 31 |
| 845 |
leaf_return |
| 846 |
.size __ashrdi3, . - __ashrdi3 |
| 847 |
|
| 848 |
#endif /* L_ashrdi3 */ |
| 849 |
|
| 850 |
|
| 851 |
#ifdef L_lshrdi3 |
| 852 |
.align 4 |
| 853 |
.global __lshrdi3 |
| 854 |
.type __lshrdi3, @function |
| 855 |
__lshrdi3: |
| 856 |
leaf_entry sp, 16 |
| 857 |
ssr a4 |
| 858 |
bgei a4, 32, .Lhigh_only1 |
| 859 |
src ul, uh, ul |
| 860 |
srl uh, uh |
| 861 |
leaf_return |
| 862 |
|
| 863 |
.Lhigh_only1: |
| 864 |
srl ul, uh |
| 865 |
movi uh, 0 |
| 866 |
leaf_return |
| 867 |
.size __lshrdi3, . - __lshrdi3 |
| 868 |
|
| 869 |
#endif /* L_lshrdi3 */ |
| 870 |
|
| 871 |
|
| 872 |
#ifdef L_bswapsi2 |
| 873 |
.align 4 |
| 874 |
.global __bswapsi2 |
| 875 |
.type __bswapsi2, @function |
| 876 |
__bswapsi2: |
| 877 |
leaf_entry sp, 16 |
| 878 |
ssai 8 |
| 879 |
srli a3, a2, 16 |
| 880 |
src a3, a3, a2 |
| 881 |
src a3, a3, a3 |
| 882 |
src a2, a2, a3 |
| 883 |
leaf_return |
| 884 |
.size __bswapsi2, . - __bswapsi2 |
| 885 |
|
| 886 |
#endif /* L_bswapsi2 */ |
| 887 |
|
| 888 |
|
| 889 |
#ifdef L_bswapdi2 |
| 890 |
.align 4 |
| 891 |
.global __bswapdi2 |
| 892 |
.type __bswapdi2, @function |
| 893 |
__bswapdi2: |
| 894 |
leaf_entry sp, 16 |
| 895 |
ssai 8 |
| 896 |
srli a4, a2, 16 |
| 897 |
src a4, a4, a2 |
| 898 |
src a4, a4, a4 |
| 899 |
src a4, a2, a4 |
| 900 |
srli a2, a3, 16 |
| 901 |
src a2, a2, a3 |
| 902 |
src a2, a2, a2 |
| 903 |
src a2, a3, a2 |
| 904 |
mov a3, a4 |
| 905 |
leaf_return |
| 906 |
.size __bswapdi2, . - __bswapdi2 |
| 907 |
|
| 908 |
#endif /* L_bswapdi2 */ |
| 909 |
|
| 910 |
|
| 911 |
#include "ieee754-df.S" |
| 912 |
#include "ieee754-sf.S" |