Skip to content

Commit

Permalink
Remove 1L and 1UL
Browse files Browse the repository at this point in the history
Summary: 1L and 1UL are problematic because sizeof(long) depends on the platform

Reviewed By: mlomeli1

Differential Revision: D49911901

fbshipit-source-id: d4e4cb1f0283a33330bf1b8ca6b7f7bf41bc6ff4
  • Loading branch information
mdouze authored and facebook-github-bot committed Oct 4, 2023
1 parent 3f3321c commit 2b48901
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion faiss/Clustering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ float kmeans_clustering(
const float* x,
float* centroids) {
Clustering clus(d, k);
clus.verbose = d * n * k > (1L << 30);
clus.verbose = d * n * k > (size_t(1) << 30);
// display logs if > 1Gflop per iteration
IndexFlatL2 index(d);
clus.train(n, x, index);
Expand Down
8 changes: 4 additions & 4 deletions faiss/Index2Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Index2Layer::Index2Layer(
pq(quantizer->d, M, nbit) {
is_trained = false;
for (int nbyte = 0; nbyte < 7; nbyte++) {
if ((1L << (8 * nbyte)) >= nlist) {
if (((size_t)1 << (8 * nbyte)) >= nlist) {
code_size_1 = nbyte;
break;
}
Expand Down Expand Up @@ -179,7 +179,7 @@ struct DistanceXPQ4 : Distance2Level {
float operator()(idx_t i) override {
#ifdef __SSE3__
const uint8_t* code = storage.codes.data() + i * storage.code_size;
long key = 0;
idx_t key = 0;
memcpy(&key, code, storage.code_size_1);
code += storage.code_size_1;

Expand Down Expand Up @@ -225,7 +225,7 @@ struct Distance2xXPQ4 : Distance2Level {

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

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

for (int m = 0; m < M_2; m++) {
Expand Down
8 changes: 4 additions & 4 deletions faiss/IndexPQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ struct MinSumK {
// enqueue followers
int64_t ii = ti;
for (int m = 0; m < M; m++) {
int64_t n = ii & ((1L << nbit) - 1);
int64_t n = ii & (((int64_t)1 << nbit) - 1);
ii >>= nbit;
if (n + 1 >= N)
continue;
Expand All @@ -842,7 +842,7 @@ struct MinSumK {
}
int64_t ti = 0;
for (int m = 0; m < M; m++) {
int64_t n = ii & ((1L << nbit) - 1);
int64_t n = ii & (((int64_t)1 << nbit) - 1);
ti += int64_t(ssx[m].get_ord(n)) << (nbit * m);
ii >>= nbit;
}
Expand Down Expand Up @@ -966,7 +966,7 @@ void MultiIndexQuantizer::search(
void MultiIndexQuantizer::reconstruct(idx_t key, float* recons) const {
int64_t jj = key;
for (int m = 0; m < pq.M; m++) {
int64_t n = jj & ((1L << pq.nbits) - 1);
int64_t n = jj & (((int64_t)1 << pq.nbits) - 1);
jj >>= pq.nbits;
memcpy(recons, pq.get_centroids(m, n), sizeof(recons[0]) * pq.dsub);
recons += pq.dsub;
Expand Down Expand Up @@ -1098,7 +1098,7 @@ void MultiIndexQuantizer2::search(

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

for (int k = 0; k < K; k++) {
const idx_t* idmap = idmap0;
Expand Down
2 changes: 1 addition & 1 deletion faiss/gpu/perf/PerfClustering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int main(int argc, char** argv) {

cudaProfilerStop();

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

std::vector<float> vecs((size_t)FLAGS_num * FLAGS_dim);
Expand Down
2 changes: 1 addition & 1 deletion faiss/impl/AuxIndexStructures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ bool InterruptCallback::is_interrupted() {

size_t InterruptCallback::get_period_hint(size_t flops) {
if (!instance.get()) {
return 1L << 30; // never check
return (size_t)1 << 30; // never check
}
// for 10M flops, it is reasonable to check once every 10 iterations
return std::max((size_t)10 * 10 * 1000 * 1000 / (flops + 1), (size_t)1);
Expand Down
2 changes: 1 addition & 1 deletion faiss/impl/lattice_Zn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ void ZnSphereCodec::decode(uint64_t code, float* c) const {
int nnz = 0;
for (int i = 0; i < dim; i++) {
if (c[i] != 0) {
if (signs & (1UL << nnz)) {
if (signs & (uint64_t(1) << nnz)) {
c[i] = -c[i];
}
nnz++;
Expand Down

0 comments on commit 2b48901

Please sign in to comment.