HDLRuby 2.11.11 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.html +3274 -0
- data/README.md +608 -99
- data/ext/hruby_sim/hruby_rcsim_build.c +27 -0
- data/ext/hruby_sim/hruby_sim.h +3 -0
- data/ext/hruby_sim/hruby_sim_calc.c +2 -0
- data/ext/hruby_sim/hruby_sim_core.c +17 -5
- data/ext/hruby_sim/hruby_sim_stack_calc.c +1 -1
- data/ext/hruby_sim/hruby_sim_tree_calc.c +8 -1
- data/ext/hruby_sim/hruby_sim_vcd.c +24 -7
- data/ext/hruby_sim/hruby_sim_vizualize.c +9 -1
- data/lib/HDLRuby/backend/hruby_allocator.rb +2 -2
- data/lib/HDLRuby/backend/hruby_c_allocator.rb +7 -7
- data/lib/HDLRuby/hdr_samples/constant_in_function.rb +3 -1
- data/lib/HDLRuby/hdr_samples/counter_dff_bench.rb +3 -1
- data/lib/HDLRuby/hdr_samples/huge_rom.rb +1 -1
- data/lib/HDLRuby/hdr_samples/mei8.rb +11 -11
- data/lib/HDLRuby/hdr_samples/mei8_bench.rb +12 -12
- data/lib/HDLRuby/hdr_samples/neg_arith_bench.rb +4 -4
- data/lib/HDLRuby/hdr_samples/rom_nest.rb +1 -1
- data/lib/HDLRuby/hdr_samples/ruby_fir_hw.rb +4 -4
- data/lib/HDLRuby/hdr_samples/struct.rb +44 -10
- data/lib/HDLRuby/hdr_samples/with_bram.rb +45 -0
- data/lib/HDLRuby/hdr_samples/with_bram_frame_stack.rb +105 -0
- data/lib/HDLRuby/hdr_samples/with_bram_stack.rb +69 -0
- data/lib/HDLRuby/hdr_samples/with_casts.rb +3 -3
- data/lib/HDLRuby/hdr_samples/with_concat.rb +6 -6
- data/lib/HDLRuby/hdr_samples/with_connector_memory.rb +2 -2
- data/lib/HDLRuby/hdr_samples/with_def.rb +10 -3
- data/lib/HDLRuby/hdr_samples/with_define_operator.rb +44 -0
- data/lib/HDLRuby/hdr_samples/with_fixpoint.rb +12 -12
- data/lib/HDLRuby/hdr_samples/with_init.rb +3 -3
- data/lib/HDLRuby/hdr_samples/with_leftright.rb +21 -0
- data/lib/HDLRuby/hdr_samples/with_reduce.rb +13 -13
- data/lib/HDLRuby/hdr_samples/with_ref_array.rb +6 -6
- data/lib/HDLRuby/hdr_samples/with_register_stack.rb +150 -0
- data/lib/HDLRuby/hdr_samples/with_sequencer.rb +190 -0
- data/lib/HDLRuby/hdr_samples/with_sequencer_deep.rb +91 -0
- data/lib/HDLRuby/hdr_samples/with_sequencer_enumerable.rb +405 -0
- data/lib/HDLRuby/hdr_samples/with_sequencer_enumerator.rb +89 -0
- data/lib/HDLRuby/hdr_samples/with_sequencer_sync.rb +120 -0
- data/lib/HDLRuby/hdr_samples/with_subsums.rb +3 -3
- data/lib/HDLRuby/hdr_samples/with_terminate.rb +3 -3
- data/lib/HDLRuby/hdr_samples/with_to_a.rb +10 -10
- data/lib/HDLRuby/hdr_samples/with_values.rb +3 -3
- data/lib/HDLRuby/hdrcc.rb +29 -3
- data/lib/HDLRuby/hdrlib.rb +1 -1
- data/lib/HDLRuby/hruby_bstr.rb +10 -5
- data/lib/HDLRuby/hruby_db.rb +2 -2
- data/lib/HDLRuby/hruby_high.rb +152 -47
- data/lib/HDLRuby/hruby_high_fullname.rb +3 -1
- data/lib/HDLRuby/hruby_low.rb +189 -18
- data/lib/HDLRuby/hruby_low2c.rb +129 -54
- data/lib/HDLRuby/hruby_low2hdr.rb +66 -40
- data/lib/HDLRuby/hruby_low2high.rb +86 -44
- data/lib/HDLRuby/hruby_low2seq.rb +26 -18
- data/lib/HDLRuby/hruby_low2sym.rb +14 -13
- data/lib/HDLRuby/hruby_low2vhd.rb +80 -44
- data/lib/HDLRuby/hruby_low_bool2select.rb +61 -46
- data/lib/HDLRuby/hruby_low_casts_without_expression.rb +56 -44
- data/lib/HDLRuby/hruby_low_cleanup.rb +18 -16
- data/lib/HDLRuby/hruby_low_fix_types.rb +65 -32
- data/lib/HDLRuby/hruby_low_mutable.rb +83 -119
- data/lib/HDLRuby/hruby_low_resolve.rb +38 -30
- data/lib/HDLRuby/hruby_low_with_bool.rb +33 -16
- data/lib/HDLRuby/hruby_low_with_port.rb +3 -3
- data/lib/HDLRuby/hruby_low_with_var.rb +23 -9
- data/lib/HDLRuby/hruby_low_without_concat.rb +45 -19
- data/lib/HDLRuby/hruby_low_without_namespace.rb +47 -32
- data/lib/HDLRuby/hruby_low_without_parinseq.rb +32 -16
- data/lib/HDLRuby/hruby_low_without_select.rb +37 -24
- data/lib/HDLRuby/hruby_low_without_subsignals.rb +280 -0
- data/lib/HDLRuby/hruby_rcsim.rb +158 -134
- data/lib/HDLRuby/hruby_rsim.rb +194 -20
- data/lib/HDLRuby/hruby_rsim_mute.rb +2 -3
- data/lib/HDLRuby/hruby_rsim_vcd.rb +125 -50
- data/lib/HDLRuby/hruby_values.rb +48 -33
- data/lib/HDLRuby/hruby_verilog.rb +90 -48
- data/lib/HDLRuby/soft/stacks.rb +219 -0
- data/lib/HDLRuby/std/bram.rb +26 -0
- data/lib/HDLRuby/std/clocks.rb +1 -1
- data/lib/HDLRuby/std/fixpoint.rb +2 -2
- data/lib/HDLRuby/std/fsm.rb +48 -11
- data/lib/HDLRuby/std/function_generator.rb +2 -2
- data/lib/HDLRuby/std/sequencer.rb +1857 -0
- data/lib/HDLRuby/std/sequencer_sync.rb +400 -0
- data/lib/HDLRuby/std/std.rb +12 -0
- data/lib/HDLRuby/version.rb +1 -1
- data/tuto/adder_sat_flags_vcd.png +0 -0
- data/tuto/addsub_vcd.png +0 -0
- data/tuto/alu_vcd.png +0 -0
- data/tuto/bit_pong_vcd.png +0 -0
- data/tuto/checksum_vcd.png +0 -0
- data/tuto/circuit_hdr.odg +0 -0
- data/tuto/circuit_hdr.png +0 -0
- data/tuto/circuit_hie.odg +0 -0
- data/tuto/circuit_hie.png +0 -0
- data/tuto/circuit_view.odg +0 -0
- data/tuto/circuit_view.png +0 -0
- data/tuto/clock_counter_vcd.png +0 -0
- data/tuto/counter_ext_vcd.png +0 -0
- data/tuto/fact_vcd.png +0 -0
- data/tuto/hw_flow.odg +0 -0
- data/tuto/hw_flow.png +0 -0
- data/tuto/maxxer_vcd.png +0 -0
- data/tuto/pingpong0_vcd.png +0 -0
- data/tuto/pingpong1_vcd.png +0 -0
- data/tuto/pingpong2_vcd.png +0 -0
- data/tuto/ram_vcd.png +0 -0
- data/tuto/serializer_vcd.png +0 -0
- data/tuto/sw_flow.odg +0 -0
- data/tuto/sw_flow.png +0 -0
- data/tuto/the_counter_vcd.png +0 -0
- data/tuto/tutorial_sw.html +2359 -0
- data/tuto/tutorial_sw.md +2684 -0
- data/tuto/tutorial_sw.pdf +0 -0
- data/tuto/tutorial_sw_jp.md +417 -0
- metadata +49 -3
- data/lib/HDLRuby/hdr_samples/sumprod.rb +0 -29
@@ -319,6 +319,9 @@ VALUE rcsim_make_signal(VALUE mod, VALUE name, VALUE type) {
|
|
319
319
|
// printf("Creating signal named=%s\n",signal->name);
|
320
320
|
value_to_rcsim(TypeS,type,signal->type);
|
321
321
|
// printf("&type=%p type=%p width=%llu\n",&(signal->type),signal->type,type_width(signal->type));
|
322
|
+
signal->num_signals= 0;
|
323
|
+
signal->signals = NULL;
|
324
|
+
|
322
325
|
signal->c_value = make_value(signal->type,0);
|
323
326
|
// printf("signal->c_value=%p\n",signal->c_value);
|
324
327
|
signal->c_value->signal = signal;
|
@@ -1075,6 +1078,29 @@ VALUE rcsim_add_systemI_systemTs(VALUE mod, VALUE systemIV, VALUE sysVs) {
|
|
1075
1078
|
return systemIV;
|
1076
1079
|
}
|
1077
1080
|
|
1081
|
+
/* Adds sub signals a C signal. */
|
1082
|
+
VALUE rcsim_add_signal_signals(VALUE mod, VALUE signalIV, VALUE sigVs) {
|
1083
|
+
/* Get the C signal from the Ruby value. */
|
1084
|
+
SignalI signalI;
|
1085
|
+
value_to_rcsim(SignalIS,signalIV,signalI);
|
1086
|
+
// printf("rcsim_add_signal_signals with signalI=%p\n",signalI);
|
1087
|
+
/* Prepare the size for the alternate system types. */
|
1088
|
+
long num = RARRAY_LEN(sigVs);
|
1089
|
+
long old_num = signalI->num_signals;
|
1090
|
+
signalI->num_signals += num;
|
1091
|
+
signalI->signals=realloc(signalI->signals,
|
1092
|
+
sizeof(SignalI[signalI->num_signals]));
|
1093
|
+
// signalI->signals = (SignalI*)my_realloc(signalI->signals,
|
1094
|
+
// sizeof(SignalI[old_num]), sizeof(SignalI[signalI->num_signals]));
|
1095
|
+
/* Get and add the alternate system types from the Ruby value. */
|
1096
|
+
for(long i=0; i< num; ++i) {
|
1097
|
+
SignalI sig;
|
1098
|
+
value_to_rcsim(SignalIS,rb_ary_entry(sigVs,i),sig);
|
1099
|
+
signalI->signals[old_num + i] = sig;
|
1100
|
+
}
|
1101
|
+
return signalIV;
|
1102
|
+
}
|
1103
|
+
|
1078
1104
|
/* Adds arguments to a C print. */
|
1079
1105
|
VALUE rcsim_add_print_args(VALUE mod, VALUE printV, VALUE argVs) {
|
1080
1106
|
/* Get the C print from the Ruby value. */
|
@@ -1459,6 +1485,7 @@ void Init_hruby_sim() {
|
|
1459
1485
|
rb_define_singleton_method(mod,"rcsim_add_scope_scopes",rcsim_add_scope_scopes,2);
|
1460
1486
|
rb_define_singleton_method(mod,"rcsim_add_behavior_events",rcsim_add_behavior_events,2);
|
1461
1487
|
rb_define_singleton_method(mod,"rcsim_add_systemI_systemTs",rcsim_add_systemI_systemTs,2);
|
1488
|
+
rb_define_singleton_method(mod,"rcsim_add_signal_signals",rcsim_add_signal_signals,2);
|
1462
1489
|
rb_define_singleton_method(mod,"rcsim_add_print_args",rcsim_add_print_args,2);
|
1463
1490
|
rb_define_singleton_method(mod,"rcsim_add_hif_noifs",rcsim_add_hif_noifs,3);
|
1464
1491
|
rb_define_singleton_method(mod,"rcsim_add_hcase_whens",rcsim_add_hcase_whens,3);
|
data/ext/hruby_sim/hruby_sim.h
CHANGED
@@ -530,6 +530,9 @@ typedef struct SignalIS_ {
|
|
530
530
|
Value c_value; /* The current value of the signal. */
|
531
531
|
Value f_value; /* The future (next) value of the signal. */
|
532
532
|
|
533
|
+
int num_signals; /* The number of sub signals. */
|
534
|
+
SignalI* signals; /* The sub signals. */
|
535
|
+
|
533
536
|
int fading; /* Tell if the signal can be overwritten by Z. */
|
534
537
|
|
535
538
|
int num_any; /* The number of behavior activated on any edge. */
|
@@ -1777,6 +1777,8 @@ Value write_range_bitstring_no_z(Value src,
|
|
1777
1777
|
unsigned long long bw = type_width(base);
|
1778
1778
|
first *= bw;
|
1779
1779
|
last *= bw;
|
1780
|
+
last += bw-1;
|
1781
|
+
// printf("bw=%lld, first=%lld, last=%lld\n",bw,first,last);
|
1780
1782
|
/* Access the source and destination bitstring data. */
|
1781
1783
|
char* dst_data = dst->data_str;
|
1782
1784
|
char* src_data = src->data_str;
|
@@ -729,14 +729,26 @@ void transmit_to_signal_range_seq(Value value, RefRangeS ref) {
|
|
729
729
|
SignalI signal = ref.signal;
|
730
730
|
unsigned long long first = ref.first;
|
731
731
|
unsigned long long last = ref.last;
|
732
|
-
// printf("Tansmit to signal range: %s(%p) [%llu,%llu]\n",signal->name,signal,first,last);
|
732
|
+
// printf("Tansmit to signal range seq: %s(%p) [%llu,%llu]\n",signal->name,signal,first,last);
|
733
|
+
// /* Can transmit, copy the content. */
|
734
|
+
// if (signal->fading)
|
735
|
+
// // write_range(value,first,last,signal->f_value->type,signal->f_value);
|
736
|
+
// write_range(value,first,last,ref.type,signal->f_value);
|
737
|
+
// else
|
738
|
+
// // write_range_no_z(value,first,last,signal->f_value->type,signal->f_value);
|
739
|
+
// write_range_no_z(value,first,last,ref.type,signal->f_value);
|
740
|
+
/* The base type is stored here to avoid allocating a new type each time.
|
741
|
+
* It have an arbitrary base size a single element. */
|
742
|
+
static TypeS baseT = { 1, 1 };
|
743
|
+
baseT.base = signal->f_value->type->base;
|
744
|
+
// printf("Tansmit to signal range: %s(%p) [%lld:%lld]\n",signal->name,signal,first,last);
|
733
745
|
/* Can transmit, copy the content. */
|
734
746
|
if (signal->fading)
|
735
|
-
|
736
|
-
|
747
|
+
signal->f_value = write_range(value,first,last,&baseT,
|
748
|
+
signal->f_value);
|
737
749
|
else
|
738
|
-
|
739
|
-
|
750
|
+
signal->f_value = write_range_no_z(value,first,last,&baseT,
|
751
|
+
signal->f_value);
|
740
752
|
/* And touch the signal. */
|
741
753
|
touch_signal_seq(signal);
|
742
754
|
}
|
@@ -181,7 +181,7 @@ Value calc_expression(Expression expr, Value res) {
|
|
181
181
|
* @param behavior the behavior in execution. */
|
182
182
|
void execute_statement(Statement stmnt, int mode, Behavior behavior) {
|
183
183
|
/* Depending on the kind of statement. */
|
184
|
-
// printf("Executing statement=%p with kind=%d\n",stmnt,stmnt->kind);fflush(stdout);
|
184
|
+
// printf("Executing statement=%p with kind=%d in mode=%d\n",stmnt,stmnt->kind,mode);fflush(stdout);
|
185
185
|
switch(stmnt->kind) {
|
186
186
|
case TRANSMIT:
|
187
187
|
{
|
@@ -236,6 +236,7 @@ void execute_statement(Statement stmnt, int mode, Behavior behavior) {
|
|
236
236
|
lastV = calc_expression(refr->last,lastV);
|
237
237
|
long long last = value2integer(lastV);
|
238
238
|
free_value();
|
239
|
+
// printf("firstV=%lld lastV=%lld right=%lld mode=%d\n",firstV->data_int,lastV->data_int,right->data_int,mode);
|
239
240
|
/* Generate the reference inside the left value. */
|
240
241
|
RefRangeS ref =
|
241
242
|
make_ref_rangeS((SignalI)(refr->ref),refr->type,
|
@@ -399,9 +400,15 @@ void execute_statement(Statement stmnt, int mode, Behavior behavior) {
|
|
399
400
|
}
|
400
401
|
break;
|
401
402
|
}
|
403
|
+
case TIME_TERMINATE:
|
404
|
+
{
|
405
|
+
terminate();
|
406
|
+
break;
|
407
|
+
}
|
402
408
|
case BLOCK:
|
403
409
|
{
|
404
410
|
Block block = (Block)stmnt;
|
411
|
+
// printf("Block mode=%d\n",block->mode);
|
405
412
|
/* Execute each statement of the block. */
|
406
413
|
for(int i=0; i<block->num_stmnts; ++i)
|
407
414
|
execute_statement(block->stmnts[i],block->mode,behavior);
|
@@ -155,12 +155,28 @@ static void vcd_print_value(Value value) {
|
|
155
155
|
/** Prints a signal declaration.
|
156
156
|
* @param signal the signal to declare */
|
157
157
|
static void vcd_print_var(SignalI signal) {
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
158
|
+
if (signal->num_signals > 0) {
|
159
|
+
int i;
|
160
|
+
/* The signal is hierarchical, declare its sub signals. */
|
161
|
+
/* Declares the hierachical name. */
|
162
|
+
vcd_print("$scope module ");
|
163
|
+
vcd_print_name((Object)signal);
|
164
|
+
vcd_print(" $end\n");
|
165
|
+
/* Declare the inners of the systems. */
|
166
|
+
for(i=0; i<signal->num_signals; ++i) {
|
167
|
+
vcd_print_var(signal->signals[i]);
|
168
|
+
}
|
169
|
+
/* Close the hierarchy. */
|
170
|
+
vcd_print("$upscope $end\n");
|
171
|
+
} else {
|
172
|
+
/* The signal is flat, can declarate it directly. */
|
173
|
+
vcd_print("$var wire %d ",type_width(signal->type));
|
174
|
+
// vcd_print_full_name((Object)signal);
|
175
|
+
vcd_print_signal_id(signal);
|
176
|
+
vcd_print(" ");
|
177
|
+
vcd_print_name((Object)signal);
|
178
|
+
vcd_print(" $end\n");
|
179
|
+
}
|
164
180
|
}
|
165
181
|
|
166
182
|
|
@@ -180,7 +196,8 @@ static void vcd_print_signal_fvalue(SignalI signal) {
|
|
180
196
|
/** Prints a signal with its current value if any
|
181
197
|
* @param signal the signal to show */
|
182
198
|
static void vcd_print_signal_cvalue(SignalI signal) {
|
183
|
-
if (signal->c_value) {
|
199
|
+
if ((signal->num_signals == 0) && signal->c_value) {
|
200
|
+
/* The signal is not hierachical and has a current value. */
|
184
201
|
vcd_print_value(signal->c_value);
|
185
202
|
// vcd_print(" ");
|
186
203
|
// vcd_print_full_name((Object)signal);
|
@@ -63,8 +63,15 @@ void default_print_name(Object object) {
|
|
63
63
|
}
|
64
64
|
/* Depending on the kind of object. */
|
65
65
|
switch(object->kind) {
|
66
|
-
case SYSTEMT:
|
67
66
|
case SIGNALI:
|
67
|
+
/* Print the name if name. */
|
68
|
+
/* Trick: SystemT, SignalI, Scope and SystemI have the
|
69
|
+
* field name at the same place. */
|
70
|
+
if (((SignalI)object)->name != NULL) {
|
71
|
+
printf("%s",((SignalI)object)->name);
|
72
|
+
}
|
73
|
+
break;
|
74
|
+
case SYSTEMT:
|
68
75
|
case SCOPE:
|
69
76
|
case SYSTEMI:
|
70
77
|
/* Print the name if name. */
|
@@ -73,6 +80,7 @@ void default_print_name(Object object) {
|
|
73
80
|
if (((SystemI)object)->name != NULL) {
|
74
81
|
printf("%s",((SystemI)object)->name);
|
75
82
|
}
|
83
|
+
break;
|
76
84
|
default: /* Nothing to do */
|
77
85
|
break;
|
78
86
|
}
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require "HDLRuby/hruby_error"
|
2
2
|
|
3
|
+
module HDLRuby::Low
|
3
4
|
|
4
5
|
|
5
6
|
##
|
6
7
|
# Adds methods for allocating addresses to signals in Code objects.
|
7
8
|
#
|
8
9
|
########################################################################
|
9
|
-
module HDLRuby::Low
|
10
10
|
|
11
|
-
##
|
11
|
+
## Describes an allocator.
|
12
12
|
class Allocator
|
13
13
|
|
14
14
|
# The space range for the allocation.
|
@@ -3,16 +3,16 @@ require "HDLRuby/hruby_low_resolve"
|
|
3
3
|
require "HDLRuby/backend/hruby_allocator"
|
4
4
|
|
5
5
|
|
6
|
+
module HDLRuby::Low
|
6
7
|
|
7
8
|
##
|
8
9
|
# Adds methods for allocating addresses to signals in Code objects and
|
9
10
|
# integrate the result into C code.
|
10
11
|
#
|
11
12
|
########################################################################
|
12
|
-
module HDLRuby::Low
|
13
13
|
|
14
|
-
## Extends the SystemT class with support for C allocation of signals.
|
15
14
|
class SystemT
|
15
|
+
## Extends the SystemT class with support for C allocation of signals.
|
16
16
|
|
17
17
|
## Allocates signals within C code using +allocator+.
|
18
18
|
def c_code_allocate(allocator)
|
@@ -21,8 +21,8 @@ module HDLRuby::Low
|
|
21
21
|
end
|
22
22
|
|
23
23
|
|
24
|
-
## Extends the scope class with support for C allocation of signals.
|
25
24
|
class Scope
|
25
|
+
## Extends the scope class with support for C allocation of signals.
|
26
26
|
|
27
27
|
## Allocates signals within C code using +allocator+.
|
28
28
|
def c_code_allocate(allocator)
|
@@ -34,10 +34,10 @@ module HDLRuby::Low
|
|
34
34
|
end
|
35
35
|
|
36
36
|
|
37
|
-
## Extends the chunk class with support for self modification with
|
38
|
-
# allocation.
|
39
|
-
# NOTE: only work if the chunk is in C language.
|
40
37
|
class Chunk
|
38
|
+
## Extends the chunk class with support for self modification with
|
39
|
+
# allocation.
|
40
|
+
# NOTE: only works if the chunk is in C language.
|
41
41
|
|
42
42
|
## Allocates signal within C code using +allocator+ and self-modify
|
43
43
|
# the code correspondingly.
|
@@ -61,8 +61,8 @@ module HDLRuby::Low
|
|
61
61
|
end
|
62
62
|
|
63
63
|
|
64
|
-
## Extends the code class with support for C allocation of signals.
|
65
64
|
class Code
|
65
|
+
## Extends the code class with support for C allocation of signals.
|
66
66
|
|
67
67
|
## Allocates signals within C code using +allocator+.
|
68
68
|
def c_code_allocate(allocator)
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
function :func do |addr|
|
5
|
-
bit[4][-4].constant tbl: [
|
5
|
+
bit[4][-4].constant tbl: [ _b1000, _b1001, _b1010, _b1011 ]
|
6
6
|
|
7
7
|
tbl[addr]
|
8
8
|
end
|
@@ -10,9 +10,11 @@ end
|
|
10
10
|
|
11
11
|
system :with_func do
|
12
12
|
[4].inner :addr, :val
|
13
|
+
# bit[4][-4].constant tbl: [ _b1000, _b1001, _b1010, _b1011 ]
|
13
14
|
|
14
15
|
val <= func(addr)
|
15
16
|
# val <= 1
|
17
|
+
# val <= tbl[addr]
|
16
18
|
|
17
19
|
timed do
|
18
20
|
addr <= 0
|
@@ -117,7 +117,7 @@ system :mei8 do |prog_file = "./prog.obj"|
|
|
117
117
|
# Format 1
|
118
118
|
entry("01oooyyy") { wf <= 1
|
119
119
|
# Destination is also y in case of inc/dec
|
120
|
-
hif (ir[6..4] ==
|
120
|
+
hif (ir[6..4] == _b101) { dst <= y }
|
121
121
|
alu.(o,a,src1) } # binary alu
|
122
122
|
# Format 1 extended.
|
123
123
|
entry("10000yyy") { wr <= 0; wf <= 1
|
@@ -128,17 +128,17 @@ system :mei8 do |prog_file = "./prog.obj"|
|
|
128
128
|
entry("10011yyy") { branch <= 1 # jr y, must inc y
|
129
129
|
alu.(2,src1) } # since pc-1 is used
|
130
130
|
# Format 2
|
131
|
-
entry("1010iiii") { alu.(7,[
|
131
|
+
entry("1010iiii") { alu.(7,[_b0000,i]) } # movl i
|
132
132
|
entry("1011iiii") { alu.(7,[i,a[3..0]]) } # movh i
|
133
133
|
# Format 4
|
134
134
|
entry("11110110") { branch <= 1 # trap
|
135
135
|
alu.(7,0xFC) }
|
136
|
-
entry("11110ooo") { wf <= 1; alu.([
|
136
|
+
entry("11110ooo") { wf <= 1; alu.([_b1,o],a) } # unary alu
|
137
137
|
entry("111110os") { st <= s; ld <= ~s # ++--ld / ++--st
|
138
|
-
alu.([
|
138
|
+
alu.([_b001,o],g); dst <= 6 }
|
139
139
|
entry("1111110i") { branch <= i
|
140
140
|
st <= ~i; ld <= i
|
141
|
-
alu.([
|
141
|
+
alu.([_b001,~i],h)
|
142
142
|
dst <= 7; io_out <= pc } # push / pop pc
|
143
143
|
# Format 3
|
144
144
|
entry("11cccsii") { branch <= cc; wr <= 0
|
@@ -180,7 +180,7 @@ system :mei8 do |prog_file = "./prog.obj"|
|
|
180
180
|
[a,b,c,d,e,f,g,h,zf,cf,sf,vf,nbr,npc,s].each { |r| r <= 0 }
|
181
181
|
end
|
182
182
|
# Ensures a is 0 and enable interrupts when starting.
|
183
|
-
helsif(init) { a<= 0; s <=
|
183
|
+
helsif(init) { a<= 0; s <= _b00000011; }
|
184
184
|
helsif(iq_calc) do
|
185
185
|
s[7] <= 1
|
186
186
|
hif(iq1) { s[1] <= 0 }
|
@@ -195,14 +195,14 @@ system :mei8 do |prog_file = "./prog.obj"|
|
|
195
195
|
zf <= alu.zf; cf <= alu.cf; sf <= alu.sf; vf <= alu.vf
|
196
196
|
end
|
197
197
|
# Specific cases
|
198
|
-
hif(ir ==
|
199
|
-
hif(ir ==
|
198
|
+
hif(ir == _b11110111) { s <= a; a <= s } # xs
|
199
|
+
hif(ir == _b11110110) { s[7] <= 1 } # trap
|
200
200
|
hif(branch) { npc <= alu.z; nbr <= 1 } # Branch
|
201
201
|
end
|
202
202
|
# Write memory read result to a register if any.
|
203
203
|
helsif (io_r_done) do
|
204
204
|
hif(branch) { npc <= data; nbr <= 1 } # pop case
|
205
|
-
helsif(ir[7..3] ==
|
205
|
+
helsif(ir[7..3] == _b10001) do # ld case
|
206
206
|
[a,b,c,d,e,f,g,h].hcase(dst) {|r| r <= data }
|
207
207
|
end
|
208
208
|
helse { a <= data } # ld++-- case
|
@@ -231,8 +231,8 @@ system :mei8 do |prog_file = "./prog.obj"|
|
|
231
231
|
goto(iq_chk,:iq_s) # Interrupt / No interrupt
|
232
232
|
goto(branch,:br) # Branch instruction
|
233
233
|
goto((ld|st) & ~io_done,:ld_st) # ld/st instruction
|
234
|
-
goto(ir ==
|
235
|
-
goto(ir ==
|
234
|
+
goto(ir == _b11111110,:ht) # Halt instruction
|
235
|
+
goto(ir == _b11111111,:re) } # Reset instruction
|
236
236
|
# Branch state.
|
237
237
|
state(:br) { goto(iq_chk,:iq_s,:fe) } # Interrupt / No interrupt
|
238
238
|
sync(:br) { hif(nbr) { pc <= npc-1 } } # Next pc is the branch target
|
@@ -28,7 +28,7 @@ system :mei8 do |prog_file = "./prog.obj"|
|
|
28
28
|
bit[7..0][-256].constant mem: # The content of the memory
|
29
29
|
( File.readlines(prog_file).map {|l| l.split[0] }.select do |l|
|
30
30
|
["0","1"].include?(l[2])
|
31
|
-
end.map {|l| l[2..9].to_i(2) } )
|
31
|
+
end.map {|l| l[2..9].to_i(2).to_expr.as(bit[8]) } )
|
32
32
|
instr <= mem[addr] # The access procedure
|
33
33
|
end
|
34
34
|
|
@@ -119,7 +119,7 @@ system :mei8 do |prog_file = "./prog.obj"|
|
|
119
119
|
# Format 1
|
120
120
|
entry("01oooyyy") { wf <= 1
|
121
121
|
# Destination is also y in case of inc/dec
|
122
|
-
hif (ir[6..4] ==
|
122
|
+
hif (ir[6..4] == _b101) { dst <= y }
|
123
123
|
alu.(o,a,src1) } # binary alu
|
124
124
|
# Format 1 extended.
|
125
125
|
entry("10000yyy") { wr <= 0; wf <= 1
|
@@ -130,17 +130,17 @@ system :mei8 do |prog_file = "./prog.obj"|
|
|
130
130
|
entry("10011yyy") { branch <= 1 # jr y, must inc y
|
131
131
|
alu.(2,src1) } # since pc-1 is used
|
132
132
|
# Format 2
|
133
|
-
entry("1010iiii") { alu.(7,[
|
133
|
+
entry("1010iiii") { alu.(7,[_b0000,i]) } # movl i
|
134
134
|
entry("1011iiii") { alu.(7,[i,a[3..0]]) } # movh i
|
135
135
|
# Format 4
|
136
136
|
entry("11110110") { branch <= 1 # trap
|
137
137
|
alu.(7,0xFC) }
|
138
|
-
entry("11110ooo") { wf <= 1; alu.([
|
138
|
+
entry("11110ooo") { wf <= 1; alu.([_b1,o],a) } # unary alu
|
139
139
|
entry("111110os") { st <= s; ld <= ~s # ++--ld / ++--st
|
140
|
-
alu.([
|
140
|
+
alu.([_b001,o],g); dst <= 6 }
|
141
141
|
entry("1111110i") { branch <= i
|
142
142
|
st <= ~i; ld <= i
|
143
|
-
alu.([
|
143
|
+
alu.([_b001,~i],h)
|
144
144
|
dst <= 7; io_out <= pc } # push / pop pc
|
145
145
|
# Format 3
|
146
146
|
entry("11cccsii") { branch <= cc; wr <= 0
|
@@ -182,7 +182,7 @@ system :mei8 do |prog_file = "./prog.obj"|
|
|
182
182
|
[a,b,c,d,e,f,g,h,zf,cf,sf,vf,nbr,npc,s].each { |r| r <= 0 }
|
183
183
|
end
|
184
184
|
# Ensures a is 0 and enable interrupts when starting.
|
185
|
-
helsif(init) { a<= 0; s <=
|
185
|
+
helsif(init) { a<= 0; s <= _b00000011; }
|
186
186
|
helsif(iq_calc) do
|
187
187
|
s[7] <= 1
|
188
188
|
hif(iq1) { s[1] <= 0 }
|
@@ -197,14 +197,14 @@ system :mei8 do |prog_file = "./prog.obj"|
|
|
197
197
|
zf <= alu.zf; cf <= alu.cf; sf <= alu.sf; vf <= alu.vf
|
198
198
|
end
|
199
199
|
# Specific cases
|
200
|
-
hif(ir ==
|
201
|
-
hif(ir ==
|
200
|
+
hif(ir == _b11110111) { s <= a; a <= s } # xs
|
201
|
+
hif(ir == _b11110110) { s[7] <= 1 } # trap
|
202
202
|
hif(branch) { npc <= alu.z; nbr <= 1 } # Branch
|
203
203
|
end
|
204
204
|
# Write memory read result to a register if any.
|
205
205
|
helsif (io_r_done) do
|
206
206
|
hif(branch) { npc <= data; nbr <= 1 } # pop case
|
207
|
-
helsif(ir[7..3] ==
|
207
|
+
helsif(ir[7..3] == _b10001) do # ld case
|
208
208
|
[a,b,c,d,e,f,g,h].hcase(dst) {|r| r <= data }
|
209
209
|
end
|
210
210
|
helse { a <= data } # ld++-- case
|
@@ -233,8 +233,8 @@ system :mei8 do |prog_file = "./prog.obj"|
|
|
233
233
|
goto(iq_chk,:iq_s) # Interrupt / No interrupt
|
234
234
|
goto(branch,:br) # Branch instruction
|
235
235
|
goto((ld|st) & ~io_done,:ld_st) # ld/st instruction
|
236
|
-
goto(ir ==
|
237
|
-
goto(ir ==
|
236
|
+
goto(ir == _b11111110,:ht) # Halt instruction
|
237
|
+
goto(ir == _b11111111,:re) } # Reset instruction
|
238
238
|
# Branch state.
|
239
239
|
state(:br) { goto(iq_chk,:iq_s,:fe) } # Interrupt / No interrupt
|
240
240
|
sync(:br) { hif(nbr) { pc <= npc-1 } } # Next pc is the branch target
|
@@ -42,15 +42,15 @@ system :neg_arith_bench do
|
|
42
42
|
z <= x * y
|
43
43
|
cmp <= (x < y)
|
44
44
|
!10.ns
|
45
|
-
x <=
|
46
|
-
y <=
|
45
|
+
x <= _b000000011010
|
46
|
+
y <= _b000011111010
|
47
47
|
z <= 0
|
48
48
|
!10.ns
|
49
49
|
z <= x * y
|
50
50
|
cmp <= (x < y)
|
51
51
|
!10.ns
|
52
|
-
x <=
|
53
|
-
y <=
|
52
|
+
x <= _b000000011010
|
53
|
+
y <= _b111111111010
|
54
54
|
z <= 0
|
55
55
|
!10.ns
|
56
56
|
z <= x * y
|
@@ -50,13 +50,13 @@ system :work do
|
|
50
50
|
|
51
51
|
# The input memory.
|
52
52
|
mem_rom([8],8,clk,rst,
|
53
|
-
[
|
54
|
-
|
53
|
+
[_b00000001,_b00000010,_b00000011,_b00000100,
|
54
|
+
_b00000101,_b00000110,_b00000111,_b00001000]).(:iMem)
|
55
55
|
# The output memory.
|
56
56
|
mem_dual([8],8,clk,rst).(:oMem)
|
57
57
|
# The coefficients.
|
58
|
-
coefs = [
|
59
|
-
|
58
|
+
coefs = [_b11001100,_b00110011,_b10101010,_b01010101,
|
59
|
+
_b11110000,_b00001111,_b11100011,_b00011100]
|
60
60
|
|
61
61
|
# The filter
|
62
62
|
fir([8],iMem.branch(:rinc),oMem.branch(:winc),coefs).(:my_fir).(clk,rst,req,ack)
|
@@ -1,14 +1,48 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
output :q
|
4
|
-
|
5
|
-
par(clk.posedge) { q <= d & ~rst }
|
1
|
+
typedef(:some_struct) do
|
2
|
+
{ sub2: bit, sub3: bit[2] }
|
6
3
|
end
|
7
4
|
|
8
5
|
system :my_system do
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
inner :x
|
7
|
+
[3].inner :y
|
8
|
+
inner :z
|
9
|
+
{ sub0: bit, sub1: bit[2]}.inner :sigA
|
10
|
+
some_struct.inner :sigB, :sigC
|
11
|
+
|
12
|
+
sigC <= sigA
|
13
|
+
|
14
|
+
par(sigA) { z <= ~z }
|
15
|
+
|
16
|
+
|
17
|
+
timed do
|
18
|
+
z <= 0
|
19
|
+
x <= 1
|
20
|
+
y <= _b000
|
21
|
+
!10.ns
|
22
|
+
sigA.sub0 <= 0
|
23
|
+
sigA.sub1 <= x
|
24
|
+
sigB.sub2 <= 0
|
25
|
+
sigB.sub3 <= x
|
26
|
+
!10.ns
|
27
|
+
sigA.sub0 <= x
|
28
|
+
sigA.sub1 <= ~sigB.sub3
|
29
|
+
sigB.sub2 <= x
|
30
|
+
sigB.sub3 <= ~sigA.sub1
|
31
|
+
!10.ns
|
32
|
+
sigA <= _b111
|
33
|
+
sigB <= _b111
|
34
|
+
!10.ns
|
35
|
+
sigA <= _b100
|
36
|
+
!10.ns
|
37
|
+
y <= sigA
|
38
|
+
sigB <= sigA
|
39
|
+
!10.ns
|
40
|
+
sigA <= _b011
|
41
|
+
!10.ns
|
42
|
+
sigB <= sigA
|
43
|
+
!10.ns
|
44
|
+
sigB <= sigA + 1
|
45
|
+
!10.ns
|
46
|
+
end
|
47
|
+
|
14
48
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'std/bram.rb'
|
2
|
+
|
3
|
+
include HDLRuby::High::Std
|
4
|
+
|
5
|
+
|
6
|
+
# A system testing the memory.
|
7
|
+
system :bram_test do
|
8
|
+
|
9
|
+
widthA = 16
|
10
|
+
widthD = 8
|
11
|
+
|
12
|
+
|
13
|
+
input :clk,:rwb
|
14
|
+
[widthA].inner :addr
|
15
|
+
[widthD].inner :din,:dout
|
16
|
+
|
17
|
+
bram(widthA,widthD).(:bramI).(clk,rwb,addr,din,dout)
|
18
|
+
|
19
|
+
timed do
|
20
|
+
clk <= 0
|
21
|
+
rwb <= 0
|
22
|
+
addr <= 0
|
23
|
+
din <= 0
|
24
|
+
!10.ns
|
25
|
+
clk <= 1
|
26
|
+
!10.ns
|
27
|
+
rwb <= 0
|
28
|
+
repeat(16) do
|
29
|
+
clk <= 0
|
30
|
+
!10.ns
|
31
|
+
clk <= 1
|
32
|
+
addr <= addr + 1
|
33
|
+
din <= din + 1
|
34
|
+
!10.ns
|
35
|
+
end
|
36
|
+
rwb <= 1
|
37
|
+
repeat(16) do
|
38
|
+
clk <= 0
|
39
|
+
!10.ns
|
40
|
+
clk <= 1
|
41
|
+
addr <= addr-1
|
42
|
+
!10.ns
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|