Skip to content

Commit 0c3b6e6

Browse files
author
Thomas G. Lockhart
committed
Initial 64-bit integer package.
1 parent 5bc1024 commit 0c3b6e6

File tree

5 files changed

+841
-0
lines changed

5 files changed

+841
-0
lines changed

contrib/int8/Makefile

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#-------------------------------------------------------------------------
2+
#
3+
# Makefile--
4+
# Makefile for Postgres 64-bit integer extensions
5+
#
6+
# Thomas G. Lockhart <Thomas.Lockhart@jpl.nasa.gov>
7+
#
8+
# This is a first attempt at 64-bit arithmetic for Postgres.
9+
# It takes advantage of "long long int" support in GNU C on 32-bit machines.
10+
# The modules are built and installed as user-defined types,
11+
# so destination directories are pointing away from the standard
12+
# Postgres areas. You will need to modify the paths to fit your machine.
13+
#
14+
# On my Linux box, I had to find an extra library for the division function (?).
15+
# For Alpha boxes, both the DEC and GNU compilers should need "long int" only.
16+
#
17+
#-------------------------------------------------------------------------
18+
19+
ifndef PGDIR
20+
PGDIR= /opt/postgres/current
21+
endif
22+
23+
SRCDIR= $(PGDIR)/src
24+
25+
include $(SRCDIR)/Makefile.global
26+
27+
# Comment out this re-declaration of LIBDIR
28+
# if you are installing as the postgres superuser
29+
# into a specific database or into template1.
30+
LIBDIR= /home/tgl/lib
31+
32+
CFLAGS+= -I$(PGDIR)/include -I$(PGDIR)/src/include -I$(LIBPQDIR)
33+
34+
# This extra library is for the 64-bit division routine on my Linux box
35+
# and probably will need to be commented-out for most other platforms.
36+
CLIBS+= /usr/lib/gcc-lib/i486-linux/2.7.2/libgcc.a
37+
38+
TARGETS= int8.sql int8$(DLSUFFIX)
39+
40+
all: $(TARGETS)
41+
42+
int8$(DLSUFFIX): int8.o
43+
$(CC) -shared -o int8$(DLSUFFIX) int8.o $(CLIBS)
44+
45+
install:
46+
$(MAKE) all
47+
cp -p int8$(DLSUFFIX) $(LIBDIR)
48+
49+
%.sql: %.source
50+
if [ -z "$$USER" ]; then USER=$$LOGNAME; fi; \
51+
if [ -z "$$USER" ]; then USER=`whoami`; fi; \
52+
if [ -z "$$USER" ]; then echo 'Cannot deduce $$USER.'; exit 1; fi; \
53+
rm -f $@; \
54+
C=`pwd`; \
55+
O=$C; \
56+
if [ -d ${LIBDIR} ]; then O=${LIBDIR}; fi; \
57+
sed -e "s:_CWD_:$$C:g" \
58+
-e "s:_OBJWD_:$$O:g" \
59+
-e "s:_DLSUFFIX_:$(DLSUFFIX):g" \
60+
-e "s/_USER_/$$USER/g" < $< > $@
61+
62+
clean:
63+
rm -f $(TARGETS) int8.o
64+

contrib/int8/README

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
Postgres int8
2+
3+
Thomas G. Lockhart <Thomas.Lockhart@jpl.nasa.gov>
4+
5+
This is a first attempt at 64-bit integer arithmetic for Postgres. The code
6+
should support any 64-bit architecture and any 32-bit machine using a recent
7+
GNU C compiler. At the moment, DEC-Alpha and Linux/gcc are explicitly
8+
supported. The code uses "long long int" support in GNU C on 32-bit machines.
9+
This type is an extension to ANSI-C, and may not appear on any other compiler.
10+
11+
The modules are built and installed as user-defined types, so destination
12+
directories are pointing away from the standard Postgres areas.
13+
14+
Other compilers and architectures should be supportable, so please let me know
15+
what changes were required to run on your machine, and I will fold those into
16+
this standard distribution.
17+
18+
Good luck!
19+
20+
- Tom
21+
22+
23+
Installation
24+
25+
You will need to modify the Makefile paths to fit your machine. Since this
26+
is packaged as a "user-installable" type, the libraries and source code
27+
can reside outside of the standard Postgres areas.
28+
29+
If you are compiling on a DEC-Alpha, then the code might compile
30+
and run without change. (I do a lot of code development on Alphas,
31+
but do not have a Postgres installation to test).
32+
33+
make
34+
make install
35+
psql dbname < int8.sql
36+
37+
If you are running gcc on a 32-bit machine, you will probably need to:
38+
- remove the extra library reference in the Makefile.
39+
- if there are unresolved symbols when you try running, then find
40+
the right library. The one I had chosen might be a clue.
41+
42+
If you are not running gcc on a 32-bit machine, you will need to:
43+
- redeclare the 64 bit data type.
44+
- modify the scanf and printf() arguments to use the appropriate
45+
64-bit int arguments.
46+
47+
On my Linux box, I had to find an extra library for the division function.
48+
For Alpha boxes, both the DEC and GNU compilers should need "long int" only.
49+
I have a reference to "__alpha" in the C source code, but have not tested it
50+
and am not certain that this is the correct pre-defined symbol for that machine.
51+
52+
itest.sql is a small test file which exercises some of the I/O, functions,
53+
and boolean operators.
54+
55+
int8:
56+
=
57+
<>
58+
<
59+
>
60+
<=
61+
>=
62+
63+
- unary minus
64+
+ addition
65+
- subtraction
66+
* multiplication
67+
/ division
68+
69+
int4() convert to 4-byte integer
70+
float8() convert to double float
71+
72+
Routines defined are:
73+
74+
int64 *int8in(char *str);
75+
char *int8out(int64 *val);
76+
77+
bool int8eq(int64 *val1, int64 *val2);
78+
bool int8ne(int64 *val1, int64 *val2);
79+
bool int8lt(int64 *val1, int64 *val2);
80+
bool int8gt(int64 *val1, int64 *val2);
81+
bool int8le(int64 *val1, int64 *val2);
82+
bool int8ge(int64 *val1, int64 *val2);
83+
84+
bool int84eq(int64 *val1, int32 val2);
85+
bool int84ne(int64 *val1, int32 val2);
86+
bool int84lt(int64 *val1, int32 val2);
87+
bool int84gt(int64 *val1, int32 val2);
88+
bool int84le(int64 *val1, int32 val2);
89+
bool int84ge(int64 *val1, int32 val2);
90+
91+
int64 *int8um(int64 *val);
92+
int64 *int8pl(int64 *val1, int64 *val2);
93+
int64 *int8mi(int64 *val1, int64 *val2);
94+
int64 *int8mul(int64 *val1, int64 *val2);
95+
int64 *int8div(int64 *val1, int64 *val2);
96+
97+
int64 *int48(int32 val);
98+
int32 int84(int64 *val);
99+
100+
int64 *dtoi8(float8 *val);
101+
float8 *i8tod(int64 *val);

0 commit comments

Comments
 (0)