[Libre-soc-bugs] [Bug 980] Implement C-based Power ISA pseudocode compiler
bugzilla-daemon at libre-soc.org
bugzilla-daemon at libre-soc.org
Sun Jan 14 08:52:15 GMT 2024
https://bugs.libre-soc.org/show_bug.cgi?id=980
--- Comment #98 from Jacob Lifshay <programmerjake at gmail.com> ---
(In reply to Dmitry Selyutin from comment #95)
> What's the point of having ok or flags in each and every integer?
mostly because that's how we did it in python...yeah I can see your point why
we shouldn't do it that way.
how about:
#include <stdbool.h> // so we can use bool regardless of C or C++
#include <stdint.h>
typedef enum oppc_type_tag {
oppc_tt_sel_int,
// add more stuff later
} oppc_type_tag;
typedef struct oppc_sel_int {
uint32_t bits;
union {
uint64_t small; // for bits <= 64
// add another field later for > 64 bits
};
} oppc_sel_int;
typedef struct oppc_value {
oppc_type_tag type : 4;
bool ok : 1;
: 0; // terminate bitfield
union {
oppc_sel_int si;
// add more stuff later
};
} oppc_value;
static inline oppc_value oppc_si_small(uint64_t value, uint32_t bits) {
assert(bits <= 64);
if(bits < 64)
// note ULL is guaranteed to be >= 64-bits so this works.
value &= (1ULL << bits) - 1ULL;
return (oppc_value){
.type = oppc_tt_sel_int,
.ok = true,
.si = {.bits = bits, .small = value},
};
}
static inline oppc_value oppc_add(oppc_value a, oppc_value b) {
assert(a.type == oppc_tt_si);
assert(b.type == oppc_tt_si);
assert(a.si.bits == b.si.bits);
assert(a.si.bits <= 64);
return oppc_si_small(a.si.small + b.si.small, a.si.bits);
}
--
You are receiving this mail because:
You are on the CC list for the bug.
More information about the libre-soc-bugs
mailing list