]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - prvm_execprogram.h
add prvm_uint_t type
[xonotic/darkplaces.git] / prvm_execprogram.h
1 #ifdef PRVMTIMEPROFILING 
2 #define PreError() \
3         prog->xstatement = st - cached_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 - cached_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 - cached_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 - cached_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 - cached_statements]++;
40                         if (prog->break_statement >= 0)
41                                 if ((st - cached_statements) == prog->break_statement)
42                                 {
43                                         prog->xstatement = st - cached_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 - cached_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 ((prvm_uint_t)OPB->_int - cached_entityfields >= cached_entityfieldsarea_entityfields)
191                                 {
192                                         if ((prvm_uint_t)OPB->_int >= cached_entityfieldsarea)
193                                         {
194                                                 PreError();
195                                                 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
196                                                 goto cleanup;
197                                         }
198                                         if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
199                                         {
200                                                 prog->xstatement = st - cached_statements;
201                                                 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);
202                                         }
203                                 }
204                                 ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
205                                 ptr->_int = OPA->_int;
206                                 break;
207                         case OP_STOREP_V:
208                                 if ((prvm_uint_t)OPB->_int - cached_entityfields > (prvm_uint_t)cached_entityfieldsarea_entityfields_3)
209                                 {
210                                         if ((prvm_uint_t)OPB->_int > cached_entityfieldsarea_3)
211                                         {
212                                                 PreError();
213                                                 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
214                                                 goto cleanup;
215                                         }
216                                         if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
217                                         {
218                                                 prog->xstatement = st - cached_statements;
219                                                 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);
220                                         }
221                                 }
222                                 ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
223                                 ptr->ivector[0] = OPA->ivector[0];
224                                 ptr->ivector[1] = OPA->ivector[1];
225                                 ptr->ivector[2] = OPA->ivector[2];
226                                 break;
227
228                         case OP_ADDRESS:
229                                 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
230                                 {
231                                         PreError();
232                                         prog->error_cmd("%s Progs attempted to address an out of bounds edict number", prog->name);
233                                         goto cleanup;
234                                 }
235                                 if ((prvm_uint_t)OPB->_int >= cached_entityfields)
236                                 {
237                                         PreError();
238                                         prog->error_cmd("%s attempted to address an invalid field (%i) in an edict", prog->name, (int)OPB->_int);
239                                         goto cleanup;
240                                 }
241 #if 0
242                                 if (OPA->edict == 0 && !cached_allowworldwrites)
243                                 {
244                                         PreError();
245                                         prog->error_cmd("forbidden assignment to null/world entity in %s", prog->name);
246                                         goto cleanup;
247                                 }
248 #endif
249                                 OPC->_int = OPA->edict * cached_entityfields + OPB->_int;
250                                 break;
251
252                         case OP_LOAD_F:
253                         case OP_LOAD_FLD:
254                         case OP_LOAD_ENT:
255                         case OP_LOAD_S:
256                         case OP_LOAD_FNC:
257                                 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
258                                 {
259                                         PreError();
260                                         prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
261                                         goto cleanup;
262                                 }
263                                 if ((prvm_uint_t)OPB->_int >= cached_entityfields)
264                                 {
265                                         PreError();
266                                         prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
267                                         goto cleanup;
268                                 }
269                                 ed = PRVM_PROG_TO_EDICT(OPA->edict);
270                                 OPC->_int = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->_int;
271                                 break;
272
273                         case OP_LOAD_V:
274                                 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
275                                 {
276                                         PreError();
277                                         prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
278                                         goto cleanup;
279                                 }
280                                 if ((prvm_uint_t)OPB->_int > cached_entityfields_3)
281                                 {
282                                         PreError();
283                                         prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
284                                         goto cleanup;
285                                 }
286                                 ed = PRVM_PROG_TO_EDICT(OPA->edict);
287                                 ptr = (prvm_eval_t *)(ed->fields.ip + OPB->_int);
288                                 OPC->ivector[0] = ptr->ivector[0];
289                                 OPC->ivector[1] = ptr->ivector[1];
290                                 OPC->ivector[2] = ptr->ivector[2];
291                                 break;
292
293                 //==================
294
295                         case OP_IFNOT:
296                                 if(!FLOAT_IS_TRUE_FOR_INT(OPA->_int))
297                                 // TODO add an "int-if", and change this one to OPA->_float
298                                 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
299                                 // and entity, string, field values can never have that value
300                                 {
301                                         prog->xfunction->profile += (st - startst);
302                                         st = cached_statements + st->jumpabsolute - 1;  // offset the st++
303                                         startst = st;
304                                         // no bounds check needed, it is done when loading progs
305                                         if (++jumpcount == 10000000 && prvm_runawaycheck)
306                                         {
307                                                 prog->xstatement = st - cached_statements;
308                                                 PRVM_Profile(prog, 1<<30, 1000000, 0);
309                                                 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
310                                         }
311                                 }
312                                 break;
313
314                         case OP_IF:
315                                 if(FLOAT_IS_TRUE_FOR_INT(OPA->_int))
316                                 // TODO add an "int-if", and change this one, as well as the FLOAT_IS_TRUE_FOR_INT usages, to OPA->_float
317                                 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
318                                 // and entity, string, field values can never have that value
319                                 {
320                                         prog->xfunction->profile += (st - startst);
321                                         st = cached_statements + st->jumpabsolute - 1;  // offset the st++
322                                         startst = st;
323                                         // no bounds check needed, it is done when loading progs
324                                         if (++jumpcount == 10000000 && prvm_runawaycheck)
325                                         {
326                                                 prog->xstatement = st - cached_statements;
327                                                 PRVM_Profile(prog, 1<<30, 0.01, 0);
328                                                 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
329                                         }
330                                 }
331                                 break;
332
333                         case OP_GOTO:
334                                 prog->xfunction->profile += (st - startst);
335                                 st = cached_statements + st->jumpabsolute - 1;  // offset the st++
336                                 startst = st;
337                                 // no bounds check needed, it is done when loading progs
338                                 if (++jumpcount == 10000000 && prvm_runawaycheck)
339                                 {
340                                         prog->xstatement = st - cached_statements;
341                                         PRVM_Profile(prog, 1<<30, 0.01, 0);
342                                         prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
343                                 }
344                                 break;
345
346                         case OP_CALL0:
347                         case OP_CALL1:
348                         case OP_CALL2:
349                         case OP_CALL3:
350                         case OP_CALL4:
351                         case OP_CALL5:
352                         case OP_CALL6:
353                         case OP_CALL7:
354                         case OP_CALL8:
355 #ifdef PRVMTIMEPROFILING 
356                                 tm = Sys_DirtyTime();
357                                 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
358                                 starttm = tm;
359 #endif
360                                 prog->xfunction->profile += (st - startst);
361                                 startst = st;
362                                 prog->xstatement = st - cached_statements;
363                                 prog->argc = st->op - OP_CALL0;
364                                 if (!OPA->function)
365                                         prog->error_cmd("NULL function in %s", prog->name);
366
367                                 if(!OPA->function || OPA->function < 0 || OPA->function >= prog->numfunctions)
368                                 {
369                                         PreError();
370                                         prog->error_cmd("%s CALL outside the program", prog->name);
371                                         goto cleanup;
372                                 }
373
374                                 newf = &prog->functions[OPA->function];
375                                 newf->callcount++;
376
377                                 if (newf->first_statement < 0)
378                                 {
379                                         // negative first_statement values are built in functions
380                                         int builtinnumber = -newf->first_statement;
381                                         prog->xfunction->builtinsprofile++;
382                                         if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
383                                         {
384                                                 prog->builtins[builtinnumber](prog);
385 #ifdef PRVMTIMEPROFILING 
386                                                 tm = Sys_DirtyTime();
387                                                 newf->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
388                                                 prog->xfunction->tbprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
389                                                 starttm = tm;
390 #endif
391                                                 // builtins may cause ED_Alloc() to be called, update cached variables
392                                                 cached_edictsfields = prog->edictsfields;
393                                                 cached_entityfields = prog->entityfields;
394                                                 cached_entityfields_3 = prog->entityfields - 3;
395                                                 cached_entityfieldsarea = prog->entityfieldsarea;
396                                                 cached_entityfieldsarea_entityfields = prog->entityfieldsarea - prog->entityfields;
397                                                 cached_entityfieldsarea_3 = prog->entityfieldsarea - 3;
398                                                 cached_entityfieldsarea_entityfields_3 = prog->entityfieldsarea - prog->entityfields - 3;
399                                                 cached_max_edicts = prog->max_edicts;
400                                                 // these do not change
401                                                 //cached_statements = prog->statements;
402                                                 //cached_allowworldwrites = prog->allowworldwrites;
403                                                 //cached_flag = prog->flag;
404                                                 // if prog->trace changed we need to change interpreter path
405                                                 if (prog->trace != cachedpr_trace)
406                                                         goto chooseexecprogram;
407                                         }
408                                         else
409                                                 prog->error_cmd("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, prog->name);
410                                 }
411                                 else
412                                         st = cached_statements + PRVM_EnterFunction(prog, newf);
413                                 startst = st;
414                                 break;
415
416                         case OP_DONE:
417                         case OP_RETURN:
418 #ifdef PRVMTIMEPROFILING 
419                                 tm = Sys_DirtyTime();
420                                 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
421                                 starttm = tm;
422 #endif
423                                 prog->xfunction->profile += (st - startst);
424                                 prog->xstatement = st - cached_statements;
425
426                                 prog->globals.ip[OFS_RETURN  ] = prog->globals.ip[st->operand[0]  ];
427                                 prog->globals.ip[OFS_RETURN+1] = prog->globals.ip[st->operand[0]+1];
428                                 prog->globals.ip[OFS_RETURN+2] = prog->globals.ip[st->operand[0]+2];
429
430                                 st = cached_statements + PRVM_LeaveFunction(prog);
431                                 startst = st;
432                                 if (prog->depth <= exitdepth)
433                                         goto cleanup; // all done
434                                 break;
435
436                         case OP_STATE:
437                                 if(cached_flag & PRVM_OP_STATE)
438                                 {
439                                         ed = PRVM_PROG_TO_EDICT(PRVM_gameglobaledict(self));
440                                         PRVM_gameedictfloat(ed,nextthink) = PRVM_gameglobalfloat(time) + 0.1;
441                                         PRVM_gameedictfloat(ed,frame) = OPA->_float;
442                                         PRVM_gameedictfunction(ed,think) = OPB->function;
443                                 }
444                                 else
445                                 {
446                                         PreError();
447                                         prog->xstatement = st - cached_statements;
448                                         prog->error_cmd("OP_STATE not supported by %s", prog->name);
449                                 }
450                                 break;
451
452 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
453 /*
454                         case OP_ADD_I:
455                                 OPC->_int = OPA->_int + OPB->_int;
456                                 break;
457                         case OP_ADD_IF:
458                                 OPC->_int = OPA->_int + (prvm_int_t) OPB->_float;
459                                 break;
460                         case OP_ADD_FI:
461                                 OPC->_float = OPA->_float + (prvm_vec_t) OPB->_int;
462                                 break;
463                         case OP_SUB_I:
464                                 OPC->_int = OPA->_int - OPB->_int;
465                                 break;
466                         case OP_SUB_IF:
467                                 OPC->_int = OPA->_int - (prvm_int_t) OPB->_float;
468                                 break;
469                         case OP_SUB_FI:
470                                 OPC->_float = OPA->_float - (prvm_vec_t) OPB->_int;
471                                 break;
472                         case OP_MUL_I:
473                                 OPC->_int = OPA->_int * OPB->_int;
474                                 break;
475                         case OP_MUL_IF:
476                                 OPC->_int = OPA->_int * (prvm_int_t) OPB->_float;
477                                 break;
478                         case OP_MUL_FI:
479                                 OPC->_float = OPA->_float * (prvm_vec_t) OPB->_int;
480                                 break;
481                         case OP_MUL_VI:
482                                 OPC->vector[0] = (prvm_vec_t) OPB->_int * OPA->vector[0];
483                                 OPC->vector[1] = (prvm_vec_t) OPB->_int * OPA->vector[1];
484                                 OPC->vector[2] = (prvm_vec_t) OPB->_int * OPA->vector[2];
485                                 break;
486                         case OP_DIV_VF:
487                                 {
488                                         float temp = 1.0f / OPB->_float;
489                                         OPC->vector[0] = temp * OPA->vector[0];
490                                         OPC->vector[1] = temp * OPA->vector[1];
491                                         OPC->vector[2] = temp * OPA->vector[2];
492                                 }
493                                 break;
494                         case OP_DIV_I:
495                                 OPC->_int = OPA->_int / OPB->_int;
496                                 break;
497                         case OP_DIV_IF:
498                                 OPC->_int = OPA->_int / (prvm_int_t) OPB->_float;
499                                 break;
500                         case OP_DIV_FI:
501                                 OPC->_float = OPA->_float / (prvm_vec_t) OPB->_int;
502                                 break;
503                         case OP_CONV_IF:
504                                 OPC->_float = OPA->_int;
505                                 break;
506                         case OP_CONV_FI:
507                                 OPC->_int = OPA->_float;
508                                 break;
509                         case OP_BITAND_I:
510                                 OPC->_int = OPA->_int & OPB->_int;
511                                 break;
512                         case OP_BITOR_I:
513                                 OPC->_int = OPA->_int | OPB->_int;
514                                 break;
515                         case OP_BITAND_IF:
516                                 OPC->_int = OPA->_int & (prvm_int_t)OPB->_float;
517                                 break;
518                         case OP_BITOR_IF:
519                                 OPC->_int = OPA->_int | (prvm_int_t)OPB->_float;
520                                 break;
521                         case OP_BITAND_FI:
522                                 OPC->_float = (prvm_int_t)OPA->_float & OPB->_int;
523                                 break;
524                         case OP_BITOR_FI:
525                                 OPC->_float = (prvm_int_t)OPA->_float | OPB->_int;
526                                 break;
527                         case OP_GE_I:
528                                 OPC->_float = OPA->_int >= OPB->_int;
529                                 break;
530                         case OP_LE_I:
531                                 OPC->_float = OPA->_int <= OPB->_int;
532                                 break;
533                         case OP_GT_I:
534                                 OPC->_float = OPA->_int > OPB->_int;
535                                 break;
536                         case OP_LT_I:
537                                 OPC->_float = OPA->_int < OPB->_int;
538                                 break;
539                         case OP_AND_I:
540                                 OPC->_float = OPA->_int && OPB->_int;
541                                 break;
542                         case OP_OR_I:
543                                 OPC->_float = OPA->_int || OPB->_int;
544                                 break;
545                         case OP_GE_IF:
546                                 OPC->_float = (prvm_vec_t)OPA->_int >= OPB->_float;
547                                 break;
548                         case OP_LE_IF:
549                                 OPC->_float = (prvm_vec_t)OPA->_int <= OPB->_float;
550                                 break;
551                         case OP_GT_IF:
552                                 OPC->_float = (prvm_vec_t)OPA->_int > OPB->_float;
553                                 break;
554                         case OP_LT_IF:
555                                 OPC->_float = (prvm_vec_t)OPA->_int < OPB->_float;
556                                 break;
557                         case OP_AND_IF:
558                                 OPC->_float = (prvm_vec_t)OPA->_int && OPB->_float;
559                                 break;
560                         case OP_OR_IF:
561                                 OPC->_float = (prvm_vec_t)OPA->_int || OPB->_float;
562                                 break;
563                         case OP_GE_FI:
564                                 OPC->_float = OPA->_float >= (prvm_vec_t)OPB->_int;
565                                 break;
566                         case OP_LE_FI:
567                                 OPC->_float = OPA->_float <= (prvm_vec_t)OPB->_int;
568                                 break;
569                         case OP_GT_FI:
570                                 OPC->_float = OPA->_float > (prvm_vec_t)OPB->_int;
571                                 break;
572                         case OP_LT_FI:
573                                 OPC->_float = OPA->_float < (prvm_vec_t)OPB->_int;
574                                 break;
575                         case OP_AND_FI:
576                                 OPC->_float = OPA->_float && (prvm_vec_t)OPB->_int;
577                                 break;
578                         case OP_OR_FI:
579                                 OPC->_float = OPA->_float || (prvm_vec_t)OPB->_int;
580                                 break;
581                         case OP_NOT_I:
582                                 OPC->_float = !OPA->_int;
583                                 break;
584                         case OP_EQ_I:
585                                 OPC->_float = OPA->_int == OPB->_int;
586                                 break;
587                         case OP_EQ_IF:
588                                 OPC->_float = (prvm_vec_t)OPA->_int == OPB->_float;
589                                 break;
590                         case OP_EQ_FI:
591                                 OPC->_float = OPA->_float == (prvm_vec_t)OPB->_int;
592                                 break;
593                         case OP_NE_I:
594                                 OPC->_float = OPA->_int != OPB->_int;
595                                 break;
596                         case OP_NE_IF:
597                                 OPC->_float = (prvm_vec_t)OPA->_int != OPB->_float;
598                                 break;
599                         case OP_NE_FI:
600                                 OPC->_float = OPA->_float != (prvm_vec_t)OPB->_int;
601                                 break;
602                         case OP_STORE_I:
603                                 OPB->_int = OPA->_int;
604                                 break;
605                         case OP_STOREP_I:
606 #if PRBOUNDSCHECK
607                                 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
608                                 {
609                                         PreError();
610                                         prog->error_cmd("%s Progs attempted to write to an out of bounds edict", prog->name);
611                                         goto cleanup;
612                                 }
613 #endif
614                                 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
615                                 ptr->_int = OPA->_int;
616                                 break;
617                         case OP_LOAD_I:
618 #if PRBOUNDSCHECK
619                                 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
620                                 {
621                                         PreError();
622                                         prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
623                                         goto cleanup;
624                                 }
625                                 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
626                                 {
627                                         PreError();
628                                         prog->error_cmd("%s Progs attempted to read an invalid field in an edict", prog->name);
629                                         goto cleanup;
630                                 }
631 #endif
632                                 ed = PRVM_PROG_TO_EDICT(OPA->edict);
633                                 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
634                                 break;
635
636                         case OP_GSTOREP_I:
637                         case OP_GSTOREP_F:
638                         case OP_GSTOREP_ENT:
639                         case OP_GSTOREP_FLD:            // integers
640                         case OP_GSTOREP_S:
641                         case OP_GSTOREP_FNC:            // pointers
642 #if PRBOUNDSCHECK
643                                 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
644                                 {
645                                         PreError();
646                                         prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
647                                         goto cleanup;
648                                 }
649 #endif
650                                 pr_iglobals[OPB->_int] = OPA->_int;
651                                 break;
652                         case OP_GSTOREP_V:
653 #if PRBOUNDSCHECK
654                                 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
655                                 {
656                                         PreError();
657                                         prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
658                                         goto cleanup;
659                                 }
660 #endif
661                                 pr_iglobals[OPB->_int  ] = OPA->ivector[0];
662                                 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
663                                 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
664                                 break;
665
666                         case OP_GADDRESS:
667                                 i = OPA->_int + (prvm_int_t) OPB->_float;
668 #if PRBOUNDSCHECK
669                                 if (i < 0 || i >= pr_globaldefs)
670                                 {
671                                         PreError();
672                                         prog->error_cmd("%s Progs attempted to address an out of bounds global", prog->name);
673                                         goto cleanup;
674                                 }
675 #endif
676                                 OPC->_int = pr_iglobals[i];
677                                 break;
678
679                         case OP_GLOAD_I:
680                         case OP_GLOAD_F:
681                         case OP_GLOAD_FLD:
682                         case OP_GLOAD_ENT:
683                         case OP_GLOAD_S:
684                         case OP_GLOAD_FNC:
685 #if PRBOUNDSCHECK
686                                 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
687                                 {
688                                         PreError();
689                                         prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
690                                         goto cleanup;
691                                 }
692 #endif
693                                 OPC->_int = pr_iglobals[OPA->_int];
694                                 break;
695
696                         case OP_GLOAD_V:
697 #if PRBOUNDSCHECK
698                                 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
699                                 {
700                                         PreError();
701                                         prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
702                                         goto cleanup;
703                                 }
704 #endif
705                                 OPC->ivector[0] = pr_iglobals[OPA->_int  ];
706                                 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
707                                 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
708                                 break;
709
710                         case OP_BOUNDCHECK:
711                                 if (OPA->_int < 0 || OPA->_int >= st->b)
712                                 {
713                                         PreError();
714                                         prog->error_cmd("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", prog->name, st->b, st->c);
715                                         goto cleanup;
716                                 }
717                                 break;
718
719 */
720
721                         default:
722                                 PreError();
723                                 prog->error_cmd("Bad opcode %i in %s", st->op, prog->name);
724                                 goto cleanup;
725                         }
726 #if PRVMSLOWINTERPRETER
727                         {
728                                 if (prog->watch_global_type != ev_void)
729                                 {
730                                         prvm_eval_t *f = PRVM_GLOBALFIELDVALUE(prog->watch_global);
731                                         prog->xstatement = st - cached_statements;
732                                         PRVM_Watchpoint(prog, 0, "Global watchpoint hit", prog->watch_global_type, &prog->watch_global_value, f);
733                                 }
734                                 if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
735                                 {
736                                         prvm_eval_t *f = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
737                                         prog->xstatement = st - cached_statements;
738                                         PRVM_Watchpoint(prog, 0, "Entityfield watchpoint hit", prog->watch_field_type, &prog->watch_edictfield_value, f);
739                                 }
740                         }
741 #endif
742                 }
743
744 #undef PreError