Skip to content

Commit 28ce50b

Browse files
Use spaceship operators, and fix up iterating over starMap for sycl::vec implementations.
1 parent 6e18b02 commit 28ce50b

File tree

3 files changed

+39
-38
lines changed

3 files changed

+39
-38
lines changed

models/starComplexity.h

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,40 @@ constexpr unsigned maxNodes=22, maxStars=2*maxNodes-1;
88
#include "vecBitSet.h"
99

1010

11-
12-
class linkRep
11+
template <class I>
12+
class linkRepImpl
1313
{
1414
public:
15-
#ifdef SYCL_LANGUAGE_VERSION
16-
using Impl=VecBitSet<unsigned,4>;
17-
#else
18-
using Impl=/*long long*/ unsigned;
19-
#endif
15+
using Impl=I;
2016
private:
2117
constexpr static unsigned size=maxNodes*(maxNodes-1)/(16*sizeof(Impl))+1;
22-
Impl data[linkRep::size];
23-
CLASSDESC_ACCESS(linkRep);
18+
Impl data[linkRepImpl<I>::size];
19+
CLASSDESC_ACCESS(linkRepImpl);
2420
public:
25-
linkRep()=default;
26-
linkRep(unsigned long long x) {
21+
linkRepImpl()=default;
22+
linkRepImpl(unsigned long long x) {
2723
static_assert(sizeof(data)>=sizeof(x));
2824
memcpy(data,&x,sizeof(x));
2925
memset(((char*)data)+sizeof(x),0,sizeof(data)-sizeof(x));
3026
}
31-
const linkRep& operator|=(const linkRep& x) {
27+
const linkRepImpl& operator|=(const linkRepImpl& x) {
3228
for (unsigned i=0; i<size; ++i) data[i]|=x.data[i];
3329
return *this;
3430
}
35-
linkRep operator|(linkRep x) {return x|=*this;}
36-
const linkRep& operator&=(const linkRep& x) {
31+
linkRepImpl operator|(linkRepImpl x) {return x|=*this;}
32+
const linkRepImpl& operator&=(const linkRepImpl& x) {
3733
for (unsigned i=0; i<size; ++i) data[i]&=x.data[i];
3834
return *this;
3935
}
40-
linkRep operator&(linkRep x) {return x&=*this;}
36+
linkRepImpl operator&(linkRepImpl x) {return x&=*this;}
4137

42-
linkRep operator~() const {
43-
linkRep r;
38+
linkRepImpl operator~() const {
39+
linkRepImpl r;
4440
for (unsigned i=0; i<size; ++i) r.data[i]=~data[i];
4541
return r;
4642
}
47-
linkRep operator<<(int n) {
48-
linkRep r;
43+
linkRepImpl operator<<(int n) {
44+
linkRepImpl r;
4945
auto d=div(n, int(8*sizeof(Impl)));
5046
for (unsigned i=0; i<size-d.quot; ++i)
5147
r.data[i+d.quot]=data[i]<<d.rem;
@@ -57,22 +53,29 @@ class linkRep
5753
return nullptr;
5854
}
5955

60-
bool operator<(const linkRep& x) const {
56+
auto operator<=>(const linkRepImpl& x) const {
6157
for (unsigned i=0; i<size; ++i)
62-
{
63-
if (data[i]<x.data[i]) return true;
64-
if (x.data[i]<data[i]) return false;
65-
}
66-
return false;
58+
if (auto r=data[i]<=>x.data[i]; r!=0)
59+
return r;
60+
return std::strong_ordering::equal;
6761
}
68-
std::vector<linkRep::Impl> dataAsVector() const {
69-
return std::vector<Impl>(data,data+size);
62+
std::vector<unsigned> dataAsVector() const {
63+
auto start=reinterpret_cast<const unsigned*>(data);
64+
auto end=reinterpret_cast<const unsigned*>(data+size);
65+
return std::vector<unsigned>(start,end);
7066
}
71-
void dataFromVector(const std::vector<linkRep::Impl>& x) {
72-
memcpy(data,x.data(),std::min(size_t(size),x.size())*sizeof(linkRep::Impl));
67+
void dataFromVector(const std::vector<unsigned>& x) {
68+
memcpy(data,x.data(),std::min(size_t(size),x.size())*sizeof(Impl));
7369
}
7470
};
7571

72+
#ifdef SYCL_LANGUAGE_VERSION
73+
using linkRep=linkRepImpl<VecBitSet<unsigned,4>>;
74+
#else
75+
// on NUC, unsigned works best (32 bits)
76+
using linkRep=linkRepImpl<unsigned>;
77+
#endif
78+
7679
// Convert to/from a JSON array for Python conversion
7780
#define CLASSDESC_json_pack___linkRep
7881
#define CLASSDESC_json_unpack___linkRep
@@ -84,7 +87,7 @@ namespace classdesc_access
8487
template <class _CD_ARG_TYPE>
8588
void operator()(classdesc::json_pack_t& targ, const classdesc::string& desc,_CD_ARG_TYPE& arg)
8689
{
87-
std::vector<linkRep::Impl> tmp=arg.dataAsVector();
90+
auto tmp=arg.dataAsVector();
8891
targ<<tmp;
8992
}
9093
};
@@ -93,7 +96,7 @@ namespace classdesc_access
9396
template <class _CD_ARG_TYPE>
9497
void operator()(classdesc::json_pack_t& targ, const classdesc::string& desc,_CD_ARG_TYPE& arg)
9598
{
96-
std::vector<linkRep::Impl> tmp;
99+
std::vector<unsigned> tmp;
97100
targ>>tmp;
98101
arg.dataFromVector(tmp);
99102
}

models/starComplexity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
maxStars=max(maxStars,v)
1212

1313
print('maxStars=',maxStars)
14-
maxStars=9
14+
maxStars=8
1515

1616
starC.blockSize(256)
1717
#starC.blockSize(4096)

models/vecBitSet.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,11 @@ class VecBitSet: public sycl::vec<T,N>
129129
}
130130
}
131131

132-
int operator<=>(const VecBitSet& x) const {
132+
auto operator<=>(const VecBitSet& x) const {
133133
for (unsigned i=0; i<N; ++i)
134-
{
135-
if ((*this)[i]<x[i]) return -1;
136-
if (x[i]<(*this)[i]) return 1;
137-
}
138-
return 0;
134+
if (auto r=(*this)[i]<=>x[i]; r!=0)
135+
return r;
136+
return std::strong_ordering::equal;
139137
}
140138
};
141139

0 commit comments

Comments
 (0)