<commit_before>/*
 * This file is part of libFirm.
 * Copyright (C) 2014 University of Karlsruhe.
 */

/**
 * @file
 * @brief  Helper functions for immediates / relocations.
 * @author <NAME>
 */
#include "x86_node.h"

#include <inttypes.h>

#include "bediagnostic.h"
#include "begnuas.h"
#include "betranshlp.h"
#include "beemitter.h"
#include "irmode_t.h"
#include "irnode_t.h"
#include "irprintf.h"
#include "panic.h"
#include "tv_t.h"

char const *x86_pic_base_label;

static bool check_immediate_constraint(long val, char immediate_constraint_type)
{
	/* Workaround for warning about always true comparison when long has 32 bits. */
	long long const v31 = 2147483648;
	switch (immediate_constraint_type) {
	case 'g':
	case 'i':
	case 'n': return true;

	case 'e': return -v31 <= val && val < v31;
	case 'I': return 0 <= val && val <=  31;
	case 'J': return 0 <= val && val <=  63;
	case 'K': return -128 <= val && val < 128;
	case 'L': return val == 0xff || val == 0xffff;
	case 'M': return 0 <= val && val <=   3;
	case 'N': return 0 <= val && val <= 255;
	case 'O': return 0 <= val && val <= 127;
	}
	panic("invalid immediate constraint found");
}

bool x86_match_immediate(x86_imm32_t *immediate, const ir_node *node,
                         char const constraint)
{
	ir_mode *const mode = get_irn_mode(node);
	if (get_mode_arithmetic(mode) != irma_twos_complement)
		return false;

	ir_tarval *offset;
	ir_entity *entity;
	unsigned   reloc_kind;
	if (!be_match_immediate(node, &offset, &entity, &reloc_kind))
		return false;

	long val = 0;
	if (offset) {
		if (!tarval_is_long(offset)) {
			be_warningf(node, "tarval is not long");
			return false;
		}<commit_msg>x86: Consistently use half-open intervals in checks for immediate constraints.<commit_after>/*
 * This file is part of libFirm.
 * Copyright (C) 2014 University of Karlsruhe.
 */

/**
 * @file
 * @brief  Helper functions for immediates / relocations.
 * @author <NAME>
 */
#include "x86_node.h"

#include <inttypes.h>

#include "bediagnostic.h"
#include "begnuas.h"
#include "betranshlp.h"
#include "beemitter.h"
#include "irmode_t.h"
#include "irnode_t.h"
#include "irprintf.h"
#include "panic.h"
#include "tv_t.h"

char const *x86_pic_base_label;

static bool check_immediate_constraint(long val, char immediate_constraint_type)
{
	/* Workaround for warning about always true comparison when long has 32 bits. */
	long long const v31 = 2147483648;
	switch (immediate_constraint_type) {
	case 'g':
	case 'i':
	case 'n': return true;

	case 'e': return -v31 <= val && val < v31;
	case 'I': return    0 <= val && val <  32;
	case 'J': return    0 <= val && val <  64;
	case 'K': return -128 <= val && val < 128;
	case 'L': return val == 0xff || val == 0xffff;
	case 'M': return    0 <= val && val <   4;
	case 'N': return    0 <= val && val < 256;
	case 'O': return    0 <= val && val < 128;
	}
	panic("invalid immediate constraint found");
}

bool x86_match_immediate(x86_imm32_t *immediate, const ir_node *node,
                         char const constraint)
{
	ir_mode *const mode = get_irn_mode(node);
	if (get_mode_arithmetic(mode) != irma_twos_complement)
		return false;

	ir_tarval *offset;
	ir_entity *entity;
	unsigned   reloc_kind;
	if (!be_match_immediate(node, &offset, &entity, &reloc_kind))
		return false;

	long val = 0;
	if (offset) {
		if (!tarval_is_long(offset)) {
			be_warningf(node, "tarval is not long");
			return false;
		}
{'fraction_non_alphanumeric': 0.13956204379562043, 'fraction_numerical': 0.03386861313868613, 'mean_word_length': 3.832157968970381, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 7, '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': '6679453', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1247, 'n_words': 379}