mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 03:32:45 +00:00 
			
		
		
		
	AK: Add very naive implementation of {sin,cos,tan} for aarch64
The {sin,cos,tan} functions in AK are used as the implementation of the
same function in libm. We cannot use the __builtin_foo functions as
these would just call the libc functions. This was causing an infinite
loop. Fix this by adding a very naive implementation of
AK::{sin, cos,tan}, that is only valid for small inputs. For the other
functions in this file, I added a TODO() such that we'll crash, instead
of infinite looping.
			
			
This commit is contained in:
		
							parent
							
								
									9ed04bdb33
								
							
						
					
					
						commit
						957f89ce4a
					
				
					 1 changed files with 27 additions and 3 deletions
				
			
		
							
								
								
									
										30
									
								
								AK/Math.h
									
										
									
									
									
								
							
							
						
						
									
										30
									
								
								AK/Math.h
									
										
									
									
									
								
							|  | @ -90,6 +90,8 @@ constexpr T fmod(T x, T y) | ||||||
|     } while (fpu_status & 0x400); |     } while (fpu_status & 0x400); | ||||||
|     return x; |     return x; | ||||||
| #else | #else | ||||||
|  |     // TODO: Add implementation for this function.
 | ||||||
|  |     TODO(); | ||||||
|     return __builtin_fmod(x, y); |     return __builtin_fmod(x, y); | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
|  | @ -109,6 +111,8 @@ constexpr T remainder(T x, T y) | ||||||
|     } while (fpu_status & 0x400); |     } while (fpu_status & 0x400); | ||||||
|     return x; |     return x; | ||||||
| #else | #else | ||||||
|  |     // TODO: Add implementation for this function.
 | ||||||
|  |     TODO(); | ||||||
|     return __builtin_fmod(x, y); |     return __builtin_fmod(x, y); | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
|  | @ -244,7 +248,9 @@ constexpr T sin(T angle) | ||||||
|         : "0"(angle)); |         : "0"(angle)); | ||||||
|     return ret; |     return ret; | ||||||
| #else | #else | ||||||
|     return __builtin_sin(angle); |     // FIXME: This is a very naive implementation, and is only valid for small x.
 | ||||||
|  |     //        Probably a good idea to use a better algorithm in the future, such as a taylor approximation.
 | ||||||
|  |     return angle; | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -261,7 +267,9 @@ constexpr T cos(T angle) | ||||||
|         : "0"(angle)); |         : "0"(angle)); | ||||||
|     return ret; |     return ret; | ||||||
| #else | #else | ||||||
|     return __builtin_cos(angle); |     // FIXME: This is a very naive implementation, and is only valid for small x.
 | ||||||
|  |     //        Probably a good idea to use a better algorithm in the future, such as a taylor approximation.
 | ||||||
|  |     return 1 - ((angle * angle) / 2); | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -298,7 +306,9 @@ constexpr T tan(T angle) | ||||||
| 
 | 
 | ||||||
|     return ret; |     return ret; | ||||||
| #else | #else | ||||||
|     return __builtin_tan(angle); |     // FIXME: This is a very naive implementation, and is only valid for small x.
 | ||||||
|  |     //        Probably a good idea to use a better algorithm in the future, such as a taylor approximation.
 | ||||||
|  |     return angle; | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -316,6 +326,8 @@ constexpr T atan(T value) | ||||||
|         : "0"(value)); |         : "0"(value)); | ||||||
|     return ret; |     return ret; | ||||||
| #else | #else | ||||||
|  |     // TODO: Add implementation for this function.
 | ||||||
|  |     TODO(); | ||||||
|     return __builtin_atan(value); |     return __builtin_atan(value); | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
|  | @ -371,6 +383,8 @@ constexpr T atan2(T y, T x) | ||||||
|         : "st(1)"); |         : "st(1)"); | ||||||
|     return ret; |     return ret; | ||||||
| #else | #else | ||||||
|  |     // TODO: Add implementation for this function.
 | ||||||
|  |     TODO(); | ||||||
|     return __builtin_atan2(y, x); |     return __builtin_atan2(y, x); | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
|  | @ -404,6 +418,8 @@ constexpr T log(T x) | ||||||
|         : "0"(x)); |         : "0"(x)); | ||||||
|     return ret; |     return ret; | ||||||
| #else | #else | ||||||
|  |     // TODO: Add implementation for this function.
 | ||||||
|  |     TODO(); | ||||||
|     return __builtin_log(x); |     return __builtin_log(x); | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
|  | @ -423,6 +439,8 @@ constexpr T log2(T x) | ||||||
|         : "0"(x)); |         : "0"(x)); | ||||||
|     return ret; |     return ret; | ||||||
| #else | #else | ||||||
|  |     // TODO: Add implementation for this function.
 | ||||||
|  |     TODO(); | ||||||
|     return __builtin_log2(x); |     return __builtin_log2(x); | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
|  | @ -442,6 +460,8 @@ constexpr T log10(T x) | ||||||
|         : "0"(x)); |         : "0"(x)); | ||||||
|     return ret; |     return ret; | ||||||
| #else | #else | ||||||
|  |     // TODO: Add implementation for this function.
 | ||||||
|  |     TODO(); | ||||||
|     return __builtin_log10(x); |     return __builtin_log10(x); | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
|  | @ -466,6 +486,8 @@ constexpr T exp(T exponent) | ||||||
|         : "0"(exponent)); |         : "0"(exponent)); | ||||||
|     return res; |     return res; | ||||||
| #else | #else | ||||||
|  |     // TODO: Add implementation for this function.
 | ||||||
|  |     TODO(); | ||||||
|     return __builtin_exp(exponent); |     return __builtin_exp(exponent); | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
|  | @ -488,6 +510,8 @@ constexpr T exp2(T exponent) | ||||||
|         : "0"(exponent)); |         : "0"(exponent)); | ||||||
|     return res; |     return res; | ||||||
| #else | #else | ||||||
|  |     // TODO: Add implementation for this function.
 | ||||||
|  |     TODO(); | ||||||
|     return __builtin_exp2(exponent); |     return __builtin_exp2(exponent); | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timon Kruiper
						Timon Kruiper