forked from Hydr8gon/sm64
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite rounding function without float adds
Force float sqrt to use hardware sqrt
- Loading branch information
Showing
3 changed files
with
52 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,6 @@ double sin(double); | |
float cosf(float); | ||
double cos(double); | ||
|
||
float sqrtf(float); | ||
#define sqrtf fsqrt; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
#include "nds_include.h" | ||
|
||
#define f32 float | ||
#define u32 uint32_t | ||
#define s32 int32_t | ||
#define u64 uint64_t | ||
|
||
#ifdef TARGET_NDS | ||
#define NDS_ITCM_CODE __attribute__((section(".itcm"))) | ||
#else | ||
#define NDS_ITCM_CODE | ||
#endif | ||
|
||
NDS_ITCM_CODE f32 fsqrt(f32 x){ | ||
union{f32 f; u32 i;}xu; | ||
xu.f=x; | ||
//grab exponent | ||
s32 exponent= (xu.i & (0xff<<23)); | ||
if(exponent==0)return 0.0; | ||
exponent=exponent-(127<<23); | ||
exponent=exponent>>1; //right shift on negative number depends on compiler | ||
u64 mantissa=xu.i & ((1<<23)-1); | ||
mantissa=(mantissa+(1<<23))<<23; | ||
if ((exponent & (1<<22))>0){ | ||
mantissa=mantissa<<1; | ||
} | ||
//printf("exponent: %d\n", exponent); | ||
//printf("mantissa: %ld\n", mantissa); | ||
u32 new_mantissa= (u32) sqrt64(mantissa); //modify this line to use hardware sqrt | ||
|
||
xu.i= ((exponent+(127<<23))& (0xff<<23) ) | (new_mantissa & ((1<<23)-1)); | ||
return xu.f; | ||
} |