Skip to content

Commit eac5d90

Browse files
committed
move utils back to the vector1bit to simplify inlining for compiler
1 parent cd9cea3 commit eac5d90

4 files changed

Lines changed: 29 additions & 42 deletions

File tree

libsql-sqlite3/src/sqliteInt.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5321,8 +5321,6 @@ int sqlite3AddInt64(i64*,i64);
53215321
int sqlite3SubInt64(i64*,i64);
53225322
int sqlite3MulInt64(i64*,i64);
53235323
int sqlite3AbsInt32(int);
5324-
int sqlite3PopCount32(u32);
5325-
int sqlite3PopCount64(u64);
53265324
#ifdef SQLITE_ENABLE_8_3_NAMES
53275325
void sqlite3FileSuffix3(const char*, char*);
53285326
#else

libsql-sqlite3/src/util.c

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,43 +1542,6 @@ int sqlite3SafetyCheckSickOrOk(sqlite3 *db){
15421542
}
15431543
}
15441544

1545-
1546-
// [sum(map(int, bin(i)[2:])) for i in range(256)]
1547-
static int BitsCount[256] = {
1548-
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
1549-
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
1550-
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
1551-
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
1552-
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
1553-
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
1554-
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
1555-
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
1556-
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
1557-
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
1558-
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
1559-
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
1560-
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
1561-
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
1562-
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
1563-
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
1564-
};
1565-
1566-
int sqlite3PopCount32(u32 a){
1567-
#if GCC_VERSION>=5004000 && !defined(__INTEL_COMPILER)
1568-
return __builtin_popcount(a);
1569-
#else
1570-
return BitsCount[a >> 24] + BitsCount[(a >> 16) & 0xff] + BitsCount[(a >> 8) & 0xff] + BitsCount[a & 0xff];
1571-
#endif
1572-
}
1573-
1574-
int sqlite3PopCount64(u64 a){
1575-
#if GCC_VERSION>=5004000 && !defined(__INTEL_COMPILER)
1576-
return __builtin_popcountll(a);
1577-
#else
1578-
return sqlite3PopCount32(a >> 32) + sqlite3PopCount32(a & 0xffffffff);
1579-
#endif
1580-
}
1581-
15821545
/*
15831546
** Attempt to add, subtract, or multiply the 64-bit signed value iB against
15841547
** the other 64-bit signed integer at *pA and store the result in *pA.

libsql-sqlite3/src/vector.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,7 @@ void vectorConvert(const Vector *pFrom, Vector *pTo){
494494
bitData[i / 8] = 0;
495495
}
496496
for(i = 0; i < pFrom->dims; i++){
497-
if( floatData[i] < 0 ){
498-
bitData[i / 8] &= ~(1 << (i & 7));
499-
}else{
497+
if( floatData[i] > 0 ){
500498
bitData[i / 8] |= (1 << (i & 7));
501499
}
502500
}

libsql-sqlite3/src/vector1bit.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,34 @@ size_t vector1BitSerializeToBlob(
7070
return (pVector->dims + 7) / 8;
7171
}
7272

73+
// [sum(map(int, bin(i)[2:])) for i in range(256)]
74+
static int BitsCount[256] = {
75+
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
76+
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
77+
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
78+
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
79+
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
80+
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
81+
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
82+
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
83+
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
84+
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
85+
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
86+
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
87+
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
88+
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
89+
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
90+
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
91+
};
92+
93+
static inline int sqlite3PopCount32(u32 a){
94+
#if GCC_VERSION>=5004000 && !defined(__INTEL_COMPILER)
95+
return __builtin_popcount(a);
96+
#else
97+
return BitsCount[a >> 24] + BitsCount[(a >> 16) & 0xff] + BitsCount[(a >> 8) & 0xff] + BitsCount[a & 0xff];
98+
#endif
99+
}
100+
73101
int vector1BitDistanceHamming(const Vector *v1, const Vector *v2){
74102
int diff = 0;
75103
u8 *e1U8 = v1->data;

0 commit comments

Comments
 (0)