Skip to content

Commit e809d4e

Browse files
committed
blst_t.hpp: facilitate constant instantiations.
1 parent 105d4af commit e809d4e

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

src/blst_t.hpp

+52-2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,33 @@ class blst_384_t {
8787
}
8888
inline blst_384_t(int a) : blst_384_t((uint64_t)a) {}
8989

90+
#if defined(__CUDACC__) || defined(__HIPCC__)
91+
template<typename... Ts>
92+
constexpr blst_384_t(limb_t a0, Ts... arr)
93+
{
94+
limb_t temp[11] = {arr...};
95+
96+
if (sizeof...(arr) < 6) {
97+
val[0] = a0;
98+
val[1] = temp[0];
99+
val[2] = temp[1];
100+
val[3] = temp[2];
101+
val[4] = temp[3];
102+
val[5] = temp[4];
103+
} else {
104+
val[0] = a0 | (temp[0] << 32);
105+
val[1] = temp[1] | (temp[2] << 32);
106+
val[2] = temp[3] | (temp[4] << 32);
107+
val[3] = temp[5] | (temp[6] << 32);
108+
val[4] = temp[7] | (temp[8] << 32);
109+
val[5] = temp[9] | (temp[10] << 32);
110+
}
111+
}
112+
#else
113+
template<typename... Ts>
114+
constexpr blst_384_t(limb_t a0, Ts... arr) : vec{a0, arr...} {}
115+
#endif
116+
90117
inline void to_scalar(pow_t& scalar) const
91118
{
92119
const union {
@@ -296,7 +323,7 @@ class blst_384_t {
296323
*str++ = '0', *str++ = 'x';
297324
for (size_t i = 0; i < sizeof(obj); i++)
298325
*str++ = hex_from_nibble(be[i]>>4), *str++ = hex_from_nibble(be[i]);
299-
*str = '\0';
326+
*str = '\0';
300327

301328
return os << buf;
302329
}
@@ -338,6 +365,29 @@ class blst_256_t {
338365
}
339366
inline blst_256_t(int a) : blst_256_t((uint64_t)a) {}
340367

368+
#if defined(__CUDACC__) || defined(__HIPCC__)
369+
template<typename... Ts>
370+
constexpr blst_256_t(limb_t a0, Ts... arr)
371+
{
372+
limb_t temp[7] = {arr...};
373+
374+
if (sizeof...(arr) < 4) {
375+
val[0] = a0;
376+
val[1] = temp[0];
377+
val[2] = temp[1];
378+
val[3] = temp[2];
379+
} else {
380+
val[0] = a0 | (temp[0] << 32);
381+
val[1] = temp[1] | (temp[2] << 32);
382+
val[2] = temp[3] | (temp[4] << 32);
383+
val[3] = temp[5] | (temp[6] << 32);
384+
}
385+
}
386+
#else
387+
template<typename... Ts>
388+
constexpr blst_256_t(limb_t a0, Ts... arr) : vec{a0, arr...} {}
389+
#endif
390+
341391
inline void to_scalar(pow_t& scalar) const
342392
{
343393
const union {
@@ -614,7 +664,7 @@ class blst_256_t {
614664
*str++ = '0', *str++ = 'x';
615665
for (size_t i = 0; i < sizeof(obj); i++)
616666
*str++ = hex_from_nibble(be[i]>>4), *str++ = hex_from_nibble(be[i]);
617-
*str = '\0';
667+
*str = '\0';
618668

619669
return os << buf;
620670
}

0 commit comments

Comments
 (0)