Commit f1522129 authored by Matthias Braun's avatar Matthias Braun
Browse files

cleanups/fixes for ASM handling

[r20749]
parent ba8fb5d3
......@@ -105,12 +105,12 @@ void be_main(FILE *output, const char *compilation_unit_name);
* parse assembler constraint strings and returns flags (so the frontend knows
* which operands are inputs/outputs and wether memory is required)
*/
asm_constraint_flags_t parse_asm_constraints(const char *constraint);
asm_constraint_flags_t be_parse_asm_constraints(const char *constraints);
/**
* tests wether a string is a valid clobber in an asm instruction
*/
bool is_valid_clobber(const char *clobber);
bool be_is_valid_clobber(const char *clobber);
typedef struct be_main_env_t be_main_env_t;
typedef struct be_options_t be_options_t;
......
......@@ -240,10 +240,10 @@ void be_init_default_asm_constraint_flags(void)
asm_constraint_flags['\r'] = ASM_CONSTRAINT_FLAG_NO_SUPPORT;
}
asm_constraint_flags_t parse_asm_constraints(const char *constraint)
asm_constraint_flags_t be_parse_asm_constraints(const char *constraint)
{
asm_constraint_flags_t flags = 0;
const char *c;
asm_constraint_flags_t flags;
asm_constraint_flags_t tflags;
for (c = constraint; *c != '\0'; ++c) {
......@@ -279,16 +279,25 @@ asm_constraint_flags_t parse_asm_constraints(const char *constraint)
&& (flags & ASM_CONSTRAINT_FLAG_MODIFIER_NO_READ)))) {
flags |= ASM_CONSTRAINT_FLAG_INVALID;
}
if (! (flags & (ASM_CONSTRAINT_FLAG_MODIFIER_READ
| ASM_CONSTRAINT_FLAG_MODIFIER_WRITE
| ASM_CONSTRAINT_FLAG_MODIFIER_NO_WRITE
| ASM_CONSTRAINT_FLAG_MODIFIER_NO_READ))) {
flags |= ASM_CONSTRAINT_FLAG_MODIFIER_READ;
}
return flags;
}
bool is_valid_clobber(const char *clobber)
bool be_is_valid_clobber(const char *clobber)
{
/* memory is a valid clobber. (the frontend has to detect this case too,
* because it has to add memory edges to the asm) */
if (strcmp(clobber, "memory") == 0)
return true;
/* cc (condition code) is always valid */
if (strcmp(clobber, "cc") == 0)
return true;
return isa_if->is_valid_clobber(isa_if, clobber);
}
......
......@@ -1709,7 +1709,6 @@ static arch_env_t *ia32_init(FILE *file_handle) {
return NULL;
inited = 1;
init_asm_constraints();
set_tarval_output_modes();
isa = xmalloc(sizeof(*isa));
......@@ -2254,6 +2253,10 @@ static const backend_params *ia32_get_libfirm_params(void) {
ia32_setup_cg_config();
/* doesn't really belong here, but this is the earliest place the backend
* is called... */
init_asm_constraints();
p.dep_param = &ad;
p.if_conv_info = &ifconv;
return &p;
......
This diff is collapsed.
......@@ -67,13 +67,12 @@ static const arch_register_req_t no_register_req = {
*/
typedef struct constraint_t constraint_t;
struct constraint_t {
int is_in;
int n_outs;
const arch_register_req_t **out_reqs;
const arch_register_req_t *req;
unsigned immediate_possible;
char immediate_type;
const arch_register_class_t *cls;
unsigned allowed_registers;
bool all_registers_allowed;
bool memory_possible;
char immediate_type;
int same_as;
};
/**
......@@ -98,9 +97,9 @@ ir_type *ia32_get_prim_type(pmap *types, ir_mode *mode);
*/
int ia32_mode_needs_gp_reg(ir_mode *mode);
void parse_asm_constraint(int pos, constraint_t *constraint, const char *c);
void parse_clobber(ir_node *node, int pos, constraint_t *constraint,
const char *clobber);
void ia32_parse_asm_constraints(constraint_t *constraint, const char *c);
void ia32_parse_clobber(ir_node *node, int pos, constraint_t *constraint,
const char *clobber);
/**
* returns register by name (used for determining clobber specifications in
......
......@@ -25,11 +25,11 @@ static void sincostest(double arg)
printf("Arg: %f Sin: %f Cos: %f\n", arg, sin, cos);
}
static inline int mov(int val)
static inline int mov_noeax(int val)
{
int res;
__asm__ ("movl %1, %0" : "=r"(res) : "ri" (val));
__asm__ ("movl %1, %0" : "=r"(res) : "ri" (val) : "eax");
return res;
}
......@@ -46,9 +46,14 @@ static inline unsigned int swap32(unsigned int x)
return x;
}
static inline void inc(int *v)
void inc(int *v)
{
__asm__("incl %0" : "+g" (*v) : : "cc");
__asm__("incl %0" : "+rm" (*v) : : "cc");
}
void inc2(int *v)
{
__asm__("incl %0" : "+m" (*v) : : "cc");
}
#if 1
......@@ -61,7 +66,7 @@ typedef int kernel_fd_set;
#endif
void fd_set(int fd, kernel_fd_set* set) {
__asm__("btsl %1,%0" : "=m" (*(set)) : "r" (fd));
__asm__("btsl %1,%0" : "=m" (*(set)) : "r" (fd) : "cc");
}
int fd_isset(int fd, kernel_fd_set *set) {
......@@ -70,7 +75,8 @@ int fd_isset(int fd, kernel_fd_set *set) {
__asm__ __volatile__("btl %1,%2\n"
"\tsetb %0"
: "=q" (result)
: "r" (fd), "m" (*set));
: "r" (fd), "m" (*set)
: "cc");
return result;
}
......@@ -93,9 +99,9 @@ int main()
swap16(0xAABB), swap32(0xAABBCCDD));
k = 41;
inc(&k);
printf("mov(inc(41)): %d\n", mov(k));
printf("mov(inc(41)): %d\n", mov_noeax(k));
return mov(0);
return mov_noeax(0);
}
#else
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment