Changeset 890
 Timestamp:
 Sep 2, 2011, 2:28:41 AM (8 years ago)
 Location:
 trunk
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/trig.cpp
r888 r890 25 25 26 26 static const double PI = 3.14159265358979323846; 27 static const double NEG_PI = 3.14159265358979323846; 27 28 static const double PI_2 = PI / 2.0; 28 29 static const double PI_4 = PI / 4.0; … … 36 37 static const double TWO = 2.0; 37 38 static const double VERY_SMALL_NUMBER = 0x1.0p128; 38 static const double VERY_LARGE_NUMBER= 4503599627370496.0;39 static const double EVEN_LARGER_NUMBER = 9007199254740992.0;39 static const double TWO_EXP_52 = 4503599627370496.0; 40 static const double TWO_EXP_54 = 18014398509481984.0; 40 41 41 42 /** sin Taylor series coefficients. */ 42 43 static const double SC[] = 43 44 { 44 1.6 666666666666666666667e01, // 1/3!45 +8. 3333333333333333333333e03, // 1/5!46 1.9 841269841269841269841e04, // 1/7!47 +2. 7557319223985890652557e06, // 1/9!48 2. 5052108385441718775052e08, // 1/11!49 +1. 6059043836821614599392e10, // 1/13!50  7.6471637318198164759011e13, // 1/15!51 +2. 8114572543455207631989e15, // 1/17!45 1.6449340668482264364724e0, // pi^2/3! 46 +8.1174242528335364363700e1, // pi^4/5! 47 1.9075182412208421369647e1, // pi^6/7! 48 +2.6147847817654800504653e2, // pi^8/9! 49 2.3460810354558236375089e3, // pi^10/11! 50 +1.4842879303107100368487e4, // pi^12/13! 51 6.9758736616563804745344e6, // pi^14/15! 52 +2.5312174041370276513517e7, // pi^16/17! 52 53 }; 53 54 … … 166 167 double lol_sin(double x) 167 168 { 168 double absx = lol_fabs(x );169 double sign = lol_fsel(x, ONE, NEG_ONE);169 double absx = lol_fabs(x * INV_PI); 170 double sign = lol_fsel(x, PI, NEG_PI); 170 171 #if defined __CELLOS_LV2__ 171 double num_cycles = lol_round(absx * INV_PI);172 double num_cycles = lol_round(absx); 172 173 double is_even = lol_trunc(num_cycles * HALF)  (num_cycles * HALF); 174 sign = lol_fsel(is_even, sign, sign); 173 175 #else 174 double num_cycles = absx * INV_PI + VERY_LARGE_NUMBER; 175 __asm__("" : "+m" (num_cycles)); 176 num_cycles = VERY_LARGE_NUMBER; 176 double num_cycles = absx + TWO_EXP_52; 177 __asm__("" : "+m" (num_cycles)); num_cycles = TWO_EXP_52; 177 178 178 double is_even = num_cycles  HALF; 179 double is_even = TWO * num_cycles  ONE; 180 __asm__("" : "+m" (is_even)); is_even += TWO_EXP_54; 181 __asm__("" : "+m" (is_even)); is_even = TWO_EXP_54; 179 182 __asm__("" : "+m" (is_even)); 180 is_even += EVEN_LARGER_NUMBER; 181 __asm__("" : "+m" (is_even)); 182 is_even = EVEN_LARGER_NUMBER; 183 __asm__("" : "+m" (is_even)); 184 is_even = num_cycles; 183 is_even = TWO * num_cycles  ONE; 184 sign *= is_even; 185 185 #endif 186 double norm_x = absx  PI *num_cycles;186 double norm_x = absx  num_cycles; 187 187 double y = norm_x * norm_x; 188 double taylor = ((((((((SC[7] * y + SC[6]) * y + SC[5]) 189 * y + SC[4]) * y + SC[3]) 190 * y + SC[2]) * y + SC[1]) 191 * y + SC[0]) * y); 192 sign = lol_fsel(is_even, sign, sign); 193 double result = norm_x + norm_x * taylor; 188 double taylor = (((((((SC[7] * y + SC[6]) * y + SC[5]) 189 * y + SC[4]) * y + SC[3]) 190 * y + SC[2]) * y + SC[1]) 191 * y + SC[0]) * y + ONE; 192 double result = norm_x * taylor; 194 193 return result * sign; 195 194 } 
trunk/test/lolbench.cpp
r886 r890 51 51 52 52 Log::Info("\n"); 53 Log::Info(" Trigonometry [1e2, 1e2]\n"); 54 Log::Info("\n"); 55 bench_trig(3); 56 57 Log::Info("\n"); 53 58 Log::Info(" Float matrices [2.0, 2.0]\n"); 54 59 Log::Info("\n"); … … 88 93 for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) 89 94 pf[i] = RandF(M_PI, M_PI); 95 break; 96 case 3: 97 for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) 98 pf[i] = RandF(1e2f, 1e2f); 90 99 break; 91 100 }
Note: See TracChangeset
for help on using the changeset viewer.