This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* lfsr.c - lfsr library | |
* | |
* Copyright (C) 2009 Robert C. Curtis | |
* | |
* lfsr.c is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 2 of the License, or | |
* (at your option) any later version. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef I__BITFIELD_H__ | |
#define I__BITFIELD_H__ | |
/* Bitfield Macros | |
* | |
* A bitfield is any range of bits in a word. A bitfield definition | |
* needs to specify the SIZE and SHIFT in the following format: | |
* #define BITFIELD_NAME SIZE:SHIFT | |
* Examples (X is don't care, F is the field): | |
* Register: XXXXXFFX = Bitfield 2:1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Log(N) method for calculating the number of bits set in a word */ | |
uint8_t bits_set(uint32_t word) | |
{ | |
word = (word & 0x55555555) + ((word >> 1) & 0x55555555); | |
word = (word & 0x33333333) + ((word >> 2) & 0x33333333); | |
word = (word & 0x0F0F0F0F) + ((word >> 4) & 0x0F0F0F0F); | |
word = (word & 0x00FF00FF) + ((word >> 8) & 0x00FF00FF); | |
word = (word & 0x0000FFFF) + ((word >> 16) & 0x0000FFFF); | |
return (uint8_t)word; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
class Foo { | |
public: | |
Foo(int val) : val_(val) { } | |
void operator()(int v) const | |
{ | |
printf("%p : val = %d\n", this, val_ + v); | |
} |