1 |
/* Copyright (c) 2002, Marek Michalkiewicz |
/* Copyright (c) 2005 Joerg Wunsch |
|
Copyright (c) 2004, Joerg Wunsch |
|
2 |
All rights reserved. |
All rights reserved. |
3 |
|
|
4 |
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
30 |
|
|
31 |
/* $Id$ */ |
/* $Id$ */ |
32 |
|
|
|
/* avr/parity.h - optimized code to calculate parity bit of a byte */ |
|
|
|
|
33 |
#ifndef _AVR_PARITY_H_ |
#ifndef _AVR_PARITY_H_ |
34 |
#define _AVR_PARITY_H_ |
#define _AVR_PARITY_H_ |
35 |
|
|
36 |
/** \defgroup avr_parity <avr/parity.h>: Parity bit generation |
#warning "This file has been moved to <util/parity.h>." |
37 |
\code #include <avr/parity.h> \endcode |
#include <util/parity.h> |
|
|
|
|
This header file contains optimized assembler code to calculate |
|
|
the parity bit for a byte. |
|
|
*/ |
|
|
/** \def parity_even_bit |
|
|
\ingroup avr_parity |
|
|
\returns 1 if \c val has an odd number of bits set. */ |
|
|
#define parity_even_bit(val) \ |
|
|
(__extension__({ \ |
|
|
unsigned char __t; \ |
|
|
__asm__ ( \ |
|
|
"mov __tmp_reg__,%0" "\n\t" \ |
|
|
"swap %0" "\n\t" \ |
|
|
"eor %0,__tmp_reg__" "\n\t" \ |
|
|
"mov __tmp_reg__,%0" "\n\t" \ |
|
|
"lsr %0" "\n\t" \ |
|
|
"lsr %0" "\n\t" \ |
|
|
"eor %0,__tmp_reg__" \ |
|
|
: "=r" (__t) \ |
|
|
: "0" ((unsigned char)(val)) \ |
|
|
: "r0" \ |
|
|
); \ |
|
|
(((__t + 1) >> 1) & 1); \ |
|
|
})) |
|
38 |
|
|
39 |
#endif /* _AVR_PARITY_H_ */ |
#endif /* _AVR_PARITY_H_ */ |