make MUL_VF and MUL_FV friendlier for compilers, and fix segfaul in LOAD_V
[xonotic/darkplaces.git] / prvm_execprogram.h
1 #ifdef PRVMTIMEPROFILING 
2 #define PreError() \
3         prog->xstatement = st - prog->statements; \
4         tm = Sys_DirtyTime(); \
5         prog->xfunction->profile += (st - startst); \
6         prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
7 #else
8 #define PreError() \
9         prog->xstatement = st - prog->statements; \
10         prog->xfunction->profile += (st - startst);
11 #endif
12
13 // This code isn't #ifdef/#define protectable, don't try.
14
15 #if PRVMSLOWINTERPRETER
16                 {
17                         if (prog->watch_global_type != ev_void)
18                         {
19                                 prvm_eval_t *f = PRVM_GLOBALFIELDVALUE(prog->watch_global);
20                                 prog->xstatement = st + 1 - prog->statements;
21                                 PRVM_Watchpoint(prog, 1, "Global watchpoint hit by engine", prog->watch_global_type, &prog->watch_global_value, f);
22                         }
23                         if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
24                         {
25                                 prvm_eval_t *f = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
26                                 prog->xstatement = st + 1 - prog->statements;
27                                 PRVM_Watchpoint(prog, 1, "Entityfield watchpoint hit by engine", prog->watch_field_type, &prog->watch_edictfield_value, f);
28                         }
29                 }
30 #endif
31
32                 while (1)
33                 {
34                         st++;
35
36 #if PRVMSLOWINTERPRETER
37                         if (prog->trace)
38                                 PRVM_PrintStatement(prog, st);
39                         prog->statement_profile[st - prog->statements]++;
40                         if (prog->break_statement >= 0)
41                                 if ((st - prog->statements) == prog->break_statement)
42                                 {
43                                         prog->xstatement = st - prog->statements;
44                                         PRVM_Breakpoint(prog, prog->break_stack_index, "Breakpoint hit");
45                                 }
46 #endif
47
48                         switch (st->op)
49                         {
50                         case OP_ADD_F:
51                                 OPC->_float = OPA->_float + OPB->_float;
52                                 break;
53                         case OP_ADD_V:
54                                 OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
55                                 OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
56                                 OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
57                                 break;
58                         case OP_SUB_F:
59                                 OPC->_float = OPA->_float - OPB->_float;
60                                 break;
61                         case OP_SUB_V:
62                                 OPC->vector[0] = OPA->vector[0] - OPB->vector[0];
63                                 OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
64                                 OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
65                                 break;
66                         case OP_MUL_F:
67                                 OPC->_float = OPA->_float * OPB->_float;
68                                 break;
69                         case OP_MUL_V:
70                                 OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
71                                 break;
72                         case OP_MUL_FV:
73                                 tempfloat = OPA->_float;
74                                 OPC->vector[0] = tempfloat * OPB->vector[0];
75                                 OPC->vector[1] = tempfloat * OPB->vector[1];
76                                 OPC->vector[2] = tempfloat * OPB->vector[2];
77                                 break;
78                         case OP_MUL_VF:
79                                 tempfloat = OPB->_float;
80                                 OPC->vector[0] = tempfloat * OPA->vector[0];
81                                 OPC->vector[1] = tempfloat * OPA->vector[1];
82                                 OPC->vector[2] = tempfloat * OPA->vector[2];
83                                 break;
84                         case OP_DIV_F:
85                                 if( OPB->_float != 0.0f )
86                                 {
87                                         OPC->_float = OPA->_float / OPB->_float;
88                                 }
89                                 else
90                                 {
91                                         if (developer.integer)
92                                         {
93                                                 prog->xfunction->profile += (st - startst);
94                                                 startst = st;
95                                                 prog->xstatement = st - prog->statements;
96                                                 VM_Warning(prog, "Attempted division by zero in %s\n", prog->name );
97                                         }
98                                         OPC->_float = 0.0f;
99                                 }
100                                 break;
101                         case OP_BITAND:
102                                 OPC->_float = (prvm_int_t)OPA->_float & (prvm_int_t)OPB->_float;
103                                 break;
104                         case OP_BITOR:
105                                 OPC->_float = (prvm_int_t)OPA->_float | (prvm_int_t)OPB->_float;
106                                 break;
107                         case OP_GE:
108                                 OPC->_float = OPA->_float >= OPB->_float;
109                                 break;
110                         case OP_LE:
111                                 OPC->_float = OPA->_float <= OPB->_float;
112                                 break;
113                         case OP_GT:
114                                 OPC->_float = OPA->_float > OPB->_float;
115                                 break;
116                         case OP_LT:
117                                 OPC->_float = OPA->_float < OPB->_float;
118                                 break;
119                         case OP_AND:
120                                 OPC->_float = FLOAT_IS_TRUE_FOR_INT(OPA->_int) && FLOAT_IS_TRUE_FOR_INT(OPB->_int); // TODO change this back to float, and add AND_I to be used by fteqcc for anything not a float
121                                 break;
122                         case OP_OR:
123                                 OPC->_float = FLOAT_IS_TRUE_FOR_INT(OPA->_int) || FLOAT_IS_TRUE_FOR_INT(OPB->_int); // TODO change this back to float, and add OR_I to be used by fteqcc for anything not a float
124                                 break;
125                         case OP_NOT_F:
126                                 OPC->_float = !FLOAT_IS_TRUE_FOR_INT(OPA->_int);
127                                 break;
128                         case OP_NOT_V:
129                                 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
130                                 break;
131                         case OP_NOT_S:
132                                 OPC->_float = !OPA->string || !*PRVM_GetString(prog, OPA->string);
133                                 break;
134                         case OP_NOT_FNC:
135                                 OPC->_float = !OPA->function;
136                                 break;
137                         case OP_NOT_ENT:
138                                 OPC->_float = (OPA->edict == 0);
139                                 break;
140                         case OP_EQ_F:
141                                 OPC->_float = OPA->_float == OPB->_float;
142                                 break;
143                         case OP_EQ_V:
144                                 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
145                                 break;
146                         case OP_EQ_S:
147                                 OPC->_float = !strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
148                                 break;
149                         case OP_EQ_E:
150                                 OPC->_float = OPA->_int == OPB->_int;
151                                 break;
152                         case OP_EQ_FNC:
153                                 OPC->_float = OPA->function == OPB->function;
154                                 break;
155                         case OP_NE_F:
156                                 OPC->_float = OPA->_float != OPB->_float;
157                                 break;
158                         case OP_NE_V:
159                                 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
160                                 break;
161                         case OP_NE_S:
162                                 OPC->_float = strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
163                                 break;
164                         case OP_NE_E:
165                                 OPC->_float = OPA->_int != OPB->_int;
166                                 break;
167                         case OP_NE_FNC:
168                                 OPC->_float = OPA->function != OPB->function;
169                                 break;
170
171                 //==================
172                         case OP_STORE_F:
173                         case OP_STORE_ENT:
174                         case OP_STORE_FLD:              // integers
175                         case OP_STORE_S:
176                         case OP_STORE_FNC:              // pointers
177                                 OPB->_int = OPA->_int;
178                                 break;
179                         case OP_STORE_V:
180                                 OPB->ivector[0] = OPA->ivector[0];
181                                 OPB->ivector[1] = OPA->ivector[1];
182                                 OPB->ivector[2] = OPA->ivector[2];
183                                 break;
184
185                         case OP_STOREP_F:
186                         case OP_STOREP_ENT:
187                         case OP_STOREP_FLD:             // integers
188                         case OP_STOREP_S:
189                         case OP_STOREP_FNC:             // pointers
190                                 if (OPB->_int < 0 || OPB->_int + 1 > prog->entityfieldsarea)
191                                 {
192                                         PreError();
193                                         prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
194                                         goto cleanup;
195                                 }
196                                 if (OPB->_int < prog->entityfields && !prog->allowworldwrites)
197                                 {
198                                         prog->xstatement = st - prog->statements;
199                                         VM_Warning(prog, "assignment to world.%s (field %i) in %s\n", PRVM_GetString(prog, PRVM_ED_FieldAtOfs(prog, OPB->_int)->s_name), (int)OPB->_int, prog->name);
200                                 }
201                                 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
202                                 ptr->_int = OPA->_int;
203                                 break;
204                         case OP_STOREP_V:
205                                 if (OPB->_int < 0 || OPB->_int + 3 > prog->entityfieldsarea)
206                                 {
207                                         PreError();
208                                         prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
209                                         goto cleanup;
210                                 }
211                                 if (OPB->_int < prog->entityfields && !prog->allowworldwrites)
212                                 {
213                                         prog->xstatement = st - prog->statements;
214                                         VM_Warning(prog, "assignment to world.%s (field %i) in %s\n", PRVM_GetString(prog, PRVM_ED_FieldAtOfs(prog, OPB->_int)->s_name), (int)OPB->_int, prog->name);
215                                 }
216                                 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
217                                 ptr->ivector[0] = OPA->ivector[0];
218                                 ptr->ivector[1] = OPA->ivector[1];
219                                 ptr->ivector[2] = OPA->ivector[2];
220                                 break;
221
222                         case OP_ADDRESS:
223                                 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
224                                 {
225                                         PreError();
226                                         prog->error_cmd("%s Progs attempted to address an out of bounds edict number", prog->name);
227                                         goto cleanup;
228                                 }
229                                 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->entityfields))
230                                 {
231                                         PreError();
232                                         prog->error_cmd("%s attempted to address an invalid field (%i) in an edict", prog->name, (int)OPB->_int);
233                                         goto cleanup;
234                                 }
235 #if 0
236                                 if (OPA->edict == 0 && !prog->allowworldwrites)
237                                 {
238                                         PreError();
239                                         prog->error_cmd("forbidden assignment to null/world entity in %s", prog->name);
240                                         goto cleanup;
241                                 }
242 #endif
243                                 ed = PRVM_PROG_TO_EDICT(OPA->edict);
244                                 OPC->_int = ed->fields.fp - prog->edictsfields + OPB->_int;
245                                 break;
246
247                         case OP_LOAD_F:
248                         case OP_LOAD_FLD:
249                         case OP_LOAD_ENT:
250                         case OP_LOAD_S:
251                         case OP_LOAD_FNC:
252                                 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
253                                 {
254                                         PreError();
255                                         prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
256                                         goto cleanup;
257                                 }
258                                 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->entityfields))
259                                 {
260                                         PreError();
261                                         prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
262                                         goto cleanup;
263                                 }
264                                 ed = PRVM_PROG_TO_EDICT(OPA->edict);
265                                 OPC->_int = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->_int;
266                                 break;
267
268                         case OP_LOAD_V:
269                                 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
270                                 {
271                                         PreError();
272                                         prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
273                                         goto cleanup;
274                                 }
275                                 if (OPB->_int < 0 || OPB->_int + 2 >= prog->entityfields)
276                                 {
277                                         PreError();
278                                         prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
279                                         goto cleanup;
280                                 }
281                                 ed = PRVM_PROG_TO_EDICT(OPA->edict);
282                                 ptr = (prvm_eval_t *)(ed->fields.ip + OPB->_int);
283                                 OPC->ivector[0] = ptr->ivector[0];
284                                 OPC->ivector[1] = ptr->ivector[1];
285                                 OPC->ivector[2] = ptr->ivector[2];
286                                 break;
287
288                 //==================
289
290                         case OP_IFNOT:
291                                 if(!FLOAT_IS_TRUE_FOR_INT(OPA->_int))
292                                 // TODO add an "int-if", and change this one to OPA->_float
293                                 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
294                                 // and entity, string, field values can never have that value
295                                 {
296                                         prog->xfunction->profile += (st - startst);
297                                         st = prog->statements + st->jumpabsolute - 1;   // offset the st++
298                                         startst = st;
299                                         // no bounds check needed, it is done when loading progs
300                                         if (++jumpcount == 10000000 && prvm_runawaycheck)
301                                         {
302                                                 prog->xstatement = st - prog->statements;
303                                                 PRVM_Profile(prog, 1<<30, 1000000, 0);
304                                                 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
305                                         }
306                                 }
307                                 break;
308
309                         case OP_IF:
310                                 if(FLOAT_IS_TRUE_FOR_INT(OPA->_int))
311                                 // TODO add an "int-if", and change this one, as well as the FLOAT_IS_TRUE_FOR_INT usages, to OPA->_float
312                                 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
313                                 // and entity, string, field values can never have that value
314                                 {
315                                         prog->xfunction->profile += (st - startst);
316                                         st = prog->statements + st->jumpabsolute - 1;   // offset the st++
317                                         startst = st;
318                                         // no bounds check needed, it is done when loading progs
319                                         if (++jumpcount == 10000000 && prvm_runawaycheck)
320                                         {
321                                                 prog->xstatement = st - prog->statements;
322                                                 PRVM_Profile(prog, 1<<30, 0.01, 0);
323                                                 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
324                                         }
325                                 }
326                                 break;
327
328                         case OP_GOTO:
329                                 prog->xfunction->profile += (st - startst);
330                                 st = prog->statements + st->jumpabsolute - 1;   // offset the st++
331                                 startst = st;
332                                 // no bounds check needed, it is done when loading progs
333                                 if (++jumpcount == 10000000 && prvm_runawaycheck)
334                                 {
335                                         prog->xstatement = st - prog->statements;
336                                         PRVM_Profile(prog, 1<<30, 0.01, 0);
337                                         prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
338                                 }
339                                 break;
340
341                         case OP_CALL0:
342                         case OP_CALL1:
343                         case OP_CALL2:
344                         case OP_CALL3:
345                         case OP_CALL4:
346                         case OP_CALL5:
347                         case OP_CALL6:
348                         case OP_CALL7:
349                         case OP_CALL8:
350 #ifdef PRVMTIMEPROFILING 
351                                 tm = Sys_DirtyTime();
352                                 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
353                                 starttm = tm;
354 #endif
355                                 prog->xfunction->profile += (st - startst);
356                                 startst = st;
357                                 prog->xstatement = st - prog->statements;
358                                 prog->argc = st->op - OP_CALL0;
359                                 if (!OPA->function)
360                                         prog->error_cmd("NULL function in %s", prog->name);
361
362                                 if(!OPA->function || OPA->function < 0 || OPA->function >= prog->numfunctions)
363                                 {
364                                         PreError();
365                                         prog->error_cmd("%s CALL outside the program", prog->name);
366                                         goto cleanup;
367                                 }
368
369                                 newf = &prog->functions[OPA->function];
370                                 newf->callcount++;
371
372                                 if (newf->first_statement < 0)
373                                 {
374                                         // negative statements are built in functions
375                                         int builtinnumber = -newf->first_statement;
376                                         prog->xfunction->builtinsprofile++;
377                                         if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
378                                         {
379                                                 prog->builtins[builtinnumber](prog);
380 #ifdef PRVMTIMEPROFILING 
381                                                 tm = Sys_DirtyTime();
382                                                 newf->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
383                                                 prog->xfunction->tbprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
384                                                 starttm = tm;
385 #endif
386                                         }
387                                         else
388                                                 prog->error_cmd("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, prog->name);
389
390                                         if (prog->trace != cachedpr_trace)
391                                                 goto chooseexecprogram;
392                                 }
393                                 else
394                                         st = prog->statements + PRVM_EnterFunction(prog, newf);
395                                 startst = st;
396                                 break;
397
398                         case OP_DONE:
399                         case OP_RETURN:
400 #ifdef PRVMTIMEPROFILING 
401                                 tm = Sys_DirtyTime();
402                                 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
403                                 starttm = tm;
404 #endif
405                                 prog->xfunction->profile += (st - startst);
406                                 prog->xstatement = st - prog->statements;
407
408                                 prog->globals.ip[OFS_RETURN  ] = prog->globals.ip[st->operand[0]  ];
409                                 prog->globals.ip[OFS_RETURN+1] = prog->globals.ip[st->operand[0]+1];
410                                 prog->globals.ip[OFS_RETURN+2] = prog->globals.ip[st->operand[0]+2];
411
412                                 st = prog->statements + PRVM_LeaveFunction(prog);
413                                 startst = st;
414                                 if (prog->depth <= exitdepth)
415                                         goto cleanup; // all done
416                                 break;
417
418                         case OP_STATE:
419                                 if(prog->flag & PRVM_OP_STATE)
420                                 {
421                                         ed = PRVM_PROG_TO_EDICT(PRVM_gameglobaledict(self));
422                                         PRVM_gameedictfloat(ed,nextthink) = PRVM_gameglobalfloat(time) + 0.1;
423                                         PRVM_gameedictfloat(ed,frame) = OPA->_float;
424                                         PRVM_gameedictfunction(ed,think) = OPB->function;
425                                 }
426                                 else
427                                 {
428                                         PreError();
429                                         prog->xstatement = st - prog->statements;
430                                         prog->error_cmd("OP_STATE not supported by %s", prog->name);
431                                 }
432                                 break;
433
434 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
435 /*
436                         case OP_ADD_I:
437                                 OPC->_int = OPA->_int + OPB->_int;
438                                 break;
439                         case OP_ADD_IF:
440                                 OPC->_int = OPA->_int + (prvm_int_t) OPB->_float;
441                                 break;
442                         case OP_ADD_FI:
443                                 OPC->_float = OPA->_float + (prvm_vec_t) OPB->_int;
444                                 break;
445                         case OP_SUB_I:
446                                 OPC->_int = OPA->_int - OPB->_int;
447                                 break;
448                         case OP_SUB_IF:
449                                 OPC->_int = OPA->_int - (prvm_int_t) OPB->_float;
450                                 break;
451                         case OP_SUB_FI:
452                                 OPC->_float = OPA->_float - (prvm_vec_t) OPB->_int;
453                                 break;
454                         case OP_MUL_I:
455                                 OPC->_int = OPA->_int * OPB->_int;
456                                 break;
457                         case OP_MUL_IF:
458                                 OPC->_int = OPA->_int * (prvm_int_t) OPB->_float;
459                                 break;
460                         case OP_MUL_FI:
461                                 OPC->_float = OPA->_float * (prvm_vec_t) OPB->_int;
462                                 break;
463                         case OP_MUL_VI:
464                                 OPC->vector[0] = (prvm_vec_t) OPB->_int * OPA->vector[0];
465                                 OPC->vector[1] = (prvm_vec_t) OPB->_int * OPA->vector[1];
466                                 OPC->vector[2] = (prvm_vec_t) OPB->_int * OPA->vector[2];
467                                 break;
468                         case OP_DIV_VF:
469                                 {
470                                         float temp = 1.0f / OPB->_float;
471                                         OPC->vector[0] = temp * OPA->vector[0];
472                                         OPC->vector[1] = temp * OPA->vector[1];
473                                         OPC->vector[2] = temp * OPA->vector[2];
474                                 }
475                                 break;
476                         case OP_DIV_I:
477                                 OPC->_int = OPA->_int / OPB->_int;
478                                 break;
479                         case OP_DIV_IF:
480                                 OPC->_int = OPA->_int / (prvm_int_t) OPB->_float;
481                                 break;
482                         case OP_DIV_FI:
483                                 OPC->_float = OPA->_float / (prvm_vec_t) OPB->_int;
484                                 break;
485                         case OP_CONV_IF:
486                                 OPC->_float = OPA->_int;
487                                 break;
488                         case OP_CONV_FI:
489                                 OPC->_int = OPA->_float;
490                                 break;
491                         case OP_BITAND_I:
492                                 OPC->_int = OPA->_int & OPB->_int;
493                                 break;
494                         case OP_BITOR_I:
495                                 OPC->_int = OPA->_int | OPB->_int;
496                                 break;
497                         case OP_BITAND_IF:
498                                 OPC->_int = OPA->_int & (prvm_int_t)OPB->_float;
499                                 break;
500                         case OP_BITOR_IF:
501                                 OPC->_int = OPA->_int | (prvm_int_t)OPB->_float;
502                                 break;
503                         case OP_BITAND_FI:
504                                 OPC->_float = (prvm_int_t)OPA->_float & OPB->_int;
505                                 break;
506                         case OP_BITOR_FI:
507                                 OPC->_float = (prvm_int_t)OPA->_float | OPB->_int;
508                                 break;
509                         case OP_GE_I:
510                                 OPC->_float = OPA->_int >= OPB->_int;
511                                 break;
512                         case OP_LE_I:
513                                 OPC->_float = OPA->_int <= OPB->_int;
514                                 break;
515                         case OP_GT_I:
516                                 OPC->_float = OPA->_int > OPB->_int;
517                                 break;
518                         case OP_LT_I:
519                                 OPC->_float = OPA->_int < OPB->_int;
520                                 break;
521                         case OP_AND_I:
522                                 OPC->_float = OPA->_int && OPB->_int;
523                                 break;
524                         case OP_OR_I:
525                                 OPC->_float = OPA->_int || OPB->_int;
526                                 break;
527                         case OP_GE_IF:
528                                 OPC->_float = (prvm_vec_t)OPA->_int >= OPB->_float;
529                                 break;
530                         case OP_LE_IF:
531                                 OPC->_float = (prvm_vec_t)OPA->_int <= OPB->_float;
532                                 break;
533                         case OP_GT_IF:
534                                 OPC->_float = (prvm_vec_t)OPA->_int > OPB->_float;
535                                 break;
536                         case OP_LT_IF:
537                                 OPC->_float = (prvm_vec_t)OPA->_int < OPB->_float;
538                                 break;
539                         case OP_AND_IF:
540                                 OPC->_float = (prvm_vec_t)OPA->_int && OPB->_float;
541                                 break;
542                         case OP_OR_IF:
543                                 OPC->_float = (prvm_vec_t)OPA->_int || OPB->_float;
544                                 break;
545                         case OP_GE_FI:
546                                 OPC->_float = OPA->_float >= (prvm_vec_t)OPB->_int;
547                                 break;
548                         case OP_LE_FI:
549                                 OPC->_float = OPA->_float <= (prvm_vec_t)OPB->_int;
550                                 break;
551                         case OP_GT_FI:
552                                 OPC->_float = OPA->_float > (prvm_vec_t)OPB->_int;
553                                 break;
554                         case OP_LT_FI:
555                                 OPC->_float = OPA->_float < (prvm_vec_t)OPB->_int;
556                                 break;
557                         case OP_AND_FI:
558                                 OPC->_float = OPA->_float && (prvm_vec_t)OPB->_int;
559                                 break;
560                         case OP_OR_FI:
561                                 OPC->_float = OPA->_float || (prvm_vec_t)OPB->_int;
562                                 break;
563                         case OP_NOT_I:
564                                 OPC->_float = !OPA->_int;
565                                 break;
566                         case OP_EQ_I:
567                                 OPC->_float = OPA->_int == OPB->_int;
568                                 break;
569                         case OP_EQ_IF:
570                                 OPC->_float = (prvm_vec_t)OPA->_int == OPB->_float;
571                                 break;
572                         case OP_EQ_FI:
573                                 OPC->_float = OPA->_float == (prvm_vec_t)OPB->_int;
574                                 break;
575                         case OP_NE_I:
576                                 OPC->_float = OPA->_int != OPB->_int;
577                                 break;
578                         case OP_NE_IF:
579                                 OPC->_float = (prvm_vec_t)OPA->_int != OPB->_float;
580                                 break;
581                         case OP_NE_FI:
582                                 OPC->_float = OPA->_float != (prvm_vec_t)OPB->_int;
583                                 break;
584                         case OP_STORE_I:
585                                 OPB->_int = OPA->_int;
586                                 break;
587                         case OP_STOREP_I:
588 #if PRBOUNDSCHECK
589                                 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
590                                 {
591                                         PreError();
592                                         prog->error_cmd("%s Progs attempted to write to an out of bounds edict", prog->name);
593                                         goto cleanup;
594                                 }
595 #endif
596                                 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
597                                 ptr->_int = OPA->_int;
598                                 break;
599                         case OP_LOAD_I:
600 #if PRBOUNDSCHECK
601                                 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
602                                 {
603                                         PreError();
604                                         prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
605                                         goto cleanup;
606                                 }
607                                 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
608                                 {
609                                         PreError();
610                                         prog->error_cmd("%s Progs attempted to read an invalid field in an edict", prog->name);
611                                         goto cleanup;
612                                 }
613 #endif
614                                 ed = PRVM_PROG_TO_EDICT(OPA->edict);
615                                 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
616                                 break;
617
618                         case OP_GSTOREP_I:
619                         case OP_GSTOREP_F:
620                         case OP_GSTOREP_ENT:
621                         case OP_GSTOREP_FLD:            // integers
622                         case OP_GSTOREP_S:
623                         case OP_GSTOREP_FNC:            // pointers
624 #if PRBOUNDSCHECK
625                                 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
626                                 {
627                                         PreError();
628                                         prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
629                                         goto cleanup;
630                                 }
631 #endif
632                                 pr_iglobals[OPB->_int] = OPA->_int;
633                                 break;
634                         case OP_GSTOREP_V:
635 #if PRBOUNDSCHECK
636                                 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
637                                 {
638                                         PreError();
639                                         prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
640                                         goto cleanup;
641                                 }
642 #endif
643                                 pr_iglobals[OPB->_int  ] = OPA->ivector[0];
644                                 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
645                                 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
646                                 break;
647
648                         case OP_GADDRESS:
649                                 i = OPA->_int + (prvm_int_t) OPB->_float;
650 #if PRBOUNDSCHECK
651                                 if (i < 0 || i >= pr_globaldefs)
652                                 {
653                                         PreError();
654                                         prog->error_cmd("%s Progs attempted to address an out of bounds global", prog->name);
655                                         goto cleanup;
656                                 }
657 #endif
658                                 OPC->_int = pr_iglobals[i];
659                                 break;
660
661                         case OP_GLOAD_I:
662                         case OP_GLOAD_F:
663                         case OP_GLOAD_FLD:
664                         case OP_GLOAD_ENT:
665                         case OP_GLOAD_S:
666                         case OP_GLOAD_FNC:
667 #if PRBOUNDSCHECK
668                                 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
669                                 {
670                                         PreError();
671                                         prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
672                                         goto cleanup;
673                                 }
674 #endif
675                                 OPC->_int = pr_iglobals[OPA->_int];
676                                 break;
677
678                         case OP_GLOAD_V:
679 #if PRBOUNDSCHECK
680                                 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
681                                 {
682                                         PreError();
683                                         prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
684                                         goto cleanup;
685                                 }
686 #endif
687                                 OPC->ivector[0] = pr_iglobals[OPA->_int  ];
688                                 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
689                                 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
690                                 break;
691
692                         case OP_BOUNDCHECK:
693                                 if (OPA->_int < 0 || OPA->_int >= st->b)
694                                 {
695                                         PreError();
696                                         prog->error_cmd("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", prog->name, st->b, st->c);
697                                         goto cleanup;
698                                 }
699                                 break;
700
701 */
702
703                         default:
704                                 PreError();
705                                 prog->error_cmd("Bad opcode %i in %s", st->op, prog->name);
706                                 goto cleanup;
707                         }
708 #if PRVMSLOWINTERPRETER
709                         {
710                                 if (prog->watch_global_type != ev_void)
711                                 {
712                                         prvm_eval_t *f = PRVM_GLOBALFIELDVALUE(prog->watch_global);
713                                         prog->xstatement = st - prog->statements;
714                                         PRVM_Watchpoint(prog, 0, "Global watchpoint hit", prog->watch_global_type, &prog->watch_global_value, f);
715                                 }
716                                 if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
717                                 {
718                                         prvm_eval_t *f = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
719                                         prog->xstatement = st - prog->statements;
720                                         PRVM_Watchpoint(prog, 0, "Entityfield watchpoint hit", prog->watch_field_type, &prog->watch_edictfield_value, f);
721                                 }
722                         }
723 #endif
724                 }
725
726 #undef PreError