-
Notifications
You must be signed in to change notification settings - Fork 14
/
sh2_fixed.s
68 lines (59 loc) · 2.41 KB
/
sh2_fixed.s
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
! The MIT License (MIT)
!
! Permission is hereby granted, free of charge, to any person obtaining a copy
! of this software and associated documentation files (the "Software"), to deal
! in the Software without restriction, including without limitation the rights
! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
! copies of the Software, and to permit persons to whom the Software is
! furnished to do so, subject to the following conditions:
!
! The above copyright notice and this permission notice shall be included in all
! copies or substantial portions of the Software.
!
! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
! SOFTWARE.
.section .sdata
! #define FixedMul(a,b) (((int64_t)(a) * (b))>>16)
! Perform a signed 16.16 by 16.16 multiply ! On entry: r4 = a, r5 = b ! On exit: r0 = (a * b) >> 16
.align 4
.global _FixedMul2
_FixedMul2:
dmuls.l r4,r5
sts mach,r1
sts macl,r0
rts
xtrct r1,r0
! Perform a signed 16.16 by 16.16 divide ! On entry: r4 = a, r5 = b ! On exit: r0 = (a << 16) / b
.align 4
.global _FixedDiv
_FixedDiv:
mov.l _sh2_div_unit,r2
swap.w r4,r0
mov.l r5,@r2 /* set 32-bit divisor */
exts.w r0, r0
mov.l r0,@(16,r2) /* set high long of 64-bit dividend */
shll16 r4
mov.l r4,@(20,r2) /* set low long of 64-bit dividend, start divide */
/* note - overflow returns 0x7FFFFFFF or 0x80000000 after 6 cycles
no overflow returns the quotient after 39 cycles */
rts
mov.l @(20,r2),r0 /* return 32-bit quotient */
! Perform a signed 32 by 32 divide ! On entry: r4 = a, r5 = b ! On exit: r0 = a / b
.align 4
.global _IDiv
_IDiv:
mov.l _sh2_div_unit,r2
mov.l r5,@r2 /* set 32-bit divisor */
mov.l r4,@(4,r2) /* set 32-bit dividend, start divide */
/* note - overflow returns 0x7FFFFFFF or 0x80000000 after 6 cycles
no overflow returns the quotient after 39 cycles */
rts
mov.l @(4,r2),r0 /* return 32-bit quotient */
.align 2
_sh2_div_unit:
.long 0xFFFFFF00