-
Notifications
You must be signed in to change notification settings - Fork 2
/
vm_opcodes.c.h
1251 lines (1092 loc) · 38.1 KB
/
vm_opcodes.c.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma once
typedef void(*qcvm_opcode_func_t) (qcvm_t *vm, const qcvm_operands_t operands, int *depth);
// This is the "source" component of vm_opcodes.h that is included alongside it.
static void F_OP_DONE(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
qcvm_leave(vm);
(*depth)--;
}
static void F_OP_RETURN(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
if (operands.a != GLOBAL_NULL)
qcvm_copy_globals_typed(qcvm_global_t[3], vm, GLOBAL_RETURN, operands.a);
qcvm_leave(vm);
(*depth)--;
}
#define F_OP_MUL(F_OP, TLeft, TRight, TResult) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
const TLeft a = *qcvm_get_global_typed(TLeft, vm, operands.a); \
const TRight b = *qcvm_get_global_typed(TRight, vm, operands.b); \
const TResult result = a * b; \
qcvm_set_global_typed_value(TResult, vm, operands.c, result); \
}
F_OP_MUL(F_OP_MUL_F, vec_t, vec_t, vec_t)
F_OP_MUL(F_OP_MUL_I, int32_t, int32_t, int32_t)
F_OP_MUL(F_OP_MUL_IF, int32_t, vec_t, vec_t)
F_OP_MUL(F_OP_MUL_FI, vec_t, int32_t, vec_t)
#undef F_OP_MUL
static void F_OP_MUL_V(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const vec3_t a = *qcvm_get_global_typed(vec3_t, vm, operands.a);
const vec3_t b = *qcvm_get_global_typed(vec3_t, vm, operands.b);
const vec_t result = DotProduct(a, b);
qcvm_set_global_typed_value(vec_t, vm, operands.c, result);
}
static void F_OP_MUL_VF(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const vec3_t a = *qcvm_get_global_typed(vec3_t, vm, operands.a);
const vec_t b = *qcvm_get_global_typed(vec_t, vm, operands.b);
const vec3_t result = VectorScaleF(a, b);
qcvm_set_global_typed_value(vec3_t, vm, operands.c, result);
}
static void F_OP_MUL_FV(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const vec_t a = *qcvm_get_global_typed(vec_t, vm, operands.a);
const vec3_t b = *qcvm_get_global_typed(vec3_t, vm, operands.b);
const vec3_t result = VectorScaleF(b, a);
qcvm_set_global_typed_value(vec3_t, vm, operands.c, result);
}
static void F_OP_MUL_VI(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const vec3_t a = *qcvm_get_global_typed(vec3_t, vm, operands.a);
const int32_t b = *qcvm_get_global_typed(int32_t, vm, operands.b);
const vec3_t result = VectorScaleI(a, b);
qcvm_set_global_typed_value(vec3_t, vm, operands.c, result);
}
static void F_OP_MUL_IV(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const int32_t a = *qcvm_get_global_typed(int32_t, vm, operands.a);
const vec3_t b = *qcvm_get_global_typed(vec3_t, vm, operands.b);
const vec3_t result = VectorScaleI(b, a);
qcvm_set_global_typed_value(vec3_t, vm, operands.c, result);
}
#define F_OP_DIV(F_OP, TLeft, TRight, TResult) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
const TLeft a = *qcvm_get_global_typed(TLeft, vm, operands.a); \
const TRight b = *qcvm_get_global_typed(TRight, vm, operands.b); \
const TResult result = a / b; \
qcvm_set_global_typed_value(TResult, vm, operands.c, result); \
}
F_OP_DIV(F_OP_DIV_F, vec_t, vec_t, vec_t)
F_OP_DIV(F_OP_DIV_I, int32_t, int32_t, int32_t)
F_OP_DIV(F_OP_DIV_IF, int32_t, vec_t, vec_t)
F_OP_DIV(F_OP_DIV_FI, vec_t, int32_t, vec_t)
#undef F_OP_DIV
static void F_OP_DIV_VF(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const vec3_t a = *qcvm_get_global_typed(vec3_t, vm, operands.a);
const vec_t b = *qcvm_get_global_typed(vec_t, vm, operands.b);
const vec3_t result = VectorDivideF(a, b);
qcvm_set_global_typed_value(vec3_t, vm, operands.c, result);
}
#define F_OP_ADD(F_OP, TLeft, TRight, TResult) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
const TLeft a = *qcvm_get_global_typed(TLeft, vm, operands.a); \
const TRight b = *qcvm_get_global_typed(TRight, vm, operands.b); \
const TResult result = a + b; \
qcvm_set_global_typed_value(TResult, vm, operands.c, result); \
}
F_OP_ADD(F_OP_ADD_F, vec_t, vec_t, vec_t)
F_OP_ADD(F_OP_ADD_I, int32_t, int32_t, int32_t)
F_OP_ADD(F_OP_ADD_FI, vec_t, int32_t, vec_t)
F_OP_ADD(F_OP_ADD_IF, int32_t, vec_t, vec_t)
#undef F_OP_ADD
static void F_OP_ADD_V(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const vec3_t a = *qcvm_get_global_typed(vec3_t, vm, operands.a);
const vec3_t b = *qcvm_get_global_typed(vec3_t, vm, operands.b);
const vec3_t result = VectorAdd(a, b);
qcvm_set_global_typed_value(vec3_t, vm, operands.c, result);
}
#define F_OP_SUB(F_OP, TLeft, TRight, TResult) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
const TLeft a = *qcvm_get_global_typed(TLeft, vm, operands.a); \
const TRight b = *qcvm_get_global_typed(TRight, vm, operands.b); \
const TResult result = a - b; \
qcvm_set_global_typed_value(TResult, vm, operands.c, result); \
}
F_OP_SUB(F_OP_SUB_F, vec_t, vec_t, vec_t)
F_OP_SUB(F_OP_SUB_I, int32_t, int32_t, int32_t)
F_OP_SUB(F_OP_SUB_FI, vec_t, int32_t, vec_t)
F_OP_SUB(F_OP_SUB_IF, int32_t, vec_t, vec_t)
#undef F_OP_SUB
static void F_OP_SUB_V(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const vec3_t a = *qcvm_get_global_typed(vec3_t, vm, operands.a);
const vec3_t b = *qcvm_get_global_typed(vec3_t, vm, operands.b);
const vec3_t result = VectorSubtract(a, b);
qcvm_set_global_typed_value(vec3_t, vm, operands.c, result);
}
#define F_OP_EQ(F_OP, TLeft, TRight, TResult) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
const TLeft a = *qcvm_get_global_typed(TLeft, vm, operands.a); \
const TRight b = *qcvm_get_global_typed(TRight, vm, operands.b); \
const TResult result = a == b; \
qcvm_set_global_typed_value(TResult, vm, operands.c, result); \
}
F_OP_EQ(F_OP_EQ_F, vec_t, vec_t, vec_t)
F_OP_EQ(F_OP_EQ_E, qcvm_ent_t, qcvm_ent_t, vec_t)
F_OP_EQ(F_OP_EQ_FNC, qcvm_func_t, qcvm_func_t, vec_t)
F_OP_EQ(F_OP_EQ_I, int32_t, int32_t, int32_t)
F_OP_EQ(F_OP_EQ_IF, int32_t, vec_t, int32_t)
F_OP_EQ(F_OP_EQ_FI, vec_t, int32_t, int32_t)
#undef F_OP_EQ
static void F_OP_EQ_V(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const vec3_t a = *qcvm_get_global_typed(vec3_t, vm, operands.a);
const vec3_t b = *qcvm_get_global_typed(vec3_t, vm, operands.b);
const vec_t result = VectorEquals(a, b);
qcvm_set_global_typed_value(vec_t, vm, operands.c, result);
}
static void F_OP_EQ_S(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const qcvm_string_t a = *qcvm_get_global_typed(qcvm_string_t, vm, operands.a);
const qcvm_string_t b = *qcvm_get_global_typed(qcvm_string_t, vm, operands.b);
vec_t result;
if (a == b)
result = 1;
else if (qcvm_strings_case_sensitive(vm))
result = !strcmp(qcvm_get_string(vm, a), qcvm_get_string(vm, b));
else
result = !stricmp(qcvm_get_string(vm, a), qcvm_get_string(vm, b));
qcvm_set_global_typed_value(vec_t, vm, operands.c, result);
}
#define F_OP_NE(F_OP, TLeft, TRight, TResult) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
const TLeft a = *qcvm_get_global_typed(TLeft, vm, operands.a); \
const TRight b = *qcvm_get_global_typed(TRight, vm, operands.b); \
const TResult result = a != b; \
qcvm_set_global_typed_value(TResult, vm, operands.c, result); \
}
F_OP_NE(F_OP_NE_F, vec_t, vec_t, vec_t)
F_OP_NE(F_OP_NE_E, qcvm_ent_t, qcvm_ent_t, vec_t)
F_OP_NE(F_OP_NE_FNC, qcvm_func_t, qcvm_func_t, vec_t)
F_OP_NE(F_OP_NE_I, int32_t, int32_t, int32_t)
F_OP_NE(F_OP_NE_IF, int32_t, vec_t, int32_t)
F_OP_NE(F_OP_NE_FI, vec_t, int32_t, int32_t)
#undef F_OP_NE
static void F_OP_NE_V(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const vec3_t a = *qcvm_get_global_typed(vec3_t, vm, operands.a);
const vec3_t b = *qcvm_get_global_typed(vec3_t, vm, operands.b);
const vec_t result = !VectorEquals(a, b);
qcvm_set_global_typed_value(vec_t, vm, operands.c, result);
}
static void F_OP_NE_S(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const qcvm_string_t a = *qcvm_get_global_typed(qcvm_string_t, vm, operands.a);
const qcvm_string_t b = *qcvm_get_global_typed(qcvm_string_t, vm, operands.b);
vec_t result;
if (a == b)
result = 0;
else if (qcvm_strings_case_sensitive(vm))
result = !!strcmp(qcvm_get_string(vm, a), qcvm_get_string(vm, b));
else
result = !!stricmp(qcvm_get_string(vm, a), qcvm_get_string(vm, b));
qcvm_set_global_typed_value(vec_t, vm, operands.c, result);
}
#define F_OP_LE(F_OP, TLeft, TRight, TResult) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
const TLeft a = *qcvm_get_global_typed(TLeft, vm, operands.a); \
const TRight b = *qcvm_get_global_typed(TRight, vm, operands.b); \
const TResult result = a <= b; \
qcvm_set_global_typed_value(TResult, vm, operands.c, result); \
}
F_OP_LE(F_OP_LE_F, vec_t, vec_t, vec_t)
F_OP_LE(F_OP_LE_I, int32_t, int32_t, int32_t)
F_OP_LE(F_OP_LE_IF, int32_t, vec_t, int32_t)
F_OP_LE(F_OP_LE_FI, vec_t, int32_t, int32_t)
#undef F_OP_LE
#define F_OP_GE(F_OP, TLeft, TRight, TResult) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
const TLeft a = *qcvm_get_global_typed(TLeft, vm, operands.a); \
const TRight b = *qcvm_get_global_typed(TRight, vm, operands.b); \
const TResult result = a >= b; \
qcvm_set_global_typed_value(TResult, vm, operands.c, result); \
}
F_OP_GE(F_OP_GE_F, vec_t, vec_t, vec_t)
F_OP_GE(F_OP_GE_I, int32_t, int32_t, int32_t)
F_OP_GE(F_OP_GE_IF, int32_t, vec_t, int32_t)
F_OP_GE(F_OP_GE_FI, vec_t, int32_t, int32_t)
#undef F_OP_GE
#define F_OP_LT(F_OP, TLeft, TRight, TResult) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
const TLeft a = *qcvm_get_global_typed(TLeft, vm, operands.a); \
const TRight b = *qcvm_get_global_typed(TRight, vm, operands.b); \
const TResult result = a < b; \
qcvm_set_global_typed_value(TResult, vm, operands.c, result); \
}
F_OP_LT(F_OP_LT_F, vec_t, vec_t, vec_t)
F_OP_LT(F_OP_LT_I, int32_t, int32_t, int32_t)
F_OP_LT(F_OP_LT_IF, int32_t, vec_t, int32_t)
F_OP_LT(F_OP_LT_FI, vec_t, int32_t, int32_t)
#undef F_OP_LT
#define F_OP_GT(F_OP, TLeft, TRight, TResult) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
const TLeft a = *qcvm_get_global_typed(TLeft, vm, operands.a); \
const TRight b = *qcvm_get_global_typed(TRight, vm, operands.b); \
const TResult result = a > b; \
qcvm_set_global_typed_value(TResult, vm, operands.c, result); \
}
F_OP_GT(F_OP_GT_F, vec_t, vec_t, vec_t)
F_OP_GT(F_OP_GT_I, int32_t, int32_t, int32_t)
F_OP_GT(F_OP_GT_IF, int32_t, vec_t, int32_t)
F_OP_GT(F_OP_GT_FI, vec_t, int32_t, int32_t)
#undef F_OP_GT
#define F_OP_LOAD(F_OP, TType) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
edict_t *ent = qcvm_ent_to_entity(vm, *qcvm_get_global_typed(qcvm_ent_t, vm, operands.a), true); \
const int32_t field = *qcvm_get_global_typed(int32_t, vm, operands.b); \
const qcvm_pointer_t pointer = qcvm_get_entity_field_pointer(vm, ent, field); \
TType *field_value; \
if (!qcvm_resolve_pointer(vm, pointer, false, sizeof(TType), (void**)&field_value)) \
qcvm_error(vm, "invalid pointer"); \
qcvm_set_global_typed_ptr(TType, vm, operands.c, field_value); \
qcvm_string_list_mark_refs_copied(vm, field_value, qcvm_get_global(vm, operands.c), sizeof(TType) / sizeof(qcvm_global_t)); \
qcvm_field_wrap_list_check_set(vm, qcvm_get_global(vm, operands.c), sizeof(TType) / sizeof(qcvm_global_t)); \
}
F_OP_LOAD(F_OP_LOAD_F, vec_t)
F_OP_LOAD(F_OP_LOAD_V, vec3_t)
F_OP_LOAD(F_OP_LOAD_S, qcvm_string_t)
F_OP_LOAD(F_OP_LOAD_ENT, qcvm_ent_t)
F_OP_LOAD(F_OP_LOAD_FLD, int32_t)
F_OP_LOAD(F_OP_LOAD_FNC, qcvm_func_t)
F_OP_LOAD(F_OP_LOAD_I, int32_t)
F_OP_LOAD(F_OP_LOAD_P, int32_t)
#undef F_OP_LOAD
static void F_OP_ADDRESS(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
edict_t *ent = qcvm_ent_to_entity(vm, *qcvm_get_global_typed(qcvm_ent_t, vm, operands.a), true);
const int32_t field = *qcvm_get_global_typed(int32_t, vm, operands.b);
const qcvm_pointer_t pointer = qcvm_get_entity_field_pointer(vm, ent, field);
qcvm_set_global_typed_value(qcvm_pointer_t, vm, operands.c, pointer);
}
#define F_OP_STORE_SAME(F_OP, TType) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
qcvm_copy_globals_typed(TType, vm, operands.b, operands.a); \
}
#define F_OP_STORE_DIFF(F_OP, TType, TResult) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
qcvm_copy_globals_safe(TResult, TType, vm, operands.b, operands.a); \
}
F_OP_STORE_SAME(F_OP_STORE_F, vec_t)
F_OP_STORE_SAME(F_OP_STORE_V, vec3_t)
F_OP_STORE_SAME(F_OP_STORE_S, qcvm_string_t)
F_OP_STORE_SAME(F_OP_STORE_ENT, qcvm_ent_t)
F_OP_STORE_SAME(F_OP_STORE_FLD, int32_t)
F_OP_STORE_SAME(F_OP_STORE_FNC, qcvm_func_t)
F_OP_STORE_SAME(F_OP_STORE_I, int32_t)
F_OP_STORE_DIFF(F_OP_STORE_IF, int32_t, vec_t)
F_OP_STORE_DIFF(F_OP_STORE_FI, vec_t, int32_t)
F_OP_STORE_SAME(F_OP_STORE_P, int32_t)
#undef F_OP_STORE
#define F_OP_STOREP(F_OP, TType, TResult) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
qcvm_pointer_t pointer = *qcvm_get_global_typed(qcvm_pointer_t, vm, operands.b); \
const ptrdiff_t offset = *qcvm_get_global_typed(int32_t, vm, operands.c); \
pointer = qcvm_offset_pointer(vm, pointer, offset * sizeof(qcvm_global_t)); \
TResult *address_ptr; \
\
if (!qcvm_resolve_pointer(vm, pointer, false, sizeof(TResult), (void **)&address_ptr)) \
qcvm_error(vm, "invalid address"); \
\
const TType *value = qcvm_get_global_typed(TType, vm, operands.a); \
const size_t span = sizeof(TType) / sizeof(qcvm_global_t); \
\
*address_ptr = *value; \
qcvm_string_list_mark_refs_copied(vm, value, address_ptr, span); \
qcvm_field_wrap_list_check_set(vm, address_ptr, span); \
}
F_OP_STOREP(F_OP_STOREP_F, vec_t, vec_t)
F_OP_STOREP(F_OP_STOREP_V, vec3_t, vec3_t)
F_OP_STOREP(F_OP_STOREP_S, qcvm_string_t, qcvm_string_t)
F_OP_STOREP(F_OP_STOREP_ENT, qcvm_ent_t, qcvm_ent_t)
F_OP_STOREP(F_OP_STOREP_FLD, int32_t, int32_t)
F_OP_STOREP(F_OP_STOREP_FNC, qcvm_func_t, qcvm_func_t)
F_OP_STOREP(F_OP_STOREP_I, int32_t, int32_t)
F_OP_STOREP(F_OP_STOREP_IF, int32_t, vec_t)
F_OP_STOREP(F_OP_STOREP_FI, vec_t, int32_t)
#undef F_OP_STOREP
#define F_OP_NOT(F_OP, TType, TResult) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
const TType a = *qcvm_get_global_typed(TType, vm, operands.a); \
const TResult result = !a; \
qcvm_set_global_typed_value(TResult, vm, operands.c, result); \
}
F_OP_NOT(F_OP_NOT_F, vec_t, vec_t)
F_OP_NOT(F_OP_NOT_FNC, qcvm_func_t, vec_t)
F_OP_NOT(F_OP_NOT_ENT, qcvm_ent_t, vec_t)
F_OP_NOT(F_OP_NOT_I, int32_t, int32_t)
#undef F_OP_NOT
static void F_OP_NOT_V(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const vec3_t a = *qcvm_get_global_typed(vec3_t, vm, operands.a);
const vec_t result = VectorEmpty(a);
qcvm_set_global_typed_value(vec_t, vm, operands.c, result);
}
static void F_OP_NOT_S(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const qcvm_string_t a = *qcvm_get_global_typed(qcvm_string_t, vm, operands.a);
const vec_t result = a == STRING_EMPTY || !*qcvm_get_string(vm, a);
qcvm_set_global_typed_value(vec_t, vm, operands.c, result);
}
#if ALLOW_INSTRUMENTING
#define PROFILE_COND_JUMP \
if (vm->profiling.flags & PROFILE_FIELDS) \
current->profile->fields[NumConditionalJumps][vm->profiling.mark]++
#else
#define PROFILE_COND_JUMP
#endif
#define F_OP_IF(F_OP, TType) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
if (*qcvm_get_global_typed(TType, vm, operands.a)) \
{ \
qcvm_stack_t *current = &vm->state.stack[vm->state.current]; \
current->statement += (int16_t)current->statement->args.b - 1; \
PROFILE_COND_JUMP; \
} \
}
F_OP_IF(F_OP_IF_I, vec_t)
F_OP_IF(F_OP_IF_F, int32_t)
#undef F_OP_IF
static void F_OP_IF_S(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const qcvm_string_t s = *qcvm_get_global_typed(qcvm_string_t, vm, operands.a);
if (s != STRING_EMPTY && *qcvm_get_string(vm, s))
{
qcvm_stack_t *current = &vm->state.stack[vm->state.current];
current->statement += (int16_t)current->statement->args.b - 1;
PROFILE_COND_JUMP;
}
}
#define F_OP_IFNOT(F_OP, TType) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
if (!*qcvm_get_global_typed(TType, vm, operands.a)) \
{ \
qcvm_stack_t *current = &vm->state.stack[vm->state.current]; \
current->statement += (int16_t)current->statement->args.b - 1; \
PROFILE_COND_JUMP; \
} \
}
F_OP_IFNOT(F_OP_IFNOT_I, vec_t)
F_OP_IFNOT(F_OP_IFNOT_F, int32_t)
#undef F_IFNOT
static void F_OP_IFNOT_S(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const qcvm_string_t s = *qcvm_get_global_typed(qcvm_string_t, vm, operands.a);
if (s == STRING_EMPTY || !*qcvm_get_string(vm, s))
{
qcvm_stack_t *current = &vm->state.stack[vm->state.current];
current->statement += (int16_t)current->statement->args.b - 1;
PROFILE_COND_JUMP;
}
}
#ifndef _DEBUG
qcvm_always_inline
#endif
static void F_OP_CALL_BASE(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const int32_t enter_func = *qcvm_get_global_typed(int32_t, vm, operands.a);
if (enter_func <= 0 || enter_func >= vm->functions_size)
qcvm_error(vm, "NULL function");
#if ALLOW_INSTRUMENTING
if (vm->profiling.flags & PROFILE_FIELDS)
{
qcvm_stack_t *current = &vm->state.stack[vm->state.current];
current->profile->fields[NumFuncCalls][vm->profiling.mark]++;
}
#endif
qcvm_function_t *call = &vm->functions[enter_func];
if (!call->id)
qcvm_error(vm, "Tried to call missing function %s", qcvm_get_string(vm, call->name_index));
#if ALLOW_PROFILING
if (vm->profiling.flags & PROFILE_SAMPLES)
{
if (!--vm->profiling.sampling.function_id)
{
vm->profiling.sampling.function_data[enter_func].count[vm->profiling.mark]++;
vm->profiling.sampling.function_id = vm->profiling.sampling.rate;
}
}
#endif
if (call->id < 0) /* negative statements are built in functions */
{
qcvm_call_builtin(vm, call);
return;
}
(*depth)++;
qcvm_enter(vm, call);
}
#define F_OP_CALL(F_OP, num_args) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
vm->state.argc = num_args; \
F_OP_CALL_BASE(vm, operands, depth); \
}
#define F_OP_CALLH1(F_OP, num_args) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
vm->state.argc = num_args; \
qcvm_copy_globals_typed(qcvm_global_t[3], vm, GLOBAL_PARM0, operands.b); \
F_OP_CALL_BASE(vm, operands, depth); \
}
#define F_OP_CALLH2(F_OP, num_args) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
vm->state.argc = num_args; \
qcvm_copy_globals_typed(qcvm_global_t[3], vm, GLOBAL_PARM0, operands.b); \
qcvm_copy_globals_typed(qcvm_global_t[3], vm, GLOBAL_PARM1, operands.c); \
F_OP_CALL_BASE(vm, operands, depth); \
}
F_OP_CALL(F_OP_CALL0, 0)
F_OP_CALL(F_OP_CALL1, 1)
F_OP_CALL(F_OP_CALL2, 2)
F_OP_CALL(F_OP_CALL3, 3)
F_OP_CALL(F_OP_CALL4, 4)
F_OP_CALL(F_OP_CALL5, 5)
F_OP_CALL(F_OP_CALL6, 6)
F_OP_CALL(F_OP_CALL7, 7)
F_OP_CALL(F_OP_CALL8, 8)
F_OP_CALLH1(F_OP_CALL1H, 1)
F_OP_CALLH2(F_OP_CALL2H, 2)
F_OP_CALLH2(F_OP_CALL3H, 3)
F_OP_CALLH2(F_OP_CALL4H, 4)
F_OP_CALLH2(F_OP_CALL5H, 5)
F_OP_CALLH2(F_OP_CALL6H, 6)
F_OP_CALLH2(F_OP_CALL7H, 7)
F_OP_CALLH2(F_OP_CALL8H, 8)
#undef F_OP_CALL
#undef F_OP_CALLH1
#undef F_OP_CALLH2
static void F_OP_GOTO(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
qcvm_stack_t *current = &vm->state.stack[vm->state.current];
current->statement += (int16_t)current->statement->args.a - 1;
#if ALLOW_INSTRUMENTING
if (vm->profiling.flags & PROFILE_FIELDS)
current->profile->fields[NumUnconditionalJumps][vm->profiling.mark]++;
#endif
}
#define F_OP_AND(F_OP, TLeft, TRight, TResult) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
const TLeft a = *qcvm_get_global_typed(TLeft, vm, operands.a); \
const TRight b = *qcvm_get_global_typed(TRight, vm, operands.b); \
const TResult result = a && b; \
qcvm_set_global_typed_value(TResult, vm, operands.c, result); \
}
F_OP_AND(F_OP_AND_F, vec_t, vec_t, vec_t)
F_OP_AND(F_OP_AND_I, int32_t, int32_t, int32_t)
F_OP_AND(F_OP_AND_IF, int32_t, vec_t, int32_t)
F_OP_AND(F_OP_AND_FI, vec_t, int32_t, int32_t)
#undef F_OP_AND
#define F_OP_OR(F_OP, TLeft, TRight, TResult) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
const TLeft a = *qcvm_get_global_typed(TLeft, vm, operands.a); \
const TRight b = *qcvm_get_global_typed(TRight, vm, operands.b); \
const TResult result = a || b; \
qcvm_set_global_typed_value(TResult, vm, operands.c, result); \
}
F_OP_OR(F_OP_OR_F, vec_t, vec_t, vec_t)
F_OP_OR(F_OP_OR_I, int32_t, int32_t, int32_t)
F_OP_OR(F_OP_OR_IF, int32_t, vec_t, int32_t)
F_OP_OR(F_OP_OR_FI, vec_t, int32_t, int32_t)
#undef F_OP_OR
#define F_OP_BITAND(F_OP, TLeft, TRight, TResult) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
const int32_t a = (int32_t)*qcvm_get_global_typed(TLeft, vm, operands.a); \
const int32_t b = (int32_t)*qcvm_get_global_typed(TRight, vm, operands.b); \
const TResult result = a & b; \
qcvm_set_global_typed_value(TResult, vm, operands.c, result); \
}
F_OP_BITAND(F_OP_BITAND_F, vec_t, vec_t, vec_t)
F_OP_BITAND(F_OP_BITAND_I, int32_t, int32_t, int32_t)
F_OP_BITAND(F_OP_BITAND_IF, int32_t, vec_t, int32_t)
F_OP_BITAND(F_OP_BITAND_FI, vec_t, int32_t, int32_t)
#undef F_OP_BITAND
#define F_OP_BITOR(F_OP, TLeft, TRight, TResult) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
const int32_t a = (int32_t)*qcvm_get_global_typed(TLeft, vm, operands.a); \
const int32_t b = (int32_t)*qcvm_get_global_typed(TRight, vm, operands.b); \
const TResult result = a | b; \
qcvm_set_global_typed_value(TResult, vm, operands.c, result); \
}
F_OP_BITOR(F_OP_BITOR_F, vec_t, vec_t, vec_t)
F_OP_BITOR(F_OP_BITOR_I, int32_t, int32_t, int32_t)
F_OP_BITOR(F_OP_BITOR_IF, int32_t, vec_t, int32_t)
F_OP_BITOR(F_OP_BITOR_FI, vec_t, int32_t, int32_t)
#undef F_OP_BITOR
static void F_OP_CONV_ITOF(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const vec_t result = (vec_t)*qcvm_get_global_typed(int32_t, vm, operands.a);
qcvm_set_global_typed_value(vec_t, vm, operands.c, result);
}
static void F_OP_CONV_FTOI(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const int32_t result = (int32_t)*qcvm_get_global_typed(vec_t, vm, operands.a);
qcvm_set_global_typed_value(int32_t, vm, operands.c, result);
}
static void F_OP_CP_ITOF(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const qcvm_pointer_t address = *qcvm_get_global_typed(qcvm_pointer_t, vm, operands.a);
int32_t i;
if (!qcvm_resolve_pointer(vm, address, false, sizeof(int32_t), (void**)&i))
qcvm_error(vm, "invalid address");
const vec_t result = i;
qcvm_set_global_typed_value(vec_t, vm, operands.c, result);
}
static void F_OP_CP_FTOI(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const qcvm_pointer_t address = *qcvm_get_global_typed(qcvm_pointer_t, vm, operands.a);
vec_t f;
if (!qcvm_resolve_pointer(vm, address, false, sizeof(vec_t), (void**)&f))
qcvm_error(vm, "invalid address");
const int32_t result = f;
qcvm_set_global_typed_value(int32_t, vm, operands.c, result);
}
static void F_OP_BITXOR_I(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const int32_t a = *qcvm_get_global_typed(int32_t, vm, operands.a);
const int32_t b = *qcvm_get_global_typed(int32_t, vm, operands.b);
const int32_t result = a ^ b;
qcvm_set_global_typed_value(int32_t, vm, operands.c, result);
}
static void F_OP_RSHIFT_I(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const int32_t a = *qcvm_get_global_typed(int32_t, vm, operands.a);
const int32_t b = *qcvm_get_global_typed(int32_t, vm, operands.b);
const int32_t result = a >> b;
qcvm_set_global_typed_value(int32_t, vm, operands.c, result);
}
static void F_OP_LSHIFT_I(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const int32_t a = *qcvm_get_global_typed(int32_t, vm, operands.a);
const int32_t b = *qcvm_get_global_typed(int32_t, vm, operands.b);
const int32_t result = a << b;
qcvm_set_global_typed_value(int32_t, vm, operands.c, result);
}
static void F_OP_GLOBALADDRESS(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const qcvm_global_t *base = qcvm_get_global(vm, operands.a);
const ptrdiff_t offset = *qcvm_get_global_typed(int32_t, vm, operands.b);
const qcvm_pointer_t pointer = qcvm_make_pointer(vm, QCVM_POINTER_GLOBAL, base + offset);
#ifdef _DEBUG
if (!qcvm_resolve_pointer(vm, pointer, false, sizeof(qcvm_global_t), NULL))
qcvm_error(vm, "bad pointer");
#endif
qcvm_set_global_typed_value(qcvm_pointer_t, vm, operands.c, pointer);
}
static void F_OP_ADD_PIW(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const int32_t a = *qcvm_get_global_typed(int32_t, vm, operands.a);
const int32_t b = *qcvm_get_global_typed(int32_t, vm, operands.b);
int32_t result = a + (b * sizeof(qcvm_global_t));
qcvm_set_global_typed_value(int32_t, vm, operands.c, result);
}
#define F_OP_LOADA(F_OP, TType) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
const ptrdiff_t address = (ptrdiff_t)operands.a + *qcvm_get_global_typed(int32_t, vm, operands.b); \
const qcvm_pointer_t pointer = qcvm_make_pointer(vm, QCVM_POINTER_GLOBAL, (void *)(vm->global_data + address)); \
TType *field_value; \
\
if (!qcvm_resolve_pointer(vm, pointer, false, sizeof(TType), (void**)&field_value)) \
qcvm_error(vm, "Invalid pointer %x", address); \
\
qcvm_set_global_typed_ptr(TType, vm, operands.c, field_value); \
\
const size_t span = sizeof(TType) / sizeof(qcvm_global_t); \
qcvm_string_list_mark_refs_copied(vm, field_value, qcvm_get_global(vm, operands.c), span); \
qcvm_field_wrap_list_check_set(vm, qcvm_get_global(vm, operands.c), span); \
}
F_OP_LOADA(F_OP_LOADA_F, vec_t)
F_OP_LOADA(F_OP_LOADA_V, vec3_t)
F_OP_LOADA(F_OP_LOADA_S, qcvm_string_t)
F_OP_LOADA(F_OP_LOADA_ENT, qcvm_ent_t)
F_OP_LOADA(F_OP_LOADA_FLD, int32_t)
F_OP_LOADA(F_OP_LOADA_FNC, qcvm_func_t)
F_OP_LOADA(F_OP_LOADA_I, int32_t)
#undef F_OP_LOADA
static inline void F_OP_LOADP_BASE(qcvm_t *vm, const qcvm_operands_t operands, int *depth, const size_t TType_size)
{
qcvm_pointer_t pointer = *qcvm_get_global_typed(qcvm_pointer_t, vm, operands.a);
pointer = qcvm_offset_pointer(vm, pointer, *qcvm_get_global_typed(int32_t, vm, operands.b) * sizeof(qcvm_global_t));
void *field_value;
if (!qcvm_resolve_pointer(vm, pointer, false, TType_size, &field_value))
qcvm_error(vm, "Invalid pointer");
qcvm_set_global(vm, operands.c, field_value, TType_size);
const size_t span = TType_size / sizeof(qcvm_global_t);
qcvm_string_list_mark_refs_copied(vm, field_value, qcvm_get_global(vm, operands.c), span);
qcvm_field_wrap_list_check_set(vm, qcvm_get_global(vm, operands.c), span);
}
#define F_OP_LOADP(F_OP, TType) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
F_OP_LOADP_BASE(vm, operands, depth, sizeof(TType)); \
}
F_OP_LOADP(F_OP_LOADP_F, vec_t)
F_OP_LOADP(F_OP_LOADP_V, vec3_t)
F_OP_LOADP(F_OP_LOADP_S, qcvm_string_t)
F_OP_LOADP(F_OP_LOADP_ENT, qcvm_ent_t)
F_OP_LOADP(F_OP_LOADP_FLD, int32_t)
F_OP_LOADP(F_OP_LOADP_FNC, qcvm_func_t)
F_OP_LOADP(F_OP_LOADP_I, int32_t)
#undef F_OP_LOADP
static void F_OP_LOADP_C(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const qcvm_string_t strid = *qcvm_get_global_typed(qcvm_string_t, vm, operands.a);
const size_t offset = *qcvm_get_global_typed(int32_t, vm, operands.b);
int32_t result;
if (offset > qcvm_get_string_length(vm, strid))
result = 0;
else
{
const char *str = qcvm_get_string(vm, strid);
result = str[offset];
}
qcvm_set_global_typed_value(vec_t, vm, operands.c, result);
}
static void F_OP_BOUNDCHECK(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
#if _DEBUG
const uint32_t a = *qcvm_get_global_typed(uint32_t, vm, operands.a);
const uint32_t b = (uint32_t)operands.b;
const uint32_t c = (uint32_t)operands.c;
if (a < c || a >= b)
qcvm_error(vm, "bounds check failed");
#endif
}
static void F_OP_MULSTOREP_F(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const qcvm_pointer_t pointer = *qcvm_get_global_typed(qcvm_pointer_t, vm, operands.b);
vec_t *f;
if (!qcvm_resolve_pointer(vm, pointer, false, sizeof(vec_t), (void**)&f))
qcvm_error(vm, "bad pointer");
const vec_t a = *qcvm_get_global_typed(vec_t, vm, operands.a);
const vec_t result = (*f) *= a;
qcvm_set_global_typed_value(vec_t, vm, operands.c, result);
qcvm_field_wrap_list_check_set(vm, f, sizeof(vec_t) / sizeof(qcvm_global_t));
}
static void F_OP_MULSTOREP_VF(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const qcvm_pointer_t pointer = *qcvm_get_global_typed(qcvm_pointer_t, vm, operands.b);
vec3_t *f;
if (!qcvm_resolve_pointer(vm, pointer, false, sizeof(vec3_t), (void**)&f))
qcvm_error(vm, "bad pointer");
const vec_t a = *qcvm_get_global_typed(vec_t, vm, operands.a);
const vec3_t result = (*f) = VectorScaleF(*f, a);
qcvm_set_global_typed_value(vec3_t, vm, operands.c, result);
qcvm_field_wrap_list_check_set(vm, f, sizeof(vec3_t) / sizeof(qcvm_global_t));
}
static void F_OP_DIVSTOREP_F(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const qcvm_pointer_t pointer = *qcvm_get_global_typed(qcvm_pointer_t, vm, operands.b);
vec_t *f;
if (!qcvm_resolve_pointer(vm, pointer, false, sizeof(vec_t), (void**)&f))
qcvm_error(vm, "bad pointer");
const vec_t a = *qcvm_get_global_typed(vec_t, vm, operands.a);
const vec_t result = (*f) /= a;
qcvm_set_global_typed_value(vec_t, vm, operands.c, result);
qcvm_field_wrap_list_check_set(vm, f, sizeof(vec_t) / sizeof(qcvm_global_t));
}
static void F_OP_ADDSTOREP_F(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const qcvm_pointer_t pointer = *qcvm_get_global_typed(qcvm_pointer_t, vm, operands.b);
vec_t *f;
if (!qcvm_resolve_pointer(vm, pointer, false, sizeof(vec_t), (void**)&f))
qcvm_error(vm, "bad pointer");
const vec_t a = *qcvm_get_global_typed(vec_t, vm, operands.a);
const vec_t result = (*f) += a;
qcvm_set_global_typed_value(vec_t, vm, operands.c, result);
qcvm_field_wrap_list_check_set(vm, f, sizeof(vec_t) / sizeof(qcvm_global_t));
}
static void F_OP_ADDSTOREP_V(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const qcvm_pointer_t pointer = *qcvm_get_global_typed(qcvm_pointer_t, vm, operands.b);
vec3_t *f;
if (!qcvm_resolve_pointer(vm, pointer, false, sizeof(vec3_t), (void**)&f))
qcvm_error(vm, "bad pointer");
const vec3_t a = *qcvm_get_global_typed(vec3_t, vm, operands.a);
const vec3_t result = (*f) = VectorAdd(*f, a);
qcvm_set_global_typed_value(vec3_t, vm, operands.c, result);
qcvm_field_wrap_list_check_set(vm, f, sizeof(vec3_t) / sizeof(qcvm_global_t));
}
static void F_OP_SUBSTOREP_F(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const qcvm_pointer_t pointer = *qcvm_get_global_typed(qcvm_pointer_t, vm, operands.b);
vec_t *f;
if (!qcvm_resolve_pointer(vm, pointer, false, sizeof(vec_t), (void**)&f))
qcvm_error(vm, "bad pointer");
const vec_t a = *qcvm_get_global_typed(vec_t, vm, operands.a);
const vec_t result = (*f) -= a;
qcvm_set_global_typed_value(vec_t, vm, operands.c, result);
qcvm_field_wrap_list_check_set(vm, f, sizeof(vec_t) / sizeof(qcvm_global_t));
}
static void F_OP_SUBSTOREP_V(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const qcvm_pointer_t pointer = *qcvm_get_global_typed(qcvm_pointer_t, vm, operands.b);
vec3_t *f;
if (!qcvm_resolve_pointer(vm, pointer, false, sizeof(vec3_t), (void**)&f))
qcvm_error(vm, "bad pointer");
const vec3_t a = *qcvm_get_global_typed(vec3_t, vm, operands.a);
const vec3_t result = (*f) = VectorSubtract(*f, a);
qcvm_set_global_typed_value(vec3_t, vm, operands.c, result);
qcvm_field_wrap_list_check_set(vm, f, sizeof(vec3_t) / sizeof(qcvm_global_t));
}
static void F_OP_RAND0(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const vec_t result = frand();
qcvm_set_global_typed_value(vec_t, vm, operands.c, result);
}
static void F_OP_RAND1(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const vec_t result = frand_m(*qcvm_get_global_typed(vec_t, vm, operands.a));
qcvm_set_global_typed_value(vec_t, vm, operands.c, result);
}
static void F_OP_RAND2(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const vec_t result = frand_mm(*qcvm_get_global_typed(vec_t, vm, operands.a), *qcvm_get_global_typed(vec_t, vm, operands.b));
qcvm_set_global_typed_value(vec_t, vm, operands.c, result);
}
static void F_OP_RANDV0(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const vec3_t result = { frand(), frand(), frand() };
qcvm_set_global_typed_value(vec3_t, vm, operands.c, result);
}
static void F_OP_RANDV1(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const vec3_t a = *qcvm_get_global_typed(vec3_t, vm, operands.a);
const vec3_t result = { frand_m(a.x), frand_m(a.y), frand_m(a.z) };
qcvm_set_global_typed_value(vec3_t, vm, operands.c, result);
}
static void F_OP_RANDV2(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const vec3_t a = *qcvm_get_global_typed(vec3_t, vm, operands.a);
const vec3_t b = *qcvm_get_global_typed(vec3_t, vm, operands.b);
const vec3_t result = { frand_mm(a.x, b.x), frand_mm(a.y, b.y), frand_mm(a.z, b.z) };
qcvm_set_global_typed_value(vec3_t, vm, operands.c, result);
}
#define F_OP_STOREF(F_OP, TType) \
static void F_OP(qcvm_t *vm, const qcvm_operands_t operands, int *depth) \
{ \
const size_t span = sizeof(TType) / sizeof(qcvm_global_t); \
edict_t *ent = qcvm_ent_to_entity(vm, *qcvm_get_global_typed(qcvm_ent_t, vm, operands.a), true); \
const int32_t field = *qcvm_get_global_typed(int32_t, vm, operands.b); \
const qcvm_pointer_t pointer = qcvm_get_entity_field_pointer(vm, ent, field); \
TType *field_value; \
if (!qcvm_resolve_pointer(vm, pointer, false, sizeof(TType), (void**)&field_value)) \
qcvm_error(vm, "bad pointer"); \
const TType *value = qcvm_get_global_typed(TType, vm, operands.c); \
\
*field_value = *value; \
\
qcvm_string_list_mark_refs_copied(vm, value, field_value, span); \
qcvm_field_wrap_list_check_set(vm, field_value, span); \
}
F_OP_STOREF(F_OP_STOREF_F, vec_t)
F_OP_STOREF(F_OP_STOREF_S, qcvm_string_t)
F_OP_STOREF(F_OP_STOREF_I, int32_t)
F_OP_STOREF(F_OP_STOREF_V, vec3_t)
#undef F_OP_STOREF
static void F_OP_LOADP_B(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const qcvm_string_t strid = *qcvm_get_global_typed(qcvm_string_t, vm, operands.a);
const size_t offset = *qcvm_get_global_typed(int32_t, vm, operands.b);
int32_t result;
if (offset > qcvm_get_string_length(vm, strid))
result = 0;
else
{
const char *str = qcvm_get_string(vm, strid);
result = str[offset];
}
qcvm_set_global_typed_value(int32_t, vm, operands.c, result);
}
static void F_OP_INTRIN_SQRT(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const vec_t result = sqrt(*qcvm_get_global_typed(vec_t, vm, operands.b));
qcvm_set_global_typed_value(vec_t, vm, GLOBAL_RETURN, result);
}
static void F_OP_INTRIN_SIN(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const vec_t result = sin(*qcvm_get_global_typed(vec_t, vm, operands.b));
qcvm_set_global_typed_value(vec_t, vm, GLOBAL_RETURN, result);
}
static void F_OP_INTRIN_COS(qcvm_t *vm, const qcvm_operands_t operands, int *depth)
{
const vec_t result = cos(*qcvm_get_global_typed(vec_t, vm, operands.b));
qcvm_set_global_typed_value(vec_t, vm, GLOBAL_RETURN, result);
}
#define FOR_ALL_JUMPCODES(OP) \
OP(DONE) \
\
OP(MUL_F) \
OP(MUL_V) \
OP(MUL_FV) \
OP(MUL_VF) \
OP(MUL_I) \
OP(MUL_IF) \
OP(MUL_FI) \
OP(MUL_VI) \
OP(MUL_IV) \