From 1c904222268cde87246b3c2ca59f8ba989e2be09 Mon Sep 17 00:00:00 2001 From: Spoike Date: Tue, 21 Feb 2017 23:26:13 +0000 Subject: [PATCH] added support for vector bitwise operators emulation. fix some compile issues git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5061 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/cd_linux.c | 4 ++- engine/client/cd_null.c | 6 +++- engine/client/cd_sdl.c | 4 ++- engine/qclib/pr_comp.h | 5 ++++ engine/qclib/qcc_pr_comp.c | 60 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 3 deletions(-) diff --git a/engine/client/cd_linux.c b/engine/client/cd_linux.c index b491a9af0..a56d43bf0 100644 --- a/engine/client/cd_linux.c +++ b/engine/client/cd_linux.c @@ -22,7 +22,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" -#ifdef __CYGWIN__ +#ifndef HAVE_CDPLAYER + //nothing +#elif defined(__CYGWIN__) #include "cd_null.c" #else diff --git a/engine/client/cd_null.c b/engine/client/cd_null.c index 27cf341fc..0c48915ed 100644 --- a/engine/client/cd_null.c +++ b/engine/client/cd_null.c @@ -1,5 +1,8 @@ #include "quakedef.h" +#ifdef HAVE_CDPLAYER + //nothing + #ifdef _WIN32 //not really needed, but nice none-the-less. #include "winquake.h" @@ -53,4 +56,5 @@ int CDAudio_GetAudioDiskInfo(void) qboolean CDAudio_Startup(void) { return false; -} \ No newline at end of file +} +#endif diff --git a/engine/client/cd_sdl.c b/engine/client/cd_sdl.c index 051be11af..f39cdf80a 100644 --- a/engine/client/cd_sdl.c +++ b/engine/client/cd_sdl.c @@ -2,7 +2,9 @@ #include -#if SDL_MAJOR_VERSION >= 2 +#ifndef HAVE_CDPLAYER + //nothing +#elif SDL_MAJOR_VERSION >= 2 //sdl2 has no cd support. sod off. #include "cd_null.c" #else diff --git a/engine/qclib/pr_comp.h b/engine/qclib/pr_comp.h index 93d150a6c..12a407288 100644 --- a/engine/qclib/pr_comp.h +++ b/engine/qclib/pr_comp.h @@ -417,6 +417,11 @@ enum qcop_e { OP_SUB_EI, OP_SUB_EF, + OP_BITAND_V, + OP_BITOR_V, + OP_BITNOT_V, + OP_BITXOR_V, + OP_NUMOPS }; diff --git a/engine/qclib/qcc_pr_comp.c b/engine/qclib/qcc_pr_comp.c index 032a8b818..771d8ce25 100644 --- a/engine/qclib/qcc_pr_comp.c +++ b/engine/qclib/qcc_pr_comp.c @@ -681,6 +681,11 @@ QCC_opcode_t pr_opcodes[] = {7, "-", "SUB_EI", 4, ASSOC_LEFT, &type_entity, &type_integer, &type_entity}, {7, "-", "SUB_EF", 4, ASSOC_LEFT, &type_entity, &type_float, &type_entity}, + {7, "&", "BITAND_V", 5, ASSOC_LEFT, &type_vector, &type_vector, &type_vector}, + {7, "|", "BITOR_V", 5, ASSOC_LEFT, &type_vector, &type_vector, &type_vector}, + {7, "~", "BITNOT_V", -1, ASSOC_LEFT, &type_vector, &type_void, &type_vector}, + {7, "^", "BITXOR_V", 3, ASSOC_LEFT, &type_vector, &type_vector, &type_vector}, + {0, NULL} }; @@ -932,6 +937,7 @@ QCC_opcode_t *opcodes_orstore[] = &pr_opcodes[OP_BITOR_I], &pr_opcodes[OP_BITOR_IF], &pr_opcodes[OP_BITOR_FI], + &pr_opcodes[OP_BITOR_V], NULL }; QCC_opcode_t *opcodes_orstorep[] = @@ -943,6 +949,7 @@ QCC_opcode_t *opcodes_xorstore[] = { &pr_opcodes[OP_BITXOR_I], &pr_opcodes[OP_BITXOR_F], + &pr_opcodes[OP_BITXOR_V], NULL }; QCC_opcode_t *opcodes_andstore[] = @@ -951,6 +958,7 @@ QCC_opcode_t *opcodes_andstore[] = &pr_opcodes[OP_BITAND_I], &pr_opcodes[OP_BITAND_IF], &pr_opcodes[OP_BITAND_FI], + &pr_opcodes[OP_BITAND_V], NULL }; QCC_opcode_t *opcodes_clearstore[] = @@ -1038,14 +1046,17 @@ QCC_opcode_t *opcodeprioritized[TOP_PRIORITY+1][128] = &pr_opcodes[OP_BITAND_I], &pr_opcodes[OP_BITAND_IF], &pr_opcodes[OP_BITAND_FI], + &pr_opcodes[OP_BITAND_V], &pr_opcodes[OP_BITOR_F], &pr_opcodes[OP_BITOR_I], &pr_opcodes[OP_BITOR_IF], &pr_opcodes[OP_BITOR_FI], + &pr_opcodes[OP_BITOR_V], &pr_opcodes[OP_BITXOR_I], &pr_opcodes[OP_BITXOR_F], + &pr_opcodes[OP_BITXOR_V], &pr_opcodes[OP_RSHIFT_I], &pr_opcodes[OP_RSHIFT_F], @@ -2346,10 +2357,24 @@ QCC_sref_t QCC_PR_StatementFlags ( QCC_opcode_t *op, QCC_sref_t var_a, QCC_sref_ QCC_FreeTemp(var_a); QCC_FreeTemp(var_b); optres_constantarithmatic++; return QCC_MakeFloatConst(QCC_PR_RoundFloatConst(eval_a) | QCC_PR_RoundFloatConst(eval_b)); + case OP_BITOR_V: + QCC_FreeTemp(var_a); QCC_FreeTemp(var_b); + optres_constantarithmatic++; + return QCC_MakeVectorConst( + (int)eval_a->vector[0] | (int)eval_b->vector[0], + (int)eval_a->vector[1] | (int)eval_b->vector[1], + (int)eval_a->vector[2] | (int)eval_b->vector[2]); case OP_BITAND_F: QCC_FreeTemp(var_a); QCC_FreeTemp(var_b); optres_constantarithmatic++; return QCC_MakeFloatConst(QCC_PR_RoundFloatConst(eval_a) & QCC_PR_RoundFloatConst(eval_b)); + case OP_BITAND_V: + QCC_FreeTemp(var_a); QCC_FreeTemp(var_b); + optres_constantarithmatic++; + return QCC_MakeVectorConst( + (int)eval_a->vector[0] & (int)eval_b->vector[0], + (int)eval_a->vector[1] & (int)eval_b->vector[1], + (int)eval_a->vector[2] & (int)eval_b->vector[2]); case OP_MUL_F: QCC_FreeTemp(var_a); QCC_FreeTemp(var_b); optres_constantarithmatic++; @@ -2624,6 +2649,9 @@ QCC_sref_t QCC_PR_StatementFlags ( QCC_opcode_t *op, QCC_sref_t var_a, QCC_sref_ case OP_BITNOT_I: QCC_FreeTemp(var_a); return QCC_MakeIntConst(~eval_a->_int); + case OP_BITNOT_V: + QCC_FreeTemp(var_a); + return QCC_MakeVectorConst(~(int)eval_a->vector[0], ~(int)eval_a->vector[1], ~(int)eval_a->vector[2]); case OP_CONV_FTOI: QCC_FreeTemp(var_a); optres_constantarithmatic++; @@ -3241,6 +3269,22 @@ QCC_sref_t QCC_PR_StatementFlags ( QCC_opcode_t *op, QCC_sref_t var_a, QCC_sref_ return var_c; } break; + case OP_BITAND_V: + case OP_BITOR_V: + op = &pr_opcodes[((op - pr_opcodes)==OP_BITAND_V)?OP_BITAND_F:OP_BITOR_F]; + var_c = QCC_GetTemp(type_vector); + var_a.cast = type_float; + var_b.cast = type_float; + var_c.cast = type_float; + QCC_PR_SimpleStatement(op, var_a, var_b, var_c, true); + var_a.ofs++; var_b.ofs++; var_c.ofs++; + QCC_PR_SimpleStatement(op, var_a, var_b, var_c, true); + var_a.ofs++; var_b.ofs++; var_c.ofs++; + QCC_PR_SimpleStatement(op, var_a, var_b, var_c, true); + var_a.ofs++; var_b.ofs++; var_c.ofs++; + var_c.cast = type_vector; + var_c.ofs -= 3; + return var_c; case OP_ADD_I: { QCC_sref_t fnc = QCC_PR_GetSRef(NULL, "AddInt", NULL, false, 0, 0); @@ -3393,6 +3437,14 @@ QCC_sref_t QCC_PR_StatementFlags ( QCC_opcode_t *op, QCC_sref_t var_a, QCC_sref_ var_a = QCC_PR_StatementFlags(&pr_opcodes[OP_BITAND_F], var_b, var_a, NULL, 0); return QCC_PR_StatementFlags(&pr_opcodes[OP_BITOR_F], var_c, var_a, NULL, 0); + case OP_BITXOR_V: +// r = (a & ~b) | (b & ~a); + var_c = QCC_PR_StatementFlags(&pr_opcodes[OP_BITNOT_V], var_b, nullsref, NULL, STFL_PRESERVEA); + var_c = QCC_PR_StatementFlags(&pr_opcodes[OP_BITAND_V], var_a, var_c, NULL, STFL_PRESERVEA); + var_a = QCC_PR_StatementFlags(&pr_opcodes[OP_BITNOT_V], var_a, nullsref, NULL, 0); + var_a = QCC_PR_StatementFlags(&pr_opcodes[OP_BITAND_V], var_b, var_a, NULL, 0); + return QCC_PR_StatementFlags(&pr_opcodes[OP_BITOR_V], var_c, var_a, NULL, 0); + case OP_IF_S: tmp = QCC_MakeFloatConst(0); tmp.cast = type_string; @@ -3481,6 +3533,12 @@ QCC_sref_t QCC_PR_StatementFlags ( QCC_opcode_t *op, QCC_sref_t var_a, QCC_sref_ var_b = var_a; var_a = QCC_MakeFloatConst(-1); //divVerent says -1 is safe, even with floats. I guess I'm just too paranoid. break; + case OP_BITNOT_V: + op = &pr_opcodes[OP_SUB_V]; + var_b = var_a; + var_a = QCC_MakeVectorConst(-1, -1, -1); + var_a.sym->referenced=true; + break; case OP_DIVSTORE_F: op = &pr_opcodes[OP_DIV_F]; @@ -7599,6 +7657,8 @@ QCC_ref_t *QCC_PR_RefTerm (QCC_ref_t *retbuf, unsigned int exprflags) e2 = QCC_PR_Statement (&pr_opcodes[OP_BITNOT_F], e, nullsref, NULL); else if (t == ev_integer) e2 = QCC_PR_Statement (&pr_opcodes[OP_BITNOT_I], e, nullsref, NULL); //functions are integer values too. + else if (t == ev_vector) + e2 = QCC_PR_Statement (&pr_opcodes[OP_BITNOT_V], e, nullsref, NULL); //functions are integer values too. else { e2 = nullsref; // shut up compiler warning;