2013-11-25 03:13:10 +08:00
|
|
|
#ifndef NASM_IFLAG_H
|
|
|
|
#define NASM_IFLAG_H
|
|
|
|
|
|
|
|
#include "compiler.h"
|
2017-09-28 04:34:42 +08:00
|
|
|
#include "ilog2.h"
|
2013-11-25 03:13:10 +08:00
|
|
|
|
2018-02-07 06:43:07 +08:00
|
|
|
#include <string.h>
|
2013-11-25 03:13:10 +08:00
|
|
|
|
|
|
|
#include "iflaggen.h"
|
|
|
|
|
|
|
|
#define IF_GENBIT(bit) (UINT32_C(1) << (bit))
|
|
|
|
|
2018-02-07 06:43:07 +08:00
|
|
|
static inline bool iflag_test(const iflag_t *f, unsigned int bit)
|
2013-11-25 03:13:10 +08:00
|
|
|
{
|
2018-02-07 06:43:07 +08:00
|
|
|
return !!(f->field[bit >> 5] & IF_GENBIT(bit & 31));
|
2013-11-25 03:13:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void iflag_set(iflag_t *f, unsigned int bit)
|
|
|
|
{
|
2018-02-07 06:43:07 +08:00
|
|
|
f->field[bit >> 5] |= IF_GENBIT(bit & 31);
|
2013-11-25 03:13:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void iflag_clear(iflag_t *f, unsigned int bit)
|
|
|
|
{
|
2018-02-07 06:43:07 +08:00
|
|
|
f->field[bit >> 5] &= ~IF_GENBIT(bit & 31);
|
2013-11-25 03:13:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void iflag_clear_all(iflag_t *f)
|
|
|
|
{
|
|
|
|
memset(f, 0, sizeof(*f));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void iflag_set_all(iflag_t *f)
|
|
|
|
{
|
2018-02-07 06:43:07 +08:00
|
|
|
memset(f, ~0, sizeof(*f));
|
2013-11-25 03:13:10 +08:00
|
|
|
}
|
|
|
|
|
2018-02-07 06:43:07 +08:00
|
|
|
#define iflag_for_each_field(v) for ((v) = 0; (v) < IF_FIELD_COUNT; (v)++)
|
|
|
|
|
2013-11-25 09:13:20 +08:00
|
|
|
static inline int iflag_cmp(const iflag_t *a, const iflag_t *b)
|
2013-11-25 03:13:10 +08:00
|
|
|
{
|
2013-11-27 07:21:15 +08:00
|
|
|
int i;
|
2013-11-25 03:13:10 +08:00
|
|
|
|
2018-02-07 06:43:07 +08:00
|
|
|
/* This is intentionally a reverse loop! */
|
|
|
|
for (i = IF_FIELD_COUNT-1; i >= 0; i--) {
|
2013-11-28 05:41:50 +08:00
|
|
|
if (a->field[i] == b->field[i])
|
|
|
|
continue;
|
|
|
|
|
2018-02-07 06:43:07 +08:00
|
|
|
return (int)(a->field[i] - b->field[i]);
|
2013-11-25 03:13:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define IF_GEN_HELPER(name, op) \
|
2013-11-25 09:13:20 +08:00
|
|
|
static inline iflag_t iflag_##name(const iflag_t *a, const iflag_t *b) \
|
2013-11-25 03:13:10 +08:00
|
|
|
{ \
|
|
|
|
unsigned int i; \
|
|
|
|
iflag_t res; \
|
|
|
|
\
|
2018-02-07 06:43:07 +08:00
|
|
|
iflag_for_each_field(i) \
|
2013-11-25 03:13:10 +08:00
|
|
|
res.field[i] = a->field[i] op b->field[i]; \
|
|
|
|
\
|
|
|
|
return res; \
|
|
|
|
}
|
|
|
|
|
|
|
|
IF_GEN_HELPER(xor, ^)
|
|
|
|
|
|
|
|
/* Some helpers which are to work with predefined masks */
|
|
|
|
#define IF_SMASK \
|
|
|
|
(IF_GENBIT(IF_SB) |\
|
|
|
|
IF_GENBIT(IF_SW) |\
|
|
|
|
IF_GENBIT(IF_SD) |\
|
|
|
|
IF_GENBIT(IF_SQ) |\
|
|
|
|
IF_GENBIT(IF_SO) |\
|
|
|
|
IF_GENBIT(IF_SY) |\
|
|
|
|
IF_GENBIT(IF_SZ) |\
|
|
|
|
IF_GENBIT(IF_SIZE))
|
|
|
|
#define IF_ARMASK \
|
|
|
|
(IF_GENBIT(IF_AR0) |\
|
|
|
|
IF_GENBIT(IF_AR1) |\
|
|
|
|
IF_GENBIT(IF_AR2) |\
|
|
|
|
IF_GENBIT(IF_AR3) |\
|
|
|
|
IF_GENBIT(IF_AR4))
|
|
|
|
|
2013-11-25 09:14:34 +08:00
|
|
|
#define _itemp_smask(idx) (insns_flags[(idx)].field[0] & IF_SMASK)
|
|
|
|
#define _itemp_armask(idx) (insns_flags[(idx)].field[0] & IF_ARMASK)
|
|
|
|
#define _itemp_arg(idx) ((_itemp_armask(idx) >> IF_AR0) - 1)
|
2013-11-25 03:13:10 +08:00
|
|
|
|
2013-11-25 09:14:34 +08:00
|
|
|
#define itemp_smask(itemp) _itemp_smask((itemp)->iflag_idx)
|
|
|
|
#define itemp_arg(itemp) _itemp_arg((itemp)->iflag_idx)
|
|
|
|
#define itemp_armask(itemp) _itemp_armask((itemp)->iflag_idx)
|
2013-11-25 03:13:10 +08:00
|
|
|
|
2018-02-07 06:43:07 +08:00
|
|
|
/*
|
|
|
|
* IF_8086 is the first CPU level flag and IF_PLEVEL the last
|
|
|
|
*/
|
|
|
|
#if IF_8086 & 31
|
|
|
|
#error "IF_8086 must be on a uint32_t boundary"
|
|
|
|
#endif
|
|
|
|
#define IF_PLEVEL IF_IA64
|
|
|
|
#define IF_CPU_FIELD (IF_8086 >> 5)
|
|
|
|
#define IF_CPU_LEVEL_MASK ((IF_GENBIT(IF_PLEVEL & 31) << 1) - 1)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IF_PRIV is the firstr instruction filtering flag
|
|
|
|
*/
|
|
|
|
#if IF_PRIV & 31
|
|
|
|
#error "IF_PRIV must be on a uint32_t boundary"
|
|
|
|
#endif
|
|
|
|
#define IF_FEATURE_FIELD (IF_PRIV >> 5)
|
|
|
|
|
|
|
|
static inline int iflag_cmp_cpu(const iflag_t *a, const iflag_t *b)
|
|
|
|
{
|
|
|
|
return (int)(a->field[IF_CPU_FIELD] - b->field[IF_CPU_FIELD]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t _iflag_cpu_level(const iflag_t *a)
|
|
|
|
{
|
|
|
|
return a->field[IF_CPU_FIELD] & IF_CPU_LEVEL_MASK;
|
|
|
|
}
|
|
|
|
|
2013-11-25 09:13:20 +08:00
|
|
|
static inline int iflag_cmp_cpu_level(const iflag_t *a, const iflag_t *b)
|
2013-11-25 03:13:10 +08:00
|
|
|
{
|
2018-02-07 06:43:07 +08:00
|
|
|
uint32_t aa = _iflag_cpu_level(a);
|
|
|
|
uint32_t bb = _iflag_cpu_level(b);
|
2013-11-25 03:13:10 +08:00
|
|
|
|
2018-02-07 06:43:07 +08:00
|
|
|
return (int)(aa - bb);
|
|
|
|
}
|
2013-11-25 03:13:10 +08:00
|
|
|
|
2018-02-07 06:43:07 +08:00
|
|
|
/* Returns true if the CPU level is at least a certain value */
|
|
|
|
static inline bool iflag_cpu_level_ok(const iflag_t *a, unsigned int bit)
|
|
|
|
{
|
|
|
|
return _iflag_cpu_level(a) >= IF_GENBIT(bit & 31);
|
|
|
|
}
|
2013-11-25 03:13:10 +08:00
|
|
|
|
2018-02-07 06:43:07 +08:00
|
|
|
static inline void iflag_set_all_features(iflag_t *a)
|
|
|
|
{
|
|
|
|
size_t i;
|
2013-11-25 03:13:10 +08:00
|
|
|
|
2018-02-07 06:43:07 +08:00
|
|
|
for (i = IF_FEATURE_FIELD; i < IF_CPU_FIELD; i++)
|
|
|
|
a->field[i] = ~UINT32_C(0);
|
|
|
|
}
|
2013-11-25 03:13:10 +08:00
|
|
|
|
2018-02-07 06:43:07 +08:00
|
|
|
static inline void iflag_set_cpu(iflag_t *a, unsigned int cpu)
|
|
|
|
{
|
|
|
|
a->field[0] = 0; /* Not applicable to the CPU type */
|
|
|
|
iflag_set_all_features(a); /* All feature masking bits set for now */
|
|
|
|
a->field[IF_CPU_FIELD] &= ~IF_CPU_LEVEL_MASK;
|
|
|
|
iflag_set(a, cpu);
|
|
|
|
}
|
2013-11-25 03:13:10 +08:00
|
|
|
|
2018-02-07 06:43:07 +08:00
|
|
|
static inline void iflag_set_default_cpu(iflag_t *a)
|
|
|
|
{
|
|
|
|
iflag_set_cpu(a, IF_PLEVEL);
|
2013-11-25 03:13:10 +08:00
|
|
|
}
|
|
|
|
|
2013-11-25 09:14:34 +08:00
|
|
|
static inline iflag_t _iflag_pfmask(const iflag_t *a)
|
2013-11-25 03:13:10 +08:00
|
|
|
{
|
2013-12-10 15:09:49 +08:00
|
|
|
iflag_t r;
|
|
|
|
|
|
|
|
iflag_clear_all(&r);
|
2013-11-25 03:13:10 +08:00
|
|
|
|
2013-12-07 20:14:00 +08:00
|
|
|
if (iflag_test(a, IF_CYRIX))
|
|
|
|
iflag_set(&r, IF_CYRIX);
|
|
|
|
if (iflag_test(a, IF_AMD))
|
|
|
|
iflag_set(&r, IF_AMD);
|
2013-11-25 03:13:10 +08:00
|
|
|
|
2013-12-07 20:14:00 +08:00
|
|
|
return r;
|
2013-11-25 03:13:10 +08:00
|
|
|
}
|
|
|
|
|
2013-12-07 20:14:00 +08:00
|
|
|
#define iflag_pfmask(itemp) _iflag_pfmask(&insns_flags[(itemp)->iflag_idx])
|
2013-11-25 03:13:10 +08:00
|
|
|
|
2013-11-25 09:14:34 +08:00
|
|
|
#endif /* NASM_IFLAG_H */
|