move asm to inline asm (consolidate gcc functions)

This commit is contained in:
fig02
2022-02-12 00:00:41 -05:00
parent cbddf7146d
commit 82ba5da981
13 changed files with 153 additions and 150 deletions
+119 -12
View File
@@ -1,12 +1,14 @@
#ifdef __GNUC__
#include "global.h"
// Define functions needed for the GCC build here.
// Self-hosted memcmp.
int memcmp(void *s1, const void *s2, size_t n) {
u8 *m1 = (u8 *)s1;
u8 *m2 = (u8 *)s2;
int i;
int memcmp(void* s1, const void* s2, size_t n) {
u8* m1 = (u8*)s1;
u8* m2 = (u8*)s2;
u32 i;
for (i = 0; i < n; i++) {
if (m1[i] < m2[i]) {
return -1;
@@ -17,10 +19,10 @@ int memcmp(void *s1, const void *s2, size_t n) {
return 0;
}
void *memset(void *str, int c, size_t n) {
u8 *m1 = (u8 *)str;
int i;
for(i = 0; i < n; i++) {
void* memset(void* str, s32 c, size_t n) {
u8* m1 = (u8*)str;
u32 i;
for (i = 0; i < n; i++) {
m1[i] = c;
}
return str;
@@ -29,14 +31,16 @@ void *memset(void *str, int c, size_t n) {
// These functions convert c to an unsigned integer, rounding toward zero. Negative values
// all become zero.
u32 __fixunssfdi(f32 a) {
if (a < 0.0f)
if (a < 0.0f) {
a = 0.0f;
}
return (u32)a;
}
u32 __fixunsdfdi(f64 a) {
if (a < 0.0)
if (a < 0.0) {
a = 0.0;
}
return (u32)a;
}
@@ -60,7 +64,7 @@ f64 __floatdidf(s32 c) {
// These functions convert c, an unsigned integer, to floating point.
f32 __floatundisf(u32 c) {
return (f32)c;
return (f32)c;
}
f64 __floatundidf(u32 c) {
@@ -84,5 +88,108 @@ f32 __powisf2(f32 a, s32 b) {
a *= a;
}
return recip ? 1/r : r;
return recip ? 1 / r : r;
}
unsigned long __umoddi3(unsigned long a, unsigned long b) {
__asm__(".set push;"
".set noat;"
".set noreorder;"
".set gp=64;"
"sw $a0, ($sp);"
"sw $a1, 4($sp);"
"sw $a2, 8($sp);"
"sw $a3, 0xc($sp);"
"ld $t7, 8($sp);"
"ld $t6, ($sp);"
"ddivu $zero, $t6, $t7;"
"bnez $t7, .L80324144;"
" nop;"
"break 7;"
".L80324144:"
"mfhi $v0;"
"dsll32 $v1, $v0, 0;"
"dsra32 $v1, $v1, 0;"
"dsra32 $v0, $v0, 0;"
".set pop;");
}
unsigned long __udivdi3(unsigned long a, unsigned long b) {
__asm__(".set push;"
".set noat;"
".set noreorder;"
".set gp=64;"
"sw $a0, ($sp);"
"sw $a1, 4($sp);"
"sw $a2, 8($sp);"
"sw $a3, 0xc($sp);"
"ld $t7, 8($sp);"
"ld $t6, ($sp);"
"ddivu $zero, $t6, $t7;"
"bnez $t7, .L80324180;"
" nop;"
"break 7;"
".L80324180:"
"mflo $v0;"
"dsll32 $v1, $v0, 0;"
"dsra32 $v1, $v1, 0;"
" dsra32 $v0, $v0, 0;"
".set pop;");
}
long __moddi3(long a, long b) {
__asm__(".set push;"
".set noat;"
".set noreorder;"
".set gp=64;"
"sw $a0, ($sp);"
"sw $a1, 4($sp);"
"sw $a2, 8($sp);"
"sw $a3, 0xc($sp);"
"ld $t7, 8($sp);"
"ld $t6, ($sp);"
"ddivu $zero, $t6, $t7;"
"bnez $t7, .L803241E8;"
" nop;"
"break 7;"
".L803241E8:"
"mfhi $v0;"
"dsll32 $v1, $v0, 0;"
"dsra32 $v1, $v1, 0;"
" dsra32 $v0, $v0, 0;"
".set pop;");
}
long __divdi3(long a, long b) {
__asm__(".set push;"
".set noat;"
".set noreorder;"
".set gp=64;"
"sw $a0, ($sp);"
"sw $a1, 4($sp);"
"sw $a2, 8($sp);"
"sw $a3, 0xc($sp);"
"ld $t7, 8($sp);"
"ld $t6, ($sp);"
"ddiv $zero, $t6, $t7;"
"nop;"
"bnez $t7, .L80324228;"
" nop;"
"break 7;"
".L80324228:"
"daddiu $at, $zero, -1;"
"bne $t7, $at, .L80324244;"
" daddiu $at, $zero, 1;"
"dsll32 $at, $at, 0x1f;"
"bne $t6, $at, .L80324244;"
" nop;"
"break 6;"
".L80324244:"
"mflo $v0;"
"dsll32 $v1, $v0, 0;"
"dsra32 $v1, $v1, 0;"
" dsra32 $v0, $v0, 0;"
".set pop;");
}
#endif