From 5dde558ce60db1f8747bbf745d56bd9cd5f4c7b7 Mon Sep 17 00:00:00 2001 From: "Marc G. Fournier" Date: Wed, 12 Mar 1997 21:13:19 +0000 Subject: [PATCH] From: Dan McGuirk Subject: [HACKERS] linux/alpha patches These patches lay the groundwork for a Linux/Alpha port. The port doesn't actually work unless you tweak the linker to put all the pointers in the first 32 bits of the address space, but it's at least a start. It implements the test-and-set instruction in Alpha assembly, and also fixes a lot of pointer-to-integer conversions, which is probably good anyway. --- src/backend/optimizer/plan/createplan.c | 8 ++--- src/backend/optimizer/plan/initsplan.c | 6 ++-- src/backend/optimizer/util/plancat.c | 8 ++--- src/backend/storage/ipc/s_lock.c | 48 +++++++++++++++++++++++-- src/backend/storage/page/bufpage.c | 7 ++-- src/backend/tcop/fastpath.c | 4 +-- src/backend/utils/adt/float.c | 22 +++++++++++- src/backend/utils/adt/oid.c | 18 +++++----- src/backend/utils/error/elog.c | 5 +-- src/backend/utils/error/exc.c | 5 +-- src/include/nodes/pg_list.h | 22 ++++++++---- src/include/storage/ipc.h | 4 +-- src/include/utils/memutils.h | 9 +++-- 13 files changed, 123 insertions(+), 43 deletions(-) diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index 7d131d7371..463cc2448e 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.7 1997/01/10 20:17:56 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.8 1997/03/12 21:05:56 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -292,7 +292,7 @@ create_seqscan_node(Path *best_path, List *tlist, List *scan_clauses) if(temp == NULL) elog(WARN,"scanrelid is empty"); else - scan_relid = (Index)lfirst(temp); /* ??? who takes care of lnext? - ay */ + scan_relid = (Index)lfirsti(temp); /* ??? who takes care of lnext? - ay */ scan_node = make_seqscan(tlist, scan_clauses, scan_relid, @@ -640,10 +640,10 @@ fix_indxqual_references(Node *clause, Path *index_path) is_funcclause((Node*)get_leftop((Expr*)clause)) && ((Func*)((Expr*)get_leftop((Expr*)clause))->oper)->funcisindex){ Var *newvar = - makeVar((Index)lfirst(index_path->parent->relids), + makeVar((Index)lfirsti(index_path->parent->relids), 1, /* func indices have one key */ ((Func*)((Expr*)clause)->oper)->functype, - (Index)lfirst(index_path->parent->relids), + (Index)lfirsti(index_path->parent->relids), 0); return diff --git a/src/backend/optimizer/plan/initsplan.c b/src/backend/optimizer/plan/initsplan.c index f7ec544eee..cec015bb01 100644 --- a/src/backend/optimizer/plan/initsplan.c +++ b/src/backend/optimizer/plan/initsplan.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.3 1997/02/20 02:53:26 vadim Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.4 1997/03/12 21:05:59 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -256,8 +256,8 @@ add_join_clause_info_to_rels(Query *root, CInfo *clauseinfo, List *join_relids) foreach (rel, join_relids) { - if ( (int)lfirst(rel) != (int)lfirst(join_relid) ) - other_rels = lappendi (other_rels, lfirst(rel)); + if ( lfirsti(rel) != lfirsti(join_relid) ) + other_rels = lappendi (other_rels, lfirsti(rel)); } joininfo = diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index 371b121a0f..7a108578ed 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.3 1996/11/06 09:29:24 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.4 1997/03/12 21:06:14 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -267,12 +267,12 @@ index_selectivity(Oid indid, i = 0; foreach(xopno, opnos) { - opno_array[i++] = (int)lfirst(xopno); + opno_array[i++] = lfirsti(xopno); } i = 0; foreach(xattno,attnos) { - attno_array[i++] = (int)lfirst(xattno); + attno_array[i++] = lfirsti(xattno); } i = 0; @@ -282,7 +282,7 @@ index_selectivity(Oid indid, i = 0; foreach(flag,flags) { - flag_array[i++] = (int)lfirst(flag); + flag_array[i++] = lfirsti(flag); } IndexSelectivity(indid, diff --git a/src/backend/storage/ipc/s_lock.c b/src/backend/storage/ipc/s_lock.c index 079aaaf39f..539a7f9af4 100644 --- a/src/backend/storage/ipc/s_lock.c +++ b/src/backend/storage/ipc/s_lock.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/s_lock.c,v 1.11 1997/02/14 04:16:43 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/s_lock.c,v 1.12 1997/03/12 21:06:48 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -126,7 +126,7 @@ S_LOCK_FREE(slock_t *lock) * (see storage/ipc.h). */ -#if defined(alpha) +#if defined(alpha) && !defined(linuxalpha) void S_LOCK(slock_t *lock) @@ -409,4 +409,48 @@ S_INIT_LOCK(slock_t *lock) #endif /* NEED_I386_TAS_ASM */ +#if defined(linuxalpha) + +int +tas(slock_t *m) +{ + slock_t res; + __asm__(" ldq $0, %0 \n\ + bne $0, already_set \n\ + ldq_l $0, %0 \n\ + bne $0, already_set \n\ + or $31, 1, $0 \n\ + stq_c $0, %0 \n\ + beq $0, stqc_fail \n\ + success: bis $31, $31, %1 \n\ + mb \n\ + jmp $31, end \n\ + stqc_fail: or $31, 1, $0 \n\ + already_set: bis $0, $0, %1 \n\ + end: nop " : "=m" (*m), "=r" (res) :: "0" ); + return(res); +} + +void +S_LOCK(slock_t *lock) +{ + while (tas(lock)) + ; +} + +void +S_UNLOCK(slock_t *lock) +{ + __asm__("mb"); + *lock = 0; +} + +void +S_INIT_LOCK(slock_t *lock) +{ + S_UNLOCK(lock); +} + +#endif + #endif /* HAS_TEST_AND_SET */ diff --git a/src/backend/storage/page/bufpage.c b/src/backend/storage/page/bufpage.c index 703d960662..bf150a27b9 100644 --- a/src/backend/storage/page/bufpage.c +++ b/src/backend/storage/page/bufpage.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/page/bufpage.c,v 1.5 1996/11/24 04:41:29 bryanh Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/page/bufpage.c,v 1.6 1997/03/12 21:07:11 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -512,12 +512,13 @@ PageIndexTupleDeleteAdjustLinePointers(PageHeader phdr, Size size) { int i; + unsigned offset; /* location is an index into the page... */ - location -= (int) phdr; + offset = (unsigned)(location - (char *)phdr); for (i = PageGetMaxOffsetNumber((Page) phdr) - 1; i >= 0; i--) { - if (phdr->pd_linp[i].lp_off <= (unsigned) location) { + if (phdr->pd_linp[i].lp_off <= offset) { phdr->pd_linp[i].lp_off += size; } } diff --git a/src/backend/tcop/fastpath.c b/src/backend/tcop/fastpath.c index 611adb3a19..20951fa4cb 100644 --- a/src/backend/tcop/fastpath.c +++ b/src/backend/tcop/fastpath.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/tcop/fastpath.c,v 1.3 1996/11/08 05:59:26 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/tcop/fastpath.c,v 1.4 1997/03/12 21:07:50 scrappy Exp $ * * NOTES * This cruft is the server side of PQfn. @@ -93,7 +93,7 @@ SendFunctionResult(Oid fid, /* function id */ pq_putnchar("G", 1); if (retbyval) { /* by-value */ pq_putint(retlen, 4); - pq_putint((int)retval, retlen); + pq_putint((int)(Datum)retval, retlen); } else { /* by-reference ... */ if (retlen < 0) { /* ... varlena */ pq_putint(VARSIZE(retval) - VARHDRSZ, 4); diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c index 52fc5f98e3..509ce6ce6d 100644 --- a/src/backend/utils/adt/float.c +++ b/src/backend/utils/adt/float.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.12 1997/02/19 20:10:49 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.13 1997/03/12 21:09:11 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -100,6 +100,26 @@ extern double atof(const char *p); #define FLOAT8_MAX DBL_MAX #define FLOAT8_MIN DBL_MIN +/* + * if FLOAT8_MIN and FLOAT8_MAX are the limits of the range a + * double can store, then how are we ever going to wind up + * with something stored in a double that is outside those + * limits? (and similarly for FLOAT4_{MIN,MAX}/float.) + * doesn't make sense to me, and it causes a + * floating point exception on linuxalpha, so UNSAFE_FLOATS + * it is. + * (maybe someone wanted to allow for values other than DBL_MIN/ + * DBL_MAX for FLOAT8_MIN/FLOAT8_MAX?) + * --djm 12/12/96 + * according to Richard Henderson this is a known bug in gcc on + * the Alpha. might as well leave the workaround in + * until the distributions are updated. + * --djm 12/16/96 + */ +#if defined(linuxalpha) && !defined(UNSAFE_FLOATS) +#define UNSAFE_FLOATS +#endif + /* check to see if a float4 val is outside of the FLOAT4_MIN, FLOAT4_MAX bounds. diff --git a/src/backend/utils/adt/oid.c b/src/backend/utils/adt/oid.c index 7f5a05e5be..2ee6cb6545 100644 --- a/src/backend/utils/adt/oid.c +++ b/src/backend/utils/adt/oid.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.4 1997/01/10 20:19:45 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.5 1997/03/12 21:09:15 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -37,14 +37,14 @@ Oid *oid8in(char *oidString) return(NULL); result = (Oid (*)[]) palloc(sizeof(Oid [8])); if ((nums = sscanf(oidString, "%d%d%d%d%d%d%d%d", - *result, - *result + 1, - *result + 2, - *result + 3, - *result + 4, - *result + 5, - *result + 6, - *result + 7)) != 8) { + &(*result)[0], + &(*result)[1], + &(*result)[2], + &(*result)[3], + &(*result)[4], + &(*result)[5], + &(*result)[6], + &(*result)[7])) != 8) { do (*result)[nums++] = 0; while (nums < 8); diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 992fd7cb0f..77477ab222 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.12 1997/02/14 04:17:57 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.13 1997/03/12 21:10:53 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -49,7 +49,8 @@ elog(int lev, const char *fmt, ... ) extern int errno, sys_nerr; #if !defined(BSD44_derived) && \ !defined(bsdi) && \ - !defined(bsdi_2_1) + !defined(bsdi_2_1) && \ + !defined(linuxalpha) extern char *sys_errlist[]; #endif /* bsd derived */ #ifndef PG_STANDALONE diff --git a/src/backend/utils/error/exc.c b/src/backend/utils/error/exc.c index 1caa5bca93..9eae4ad109 100644 --- a/src/backend/utils/error/exc.c +++ b/src/backend/utils/error/exc.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/error/Attic/exc.c,v 1.9 1996/12/27 13:13:58 vadim Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/error/Attic/exc.c,v 1.10 1997/03/12 21:10:56 scrappy Exp $ * * NOTE * XXX this code needs improvement--check for state violations and @@ -95,7 +95,8 @@ ExcPrint(Exception *excP, extern int sys_nerr; #if !defined(BSD44_derived) && \ !defined(bsdi) && \ - !defined(bsdi_2_1) + !defined(bsdi_2_1) && \ + !defined(linuxalpha) extern char *sys_errlist[]; #endif /* ! bsd_derived */ diff --git a/src/include/nodes/pg_list.h b/src/include/nodes/pg_list.h index d3bf7c0de9..b67b31bb19 100644 --- a/src/include/nodes/pg_list.h +++ b/src/include/nodes/pg_list.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: pg_list.h,v 1.3 1996/11/04 07:18:19 scrappy Exp $ + * $Id: pg_list.h,v 1.4 1997/03/12 21:11:23 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -44,7 +44,10 @@ typedef struct Value { */ typedef struct List { NodeTag type; - void *elem; + union { + void *ptr_value; + int int_value; + } elem; struct List *next; } List; @@ -54,10 +57,15 @@ typedef struct List { * accessor macros * ---------------- */ -#define lfirst(l) ((l)->elem) + +/* anything that doesn't end in 'i' is assumed to be referring to the */ +/* pointer version of the list (where it makes a difference) */ +#define lfirst(l) ((l)->elem.ptr_value) #define lnext(l) ((l)->next) #define lsecond(l) (lfirst(lnext(l))) +#define lfirsti(l) ((l)->elem.int_value) + /* * foreach - * a convenience macro which loops through the list @@ -85,13 +93,13 @@ extern void freeList(List *list); extern void *nth(int n, List *l); extern void set_nth(List *l, int n, void *elem); -/* hack for now */ -#define lconsi(i,l) lcons((void*)(int)i,l) -#define lfirsti(l) ((int)lfirst(l)) -#define lappendi(l,i) lappend(l,(void*)i) +List *lconsi(int datum, List *list); +List *lappendi(List *list, int datum); extern bool intMember(int, List *); extern List *intAppend(List *list1, List *list2); +extern int nthi(int n, List *l); + extern List *nreverse(List *); extern List *set_difference(List *, List *); extern List *set_differencei(List *, List *); diff --git a/src/include/storage/ipc.h b/src/include/storage/ipc.h index 7cc11e0baf..d0f17b9227 100644 --- a/src/include/storage/ipc.h +++ b/src/include/storage/ipc.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: ipc.h,v 1.15 1997/03/03 23:34:27 scrappy Exp $ + * $Id: ipc.h,v 1.16 1997/03/12 21:12:27 scrappy Exp $ * * NOTES * This file is very architecture-specific. This stuff should actually @@ -32,7 +32,7 @@ extern void S_LOCK(slock_t *lock); extern void S_UNLOCK(slock_t *lock); extern void S_INIT_LOCK(slock_t *lock); -#if defined(alpha) || \ +#if (defined(alpha) && !defined(linuxalpha)) || \ defined(hpux) || \ defined(irix5) || \ defined(nextstep) diff --git a/src/include/utils/memutils.h b/src/include/utils/memutils.h index a6dad68b22..b6f013cdbe 100644 --- a/src/include/utils/memutils.h +++ b/src/include/utils/memutils.h @@ -15,7 +15,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: memutils.h,v 1.5 1997/03/04 05:32:26 scrappy Exp $ + * $Id: memutils.h,v 1.6 1997/03/12 21:13:19 scrappy Exp $ * * NOTES * some of the information in this file will be moved to @@ -67,7 +67,12 @@ s...) */ #if defined(sun) && ! defined(sparc) #define LONGALIGN(LEN) SHORTALIGN(LEN) -#elif defined (alpha) +#elif defined (alpha) || defined(linuxalpha) + /* even though "long alignment" should really be on 8-byte boundaries + * for linuxalpha, we want the strictest alignment to be on 4-byte (int) + * boundaries, because otherwise things break when they try to use the + * FormData_pg_* structures. --djm 12/12/96 + */ #define LONGALIGN(LEN)\ (((long)(LEN) + (sizeof (int) - 1)) & ~(sizeof (int) -1)) #else -- 2.40.0