HDLRuby 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/HDLRuby.gemspec +1 -0
  3. data/README.md +10 -0
  4. data/ext/hruby_sim/hruby_rcsim_build.c +2 -0
  5. data/ext/hruby_sim/hruby_sim_calc.c +33 -6
  6. data/ext/hruby_sim/hruby_sim_tree_calc.c +111 -22
  7. data/lib/HDLRuby/hdr_samples/comparison_bench.rb +2 -2
  8. data/lib/HDLRuby/hdr_samples/counter_bench.rb +1 -1
  9. data/lib/HDLRuby/hdr_samples/counter_dff_bench.rb +8 -7
  10. data/lib/HDLRuby/hdr_samples/dff_properties.rb +2 -0
  11. data/lib/HDLRuby/hdr_samples/enum_as_param.rb +52 -0
  12. data/lib/HDLRuby/hdr_samples/linear_test.rb +2 -0
  13. data/lib/HDLRuby/hdr_samples/logic_bench.rb +6 -0
  14. data/lib/HDLRuby/hdr_samples/mei8.rb +6 -6
  15. data/lib/HDLRuby/hdr_samples/mei8_bench.rb +6 -6
  16. data/lib/HDLRuby/hdr_samples/memory_test.rb +2 -0
  17. data/lib/HDLRuby/hdr_samples/named_sub.rb +9 -5
  18. data/lib/HDLRuby/hdr_samples/ram.rb +7 -6
  19. data/lib/HDLRuby/hdr_samples/ruby_fir_hw.rb +2 -0
  20. data/lib/HDLRuby/hdr_samples/struct.rb +15 -3
  21. data/lib/HDLRuby/hdr_samples/with_bram.rb +1 -1
  22. data/lib/HDLRuby/hdr_samples/with_bram_frame_stack.rb +1 -1
  23. data/lib/HDLRuby/hdr_samples/with_bram_stack.rb +1 -1
  24. data/lib/HDLRuby/hdr_samples/with_channel.rb +2 -0
  25. data/lib/HDLRuby/hdr_samples/with_channel_other.rb +2 -0
  26. data/lib/HDLRuby/hdr_samples/with_class.rb +3 -1
  27. data/lib/HDLRuby/hdr_samples/with_connector.rb +2 -0
  28. data/lib/HDLRuby/hdr_samples/with_connector_memory.rb +2 -0
  29. data/lib/HDLRuby/hdr_samples/with_fixpoint.rb +6 -0
  30. data/lib/HDLRuby/hdr_samples/with_fixpoint_adv.rb +73 -0
  31. data/lib/HDLRuby/hdr_samples/with_leftright.rb +1 -1
  32. data/lib/HDLRuby/hdr_samples/with_sequencer.rb +17 -0
  33. data/lib/HDLRuby/hdr_samples/with_sequencer_channel.rb +58 -0
  34. data/lib/HDLRuby/hdr_samples/with_sequencer_enumerable.rb +10 -0
  35. data/lib/HDLRuby/hdr_samples/with_sequencer_enumerator.rb +18 -4
  36. data/lib/HDLRuby/hdr_samples/with_sequencer_sync.rb +2 -1
  37. data/lib/HDLRuby/hdrcc.rb +12 -0
  38. data/lib/HDLRuby/hruby_high.rb +82 -26
  39. data/lib/HDLRuby/hruby_low.rb +127 -3
  40. data/lib/HDLRuby/hruby_low2programs.rb +47 -0
  41. data/lib/HDLRuby/hruby_low_resolve.rb +3 -2
  42. data/lib/HDLRuby/hruby_low_without_namespace.rb +133 -5
  43. data/lib/HDLRuby/hruby_low_without_subsignals.rb +1 -1
  44. data/lib/HDLRuby/hruby_rcsim.rb +24 -1
  45. data/lib/HDLRuby/hruby_serializer.rb +2 -1
  46. data/lib/HDLRuby/hruby_verilog.rb +94 -20
  47. data/lib/HDLRuby/hruby_verilog_name.rb +3 -17
  48. data/lib/HDLRuby/std/fixpoint.rb +2 -2
  49. data/lib/HDLRuby/std/function_generator.rb +1 -1
  50. data/lib/HDLRuby/std/linear.rb +7 -7
  51. data/lib/HDLRuby/std/sequencer.rb +263 -13
  52. data/lib/HDLRuby/std/sequencer_channel.rb +90 -0
  53. data/lib/HDLRuby/std/sequencer_func.rb +28 -15
  54. data/lib/HDLRuby/std/std.rb +1 -0
  55. data/lib/HDLRuby/version.rb +1 -1
  56. metadata +22 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f491222adce0600f9d4ba58e748d4a72fd913adb50952fff71e5e67937f6b54
4
- data.tar.gz: ffdb34990f8dabcb0e38c3a7189e7f99c07c351cd86de6411f7eaa64314147f9
3
+ metadata.gz: bc9fecc1e612564d0a491efb3b33d88897b35dc6d40fc8a67da4c55212fececd
4
+ data.tar.gz: 8fc2490cf24c3b1343ea8bdfe0ae6dcfa56ce6e055661a19b7bed2b0929ec432
5
5
  SHA512:
6
- metadata.gz: 854a95c8b73d27c9673997cb138ebdceba87546bbd6d585d201110a9b8f0ae0be67f2c197a13a6e864c235fefb4a59ca99a4dc6f7311758becea639aadd3c0e6
7
- data.tar.gz: 60d260809614010f31e484c85e907b575518670770e4069da9216ba00e3b0a8502ef173dd260cf773e47d5ebd20d343ef00b815a840efbf7346c86b7b5b8c0cd
6
+ metadata.gz: 33448731ae5e188eefdca0cb18205abb31eedf26b0a84d9a48c4f873bbf2a978831f47f172453a726555c0845145938082dbb9e32e75da64fbe71279a5cac665
7
+ data.tar.gz: 7e75b9e351501e1ae8d2ca81e5e9f442ac3d29f400b49c9813bf6cddff409e24fd57ea72773287163f7d11b1226736c35de2f44fa14f5028f8480cd94661661f
data/HDLRuby.gemspec CHANGED
@@ -33,5 +33,6 @@ Gem::Specification.new do |spec|
33
33
  # spec.add_development_dependency "rake", "~> 10.0"
34
34
  spec.add_development_dependency "bundler", ">= 2.0.1"
35
35
  spec.add_development_dependency "rake", ">= 10.0"
36
+ spec.add_development_dependency "rake-compiler", ">= 1.0"
36
37
  # spec.add_development_dependency "minitest", "~> 5.0"
37
38
  end
data/README.md CHANGED
@@ -11,6 +11,16 @@ If you are new to HDLRuby, it is recommended that you consult first the followin
11
11
 
12
12
  __What's new__
13
13
 
14
+ For HDLRuby version 3.2.0:
15
+
16
+ * Added component for declaring BRAM and BRAM-based stacks.
17
+ The goal is to efficiently allocate memories inside FPGAs.
18
+
19
+ * Inner code overhaul for preparing version 4.0.0
20
+
21
+ * Multiple bug fixes
22
+
23
+
14
24
  For HDLRuby version 3.1.0:
15
25
 
16
26
  * [Functions for sequencers](#sequencer-specific-function-std-sequencer_func-rb) supporting recursion;
@@ -1443,6 +1443,8 @@ void Init_hruby_sim() {
1443
1443
 
1444
1444
  /* Create the class that wraps C pointers. */
1445
1445
  RCSimPointer = rb_define_class("RCSimPointer",rb_cObject);
1446
+ /* No allocator for C pointers. */
1447
+ rb_undef_alloc_func(RCSimPointer);
1446
1448
 
1447
1449
  /* Add the interface methods. */
1448
1450
  /* Getting the C simulation type objects. */
@@ -50,6 +50,12 @@
50
50
  // ({ __typeof__ (v) _v = (v); \
51
51
  // _v->type->flags.sign ? (_v->data[_v->size-1] >> (INT_BIT-1)) ? UINT_MAX : 0 : 0; })
52
52
 
53
+ /** Fix the sign of a numeric value. */
54
+ #define fix_numeric_sign(v) \
55
+ ({if ((v)->type->flags.sign && (type_width((v)->type) < 64) && ((v)->data_int & (1ULL << (type_width((v)->type)-1)))) {\
56
+ (v)->data_int |= (-1LL) << type_width((v)->type);\
57
+ }})
58
+
53
59
  /* The type engine: each type is simplified to a vector of X elements
54
60
  * of Y bits. */
55
61
 
@@ -900,6 +906,7 @@ static Value greater_equal_value_defined_bitstring(Value src0, Value src1, Value
900
906
  /* Converts the values to integers. */
901
907
  unsigned long long src0i = value2integer(src0);
902
908
  unsigned long long src1i = value2integer(src1);
909
+ // printf("src0i=%lld src1i=%lld, src0i.sign=%d src0i.width=%d, src1i.sign=%d src1i.width=%d\n",src0i,src1i,src0->type->flags.sign,type_width(src0->type),src1->type->flags.sign,type_width(src1->type));
903
910
  /* Perform the comparison. */
904
911
  if (src0->type->flags.sign) {
905
912
  if (src1->type->flags.sign)
@@ -1275,7 +1282,7 @@ static Value shift_left_value_bitstring_numeric(Value src0, Value src1, Value ds
1275
1282
  char d0 = src0_data[count];
1276
1283
  /* Set it to the destination at the right place. */
1277
1284
  unsigned long long pos = count + sh;
1278
- if ((pos>0) && (pos<width0)) {
1285
+ if ((pos>=0) && (pos<width0)) {
1279
1286
  dst_data[pos] = d0;
1280
1287
  }
1281
1288
  }
@@ -1290,6 +1297,7 @@ static Value shift_left_value_bitstring_numeric(Value src0, Value src1, Value ds
1290
1297
  * @param dst the destination
1291
1298
  * @return dst */
1292
1299
  static Value shift_right_value_bitstring_numeric(Value src0, Value src1, Value dst) {
1300
+ // printf("shift_right_value_bitstring_numeric with src0=%s src1=%lld\n",src0->data_str,src1->data_int);
1293
1301
  unsigned long long count;
1294
1302
  /* Get the widths of the first source. */
1295
1303
  unsigned long long width0 = type_width(src0->type);
@@ -1319,10 +1327,11 @@ static Value shift_right_value_bitstring_numeric(Value src0, Value src1, Value d
1319
1327
  char d0 = src0_data[count];
1320
1328
  /* Set it to the destination at the right place. */
1321
1329
  unsigned long long pos = count + sh;
1322
- if ((pos>0) && (pos<width0)) {
1330
+ if ((pos>=0) && (pos<width0)) {
1323
1331
  dst_data[pos] = d0;
1324
1332
  }
1325
1333
  }
1334
+ // printf("result=%s\n",dst_data);
1326
1335
  /* Return the destination value. */
1327
1336
  return dst;
1328
1337
  }
@@ -1683,6 +1692,7 @@ Value read_range_bitstring(Value src,
1683
1692
  unsigned long long first, unsigned long long last,
1684
1693
  Type base, Value dst) {
1685
1694
  // printf("read_range_bitstring with first=%lld last=%lld src=%s\n",first,last,src->data_str);
1695
+ // printf("read_range_bitstring with first=%lld last=%lld\n",first,last);
1686
1696
  /* Ensure first is the smaller. */
1687
1697
  if (first > last) {
1688
1698
  long long tmp = last;
@@ -1705,6 +1715,7 @@ Value read_range_bitstring(Value src,
1705
1715
 
1706
1716
  /* Performs the read. */
1707
1717
  memcpy(dst->data_str,src->data_str + first, length);
1718
+ // printf("result: %s\n",dst->data_str);
1708
1719
 
1709
1720
  /* Return the destination. */
1710
1721
  return dst;
@@ -1888,9 +1899,15 @@ static Value mul_value_numeric(Value src0, Value src1, Value dst) {
1888
1899
  /* Sets state of the destination using the first source. */
1889
1900
  dst->type = src0->type;
1890
1901
  dst->numeric = 1;
1902
+ /* Fix the numeric signs since multiply is sensitive to it. */
1903
+ // printf("src0 type_width=%d src1 type_width=%d (%d)\n",type_width(src0->type),type_width(src1->type),src1->type->flags.sign);
1904
+ fix_numeric_sign(src0);
1905
+ fix_numeric_sign(src1);
1906
+ // printf("Then src0->data_int=%llx src1->data_int=%llx\n",src0->data_int,src1->data_int);
1891
1907
 
1892
1908
  /* Perform the multiplication. */
1893
1909
  dst->data_int = fix_numeric_type(dst->type, src0->data_int * src1->data_int);
1910
+ // printf("result=%llx\n",dst->data_int);
1894
1911
  return dst;
1895
1912
  }
1896
1913
 
@@ -1905,6 +1922,10 @@ static Value div_value_numeric(Value src0, Value src1, Value dst) {
1905
1922
  dst->type = src0->type;
1906
1923
  dst->numeric = 1;
1907
1924
 
1925
+ /* Fix the numeric signs since multiply is sensitive to it. */
1926
+ fix_numeric_sign(src0);
1927
+ fix_numeric_sign(src1);
1928
+
1908
1929
  /* Perform the division. */
1909
1930
  dst->data_int = fix_numeric_type(dst->type, src0->data_int / src1->data_int);
1910
1931
  return dst;
@@ -3347,13 +3368,20 @@ RefRangeS make_ref_rangeS(SignalI signal, Type typ,
3347
3368
  * @param value the value to convert
3348
3369
  * @return the resulting int. */
3349
3370
  unsigned long long value2integer(Value value) {
3371
+ // printf("value2integer\n");
3350
3372
  unsigned long long width = type_width(value->type);
3351
- /* If the value is numeric, just return its data as is. */
3373
+ /* If the value is numeric, return it with its sign propoerly extended*/
3352
3374
  if (value->numeric) {
3353
3375
  // printf("width=%llu\n",width);
3354
3376
  if (width == 64)
3377
+ /* Nothing to do. */
3355
3378
  return value->data_int;
3379
+ else if (value->type->flags.sign &&
3380
+ ((value->data_int >> (width-1))&1))
3381
+ /* Sign extension. */
3382
+ return value->data_int | (0xFFFFFFFFFFFFFFFFULL << width);
3356
3383
  else
3384
+ /* Zero extension. */
3357
3385
  return value->data_int & ~(0xFFFFFFFFFFFFFFFFULL << width);
3358
3386
  }
3359
3387
  /* Otherwise convert the bitstring to an integer if possible,
@@ -3377,11 +3405,10 @@ unsigned long long value2integer(Value value) {
3377
3405
  res = (res << 1) | bit;
3378
3406
  }
3379
3407
  // printf("first res=%llx\n",res);
3380
- unsigned long long bit0 = (data_str[width-1]-'0') << i;
3381
3408
  /* Perform the sign extension if required. */
3382
- if (i>=width && value->type->flags.sign) {
3409
+ if (value->type->flags.sign) {
3410
+ unsigned long long bit0 = (data_str[width-1]-'0') << i;
3383
3411
  for(; i<LONG_LONG_BIT; ++i) {
3384
- // res = (res << 1) | bit;
3385
3412
  res |= bit0;
3386
3413
  bit0 <<= 1;
3387
3414
  }
@@ -121,6 +121,9 @@ Value calc_expression(Expression expr, Value res) {
121
121
  free_value();
122
122
  /* Performs the access. */
123
123
  res = read_range(value,index,index,rexpr->type,res);
124
+ /* Set the type to the one of the reference since it is
125
+ * an index access and not a range one. */
126
+ res->type = rexpr->type;
124
127
  free_value();
125
128
  break;
126
129
  }
@@ -174,6 +177,82 @@ Value calc_expression(Expression expr, Value res) {
174
177
  }
175
178
 
176
179
 
180
+ /** Calculates a range access from a reference.
181
+ * Recurse over the multiple references.
182
+ * @param ref the reference to work on.
183
+ * @param first the first index of the access.
184
+ * @param last the last index of the access.
185
+ * @param sig the target signal. */
186
+ void calc_ref_rangeS(Reference ref, long long* first, long long *last,
187
+ SignalI* sig) {
188
+ // printf("calc_ref_rangeS with kind=%d\n",ref->kind);
189
+ if (ref->kind == CAST) {
190
+ /* Create a new reference for the computation that changes the type. */
191
+ Cast refc = (Cast)ref;
192
+ /* Compute the range for the child. */
193
+ long long cfirst, clast;
194
+ calc_ref_rangeS(refc->child,&cfirst,&clast,sig);
195
+ /* Update first and last using the cast. */
196
+ /* Both first and last should be equal since the type of the cast sets
197
+ * the width */
198
+ // printf("cfirst=%d clast=%d\n",cfirst,clast);
199
+ *first = *last = cfirst;
200
+ }
201
+ else if (ref->kind == REF_INDEX) {
202
+ RefIndex refi = (RefIndex)ref;
203
+ /* Compute the index of refi. */
204
+ Value indexV = get_value();
205
+ indexV = calc_expression(refi->index,indexV);
206
+ long long index = value2integer(indexV);
207
+ // printf("index=%d\n",index);
208
+ free_value();
209
+ /* Is the reference a signal? */
210
+ if (refi->ref->kind == SIGNALI) {
211
+ /* Yes, end here. */
212
+ *first = index;
213
+ *last = index;
214
+ *sig = (SignalI)(refi->ref);
215
+ } else {
216
+ /* No, need to recurse. */
217
+ long long pfirst, plast;
218
+ calc_ref_rangeS(refi->ref,&pfirst,&plast,sig);
219
+ // printf("pfirst=%d plast=%d\n",pfirst,plast);
220
+ /* Calculate the final first and last. */
221
+ *first = *last = pfirst + index;
222
+ }
223
+ } else if (ref->kind == REF_RANGE) {
224
+ RefRangeE refr = (RefRangeE)ref;
225
+ /* Compute the range of refr */
226
+ Value firstV = get_value();
227
+ firstV = calc_expression(refr->first,firstV);
228
+ long long firstR = value2integer(firstV);
229
+ free_value();
230
+ Value lastV = get_value();
231
+ lastV = calc_expression(refr->last,lastV);
232
+ long long lastR = value2integer(lastV);
233
+ free_value();
234
+ // printf("firstR=%d lastR=%d\n",firstR,lastR);
235
+ /* Is the reference a signal? */
236
+ if (refr->ref->kind == SIGNALI) {
237
+ /* Yes, end here. */
238
+ *first = firstR;
239
+ *last = lastR;
240
+ *sig = (SignalI)(refr->ref);
241
+ } else {
242
+ /* No, need to recurse. */
243
+ long long pfirst, plast;
244
+ calc_ref_rangeS(refr->ref,&pfirst,&plast,sig);
245
+ /* Calculate the final first and last. */
246
+ *first = pfirst + firstR;
247
+ *last = plast + lastR;
248
+ }
249
+ } else {
250
+ perror("Invalid reference for converting to range access.");
251
+ exit(1);
252
+ }
253
+ }
254
+
255
+
177
256
 
178
257
  /** Executes a statement.
179
258
  * @param stmnt the statement to execute.
@@ -205,15 +284,22 @@ void execute_statement(Statement stmnt, int mode, Behavior behavior) {
205
284
  {
206
285
  /* Transmission to sub element. */
207
286
  RefIndex refi = (RefIndex)(trans->left);
208
- /* Compute the index. */
209
- Value indexV = get_value();
210
- indexV = calc_expression(refi->index,indexV);
211
- long long index = value2integer(indexV);
212
- free_value();
213
- /* Generate the reference inside the left value. */
287
+ // /* Compute the index. */
288
+ // Value indexV = get_value();
289
+ // indexV = calc_expression(refi->index,indexV);
290
+ // long long index = value2integer(indexV);
291
+ // free_value();
292
+ // /* Generate the reference inside the left value. */
293
+ // RefRangeS ref =
294
+ // make_ref_rangeS((SignalI)(refi->ref),refi->type,
295
+ // index,index);
296
+ /* Compute the range. */
297
+ long long first,last;
298
+ SignalI sig;
299
+ calc_ref_rangeS((Reference)refi,&first,&last,&sig);
300
+ /* Now can create the range. */
214
301
  RefRangeS ref =
215
- make_ref_rangeS((SignalI)(refi->ref),refi->type,
216
- index,index);
302
+ make_ref_rangeS(sig,refi->type,first,last);
217
303
  /* Perform the transmit. */
218
304
  if(mode)
219
305
  transmit_to_signal_range_seq(right,ref);
@@ -226,21 +312,24 @@ void execute_statement(Statement stmnt, int mode, Behavior behavior) {
226
312
  /* Transmission to range of sub elements. */
227
313
  RefRangeE refr = (RefRangeE)(trans->left);
228
314
  /* Compute the range. */
229
- // Value firstV = calc_expression(refr->first);
230
- Value firstV = get_value();
231
- firstV = calc_expression(refr->first,firstV);
232
- long long first = value2integer(firstV);
233
- free_value();
234
- // Value lastV = calc_expression(refr->last);
235
- Value lastV = get_value();
236
- lastV = calc_expression(refr->last,lastV);
237
- long long last = value2integer(lastV);
238
- free_value();
239
- // printf("firstV=%lld lastV=%lld right=%lld mode=%d\n",firstV->data_int,lastV->data_int,right->data_int,mode);
240
- /* Generate the reference inside the left value. */
315
+ // Value firstV = get_value();
316
+ // firstV = calc_expression(refr->first,firstV);
317
+ // long long first = value2integer(firstV);
318
+ // free_value();
319
+ // Value lastV = get_value();
320
+ // lastV = calc_expression(refr->last,lastV);
321
+ // long long last = value2integer(lastV);
322
+ // free_value();
323
+ // /* Generate the reference inside the left value. */
324
+ // RefRangeS ref =
325
+ // make_ref_rangeS((SignalI)(refr->ref),refr->type,
326
+ // first,last);
327
+ long long first,last;
328
+ SignalI sig;
329
+ calc_ref_rangeS((Reference)refr,&first,&last,&sig);
330
+ /* Now can create the range. */
241
331
  RefRangeS ref =
242
- make_ref_rangeS((SignalI)(refr->ref),refr->type,
243
- first,last);
332
+ make_ref_rangeS(sig,refr->type,first,last);
244
333
  /* Perform the transmit. */
245
334
  if(mode)
246
335
  transmit_to_signal_range_seq(right,ref);
@@ -1,7 +1,7 @@
1
1
  # Test the comparison operators.
2
2
 
3
- # A benchmark for the adder.
4
- system :adder_bench do
3
+ # A benchmark for the comparators.
4
+ system :comparison_bench do
5
5
  [8].inner :x, :y
6
6
  signed[8].inner :u,:v
7
7
  inner :ue, :ult, :ule, :ugt, :uge
@@ -19,8 +19,8 @@ system :counter do
19
19
  par do
20
20
  hif(rst) { [cc,qq] <= 0 }
21
21
  helse do
22
- add.(q,1,[cc,qq])
23
22
  hif(ctrl == 1) { add.(q,-1,[cc,qq]) }
23
+ helse { add.(q,1,[cc,qq]) }
24
24
  end
25
25
  end
26
26
 
@@ -1,34 +1,35 @@
1
1
  # A simple D-FF
2
2
  system :dff do
3
- input :clk, :d
3
+ input :clk, :rst, :d
4
4
  output :q
5
5
 
6
- (q <= d).at(clk.posedge)
6
+ (q <= d & ~rst).at(clk.posedge)
7
7
  end
8
8
 
9
9
  # A benchmark for the dff.
10
10
  system :dff_bench do
11
- inner :clk
11
+ inner :clk, :rst
12
12
  inner :d0, :q0, :d1, :q1
13
13
 
14
- dff(:my_dff0).(clk,d0,q0)
15
- dff(:my_dff1).(d0,d1,q1)
14
+ dff(:my_dff0).(clk,rst,d0,q0)
15
+ dff(:my_dff1).(d0,rst,d1,q1)
16
16
 
17
17
  d0 <= ~q0
18
18
  d1 <= ~q1
19
19
 
20
20
  timed do
21
- d0 <= 0
22
- d1 <= 0
23
21
  clk <= 0
22
+ rst <= 0
24
23
  !10.ns
25
24
  clk <= 1
26
25
  !10.ns
27
26
  clk <= 0
27
+ rst <= 1
28
28
  !10.ns
29
29
  clk <= 1
30
30
  !10.ns
31
31
  clk <= 0
32
+ rst <= 0
32
33
  !10.ns
33
34
  clk <= 1
34
35
  !10.ns
@@ -1,3 +1,5 @@
1
+ raise "Properties are deprecated in HDLRuby."
2
+
1
3
  # A simple D-FF
2
4
  system :dff do
3
5
  input :clk, :rst, :d
@@ -0,0 +1,52 @@
1
+ # Check if an enum can be passed as generic parameter.
2
+
3
+
4
+ system :machin do |vals|
5
+ input :clk,:rst
6
+ [8].output :res
7
+ sequencer(clk,rst) do
8
+ vals.seach { |val| res <= val }
9
+ end
10
+ end
11
+
12
+ system :truc do |sig|
13
+ [8].output :res
14
+
15
+ res <= sig
16
+ end
17
+
18
+ system :machin_bench do
19
+ inner :clk,:rst
20
+
21
+ bit[8][-4].inner vals: [ _h01,_h02,_h03,_h05 ]
22
+ [8].inner :res0
23
+
24
+ machin(vals).(:my_machin).(clk,rst,res0)
25
+
26
+ [8].inner :val, :res1
27
+ truc(val).(:my_truc).(res1)
28
+
29
+ timed do
30
+ val <= 10
31
+ clk <= 0
32
+ rst <= 0
33
+ !10.ns
34
+ clk <= 1
35
+ rst <= 0
36
+ !10.ns
37
+ clk <= 0
38
+ rst <= 1
39
+ !10.ns
40
+ clk <= 1
41
+ !10.ns
42
+ clk <= 0
43
+ rst <= 0
44
+ !10.ns
45
+ repeat(15) do
46
+ clk <= 1
47
+ !10.ns
48
+ clk <= 0
49
+ !10.ns
50
+ end
51
+ end
52
+ end
@@ -1,6 +1,8 @@
1
1
  require 'std/memory.rb'
2
2
  require 'std/linear.rb'
3
3
 
4
+ raise "std/memory.rb is deprecated."
5
+
4
6
  include HDLRuby::High::Std
5
7
 
6
8
  # Tries for matrix-vector product.
@@ -3,6 +3,8 @@
3
3
  system :logic_bench do
4
4
  [3].inner :x,:y
5
5
  [3].inner :s_not, :s_and, :s_or, :s_xor, :s_nxor
6
+
7
+ signed[16].inner :a,:b,:shl,:shr
6
8
 
7
9
  timed do
8
10
  8.times do |i|
@@ -15,6 +17,10 @@ system :logic_bench do
15
17
  s_xor <= x ^ y
16
18
  s_nxor <= (x == y)
17
19
  !10.ns
20
+ a <= i
21
+ b <= j
22
+ shl <= (a << b)
23
+ shr <= (a >> b)
18
24
  end
19
25
  end
20
26
  end
@@ -54,7 +54,7 @@ system :mei8 do |prog_file = "./prog.obj"|
54
54
  end
55
55
 
56
56
  # The control part for choosing between 0, add, sub and neg.
57
- par do
57
+ par(opr,x,y) do
58
58
  # Default computations
59
59
  cf <= 0; vf <= 0; zf <= (z == 0); sf <= z[7]
60
60
  add.(0,0,0)
@@ -148,14 +148,14 @@ system :mei8 do |prog_file = "./prog.obj"|
148
148
  end
149
149
  end
150
150
 
151
+ # Handling of the 3-state data bus
152
+ dbus <= mux(io_rwb,io_out,_bzzzzzzzz)
153
+ io_in <= dbus
154
+
151
155
  # The io unit.
152
156
  fsm(clk.posedge,rst,:async) do
153
157
  default { io_done <= 0; req <= 0; rwb <= 0; addr <= 0
154
- io_r_done <= 0
155
- # Default handling of the 3-state data bus
156
- hif(io_rwb) { dbus <= _zzzzzzzz }
157
- helse { dbus <= io_out }
158
- io_in <= dbus }
158
+ io_r_done <= 0 }
159
159
  reset(:sync) { data <= 0; }
160
160
  state(:wait) { goto(io_req,:start,:wait) } # Waiting for an IO
161
161
  state(:start) { req <= 1; rwb <= io_rwb; addr <= g # Start an IO
@@ -56,7 +56,7 @@ system :mei8 do |prog_file = "./prog.obj"|
56
56
  end
57
57
 
58
58
  # The control part for choosing between 0, add, sub and neg.
59
- par do
59
+ par(opr,x,y) do
60
60
  # Default computations
61
61
  cf <= 0; vf <= 0; zf <= (z == 0); sf <= z[7]
62
62
  add.(0,0,0)
@@ -150,14 +150,14 @@ system :mei8 do |prog_file = "./prog.obj"|
150
150
  end
151
151
  end
152
152
 
153
+ # Handling of the 3-state data bus
154
+ dbus <= mux(io_rwb,io_out,_bzzzzzzzz)
155
+ io_in <= dbus
156
+
153
157
  # The io unit.
154
158
  fsm(clk.posedge,rst,:async) do
155
159
  default { io_done <= 0; req <= 0; rwb <= 0; addr <= 0
156
- io_r_done <= 0
157
- # Default handling of the 3-state data bus
158
- hif(io_rwb) { dbus <= _zzzzzzzz }
159
- helse { dbus <= io_out }
160
- io_in <= dbus }
160
+ io_r_done <= 0 }
161
161
  reset(:sync) { data <= 0; }
162
162
  state(:wait) { goto(io_req,:start,:wait) } # Waiting for an IO
163
163
  state(:start) { req <= 1; rwb <= io_rwb; addr <= g # Start an IO
@@ -1,5 +1,7 @@
1
1
  require 'std/memory.rb'
2
2
 
3
+ raise "std/memory.rb is deprecated."
4
+
3
5
  include HDLRuby::High::Std
4
6
 
5
7
 
@@ -4,9 +4,9 @@
4
4
 
5
5
 
6
6
  # A simple circuit with named sub
7
- system :named_sub do
8
- input :x, :y
9
- output :s
7
+ system :named_sub do |x|
8
+ input :y
9
+ output :s, :z
10
10
 
11
11
  sub :somesub do
12
12
  inner :sig
@@ -17,13 +17,17 @@ system :named_sub do
17
17
  s <= ~somesub.sig
18
18
  end
19
19
 
20
+ z <= s
21
+
20
22
  end
21
23
 
22
24
  # A benchmark for the circuit.
23
25
  system :named_sub_bench do
24
- inner :x, :y, :s
26
+ inner :x, :y, :s, :z
27
+
28
+ named_sub(x).(:my_named_sub).(y,s)
25
29
 
26
- named_sub(:my_named_sub).(x,y,s)
30
+ z <= my_named_sub.z
27
31
 
28
32
  timed do
29
33
  x <= 0
@@ -4,15 +4,16 @@ system :ram8_16 do
4
4
  [7..0].input :addr
5
5
  [7..0].inout :data
6
6
 
7
+ [7..0].inner :data_in
8
+
7
9
  bit[7..0][2**8].inner :content
8
10
 
9
- # Memory enabled?
11
+ data <= mux(en & rwb, _bzzzzzzzz, content[addr])
12
+ data_in <= data
13
+
10
14
  par(clk.posedge) do
11
- hif(en) do
12
- # Read case
13
- hif(rwb) { data <= content[addr] }
14
- helse { content[addr] <= data }
15
+ hif(en & ~rwb) do
16
+ content[addr] <= data_in
15
17
  end
16
- helse { data <= _bZZZZZZZZ }
17
18
  end
18
19
  end
@@ -2,6 +2,8 @@ require 'std/memory.rb'
2
2
  require 'std/linear.rb'
3
3
  # require 'std/timing.rb'
4
4
 
5
+ raise "std/memory.rb is deprecated."
6
+
5
7
  include HDLRuby::High::Std
6
8
 
7
9
 
@@ -8,6 +8,8 @@ system :my_system do
8
8
  inner :z
9
9
  { sub0: bit, sub1: bit[2]}.inner :sigA
10
10
  some_struct.inner :sigB, :sigC
11
+ # { sub4: bit[8], sub5: bit[8] }.to_type[-2].inner :sigs
12
+ { sub4: bit[8][-2], sub5: bit[8][-2] }.inner :sigs
11
13
 
12
14
  sigC <= sigA
13
15
 
@@ -15,9 +17,19 @@ system :my_system do
15
17
 
16
18
 
17
19
  timed do
18
- z <= 0
19
- x <= 1
20
- y <= _b000
20
+ # z <= 0
21
+ # x <= 1
22
+ # y <= _b000
23
+
24
+ # sigs[0].sub4 <= 1
25
+ # sigs[0].sub5 <= 2
26
+ # sigs[1].sub4 <= 3
27
+ # sigs[1].sub5 <= 4
28
+ sigs.sub4[0] <= 1
29
+ sigs.sub5[0] <= 2
30
+ sigs.sub4[1] <= 3
31
+ sigs.sub5[1] <= 4
32
+
21
33
  !10.ns
22
34
  sigA.sub0 <= 0
23
35
  sigA.sub1 <= x
@@ -10,7 +10,7 @@ system :bram_test do
10
10
  widthD = 8
11
11
 
12
12
 
13
- input :clk,:rwb
13
+ inner :clk,:rwb
14
14
  [widthA].inner :addr
15
15
  [widthD].inner :din,:dout
16
16