aboutsummaryrefslogtreecommitdiffstats
path: root/src/arch/riscv32/libgcc/llshift.S
blob: 8ad6a6daac3c1791cfda037fc79856a84cae764e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * Copyright (C) 2024 Michael Brown <mbrown@fensystems.co.uk>.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 *
 * You can also choose to distribute this program under the terms of
 * the Unmodified Binary Distribution Licence (as given in the file
 * COPYING.UBDL), provided that you have satisfied its requirements.
 */

	FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

/** @file
 *
 * Long shifts
 *
 */

	.section ".note.GNU-stack", "", @progbits
	.text

/**
 * Shift left
 *
 * @v a1:a0		Value to shift
 * @v a2		Shift amount
 * @ret a1:a0		Shifted value
 */
	.section ".text.__ashldi3", "ax", @progbits
	.globl	__ashldi3
__ashldi3:
	/* Perform shift by 32 bits, if applicable */
	li	t0, 32
	sub	t1, t0, a2
	bgtz	t1, 1f
	mv	a1, a0
	mv	a0, zero
1:	/* Perform shift by modulo-32 bits, if applicable */
	andi	a2, a2, 0x1f
	beqz	a2, 2f
	srl	t2, a0, t1
	sll	a0, a0, a2
	sll	a1, a1, a2
	or	a1, a1, t2
2:	ret
	.size	__ashldi3, . - __ashldi3

/**
 * Logical shift right
 *
 * @v a1:a0		Value to shift
 * @v a2		Shift amount
 * @ret a1:a0		Shifted value
 */
	.section ".text.__lshrdi3", "ax", @progbits
	.globl	__lshrdi3
__lshrdi3:
	/* Perform shift by 32 bits, if applicable */
	li	t0, 32
	sub	t1, t0, a2
	bgtz	t1, 1f
	mv	a0, a1
	mv	a1, zero
1:	/* Perform shift by modulo-32 bits, if applicable */
	andi	a2, a2, 0x1f
	beqz	a2, 2f
	sll	t2, a1, t1
	srl	a1, a1, a2
	srl	a0, a0, a2
	or	a0, a0, t2
2:	ret
	.size	__lshrdi3, . - __lshrdi3

/**
 * Arithmetic shift right
 *
 * @v a1:a0		Value to shift
 * @v a2		Shift amount
 * @ret a1:a0		Shifted value
 */
	.section ".text.__ashrdi3", "ax", @progbits
	.globl	__ashrdi3
__ashrdi3:
	/* Perform shift by 32 bits, if applicable */
	li	t0, 32
	sub	t1, t0, a2
	bgtz	t1, 1f
	mv	a0, a1
	srai	a1, a1, 16
	srai	a1, a1, 16
1:	/* Perform shift by modulo-32 bits, if applicable */
	andi	a2, a2, 0x1f
	beqz	a2, 2f
	sll	t2, a1, t1
	sra	a1, a1, a2
	srl	a0, a0, a2
	or	a0, a0, t2
2:	ret
	.size	__ashrdi3, . - __ashrdi3