Skip to content

Commit b0c1c53

Browse files
committed
Integer binary operators, from Marko Kreen <marko@l-t.ee>. Renamed bitxor
operator to '#' for consistency. Parser still needs work.
1 parent fa9357d commit b0c1c53

File tree

7 files changed

+297
-8
lines changed

7 files changed

+297
-8
lines changed

doc/src/sgml/oper.sgml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/Attic/oper.sgml,v 1.20 2000/10/04 15:47:45 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/Attic/oper.sgml,v 1.21 2000/10/24 20:13:31 petere Exp $
33
-->
44

55
<Chapter Id="operators">
@@ -493,6 +493,36 @@ logical union
493493
<ENTRY>Cube root</ENTRY>
494494
<ENTRY>||/ 27.0</ENTRY>
495495
</ROW>
496+
<ROW>
497+
<ENTRY> & </ENTRY>
498+
<ENTRY>Binary AND</ENTRY>
499+
<ENTRY>91 & 15</ENTRY>
500+
</ROW>
501+
<ROW>
502+
<ENTRY> | </ENTRY>
503+
<ENTRY>Binary OR</ENTRY>
504+
<ENTRY>32 | 3</ENTRY>
505+
</ROW>
506+
<ROW>
507+
<ENTRY> # </ENTRY>
508+
<ENTRY>Binary XOR</ENTRY>
509+
<ENTRY>15 # 4</ENTRY>
510+
</ROW>
511+
<ROW>
512+
<ENTRY> ~ </ENTRY>
513+
<ENTRY>Binary NOT</ENTRY>
514+
<ENTRY>~1</ENTRY>
515+
</ROW>
516+
<ROW>
517+
<ENTRY> &lt;&lt; </ENTRY>
518+
<ENTRY>Binary shift left</ENTRY>
519+
<ENTRY>1 &lt;&lt; 4</ENTRY>
520+
</ROW>
521+
<ROW>
522+
<ENTRY> &gt;&gt; </ENTRY>
523+
<ENTRY>Binary shift right</ENTRY>
524+
<ENTRY>8 &gt;&gt; 2</ENTRY>
525+
</ROW>
496526
</TBODY>
497527
</TGROUP>
498528
</TABLE>

src/backend/utils/adt/int.c

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.42 2000/08/01 18:29:35 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.43 2000/10/24 20:14:35 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -843,3 +843,121 @@ int4smaller(PG_FUNCTION_ARGS)
843843

844844
PG_RETURN_INT32((arg1 < arg2) ? arg1 : arg2);
845845
}
846+
847+
/* Binary arithmetics
848+
*
849+
* int[24]and - returns arg1 & arg2
850+
* int[24]or - returns arg1 | arg2
851+
* int[24]xor - returns arg1 # arg2
852+
* int[24]not - returns ~arg1
853+
* int[24]shl - returns arg1 << arg2
854+
* int[24]shr - returns arg1 >> arg2
855+
*/
856+
857+
Datum
858+
int4and(PG_FUNCTION_ARGS)
859+
{
860+
int32 arg1 = PG_GETARG_INT32(0);
861+
int32 arg2 = PG_GETARG_INT32(1);
862+
863+
PG_RETURN_INT32(arg1 & arg2);
864+
}
865+
866+
Datum
867+
int4or(PG_FUNCTION_ARGS)
868+
{
869+
int32 arg1 = PG_GETARG_INT32(0);
870+
int32 arg2 = PG_GETARG_INT32(1);
871+
872+
PG_RETURN_INT32(arg1 | arg2);
873+
}
874+
875+
Datum
876+
int4xor(PG_FUNCTION_ARGS)
877+
{
878+
int32 arg1 = PG_GETARG_INT32(0);
879+
int32 arg2 = PG_GETARG_INT32(1);
880+
881+
PG_RETURN_INT32(arg1 ^ arg2);
882+
}
883+
884+
Datum
885+
int4shl(PG_FUNCTION_ARGS)
886+
{
887+
int32 arg1 = PG_GETARG_INT32(0);
888+
int32 arg2 = PG_GETARG_INT32(1);
889+
890+
PG_RETURN_INT32(arg1 << arg2);
891+
}
892+
893+
Datum
894+
int4shr(PG_FUNCTION_ARGS)
895+
{
896+
int32 arg1 = PG_GETARG_INT32(0);
897+
int32 arg2 = PG_GETARG_INT32(1);
898+
899+
PG_RETURN_INT32(arg1 >> arg2);
900+
}
901+
902+
Datum
903+
int4not(PG_FUNCTION_ARGS)
904+
{
905+
int32 arg1 = PG_GETARG_INT32(0);
906+
907+
PG_RETURN_INT32(~arg1);
908+
}
909+
910+
Datum
911+
int2and(PG_FUNCTION_ARGS)
912+
{
913+
int16 arg1 = PG_GETARG_INT16(0);
914+
int16 arg2 = PG_GETARG_INT16(1);
915+
916+
PG_RETURN_INT16(arg1 & arg2);
917+
}
918+
919+
Datum
920+
int2or(PG_FUNCTION_ARGS)
921+
{
922+
int16 arg1 = PG_GETARG_INT16(0);
923+
int16 arg2 = PG_GETARG_INT16(1);
924+
925+
PG_RETURN_INT16(arg1 | arg2);
926+
}
927+
928+
Datum
929+
int2xor(PG_FUNCTION_ARGS)
930+
{
931+
int16 arg1 = PG_GETARG_INT16(0);
932+
int16 arg2 = PG_GETARG_INT16(1);
933+
934+
PG_RETURN_INT16(arg1 ^ arg2);
935+
}
936+
937+
Datum
938+
int2not(PG_FUNCTION_ARGS)
939+
{
940+
int16 arg1 = PG_GETARG_INT16(0);
941+
942+
PG_RETURN_INT16(~arg1);
943+
}
944+
945+
946+
Datum
947+
int2shl(PG_FUNCTION_ARGS)
948+
{
949+
int16 arg1 = PG_GETARG_INT16(0);
950+
int32 arg2 = PG_GETARG_INT32(1);
951+
952+
PG_RETURN_INT16(arg1 << arg2);
953+
}
954+
955+
Datum
956+
int2shr(PG_FUNCTION_ARGS)
957+
{
958+
int16 arg1 = PG_GETARG_INT16(0);
959+
int32 arg2 = PG_GETARG_INT32(1);
960+
961+
PG_RETURN_INT16(arg1 >> arg2);
962+
}
963+

src/backend/utils/adt/int8.c

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.24 2000/07/28 05:07:41 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.25 2000/10/24 20:14:35 petere Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -591,6 +591,68 @@ int48div(PG_FUNCTION_ARGS)
591591
PG_RETURN_INT64(val1 / val2);
592592
}
593593

594+
/* Binary arithmetics
595+
*
596+
* int8and - returns arg1 & arg2
597+
* int8or - returns arg1 | arg2
598+
* int8xor - returns arg1 # arg2
599+
* int8not - returns ~arg1
600+
* int8shl - returns arg1 << arg2
601+
* int8shr - returns arg1 >> arg2
602+
*/
603+
604+
Datum
605+
int8and(PG_FUNCTION_ARGS)
606+
{
607+
int64 arg1 = PG_GETARG_INT64(0);
608+
int64 arg2 = PG_GETARG_INT64(1);
609+
610+
PG_RETURN_INT64(arg1 & arg2);
611+
}
612+
613+
Datum
614+
int8or(PG_FUNCTION_ARGS)
615+
{
616+
int64 arg1 = PG_GETARG_INT64(0);
617+
int64 arg2 = PG_GETARG_INT64(1);
618+
619+
PG_RETURN_INT64(arg1 | arg2);
620+
}
621+
622+
Datum
623+
int8xor(PG_FUNCTION_ARGS)
624+
{
625+
int64 arg1 = PG_GETARG_INT64(0);
626+
int64 arg2 = PG_GETARG_INT64(1);
627+
628+
PG_RETURN_INT64(arg1 ^ arg2);
629+
}
630+
631+
Datum
632+
int8not(PG_FUNCTION_ARGS)
633+
{
634+
int64 arg1 = PG_GETARG_INT64(0);
635+
636+
PG_RETURN_INT64(~arg1);
637+
}
638+
639+
Datum
640+
int8shl(PG_FUNCTION_ARGS)
641+
{
642+
int64 arg1 = PG_GETARG_INT64(0);
643+
int32 arg2 = PG_GETARG_INT32(1);
644+
645+
PG_RETURN_INT64(arg1 << arg2);
646+
}
647+
648+
Datum
649+
int8shr(PG_FUNCTION_ARGS)
650+
{
651+
int64 arg1 = PG_GETARG_INT64(0);
652+
int32 arg2 = PG_GETARG_INT32(1);
653+
654+
PG_RETURN_INT64(arg1 >> arg2);
655+
}
594656

595657
/*----------------------------------------------------------
596658
* Conversion operators.

src/include/catalog/pg_operator.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $Id: pg_operator.h,v 1.82 2000/09/15 18:45:27 tgl Exp $
11+
* $Id: pg_operator.h,v 1.83 2000/10/24 20:15:45 petere Exp $
1212
*
1313
* NOTES
1414
* the genbki.sh script reads this file and generates .bki
@@ -727,7 +727,7 @@ DATA(insert OID = 1788 ( "<=" PGUID 0 b t f 1560 1560 16 1789 1787 0 0 bitle
727727
DATA(insert OID = 1789 ( ">=" PGUID 0 b t f 1560 1560 16 1788 1786 0 0 bitge scalargtsel scalargtjoinsel ));
728728
DATA(insert OID = 1791 ( "&" PGUID 0 b t f 1560 1560 1560 1791 0 0 0 bitand - - ));
729729
DATA(insert OID = 1792 ( "|" PGUID 0 b t f 1560 1560 1560 1792 0 0 0 bitor - - ));
730-
DATA(insert OID = 1793 ( "^" PGUID 0 b t f 1560 1560 1560 1793 0 0 0 bitxor - - ));
730+
DATA(insert OID = 1793 ( "#" PGUID 0 b t f 1560 1560 1560 1793 0 0 0 bitxor - - ));
731731
DATA(insert OID = 1794 ( "~" PGUID 0 l t f 0 1560 1560 0 0 0 0 bitnot - - ));
732732
DATA(insert OID = 1795 ( "<<" PGUID 0 b t f 1560 23 1560 0 0 0 0 bitshiftleft - - ));
733733
DATA(insert OID = 1796 ( ">>" PGUID 0 b t f 1560 23 1560 0 0 0 0 bitshiftright - - ));
@@ -754,6 +754,27 @@ DATA(insert OID = 1871 ( ">" PGUID 0 b t f 20 21 16 1864 1872 0 0 int8
754754
DATA(insert OID = 1872 ( "<=" PGUID 0 b t f 20 21 16 1867 1871 0 0 int82le scalarltsel scalarltjoinsel ));
755755
DATA(insert OID = 1873 ( ">=" PGUID 0 b t f 20 21 16 1866 1870 0 0 int82ge scalargtsel scalargtjoinsel ));
756756

757+
DATA(insert OID = 1874 ( "&" PGUID 0 b t f 21 21 21 1874 0 0 0 int2and - - ));
758+
DATA(insert OID = 1875 ( "|" PGUID 0 b t f 21 21 21 1875 0 0 0 int2or - - ));
759+
DATA(insert OID = 1876 ( "#" PGUID 0 b t f 21 21 21 1876 0 0 0 int2xor - - ));
760+
DATA(insert OID = 1877 ( "~" PGUID 0 l t f 0 21 21 0 0 0 0 int2not - - ));
761+
DATA(insert OID = 1878 ( "<<" PGUID 0 b t f 21 23 21 0 0 0 0 int2shl - - ));
762+
DATA(insert OID = 1879 ( ">>" PGUID 0 b t f 21 23 21 0 0 0 0 int2shr - - ));
763+
764+
DATA(insert OID = 1880 ( "&" PGUID 0 b t f 23 23 23 1880 0 0 0 int4and - - ));
765+
DATA(insert OID = 1881 ( "|" PGUID 0 b t f 23 23 23 1881 0 0 0 int4or - - ));
766+
DATA(insert OID = 1882 ( "#" PGUID 0 b t f 23 23 23 1882 0 0 0 int4xor - - ));
767+
DATA(insert OID = 1883 ( "~" PGUID 0 l t f 0 23 23 0 0 0 0 int4not - - ));
768+
DATA(insert OID = 1884 ( "<<" PGUID 0 b t f 23 23 23 0 0 0 0 int4shl - - ));
769+
DATA(insert OID = 1885 ( ">>" PGUID 0 b t f 23 23 23 0 0 0 0 int4shr - - ));
770+
771+
DATA(insert OID = 1886 ( "&" PGUID 0 b t f 20 20 20 1886 0 0 0 int8and - - ));
772+
DATA(insert OID = 1887 ( "|" PGUID 0 b t f 20 20 20 1887 0 0 0 int8or - - ));
773+
DATA(insert OID = 1888 ( "#" PGUID 0 b t f 20 20 20 1888 0 0 0 int8xor - - ));
774+
DATA(insert OID = 1889 ( "~" PGUID 0 l t f 0 20 20 0 0 0 0 int8not - - ));
775+
DATA(insert OID = 1890 ( "<<" PGUID 0 b t f 20 23 20 0 0 0 0 int8shl - - ));
776+
DATA(insert OID = 1891 ( ">>" PGUID 0 b t f 20 23 20 0 0 0 0 int8shr - - ));
777+
757778
/*
758779
* function prototypes
759780
*/

src/include/catalog/pg_proc.h

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_proc.h,v 1.169 2000/10/11 15:31:13 pjw Exp $
10+
* $Id: pg_proc.h,v 1.170 2000/10/24 20:15:45 petere Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -2513,6 +2513,44 @@ DESCR("less-than-or-equal");
25132513
DATA(insert OID = 1861 ( int82ge PGUID 12 f t t t 2 f 16 "20 21" 100 0 0 100 int82ge - ));
25142514
DESCR("greater-than-or-equal");
25152515

2516+
DATA(insert OID = 1892 ( int2and PGUID 12 f t t t 2 f 21 "21 21" 100 0 0 100 int2and - ));
2517+
DESCR("binary and");
2518+
DATA(insert OID = 1893 ( int2or PGUID 12 f t t t 2 f 21 "21 21" 100 0 0 100 int2or - ));
2519+
DESCR("binary or");
2520+
DATA(insert OID = 1894 ( int2xor PGUID 12 f t t t 2 f 21 "21 21" 100 0 0 100 int2xor - ));
2521+
DESCR("binary xor");
2522+
DATA(insert OID = 1895 ( int2not PGUID 12 f t t t 1 f 21 "21" 100 0 0 100 int2not - ));
2523+
DESCR("binary not");
2524+
DATA(insert OID = 1896 ( int2shl PGUID 12 f t t t 2 f 21 "21 23" 100 0 0 100 int2shl - ));
2525+
DESCR("binary shift left");
2526+
DATA(insert OID = 1897 ( int2shr PGUID 12 f t t t 2 f 21 "21 23" 100 0 0 100 int2shr - ));
2527+
DESCR("binary shift right");
2528+
2529+
DATA(insert OID = 1898 ( int4and PGUID 12 f t t t 2 f 23 "23 23" 100 0 0 100 int4and - ));
2530+
DESCR("binary and");
2531+
DATA(insert OID = 1899 ( int4or PGUID 12 f t t t 2 f 23 "23 23" 100 0 0 100 int4or - ));
2532+
DESCR("binary or");
2533+
DATA(insert OID = 1900 ( int4xor PGUID 12 f t t t 2 f 23 "23 23" 100 0 0 100 int4xor - ));
2534+
DESCR("binary xor");
2535+
DATA(insert OID = 1901 ( int4not PGUID 12 f t t t 1 f 23 "23" 100 0 0 100 int4not - ));
2536+
DESCR("binary not");
2537+
DATA(insert OID = 1902 ( int4shl PGUID 12 f t t t 2 f 23 "23 23" 100 0 0 100 int4shl - ));
2538+
DESCR("binary shift left");
2539+
DATA(insert OID = 1903 ( int4shr PGUID 12 f t t t 2 f 23 "23 23" 100 0 0 100 int4shr - ));
2540+
DESCR("binary shift right");
2541+
2542+
DATA(insert OID = 1904 ( int8and PGUID 12 f t t t 2 f 20 "20 20" 100 0 0 100 int8and - ));
2543+
DESCR("binary and");
2544+
DATA(insert OID = 1905 ( int8or PGUID 12 f t t t 2 f 20 "20 20" 100 0 0 100 int8or - ));
2545+
DESCR("binary or");
2546+
DATA(insert OID = 1906 ( int8xor PGUID 12 f t t t 2 f 20 "20 20" 100 0 0 100 int8xor - ));
2547+
DESCR("binary xor");
2548+
DATA(insert OID = 1907 ( int8not PGUID 12 f t t t 1 f 20 "20" 100 0 0 100 int8not - ));
2549+
DESCR("binary not");
2550+
DATA(insert OID = 1908 ( int8shl PGUID 12 f t t t 2 f 20 "20 23" 100 0 0 100 int8shl - ));
2551+
DESCR("binary shift left");
2552+
DATA(insert OID = 1909 ( int8shr PGUID 12 f t t t 2 f 20 "20 23" 100 0 0 100 int8shr - ));
2553+
DESCR("binary shift right");
25162554

25172555
/*
25182556
* prototypes for functions pg_proc.c

src/include/utils/builtins.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: builtins.h,v 1.139 2000/09/25 16:36:36 tgl Exp $
10+
* $Id: builtins.h,v 1.140 2000/10/24 20:16:47 petere Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -127,6 +127,19 @@ extern Datum int2smaller(PG_FUNCTION_ARGS);
127127
extern Datum int4larger(PG_FUNCTION_ARGS);
128128
extern Datum int4smaller(PG_FUNCTION_ARGS);
129129

130+
extern Datum int4and(PG_FUNCTION_ARGS);
131+
extern Datum int4or(PG_FUNCTION_ARGS);
132+
extern Datum int4xor(PG_FUNCTION_ARGS);
133+
extern Datum int4not(PG_FUNCTION_ARGS);
134+
extern Datum int4shl(PG_FUNCTION_ARGS);
135+
extern Datum int4shr(PG_FUNCTION_ARGS);
136+
extern Datum int2and(PG_FUNCTION_ARGS);
137+
extern Datum int2or(PG_FUNCTION_ARGS);
138+
extern Datum int2xor(PG_FUNCTION_ARGS);
139+
extern Datum int2not(PG_FUNCTION_ARGS);
140+
extern Datum int2shl(PG_FUNCTION_ARGS);
141+
extern Datum int2shr(PG_FUNCTION_ARGS);
142+
130143
/* name.c */
131144
extern Datum namein(PG_FUNCTION_ARGS);
132145
extern Datum nameout(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy