<commit_before>/*
 * Copyright 2007-2009 RELIC Project
 *
 * This file is part of RELIC. RELIC is legal property of its developers,
 * whose names are not listed here. Please refer to the COPYRIGHT file.
 *
 * RELIC is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * RELIC 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with RELIC. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @file
 *
 * Implementation of the low-level binary field square root.
 *
 * @version $Id$
 * @ingroup fb
 */

#include <stdlib.h>

#include "relic_fb.h"
#include "relic_fb_low.h"
#include "relic_util.h"

/*============================================================================*/
/* Private definitions                                                        */
/*============================================================================*/

static const dig_t table_evens[16] = {
	0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15
};
static const dig_t table_odds[16] = {
	0, 4, 1, 5, 8, 12, 9, 13, 2, 6, 3, 7, 10, 14, 11, 15
};

static void fb_srtt_low(dig_t *c, dig_t *a, int fa) {
	int i, j, n, h, sh, rh, lh, sa, la, ra;
	dv_t t = NULL;
	dig_t d, d_e, d_o;

	dv_new(t);
	dv_zero(t, 2 * FB_DIGS);

	sh = 1 + (FB_BITS >> FB_DIG_LOG);
	h = (sh + 1) / 2;
	rh = (h << FB_DIG_LOG) - 1 - (FB_BITS - 1) / 2;
	lh = FB_DIGIT - rh;

	SPLIT(la, sa, (fa + 1) >> 1, FB_DIG_LOG);
	ra = FB_DIGIT - la;

	for (i = 0; i < sh; i++) {
		n = i >> 1;
		d = a[i];

		d_e = d_o = 0;
		for (j = 0; j < FB_DIGIT / 8; j++) {
			d_e |= table_evens[((d & 0x05) + ((d & 0x50) >> 3))] << (j << 2);
			d_o |= table_odds[((d & 0x0A) + ((d & 0xA0) >> 5))] << (j << 2);
			d >>= 8;
		}

		i++;
		if (i < sh) {
			d = a[i];

			for (j = 0; j < FB_DIGIT / 8; j++) {
				d_e |= table_evens[((d & 0x05) + ((d & 0x50) >> 3))] <<
						((FB_DIGIT / 2) + (j << 2));
				d_o |= table_odds[((d & 0x0A) + ((d & 0xA0) >> 5))] <<
						((FB_DIGIT / 2) + (j << 2));
				d >>= 8;
			}
		}

		t[n] ^= d_e;
<commit_msg>Bugfix.<commit_after>/*
 * Copyright 2007-2009 RELIC Project
 *
 * This file is part of RELIC. RELIC is legal property of its developers,
 * whose names are not listed here. Please refer to the COPYRIGHT file.
 *
 * RELIC is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * RELIC 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with RELIC. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @file
 *
 * Implementation of the low-level binary field square root.
 *
 * @version $Id$
 * @ingroup fb
 */

#include <stdlib.h>

#include "relic_fb.h"
#include "relic_fb_low.h"
#include "relic_util.h"

/*============================================================================*/
/* Private definitions                                                        */
/*============================================================================*/

static const dig_t table_evens[16] = {
	0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15
};
static const dig_t table_odds[16] = {
	0, 4, 1, 5, 8, 12, 9, 13, 2, 6, 3, 7, 10, 14, 11, 15
};

static void fb_srtt_low(dig_t *c, dig_t *a, int fa) {
	int i, j, n, h, sh, rh, lh, sa, la, ra;
	dv_t t = NULL;
	dig_t d, d_e, d_o;

	dv_new(t);
	dv_zero(t, 2 * FB_DIGS);

	h = (FB_DIGS + 1) / 2;
	rh = (h << FB_DIG_LOG) - 1 - (FB_BITS - 1) / 2;
	lh = FB_DIGIT - rh;

	SPLIT(la, sa, (fa + 1) >> 1, FB_DIG_LOG);
	ra = FB_DIGIT - la;

	for (i = 0; i < FB_DIGS; i++) {
		n = i >> 1;
		d = a[i];

		d_e = d_o = 0;
		for (j = 0; j < FB_DIGIT / 8; j++) {
			d_e |= table_evens[((d & 0x05) + ((d & 0x50) >> 3))] << (j << 2);
			d_o |= table_odds[((d & 0x0A) + ((d & 0xA0) >> 5))] << (j << 2);
			d >>= 8;
		}

		i++;
		if (i < sh) {
			d = a[i];

			for (j = 0; j < FB_DIGIT / 8; j++) {
				d_e |= table_evens[((d & 0x05) + ((d & 0x50) >> 3))] <<
						((FB_DIGIT / 2) + (j << 2));
				d_o |= table_odds[((d & 0x0A) + ((d & 0xA0) >> 5))] <<
						((FB_DIGIT / 2) + (j << 2));
				d >>= 8;
			}
		}

		t[n] ^= d_e;

{'fraction_non_alphanumeric': 0.22053075498868546, 'fraction_numerical': 0.04299526846327916, 'mean_word_length': 2.751543209876543, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2991346', 'n_tokens_mistral': 2180, 'n_tokens_neox': 1824, 'n_words': 646}