Skip to content

Commit 2362a9d

Browse files
authored
Merge pull request #509 from llaniewski/fix/uint_flag
Fixing narrowing conversion for large flag sizes
2 parents f670aaf + a7b4dba commit 2362a9d

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

src/Consts.h.Rt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,11 @@
2424
#define PART_MAR_BOX <?%f max(0,PartMargin-0.5) ?>
2525

2626
<?R
27-
big_hex = function(x,bits=16) {
28-
ret = ""
29-
while (x > 0 | bits > 0) {
30-
a = x %% 16
31-
ret = sprintf("%01x%s",a,ret)
32-
x = (x-a) / 16
33-
bits = bits - 4
34-
}
35-
ret
36-
}
3727
for (n in rows(NodeTypes)) { ?>
38-
#define <?%-20s n$Index ?> 0x<?%s big_hex(n$value) ?> <?R
28+
#define <?%-20s n$Index ?> <?%s big_hex(n$value) ?> <?R
3929
}
4030
for (n in rows(NodeTypeGroups)) { ?>
41-
#define <?%-20s n$Index ?> 0x<?%s big_hex(n$mask) ?> <?R
31+
#define <?%-20s n$Index ?> <?%s big_hex(n$mask) ?> <?R
4232
}
4333
?>
4434
<?R

src/Lattice.h.Rt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ public:
142142
void <?%s a$FunName ?>_Opt(int, int, int, int, int);
143143
void <?%s a$FunName ?>(int, int, int); <?R
144144
} ?>
145-
void GetFlags(lbRegion, big_flag_t *);
146145
void GetCoords(real_t*);
147146
void Get_Field(int, real_t * tab);
148147
void Set_Field(int, real_t * tab);

src/Lists.cpp.Rt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ Model_m::Model_m() {
156156
id = NodeTypeGroups$Index,
157157
name = q(NodeTypeGroups$name),
158158
shift = NodeTypeGroups$shift,
159-
max = NodeTypeGroups$max,
160-
capacity = NodeTypeGroups$capacity,
159+
max = big_hex(NodeTypeGroups$max),
160+
capacity = big_hex(NodeTypeGroups$capacity),
161161
bits = NodeTypeGroups$bits,
162162
isSave = NodeTypeGroups$save
163163
)

src/Lists.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ class Model {
5353
struct NodeTypeGroupFlag : Thing {
5454
big_flag_t flag;
5555
int shift;
56-
int max;
57-
int capacity;
56+
big_flag_t max;
57+
big_flag_t capacity;
5858
int bits;
5959
bool isSave;
6060
inline NodeTypeGroupFlag() : flag(0), shift(0), max(0), capacity(0), bits(0), isSave(false) {}
6161
inline NodeTypeGroupFlag(const big_flag_t& flag_, const std::string& name_,
62-
const int& shift_, const int& max_, const int& capacity_, const int& bits_, const bool& isSave_)
62+
const int& shift_, const big_flag_t& max_, const big_flag_t& capacity_, const int& bits_, const bool& isSave_)
6363
: Thing(flag_,name_), flag(flag_), shift(shift_), max(max_), capacity(capacity_), bits(bits_), isSave(isSave_) {}
6464
};
6565

src/conf.R

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ if (nrow(NodeTypes) > 0) {
565565
tab$mask = NodeShift*((2^l)-1)
566566
tab$max = n
567567
tab$bits = l
568-
tab$capacity = 2^l
568+
tab$capacity = 2^l-1
569569
tab$shift = NodeShiftNum
570570
tab$groupIndex = paste("NODE",tab$group,sep="_")
571571
tab$save = TRUE
@@ -588,7 +588,7 @@ if (NodeShiftNum > 14) {
588588
ZoneBits = FlagTBits - NodeShiftNum
589589
ZoneShift = NodeShiftNum
590590
if (ZoneBits == 0) warning("No additional zones! (too many node types) - it will run, but you cannot use local settings")
591-
ZoneMax = 2^ZoneBits
591+
ZoneMax = 2^ZoneBits-1
592592
NodeTypes = rbind(NodeTypes,data.frame(
593593
name="DefaultZone",
594594
group="SETTINGZONE",
@@ -598,7 +598,7 @@ NodeTypes = rbind(NodeTypes,data.frame(
598598
max=ZoneMax,
599599
bits=ZoneBits,
600600
capacity=ZoneMax,
601-
mask=(ZoneMax-1)*NodeShift,
601+
mask=(ZoneMax)*NodeShift,
602602
shift=NodeShiftNum,
603603
groupIndex = "NODE_SETTINGZONE",
604604
save = TRUE
@@ -611,7 +611,7 @@ if (any(NodeTypes$value >= 2^FlagTBits)) stop("NodeTypes exceeds size of flag_t"
611611
#ALLBits = ZoneShift
612612
#ALLMax = 2^ZoneShift
613613
ALLBits = FlagTBits
614-
ALLMax = 2^ALLBits
614+
ALLMax = 2^ALLBits-1
615615
NodeTypes = rbind(NodeTypes,data.frame(
616616
name="None",
617617
group="NONE",
@@ -636,7 +636,7 @@ NodeTypes = rbind(NodeTypes,data.frame(
636636
max=ALLMax,
637637
bits=ALLBits,
638638
capacity=ALLMax,
639-
mask=(ALLMax-1),
639+
mask=ALLMax,
640640
shift=0,
641641
groupIndex = "NODE_ALL",
642642
save = FALSE
@@ -1035,3 +1035,14 @@ hash_header = function() {
10351035
cat("# |",l,"|\n",sep="");
10361036
cat("\n");
10371037
}
1038+
1039+
big_hex = function(x,bits=16) {
1040+
ret = ""
1041+
while (any(x > 0) | bits > 0) {
1042+
a = x %% 16
1043+
ret = sprintf("%01x%s",a,ret)
1044+
x = (x-a) / 16
1045+
bits = bits - 4
1046+
}
1047+
paste0("0x",ret)
1048+
}

0 commit comments

Comments
 (0)