Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MorsGames
GitHub Repository: MorsGames/sm64plus
Path: blob/master/lib/asm/llmuldiv_gcc.s
7858 views
1
// assembler directives
2
.set noat // allow manual use of $at
3
.set noreorder // don't insert nops after branches
4
.set gp=64
5
6
#include "macros.inc"
7
8
9
.section .text, "ax"
10
11
/* -------------------------------------------------------------------------------------- */
12
/* need to asm these functions because lib32gcc-7-dev-mips-cross does not exist so we */
13
/* cannot naturally link a libgcc variant for this target given this architecture and */
14
/* compiler. Until we have a good workaround with a gcc target that doesn't involve */
15
/* assuming a 32-bit to 64-bit change, we have to encode these functions as raw assembly */
16
/* for it to compile. */
17
/* -------------------------------------------------------------------------------------- */
18
19
/* TODO: Is there a non-insane way to fix this hack that doesn't involve the user compiling */
20
/* a library themselves? */
21
glabel __umoddi3
22
sw $a0, ($sp)
23
sw $a1, 4($sp)
24
sw $a2, 8($sp)
25
sw $a3, 0xc($sp)
26
ld $t7, 8($sp)
27
ld $t6, ($sp)
28
ddivu $zero, $t6, $t7
29
bnez $t7, .L80324144
30
nop
31
break 7
32
.L80324144:
33
mfhi $v0
34
dsll32 $v1, $v0, 0
35
dsra32 $v1, $v1, 0
36
jr $ra
37
dsra32 $v0, $v0, 0
38
39
glabel __udivdi3
40
sw $a0, ($sp)
41
sw $a1, 4($sp)
42
sw $a2, 8($sp)
43
sw $a3, 0xc($sp)
44
ld $t7, 8($sp)
45
ld $t6, ($sp)
46
ddivu $zero, $t6, $t7
47
bnez $t7, .L80324180
48
nop
49
break 7
50
.L80324180:
51
mflo $v0
52
dsll32 $v1, $v0, 0
53
dsra32 $v1, $v1, 0
54
jr $ra
55
dsra32 $v0, $v0, 0
56
57
glabel __moddi3
58
sw $a0, ($sp)
59
sw $a1, 4($sp)
60
sw $a2, 8($sp)
61
sw $a3, 0xc($sp)
62
ld $t7, 8($sp)
63
ld $t6, ($sp)
64
ddivu $zero, $t6, $t7
65
bnez $t7, .L803241E8
66
nop
67
break 7
68
.L803241E8:
69
mfhi $v0
70
dsll32 $v1, $v0, 0
71
dsra32 $v1, $v1, 0
72
jr $ra
73
dsra32 $v0, $v0, 0
74
75
glabel __divdi3
76
sw $a0, ($sp)
77
sw $a1, 4($sp)
78
sw $a2, 8($sp)
79
sw $a3, 0xc($sp)
80
ld $t7, 8($sp)
81
ld $t6, ($sp)
82
ddiv $zero, $t6, $t7
83
nop
84
bnez $t7, .L80324228
85
nop
86
break 7
87
.L80324228:
88
daddiu $at, $zero, -1
89
bne $t7, $at, .L80324244
90
daddiu $at, $zero, 1
91
dsll32 $at, $at, 0x1f
92
bne $t6, $at, .L80324244
93
nop
94
break 6
95
.L80324244:
96
mflo $v0
97
dsll32 $v1, $v0, 0
98
dsra32 $v1, $v1, 0
99
jr $ra
100
dsra32 $v0, $v0, 0
101
102