Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Madghostek committed May 31, 2021
2 parents 917b9e9 + cd0ebc8 commit 763c9a7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 69 deletions.
20 changes: 10 additions & 10 deletions r4300/cop1_d.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void ROUND_L_D()
CHECK_INPUT(*reg_cop1_double[cffs]);
set_round_to_nearest();
clear_x87_exceptions();
*((long long*)(reg_cop1_double[cffd])) = *reg_cop1_double[cffs];
FLOAT_CONVERT_L_D(reg_cop1_double[cffs], reg_cop1_double[cffd]);
set_rounding();
PC++;
}
Expand All @@ -131,7 +131,7 @@ void TRUNC_L_D()
CHECK_INPUT(*reg_cop1_double[cffs]);
set_trunc();
clear_x87_exceptions();
*((long long*)(reg_cop1_double[cffd])) = *reg_cop1_double[cffs];
FLOAT_CONVERT_L_D(reg_cop1_double[cffs], reg_cop1_double[cffd]);
set_rounding();
PC++;
}
Expand All @@ -142,7 +142,7 @@ void CEIL_L_D()
CHECK_INPUT(*reg_cop1_double[cffs]);
set_ceil();
clear_x87_exceptions();
*((long long*)(reg_cop1_double[cffd])) = *reg_cop1_double[cffs];
FLOAT_CONVERT_L_D(reg_cop1_double[cffs], reg_cop1_double[cffd]);
set_rounding();
PC++;
}
Expand All @@ -153,7 +153,7 @@ void FLOOR_L_D()
CHECK_INPUT(*reg_cop1_double[cffs]);
set_floor();
clear_x87_exceptions();
*((long long*)(reg_cop1_double[cffd])) = *reg_cop1_double[cffs];
FLOAT_CONVERT_L_D(reg_cop1_double[cffs], reg_cop1_double[cffd]);
set_rounding();
PC++;
}
Expand All @@ -164,7 +164,7 @@ void ROUND_W_D()
CHECK_INPUT(*reg_cop1_double[cffs]);
set_round_to_nearest();
clear_x87_exceptions();
*((long*)reg_cop1_simple[cffd]) = *reg_cop1_double[cffs];
FLOAT_CONVERT_W_D(reg_cop1_double[cffs], reg_cop1_simple[cffd]);
set_rounding();
PC++;
}
Expand All @@ -175,7 +175,7 @@ void TRUNC_W_D()
CHECK_INPUT(*reg_cop1_double[cffs]);
set_trunc();
clear_x87_exceptions();
*((long*)reg_cop1_simple[cffd]) = *reg_cop1_double[cffs];
FLOAT_CONVERT_W_D(reg_cop1_double[cffs], reg_cop1_simple[cffd]);
set_rounding();
PC++;
}
Expand All @@ -186,7 +186,7 @@ void CEIL_W_D()
CHECK_INPUT(*reg_cop1_double[cffs]);
set_ceil();
clear_x87_exceptions();
*((long*)reg_cop1_simple[cffd]) = *reg_cop1_double[cffs];
FLOAT_CONVERT_W_D(reg_cop1_double[cffs], reg_cop1_simple[cffd]);
set_rounding();
PC++;
}
Expand All @@ -197,7 +197,7 @@ void FLOOR_W_D()
CHECK_INPUT(*reg_cop1_double[cffs]);
set_floor();
clear_x87_exceptions();
*((long*)reg_cop1_simple[cffd]) = *reg_cop1_double[cffs];
FLOAT_CONVERT_W_D(reg_cop1_double[cffs], reg_cop1_simple[cffd]);
set_rounding();
PC++;
}
Expand All @@ -222,7 +222,7 @@ void CVT_W_D()
if (check_cop1_unusable()) return;
CHECK_INPUT(*reg_cop1_double[cffs]);
clear_x87_exceptions();
*((long*)reg_cop1_simple[cffd]) = *reg_cop1_double[cffs];
FLOAT_CONVERT_W_D(reg_cop1_double[cffs], reg_cop1_simple[cffd]);
PC++;
}

Expand All @@ -231,7 +231,7 @@ void CVT_L_D()
if (check_cop1_unusable()) return;
CHECK_INPUT(*reg_cop1_double[cffs]);
clear_x87_exceptions();
*((long long*)(reg_cop1_double[cffd])) = *reg_cop1_double[cffs];
FLOAT_CONVERT_L_D(reg_cop1_double[cffs], reg_cop1_double[cffd]);
PC++;
}

Expand Down
20 changes: 10 additions & 10 deletions r4300/cop1_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void ROUND_L_S()
CHECK_INPUT(*reg_cop1_simple[cffs]);
set_round_to_nearest();
clear_x87_exceptions();
*((long long*)(reg_cop1_double[cffd])) = *reg_cop1_simple[cffs];
FLOAT_CONVERT_L_S(reg_cop1_simple[cffs], reg_cop1_double[cffd]);
set_rounding();
CHECK_CONVERT_EXCEPTIONS();
PC++;
Expand All @@ -132,7 +132,7 @@ void TRUNC_L_S()
CHECK_INPUT(*reg_cop1_simple[cffs]);
set_trunc();
clear_x87_exceptions();
*((long long*)(reg_cop1_double[cffd])) = *reg_cop1_simple[cffs];
FLOAT_CONVERT_L_S(reg_cop1_simple[cffs], reg_cop1_double[cffd]);
set_rounding();
CHECK_CONVERT_EXCEPTIONS();
PC++;
Expand All @@ -144,7 +144,7 @@ void CEIL_L_S()
CHECK_INPUT(*reg_cop1_simple[cffs]);
set_ceil();
clear_x87_exceptions();
*((long long*)(reg_cop1_double[cffd])) = *reg_cop1_simple[cffs];
FLOAT_CONVERT_L_S(reg_cop1_simple[cffs], reg_cop1_double[cffd]);
set_rounding();
CHECK_CONVERT_EXCEPTIONS();
PC++;
Expand All @@ -156,7 +156,7 @@ void FLOOR_L_S()
CHECK_INPUT(*reg_cop1_simple[cffs]);
set_floor();
clear_x87_exceptions();
*((long long*)(reg_cop1_double[cffd])) = *reg_cop1_simple[cffs];
FLOAT_CONVERT_L_S(reg_cop1_simple[cffs], reg_cop1_double[cffd]);
set_rounding();
CHECK_CONVERT_EXCEPTIONS();
PC++;
Expand All @@ -168,7 +168,7 @@ void ROUND_W_S()
CHECK_INPUT(*reg_cop1_simple[cffs]);
set_round_to_nearest();
clear_x87_exceptions();
*((long*)reg_cop1_simple[cffd]) = *reg_cop1_simple[cffs];
FLOAT_CONVERT_W_S(reg_cop1_simple[cffs], reg_cop1_simple[cffd]);
set_rounding();
CHECK_CONVERT_EXCEPTIONS();
PC++;
Expand All @@ -180,7 +180,7 @@ void TRUNC_W_S()
CHECK_INPUT(*reg_cop1_simple[cffs]);
set_trunc();
clear_x87_exceptions();
*((long*)reg_cop1_simple[cffd]) = *reg_cop1_simple[cffs];
FLOAT_CONVERT_W_S(reg_cop1_simple[cffs], reg_cop1_simple[cffd]);
set_rounding();
CHECK_CONVERT_EXCEPTIONS();
PC++;
Expand All @@ -192,7 +192,7 @@ void CEIL_W_S()
CHECK_INPUT(*reg_cop1_simple[cffs]);
set_ceil();
clear_x87_exceptions();
*((long*)reg_cop1_simple[cffd]) = *reg_cop1_simple[cffs];
FLOAT_CONVERT_W_S(reg_cop1_simple[cffs], reg_cop1_simple[cffd]);
set_rounding();
CHECK_CONVERT_EXCEPTIONS();
PC++;
Expand All @@ -204,7 +204,7 @@ void FLOOR_W_S()
CHECK_INPUT(*reg_cop1_simple[cffs]);
set_floor();
clear_x87_exceptions();
*((long*)reg_cop1_simple[cffd]) = *reg_cop1_simple[cffs];
FLOAT_CONVERT_W_S(reg_cop1_simple[cffs], reg_cop1_simple[cffd]);
set_rounding();
CHECK_CONVERT_EXCEPTIONS();
PC++;
Expand All @@ -223,7 +223,7 @@ void CVT_W_S()
if (check_cop1_unusable()) return;
CHECK_INPUT(*reg_cop1_simple[cffs]);
clear_x87_exceptions();
*((long*)reg_cop1_simple[cffd]) = *reg_cop1_simple[cffs];
FLOAT_CONVERT_W_S(reg_cop1_simple[cffs], reg_cop1_simple[cffd]);
CHECK_CONVERT_EXCEPTIONS();
PC++;
}
Expand All @@ -233,7 +233,7 @@ void CVT_L_S()
if (check_cop1_unusable()) return;
CHECK_INPUT(*reg_cop1_simple[cffs]);
clear_x87_exceptions();
*((long long*)(reg_cop1_double[cffd])) = *reg_cop1_simple[cffs];
FLOAT_CONVERT_L_S(reg_cop1_simple[cffs], reg_cop1_double[cffd]);
CHECK_CONVERT_EXCEPTIONS();
PC++;
}
Expand Down
27 changes: 14 additions & 13 deletions r4300/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ stop=1; \
#define read_x87_status_word() __asm { fstsw x87_status_word }

//asm converter that respects rounding modes
#define FLOAT_CONVERT(input_width, output_width) __asm {mov eax, src __asm fld input_width ptr [eax] __asm mov ebx, dest __asm fistp output_width ptr[ebx]}
#define FLOAT_CONVERT(input_width, output_width) __asm { \
__asm mov eax, src \
__asm fld input_width ptr [eax] \
__asm mov eax, dest \
__asm fistp output_width ptr [eax] \
}
#else
#define set_rounding() __asm__ __volatile__("fldcw %0" : : "m" (rounding_mode) : "memory")
#define set_trunc() __asm__ __volatile__("fldcw %0" : : "m" (trunc_mode) : "memory")
Expand All @@ -127,8 +132,12 @@ stop=1; \
#define clear_x87_exceptions() __asm__ __volatile__("fclex" : : : "memory")
#define read_x87_status_word() __asm__ __volatile__("fstsw %0" : "=m" (x87_status_word) : : "memory")

//gcc version
#define FLOAT_CONVERT(input_width, output_width) __asm__ __volatile__(???)
#define FLOAT_CONVERT(input_width, output_width) __asm__ __volatile__( \
".intel_syntax\n\t" \
"fld " #input_width " ptr [%V0]\n\t" \
"fistp " #output_width " ptr [%V1]\n\t" \
".att_syntax" \
: : "r" (src), "r" (dest) : "memory")
#endif // _MSC_VER
#else
#define set_rounding() ((void) 0)
Expand All @@ -137,20 +146,12 @@ stop=1; \
#define set_ceil() ((void) 0)
#define set_floor() ((void) 0)
#define clear_x87_exceptions() ((void) 0)
#define read_x87_status_word()
#define FLOAT_CONVERT(input_width, output_width) *dest = *src
#endif

//this should work cross platrofm (although size types are suspicious)
//float
#define FLOAT_CONVERT_L_S(s,d) { float* src = s; long long* dest = (long long*)d; FLOAT_CONVERT(dword, qword); }
#define FLOAT_CONVERT_W_S(s,d) { float* src = s; long* dest = (long*)d; FLOAT_CONVERT(dword, dword); }
//round,trunc,floor,ceil
#define FLOAT_L_S(s,d) { float* src = s; long long* dest = (long long*)d; FLOAT_CONVERT(dword, qword)}
#define FLOAT_W_S(s,d) { float* src = s; long* dest = (long*)d; FLOAT_CONVERT(dword, dword)}
//double
#define FLOAT_CONVERT_L_D(s,d) { double* src = s; long long* dest = (long long*)d; FLOAT_CONVERT(qword, dword); }
#define FLOAT_CONVERT_W_D(s,d) { double* src = s; long* dest = (long*)d; FLOAT_CONVERT(qword, qword); }
//double round,trunc,floor,ceil
#define FLOAT_L_D(s,d) { double* src = s; long long* dest = (long long*)d; FLOAT_CONVERT(qword, dword)}
#define FLOAT_W_D(s,d) { double* src = s; long* dest = (long*)d; FLOAT_CONVERT(qword, qword)}

#endif
Loading

0 comments on commit 763c9a7

Please sign in to comment.