Skip to content

Commit 2b48901

Browse files
mdouzefacebook-github-bot
authored andcommitted
Remove 1L and 1UL
Summary: 1L and 1UL are problematic because sizeof(long) depends on the platform Reviewed By: mlomeli1 Differential Revision: D49911901 fbshipit-source-id: d4e4cb1f0283a33330bf1b8ca6b7f7bf41bc6ff4
1 parent 3f3321c commit 2b48901

6 files changed

+12
-12
lines changed

faiss/Clustering.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ float kmeans_clustering(
576576
const float* x,
577577
float* centroids) {
578578
Clustering clus(d, k);
579-
clus.verbose = d * n * k > (1L << 30);
579+
clus.verbose = d * n * k > (size_t(1) << 30);
580580
// display logs if > 1Gflop per iteration
581581
IndexFlatL2 index(d);
582582
clus.train(n, x, index);

faiss/Index2Layer.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Index2Layer::Index2Layer(
4747
pq(quantizer->d, M, nbit) {
4848
is_trained = false;
4949
for (int nbyte = 0; nbyte < 7; nbyte++) {
50-
if ((1L << (8 * nbyte)) >= nlist) {
50+
if (((size_t)1 << (8 * nbyte)) >= nlist) {
5151
code_size_1 = nbyte;
5252
break;
5353
}
@@ -179,7 +179,7 @@ struct DistanceXPQ4 : Distance2Level {
179179
float operator()(idx_t i) override {
180180
#ifdef __SSE3__
181181
const uint8_t* code = storage.codes.data() + i * storage.code_size;
182-
long key = 0;
182+
idx_t key = 0;
183183
memcpy(&key, code, storage.code_size_1);
184184
code += storage.code_size_1;
185185

@@ -225,7 +225,7 @@ struct Distance2xXPQ4 : Distance2Level {
225225

226226
float operator()(idx_t i) override {
227227
const uint8_t* code = storage.codes.data() + i * storage.code_size;
228-
long key01 = 0;
228+
int64_t key01 = 0;
229229
memcpy(&key01, code, storage.code_size_1);
230230
code += storage.code_size_1;
231231
#ifdef __SSE3__
@@ -237,7 +237,7 @@ struct Distance2xXPQ4 : Distance2Level {
237237
__m128 accu = _mm_setzero_ps();
238238

239239
for (int mi_m = 0; mi_m < 2; mi_m++) {
240-
long l1_idx = key01 & ((1L << mi_nbits) - 1);
240+
int64_t l1_idx = key01 & (((int64_t)1 << mi_nbits) - 1);
241241
const __m128* pq_l1 = pq_l1_t + M_2 * l1_idx;
242242

243243
for (int m = 0; m < M_2; m++) {

faiss/IndexPQ.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ struct MinSumK {
818818
// enqueue followers
819819
int64_t ii = ti;
820820
for (int m = 0; m < M; m++) {
821-
int64_t n = ii & ((1L << nbit) - 1);
821+
int64_t n = ii & (((int64_t)1 << nbit) - 1);
822822
ii >>= nbit;
823823
if (n + 1 >= N)
824824
continue;
@@ -842,7 +842,7 @@ struct MinSumK {
842842
}
843843
int64_t ti = 0;
844844
for (int m = 0; m < M; m++) {
845-
int64_t n = ii & ((1L << nbit) - 1);
845+
int64_t n = ii & (((int64_t)1 << nbit) - 1);
846846
ti += int64_t(ssx[m].get_ord(n)) << (nbit * m);
847847
ii >>= nbit;
848848
}
@@ -966,7 +966,7 @@ void MultiIndexQuantizer::search(
966966
void MultiIndexQuantizer::reconstruct(idx_t key, float* recons) const {
967967
int64_t jj = key;
968968
for (int m = 0; m < pq.M; m++) {
969-
int64_t n = jj & ((1L << pq.nbits) - 1);
969+
int64_t n = jj & (((int64_t)1 << pq.nbits) - 1);
970970
jj >>= pq.nbits;
971971
memcpy(recons, pq.get_centroids(m, n), sizeof(recons[0]) * pq.dsub);
972972
recons += pq.dsub;
@@ -1098,7 +1098,7 @@ void MultiIndexQuantizer2::search(
10981098

10991099
const idx_t* idmap0 = sub_ids.data() + i * k2;
11001100
int64_t ld_idmap = k2 * n;
1101-
int64_t mask1 = ksub - 1L;
1101+
int64_t mask1 = ksub - (int64_t)1;
11021102

11031103
for (int k = 0; k < K; k++) {
11041104
const idx_t* idmap = idmap0;

faiss/gpu/perf/PerfClustering.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int main(int argc, char** argv) {
4242

4343
cudaProfilerStop();
4444

45-
auto seed = FLAGS_seed != -1L ? FLAGS_seed : time(nullptr);
45+
auto seed = FLAGS_seed != -1 ? FLAGS_seed : time(nullptr);
4646
printf("using seed %ld\n", seed);
4747

4848
std::vector<float> vecs((size_t)FLAGS_num * FLAGS_dim);

faiss/impl/AuxIndexStructures.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ bool InterruptCallback::is_interrupted() {
230230

231231
size_t InterruptCallback::get_period_hint(size_t flops) {
232232
if (!instance.get()) {
233-
return 1L << 30; // never check
233+
return (size_t)1 << 30; // never check
234234
}
235235
// for 10M flops, it is reasonable to check once every 10 iterations
236236
return std::max((size_t)10 * 10 * 1000 * 1000 / (flops + 1), (size_t)1);

faiss/impl/lattice_Zn.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ void ZnSphereCodec::decode(uint64_t code, float* c) const {
455455
int nnz = 0;
456456
for (int i = 0; i < dim; i++) {
457457
if (c[i] != 0) {
458-
if (signs & (1UL << nnz)) {
458+
if (signs & (uint64_t(1) << nnz)) {
459459
c[i] = -c[i];
460460
}
461461
nnz++;

0 commit comments

Comments
 (0)