comparison gen_x86.c @ 487:c08a4efeee7f opengl

Update opengl branch from default. Fix build breakage unrelated to merge
author Mike Pavone <pavone@retrodev.com>
date Sat, 26 Oct 2013 22:38:47 -0700
parents 0bf5e6b672fe
children 96489fb27dbf
comparison
equal deleted inserted replaced
449:7696d824489d 487:c08a4efeee7f
1 /*
2 Copyright 2013 Michael Pavone
3 This file is part of BlastEm.
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
5 */
1 #include "gen_x86.h" 6 #include "gen_x86.h"
2 #include "68kinst.h" 7 #include "68kinst.h"
3 #include <stddef.h> 8 #include <stddef.h>
4 #include <stdio.h> 9 #include <stdio.h>
5 #include <stdlib.h> 10 #include <stdlib.h>
23 #define OP_POP 0x58 28 #define OP_POP 0x58
24 #define OP_MOVSXD 0x63 29 #define OP_MOVSXD 0x63
25 #define PRE_SIZE 0x66 30 #define PRE_SIZE 0x66
26 #define OP_JCC 0x70 31 #define OP_JCC 0x70
27 #define OP_IMMED_ARITH 0x80 32 #define OP_IMMED_ARITH 0x80
33 #define OP_TEST 0x84
28 #define OP_XCHG 0x86 34 #define OP_XCHG 0x86
29 #define OP_MOV 0x88 35 #define OP_MOV 0x88
30 #define OP_XCHG_AX 0x90 36 #define OP_XCHG_AX 0x90
31 #define OP_CDQ 0x99 37 #define OP_CDQ 0x99
32 #define OP_PUSHF 0x9C 38 #define OP_PUSHF 0x9C
423 } 429 }
424 430
425 uint8_t * x86_ir(uint8_t * out, uint8_t opcode, uint8_t op_ex, uint8_t al_opcode, int32_t val, uint8_t dst, uint8_t size) 431 uint8_t * x86_ir(uint8_t * out, uint8_t opcode, uint8_t op_ex, uint8_t al_opcode, int32_t val, uint8_t dst, uint8_t size)
426 { 432 {
427 uint8_t sign_extend = 0; 433 uint8_t sign_extend = 0;
428 if ((size == SZ_D || size == SZ_Q) && val <= 0x7F && val >= -0x80) { 434 if (opcode != OP_NOT_NEG && (size == SZ_D || size == SZ_Q) && val <= 0x7F && val >= -0x80) {
429 sign_extend = 1; 435 sign_extend = 1;
430 opcode |= BIT_DIR; 436 opcode |= BIT_DIR;
431 } 437 }
432 if (size == SZ_W) { 438 if (size == SZ_W) {
433 *(out++) = PRE_SIZE; 439 *(out++) = PRE_SIZE;
1016 uint8_t * cmp_rdisp8r(uint8_t * out, uint8_t src_base, int8_t disp, uint8_t dst, uint8_t size) 1022 uint8_t * cmp_rdisp8r(uint8_t * out, uint8_t src_base, int8_t disp, uint8_t dst, uint8_t size)
1017 { 1023 {
1018 return x86_rrdisp8_sizedir(out, OP_CMP, dst, src_base, disp, size, BIT_DIR); 1024 return x86_rrdisp8_sizedir(out, OP_CMP, dst, src_base, disp, size, BIT_DIR);
1019 } 1025 }
1020 1026
1027 uint8_t * test_rr(uint8_t * out, uint8_t src, uint8_t dst, uint8_t size)
1028 {
1029 return x86_rr_sizedir(out, OP_TEST, src, dst, size);
1030 }
1031
1032 uint8_t * test_ir(uint8_t * out, int32_t val, uint8_t dst, uint8_t size)
1033 {
1034 return x86_ir(out, OP_NOT_NEG, OP_EX_TEST_I, OP_TEST, val, dst, size);
1035 }
1036
1037 uint8_t * test_irdisp8(uint8_t * out, int32_t val, uint8_t dst_base, int8_t disp, uint8_t size)
1038 {
1039 return x86_irdisp8(out, OP_NOT_NEG, OP_EX_TEST_I, val, dst_base, disp, size);
1040 }
1041
1042 uint8_t * test_rrdisp8(uint8_t * out, uint8_t src, uint8_t dst_base, int8_t disp, uint8_t size)
1043 {
1044 return x86_rrdisp8_sizedir(out, OP_TEST, src, dst_base, disp, size, 0);
1045 }
1046
1047 uint8_t * test_rdisp8r(uint8_t * out, uint8_t src_base, int8_t disp, uint8_t dst, uint8_t size)
1048 {
1049 return x86_rrdisp8_sizedir(out, OP_TEST, dst, src_base, disp, size, BIT_DIR);
1050 }
1051
1021 uint8_t * imul_rr(uint8_t * out, uint8_t src, uint8_t dst, uint8_t size) 1052 uint8_t * imul_rr(uint8_t * out, uint8_t src, uint8_t dst, uint8_t size)
1022 { 1053 {
1023 return x86_rr_sizedir(out, OP2_IMUL | (PRE_2BYTE << 8), dst, src, size); 1054 return x86_rr_sizedir(out, OP2_IMUL | (PRE_2BYTE << 8), dst, src, size);
1024 } 1055 }
1025 1056
1132 { 1163 {
1133 return x86_rrindex_sizedir(out, OP_MOV, dst, src_base, src_index, scale, size, BIT_DIR); 1164 return x86_rrindex_sizedir(out, OP_MOV, dst, src_base, src_index, scale, size, BIT_DIR);
1134 } 1165 }
1135 1166
1136 uint8_t * mov_ir(uint8_t * out, int64_t val, uint8_t dst, uint8_t size) 1167 uint8_t * mov_ir(uint8_t * out, int64_t val, uint8_t dst, uint8_t size)
1137 { 1168 {
1138 uint8_t sign_extend = 0; 1169 uint8_t sign_extend = 0;
1139 if (size == SZ_Q && val <= 0x7FFFFFFF && val >= -2147483648) { 1170 if (size == SZ_Q && val <= 0x7FFFFFFF && val >= -2147483648) {
1140 sign_extend = 1; 1171 sign_extend = 1;
1141 } 1172 }
1142 if (size == SZ_W) { 1173 if (size == SZ_W) {