Skip to content

Commit be1fca5

Browse files
authored
feat(vector): add basic functions (vector/vector_extract etc) (#1531)
* add basic functions for working with f32/f64 vectors * add header file * fix comment style * add generic code for working with vectors * register vector functions * fix edge cases in vector extract impl * add static flag for vector (will be used later) * add basic TCL-based tests * guard vector functions with SQLITE_OMIT_VECTOR * adjust build scripts * delete libsql_vector_idx from this branch * add one more test * update bundles * fix asserts * fix constants (#define-s are universal but const int doesn't recognized by all compilers) * update bundles * review fixes * build bundles * add comment about linking math library
1 parent 2402249 commit be1fca5

File tree

18 files changed

+3661
-14
lines changed

18 files changed

+3661
-14
lines changed

libsql-ffi/bundled/SQLite3MultipleCiphers/src/sqlite3.c

Lines changed: 1168 additions & 0 deletions
Large diffs are not rendered by default.

libsql-ffi/bundled/src/sqlite3.c

Lines changed: 1168 additions & 0 deletions
Large diffs are not rendered by default.

libsql-sqlite3/Makefile.in

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ LIBOBJS0 = alter.lo analyze.lo attach.lo auth.lo \
195195
sqlite3session.lo select.lo sqlite3rbu.lo status.lo stmt.lo \
196196
table.lo threads.lo tokenize.lo treeview.lo trigger.lo \
197197
update.lo userauth.lo upsert.lo util.lo vacuum.lo \
198+
vector.lo vectorfloat32.lo vectorfloat64.lo \
198199
vdbe.lo vdbeapi.lo vdbeaux.lo vdbeblob.lo vdbemem.lo vdbesort.lo \
199200
vdbetrace.lo vdbevtab.lo \
200201
wal.lo walker.lo wasmedge_bindings.lo where.lo wherecode.lo whereexpr.lo \
@@ -299,6 +300,10 @@ SRC = \
299300
$(TOP)/src/upsert.c \
300301
$(TOP)/src/util.c \
301302
$(TOP)/src/vacuum.c \
303+
$(TOP)/src/vector.c \
304+
$(TOP)/src/vectorInt.h \
305+
$(TOP)/src/vectorfloat32.c \
306+
$(TOP)/src/vectorfloat64.c \
302307
$(TOP)/src/vdbe.c \
303308
$(TOP)/src/vdbe.h \
304309
$(TOP)/src/vdbeapi.c \
@@ -577,6 +582,7 @@ HDR = \
577582
$(TOP)/src/sqliteLimit.h \
578583
$(TOP)/src/vdbe.h \
579584
$(TOP)/src/vdbeInt.h \
585+
$(TOP)/src/vectorInt.h \
580586
$(TOP)/src/vxworks.h \
581587
$(TOP)/src/whereInt.h \
582588
sqlite_cfg.h
@@ -1103,6 +1109,15 @@ util.lo: $(TOP)/src/util.c $(HDR)
11031109
vacuum.lo: $(TOP)/src/vacuum.c $(HDR)
11041110
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/vacuum.c
11051111

1112+
vector.lo: $(TOP)/src/vector.c $(HDR)
1113+
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/vector.c
1114+
1115+
vectorfloat32.lo: $(TOP)/src/vectorfloat32.c $(HDR)
1116+
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/vectorfloat32.c
1117+
1118+
vectorfloat64.lo: $(TOP)/src/vectorfloat64.c $(HDR)
1119+
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/vectorfloat64.c
1120+
11061121
vdbe.lo: $(TOP)/src/vdbe.c $(HDR)
11071122
$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/vdbe.c
11081123

libsql-sqlite3/Makefile.msc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,7 @@ SRC05 = \
14371437
$(TOP)\src\sqliteLimit.h \
14381438
$(TOP)\src\vdbe.h \
14391439
$(TOP)\src\vdbeInt.h \
1440+
$(TOP)\src\vectorInt.h \
14401441
$(TOP)\src\vxworks.h \
14411442
$(TOP)\src\wal.h \
14421443
$(TOP)\src\whereInt.h

libsql-sqlite3/configure

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,7 @@ enable_amalgamation
939939
enable_load_extension
940940
enable_math
941941
enable_json
942+
enable_vector
942943
enable_wasm_runtime
943944
enable_wasm_runtime_dynamic
944945
enable_wasm_runtime_wasmedge
@@ -1605,6 +1606,7 @@ Optional Features:
16051606
Disable loading of external extensions
16061607
--disable-math Disable math functions
16071608
--disable-json Disable JSON functions
1609+
--disable-vector Disable vector functions
16081610
--enable-wasm-runtime Enable WebAssembly runtime integration
16091611
--enable-wasm-runtime-dynamic
16101612
Link with WebAssembly runtime dynamically
@@ -4476,13 +4478,13 @@ then :
44764478
else $as_nop
44774479
lt_cv_nm_interface="BSD nm"
44784480
echo "int some_variable = 0;" > conftest.$ac_ext
4479-
(eval echo "\"\$as_me:4479: $ac_compile\"" >&5)
4481+
(eval echo "\"\$as_me:4481: $ac_compile\"" >&5)
44804482
(eval "$ac_compile" 2>conftest.err)
44814483
cat conftest.err >&5
4482-
(eval echo "\"\$as_me:4482: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
4484+
(eval echo "\"\$as_me:4484: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
44834485
(eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
44844486
cat conftest.err >&5
4485-
(eval echo "\"\$as_me:4485: output\"" >&5)
4487+
(eval echo "\"\$as_me:4487: output\"" >&5)
44864488
cat conftest.out >&5
44874489
if $GREP 'External.*some_variable' conftest.out > /dev/null; then
44884490
lt_cv_nm_interface="MS dumpbin"
@@ -5733,7 +5735,7 @@ ia64-*-hpux*)
57335735
;;
57345736
*-*-irix6*)
57355737
# Find out which ABI we are using.
5736-
echo '#line 5736 "configure"' > conftest.$ac_ext
5738+
echo '#line 5738 "configure"' > conftest.$ac_ext
57375739
if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
57385740
(eval $ac_compile) 2>&5
57395741
ac_status=$?
@@ -7076,11 +7078,11 @@ else $as_nop
70767078
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
70777079
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
70787080
-e 's:$: $lt_compiler_flag:'`
7079-
(eval echo "\"\$as_me:7079: $lt_compile\"" >&5)
7081+
(eval echo "\"\$as_me:7081: $lt_compile\"" >&5)
70807082
(eval "$lt_compile" 2>conftest.err)
70817083
ac_status=$?
70827084
cat conftest.err >&5
7083-
echo "$as_me:7083: \$? = $ac_status" >&5
7085+
echo "$as_me:7085: \$? = $ac_status" >&5
70847086
if (exit $ac_status) && test -s "$ac_outfile"; then
70857087
# The compiler can only warn and ignore the option if not recognized
70867088
# So say no if there are warnings other than the usual output.
@@ -7416,11 +7418,11 @@ else $as_nop
74167418
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
74177419
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
74187420
-e 's:$: $lt_compiler_flag:'`
7419-
(eval echo "\"\$as_me:7419: $lt_compile\"" >&5)
7421+
(eval echo "\"\$as_me:7421: $lt_compile\"" >&5)
74207422
(eval "$lt_compile" 2>conftest.err)
74217423
ac_status=$?
74227424
cat conftest.err >&5
7423-
echo "$as_me:7423: \$? = $ac_status" >&5
7425+
echo "$as_me:7425: \$? = $ac_status" >&5
74247426
if (exit $ac_status) && test -s "$ac_outfile"; then
74257427
# The compiler can only warn and ignore the option if not recognized
74267428
# So say no if there are warnings other than the usual output.
@@ -7523,11 +7525,11 @@ else $as_nop
75237525
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
75247526
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
75257527
-e 's:$: $lt_compiler_flag:'`
7526-
(eval echo "\"\$as_me:7526: $lt_compile\"" >&5)
7528+
(eval echo "\"\$as_me:7528: $lt_compile\"" >&5)
75277529
(eval "$lt_compile" 2>out/conftest.err)
75287530
ac_status=$?
75297531
cat out/conftest.err >&5
7530-
echo "$as_me:7530: \$? = $ac_status" >&5
7532+
echo "$as_me:7532: \$? = $ac_status" >&5
75317533
if (exit $ac_status) && test -s out/conftest2.$ac_objext
75327534
then
75337535
# The compiler can only warn and ignore the option if not recognized
@@ -7579,11 +7581,11 @@ else $as_nop
75797581
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
75807582
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
75817583
-e 's:$: $lt_compiler_flag:'`
7582-
(eval echo "\"\$as_me:7582: $lt_compile\"" >&5)
7584+
(eval echo "\"\$as_me:7584: $lt_compile\"" >&5)
75837585
(eval "$lt_compile" 2>out/conftest.err)
75847586
ac_status=$?
75857587
cat out/conftest.err >&5
7586-
echo "$as_me:7586: \$? = $ac_status" >&5
7588+
echo "$as_me:7588: \$? = $ac_status" >&5
75877589
if (exit $ac_status) && test -s out/conftest2.$ac_objext
75887590
then
75897591
# The compiler can only warn and ignore the option if not recognized
@@ -9967,7 +9969,7 @@ else
99679969
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
99689970
lt_status=$lt_dlunknown
99699971
cat > conftest.$ac_ext <<_LT_EOF
9970-
#line 9970 "configure"
9972+
#line 9972 "configure"
99719973
#include "confdefs.h"
99729974
99739975
#if HAVE_DLFCN_H
@@ -10064,7 +10066,7 @@ else
1006410066
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
1006510067
lt_status=$lt_dlunknown
1006610068
cat > conftest.$ac_ext <<_LT_EOF
10067-
#line 10067 "configure"
10069+
#line 10069 "configure"
1006810070
#include "confdefs.h"
1006910071
1007010072
#if HAVE_DLFCN_H
@@ -12151,6 +12153,26 @@ else
1215112153
printf "%s\n" "yes" >&6; }
1215212154
fi
1215312155

12156+
##########
12157+
# Do we want to support vector functions
12158+
#
12159+
# Check whether --enable-vector was given.
12160+
if test ${enable_vector+y}
12161+
then :
12162+
enableval=$enable_vector;
12163+
fi
12164+
12165+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to support vector functions" >&5
12166+
printf %s "checking whether to support vector functions... " >&6; }
12167+
if test "$enable_vector" = "no"; then
12168+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
12169+
printf "%s\n" "no" >&6; }
12170+
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_OMIT_VECTOR"
12171+
else
12172+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
12173+
printf "%s\n" "yes" >&6; }
12174+
fi
12175+
1215412176
##########
1215512177
# Do we want to support WebAssembly runtime
1215612178
#

libsql-sqlite3/configure.ac

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,19 @@ else
697697
AC_MSG_RESULT([yes])
698698
fi
699699

700+
##########
701+
# Do we want to support vector functions
702+
#
703+
AC_ARG_ENABLE(vector,
704+
AS_HELP_STRING([--disable-vector],[Disable vector functions]))
705+
AC_MSG_CHECKING([whether to support vector functions])
706+
if test "$enable_vector" = "no"; then
707+
AC_MSG_RESULT([no])
708+
OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_OMIT_VECTOR"
709+
else
710+
AC_MSG_RESULT([yes])
711+
fi
712+
700713
##########
701714
# Do we want to support WebAssembly runtime
702715
#

libsql-sqlite3/ext/crr/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# we need math.h for sqrt function in LIBSQL vector feature
2+
LDLIBS += -lm
3+
14
ifndef CI_GCC
25
CC:=gcc
36
else

libsql-sqlite3/src/func.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2869,6 +2869,9 @@ void sqlite3RegisterBuiltinFunctions(void){
28692869
sqlite3WindowFunctions();
28702870
sqlite3RegisterDateTimeFunctions();
28712871
sqlite3RegisterJsonFunctions();
2872+
#ifndef SQLITE_OMIT_VECTOR
2873+
sqlite3RegisterVectorFunctions();
2874+
#endif
28722875
sqlite3InsertBuiltinFuncs(aBuiltinFunc, ArraySize(aBuiltinFunc));
28732876

28742877
#if 0 /* Enable to print out how the built-in functions are hashed */

libsql-sqlite3/src/sqliteInt.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5086,6 +5086,9 @@ void sqlite3QuoteValue(StrAccum*,sqlite3_value*);
50865086
void sqlite3RegisterBuiltinFunctions(void);
50875087
void sqlite3RegisterDateTimeFunctions(void);
50885088
void sqlite3RegisterJsonFunctions(void);
5089+
#ifndef SQLITE_OMIT_VECTOR
5090+
void sqlite3RegisterVectorFunctions(void);
5091+
#endif
50895092
void sqlite3RegisterPerConnectionBuiltinFunctions(sqlite3*);
50905093
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_JSON)
50915094
int sqlite3JsonTableFunctions(sqlite3*);

0 commit comments

Comments
 (0)