Skip to content

Commit

Permalink
Removing of cross-platform code and dependencies from external includ…
Browse files Browse the repository at this point in the history
…es (common.h, rotate.h, netconv.h)
  • Loading branch information
sysprg committed Jun 7, 2019
1 parent f1d62c2 commit 5dba52a
Show file tree
Hide file tree
Showing 31 changed files with 235 additions and 1,947 deletions.
48 changes: 4 additions & 44 deletions tempesta_fw/http2/bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@
#ifndef BITS_H
#define BITS_H

#include "common.h"
#include <inttypes.h>

#define Bit_Sub -
#define Bit_High(x, n) (x) >= (1U << n)

#ifdef __GNUC__

#if Platform_64bit

#define Bit_CRC(crc, x) \
(__extension__ ({ \
register uintptr_t __r = crc; \
Expand All @@ -57,56 +55,19 @@

#else

#define Bit_CRC(crc, x) \
(__extension__ ({ \
register uintptr_t __r = crc; \
__asm__( \
"crc32 %2,%0" : "=r" (__r) : "0" (__r), "rm" ((uintptr_t) x) : "cc" \
); \
__r; \
}))

#define Bit_FastLog2(x) \
(__extension__ ({ \
register uintptr_t __r; \
__asm__( \
"bsr %1,%0" : "=r" (__r) : "rm" ((uintptr_t) x) : "cc" \
); \
__r; \
}))

#endif

#else

common_inline unsigned int
static __inline__ unsigned int
Bit_FastLog2(uintptr_t value)
{
unsigned int x = (unsigned int)value;
unsigned int n = 0;
unsigned int c;

#ifdef Platform_64bit
if (Bit_High(value, 32)) {
x = (unsigned int)(value >> 32);
n = 32;
}
if (Bit_High(x, 16))
x = x >> 16, n += 16;
#else
if (Bit_High(x, 16))
x = x >> 16, n = 16;
#endif
#ifndef Branch_Free
if (x >= 256)
x = x >> 8, n += 8;
if (x >= 16)
x = x >> 4, n += 4;
if (x >= 4)
x = x >> 2, n += 2;
n = n + (x >> 1);
#else
unsigned int c;

x = (x | 1) >> n;
n = n + 15;
c = ((x - 0x0100) >> 16) & 8;
Expand All @@ -116,13 +77,12 @@ Bit_FastLog2(uintptr_t value)
n = n - c;
x = x >> (12 Bit_Sub c);
n = n - ((x + 2) >> (x >> 1));
#endif
return n;
}

#endif

common_inline uintptr_t
static __inline__ uintptr_t
Bit_UpPowerOfTwo(uintptr_t x)
{
if (likely(x > 2)) {
Expand Down
9 changes: 2 additions & 7 deletions tempesta_fw/http2/buffers.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <string.h>
#include <stdio.h>
#include <inttypes.h>
#include "common.h"
#include "../pool.h"
#include "../str.h"
#include "hash.h"
Expand Down Expand Up @@ -422,7 +421,7 @@ void
buffer_new(HTTP2Output * __restrict p,
TfwPool * __restrict pool, unsigned int alignment)
{
unsigned int align = Word_Size - 1;
unsigned int align = sizeof(uintptr_t) - 1;

if (alignment) {
align = ~alignment & (alignment - 1);
Expand Down Expand Up @@ -1202,11 +1201,7 @@ buffer_str_cmp(const TfwStr * __restrict x, const TfwStr * __restrict y)
Final:
delta = (cx >> 1) - (cy >> 1);
if (delta) {
#if Fast_Capacity < Bit_Capacity
return (delta >> (Bit_Capacity - Fast_Capacity)) | 1;
#else
return delta;
#endif
return (delta >> 32) | 1;
}
return (int)(cx - cy);
}
Expand Down
5 changes: 3 additions & 2 deletions tempesta_fw/http2/buffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
#ifndef HTTP2_BUFFERS_H
#define HTTP2_BUFFERS_H

#include "common.h"
#include <inttypes.h>

#include "../pool.h"
#include "../str.h"
#include "errors.h"
Expand Down Expand Up @@ -322,7 +323,7 @@ void buffer_str_print(const TfwStr * __restrict str);
/* Free memory occupied by the TfwStr descriptors, */
/* which may be allocated for compound strings: */

common_inline void
static __inline__ void
buffer_str_free(TfwPool * __restrict pool, TfwStr * __restrict str)
{
if (!TFW_STR_PLAIN(str)) {
Expand Down
Loading

0 comments on commit 5dba52a

Please sign in to comment.