<commit_before>/* Copyright (c) 2014, Linaro Limited
 * All rights reserved.
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 */

/**
 * @file
 *
 * ODP checksum helper
 */
#ifndef ODPH_CHKSUM_H_
#define ODPH_CHKSUM_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <odp_api.h>

/** @addtogroup odph_chksum ODPH CHECK SUM
 *  @{
 */

/**
 * Chksum Operation Code
 *
 * This enumeration type is used to tell odph_udp_tcp_chksum what to do once
 * it has calculated the TCP/UDP check sum.
 */
typedef enum {
	ODPH_CHKSUM_GENERATE, /**< Set TCP/UDP header chksum field */
	ODPH_CHKSUM_VERIFY,   /**< See if TCP/UDP header chksum is correct */
	ODPH_CHKSUM_RETURN    /**< Don't generate or verify chksum */
} odph_chksum_op_t;

/**
 * Checksum
 *
 * @param buffer calculate chksum for buffer
 * @param len    buffer length
 *
 * @return checksum value in host cpu order
 */
static inline odp_u16sum_t odph_chksum(void *buffer, int len)
{
	uint16_t *buf = (uint16_t*) buffer;
	uint32_t sum = 0;
	uint16_t result;

	for (sum = 0; len > 1; len -= 2)
		sum += *buf++;

	if (len == 1)
		sum += *(unsigned char *)buf;

	sum = (sum >> 16) + (sum & 0xFFFF);
	sum += (sum >> 16);
	result = ~sum;

	return  (__odp_force odp_u16sum_t) result;
}

/**
 * General Purpose TCP/UDP checksum function<commit_msg>Revert "linux-generic: helper api: fix type casting for C++ include"<commit_after>/* Copyright (c) 2014, Linaro Limited
 * All rights reserved.
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 */

/**
 * @file
 *
 * ODP checksum helper
 */
#ifndef ODPH_CHKSUM_H_
#define ODPH_CHKSUM_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <odp_api.h>

/** @addtogroup odph_chksum ODPH CHECK SUM
 *  @{
 */

/**
 * Chksum Operation Code
 *
 * This enumeration type is used to tell odph_udp_tcp_chksum what to do once
 * it has calculated the TCP/UDP check sum.
 */
typedef enum {
	ODPH_CHKSUM_GENERATE, /**< Set TCP/UDP header chksum field */
	ODPH_CHKSUM_VERIFY,   /**< See if TCP/UDP header chksum is correct */
	ODPH_CHKSUM_RETURN    /**< Don't generate or verify chksum */
} odph_chksum_op_t;

/**
 * Checksum
 *
 * @param buffer calculate chksum for buffer
 * @param len    buffer length
 *
 * @return checksum value in host cpu order
 */
static inline odp_u16sum_t odph_chksum(void *buffer, int len)
{
	uint16_t *buf = buffer;
	uint32_t sum = 0;
	uint16_t result;

	for (sum = 0; len > 1; len -= 2)
		sum += *buf++;

	if (len == 1)
		sum += *(unsigned char *)buf;

	sum = (sum >> 16) + (sum & 0xFFFF);
	sum += (sum >> 16);
	result = ~sum;

	return  (__odp_force odp_u16sum_t) result;
}

/**
 * General Purpose TCP/UDP checksum function
{'fraction_non_alphanumeric': 0.12846826301786393, 'fraction_numerical': 0.01976434815659445, 'mean_word_length': 3.430976430976431, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6699788', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1006, 'n_words': 297}