intmath.hh (6216:2f4020838149) | intmath.hh (7584:28ddf6d9e982) |
---|---|
1/* 2 * Copyright (c) 2001, 2003-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 19 unchanged lines hidden (view full) --- 28 * Authors: Nathan Binkert 29 */ 30 31#ifndef __BASE_INTMATH_HH__ 32#define __BASE_INTMATH_HH__ 33 34#include <cassert> 35 | 1/* 2 * Copyright (c) 2001, 2003-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 19 unchanged lines hidden (view full) --- 28 * Authors: Nathan Binkert 29 */ 30 31#ifndef __BASE_INTMATH_HH__ 32#define __BASE_INTMATH_HH__ 33 34#include <cassert> 35 |
36#include "base/misc.hh" |
|
36#include "base/types.hh" 37 38// Returns the prime number one less than n. 39int prevPrime(int n); 40 41// Determine if a number is prime 42template <class T> 43inline bool --- 25 unchanged lines hidden (view full) --- 69 70template <class T> 71inline bool 72isPowerOf2(T n) 73{ 74 return n != 0 && leastSigBit(n) == n; 75} 76 | 37#include "base/types.hh" 38 39// Returns the prime number one less than n. 40int prevPrime(int n); 41 42// Determine if a number is prime 43template <class T> 44inline bool --- 25 unchanged lines hidden (view full) --- 70 71template <class T> 72inline bool 73isPowerOf2(T n) 74{ 75 return n != 0 && leastSigBit(n) == n; 76} 77 |
78inline uint64_t 79power(uint32_t n, uint32_t e) 80{ 81 if (e > 20) 82 warn("Warning, power() function is quite slow for large exponents\n"); 83 84 if (e == 0) 85 return 1; 86 87 uint64_t result = n; 88 uint64_t old_result = 0; 89 for (int x = 1; x < e; x++) { 90 old_result = result; 91 result *= n; 92 if (old_result > result) 93 warn("power() overflowed!\n"); 94 } 95 return result; 96} 97 98 |
|
77inline int 78floorLog2(unsigned x) 79{ 80 assert(x > 0); 81 82 int y = 0; 83 84 if (x & 0xffff0000) { y += 16; x >>= 16; } --- 148 unchanged lines hidden --- | 99inline int 100floorLog2(unsigned x) 101{ 102 assert(x > 0); 103 104 int y = 0; 105 106 if (x & 0xffff0000) { y += 16; x >>= 16; } --- 148 unchanged lines hidden --- |