Author: leo
Date: Wed Apr 27 07:15:59 2005
New Revision: 7932
Added:
trunk/include/parrot/pic.h
Modified:
trunk/MANIFEST
trunk/include/parrot/interpreter.h
trunk/include/parrot/packfile.h
trunk/include/parrot/parrot.h
trunk/src/pic.c
Log:
PIC 1 - structures and allocation
* new header pic.h
* storage and PIC structures
* allocation code
All not yet plugged into functionality.
Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST (original)
+++ trunk/MANIFEST Wed Apr 27 07:15:59 2005
@@ -749,6 +749,7 @@
include/parrot/packfile.h [devel]include
include/parrot/parrot.h [devel]include
include/parrot/perltypes.h [devel]include
+include/parrot/pic.h [devel]include
include/parrot/pmc.h [devel]include
include/parrot/pmc_freeze.h [devel]include
include/parrot/pobj.h [devel]include
Modified: trunk/include/parrot/interpreter.h
==============================================================================
--- trunk/include/parrot/interpreter.h (original)
+++ trunk/include/parrot/interpreter.h Wed Apr 27 07:15:59 2005
@@ -457,7 +457,6 @@
void enter_nci_method(Interp *, int type,
void *func, const char *name, const char *proto);
-void parrot_PIC_prederef(Interp *, opcode_t op, void **pc_pred, int type);
#else
Modified: trunk/include/parrot/packfile.h
==============================================================================
--- trunk/include/parrot/packfile.h (original)
+++ trunk/include/parrot/packfile.h Wed Apr 27 07:15:59 2005
@@ -172,6 +172,8 @@
struct PackFile_Segment base;
Prederef prederef; /* The predereferenced code and info */
void *jit_info; /* JITs data */
+ Parrot_PIC_store * pic_store; /* PIC storage */
+ struct PackFile_Segment * pic_index; /* segment of indices into store */
struct PackFile_ByteCode * prev; /* was executed previous */
struct PackFile_Debug * debugs;
struct PackFile_ConstTable *const_table;
Modified: trunk/include/parrot/parrot.h
==============================================================================
--- trunk/include/parrot/parrot.h (original)
+++ trunk/include/parrot/parrot.h Wed Apr 27 07:15:59 2005
@@ -248,6 +248,7 @@
#include "parrot/exceptions.h"
#include "parrot/warnings.h"
#include "parrot/memory.h"
+#include "parrot/pic.h"
#include "parrot/packfile.h"
#include "parrot/io.h"
#include "parrot/op.h"
Added: trunk/include/parrot/pic.h
==============================================================================
--- (empty file)
+++ trunk/include/parrot/pic.h Wed Apr 27 07:15:59 2005
@@ -0,0 +1,82 @@
+/* pic.h
+ * Copyright: 2005 The Perl Foundation. All Rights Reserved.
+ * CVS Info
+ * $Id$
+ * Overview:
+ * This is the api header for the pic subsystem
+ * Data Structure and Algorithms:
+ * History:
+ * Notes:
+ * References:
+ */
+
+#if !defined(PARROT_PIC_H_GUARD)
+#define PARROT_PIC_H_GUARD
+
+/*
+ * one cache slot
+ *
+ * if types exceed 16 bits or for general MMD function calls an
+ * extended cache slot is needed with more type entries
+ */
+typedef struct Parrot_pic_lru_t {
+ INTVAL lr_type; /* for MMD left << 16 | right type */
+ union {
+ funcptr_t real_function; /* the actual C code */
+ PMC *sub; /* or a Sub PMC */
+ PMC **pattr; /* attribute location */
+ } f;
+} Parrot_PIC_lru;
+
+/*
+ * PIC 3 more cache slots
+ */
+typedef struct Parrot_pic_t {
+ Parrot_PIC_lru lru[3]; /* PIC - three more cache entries */
+ INTVAL miss_count; /* how many misses */
+} Parrot_PIC;
+
+/*
+ * the main used MIC one cache slot - 4 words size
+ */
+typedef struct Parrot_mic_t {
+ Parrot_PIC_lru lru; /* MIC - one cache */
+ union {
+ STRING *method; /* for callmethod */
+ INTVAL func_nr; /* MMD function number */
+ STRING *attribute; /* obj.attribute */
+ } m;
+ Parrot_PIC *pic; /* more cache entries */
+} Parrot_MIC;
+
+/*
+ * memory is managed by this structure hanging off a
+ * PackFile_ByteCode segment
+ */
+typedef struct Parrot_pic_store_t {
+ struct Parrot_pic_store_t *prev; /* prev pic_store */
+ size_t usable; /* size of usable memory: */
+ Parrot_PIC *pic; /* from rear */
+ Parrot_MIC **mic; /* idx access to allocated MICs */
+ size_t n_mics; /* range check, debugging mainly */
+} Parrot_PIC_store;
+
+/* more or less private interfaces */
+void parrot_PIC_prederef(Interp *, opcode_t op, void **pc_pred, int type);
+void parrot_PIC_alloc_store(Interp *, struct PackFile_ByteCode *, size_t n);
+void parrot_PIC_destroy(Interp *, struct PackFile_ByteCode *);
+int parrot_PIC_op_is_cached(Interp *, int op_code);
+Parrot_MIC* parrot_PIC_alloc_mic(Interp*, size_t n);
+Parrot_PIC* parrot_PIC_alloc_pic(Interp*);
+
+#endif /* PARROT_PIC_H_GUARD */
+
+/*
+ * Local variables:
+ * c-indentation-style: bsd
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vim: expandtab shiftwidth=4:
+*/
Modified: trunk/src/pic.c
==============================================================================
--- trunk/src/pic.c (original)
+++ trunk/src/pic.c Wed Apr 27 07:15:59 2005
@@ -12,6 +12,12 @@
prederefed run cores. Additionally opcodes that do some kind of lookup
like C<new_p_sc> are changed to faster variants.
+TODO For non-prederefed run-cores there's a less efficient variant which
+is basically:
+
+ * the bytecode segment has an index per cached opcode
+ * this index points into pic_store
+
=head2 Functions
=over 4
@@ -28,6 +34,130 @@
/*
+=item C<void parrot_PIC_alloc_store(Interp *, struct PackFile_ByteCode *,
size_t n);>
+
+Initialize the PIC storage for the given code segment with the capacitiy of
+holding at least C<n> MIC entries. The PIC_store itself, room for C<n> MICs and
+some space for PICs is allocated as one piece. MICs are returned from the start
+of usable memory, PICs from the rear.
+
+=item C<void parrot_PIC_destroy(Interp *, struct PackFile_ByteCode *);>
+
+Free memory for the PIC storage.
+
+=cut
+
+*/
+
+void
+parrot_PIC_alloc_store(Interp *interpreter,
+ struct PackFile_ByteCode *cs, size_t n)
+{
+ size_t size, poly;
+ Parrot_PIC_store *store;
+
+ /*
+ * estimated 95% of calls are monomorphic, 5% are polymorphic
+ * we need therefore:
+ */
+#define POLYMORPHIC 0.05
+
+ poly = (size_t)(n * POLYMORPHIC) * sizeof(Parrot_PIC);
+ if (!poly)
+ poly = 2 * sizeof(Parrot_PIC);
+ size = n * sizeof(Parrot_MIC) + poly + sizeof(Parrot_PIC_store);
+
+ store = mem_sys_allocate_zeroed(size);
+ SET_NULL_P(store->prev, Parrot_PIC_store*);
+ cs->pic_store = store;
+
+ store->pic = (Parrot_PIC*)((char *)store + size);
+ store->usable = poly;
+ store->mic = (Parrot_MIC**)((char*)store + sizeof(Parrot_PIC_store));
+ store->n_mics = n;
+}
+
+void
+parrot_PIC_destroy(Interp *interpreter, struct PackFile_ByteCode *cs)
+{
+ Parrot_PIC_store *store, *prev;
+
+ for (store = cs->pic_store; store; ) {
+ prev = store->prev;
+ mem_sys_free(store);
+ store = prev;
+ }
+ cs->pic_store = NULL;
+}
+
+/*
+
+=item C<int parrot_PIC_op_is_cached(Interp *, int op_code);>
+
+Return true, if the opcode needs a PIC slot.
+
+*/
+
+int
+parrot_PIC_op_is_cached(Interp *interpreter, int op_code)
+{
+ return 0;
+}
+/*
+
+=item C<Parrot_MIC* parrot_PIC_alloc_mic(Interp*, size_t n);>
+
+=item C<Parrot_MIC* parrot_PIC_alloc_pic(Interp*);>
+
+Allocate a new PIC or MIC structure for the C<n>th cached opcode in this
+bytecode segement.
+
+=cut
+
+*/
+
+Parrot_MIC*
+parrot_PIC_alloc_mic(Interp*interpreter, size_t n)
+{
+ Parrot_PIC_store *store;
+
+ store = interpreter->code->pic_store;
+ assert(n < store->n_mics);
+ return store->mic[n];
+}
+
+Parrot_PIC*
+parrot_PIC_alloc_pic(Interp* interpreter)
+{
+ Parrot_PIC_store *store, *new_store;
+ size_t size;
+
+ store = interpreter->code->pic_store;
+ if (store->usable < sizeof(Parrot_PIC)) {
+ size = (size_t)(store->n_mics * POLYMORPHIC) * sizeof(Parrot_PIC);
+ if (size == 0)
+ size = 2 * sizeof(Parrot_PIC);
+ new_store = mem_sys_allocate_zeroed(size + sizeof(Parrot_PIC_store));
+ new_store->prev = store;
+ interpreter->code->pic_store = new_store;
+
+ new_store->pic = (Parrot_PIC*)((char *)new_store + size +
+ sizeof(Parrot_PIC_store));
+ new_store->usable = size;
+ /*
+ * the addon store has only poly-morphic slots
+ * point the monomorphic to the old store
+ */
+ new_store->mic = store->mic;
+ new_store->n_mics = store->n_mics;
+ store = new_store;
+ }
+ store->usable -= sizeof(Parrot_PIC);
+ return --store->pic;
+}
+
+/*
+
=item C<void parrot_PIC_prederef(Interp *, opcode_t op, void **pc_pred, int
type)>
Define either the normal prederef function or the PIC stub, if PIC for
@@ -96,7 +226,8 @@
=head1 SEE ALSO
-F<src/mmd.c>, F<src/object.c>, F<src/interpreter.c>, F<ops/core_ops_cgp.c>
+F<src/mmd.c>, F<src/object.c>, F<src/interpreter.c>, F<ops/core_ops_cgp.c>,
+F<include/parrot/pic.h>
=cut