HDLRuby 3.7.6 → 3.7.8
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.md +4 -0
- data/ext/hruby_sim/hruby_sim_calc.c +282 -72
- data/lib/HDLRuby/hdr_samples/comparison_bench.rb +34 -0
- data/lib/HDLRuby/std/sequencer_sw.rb +102 -37
- data/lib/HDLRuby/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 343e43059315343f17e5999397af265b9d7c241ce527c57855b4b7d24d4c698a
|
4
|
+
data.tar.gz: d21dd89efe29eb843ad69c20ae802bad2c11d9d2ad5f6a2d96a904cdd72b9b33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ebc27526e8c259b80a40171e7eb65fa529c477621366296926acbb266f20dd44a55cff96a875cf77cf7c3d739d2d7f252281fec9671a06400829ae01f84883b
|
7
|
+
data.tar.gz: 36e07d94b685e170b815ca07f1e2c8e50b580b02c49602e8737aced082e606b3c269e1173c9ed92dee89d53418f1dc3a04491d0d9510992e4f04088062fca15e
|
data/README.md
CHANGED
@@ -690,13 +690,13 @@ static Value mul_value_defined_bitstring(Value src0, Value src1, Value dst) {
|
|
690
690
|
int sgn1 = (src1->type->flags.sign) && (src1->data_str[width1-1] == '1');
|
691
691
|
// printf("sgn0=%d sgn1=%d\n",(src0->type->flags.sign) && (src0->data_str[width0-1] == '1'),sgn1);
|
692
692
|
Value psrc1;
|
693
|
-
// printf("first
|
693
|
+
// printf("first src1->data_str=%s\n",src1->data_str);fflush(stdout);
|
694
694
|
if (sgn1) {
|
695
695
|
psrc1 = neg_value_bitstring(src1,get_value());
|
696
696
|
} else {
|
697
697
|
psrc1 = src1;
|
698
698
|
}
|
699
|
-
// printf("now
|
699
|
+
// printf("now psrc1->data_str=%s\n",psrc1->data_str);fflush(stdout);
|
700
700
|
/* Perform the multiplying with sucessive shifts and additions. */
|
701
701
|
/* First the result is zero. */
|
702
702
|
const char* str = psrc1->data_str;
|
@@ -778,8 +778,8 @@ static Value mod_value_defined_bitstring(Value src0, Value src1, Value dst) {
|
|
778
778
|
|
779
779
|
|
780
780
|
/** Computes the greater comparision of two defined bitstring values.
|
781
|
-
* @param src0 the first source value of the
|
782
|
-
* @param src1 the second source value of the
|
781
|
+
* @param src0 the first source value of the comparison
|
782
|
+
* @param src1 the second source value of the comparison
|
783
783
|
* @param dst the destination value
|
784
784
|
* @return dst */
|
785
785
|
static Value greater_value_defined_bitstring(Value src0, Value src1, Value dst) {
|
@@ -788,28 +788,13 @@ static Value greater_value_defined_bitstring(Value src0, Value src1, Value dst)
|
|
788
788
|
dst->type = src0->type;
|
789
789
|
dst->numeric = 1;
|
790
790
|
|
791
|
-
// /* Converts the values to integers. */
|
792
|
-
// unsigned long long src0i = value2integer(src0);
|
793
|
-
// unsigned long long src1i = value2integer(src1);
|
794
|
-
// /* Perform the comparison. */
|
795
|
-
// if (src0->type->flags.sign) {
|
796
|
-
// if (src1->type->flags.sign)
|
797
|
-
// dst->data_int = (signed long long)src0i > (signed long long)src1i;
|
798
|
-
// else
|
799
|
-
// dst->data_int = (signed long long)src0i >= 0 ? src0i > src1i : 0;
|
800
|
-
// } else {
|
801
|
-
// if (src1->type->flags.sign)
|
802
|
-
// dst->data_int = (signed long long)src1i >= 0 ? src0i > src1i : 1;
|
803
|
-
// else
|
804
|
-
// dst->data_int = src0i > src1i;
|
805
|
-
// }
|
806
791
|
char* src0_data = src0->data_str;
|
807
792
|
char* src1_data = src1->data_str;
|
808
793
|
long long width0 = type_width(src0->type);
|
809
794
|
long long width1 = type_width(src1->type);
|
810
795
|
long long width = width0>width1 ? width0 : width1;
|
811
|
-
if (src0->type->flags.sign && src0_data[width0-1] == '1') {
|
812
|
-
if(src1->type->flags.sign && src1_data[width1-1] == '1') {
|
796
|
+
if (src0->type->flags.sign && (src0_data[width0-1] == '1')) {
|
797
|
+
if(src1->type->flags.sign && (src1_data[width1-1] == '1')) {
|
813
798
|
/* Negative-negative comparison. */
|
814
799
|
for(long long i=width-1; i >= 0; --i) {
|
815
800
|
char d0 = i >= width0 ? '1' : src0_data[i];
|
@@ -828,7 +813,7 @@ static Value greater_value_defined_bitstring(Value src0, Value src1, Value dst)
|
|
828
813
|
return dst;
|
829
814
|
}
|
830
815
|
} else {
|
831
|
-
if(src1->type->flags.sign && src1_data[width1-1] == '1') {
|
816
|
+
if(src1->type->flags.sign && (src1_data[width1-1] == '1')) {
|
832
817
|
/* Positive-negative comparison, src0 is greater. */
|
833
818
|
dst->data_int = 1;
|
834
819
|
return dst;
|
@@ -852,9 +837,72 @@ static Value greater_value_defined_bitstring(Value src0, Value src1, Value dst)
|
|
852
837
|
return dst;
|
853
838
|
}
|
854
839
|
|
840
|
+
/** Computes the greater comparision of a numeric value and a
|
841
|
+
* defined bitstring values.
|
842
|
+
* @param src0 the first source value of the comparison
|
843
|
+
* @param src1 the second source value of the comparison
|
844
|
+
* @param dst the destination value
|
845
|
+
* @return dst */
|
846
|
+
static Value greater_value_numeric_defined_bitstring(Value src0, Value src1, Value dst) {
|
847
|
+
// printf("greater_value_numeric_defined_bitstring.\n");
|
848
|
+
/* Sets state of the destination using the first source. */
|
849
|
+
dst->type = src0->type;
|
850
|
+
dst->numeric = 1;
|
851
|
+
|
852
|
+
unsigned long long src0_int = src0->data_int;
|
853
|
+
char* src1_data = src1->data_str;
|
854
|
+
long long width0 = type_width(src0->type);
|
855
|
+
long long width1 = type_width(src1->type);
|
856
|
+
long long width = width0>width1 ? width0 : width1;
|
857
|
+
if (src0->type->flags.sign && (src0_int & (1 << (width0-1)))) {
|
858
|
+
if(src1->type->flags.sign && (src1_data[width1-1] == '1')) {
|
859
|
+
/* Negative-negative comparison. */
|
860
|
+
for(long long i=width-1; i >= 0; --i) {
|
861
|
+
char d0 = i >= width0 ? '1' :
|
862
|
+
((src0_int & (1 << i)) ? '1' : '0');
|
863
|
+
char d1 = i >= width1 ? '1' : src1_data[i];
|
864
|
+
if (d0 < d1) {
|
865
|
+
dst->data_int = 0;
|
866
|
+
return dst;
|
867
|
+
} else if (d0 > d1) {
|
868
|
+
dst->data_int = 1;
|
869
|
+
return dst;
|
870
|
+
}
|
871
|
+
}
|
872
|
+
} else {
|
873
|
+
/* Negative positive comparison, src0 is smaller. */
|
874
|
+
dst->data_int = 0;
|
875
|
+
return dst;
|
876
|
+
}
|
877
|
+
} else {
|
878
|
+
if(src1->type->flags.sign && (src1_data[width1-1] == '1')) {
|
879
|
+
/* Positive-negative comparison, src0 is greater. */
|
880
|
+
dst->data_int = 1;
|
881
|
+
return dst;
|
882
|
+
} else {
|
883
|
+
/* Positive-positive comparison. */
|
884
|
+
for(long long i=width-1; i >= 0; --i) {
|
885
|
+
char d0 = i >= width0 ? '0' :
|
886
|
+
((src0_int & (1 << i)) ? '1' : '0');
|
887
|
+
char d1 = i >= width1 ? '0' : src1_data[i];
|
888
|
+
if (d0 < d1) {
|
889
|
+
dst->data_int = 0;
|
890
|
+
return dst;
|
891
|
+
} else if (d0 > d1) {
|
892
|
+
dst->data_int = 1;
|
893
|
+
return dst;
|
894
|
+
}
|
895
|
+
}
|
896
|
+
}
|
897
|
+
}
|
898
|
+
/* Equality. */
|
899
|
+
dst->data_int = 0;
|
900
|
+
return dst;
|
901
|
+
}
|
902
|
+
|
855
903
|
/** Computes the lesser comparision of two defined bitstring values.
|
856
|
-
* @param src0 the first source value of the
|
857
|
-
* @param src1 the second source value of the
|
904
|
+
* @param src0 the first source value of the comparison
|
905
|
+
* @param src1 the second source value of the comparison
|
858
906
|
* @param dst the destination value
|
859
907
|
* @return dst */
|
860
908
|
static Value lesser_value_defined_bitstring(Value src0, Value src1, Value dst) {
|
@@ -863,21 +911,6 @@ static Value lesser_value_defined_bitstring(Value src0, Value src1, Value dst) {
|
|
863
911
|
dst->type = src0->type;
|
864
912
|
dst->numeric = 1;
|
865
913
|
|
866
|
-
// /* Converts the values to integers. */
|
867
|
-
// unsigned long long src0i = value2integer(src0);
|
868
|
-
// unsigned long long src1i = value2integer(src1);
|
869
|
-
// /* Perform the comparison. */
|
870
|
-
// if (src0->type->flags.sign) {
|
871
|
-
// if (src1->type->flags.sign)
|
872
|
-
// dst->data_int = (signed long long)src0i < (signed long long)src1i;
|
873
|
-
// else
|
874
|
-
// dst->data_int = (signed long long)src0i >= 0 ? src0i < src1i : 1;
|
875
|
-
// } else {
|
876
|
-
// if (src1->type->flags.sign)
|
877
|
-
// dst->data_int = (signed long long)src1i >= 0 ? src0i < src1i : 0;
|
878
|
-
// else
|
879
|
-
// dst->data_int = src0i < src1i;
|
880
|
-
// }
|
881
914
|
char* src0_data = src0->data_str;
|
882
915
|
char* src1_data = src1->data_str;
|
883
916
|
long long width0 = type_width(src0->type);
|
@@ -927,32 +960,80 @@ static Value lesser_value_defined_bitstring(Value src0, Value src1, Value dst) {
|
|
927
960
|
return dst;
|
928
961
|
}
|
929
962
|
|
963
|
+
/** Computes the lesser comparision of one numeric value and one
|
964
|
+
* defined bitstring values.
|
965
|
+
* @param src0 the first source value of the comparison
|
966
|
+
* @param src1 the second source value of the comparison
|
967
|
+
* @param dst the destination value
|
968
|
+
* @return dst */
|
969
|
+
static Value lesser_value_numeric_defined_bitstring(Value src0, Value src1, Value dst) {
|
970
|
+
// printf("lesser_value_numeric_defined_bitstring.\n");
|
971
|
+
/* Sets state of the destination using the first source. */
|
972
|
+
dst->type = src0->type;
|
973
|
+
dst->numeric = 1;
|
974
|
+
|
975
|
+
unsigned long long src0_int = src0->data_int;
|
976
|
+
char* src1_data = src1->data_str;
|
977
|
+
long long width0 = type_width(src0->type);
|
978
|
+
long long width1 = type_width(src1->type);
|
979
|
+
long long width = width0>width1 ? width0 : width1;
|
980
|
+
if (src0->type->flags.sign && (src0_int & (1 << (width0-1)))) {
|
981
|
+
if(src1->type->flags.sign && src1_data[width1-1] == '1') {
|
982
|
+
/* Negative-negative comparison. */
|
983
|
+
for(long long i=width-1; i >= 0; --i) {
|
984
|
+
char d0 = i >= width0 ? '1' :
|
985
|
+
((src0_int & (1 << i)) ? '1' : '0');
|
986
|
+
char d1 = i >= width1 ? '1' : src1_data[i];
|
987
|
+
if (d0 < d1) {
|
988
|
+
dst->data_int = 1;
|
989
|
+
return dst;
|
990
|
+
} else if (d0 > d1) {
|
991
|
+
dst->data_int = 0;
|
992
|
+
return dst;
|
993
|
+
}
|
994
|
+
}
|
995
|
+
} else {
|
996
|
+
/* Negative positive comparison, src0 is smaller. */
|
997
|
+
dst->data_int = 1;
|
998
|
+
return dst;
|
999
|
+
}
|
1000
|
+
} else {
|
1001
|
+
if(src1->type->flags.sign && src1_data[width1-1] == '1') {
|
1002
|
+
/* Positive-negative comparison, src0 is greater. */
|
1003
|
+
dst->data_int = 0;
|
1004
|
+
return dst;
|
1005
|
+
} else {
|
1006
|
+
/* Positive-positive comparison. */
|
1007
|
+
for(long long i=width-1; i >= 0; --i) {
|
1008
|
+
char d0 = i >= width0 ? '0' :
|
1009
|
+
((src0_int & (1 << i)) ? '1' : '0');
|
1010
|
+
char d1 = i >= width1 ? '0' : src1_data[i];
|
1011
|
+
if (d0 < d1) {
|
1012
|
+
dst->data_int = 1;
|
1013
|
+
return dst;
|
1014
|
+
} else if (d0 > d1) {
|
1015
|
+
dst->data_int = 0;
|
1016
|
+
return dst;
|
1017
|
+
}
|
1018
|
+
}
|
1019
|
+
}
|
1020
|
+
}
|
1021
|
+
/* Equality. */
|
1022
|
+
dst->data_int = 0;
|
1023
|
+
return dst;
|
1024
|
+
}
|
1025
|
+
|
930
1026
|
/** Computes the greater or equal comparision of two defined bitstring values.
|
931
|
-
* @param src0 the first source value of the
|
932
|
-
* @param src1 the second source value of the
|
1027
|
+
* @param src0 the first source value of the comparison
|
1028
|
+
* @param src1 the second source value of the comparison
|
933
1029
|
* @param dst the destination value
|
934
1030
|
* @return dst */
|
935
1031
|
static Value greater_equal_value_defined_bitstring(Value src0, Value src1, Value dst) {
|
1032
|
+
// printf("greater_equal_value_defined_bitstring.\n");
|
936
1033
|
/* Sets state of the destination using the first source. */
|
937
1034
|
dst->type = src0->type;
|
938
1035
|
dst->numeric = 1;
|
939
1036
|
|
940
|
-
// /* Converts the values to integers. */
|
941
|
-
// unsigned long long src0i = value2integer(src0);
|
942
|
-
// unsigned long long src1i = value2integer(src1);
|
943
|
-
// // 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));
|
944
|
-
// /* Perform the comparison. */
|
945
|
-
// if (src0->type->flags.sign) {
|
946
|
-
// if (src1->type->flags.sign)
|
947
|
-
// dst->data_int = (signed long long)src0i >= (signed long long)src1i;
|
948
|
-
// else
|
949
|
-
// dst->data_int = (signed long long)src0i >= 0 ? src0i >= src1i : 0;
|
950
|
-
// } else {
|
951
|
-
// if (src1->type->flags.sign)
|
952
|
-
// dst->data_int = (signed long long)src1i >= 0 ? src0i >= src1i : 1;
|
953
|
-
// else
|
954
|
-
// dst->data_int = src0i >= src1i;
|
955
|
-
// }
|
956
1037
|
char* src0_data = src0->data_str;
|
957
1038
|
char* src1_data = src1->data_str;
|
958
1039
|
long long width0 = type_width(src0->type);
|
@@ -1002,31 +1083,80 @@ static Value greater_equal_value_defined_bitstring(Value src0, Value src1, Value
|
|
1002
1083
|
return dst;
|
1003
1084
|
}
|
1004
1085
|
|
1086
|
+
/** Computes the greater or equal comparision of numeric and one
|
1087
|
+
* defined bitstring values.
|
1088
|
+
* @param src0 the first source value of the comparison
|
1089
|
+
* @param src1 the second source value of the comparison
|
1090
|
+
* @param dst the destination value
|
1091
|
+
* @return dst */
|
1092
|
+
static Value greater_equal_value_numeric_defined_bitstring(Value src0, Value src1, Value dst) {
|
1093
|
+
// printf("greater_equal_value_numeric_defined_bitstring.\n");
|
1094
|
+
/* Sets state of the destination using the first source. */
|
1095
|
+
dst->type = src0->type;
|
1096
|
+
dst->numeric = 1;
|
1097
|
+
|
1098
|
+
unsigned long long src0_int = src0->data_int;
|
1099
|
+
char* src1_data = src1->data_str;
|
1100
|
+
long long width0 = type_width(src0->type);
|
1101
|
+
long long width1 = type_width(src1->type);
|
1102
|
+
long long width = width0>width1 ? width0 : width1;
|
1103
|
+
if (src0->type->flags.sign && (src0_int & (1 <<(width0-1)))) {
|
1104
|
+
if(src1->type->flags.sign && src1_data[width1-1] == '1') {
|
1105
|
+
/* Negative-negative comparison. */
|
1106
|
+
for(long long i=width-1; i >= 0; --i) {
|
1107
|
+
char d0 = i >= width0 ? '1' :
|
1108
|
+
((src0_int & (1 << i)) ? '1' : '0');
|
1109
|
+
char d1 = i >= width1 ? '1' : src1_data[i];
|
1110
|
+
if (d0 < d1) {
|
1111
|
+
dst->data_int = 0;
|
1112
|
+
return dst;
|
1113
|
+
} else if (d0 > d1) {
|
1114
|
+
dst->data_int = 1;
|
1115
|
+
return dst;
|
1116
|
+
}
|
1117
|
+
}
|
1118
|
+
} else {
|
1119
|
+
/* Negative positive comparison, src0 is smaller. */
|
1120
|
+
dst->data_int = 0;
|
1121
|
+
return dst;
|
1122
|
+
}
|
1123
|
+
} else {
|
1124
|
+
if(src1->type->flags.sign && src1_data[width1-1] == '1') {
|
1125
|
+
/* Positive-negative comparison, src0 is greater. */
|
1126
|
+
dst->data_int = 1;
|
1127
|
+
return dst;
|
1128
|
+
} else {
|
1129
|
+
/* Positive-positive comparison. */
|
1130
|
+
for(long long i=width-1; i >= 0; --i) {
|
1131
|
+
char d0 = i >= width0 ? '0' :
|
1132
|
+
((src0_int & (1 << i)) ? '1' : '0');
|
1133
|
+
char d1 = i >= width1 ? '0' : src1_data[i];
|
1134
|
+
if (d0 < d1) {
|
1135
|
+
dst->data_int = 0;
|
1136
|
+
return dst;
|
1137
|
+
} else if (d0 > d1) {
|
1138
|
+
dst->data_int = 1;
|
1139
|
+
return dst;
|
1140
|
+
}
|
1141
|
+
}
|
1142
|
+
}
|
1143
|
+
}
|
1144
|
+
/* Equality. */
|
1145
|
+
dst->data_int = 1;
|
1146
|
+
return dst;
|
1147
|
+
}
|
1148
|
+
|
1005
1149
|
/** Computes the lesser or equal comparision of two defined bitstring values.
|
1006
1150
|
* @param src0 the first source value of the addition
|
1007
1151
|
* @param src1 the second source value of the addition
|
1008
1152
|
* @param dst the destination value
|
1009
1153
|
* @return dst */
|
1010
1154
|
static Value lesser_equal_value_defined_bitstring(Value src0, Value src1, Value dst) {
|
1155
|
+
// printf("lesser_equal_value_defined_bitstring.\n");
|
1011
1156
|
/* Sets state of the destination using the first source. */
|
1012
1157
|
dst->type = src0->type;
|
1013
1158
|
dst->numeric = 1;
|
1014
1159
|
|
1015
|
-
// /* Converts the values to integers. */
|
1016
|
-
// unsigned long long src0i = value2integer(src0);
|
1017
|
-
// unsigned long long src1i = value2integer(src1);
|
1018
|
-
// /* Perform the comparison. */
|
1019
|
-
// if (src0->type->flags.sign) {
|
1020
|
-
// if (src1->type->flags.sign)
|
1021
|
-
// dst->data_int = (signed long long)src0i <= (signed long long)src1i;
|
1022
|
-
// else
|
1023
|
-
// dst->data_int = (signed long long)src0i >= 0 ? src0i <= src1i : 1;
|
1024
|
-
// } else {
|
1025
|
-
// if (src1->type->flags.sign)
|
1026
|
-
// dst->data_int = (signed long long)src1i >= 0 ? src0i <= src1i : 0;
|
1027
|
-
// else
|
1028
|
-
// dst->data_int = src0i <= src1i;
|
1029
|
-
// }
|
1030
1160
|
char* src0_data = src0->data_str;
|
1031
1161
|
char* src1_data = src1->data_str;
|
1032
1162
|
long long width0 = type_width(src0->type);
|
@@ -1076,6 +1206,70 @@ static Value lesser_equal_value_defined_bitstring(Value src0, Value src1, Value
|
|
1076
1206
|
return dst;
|
1077
1207
|
}
|
1078
1208
|
|
1209
|
+
/** Computes the lesser or equal comparision of on numeric value and one
|
1210
|
+
* defined bitstring values.
|
1211
|
+
* @param src0 the first source value of the addition
|
1212
|
+
* @param src1 the second source value of the addition
|
1213
|
+
* @param dst the destination value
|
1214
|
+
* @return dst */
|
1215
|
+
static Value lesser_equal_value_numeric_defined_bitstring(Value src0, Value src1, Value dst) {
|
1216
|
+
// printf("lesser_equal_value_numeric_defined_bitstring.\n");
|
1217
|
+
/* Sets state of the destination using the first source. */
|
1218
|
+
dst->type = src0->type;
|
1219
|
+
dst->numeric = 1;
|
1220
|
+
|
1221
|
+
unsigned long long src0_int = src0->data_int;
|
1222
|
+
char* src1_data = src1->data_str;
|
1223
|
+
long long width0 = type_width(src0->type);
|
1224
|
+
long long width1 = type_width(src1->type);
|
1225
|
+
long long width = width0>width1 ? width0 : width1;
|
1226
|
+
if (src0->type->flags.sign && (src0_int & (1 << (width0-1)))) {
|
1227
|
+
if(src1->type->flags.sign && src1_data[width1-1] == '1') {
|
1228
|
+
/* Negative-negative comparison. */
|
1229
|
+
for(long long i=width-1; i >= 0; --i) {
|
1230
|
+
char d0 = i >= width0 ? '1' :
|
1231
|
+
((src0_int & (1 << i)) ? '1' : '0');
|
1232
|
+
char d1 = i >= width1 ? '1' : src1_data[i];
|
1233
|
+
if (d0 < d1) {
|
1234
|
+
dst->data_int = 1;
|
1235
|
+
return dst;
|
1236
|
+
} else if (d0 > d1) {
|
1237
|
+
dst->data_int = 0;
|
1238
|
+
return dst;
|
1239
|
+
}
|
1240
|
+
}
|
1241
|
+
} else {
|
1242
|
+
/* Negative positive comparison, src0 is smaller. */
|
1243
|
+
dst->data_int = 1;
|
1244
|
+
return dst;
|
1245
|
+
}
|
1246
|
+
} else {
|
1247
|
+
if(src1->type->flags.sign && src1_data[width1-1] == '1') {
|
1248
|
+
/* Positive-negative comparison, src0 is greater. */
|
1249
|
+
dst->data_int = 0;
|
1250
|
+
return dst;
|
1251
|
+
} else {
|
1252
|
+
/* Positive-positive comparison. */
|
1253
|
+
for(long long i=width-1; i >= 0; --i) {
|
1254
|
+
char d0 = i >= width0 ? '0' :
|
1255
|
+
((src0_int & (1 << i)) ? '1' : '0');
|
1256
|
+
char d1 = i >= width1 ? '0' : src1_data[i];
|
1257
|
+
// printf("d0=%c d1=%c\n",d0,d1);
|
1258
|
+
if (d0 < d1) {
|
1259
|
+
dst->data_int = 1;
|
1260
|
+
return dst;
|
1261
|
+
} else if (d0 > d1) {
|
1262
|
+
dst->data_int = 0;
|
1263
|
+
return dst;
|
1264
|
+
}
|
1265
|
+
}
|
1266
|
+
}
|
1267
|
+
}
|
1268
|
+
/* Equality. */
|
1269
|
+
dst->data_int = 1;
|
1270
|
+
return dst;
|
1271
|
+
}
|
1272
|
+
|
1079
1273
|
|
1080
1274
|
/** Computes the NOT of a bitstring value.
|
1081
1275
|
* @param src the source value of the not
|
@@ -3111,6 +3305,10 @@ Value greater_value(Value src0, Value src1, Value dst) {
|
|
3111
3305
|
/* Both sources are numeric. */
|
3112
3306
|
return greater_value_numeric(src0,src1,dst);
|
3113
3307
|
} else if (is_defined_value(src0) && is_defined_value(src1)) {
|
3308
|
+
if (src0->numeric)
|
3309
|
+
return greater_value_numeric_defined_bitstring(src0,src1,dst);
|
3310
|
+
if (src1->numeric)
|
3311
|
+
return lesser_equal_value_numeric_defined_bitstring(src1,src0,dst);
|
3114
3312
|
/* Both sources can be converted to numeric values. */
|
3115
3313
|
return greater_value_defined_bitstring(src0,src1,dst);
|
3116
3314
|
} else {
|
@@ -3139,6 +3337,10 @@ Value lesser_value(Value src0, Value src1, Value dst) {
|
|
3139
3337
|
return lesser_value_numeric(src0,src1,dst);
|
3140
3338
|
} else if (is_defined_value(src0) && is_defined_value(src1)) {
|
3141
3339
|
/* Both sources can be converted to numeric values. */
|
3340
|
+
if (src0->numeric)
|
3341
|
+
return lesser_value_numeric_defined_bitstring(src0,src1,dst);
|
3342
|
+
if (src1->numeric)
|
3343
|
+
return greater_equal_value_numeric_defined_bitstring(src1,src0,dst);
|
3142
3344
|
return lesser_value_defined_bitstring(src0,src1,dst);
|
3143
3345
|
} else {
|
3144
3346
|
/* Cannot compute (for now), simply undefines the destination. */
|
@@ -3166,6 +3368,10 @@ Value greater_equal_value(Value src0, Value src1, Value dst) {
|
|
3166
3368
|
return greater_equal_value_numeric(src0,src1,dst);
|
3167
3369
|
} else if (is_defined_value(src0) && is_defined_value(src1)) {
|
3168
3370
|
/* Both sources can be converted to numeric values. */
|
3371
|
+
if (src0->numeric)
|
3372
|
+
return greater_equal_value_numeric_defined_bitstring(src0,src1,dst);
|
3373
|
+
if (src1->numeric)
|
3374
|
+
return lesser_value_numeric_defined_bitstring(src1,src0,dst);
|
3169
3375
|
return greater_equal_value_defined_bitstring(src0,src1,dst);
|
3170
3376
|
} else {
|
3171
3377
|
/* Cannot compute (for now), simply undefines the destination. */
|
@@ -3192,6 +3398,10 @@ Value lesser_equal_value(Value src0, Value src1, Value dst) {
|
|
3192
3398
|
return lesser_equal_value_numeric(src0,src1,dst);
|
3193
3399
|
} else if (is_defined_value(src0) && is_defined_value(src1)) {
|
3194
3400
|
/* Both sources can be converted to numeric values. */
|
3401
|
+
if (src0->numeric)
|
3402
|
+
return lesser_equal_value_numeric_defined_bitstring(src0,src1,dst);
|
3403
|
+
if (src1->numeric)
|
3404
|
+
return greater_value_numeric_defined_bitstring(src1,src0,dst);
|
3195
3405
|
return lesser_equal_value_defined_bitstring(src0,src1,dst);
|
3196
3406
|
} else {
|
3197
3407
|
/* Cannot compute (for now), simply undefines the destination. */
|
@@ -42,6 +42,28 @@ system :comparison_bench do
|
|
42
42
|
sgeL <= (uL >= vL)
|
43
43
|
end
|
44
44
|
|
45
|
+
[8].inner :xND
|
46
|
+
[96].inner :yND
|
47
|
+
signed[8].inner :uND
|
48
|
+
signed[128].inner :vND
|
49
|
+
inner :ueND, :ultND, :uleND, :ugtND, :ugeND
|
50
|
+
inner :seND, :sltND, :sleND, :sgtND, :sgeND
|
51
|
+
|
52
|
+
par do
|
53
|
+
ueND <= (xND == yND)
|
54
|
+
ultND <= (xND < yND)
|
55
|
+
uleND <= (xND <= yND)
|
56
|
+
ugtND <= (xND > yND)
|
57
|
+
ugeND <= (xND >= yND)
|
58
|
+
|
59
|
+
seND <= (uND == vND)
|
60
|
+
sltND <= (uND < vND)
|
61
|
+
sleND <= (uND <= vND)
|
62
|
+
sgtND <= (uND > vND)
|
63
|
+
sgeND <= (uND >= vND)
|
64
|
+
end
|
65
|
+
|
66
|
+
|
45
67
|
timed do
|
46
68
|
x <= 0
|
47
69
|
y <= 0
|
@@ -51,26 +73,38 @@ system :comparison_bench do
|
|
51
73
|
yL <= 0
|
52
74
|
uL <= 0
|
53
75
|
vL <= 0
|
76
|
+
xND <= 0
|
77
|
+
yND <= 0
|
78
|
+
uND <= 0
|
79
|
+
vND <= 0
|
54
80
|
!10.ns
|
55
81
|
x <= 1
|
56
82
|
u <= 1
|
57
83
|
xL <= 2**80 - 1
|
58
84
|
uL <= 2**80 - 1
|
85
|
+
xND <= 1
|
86
|
+
uND <= 1
|
59
87
|
!10.ns
|
60
88
|
y <= 2
|
61
89
|
v <= 2
|
62
90
|
yL <= 2**81 - 1
|
63
91
|
vL <= 2**81 - 1
|
92
|
+
yND <= 2
|
93
|
+
vND <= 2
|
64
94
|
!10.ns
|
65
95
|
x <= 3
|
66
96
|
u <= 3
|
67
97
|
xL <= 2**81 + 2**80 - 1
|
68
98
|
uL <= 2**81 + 2**80 - 1
|
99
|
+
xND <= 3
|
100
|
+
uND <= 3
|
69
101
|
!10.ns
|
70
102
|
x <= 2
|
71
103
|
u <= -2
|
72
104
|
xL <= 2**81 - 1
|
73
105
|
uL <= -2**81 + 1
|
106
|
+
xND <= 2
|
107
|
+
uND <= -2
|
74
108
|
!10.ns
|
75
109
|
end
|
76
110
|
end
|
@@ -1325,10 +1325,10 @@ module RubyHDL::High
|
|
1325
1325
|
return @base.to_c + "[#{self.size.to_i}]"
|
1326
1326
|
else
|
1327
1327
|
# Simple vector type case.
|
1328
|
-
if float? then
|
1328
|
+
if @base.float? then
|
1329
1329
|
return @base.to_c
|
1330
1330
|
else
|
1331
|
-
return @base + " long long"
|
1331
|
+
return @base.to_c + " long long"
|
1332
1332
|
end
|
1333
1333
|
end
|
1334
1334
|
end
|
@@ -1338,7 +1338,7 @@ module RubyHDL::High
|
|
1338
1338
|
if @base.is_a?(TypeVector) then
|
1339
1339
|
# Array type case.
|
1340
1340
|
base_init = @base.to_c_init
|
1341
|
-
return "
|
1341
|
+
return "{" + ([base_init] * self.size.to_i).join(",") + "}"
|
1342
1342
|
else
|
1343
1343
|
return "0"
|
1344
1344
|
end
|
@@ -1919,7 +1919,13 @@ module RubyHDL::High
|
|
1919
1919
|
end
|
1920
1920
|
|
1921
1921
|
# Convert to C code.
|
1922
|
-
|
1922
|
+
def to_c
|
1923
|
+
if @content.is_a?(::Array) then
|
1924
|
+
return "{" + @content.to_s[1..-2] + "}"
|
1925
|
+
else
|
1926
|
+
return @content.to_s
|
1927
|
+
end
|
1928
|
+
end
|
1923
1929
|
end
|
1924
1930
|
|
1925
1931
|
|
@@ -2000,10 +2006,11 @@ module RubyHDL::High
|
|
2000
2006
|
|
2001
2007
|
# Convert to C code.
|
2002
2008
|
def to_c
|
2003
|
-
return "switch(#{@sel.to_c}) {\n" +
|
2004
|
-
|
2005
|
-
|
2006
|
-
|
2009
|
+
# return "switch(#{@sel.to_c}) {\n" +
|
2010
|
+
# @choices.map.with_index do |choice,i|
|
2011
|
+
# "case #{i}:\n#{choice.to_c}\nbreak;"
|
2012
|
+
# end.join("\n") + "\n}"
|
2013
|
+
return "#{@sel.to_c} ? #{@choices[1].to_c} : #{@choices[0].to_c}"
|
2007
2014
|
end
|
2008
2015
|
end
|
2009
2016
|
|
@@ -2112,6 +2119,7 @@ module RubyHDL::High
|
|
2112
2119
|
|
2113
2120
|
# Describes a SW implementation of an range reference.
|
2114
2121
|
class RefRange < Ref
|
2122
|
+
using RubyHDL::High
|
2115
2123
|
attr_reader :base
|
2116
2124
|
|
2117
2125
|
# Create a new index reference with +type+ data type +base+ base
|
@@ -2178,7 +2186,11 @@ module RubyHDL::High
|
|
2178
2186
|
smask = (1.to_value<<(@rng.first+1-@rng.last))-1
|
2179
2187
|
cmask = ~(smask << @rng.last)
|
2180
2188
|
# Get the final base.
|
2181
|
-
|
2189
|
+
if @base.is_a?(Ref) then
|
2190
|
+
base = @base.final_base.to_c
|
2191
|
+
else
|
2192
|
+
base = @base.to_c
|
2193
|
+
end
|
2182
2194
|
# Generate the ruby code.
|
2183
2195
|
return "(#{base} & #{cmask.to_c}) >> (#{@rng.last.to_c})"
|
2184
2196
|
end
|
@@ -2256,7 +2268,7 @@ module RubyHDL::High
|
|
2256
2268
|
def to_c
|
2257
2269
|
if (@left.is_a?(RefIndex) or @left.is_a?(RefRange)) then
|
2258
2270
|
if @left.base.type.base.is_a?(TypeVector) then
|
2259
|
-
return "#{@left.to_c} = #{@right.to_c}"
|
2271
|
+
return "#{@left.to_c} = #{@right.to_c};"
|
2260
2272
|
else
|
2261
2273
|
# Get the access range.
|
2262
2274
|
rng = @left.range
|
@@ -2275,7 +2287,7 @@ module RubyHDL::High
|
|
2275
2287
|
end
|
2276
2288
|
end
|
2277
2289
|
|
2278
|
-
# Describes a SW implementation of a
|
2290
|
+
# Describes a SW implementation of a sif statement.
|
2279
2291
|
class Sif < Statement
|
2280
2292
|
# Create a new if statement in sequencer +sequencer+
|
2281
2293
|
# with +cond+ condition and +ruby_block+
|
@@ -2336,7 +2348,7 @@ module RubyHDL::High
|
|
2336
2348
|
|
2337
2349
|
# Convert to C code.
|
2338
2350
|
def to_c
|
2339
|
-
res = @sequencer.
|
2351
|
+
res = @sequencer.clk_up_c + "\nif(#{@condition.to_c}) {\n#{@yes_blk.to_c}\n}"
|
2340
2352
|
@elsifs.each do |(cond,blk)|
|
2341
2353
|
res << "\nelse if(#{cond.to_c}) {\n#{blk.to_c}\n}"
|
2342
2354
|
end
|
@@ -2347,6 +2359,33 @@ module RubyHDL::High
|
|
2347
2359
|
end
|
2348
2360
|
end
|
2349
2361
|
|
2362
|
+
# Describes a SW implementation of a hif statement.
|
2363
|
+
class Hif < Sif
|
2364
|
+
# Convert to Ruby code.
|
2365
|
+
def to_ruby
|
2366
|
+
res = "\nif((#{@condition.to_ruby}) != 0)\n#{@yes_blk.to_ruby}\n"
|
2367
|
+
@elsifs.each do |(cond,blk)|
|
2368
|
+
res << "elsif((#{cond.to_ruby}) != 0)\n#{blk.to_ruby}\n"
|
2369
|
+
end
|
2370
|
+
if @else_blk then
|
2371
|
+
res << "else\n#{@else_blk.to_ruby}\n"
|
2372
|
+
end
|
2373
|
+
return res + "end\n"
|
2374
|
+
end
|
2375
|
+
|
2376
|
+
# Convert to C code.
|
2377
|
+
def to_c
|
2378
|
+
res = "\nif(#{@condition.to_c}) {\n#{@yes_blk.to_c}\n}"
|
2379
|
+
@elsifs.each do |(cond,blk)|
|
2380
|
+
res << "\nelse if(#{cond.to_c}) {\n#{blk.to_c}\n}"
|
2381
|
+
end
|
2382
|
+
if @else_blk then
|
2383
|
+
res << "\nelse {\n#{@else_blk.to_c}\n}"
|
2384
|
+
end
|
2385
|
+
return res
|
2386
|
+
end
|
2387
|
+
end
|
2388
|
+
|
2350
2389
|
# Describes a SW implementation of a loop statement.
|
2351
2390
|
class Sloop < Statement
|
2352
2391
|
# Create a new infinite loop statement in sequencer +sequencer+
|
@@ -2494,7 +2533,7 @@ module RubyHDL::High
|
|
2494
2533
|
|
2495
2534
|
# Convert to Ruby code.
|
2496
2535
|
def to_c
|
2497
|
-
return @sequencer.clk_up_c + "\nreturn #{
|
2536
|
+
return @sequencer.clk_up_c + "\nreturn #{@value.to_c};"
|
2498
2537
|
end
|
2499
2538
|
end
|
2500
2539
|
|
@@ -2642,7 +2681,7 @@ module RubyHDL::High
|
|
2642
2681
|
|
2643
2682
|
# Convert to C code.
|
2644
2683
|
def to_c
|
2645
|
-
return "\n__#{name}(" + @args.map {|arg| arg.to_ruby}.join(",") + ");"
|
2684
|
+
return "\n__#{@name}(" + @args.map {|arg| arg.to_ruby}.join(",") + ");"
|
2646
2685
|
end
|
2647
2686
|
|
2648
2687
|
# Create an iterator for a given method +meth+.
|
@@ -2993,21 +3032,23 @@ module RubyHDL::High
|
|
2993
3032
|
return "" if @arguments.empty?
|
2994
3033
|
res = "print("
|
2995
3034
|
@arguments.each do |arg|
|
2996
|
-
|
2997
|
-
|
2998
|
-
|
2999
|
-
|
3000
|
-
end
|
3035
|
+
if arg.is_a?(::String) then
|
3036
|
+
res << "\"#{arg}\""
|
3037
|
+
else
|
3038
|
+
res << arg.to_ruby
|
3001
3039
|
end
|
3002
|
-
res << "
|
3003
|
-
|
3040
|
+
res << ","
|
3041
|
+
end
|
3042
|
+
res[-1] = ")"
|
3043
|
+
res << "\n"
|
3044
|
+
return res
|
3004
3045
|
end
|
3005
3046
|
|
3006
3047
|
# Convert to C code.
|
3007
3048
|
def to_c
|
3008
3049
|
return "" if @arguments.empty?
|
3009
3050
|
# Create the format.
|
3010
|
-
format = @arguments.
|
3051
|
+
format = @arguments.map do |arg|
|
3011
3052
|
if arg.is_a?(Expression) then
|
3012
3053
|
arg.type.signed? ? "%lld" : "%llu"
|
3013
3054
|
else
|
@@ -3015,13 +3056,13 @@ module RubyHDL::High
|
|
3015
3056
|
end
|
3016
3057
|
end.join
|
3017
3058
|
return "printf(\"#{format}\"," +
|
3018
|
-
@arguments.
|
3059
|
+
@arguments.map do |arg|
|
3019
3060
|
if arg.is_a?(::String) then
|
3020
|
-
"\"#{arg}\""
|
3061
|
+
"\"#{arg.gsub(/\n/,"\\n")}\""
|
3021
3062
|
else
|
3022
3063
|
arg.to_c
|
3023
3064
|
end
|
3024
|
-
end.join(",")
|
3065
|
+
end.join(",") + ");"
|
3025
3066
|
end
|
3026
3067
|
end
|
3027
3068
|
|
@@ -3459,7 +3500,9 @@ module RubyHDL::High
|
|
3459
3500
|
end
|
3460
3501
|
|
3461
3502
|
# Convert to C code.
|
3462
|
-
|
3503
|
+
def to_c
|
3504
|
+
return "__" + self.name.to_s
|
3505
|
+
end
|
3463
3506
|
|
3464
3507
|
# Check if a value is defined for the signal.
|
3465
3508
|
def value?
|
@@ -3616,14 +3659,14 @@ module RubyHDL::High
|
|
3616
3659
|
# Convert to C code.
|
3617
3660
|
def to_c
|
3618
3661
|
res = ""
|
3619
|
-
# Generate the arguments if any.
|
3620
|
-
if @args.any? then
|
3621
|
-
|
3622
|
-
end
|
3662
|
+
# # Generate the arguments if any.
|
3663
|
+
# if @args.any? then
|
3664
|
+
# res = "(#{@args.map(&:to_c).join(",")})\n"
|
3665
|
+
# end
|
3623
3666
|
# Generate the statements.
|
3624
|
-
res += "{" + @statements.map do |stmnt|
|
3625
|
-
stmnt.
|
3626
|
-
end.join + "}"
|
3667
|
+
res += "{\n" + @statements.map do |stmnt|
|
3668
|
+
stmnt.to_c + "\n"
|
3669
|
+
end.join + "\n}"
|
3627
3670
|
return res
|
3628
3671
|
end
|
3629
3672
|
|
@@ -3663,7 +3706,11 @@ module RubyHDL::High
|
|
3663
3706
|
def sif(cond, &ruby_block)
|
3664
3707
|
self << RubyHDL::High::Sif.new(@sequencer,cond,&ruby_block)
|
3665
3708
|
end
|
3666
|
-
|
3709
|
+
|
3710
|
+
# Create a sequential if statement on +cond+.
|
3711
|
+
def hif(cond, &ruby_block)
|
3712
|
+
self << RubyHDL::High::Hif.new(@sequencer,cond,&ruby_block)
|
3713
|
+
end
|
3667
3714
|
|
3668
3715
|
# Create a sequential elsif statement on +cond+.
|
3669
3716
|
def selsif(cond, &ruby_block)
|
@@ -3769,7 +3816,7 @@ module RubyHDL::High
|
|
3769
3816
|
|
3770
3817
|
# Convert to C code.
|
3771
3818
|
def to_c
|
3772
|
-
return "unsigned long long __#{name}(#{@args.map {|arg| "unsigned long long " + arg.to_c}.join(",")} {\n#{@blk.sequencer.clk_up_c}\n#{@blk.to_c}\n}\n"
|
3819
|
+
return "unsigned long long __#{name}(#{@args.map {|arg| "unsigned long long __" + arg.to_c}.join(",")}) {\n#{@blk.sequencer.clk_up_c}\n#{@blk.to_c}\n}\n"
|
3773
3820
|
end
|
3774
3821
|
end
|
3775
3822
|
|
@@ -3858,11 +3905,29 @@ BUILD
|
|
3858
3905
|
def to_c
|
3859
3906
|
typ = nil
|
3860
3907
|
res = <<-BUILDC
|
3908
|
+
#include <stdio.h>
|
3909
|
+
|
3861
3910
|
#{RubyHDL::High.global_sblock.each_signal.map do |signal|
|
3862
3911
|
typ = signal.type
|
3863
|
-
|
3912
|
+
if signal.value? then
|
3913
|
+
if signal.array? then
|
3914
|
+
typ.base.to_c + " " + signal.to_c + "[#{typ.size}]" " = {" +
|
3915
|
+
signal.value.inspect[1..-2] + "};"
|
3916
|
+
else
|
3917
|
+
typ.to_c + " " + signal.to_c + "=" + signal.value.inspect + ";"
|
3918
|
+
end
|
3919
|
+
else
|
3920
|
+
if signal.array? then
|
3921
|
+
typ.base.to_c + " " + signal.to_c + "[#{typ.size}]" + " =" + typ.to_c_init + ";"
|
3922
|
+
else
|
3923
|
+
typ.to_c + " " + signal.to_c + "=" + typ.to_c_init + ";"
|
3924
|
+
end
|
3925
|
+
end
|
3864
3926
|
end.join("\n")}
|
3865
|
-
|
3927
|
+
|
3928
|
+
#{@sfunctions.map {|n,f| f.to_c }.join("\n\n")}
|
3929
|
+
|
3930
|
+
void sequencer() #{@blk.to_c}
|
3866
3931
|
BUILDC
|
3867
3932
|
return res
|
3868
3933
|
end
|
data/lib/HDLRuby/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: HDLRuby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.7.
|
4
|
+
version: 3.7.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lovic Gauthier
|
@@ -495,7 +495,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
495
495
|
- !ruby/object:Gem::Version
|
496
496
|
version: '0'
|
497
497
|
requirements: []
|
498
|
-
rubygems_version: 3.6.
|
498
|
+
rubygems_version: 3.6.9
|
499
499
|
specification_version: 4
|
500
500
|
summary: HDLRuby is a library for describing and simulating digital electronic systems.
|
501
501
|
test_files: []
|