1/*
2 * Copyright (c) 2022 ITE Corporation.
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * When the 'M' extension is disabled, compiler can not recognize div/mul
6 * instructions. So mul/div instructions in the below integer arithmetic
7 * routines are hard coded by opcodes.
8 *
9 * IMPORTANT:
10 * The workaround requires the nop instruction, please don't optimize it.
11 */
12
13#ifdef CONFIG_SOC_IT8XXX2_USE_ILM
14#define SECTION .__ram_code.arithmetic.
15#else
16#define SECTION .text.it8xxx2.arithmetic.
17#endif
18
19.macro __int_arithmetic func opcode
20.section SECTION\func
21.align 2
22.globl \func
23.type \func, @function
24\func:
25.word \opcode
26nop
27ret
28.size \func, .-\func
29.endm
30
31/* signed 32 bit multiplication. opcode of mul a0,a0,a1 is 0x02b50533 */
32__int_arithmetic __mulsi3 0x02b50533
33
34/* signed 32 bit division. opcode of div a0,a0,a1 is 0x02b54533 */
35__int_arithmetic __divsi3 0x02b54533
36
37/* unsigned 32 bit division. opcode of divu a0,a0,a1 is 0x02b55533 */
38__int_arithmetic __udivsi3 0x02b55533
39
40/*
41 * This function return the remainder of the signed division.
42 * opcode of rem a0,a0,a1 is 0x02b56533
43 */
44__int_arithmetic __modsi3 0x02b56533
45
46/*
47 * This function return the remainder of the unsigned division.
48 * opcode of remu a0,a0,a1 is 0x02b57533
49 */
50__int_arithmetic __umodsi3 0x02b57533
51