This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
tango-maat/src/inc_internal/alignment.h

79 lines
1.6 KiB
C
Raw Normal View History

/*
**********************************************************************************************
* File: alignment.h
* Description: alignment statistics
* Authors: Zheng Chao <zhengchao@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
***********************************************************************************************
*/
#ifndef _ALIGNMENT_H_
#define _ALIGNMENT_H_
#ifdef __cpluscplus
extern "C"
{
#endif
#include <stdlib.h>
#include <string.h>
#define CPU_CACHE_ALIGMENT 64
inline long long *alignment_int64_array_alloc(int size)
{
return (long long *)calloc(CPU_CACHE_ALIGMENT, size);
}
inline long long alignment_int64_array_sum(long long *array, int size)
{
int offset = 0;
long long sum = 0;
for (int i = 0; i < size; i++) {
offset = (CPU_CACHE_ALIGMENT / sizeof(long long)) * i;
sum += array[offset];
}
return sum;
}
inline long long alignment_int64_array_add(long long *array, int offset, long long op_val)
{
int idx = (CPU_CACHE_ALIGMENT / sizeof(long long)) * offset;
array[idx] += op_val;
return array[idx];
}
inline long long alignment_int64_array_cnt(long long *array, int size)
{
int offset = 0;
int cnt = 0;
for (int i = 0; i < size; i++) {
offset = (CPU_CACHE_ALIGMENT / sizeof(long long)) * i;
if (array[offset] > 0) {
cnt++;
}
}
return cnt;
}
inline void alignment_int64_array_reset(long long *array, int size)
{
memset(array, 0, CPU_CACHE_ALIGMENT * size);
}
inline void alignment_int64_array_free(long long *array)
{
free(array);
}
#ifdef __cpluscplus
}
#endif
#endif