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

parity.h

このファイルのドキュメントを参照する
00001 /* Copyright (c) 2002, Marek Michalkiewicz
00002    Copyright (c) 2004,2005,2007 Joerg Wunsch
00003    All rights reserved.
00004 
00005    Redistribution and use in source and binary forms, with or without
00006    modification, are permitted provided that the following conditions are met:
00007 
00008    * Redistributions of source code must retain the above copyright
00009      notice, this list of conditions and the following disclaimer.
00010 
00011    * Redistributions in binary form must reproduce the above copyright
00012      notice, this list of conditions and the following disclaimer in
00013      the documentation and/or other materials provided with the
00014      distribution.
00015 
00016    * Neither the name of the copyright holders nor the names of
00017      contributors may be used to endorse or promote products derived
00018      from this software without specific prior written permission.
00019 
00020   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00021   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00022   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00023   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00024   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00025   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00026   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00028   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00029   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00030   POSSIBILITY OF SUCH DAMAGE. */
00031 
00032 /* $Id: parity.h 1196 2007-01-23 15:34:58Z joerg_wunsch $ */
00033 
00034 #ifndef _UTIL_PARITY_H_
00035 #define _UTIL_PARITY_H_
00036 
00037 /** \file */
00038 /** \defgroup util_parity <util/parity.h>: Parity bit generation
00039     \code #include <util/parity.h> \endcode
00040 
00041     This header file contains optimized assembler code to calculate
00042     the parity bit for a byte.
00043 */
00044 /** \def parity_even_bit
00045     \ingroup util_parity
00046     \returns 1 if \c val has an odd number of bits set. */
00047 #define parity_even_bit(val)                            \
00048 (__extension__({                                        \
00049         unsigned char __t;                              \
00050         __asm__ (                                       \
00051                 "mov __tmp_reg__,%0" "\n\t"             \
00052                 "swap %0" "\n\t"                        \
00053                 "eor %0,__tmp_reg__" "\n\t"             \
00054                 "mov __tmp_reg__,%0" "\n\t"             \
00055                 "lsr %0" "\n\t"                         \
00056                 "lsr %0" "\n\t"                         \
00057                 "eor %0,__tmp_reg__"                    \
00058                 : "=r" (__t)                            \
00059                 : "0" ((unsigned char)(val))            \
00060                 : "r0"                                  \
00061         );                                              \
00062         (((__t + 1) >> 1) & 1);                         \
00063  }))
00064 
00065 #endif /* _UTIL_PARITY_H_ */

Automatically generated by Doxygen 1.7.2 on Wed Feb 16 2011.

翻訳更新:2011年10月8日 by cega