HDLRuby 2.5.1 → 2.6.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/HDLRuby/hdr_samples/adder.rb +1 -1
- data/lib/HDLRuby/hdr_samples/adder_bench.rb +1 -1
- data/lib/HDLRuby/hdr_samples/adder_gen.rb +1 -1
- data/lib/HDLRuby/hdr_samples/comparison_bench.rb +40 -0
- data/lib/HDLRuby/hdr_samples/constant_in_function.rb +27 -0
- data/lib/HDLRuby/hdr_samples/dff_unit.rb +3 -3
- data/lib/HDLRuby/hdr_samples/huge_rom.rb +25 -0
- data/lib/HDLRuby/hdr_samples/logic_bench.rb +21 -0
- data/lib/HDLRuby/hdr_samples/mei8_bench.rb +1 -1
- data/lib/HDLRuby/hdr_samples/multi_timed_bench.rb +54 -0
- data/lib/HDLRuby/hdr_samples/music.rb +79 -0
- data/lib/HDLRuby/hdr_samples/named_sub.rb +42 -0
- data/lib/HDLRuby/hdr_samples/rom.rb +16 -0
- data/lib/HDLRuby/hdr_samples/type_minmax_bench.rb +37 -0
- data/lib/HDLRuby/hdr_samples/with_function_generator.rb +25 -0
- data/lib/HDLRuby/hdr_samples/with_to_array.rb +29 -0
- data/lib/HDLRuby/hdrcc.rb +69 -9
- data/lib/HDLRuby/hruby_decorator.rb +3 -1
- data/lib/HDLRuby/hruby_high.rb +220 -29
- data/lib/HDLRuby/hruby_low.rb +433 -45
- data/lib/HDLRuby/hruby_low2c.rb +122 -168
- data/lib/HDLRuby/hruby_low2hdr.rb +738 -0
- data/lib/HDLRuby/hruby_low2high.rb +331 -549
- data/lib/HDLRuby/hruby_low2vhd.rb +39 -2
- data/lib/HDLRuby/hruby_low_bool2select.rb +29 -0
- data/lib/HDLRuby/hruby_low_casts_without_expression.rb +27 -0
- data/lib/HDLRuby/hruby_low_fix_types.rb +25 -0
- data/lib/HDLRuby/hruby_low_mutable.rb +70 -0
- data/lib/HDLRuby/hruby_low_resolve.rb +28 -0
- data/lib/HDLRuby/hruby_low_without_connection.rb +6 -3
- data/lib/HDLRuby/hruby_low_without_namespace.rb +7 -4
- data/lib/HDLRuby/hruby_low_without_select.rb +13 -0
- data/lib/HDLRuby/hruby_tools.rb +11 -1
- data/lib/HDLRuby/hruby_verilog.rb +1572 -1723
- data/lib/HDLRuby/sim/hruby_sim.h +45 -5
- data/lib/HDLRuby/sim/hruby_sim_calc.c +192 -20
- data/lib/HDLRuby/sim/hruby_sim_core.c +24 -9
- data/lib/HDLRuby/sim/hruby_sim_vcd.c +7 -3
- data/lib/HDLRuby/sim/hruby_sim_vizualize.c +22 -6
- data/lib/HDLRuby/std/fixpoint.rb +9 -0
- data/lib/HDLRuby/std/function_generator.rb +139 -0
- data/lib/HDLRuby/std/hruby_unit.rb +75 -0
- data/lib/HDLRuby/version.rb +1 -1
- metadata +18 -6
- data/lib/HDLRuby/hruby_unit.rb +0 -43
data/lib/HDLRuby/sim/hruby_sim.h
CHANGED
@@ -219,6 +219,13 @@ Value shift_right_value(Value src0, Value src1, Value dst);
|
|
219
219
|
* @return dst */
|
220
220
|
extern Value equal_value(Value src0, Value src1, Value dst);
|
221
221
|
|
222
|
+
/** Computes the greater comparision of two values.
|
223
|
+
* @param src0 the first source value of the comparison
|
224
|
+
* @param src1 the second source value of the comparison
|
225
|
+
* @param dst the destination value
|
226
|
+
* @return dst */
|
227
|
+
extern Value greater_value(Value src0, Value src1, Value dst);
|
228
|
+
|
222
229
|
/** Computes the lesser comparision of two values.
|
223
230
|
* @param src0 the first source value of the comparison
|
224
231
|
* @param src1 the second source value of the comparison
|
@@ -226,12 +233,19 @@ extern Value equal_value(Value src0, Value src1, Value dst);
|
|
226
233
|
* @return dst */
|
227
234
|
extern Value lesser_value(Value src0, Value src1, Value dst);
|
228
235
|
|
229
|
-
/** Computes the greater comparision of two values.
|
236
|
+
/** Computes the greater or equal comparision of two values.
|
230
237
|
* @param src0 the first source value of the comparison
|
231
238
|
* @param src1 the second source value of the comparison
|
232
239
|
* @param dst the destination value
|
233
240
|
* @return dst */
|
234
|
-
extern Value
|
241
|
+
extern Value greater_equal_value(Value src0, Value src1, Value dst);
|
242
|
+
|
243
|
+
/** Computes the lesser or equal comparision of two values.
|
244
|
+
* @param src0 the first source value of the comparison
|
245
|
+
* @param src1 the second source value of the comparison
|
246
|
+
* @param dst the destination value
|
247
|
+
* @return dst */
|
248
|
+
extern Value lesser_equal_value(Value src0, Value src1, Value dst);
|
235
249
|
|
236
250
|
/** Selects a value depending on a condition.
|
237
251
|
* @param cond the condition to use for selecting a value
|
@@ -451,7 +465,10 @@ typedef struct BehaviorS_ {
|
|
451
465
|
|
452
466
|
int activated; /* Tells if the behavior is activated or not. */
|
453
467
|
|
454
|
-
int timed; /* Tell if the behavior is timed or not
|
468
|
+
int timed; /* Tell if the behavior is timed or not:
|
469
|
+
- 0: not timed
|
470
|
+
- 1: timed
|
471
|
+
- 2: timed and finished. */
|
455
472
|
unsigned long long active_time; /* The next time the behavior has to be activated. */
|
456
473
|
pthread_t thread; /* The thread assotiated with the behavior (if any).*/
|
457
474
|
} BehaviorS;
|
@@ -573,10 +590,15 @@ extern void each_all_signal(void (*func)(SignalI));
|
|
573
590
|
/* Interface to the visualization engine. */
|
574
591
|
|
575
592
|
typedef struct {
|
593
|
+
/* The simulation prints. */
|
576
594
|
void (*print_time)(unsigned long long);
|
577
595
|
void (*print_name)(Object);
|
578
596
|
void (*print_value)(Value);
|
579
597
|
void (*print_signal)(SignalI);
|
598
|
+
/* The custom 'string' prints. */
|
599
|
+
void (*print_string)(const char*);
|
600
|
+
void (*print_string_name)(Object);
|
601
|
+
void (*print_string_value)(Value);
|
580
602
|
} PrinterS;
|
581
603
|
|
582
604
|
extern PrinterS printer;
|
@@ -585,11 +607,29 @@ extern PrinterS printer;
|
|
585
607
|
* @param print_time the time printer
|
586
608
|
* @param print_name the name printer
|
587
609
|
* @param print_value the value printer
|
588
|
-
* @param print_signal the signal state printer
|
610
|
+
* @param print_signal the signal state printer
|
611
|
+
* @param print_string the string printer
|
612
|
+
* @param print_string_name the string name printer
|
613
|
+
* @param print_string_value the string value printer */
|
589
614
|
extern void init_visualizer(void (*print_time)(unsigned long long),
|
590
615
|
void (*print_name)(Object),
|
591
616
|
void (*print_value)(Value),
|
592
|
-
void (*print_signal)(SignalI)
|
617
|
+
void (*print_signal)(SignalI),
|
618
|
+
void (*print_string)(const char*),
|
619
|
+
void (*print_string_name)(Object),
|
620
|
+
void (*print_string_value)(Value));
|
621
|
+
|
622
|
+
/** Prints a name (default).
|
623
|
+
* @param signal the signal to show */
|
624
|
+
extern void default_print_name(Object);
|
625
|
+
|
626
|
+
/** Prints a value (default).
|
627
|
+
* @param signal the signal to show */
|
628
|
+
extern void default_print_value(Value);
|
629
|
+
|
630
|
+
/** Prints a string (default).
|
631
|
+
* @param str the string to print. */
|
632
|
+
extern void default_print_string(const char* str);
|
593
633
|
|
594
634
|
// /** Prints the time.
|
595
635
|
// * @param time the time to show. */
|
@@ -325,6 +325,9 @@ Value copy_value(Value src, Value dst) {
|
|
325
325
|
/* Declared afterward. */
|
326
326
|
static Value set_bitstring_value(Value src, Value dst);
|
327
327
|
|
328
|
+
/* Declared afterward. */
|
329
|
+
static Value set_numeric_value(Value src, Value dst);
|
330
|
+
|
328
331
|
/** Copies a value to another but without overwritting with Z, the type of
|
329
332
|
* the destination is preserved.
|
330
333
|
* @param src the source value
|
@@ -393,6 +396,35 @@ static Value set_bitstring_value(Value src, Value dst) {
|
|
393
396
|
return dst;
|
394
397
|
}
|
395
398
|
|
399
|
+
/** Creates a numeric value from a bitstring value.
|
400
|
+
* @param src the bitstring source value
|
401
|
+
* @param dst the numeric destination value
|
402
|
+
* @return dst. */
|
403
|
+
static Value set_numeric_value(Value src, Value dst) {
|
404
|
+
/* Compute the width in bits of the source. */
|
405
|
+
unsigned long long width = type_width(src->type);
|
406
|
+
unsigned long long i;
|
407
|
+
/* Set the type and size of the destination from the type of the source.*/
|
408
|
+
dst->type = src->type;
|
409
|
+
dst->numeric = 1;
|
410
|
+
|
411
|
+
/* Access the data of the source and the destination. */
|
412
|
+
char* data_str = src->data_str;
|
413
|
+
unsigned long long data_int = 0;
|
414
|
+
|
415
|
+
/* Make the conversion. */
|
416
|
+
for(i=0; i < width; ++i) {
|
417
|
+
/* Get the bit from the source. */
|
418
|
+
unsigned long long bit = data_str[i] - '0';
|
419
|
+
/* And write it. */
|
420
|
+
data_int |= bit << i;
|
421
|
+
}
|
422
|
+
/* Update the destination. */
|
423
|
+
dst->data_int = data_int;
|
424
|
+
/* Return the destination. */
|
425
|
+
return dst;
|
426
|
+
}
|
427
|
+
|
396
428
|
|
397
429
|
/** Sets a value to undefined.
|
398
430
|
* @param dst the destination value
|
@@ -654,6 +686,21 @@ static Value mod_value_defined_bitstring(Value src0, Value src1, Value dst) {
|
|
654
686
|
}
|
655
687
|
|
656
688
|
|
689
|
+
/** Computes the greater comparision of two defined bitstring values.
|
690
|
+
* @param src0 the first source value of the addition
|
691
|
+
* @param src1 the second source value of the addition
|
692
|
+
* @param dst the destination value
|
693
|
+
* @return dst */
|
694
|
+
static Value greater_value_defined_bitstring(Value src0, Value src1, Value dst) {
|
695
|
+
/* Sets state of the destination using the first source. */
|
696
|
+
dst->type = src0->type;
|
697
|
+
dst->numeric = 1;
|
698
|
+
|
699
|
+
/* Perform the comparison. */
|
700
|
+
dst->data_int = (value2integer(src0) > value2integer(src1));
|
701
|
+
return dst;
|
702
|
+
}
|
703
|
+
|
657
704
|
/** Computes the lesser comparision of two defined bitstring values.
|
658
705
|
* @param src0 the first source value of the addition
|
659
706
|
* @param src1 the second source value of the addition
|
@@ -669,19 +716,33 @@ static Value lesser_value_defined_bitstring(Value src0, Value src1, Value dst) {
|
|
669
716
|
return dst;
|
670
717
|
}
|
671
718
|
|
719
|
+
/** Computes the greater or equal comparision of two defined bitstring values.
|
720
|
+
* @param src0 the first source value of the addition
|
721
|
+
* @param src1 the second source value of the addition
|
722
|
+
* @param dst the destination value
|
723
|
+
* @return dst */
|
724
|
+
static Value greater_equal_value_defined_bitstring(Value src0, Value src1, Value dst) {
|
725
|
+
/* Sets state of the destination using the first source. */
|
726
|
+
dst->type = src0->type;
|
727
|
+
dst->numeric = 1;
|
672
728
|
|
673
|
-
|
729
|
+
/* Perform the comparison. */
|
730
|
+
dst->data_int = (value2integer(src0) >= value2integer(src1));
|
731
|
+
return dst;
|
732
|
+
}
|
733
|
+
|
734
|
+
/** Computes the lesser or equal comparision of two defined bitstring values.
|
674
735
|
* @param src0 the first source value of the addition
|
675
736
|
* @param src1 the second source value of the addition
|
676
737
|
* @param dst the destination value
|
677
738
|
* @return dst */
|
678
|
-
static Value
|
739
|
+
static Value lesser_equal_value_defined_bitstring(Value src0, Value src1, Value dst) {
|
679
740
|
/* Sets state of the destination using the first source. */
|
680
741
|
dst->type = src0->type;
|
681
742
|
dst->numeric = 1;
|
682
743
|
|
683
744
|
/* Perform the comparison. */
|
684
|
-
dst->data_int = (value2integer(src0)
|
745
|
+
dst->data_int = (value2integer(src0) <= value2integer(src1));
|
685
746
|
return dst;
|
686
747
|
}
|
687
748
|
|
@@ -1620,7 +1681,7 @@ static Value not_value_numeric(Value src, Value dst) {
|
|
1620
1681
|
dst->numeric = 1;
|
1621
1682
|
|
1622
1683
|
/* Perform the not. */
|
1623
|
-
dst->data_int = fix_numeric_type(dst->type
|
1684
|
+
dst->data_int = fix_numeric_type(dst->type,~src->data_int);
|
1624
1685
|
return dst;
|
1625
1686
|
}
|
1626
1687
|
|
@@ -1730,12 +1791,29 @@ static Value equal_value_numeric(Value src0, Value src1, Value dst) {
|
|
1730
1791
|
dst->type = src0->type;
|
1731
1792
|
dst->numeric = 1;
|
1732
1793
|
|
1733
|
-
/* Perform the !XOR. */
|
1734
|
-
dst->data_int = (src0->data_int
|
1794
|
+
// /* Perform the !XOR. */
|
1795
|
+
// dst->data_int = ~(src0->data_int ^ src1->data_int);
|
1796
|
+
/* Perform the comparison. */
|
1797
|
+
dst->data_int = (src0->data_int == src1->data_int) ? 1 : 0;
|
1735
1798
|
return dst;
|
1736
1799
|
}
|
1737
1800
|
|
1738
1801
|
|
1802
|
+
/** Computes the greater comparision of two numeric values.
|
1803
|
+
* @param src0 the first source value of the addition
|
1804
|
+
* @param src1 the second source value of the addition
|
1805
|
+
* @param dst the destination value
|
1806
|
+
* @return the destination value */
|
1807
|
+
static Value greater_value_numeric(Value src0, Value src1, Value dst) {
|
1808
|
+
/* Sets state of the destination using the first source. */
|
1809
|
+
dst->type = src0->type;
|
1810
|
+
dst->numeric = 1;
|
1811
|
+
|
1812
|
+
/* Perform the greater. */
|
1813
|
+
dst->data_int = (src0->data_int > src1->data_int);
|
1814
|
+
return dst;
|
1815
|
+
}
|
1816
|
+
|
1739
1817
|
/** Computes the lesser comparision of two numeric values.
|
1740
1818
|
* @param src0 the first source value of the addition
|
1741
1819
|
* @param src1 the second source value of the addition
|
@@ -1751,18 +1829,33 @@ static Value lesser_value_numeric(Value src0, Value src1, Value dst) {
|
|
1751
1829
|
return dst;
|
1752
1830
|
}
|
1753
1831
|
|
1754
|
-
/** Computes the greater comparision of two numeric values.
|
1832
|
+
/** Computes the greater or equal comparision of two numeric values.
|
1755
1833
|
* @param src0 the first source value of the addition
|
1756
1834
|
* @param src1 the second source value of the addition
|
1757
1835
|
* @param dst the destination value
|
1758
1836
|
* @return the destination value */
|
1759
|
-
static Value
|
1837
|
+
static Value greater_equal_value_numeric(Value src0, Value src1, Value dst) {
|
1760
1838
|
/* Sets state of the destination using the first source. */
|
1761
1839
|
dst->type = src0->type;
|
1762
1840
|
dst->numeric = 1;
|
1763
1841
|
|
1764
|
-
/* Perform the
|
1765
|
-
dst->data_int = (src0->data_int
|
1842
|
+
/* Perform the greater or equal. */
|
1843
|
+
dst->data_int = (src0->data_int >= src1->data_int);
|
1844
|
+
return dst;
|
1845
|
+
}
|
1846
|
+
|
1847
|
+
/** Computes the lesser or equal comparision of two numeric values.
|
1848
|
+
* @param src0 the first source value of the addition
|
1849
|
+
* @param src1 the second source value of the addition
|
1850
|
+
* @param dst the destination value
|
1851
|
+
* @return the destination value */
|
1852
|
+
static Value lesser_equal_value_numeric(Value src0, Value src1, Value dst) {
|
1853
|
+
/* Sets state of the destination using the first source. */
|
1854
|
+
dst->type = src0->type;
|
1855
|
+
dst->numeric = 1;
|
1856
|
+
|
1857
|
+
/* Perform the lesser or equal. */
|
1858
|
+
dst->data_int = (src0->data_int <= src1->data_int);
|
1766
1859
|
return dst;
|
1767
1860
|
}
|
1768
1861
|
|
@@ -2068,15 +2161,39 @@ Value sub_value(Value src0, Value src1, Value dst) {
|
|
2068
2161
|
* @param dst the destination value
|
2069
2162
|
* @return dst */
|
2070
2163
|
Value mul_value(Value src0, Value src1, Value dst) {
|
2164
|
+
// printf("mul_value with src0=%llx src1=%llx\n",value2integer(src0),value2integer(src1));
|
2165
|
+
// printf("src0->numeric=%d src1->numeric=%d\n",src0->numeric,src1->numeric);
|
2166
|
+
// printf("is_defined_value(src0)=%d is_defined_value(src1)=%d\n",is_defined_value(src0),is_defined_value(src1));
|
2071
2167
|
/* Might allocate a new value so save the current pool state. */
|
2072
2168
|
unsigned int pos = get_value_pos();
|
2073
2169
|
/* Do a numeric computation if possible, otherwise fallback to bitstring
|
2074
2170
|
* computation. */
|
2075
|
-
if (src0->numeric
|
2076
|
-
|
2077
|
-
|
2171
|
+
if (src0->numeric) {
|
2172
|
+
if (src1->numeric) {
|
2173
|
+
/* Both sources are numeric. */
|
2174
|
+
return mul_value_numeric(src0,src1,dst);
|
2175
|
+
} else if (is_defined_value(src1)) {
|
2176
|
+
// /* src1 is a defined bitstring, convert src0 to bitstring. */
|
2177
|
+
// src0 = set_bitstring_value(src0,get_value());
|
2178
|
+
// /* And do a bitstring multiplying. */
|
2179
|
+
// return mul_value_defined_bitstring(src0,src1,dst);
|
2180
|
+
/* src1 is a defined bitstring, convert it to a numeric. */
|
2181
|
+
src1 = set_numeric_value(src1,get_value());
|
2182
|
+
/* And do a numeri multiplying. */
|
2183
|
+
return mul_value_numeric(src0,src1,dst);
|
2184
|
+
}
|
2185
|
+
} else if (src1->numeric && is_defined_value(src0)) {
|
2186
|
+
// /* src1 is numeric but src0 is a defined bitstring, convert src1 to
|
2187
|
+
// * bitstring. */
|
2188
|
+
// src1 = set_bit_string_value(src1,get_value());
|
2189
|
+
// /* And do a bitstring multiplying. */
|
2190
|
+
// return mul_value_defined_bitstring(src0,src1,dst);
|
2191
|
+
/* src0 is a defined bitstring, convert it to a numeric. */
|
2192
|
+
src0 = set_numeric_value(src0,get_value());
|
2193
|
+
/* And do a numeri multiplying. */
|
2194
|
+
return mul_value_numeric(src0,src1,dst);
|
2078
2195
|
} else if (is_defined_value(src0) && is_defined_value(src1)) {
|
2079
|
-
/* Both sources
|
2196
|
+
/* Both sources are defined bitstrings. */
|
2080
2197
|
return mul_value_defined_bitstring(src0,src1,dst);
|
2081
2198
|
} else {
|
2082
2199
|
/* Cannot compute (for now), simply undefines the destination. */
|
@@ -2377,6 +2494,34 @@ Value equal_value(Value src0, Value src1, Value dst) {
|
|
2377
2494
|
}
|
2378
2495
|
|
2379
2496
|
|
2497
|
+
|
2498
|
+
/** Computes the greater comparision of two general values.
|
2499
|
+
* @param src0 the first source value of the addition
|
2500
|
+
* @param src1 the second source value of the addition
|
2501
|
+
* @param dst the destination value
|
2502
|
+
* @return dst */
|
2503
|
+
Value greater_value(Value src0, Value src1, Value dst) {
|
2504
|
+
/* Might allocate a new value so save the current pool state. */
|
2505
|
+
unsigned int pos = get_value_pos();
|
2506
|
+
/* Do a numeric computation if possible, otherwise fallback to bitstring
|
2507
|
+
* computation. */
|
2508
|
+
if (src0->numeric && src1->numeric) {
|
2509
|
+
/* Both sources are numeric. */
|
2510
|
+
return greater_value_numeric(src0,src1,dst);
|
2511
|
+
} else if (is_defined_value(src0) && is_defined_value(src1)) {
|
2512
|
+
/* Both sources can be converted to numeric values. */
|
2513
|
+
return greater_value_defined_bitstring(src0,src1,dst);
|
2514
|
+
} else {
|
2515
|
+
/* Cannot compute (for now), simply undefines the destination. */
|
2516
|
+
/* First ensure dst has the right shape. */
|
2517
|
+
copy_value(src0,dst);
|
2518
|
+
/* Then make it undefined. */
|
2519
|
+
set_undefined_bitstring(dst);
|
2520
|
+
}
|
2521
|
+
return dst;
|
2522
|
+
}
|
2523
|
+
|
2524
|
+
|
2380
2525
|
/** Computes the lesser comparision of two general values.
|
2381
2526
|
* @param src0 the first source value of the addition
|
2382
2527
|
* @param src1 the second source value of the addition
|
@@ -2404,22 +2549,22 @@ Value lesser_value(Value src0, Value src1, Value dst) {
|
|
2404
2549
|
}
|
2405
2550
|
|
2406
2551
|
|
2407
|
-
/** Computes the greater comparision of two
|
2408
|
-
* @param src0 the first source value of the
|
2409
|
-
* @param src1 the second source value of the
|
2552
|
+
/** Computes the greater or equal comparision of two values.
|
2553
|
+
* @param src0 the first source value of the comparison
|
2554
|
+
* @param src1 the second source value of the comparison
|
2410
2555
|
* @param dst the destination value
|
2411
2556
|
* @return dst */
|
2412
|
-
Value
|
2557
|
+
Value greater_equal_value(Value src0, Value src1, Value dst) {
|
2413
2558
|
/* Might allocate a new value so save the current pool state. */
|
2414
2559
|
unsigned int pos = get_value_pos();
|
2415
2560
|
/* Do a numeric computation if possible, otherwise fallback to bitstring
|
2416
2561
|
* computation. */
|
2417
2562
|
if (src0->numeric && src1->numeric) {
|
2418
2563
|
/* Both sources are numeric. */
|
2419
|
-
return
|
2564
|
+
return greater_equal_value_numeric(src0,src1,dst);
|
2420
2565
|
} else if (is_defined_value(src0) && is_defined_value(src1)) {
|
2421
2566
|
/* Both sources can be converted to numeric values. */
|
2422
|
-
return
|
2567
|
+
return greater_equal_value_defined_bitstring(src0,src1,dst);
|
2423
2568
|
} else {
|
2424
2569
|
/* Cannot compute (for now), simply undefines the destination. */
|
2425
2570
|
/* First ensure dst has the right shape. */
|
@@ -2430,6 +2575,33 @@ Value greater_value(Value src0, Value src1, Value dst) {
|
|
2430
2575
|
return dst;
|
2431
2576
|
}
|
2432
2577
|
|
2578
|
+
/** Computes the lesser or equal comparision of two values.
|
2579
|
+
* @param src0 the first source value of the comparison
|
2580
|
+
* @param src1 the second source value of the comparison
|
2581
|
+
* @param dst the destination value
|
2582
|
+
* @return dst */
|
2583
|
+
Value lesser_equal_value(Value src0, Value src1, Value dst) {
|
2584
|
+
/* Might allocate a new value so save the current pool state. */
|
2585
|
+
unsigned int pos = get_value_pos();
|
2586
|
+
/* Do a numeric computation if possible, otherwise fallback to bitstring
|
2587
|
+
* computation. */
|
2588
|
+
if (src0->numeric && src1->numeric) {
|
2589
|
+
/* Both sources are numeric. */
|
2590
|
+
return lesser_equal_value_numeric(src0,src1,dst);
|
2591
|
+
} else if (is_defined_value(src0) && is_defined_value(src1)) {
|
2592
|
+
/* Both sources can be converted to numeric values. */
|
2593
|
+
return lesser_equal_value_defined_bitstring(src0,src1,dst);
|
2594
|
+
} else {
|
2595
|
+
/* Cannot compute (for now), simply undefines the destination. */
|
2596
|
+
/* First ensure dst has the right shape. */
|
2597
|
+
copy_value(src0,dst);
|
2598
|
+
/* Then make it undefined. */
|
2599
|
+
set_undefined_bitstring(dst);
|
2600
|
+
}
|
2601
|
+
return dst;
|
2602
|
+
}
|
2603
|
+
|
2604
|
+
|
2433
2605
|
|
2434
2606
|
/** Selects a value depending on a general condition.
|
2435
2607
|
* @param cond the condition to use for selecting a value
|
@@ -285,7 +285,8 @@ void hruby_sim_advance_time() {
|
|
285
285
|
int i;
|
286
286
|
for(i=0; i<num_timed_behaviors; ++i) {
|
287
287
|
unsigned long long beh_time = timed_behaviors[i]->active_time;
|
288
|
-
if (
|
288
|
+
if (timed_behaviors[i]->timed == 1)
|
289
|
+
if (beh_time < next_time) next_time = beh_time;
|
289
290
|
}
|
290
291
|
/* Sets the new activation time. */
|
291
292
|
hruby_sim_time = next_time;
|
@@ -310,7 +311,9 @@ void hruby_sim_activate_behaviors_on_time() {
|
|
310
311
|
/* Count the number of behaviors that will be activated. */
|
311
312
|
for(i=0; i<num_timed_behaviors; ++i) {
|
312
313
|
Behavior beh = timed_behaviors[i];
|
313
|
-
|
314
|
+
// printf("beh->active_time=%llu\n",beh->active_time);
|
315
|
+
// if (beh->active_time == hruby_sim_time) {
|
316
|
+
if (beh->timed == 1 && beh->active_time == hruby_sim_time) {
|
314
317
|
/* Increase the number of timed behavior to wait for. */
|
315
318
|
num_active_behaviors ++;
|
316
319
|
// printf("num_active_behaviors = %d\n",num_active_behaviors);
|
@@ -318,18 +321,19 @@ void hruby_sim_activate_behaviors_on_time() {
|
|
318
321
|
}
|
319
322
|
/* Activate the behaviors .*/
|
320
323
|
behaviors_can_run = 1;
|
324
|
+
// printf("$2\n");
|
321
325
|
// pthread_cond_signal(&compute_cond); /* No behaviors. */
|
322
|
-
pthread_cond_signal(&hruby_beh_cond);
|
326
|
+
// pthread_cond_signal(&hruby_beh_cond);
|
323
327
|
pthread_mutex_unlock(&hruby_sim_mutex);
|
324
|
-
|
328
|
+
pthread_cond_broadcast(&hruby_beh_cond);
|
325
329
|
}
|
326
330
|
|
327
331
|
|
328
332
|
/** Wait for the active timed behaviors to advance. */
|
329
333
|
void hruby_sim_wait_behaviors() {
|
330
|
-
// printf("$3\n");
|
331
334
|
pthread_mutex_lock(&hruby_sim_mutex);
|
332
335
|
while(num_active_behaviors > 0) {
|
336
|
+
// printf("$3\n");
|
333
337
|
// printf("num_active_behaviors = %d\n",num_active_behaviors);
|
334
338
|
// pthread_cond_wait(&active_behaviors_cond, &hruby_sim_mutex);
|
335
339
|
pthread_cond_wait(&hruby_sim_cond, &hruby_sim_mutex);
|
@@ -349,6 +353,7 @@ void* behavior_run(void* arg) {
|
|
349
353
|
pthread_mutex_lock(&hruby_sim_mutex);
|
350
354
|
num_active_behaviors -= 1;
|
351
355
|
while(!behaviors_can_run) {
|
356
|
+
// printf("cannot run\n");
|
352
357
|
// pthread_cond_wait(&compute_cond, &hruby_sim_mutex);
|
353
358
|
pthread_cond_wait(&hruby_beh_cond, &hruby_sim_mutex);
|
354
359
|
}
|
@@ -356,12 +361,17 @@ void* behavior_run(void* arg) {
|
|
356
361
|
// printf("#2\n");
|
357
362
|
/* Now can start the execution of the behavior. */
|
358
363
|
behavior->block->function();
|
364
|
+
// printf("#3\n");
|
365
|
+
/* Now can start the execution of the behavior. */
|
359
366
|
/* Stops the behavior. */
|
360
367
|
pthread_mutex_lock(&hruby_sim_mutex);
|
361
368
|
num_active_behaviors -= 1;
|
362
369
|
num_run_behaviors -= 1;
|
363
|
-
|
370
|
+
// printf("num_run_behaviors=%d\n",num_run_behaviors);
|
371
|
+
behavior->timed = 2;
|
372
|
+
// pthread_cond_signal(&hruby_sim_cond);
|
364
373
|
pthread_mutex_unlock(&hruby_sim_mutex);
|
374
|
+
pthread_cond_signal(&hruby_sim_cond);
|
365
375
|
/* End the thread. */
|
366
376
|
pthread_exit(NULL);
|
367
377
|
}
|
@@ -374,11 +384,13 @@ void hruby_sim_start_timed_behaviors() {
|
|
374
384
|
pthread_mutex_lock(&hruby_sim_mutex);
|
375
385
|
/* Sets the end flags to 0. */
|
376
386
|
sim_end_flag = 0;
|
387
|
+
/* Tells the behavior can run. */
|
388
|
+
behaviors_can_run = 1;
|
377
389
|
/* Create and start the threads. */
|
378
390
|
for(i=0; i<num_timed_behaviors; ++i) {
|
379
391
|
num_run_behaviors += 1;
|
380
392
|
// ++num_active_behaviors;
|
381
|
-
// printf("0
|
393
|
+
// printf("0 num_run_behaviors = %d\n",num_run_behaviors);
|
382
394
|
pthread_create(&timed_behaviors[i]->thread,NULL,
|
383
395
|
&behavior_run,timed_behaviors[i]);
|
384
396
|
}
|
@@ -457,7 +469,6 @@ void hruby_sim_core(char* name, void (*init_vizualizer)(char*),
|
|
457
469
|
* @param delay the delay to wait in fs.
|
458
470
|
* @param behavior the current behavior. */
|
459
471
|
void hw_wait(unsigned long long delay, Behavior behavior) {
|
460
|
-
// printf("!1\n");
|
461
472
|
/* Maybe the thread is to end immediatly. */
|
462
473
|
if (sim_end_flag)
|
463
474
|
pthread_exit(NULL);
|
@@ -465,16 +476,20 @@ void hw_wait(unsigned long long delay, Behavior behavior) {
|
|
465
476
|
pthread_mutex_lock(&hruby_sim_mutex);
|
466
477
|
/* Indicate the behavior finished current execution. */
|
467
478
|
num_active_behaviors -= 1;
|
468
|
-
|
479
|
+
// printf("!!num_active_behaviors=%d\n",num_active_behaviors);
|
480
|
+
// pthread_cond_signal(&hruby_sim_cond);
|
469
481
|
/* Update the behavior's time. */
|
470
482
|
behavior->active_time += delay;
|
471
483
|
pthread_mutex_unlock(&hruby_sim_mutex);
|
484
|
+
pthread_cond_signal(&hruby_sim_cond);
|
472
485
|
/* Wait for being reactivated. */
|
473
486
|
while(behavior->active_time > hruby_sim_time) {
|
474
487
|
pthread_mutex_lock(&hruby_sim_mutex);
|
475
488
|
while(!behaviors_can_run) {
|
489
|
+
// printf("!1\n");
|
476
490
|
// pthread_cond_wait(&compute_cond, &hruby_sim_mutex);
|
477
491
|
pthread_cond_wait(&hruby_beh_cond, &hruby_sim_mutex);
|
492
|
+
// printf("!2\n");
|
478
493
|
}
|
479
494
|
pthread_mutex_unlock(&hruby_sim_mutex);
|
480
495
|
}
|