<commit_before>#include <stdint.h>

// use SHIFT_COUNTER_BITS=4 for simulation
#define SHIFT_COUNTER_BITS 16

void output(uint8_t c)
{
	*(volatile char*)0x10000000 = c;
}

void output_gray(uint8_t c)
{
	unsigned int in_buf = c, out_buf = 0;
	for (int i = 0; i < 8; i++) {
		unsigned int bit = (in_buf & 1) ^ ((in_buf >> 1) & 1);
		in_buf = in_buf >> 1;
		out_buf = (out_buf << 1) | bit;
	}
	output(out_buf);
}

void main()
{
	for (uint32_t counter = (2+4+32+64) << SHIFT_COUNTER_BITS;; counter++) {
		asm volatile ("" : : "r"(counter));
		if ((counter & ~(~0 << SHIFT_COUNTER_BITS)) == 0)
			output_gray(counter >> SHIFT_COUNTER_BITS);
	}
}<commit_msg>Improvements in icestorm test firmware<commit_after>#include <stdint.h>

// use SHIFT_COUNTER_BITS=4 for simulation
#define SHIFT_COUNTER_BITS 18

void output(uint8_t c)
{
	*(volatile char*)0x10000000 = c;
}

uint8_t gray_encode_simple(uint8_t c)
{
	return c ^ (c >> 1);
}

uint8_t gray_encode_bitwise(uint8_t c)
{
	unsigned int in_buf = c, out_buf = 0, bit = 1;
	for (int i = 0; i < 8; i++) {
		if ((in_buf & 1) ^ ((in_buf >> 1) & 1))
			out_buf |= bit;
		in_buf = in_buf >> 1;
		bit = bit << 1;
	}
	return out_buf;
}

uint8_t gray_decode(uint8_t c)
{
	uint8_t t = c >> 1;
	while (t) {
		c = c ^ t;
		t = t >> 1;
	}
	return c;
}

void gray(uint8_t c)
{
	uint8_t gray_simple = gray_encode_simple(c);
	uint8_t gray_bitwise = gray_encode_bitwise(c);
	uint8_t gray_decoded = gray_decode(gray_simple);

	if (gray_simple != gray_bitwise || gray_decoded != c)
		while (1) asm volatile ("sbreak");

	output(gray_simple);
}

void main()
{
	for (uint32_t counter = (2+4+32+64) << SHIFT_COUNTER_BITS;; counter++) {
		asm volatile ("" : : "r"(counter));
		if ((counter & ~(~0 << SHIFT_COUNTER_BITS)) == 0)
			gray(counter >> SHIFT_COUNTER_BITS);
	}
}
{'fraction_non_alphanumeric': 0.16415410385259632, 'fraction_numerical': 0.044109436069235064, 'mean_word_length': 4.090909090909091, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '4982410', 'n_tokens_mistral': 854, 'n_tokens_neox': 781, 'n_words': 183}