1 /****************************************************************************
2 * Copyright © 2022 Rémi Denis-Courmont.
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
19 *****************************************************************************/
21 #include "libavutil/riscv/asm.S"
23 #if (__riscv_xlen == 64)
26 .asciz "callee-saved integer register clobbered"
30 .asciz "callee-saved floating-point register clobbered"
34 .asciz "unallocatable register clobbered"
46 /* Space to spill RA, SP, GP, TP, S0-S11 and FS0-FS11 */
51 func checkasm_set_function
52 la.tls.ie t0, checked_func
58 func checkasm_get_wrapper, v
65 andi t0, a0, 8 /* AV_CPU_FLAG_RVV_I32 */
76 2: /* <-- Entry point with the Vector extension --> */
77 /* Clobber the vectors */
78 vsetvli t0, zero, e32, m8, ta, ma
85 /* Clobber the vector configuration */
86 li t0, 0 /* Vector length: zero */
87 li t1, -1 << 31 /* Vector type: illegal */
89 csrwi vxrm, 3 /* Rounding mode: round-to-odd */
90 csrwi vxsat, 1 /* Saturation: encountered */
92 3: /* <-- Entry point without the Vector extension --> */
93 /* Save RA, unallocatable and callee-saved registers */
94 la.tls.ie t0, saved_regs
100 .irp n, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
101 sd s\n, (32 + (16 * \n))(t0)
102 fsd fs\n, (40 + (16 * \n))(t0)
105 /* Clobber the stack space right below SP */
106 li t0, 0xdeadbeef1badf00d
114 /* Clobber the saved and temporary registers */
115 .irp n, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
116 .if (\n > 0 && \n < 7)
124 /* Call the tested function */
125 la.tls.ie t0, checked_func
131 /* Check special register values */
132 la.tls.ie t0, saved_regs
138 ld t1, 24(t0) // If TP was corrupted, we probably will have...
139 bne t1, tp, 5f // ...already crashed before we even get here.
141 /* Check value of saved registers */
142 li t0, 0xdeadbeef1badf00d
143 .irp n, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
145 #ifdef __riscv_float_abi_double
146 /* TODO: check float ABI single too */
153 /* Restore RA and saved registers */
154 la.tls.ie t0, saved_regs
157 .irp n, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
158 ld s\n, (32 + (16 * \n))(t0)
159 fld fs\n, (40 + (16 * \n))(t0)
164 lla a0, fail_rsvd_reg
165 call checkasm_fail_func
166 tail abort /* The test harness would probably crash anyway */
170 call checkasm_fail_func
175 call checkasm_fail_func