AVR Libc Home Page AVRs AVR Libc Development Pages
Main Page User Manual Reference FAQ Example Projects

parity.h

Go to the documentation of this file.
01	1 Copyright (c) 2002, Marek Michalkiewicz
	022Copyright (c) 2004,2005,2007 Joerg Wunsch
033All rights reserved. 044 055Redistribution and use in source and binary forms, with or without 066modification, are permitted provided that the following conditions are met: 077 088* Redistributions of source code must retain the above copyright 099notice, this list of conditions and the following disclaimer. 1010 1111* Redistributions in binary form must reproduce the above copyright 1212notice, this list of conditions and the following disclaimer in 1313the documentation and/or other materials provided with the 1414distribution. 1515 1616* Neither the name of the copyright holders nor the names of 1717contributors may be used to endorse or promote products derived 1818from this software without specific prior written permission. 1919 2020THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 2121AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2222IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2323ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 2424LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2525CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2626SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2727INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2828CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2929ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3030POSSIBILITY OF SUCH DAMAGE. */ 3131 3232/* $Id: parity.h 1196 2007-01-23 15:34:58Z joerg_wunsch $ */ 3333 3434#ifndef _UTIL_PARITY_H_ 3535#define _UTIL_PARITY_H_ 3636 3737/** \file */ 3838/** \defgroup util_parity <util/parity.h>: Parity bit generation 3939\code #include <util/parity.h> \endcode 4040 4141This header file contains optimized assembler code to calculate 4242the parity bit for a byte. 4343*/ 4444/** \def parity_even_bit 4545\ingroup util_parity 4646\returns 1 if \c val has an odd number of bits set. */ 47 47#define parity_even_bit(val) \ 4848(__extension__({ \ 4949unsigned char __t; \ 5050__asm__ ( \ 5151"mov __tmp_reg__,%0" "\n\t" \ 5252"swap %0" "\n\t" \ 5353"eor %0,__tmp_reg__" "\n\t" \ 5454"mov __tmp_reg__,%0" "\n\t" \ 5555"lsr %0" "\n\t" \ 5656"lsr %0" "\n\t" \ 5757"eor %0,__tmp_reg__" \ 5858: "=r" (__t) \ 5959: "0" ((unsigned char)(val)) \ 6060: "r0" \ 6161); \ 6262(((__t + 1) >> 1) & 1); \ 6363})) 6464 6565#endif /* _UTIL_PARITY_H_ */