Changeset 262 for trunk/poppler/freetype2/src/base/ftcalc.c
- Timestamp:
- Jan 17, 2009, 10:45:05 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/poppler/freetype2/src/base/ftcalc.c
r251 r262 39 39 #include FT_INTERNAL_OBJECTS_H 40 40 41 #ifdef FT_MULFIX_INLINED 42 #undef FT_MulFix 43 #endif 41 44 42 45 /* we need to define a 64-bits data type here */ … … 194 197 FT_Long b ) 195 198 { 199 #ifdef FT_MULFIX_ASSEMBLER 200 201 return FT_MULFIX_ASSEMBLER( a, b ); 202 203 #else 204 196 205 FT_Int s = 1; 197 206 FT_Long c; 198 207 199 208 200 if ( a < 0 ) { a = -a; s = -1; } 201 if ( b < 0 ) { b = -b; s = -s; } 209 if ( a < 0 ) 210 { 211 a = -a; 212 s = -1; 213 } 214 215 if ( b < 0 ) 216 { 217 b = -b; 218 s = -s; 219 } 202 220 203 221 c = (FT_Long)( ( (FT_Int64)a * b + 0x8000L ) >> 16 ); 204 return ( s > 0 ) ? c : -c ; 222 223 return ( s > 0 ) ? c : -c; 224 225 #endif /* FT_MULFIX_ASSEMBLER */ 205 226 } 206 227 … … 414 435 FT_Long b ) 415 436 { 416 /* use inline assembly to speed up things a bit */ 417 418 #if defined( __GNUC__ ) && defined( i386 ) 419 420 FT_Long result; 421 422 423 __asm__ __volatile__ ( 424 "imul %%edx\n" 425 "movl %%edx, %%ecx\n" 426 "sarl $31, %%ecx\n" 427 "addl $0x8000, %%ecx\n" 428 "addl %%ecx, %%eax\n" 429 "adcl $0, %%edx\n" 430 "shrl $16, %%eax\n" 431 "shll $16, %%edx\n" 432 "addl %%edx, %%eax\n" 433 "mov %%eax, %0\n" 434 : "=a"(result), "+d"(b) 435 : "a"(a) 436 : "%ecx" 437 ); 438 return result; 439 440 #elif 1 437 #ifdef FT_MULFIX_ASSEMBLER 438 439 return FT_MULFIX_ASSEMBLER( a, b ); 440 441 #elif 0 442 443 /* 444 * This code is nonportable. See comment below. 445 * 446 * However, on a platform where right-shift of a signed quantity fills 447 * the leftmost bits by copying the sign bit, it might be faster. 448 */ 441 449 442 450 FT_Long sa, sb; … … 447 455 return a; 448 456 457 /* 458 * This is a clever way of converting a signed number `a' into its 459 * absolute value (stored back into `a') and its sign. The sign is 460 * stored in `sa'; 0 means `a' was positive or zero, and -1 means `a' 461 * was negative. (Similarly for `b' and `sb'). 462 * 463 * Unfortunately, it doesn't work (at least not portably). 464 * 465 * It makes the assumption that right-shift on a negative signed value 466 * fills the leftmost bits by copying the sign bit. This is wrong. 467 * According to K&R 2nd ed, section `A7.8 Shift Operators' on page 206, 468 * the result of right-shift of a negative signed value is 469 * implementation-defined. At least one implementation fills the 470 * leftmost bits with 0s (i.e., it is exactly the same as an unsigned 471 * right shift). This means that when `a' is negative, `sa' ends up 472 * with the value 1 rather than -1. After that, everything else goes 473 * wrong. 474 */ 449 475 sa = ( a >> ( sizeof ( a ) * 8 - 1 ) ); 450 476 a = ( a ^ sa ) - sa;
Note: See TracChangeset
for help on using the changeset viewer.