diff options
author | David Mitchell <davem@iabyn.com> | 2014-10-24 16:26:38 +0100 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2014-12-07 09:24:55 +0000 |
commit | fedf30e1c349130b23648c022f5f3cb4ad7928f3 (patch) | |
tree | 59634b92647baec7686f67156a199f0f33ef19bb /opnames.h | |
parent | 2f7c6295c991839e20b09fbf3107b861d511de31 (diff) | |
download | perl-fedf30e1c349130b23648c022f5f3cb4ad7928f3.tar.gz |
Add OP_MULTIDEREF
This op is an optimisation for any series of one or more array or hash
lookups and dereferences, where the key/index is a simple constant or
package/lexical variable. If the first-level lookup is of a simple
array/hash variable or scalar ref, then that is included in the op too.
So all of the following are replaced with a single op:
$h{foo}
$a[$i]
$a[5][$k][$i]
$r->{$k}
local $a[0][$i]
exists $a[$i]{$k}
delete $h{foo}
while these aren't:
$a[0] already handled by OP_AELEMFAST
$a[$x+1] not a simple index
and these are partially replaced:
(expr)->[0]{$k} the bit following (expr) is replaced
$h{foo}[$x+1][0] the first and third lookups are each done with
a multideref op, while the $x+1 expression and
middle lookup are done by existing add, aelem etc
ops.
Up until now, aggregate dereferencing has been very heavyweight in ops; for
example, $r->[0]{$x} is compiled as:
gv[*r] s
rv2sv sKM/DREFAV,1
rv2av[t2] sKR/1
const[IV 0] s
aelem sKM/DREFHV,2
rv2hv sKR/1
gvsv[*x] s
helem vK/2
When executing this, in addition to the actual calls to av_fetch() and
hv_fetch(), there is a lot of overhead of pushing SVs on and off the
stack, and calling lots of little pp() functions from the runops loop
(each with its potential indirect branch miss).
The multideref op avoids that by running all the code in a loop in a
switch statement. It makes use of the new UNOP_AUX type to hold an array
of
typedef union {
PADOFFSET pad_offset;
SV *sv;
IV iv;
UV uv;
} UNOP_AUX_item;
In something like $a[7][$i]{foo}, the GVs or pad offsets for @a and $i are
stored as items in the array, along with a pointer to a const SV holding
'foo', and the UV 7 is stored directly. Along with this, some UVs are used
to store a sequence of actions (several actions are squeezed into a single
UV).
Then the main body of pp_multideref is a big while loop round a switch,
which reads actions and values from the AUX array. The two big branches in
the switch are ones that are affectively unrolled (/DREFAV, rv2av, aelem)
and (/DREFHV, rv2hv, helem) triplets. The other branches are various entry
points that handle retrieving the different types of initial value; for
example 'my %h; $h{foo}' needs to get %h from the pad, while '(expr)->{foo}'
needs to pop expr off the stack.
Note that there is a slight complication with /DEREF; in the example above
of $r->[0]{$x}, the aelem op is actually
aelem sKM/DREFHV,2
which means that the aelem, after having retrieved a (possibly undef)
value from the array, is responsible for autovivifying it into a hash,
ready for the next op. Similarly, the rv2sv that retrieves $r from the
typeglob is responsible for autovivifying it into an AV. This action
of doing the next op's work for it complicates matters somewhat. Within
pp_multideref, the autovivification action is instead included as the
first step of the current action.
In terms of benchmarking with Porting/bench.pl, a simple lexical
$a[$i][$j] shows a reduction of approx 40% in numbers of instructions
executed, while $r->[0][0][0] uses 54% fewer. The speed-up for hash
accesses is relatively more modest, since the actual hash lookup (i.e.
hv_fetch()) is more expensive than an array lookup. A lexical $h{foo}
uses 10% fewer, while $r->{foo}{bar}{baz} uses 34% fewer instructions.
Overall,
bench.pl --tests='/expr::(array|hash)/' ...
gives:
PRE POST
------ ------
Ir 100.00 145.00
Dr 100.00 165.30
Dw 100.00 175.74
COND 100.00 132.02
IND 100.00 171.11
COND_m 100.00 127.65
IND_m 100.00 203.90
with cache misses unchanged at 100%.
In general, the more lookups done, the bigger the proportionate saving.
Diffstat (limited to 'opnames.h')
-rw-r--r-- | opnames.h | 485 |
1 files changed, 243 insertions, 242 deletions
@@ -159,251 +159,252 @@ typedef enum opcode { OP_HELEM = 142, OP_HSLICE = 143, OP_KVHSLICE = 144, - OP_UNPACK = 145, - OP_PACK = 146, - OP_SPLIT = 147, - OP_JOIN = 148, - OP_LIST = 149, - OP_LSLICE = 150, - OP_ANONLIST = 151, - OP_ANONHASH = 152, - OP_SPLICE = 153, - OP_PUSH = 154, - OP_POP = 155, - OP_SHIFT = 156, - OP_UNSHIFT = 157, - OP_SORT = 158, - OP_REVERSE = 159, - OP_GREPSTART = 160, - OP_GREPWHILE = 161, - OP_MAPSTART = 162, - OP_MAPWHILE = 163, - OP_RANGE = 164, - OP_FLIP = 165, - OP_FLOP = 166, - OP_AND = 167, - OP_OR = 168, - OP_XOR = 169, - OP_DOR = 170, - OP_COND_EXPR = 171, - OP_ANDASSIGN = 172, - OP_ORASSIGN = 173, - OP_DORASSIGN = 174, - OP_METHOD = 175, - OP_ENTERSUB = 176, - OP_LEAVESUB = 177, - OP_LEAVESUBLV = 178, - OP_CALLER = 179, - OP_WARN = 180, - OP_DIE = 181, - OP_RESET = 182, - OP_LINESEQ = 183, - OP_NEXTSTATE = 184, - OP_DBSTATE = 185, - OP_UNSTACK = 186, - OP_ENTER = 187, - OP_LEAVE = 188, - OP_SCOPE = 189, - OP_ENTERITER = 190, - OP_ITER = 191, - OP_ENTERLOOP = 192, - OP_LEAVELOOP = 193, - OP_RETURN = 194, - OP_LAST = 195, - OP_NEXT = 196, - OP_REDO = 197, - OP_DUMP = 198, - OP_GOTO = 199, - OP_EXIT = 200, - OP_METHOD_NAMED = 201, - OP_METHOD_SUPER = 202, - OP_METHOD_REDIR = 203, - OP_METHOD_REDIR_SUPER = 204, - OP_ENTERGIVEN = 205, - OP_LEAVEGIVEN = 206, - OP_ENTERWHEN = 207, - OP_LEAVEWHEN = 208, - OP_BREAK = 209, - OP_CONTINUE = 210, - OP_OPEN = 211, - OP_CLOSE = 212, - OP_PIPE_OP = 213, - OP_FILENO = 214, - OP_UMASK = 215, - OP_BINMODE = 216, - OP_TIE = 217, - OP_UNTIE = 218, - OP_TIED = 219, - OP_DBMOPEN = 220, - OP_DBMCLOSE = 221, - OP_SSELECT = 222, - OP_SELECT = 223, - OP_GETC = 224, - OP_READ = 225, - OP_ENTERWRITE = 226, - OP_LEAVEWRITE = 227, - OP_PRTF = 228, - OP_PRINT = 229, - OP_SAY = 230, - OP_SYSOPEN = 231, - OP_SYSSEEK = 232, - OP_SYSREAD = 233, - OP_SYSWRITE = 234, - OP_EOF = 235, - OP_TELL = 236, - OP_SEEK = 237, - OP_TRUNCATE = 238, - OP_FCNTL = 239, - OP_IOCTL = 240, - OP_FLOCK = 241, - OP_SEND = 242, - OP_RECV = 243, - OP_SOCKET = 244, - OP_SOCKPAIR = 245, - OP_BIND = 246, - OP_CONNECT = 247, - OP_LISTEN = 248, - OP_ACCEPT = 249, - OP_SHUTDOWN = 250, - OP_GSOCKOPT = 251, - OP_SSOCKOPT = 252, - OP_GETSOCKNAME = 253, - OP_GETPEERNAME = 254, - OP_LSTAT = 255, - OP_STAT = 256, - OP_FTRREAD = 257, - OP_FTRWRITE = 258, - OP_FTREXEC = 259, - OP_FTEREAD = 260, - OP_FTEWRITE = 261, - OP_FTEEXEC = 262, - OP_FTIS = 263, - OP_FTSIZE = 264, - OP_FTMTIME = 265, - OP_FTATIME = 266, - OP_FTCTIME = 267, - OP_FTROWNED = 268, - OP_FTEOWNED = 269, - OP_FTZERO = 270, - OP_FTSOCK = 271, - OP_FTCHR = 272, - OP_FTBLK = 273, - OP_FTFILE = 274, - OP_FTDIR = 275, - OP_FTPIPE = 276, - OP_FTSUID = 277, - OP_FTSGID = 278, - OP_FTSVTX = 279, - OP_FTLINK = 280, - OP_FTTTY = 281, - OP_FTTEXT = 282, - OP_FTBINARY = 283, - OP_CHDIR = 284, - OP_CHOWN = 285, - OP_CHROOT = 286, - OP_UNLINK = 287, - OP_CHMOD = 288, - OP_UTIME = 289, - OP_RENAME = 290, - OP_LINK = 291, - OP_SYMLINK = 292, - OP_READLINK = 293, - OP_MKDIR = 294, - OP_RMDIR = 295, - OP_OPEN_DIR = 296, - OP_READDIR = 297, - OP_TELLDIR = 298, - OP_SEEKDIR = 299, - OP_REWINDDIR = 300, - OP_CLOSEDIR = 301, - OP_FORK = 302, - OP_WAIT = 303, - OP_WAITPID = 304, - OP_SYSTEM = 305, - OP_EXEC = 306, - OP_KILL = 307, - OP_GETPPID = 308, - OP_GETPGRP = 309, - OP_SETPGRP = 310, - OP_GETPRIORITY = 311, - OP_SETPRIORITY = 312, - OP_TIME = 313, - OP_TMS = 314, - OP_LOCALTIME = 315, - OP_GMTIME = 316, - OP_ALARM = 317, - OP_SLEEP = 318, - OP_SHMGET = 319, - OP_SHMCTL = 320, - OP_SHMREAD = 321, - OP_SHMWRITE = 322, - OP_MSGGET = 323, - OP_MSGCTL = 324, - OP_MSGSND = 325, - OP_MSGRCV = 326, - OP_SEMOP = 327, - OP_SEMGET = 328, - OP_SEMCTL = 329, - OP_REQUIRE = 330, - OP_DOFILE = 331, - OP_HINTSEVAL = 332, - OP_ENTEREVAL = 333, - OP_LEAVEEVAL = 334, - OP_ENTERTRY = 335, - OP_LEAVETRY = 336, - OP_GHBYNAME = 337, - OP_GHBYADDR = 338, - OP_GHOSTENT = 339, - OP_GNBYNAME = 340, - OP_GNBYADDR = 341, - OP_GNETENT = 342, - OP_GPBYNAME = 343, - OP_GPBYNUMBER = 344, - OP_GPROTOENT = 345, - OP_GSBYNAME = 346, - OP_GSBYPORT = 347, - OP_GSERVENT = 348, - OP_SHOSTENT = 349, - OP_SNETENT = 350, - OP_SPROTOENT = 351, - OP_SSERVENT = 352, - OP_EHOSTENT = 353, - OP_ENETENT = 354, - OP_EPROTOENT = 355, - OP_ESERVENT = 356, - OP_GPWNAM = 357, - OP_GPWUID = 358, - OP_GPWENT = 359, - OP_SPWENT = 360, - OP_EPWENT = 361, - OP_GGRNAM = 362, - OP_GGRGID = 363, - OP_GGRENT = 364, - OP_SGRENT = 365, - OP_EGRENT = 366, - OP_GETLOGIN = 367, - OP_SYSCALL = 368, - OP_LOCK = 369, - OP_ONCE = 370, - OP_CUSTOM = 371, - OP_REACH = 372, - OP_RKEYS = 373, - OP_RVALUES = 374, - OP_COREARGS = 375, - OP_RUNCV = 376, - OP_FC = 377, - OP_PADCV = 378, - OP_INTROCV = 379, - OP_CLONECV = 380, - OP_PADRANGE = 381, - OP_REFASSIGN = 382, - OP_LVREF = 383, - OP_LVREFSLICE = 384, - OP_LVAVREF = 385, + OP_MULTIDEREF = 145, + OP_UNPACK = 146, + OP_PACK = 147, + OP_SPLIT = 148, + OP_JOIN = 149, + OP_LIST = 150, + OP_LSLICE = 151, + OP_ANONLIST = 152, + OP_ANONHASH = 153, + OP_SPLICE = 154, + OP_PUSH = 155, + OP_POP = 156, + OP_SHIFT = 157, + OP_UNSHIFT = 158, + OP_SORT = 159, + OP_REVERSE = 160, + OP_GREPSTART = 161, + OP_GREPWHILE = 162, + OP_MAPSTART = 163, + OP_MAPWHILE = 164, + OP_RANGE = 165, + OP_FLIP = 166, + OP_FLOP = 167, + OP_AND = 168, + OP_OR = 169, + OP_XOR = 170, + OP_DOR = 171, + OP_COND_EXPR = 172, + OP_ANDASSIGN = 173, + OP_ORASSIGN = 174, + OP_DORASSIGN = 175, + OP_METHOD = 176, + OP_ENTERSUB = 177, + OP_LEAVESUB = 178, + OP_LEAVESUBLV = 179, + OP_CALLER = 180, + OP_WARN = 181, + OP_DIE = 182, + OP_RESET = 183, + OP_LINESEQ = 184, + OP_NEXTSTATE = 185, + OP_DBSTATE = 186, + OP_UNSTACK = 187, + OP_ENTER = 188, + OP_LEAVE = 189, + OP_SCOPE = 190, + OP_ENTERITER = 191, + OP_ITER = 192, + OP_ENTERLOOP = 193, + OP_LEAVELOOP = 194, + OP_RETURN = 195, + OP_LAST = 196, + OP_NEXT = 197, + OP_REDO = 198, + OP_DUMP = 199, + OP_GOTO = 200, + OP_EXIT = 201, + OP_METHOD_NAMED = 202, + OP_METHOD_SUPER = 203, + OP_METHOD_REDIR = 204, + OP_METHOD_REDIR_SUPER = 205, + OP_ENTERGIVEN = 206, + OP_LEAVEGIVEN = 207, + OP_ENTERWHEN = 208, + OP_LEAVEWHEN = 209, + OP_BREAK = 210, + OP_CONTINUE = 211, + OP_OPEN = 212, + OP_CLOSE = 213, + OP_PIPE_OP = 214, + OP_FILENO = 215, + OP_UMASK = 216, + OP_BINMODE = 217, + OP_TIE = 218, + OP_UNTIE = 219, + OP_TIED = 220, + OP_DBMOPEN = 221, + OP_DBMCLOSE = 222, + OP_SSELECT = 223, + OP_SELECT = 224, + OP_GETC = 225, + OP_READ = 226, + OP_ENTERWRITE = 227, + OP_LEAVEWRITE = 228, + OP_PRTF = 229, + OP_PRINT = 230, + OP_SAY = 231, + OP_SYSOPEN = 232, + OP_SYSSEEK = 233, + OP_SYSREAD = 234, + OP_SYSWRITE = 235, + OP_EOF = 236, + OP_TELL = 237, + OP_SEEK = 238, + OP_TRUNCATE = 239, + OP_FCNTL = 240, + OP_IOCTL = 241, + OP_FLOCK = 242, + OP_SEND = 243, + OP_RECV = 244, + OP_SOCKET = 245, + OP_SOCKPAIR = 246, + OP_BIND = 247, + OP_CONNECT = 248, + OP_LISTEN = 249, + OP_ACCEPT = 250, + OP_SHUTDOWN = 251, + OP_GSOCKOPT = 252, + OP_SSOCKOPT = 253, + OP_GETSOCKNAME = 254, + OP_GETPEERNAME = 255, + OP_LSTAT = 256, + OP_STAT = 257, + OP_FTRREAD = 258, + OP_FTRWRITE = 259, + OP_FTREXEC = 260, + OP_FTEREAD = 261, + OP_FTEWRITE = 262, + OP_FTEEXEC = 263, + OP_FTIS = 264, + OP_FTSIZE = 265, + OP_FTMTIME = 266, + OP_FTATIME = 267, + OP_FTCTIME = 268, + OP_FTROWNED = 269, + OP_FTEOWNED = 270, + OP_FTZERO = 271, + OP_FTSOCK = 272, + OP_FTCHR = 273, + OP_FTBLK = 274, + OP_FTFILE = 275, + OP_FTDIR = 276, + OP_FTPIPE = 277, + OP_FTSUID = 278, + OP_FTSGID = 279, + OP_FTSVTX = 280, + OP_FTLINK = 281, + OP_FTTTY = 282, + OP_FTTEXT = 283, + OP_FTBINARY = 284, + OP_CHDIR = 285, + OP_CHOWN = 286, + OP_CHROOT = 287, + OP_UNLINK = 288, + OP_CHMOD = 289, + OP_UTIME = 290, + OP_RENAME = 291, + OP_LINK = 292, + OP_SYMLINK = 293, + OP_READLINK = 294, + OP_MKDIR = 295, + OP_RMDIR = 296, + OP_OPEN_DIR = 297, + OP_READDIR = 298, + OP_TELLDIR = 299, + OP_SEEKDIR = 300, + OP_REWINDDIR = 301, + OP_CLOSEDIR = 302, + OP_FORK = 303, + OP_WAIT = 304, + OP_WAITPID = 305, + OP_SYSTEM = 306, + OP_EXEC = 307, + OP_KILL = 308, + OP_GETPPID = 309, + OP_GETPGRP = 310, + OP_SETPGRP = 311, + OP_GETPRIORITY = 312, + OP_SETPRIORITY = 313, + OP_TIME = 314, + OP_TMS = 315, + OP_LOCALTIME = 316, + OP_GMTIME = 317, + OP_ALARM = 318, + OP_SLEEP = 319, + OP_SHMGET = 320, + OP_SHMCTL = 321, + OP_SHMREAD = 322, + OP_SHMWRITE = 323, + OP_MSGGET = 324, + OP_MSGCTL = 325, + OP_MSGSND = 326, + OP_MSGRCV = 327, + OP_SEMOP = 328, + OP_SEMGET = 329, + OP_SEMCTL = 330, + OP_REQUIRE = 331, + OP_DOFILE = 332, + OP_HINTSEVAL = 333, + OP_ENTEREVAL = 334, + OP_LEAVEEVAL = 335, + OP_ENTERTRY = 336, + OP_LEAVETRY = 337, + OP_GHBYNAME = 338, + OP_GHBYADDR = 339, + OP_GHOSTENT = 340, + OP_GNBYNAME = 341, + OP_GNBYADDR = 342, + OP_GNETENT = 343, + OP_GPBYNAME = 344, + OP_GPBYNUMBER = 345, + OP_GPROTOENT = 346, + OP_GSBYNAME = 347, + OP_GSBYPORT = 348, + OP_GSERVENT = 349, + OP_SHOSTENT = 350, + OP_SNETENT = 351, + OP_SPROTOENT = 352, + OP_SSERVENT = 353, + OP_EHOSTENT = 354, + OP_ENETENT = 355, + OP_EPROTOENT = 356, + OP_ESERVENT = 357, + OP_GPWNAM = 358, + OP_GPWUID = 359, + OP_GPWENT = 360, + OP_SPWENT = 361, + OP_EPWENT = 362, + OP_GGRNAM = 363, + OP_GGRGID = 364, + OP_GGRENT = 365, + OP_SGRENT = 366, + OP_EGRENT = 367, + OP_GETLOGIN = 368, + OP_SYSCALL = 369, + OP_LOCK = 370, + OP_ONCE = 371, + OP_CUSTOM = 372, + OP_REACH = 373, + OP_RKEYS = 374, + OP_RVALUES = 375, + OP_COREARGS = 376, + OP_RUNCV = 377, + OP_FC = 378, + OP_PADCV = 379, + OP_INTROCV = 380, + OP_CLONECV = 381, + OP_PADRANGE = 382, + OP_REFASSIGN = 383, + OP_LVREF = 384, + OP_LVREFSLICE = 385, + OP_LVAVREF = 386, OP_max } opcode; -#define MAXO 386 +#define MAXO 387 #define OP_FREED MAXO /* the OP_IS_* macros are optimized to a simple range check because |