From 91bd7afa7f6160d9db1c2fd8799ff2f9d8302809 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 27 Sep 2010 19:25:13 +0000 Subject: [PATCH] new generic bit operations by Michael Walle git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1850 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- urjtag/ChangeLog | 3 ++ urjtag/include/urjtag/Makefile.am | 1 + urjtag/include/urjtag/bitops.h | 54 +++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 urjtag/include/urjtag/bitops.h diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index 2d647771..3e428dbf 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -12,6 +12,9 @@ * configure.ac: Change to newer libtool macro (LT_INIT) to avoid warnings. * acinclude.m4: Redirect LT_INIT to AC_PROG_LIBTOOL for older libtools. + * include/urjtag/bitops.h: New generic bit operations by Michael Walle. + * include/urjtag/Makefile.am (pkginclude_HEADERS): Add bitops.h + 2010-08-30 Mike Frysinger * configure.ac: Clean up libusb detection to prefer 1.0 over 0.1, and accept diff --git a/urjtag/include/urjtag/Makefile.am b/urjtag/include/urjtag/Makefile.am index 532e95b1..ece50530 100644 --- a/urjtag/include/urjtag/Makefile.am +++ b/urjtag/include/urjtag/Makefile.am @@ -26,6 +26,7 @@ include $(top_srcdir)/Makefile.rules pkginclude_HEADERS = \ bfin.h \ bitmask.h \ + bitops.h \ bsbit.h \ bsdl.h \ bsdl_mode.h \ diff --git a/urjtag/include/urjtag/bitops.h b/urjtag/include/urjtag/bitops.h new file mode 100644 index 00000000..4f9d1922 --- /dev/null +++ b/urjtag/include/urjtag/bitops.h @@ -0,0 +1,54 @@ +/* + * $Id$ + * + * Copyright (C) 2010, Michael Walle + * + * This program 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 program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + */ + +#ifndef URJ_BITOPS_H +#define URJ_BITOPS_H + +#include + +static inline uint16_t flip16 (uint16_t v) +{ + int i; + uint16_t out = 0; + + /* flip bits (from left to right) */ + for (i = 0; i < 16; i++) + if (v & (1 << i)) + out |= (1 << (15 - i)); + + return out; +} + +static inline uint32_t flip32 (uint32_t v) +{ + int i; + uint32_t out = 0; + + /* flip bits (from left to right) */ + for (i = 0; i < 32; i++) + if (v & (1 << i)) + out |= (1 << (31 - i)); + + return out; +} + +#endif /* URJ_BITOPS_H */