Skip to content

Commit

Permalink
Merge pull request CFD-GO#509 from llaniewski/fix/uint_flag
Browse files Browse the repository at this point in the history
Fixing narrowing conversion for large flag sizes
  • Loading branch information
llaniewski authored Feb 22, 2024
2 parents f670aaf + a7b4dba commit 2362a9d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
14 changes: 2 additions & 12 deletions src/Consts.h.Rt
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,11 @@
#define PART_MAR_BOX <?%f max(0,PartMargin-0.5) ?>

<?R
big_hex = function(x,bits=16) {
ret = ""
while (x > 0 | bits > 0) {
a = x %% 16
ret = sprintf("%01x%s",a,ret)
x = (x-a) / 16
bits = bits - 4
}
ret
}
for (n in rows(NodeTypes)) { ?>
#define <?%-20s n$Index ?> 0x<?%s big_hex(n$value) ?> <?R
#define <?%-20s n$Index ?> <?%s big_hex(n$value) ?> <?R
}
for (n in rows(NodeTypeGroups)) { ?>
#define <?%-20s n$Index ?> 0x<?%s big_hex(n$mask) ?> <?R
#define <?%-20s n$Index ?> <?%s big_hex(n$mask) ?> <?R
}
?>
<?R
Expand Down
1 change: 0 additions & 1 deletion src/Lattice.h.Rt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ public:
void <?%s a$FunName ?>_Opt(int, int, int, int, int);
void <?%s a$FunName ?>(int, int, int); <?R
} ?>
void GetFlags(lbRegion, big_flag_t *);
void GetCoords(real_t*);
void Get_Field(int, real_t * tab);
void Set_Field(int, real_t * tab);
Expand Down
4 changes: 2 additions & 2 deletions src/Lists.cpp.Rt
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ Model_m::Model_m() {
id = NodeTypeGroups$Index,
name = q(NodeTypeGroups$name),
shift = NodeTypeGroups$shift,
max = NodeTypeGroups$max,
capacity = NodeTypeGroups$capacity,
max = big_hex(NodeTypeGroups$max),
capacity = big_hex(NodeTypeGroups$capacity),
bits = NodeTypeGroups$bits,
isSave = NodeTypeGroups$save
)
Expand Down
6 changes: 3 additions & 3 deletions src/Lists.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ class Model {
struct NodeTypeGroupFlag : Thing {
big_flag_t flag;
int shift;
int max;
int capacity;
big_flag_t max;
big_flag_t capacity;
int bits;
bool isSave;
inline NodeTypeGroupFlag() : flag(0), shift(0), max(0), capacity(0), bits(0), isSave(false) {}
inline NodeTypeGroupFlag(const big_flag_t& flag_, const std::string& name_,
const int& shift_, const int& max_, const int& capacity_, const int& bits_, const bool& isSave_)
const int& shift_, const big_flag_t& max_, const big_flag_t& capacity_, const int& bits_, const bool& isSave_)
: Thing(flag_,name_), flag(flag_), shift(shift_), max(max_), capacity(capacity_), bits(bits_), isSave(isSave_) {}
};

Expand Down
21 changes: 16 additions & 5 deletions src/conf.R
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ if (nrow(NodeTypes) > 0) {
tab$mask = NodeShift*((2^l)-1)
tab$max = n
tab$bits = l
tab$capacity = 2^l
tab$capacity = 2^l-1
tab$shift = NodeShiftNum
tab$groupIndex = paste("NODE",tab$group,sep="_")
tab$save = TRUE
Expand All @@ -588,7 +588,7 @@ if (NodeShiftNum > 14) {
ZoneBits = FlagTBits - NodeShiftNum
ZoneShift = NodeShiftNum
if (ZoneBits == 0) warning("No additional zones! (too many node types) - it will run, but you cannot use local settings")
ZoneMax = 2^ZoneBits
ZoneMax = 2^ZoneBits-1
NodeTypes = rbind(NodeTypes,data.frame(
name="DefaultZone",
group="SETTINGZONE",
Expand All @@ -598,7 +598,7 @@ NodeTypes = rbind(NodeTypes,data.frame(
max=ZoneMax,
bits=ZoneBits,
capacity=ZoneMax,
mask=(ZoneMax-1)*NodeShift,
mask=(ZoneMax)*NodeShift,
shift=NodeShiftNum,
groupIndex = "NODE_SETTINGZONE",
save = TRUE
Expand All @@ -611,7 +611,7 @@ if (any(NodeTypes$value >= 2^FlagTBits)) stop("NodeTypes exceeds size of flag_t"
#ALLBits = ZoneShift
#ALLMax = 2^ZoneShift
ALLBits = FlagTBits
ALLMax = 2^ALLBits
ALLMax = 2^ALLBits-1
NodeTypes = rbind(NodeTypes,data.frame(
name="None",
group="NONE",
Expand All @@ -636,7 +636,7 @@ NodeTypes = rbind(NodeTypes,data.frame(
max=ALLMax,
bits=ALLBits,
capacity=ALLMax,
mask=(ALLMax-1),
mask=ALLMax,
shift=0,
groupIndex = "NODE_ALL",
save = FALSE
Expand Down Expand Up @@ -1035,3 +1035,14 @@ hash_header = function() {
cat("# |",l,"|\n",sep="");
cat("\n");
}

big_hex = function(x,bits=16) {
ret = ""
while (any(x > 0) | bits > 0) {
a = x %% 16
ret = sprintf("%01x%s",a,ret)
x = (x-a) / 16
bits = bits - 4
}
paste0("0x",ret)
}

0 comments on commit 2362a9d

Please sign in to comment.