summaryrefslogtreecommitdiff
path: root/src/helper
diff options
context:
space:
mode:
Diffstat (limited to 'src/helper')
-rw-r--r--src/helper/binarybuffer.c37
-rw-r--r--src/helper/binarybuffer.h43
-rw-r--r--src/helper/log.h2
3 files changed, 42 insertions, 40 deletions
diff --git a/src/helper/binarybuffer.c b/src/helper/binarybuffer.c
index 6aa847aa..184d166c 100644
--- a/src/helper/binarybuffer.c
+++ b/src/helper/binarybuffer.c
@@ -49,43 +49,6 @@ const unsigned char bit_reverse_table256[] =
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
};
-int buf_set_u32(u8* buffer, unsigned int first, unsigned int num, u32 value)
-{
- unsigned int i;
-
- if (!buffer)
- return ERROR_INVALID_ARGUMENTS;
-
- for (i=first; i<first+num; i++)
- {
- if (((value >> (i-first))&1) == 1)
- buffer[i/8] |= 1 << (i%8);
- else
- buffer[i/8] &= ~(1 << (i%8));
- }
-
- return ERROR_OK;
-}
-
-u32 buf_get_u32(u8* buffer, unsigned int first, unsigned int num)
-{
- u32 result = 0;
- unsigned int i;
-
- if (!buffer)
- {
- LOG_ERROR("buffer not initialized");
- return 0;
- }
-
- for (i=first; i<first+num; i++)
- {
- if (((buffer[i/8]>>(i%8))&1) == 1)
- result |= 1 << (i-first);
- }
-
- return result;
-}
u8* buf_cpy(u8 *from, u8 *to, int size)
{
diff --git a/src/helper/binarybuffer.h b/src/helper/binarybuffer.h
index 34a167d4..47ae193e 100644
--- a/src/helper/binarybuffer.h
+++ b/src/helper/binarybuffer.h
@@ -26,8 +26,47 @@
* flip_u32 inverses the bit order inside a 32-bit word (31..0 -> 0..31)
*/
-extern int buf_set_u32(u8* buffer, unsigned int first, unsigned int num, u32 value);
-extern u32 buf_get_u32(u8* buffer, unsigned int first, unsigned int num);
+/* inlining this will help show what fn that is taking time during profiling. */
+static __inline void buf_set_u32(u8* buffer, unsigned int first, unsigned int num, u32 value)
+{
+ if ((num==32)&&(first==0))
+ {
+ buffer[3]=(value>>24)&0xff;
+ buffer[2]=(value>>16)&0xff;
+ buffer[1]=(value>>8)&0xff;
+ buffer[0]=(value>>0)&0xff;
+ } else
+ {
+ unsigned int i;
+
+ for (i=first; i<first+num; i++)
+ {
+ if (((value >> (i-first))&1) == 1)
+ buffer[i/8] |= 1 << (i%8);
+ else
+ buffer[i/8] &= ~(1 << (i%8));
+ }
+ }
+}
+static __inline u32 buf_get_u32(u8* buffer, unsigned int first, unsigned int num)
+{
+ if ((num==32)&&(first==0))
+ {
+ return (((u32)buffer[3])<<24)|(((u32)buffer[2])<<16)|(((u32)buffer[1])<<8)|(((u32)buffer[0])<<0);
+ } else
+ {
+ u32 result = 0;
+ unsigned int i;
+
+ for (i=first; i<first+num; i++)
+ {
+ if (((buffer[i/8]>>(i%8))&1) == 1)
+ result |= 1 << (i-first);
+ }
+
+ return result;
+ }
+}
extern u32 flip_u32(u32 value, unsigned int num);
diff --git a/src/helper/log.h b/src/helper/log.h
index 9929d420..6d61cf5f 100644
--- a/src/helper/log.h
+++ b/src/helper/log.h
@@ -80,7 +80,7 @@ extern int debug_level;
#define LOG_DEBUG(expr ...) \
- log_printf_lf (LOG_LVL_DEBUG, __FILE__, __LINE__, __FUNCTION__, expr)
+ if (debug_level >= LOG_LVL_DEBUG) { log_printf_lf (LOG_LVL_DEBUG, __FILE__, __LINE__, __FUNCTION__, expr); }
#define LOG_INFO(expr ...) \
log_printf_lf (LOG_LVL_INFO, __FILE__, __LINE__, __FUNCTION__, expr)