#if defined(__i386__) || defined(__386__)
#include <stdio.h>
+#include <string.h>
+#include <assert.h>
-#include "util/imports.h"
#include "main/execmem.h"
#include "x86sse.h"
/* Build a modRM byte + possible displacement. No treatment of SIB
* indexing. BZZT - no way to encode an absolute address.
*/
-static void emit_modrm( struct x86_function *p,
- struct x86_reg reg,
+static void emit_modrm( struct x86_function *p,
+ struct x86_reg reg,
struct x86_reg regmem )
{
unsigned char val = 0;
-
+
assert(reg.mod == mod_REG);
-
+
val |= regmem.mod << 6; /* mod field */
val |= reg.idx << 3; /* reg field */
val |= regmem.idx; /* r/m field */
-
+
emit_1ub(p, val);
/* Oh-oh we've stumbled into the SIB thing.
* the arguments presented.
*/
static void emit_op_modrm( struct x86_function *p,
- unsigned char op_dst_is_reg,
+ unsigned char op_dst_is_reg,
unsigned char op_dst_is_mem,
struct x86_reg dst,
struct x86_reg src )
-{
+{
switch (dst.mod) {
case mod_REG:
emit_1ub(p, op_dst_is_reg);
unsigned char *label )
{
int offset = label - (x86_get_label(p) + 2);
-
+
if (offset <= 127 && offset >= -128) {
emit_1ub(p, 0x70 + cc);
emit_1b(p, (char) offset);
struct x86_reg dst,
struct x86_reg src )
{
- assert(dst.file == file_MMX &&
+ assert(dst.file == file_MMX &&
(src.file == file_XMM || src.mod != mod_REG));
p->need_emms = 1;
void sse_shufps( struct x86_function *p,
struct x86_reg dest,
struct x86_reg arg0,
- unsigned char shuf)
+ unsigned char shuf)
{
emit_2ub(p, X86_TWOB, 0xC6);
emit_modrm(p, dest, arg0);
- emit_1ub(p, shuf);
+ emit_1ub(p, shuf);
}
void sse_cmpps( struct x86_function *p,
struct x86_reg dest,
struct x86_reg arg0,
- unsigned char cc)
+ unsigned char cc)
{
emit_2ub(p, X86_TWOB, 0xC2);
emit_modrm(p, dest, arg0);
- emit_1ub(p, cc);
+ emit_1ub(p, cc);
}
void sse_pmovmskb( struct x86_function *p,
void sse2_pshufd( struct x86_function *p,
struct x86_reg dest,
struct x86_reg arg0,
- unsigned char shuf)
+ unsigned char shuf)
{
emit_3ub(p, 0x66, X86_TWOB, 0x70);
emit_modrm(p, dest, arg0);
- emit_1ub(p, shuf);
+ emit_1ub(p, shuf);
}
void sse2_cvttps2dq( struct x86_function *p,
assert(dst.file == file_x87);
if (arg.file == file_x87) {
- if (dst.idx == 0)
+ if (dst.idx == 0)
emit_2ub(p, dst0ub0, dst0ub1+arg.idx);
- else if (arg.idx == 0)
+ else if (arg.idx == 0)
emit_2ub(p, arg0ub0, arg0ub1+arg.idx);
else
assert(0);
void x87_fmul( struct x86_function *p, struct x86_reg dst, struct x86_reg arg )
{
- x87_arith_op(p, dst, arg,
+ x87_arith_op(p, dst, arg,
0xd8, 0xc8,
0xdc, 0xc8,
4);
void x87_fsub( struct x86_function *p, struct x86_reg dst, struct x86_reg arg )
{
- x87_arith_op(p, dst, arg,
+ x87_arith_op(p, dst, arg,
0xd8, 0xe0,
0xdc, 0xe8,
4);
void x87_fsubr( struct x86_function *p, struct x86_reg dst, struct x86_reg arg )
{
- x87_arith_op(p, dst, arg,
+ x87_arith_op(p, dst, arg,
0xd8, 0xe8,
0xdc, 0xe0,
5);
void x87_fadd( struct x86_function *p, struct x86_reg dst, struct x86_reg arg )
{
- x87_arith_op(p, dst, arg,
+ x87_arith_op(p, dst, arg,
0xd8, 0xc0,
0xdc, 0xc0,
0);
void x87_fdiv( struct x86_function *p, struct x86_reg dst, struct x86_reg arg )
{
- x87_arith_op(p, dst, arg,
+ x87_arith_op(p, dst, arg,
0xd8, 0xf0,
0xdc, 0xf8,
6);
void x87_fdivr( struct x86_function *p, struct x86_reg dst, struct x86_reg arg )
{
- x87_arith_op(p, dst, arg,
+ x87_arith_op(p, dst, arg,
0xd8, 0xf8,
0xdc, 0xf0,
7);
/* st1 = st1 * log2(st0 + 1.0);
* pop_stack;
*
- * A fast operation, with restrictions: -.29 < st0 < .29
+ * A fast operation, with restrictions: -.29 < st0 < .29
*/
void x87_fyl2xp1( struct x86_function *p )
{
void x87_fld( struct x86_function *p, struct x86_reg arg )
{
- if (arg.file == file_x87)
+ if (arg.file == file_x87)
emit_2ub(p, 0xd9, 0xc0 + arg.idx);
else {
emit_1ub(p, 0xd9);
void x87_fst( struct x86_function *p, struct x86_reg dst )
{
- if (dst.file == file_x87)
+ if (dst.file == file_x87)
emit_2ub(p, 0xdd, 0xd0 + dst.idx);
else {
emit_1ub(p, 0xd9);
void x87_fstp( struct x86_function *p, struct x86_reg dst )
{
- if (dst.file == file_x87)
+ if (dst.file == file_x87)
emit_2ub(p, 0xdd, 0xd8 + dst.idx);
else {
emit_1ub(p, 0xd9);
void x87_fcom( struct x86_function *p, struct x86_reg dst )
{
- if (dst.file == file_x87)
+ if (dst.file == file_x87)
emit_2ub(p, 0xd8, 0xd0 + dst.idx);
else {
emit_1ub(p, 0xd8);
void x87_fcomp( struct x86_function *p, struct x86_reg dst )
{
- if (dst.file == file_x87)
+ if (dst.file == file_x87)
emit_2ub(p, 0xd8, 0xd8 + dst.idx);
else {
emit_1ub(p, 0xd8);
assert(dst.file == file_REG32);
if (dst.idx == reg_AX &&
- dst.mod == mod_REG)
+ dst.mod == mod_REG)
emit_2ub(p, 0xdf, 0xe0);
else {
emit_1ub(p, 0xdd);
struct x86_reg dst,
struct x86_reg src )
{
- assert(dst.file == file_MMX &&
+ assert(dst.file == file_MMX &&
(src.file == file_MMX || src.mod != mod_REG));
p->need_emms = 1;
struct x86_reg dst,
struct x86_reg src )
{
- assert(dst.file == file_MMX &&
+ assert(dst.file == file_MMX &&
(src.file == file_MMX || src.mod != mod_REG));
p->need_emms = 1;
struct x86_reg x86_fn_arg( struct x86_function *p,
unsigned arg )
{
- return x86_make_disp(x86_make_reg(file_REG32, reg_SP),
+ return x86_make_disp(x86_make_reg(file_REG32, reg_SP),
p->stack_offset + arg * 4); /* ??? */
}