• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

sst/elements/genericProc/programs/qthread-1.4/include/qt_gcd.h

00001 #ifdef HAVE_CONFIG_H
00002 # include "config.h"
00003 #endif
00004 
00005 static QINLINE size_t qt_gcd(size_t a, size_t b)
00006 {
00007 #ifdef QTHREAD_SHIFT_GCD
00008     size_t k = 0;
00009     if (a == 0) return b;
00010     if (b == 0) return a;
00011     while ((a & 1) == 0 && (b&1) == 0) { /* while they're both even */
00012         a >>= 1; /* divide by 2 */
00013         b >>= 1; /* divide by 2 */
00014         k++; /* power of 2 to the result */
00015     }
00016     /* now, one or the other is odd */
00017     do {
00018         if ((a&1) == 0)
00019             a >>= 1;
00020         else if ((b&1) == 0)
00021             b >>= 1;
00022         else if (a >= b) /* both odd */
00023             a = (a-b) >> 1;
00024         else
00025             b = (b-a) >> 1;
00026     } while (a > 0);
00027     return b << k;
00028 #else /* MOD GCD */
00029     while (1) {
00030         if (a == 0) return b;
00031         b %= a;
00032         if (b == 0) return a;
00033         a %= b;
00034     }
00035 #endif
00036 }
00037 
00038 static QINLINE size_t qt_lcm(size_t a, size_t b)
00039 {                                      /*{{{ */
00040     size_t tmp = qt_gcd(a, b);
00041 
00042     return (tmp != 0) ? (a * b / tmp) : 0;
00043 }                                      /*}}} */

Generated on Fri Oct 22 2010 11:02:24 for SST by  doxygen 1.7.1