Handbook
Glossary
rewrite ( insn -- insn/f )
Vocabulary
compiler
.
cfg
.
gvn
.
rewrite
Inputs
insn
an
object
Outputs
insn/f
an
object
Definition
IN:
compiler.cfg.gvn.rewrite
GENERIC:
rewrite
( insn -- insn/f )
Methods
USING:
accessors
combinators
compiler.cfg.gvn.avail
compiler.cfg.gvn.folding
compiler.cfg.gvn.graph
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##add-imm
rewrite
{
{
[
dup
src2>>
0
=
]
[
identity
]
}
{
[
dup
binary-constant-fold?
]
[
binary-constant-fold
]
}
{
[
dup
src1>>
vreg>insn
[
##add-imm?
]
with-available-uses?
]
[
##add-imm
reassociate-arithmetic
]
}
[
drop
f
]
}
cond
;
USING:
accessors
combinators
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##add
rewrite
{
{
[
dup
src2>>
vreg-immediate-arithmetic?
]
[
##add-imm
f
insn>imm-insn
]
}
{
[
dup
src1>>
vreg-immediate-arithmetic?
]
[
##add-imm
t
insn>imm-insn
]
}
[
drop
f
]
}
cond
;
USING:
accessors
combinators
compiler.cfg.gvn.avail
compiler.cfg.gvn.folding
compiler.cfg.gvn.graph
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##and-imm
rewrite
{
{
[
dup
binary-constant-fold?
]
[
binary-constant-fold
]
}
{
[
dup
src1>>
vreg>insn
[
##and-imm?
]
with-available-uses?
]
[
##and-imm
reassociate-bitwise
]
}
{
[
dup
src2>>
0
=
]
[
dst>>
0
##load-integer
new-insn
]
}
{
[
dup
src2>>
-1
=
]
[
identity
]
}
[
drop
f
]
}
cond
;
USING:
accessors
combinators
compiler.cfg.gvn.graph
compiler.cfg.gvn.rewrite
compiler.cfg.gvn.simd
compiler.cfg.instructions
kernel
;
M:
##and-vector
rewrite
{
{
[
dup
src1>>
vreg>insn
vector-not?
]
[
{
[
dst>>
]
[
src1>>
vreg>insn
vector-not-src
]
[
src2>>
]
[
rep>>
]
}
cleave
##andn-vector
new-insn
]
}
{
[
dup
src2>>
vreg>insn
vector-not?
]
[
{
[
dst>>
]
[
src2>>
vreg>insn
vector-not-src
]
[
src1>>
]
[
rep>>
]
}
cleave
##andn-vector
new-insn
]
}
[
drop
f
]
}
cond
;
USING:
accessors
combinators
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##and
rewrite
{
{
[
dup
diagonal?
]
[
identity
]
}
{
[
dup
src2>>
vreg-immediate-bitwise?
]
[
##and-imm
f
insn>imm-insn
]
}
{
[
dup
src1>>
vreg-immediate-bitwise?
]
[
##and-imm
t
insn>imm-insn
]
}
[
drop
f
]
}
cond
;
USING:
accessors
combinators
compiler.cfg.gvn.graph
compiler.cfg.gvn.rewrite
compiler.cfg.gvn.simd
compiler.cfg.instructions
kernel
;
M:
##andn-vector
rewrite
dup
src1>>
vreg>insn
vector-not?
[
{
[
dst>>
]
[
src1>>
vreg>insn
vector-not-src
]
[
src2>>
]
[
rep>>
]
}
cleave
##and-vector
new-insn
]
[
drop
f
]
if
;
USING:
accessors
compiler.cfg.gvn.graph
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
compiler.cfg.utilities
kernel
;
M:
##box-displaced-alien
rewrite
dup
displacement>>
vreg>insn
zero-insn?
[
[
dst>>
]
[
base>>
]
bi
<copy>
]
[
drop
f
]
if
;
USING:
accessors
combinators
compiler.cfg.gvn.comparisons
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##compare-branch
rewrite
{
{
[
dup
src1>>
vreg-immediate-comparand?
]
[
t
>compare-imm-branch
]
}
{
[
dup
src2>>
vreg-immediate-comparand?
]
[
f
>compare-imm-branch
]
}
{
[
dup
diagonal?
]
[
rewrite-self-compare-branch
]
}
[
drop
f
]
}
cond
;
USING:
combinators
compiler.cfg.gvn.comparisons
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##compare-imm-branch
rewrite
{
{
[
dup
rewrite-boolean-comparison?
]
[
rewrite-boolean-comparison
]
}
{
[
dup
fold-compare-imm?
]
[
fold-compare-imm-branch
]
}
[
drop
f
]
}
cond
;
USING:
combinators
compiler.cfg.gvn.comparisons
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##compare-imm
rewrite
{
{
[
dup
rewrite-redundant-comparison?
]
[
rewrite-redundant-comparison
]
}
{
[
dup
fold-compare-imm?
]
[
fold-compare-imm
]
}
[
drop
f
]
}
cond
;
USING:
accessors
combinators
compiler.cfg.gvn.comparisons
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##compare-integer-branch
rewrite
{
{
[
dup
src1>>
vreg-immediate-arithmetic?
]
[
t
>compare-integer-imm-branch
]
}
{
[
dup
src2>>
vreg-immediate-arithmetic?
]
[
f
>compare-integer-imm-branch
]
}
{
[
dup
diagonal?
]
[
rewrite-self-compare-branch
]
}
[
drop
f
]
}
cond
;
USING:
combinators
compiler.cfg.gvn.comparisons
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##compare-integer-imm-branch
rewrite
{
{
[
dup
fold-compare-integer-imm?
]
[
fold-compare-integer-imm-branch
]
}
{
[
dup
rewrite-into-test?
]
[
>test-branch
]
}
[
drop
f
]
}
cond
;
USING:
combinators
compiler.cfg.gvn.comparisons
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##compare-integer-imm
rewrite
{
{
[
dup
fold-compare-integer-imm?
]
[
fold-compare-integer-imm
]
}
{
[
dup
rewrite-into-test?
]
[
>test
]
}
[
drop
f
]
}
cond
;
USING:
accessors
combinators
compiler.cfg.gvn.comparisons
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##compare-integer
rewrite
{
{
[
dup
src1>>
vreg-immediate-arithmetic?
]
[
t
>compare-integer-imm
]
}
{
[
dup
src2>>
vreg-immediate-arithmetic?
]
[
f
>compare-integer-imm
]
}
{
[
dup
diagonal?
]
[
rewrite-self-compare
]
}
[
drop
f
]
}
cond
;
USING:
accessors
combinators
compiler.cfg.gvn.comparisons
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##compare
rewrite
{
{
[
dup
src1>>
vreg-immediate-comparand?
]
[
t
>compare-imm
]
}
{
[
dup
src2>>
vreg-immediate-comparand?
]
[
f
>compare-imm
]
}
{
[
dup
diagonal?
]
[
rewrite-self-compare
]
}
[
drop
f
]
}
cond
;
USING:
compiler.cfg.gvn.rewrite
compiler.cfg.gvn.simd
compiler.cfg.instructions
;
M:
##gather-int-vector-2
rewrite
rewrite-gather-vector-2
;
USING:
compiler.cfg.gvn.rewrite
compiler.cfg.gvn.simd
compiler.cfg.instructions
;
M:
##gather-int-vector-4
rewrite
rewrite-gather-vector-4
;
USING:
compiler.cfg.gvn.rewrite
compiler.cfg.gvn.simd
compiler.cfg.instructions
;
M:
##gather-vector-2
rewrite
rewrite-gather-vector-2
;
USING:
compiler.cfg.gvn.rewrite
compiler.cfg.gvn.simd
compiler.cfg.instructions
;
M:
##gather-vector-4
rewrite
rewrite-gather-vector-4
;
USING:
compiler.cfg.gvn.alien
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
;
M:
##load-memory-imm
rewrite
rewrite-memory-imm-op
;
USING:
compiler.cfg.gvn.alien
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
;
M:
##load-memory
rewrite
rewrite-memory-op
;
USING:
accessors
combinators
compiler.cfg.gvn.avail
compiler.cfg.gvn.folding
compiler.cfg.gvn.graph
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##mul-imm
rewrite
{
{
[
dup
binary-constant-fold?
]
[
binary-constant-fold
]
}
{
[
dup
mul-to-neg?
]
[
mul-to-neg
]
}
{
[
dup
mul-to-shl?
]
[
mul-to-shl
]
}
{
[
dup
src1>>
vreg>insn
[
##mul-imm?
]
with-available-uses?
]
[
##mul-imm
reassociate-arithmetic
]
}
{
[
dup
distribute-over-add?
]
[
\
##add-imm,
\
##mul-imm,
distribute
]
}
{
[
dup
distribute-over-sub?
]
[
\
##sub-imm,
\
##mul-imm,
distribute
]
}
[
drop
f
]
}
cond
;
USING:
accessors
combinators
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##mul
rewrite
{
{
[
dup
src2>>
vreg-immediate-arithmetic?
]
[
##mul-imm
f
insn>imm-insn
]
}
{
[
dup
src1>>
vreg-immediate-arithmetic?
]
[
##mul-imm
t
insn>imm-insn
]
}
[
drop
f
]
}
cond
;
USING:
combinators
compiler.cfg.gvn.folding
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##neg
rewrite
{
{
[
dup
[
##neg?
]
self-inverse?
]
[
self-inverse
]
}
{
[
dup
unary-constant-fold?
]
[
unary-constant-fold
]
}
[
drop
f
]
}
cond
;
USING:
combinators
compiler.cfg.gvn.folding
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##not
rewrite
{
{
[
dup
[
##not?
]
self-inverse?
]
[
self-inverse
]
}
{
[
dup
unary-constant-fold?
]
[
unary-constant-fold
]
}
[
drop
f
]
}
cond
;
USING:
accessors
combinators
compiler.cfg.gvn.avail
compiler.cfg.gvn.folding
compiler.cfg.gvn.graph
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##or-imm
rewrite
{
{
[
dup
src2>>
0
=
]
[
identity
]
}
{
[
dup
src2>>
-1
=
]
[
dst>>
-1
##load-integer
new-insn
]
}
{
[
dup
binary-constant-fold?
]
[
binary-constant-fold
]
}
{
[
dup
src1>>
vreg>insn
[
##or-imm?
]
with-available-uses?
]
[
##or-imm
reassociate-bitwise
]
}
[
drop
f
]
}
cond
;
USING:
accessors
combinators
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##or
rewrite
{
{
[
dup
diagonal?
]
[
identity
]
}
{
[
dup
src2>>
vreg-immediate-bitwise?
]
[
##or-imm
f
insn>imm-insn
]
}
{
[
dup
src1>>
vreg-immediate-bitwise?
]
[
##or-imm
t
insn>imm-insn
]
}
[
drop
f
]
}
cond
;
USING:
accessors
compiler.cfg.gvn.graph
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
cpu.architecture
kernel
;
M:
##replace
rewrite
[
loc>>
]
[
src>>
vreg>insn
]
bi
dup
literal-insn?
[
insn>literal
dup
immediate-store?
[
swap
##replace-imm
new-insn
]
[
2drop
f
]
if
]
[
2drop
f
]
if
;
USING:
accessors
combinators
compiler.cfg.gvn.avail
compiler.cfg.gvn.folding
compiler.cfg.gvn.graph
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##sar-imm
rewrite
{
{
[
dup
src2>>
0
=
]
[
identity
]
}
{
[
dup
binary-constant-fold?
]
[
binary-constant-fold
]
}
{
[
dup
src1>>
vreg>insn
[
##sar-imm?
]
with-available-uses?
]
[
##sar-imm
reassociate-shift
]
}
[
drop
f
]
}
cond
;
USING:
accessors
combinators
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##sar
rewrite
{
{
[
dup
src2>>
vreg-immediate-bitwise?
]
[
##sar-imm
f
insn>imm-insn
]
}
[
drop
f
]
}
cond
;
USING:
accessors
combinators
compiler.cfg.gvn.avail
compiler.cfg.gvn.graph
compiler.cfg.gvn.rewrite
compiler.cfg.gvn.simd
compiler.cfg.instructions
compiler.cfg.utilities
kernel
;
M:
##scalar>vector
rewrite
dup
src>>
vreg>insn
{
{
[
dup
literal-insn?
]
[
fold-scalar>vector
]
}
{
[
dup
[
##vector>scalar?
]
with-available-uses?
]
[
[
dst>>
]
[
src>>
]
bi*
<copy>
]
}
[
2drop
f
]
}
cond
;
USING:
compiler.cfg.gvn.rewrite
compiler.cfg.gvn.slots
compiler.cfg.instructions
;
M:
##set-slot
rewrite
simplify-slot-addressing
;
USING:
accessors
combinators
compiler.cfg.gvn.avail
compiler.cfg.gvn.folding
compiler.cfg.gvn.graph
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##shl-imm
rewrite
{
{
[
dup
src2>>
0
=
]
[
identity
]
}
{
[
dup
binary-constant-fold?
]
[
binary-constant-fold
]
}
{
[
dup
src1>>
vreg>insn
[
##shl-imm?
]
with-available-uses?
]
[
##shl-imm
reassociate-shift
]
}
{
[
dup
distribute-over-add?
]
[
\
##add-imm,
\
##shl-imm,
distribute
]
}
{
[
dup
distribute-over-sub?
]
[
\
##sub-imm,
\
##shl-imm,
distribute
]
}
[
drop
f
]
}
cond
;
USING:
accessors
combinators
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##shl
rewrite
{
{
[
dup
src2>>
vreg-immediate-bitwise?
]
[
##shl-imm
f
insn>imm-insn
]
}
[
drop
f
]
}
cond
;
USING:
accessors
combinators
compiler.cfg.gvn.avail
compiler.cfg.gvn.folding
compiler.cfg.gvn.graph
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##shr-imm
rewrite
{
{
[
dup
src2>>
0
=
]
[
identity
]
}
{
[
dup
binary-constant-fold?
]
[
binary-constant-fold
]
}
{
[
dup
src1>>
vreg>insn
[
##shr-imm?
]
with-available-uses?
]
[
##shr-imm
reassociate-shift
]
}
[
drop
f
]
}
cond
;
USING:
accessors
combinators
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##shr
rewrite
{
{
[
dup
src2>>
vreg-immediate-bitwise?
]
[
##shr-imm
f
insn>imm-insn
]
}
[
drop
f
]
}
cond
;
USING:
accessors
combinators
compiler.cfg.gvn.avail
compiler.cfg.gvn.graph
compiler.cfg.gvn.rewrite
compiler.cfg.gvn.simd
compiler.cfg.instructions
compiler.cfg.utilities
kernel
;
M:
##shuffle-vector-imm
rewrite
dup
src>>
vreg>insn
{
{
[
over
useless-shuffle-vector-imm?
]
[
drop
[
dst>>
]
[
src>>
]
bi
<copy>
]
}
{
[
dup
[
##shuffle-vector-imm?
]
with-available-uses?
]
[
compose-shuffle-vector-imm
]
}
{
[
dup
##load-reference?
]
[
fold-shuffle-vector-imm
]
}
[
2drop
f
]
}
cond
;
USING:
accessors
combinators
compiler.cfg.gvn.graph
compiler.cfg.gvn.rewrite
compiler.cfg.gvn.simd
compiler.cfg.instructions
kernel
;
M:
##shuffle-vector
rewrite
dup
[
src>>
vreg>insn
]
[
shuffle>>
vreg>insn
]
bi
{
{
[
2dup
[
##load-reference?
]
both?
]
[
fold-shuffle-vector
]
}
[
3drop
f
]
}
cond
;
USING:
compiler.cfg.gvn.rewrite
compiler.cfg.gvn.slots
compiler.cfg.instructions
;
M:
##slot
rewrite
simplify-slot-addressing
;
USING:
compiler.cfg.gvn.alien
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
;
M:
##store-memory-imm
rewrite
rewrite-memory-imm-op
;
USING:
compiler.cfg.gvn.alien
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
;
M:
##store-memory
rewrite
rewrite-memory-op
;
USING:
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
;
M:
##sub-imm
rewrite
sub-imm>add-imm
;
USING:
accessors
combinators
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##sub
rewrite
{
{
[
dup
sub-to-neg?
]
[
sub-to-neg
]
}
{
[
dup
diagonal?
]
[
rewrite-subtraction-identity
]
}
{
[
dup
src2>>
vreg-immediate-arithmetic?
]
[
##sub-imm
f
insn>imm-insn
]
}
[
drop
f
]
}
cond
;
USING:
accessors
combinators
compiler.cfg.gvn.graph
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
layouts
;
M:
##tagged>integer
rewrite
[
dst>>
]
[
src>>
vreg>insn
]
bi
{
{
[
dup
##load-integer?
]
[
val>>
tag-fixnum
##load-integer
new-insn
]
}
{
[
dup
f-insn?
]
[
drop
\
f
type-number
##load-integer
new-insn
]
}
[
2drop
f
]
}
cond
;
USING:
accessors
combinators
compiler.cfg.gvn.comparisons
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##test-branch
rewrite
{
{
[
dup
src1>>
vreg-immediate-comparand?
]
[
t
>test-imm-branch
]
}
{
[
dup
src2>>
vreg-immediate-comparand?
]
[
f
>test-imm-branch
]
}
{
[
dup
diagonal?
]
[
{
{
~quotation~ ~quotation~
}
{
~quotation~ ~quotation~
}
[
drop
f
]
}
cond
]
}
[
drop
f
]
}
cond
;
USING:
combinators
compiler.cfg.gvn.comparisons
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##test-imm-branch
rewrite
{
{
[
dup
fold-test-imm?
]
[
fold-test-imm-branch
]
}
[
drop
f
]
}
cond
;
USING:
combinators
compiler.cfg.gvn.comparisons
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##test-imm
rewrite
{
{
[
dup
fold-test-imm?
]
[
fold-test-imm
]
}
[
drop
f
]
}
cond
;
USING:
accessors
combinators
compiler.cfg.gvn.comparisons
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##test
rewrite
{
{
[
dup
src1>>
vreg-immediate-comparand?
]
[
t
>test-imm
]
}
{
[
dup
src2>>
vreg-immediate-comparand?
]
[
f
>test-imm
]
}
{
[
dup
diagonal?
]
[
{
{
~quotation~ ~quotation~
}
{
~quotation~ ~quotation~
}
[
drop
f
]
}
cond
]
}
[
drop
f
]
}
cond
;
USING:
compiler.cfg.gvn.alien
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
;
M:
##unbox-alien
rewrite
rewrite-unbox-any-c-ptr
;
USING:
compiler.cfg.gvn.alien
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
;
M:
##unbox-any-c-ptr
rewrite
rewrite-unbox-any-c-ptr
;
USING:
compiler.cfg.gvn.rewrite
compiler.cfg.gvn.slots
compiler.cfg.instructions
;
M:
##write-barrier
rewrite
simplify-slot-addressing
;
USING:
accessors
combinators
compiler.cfg.gvn.avail
compiler.cfg.gvn.folding
compiler.cfg.gvn.graph
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##xor-imm
rewrite
{
{
[
dup
src2>>
0
=
]
[
identity
]
}
{
[
dup
src2>>
-1
=
]
[
[
dst>>
]
[
src1>>
]
bi
##not
new-insn
]
}
{
[
dup
binary-constant-fold?
]
[
binary-constant-fold
]
}
{
[
dup
src1>>
vreg>insn
[
##xor-imm?
]
with-available-uses?
]
[
##xor-imm
reassociate-bitwise
]
}
[
drop
f
]
}
cond
;
USING:
accessors
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##xor-vector
rewrite
dup
diagonal?
[
[
dst>>
]
[
rep>>
]
bi
##zero-vector
new-insn
]
[
drop
f
]
if
;
USING:
accessors
combinators
compiler.cfg.gvn.math
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
##xor
rewrite
{
{
[
dup
diagonal?
]
[
dst>>
0
##load-integer
new-insn
]
}
{
[
dup
src2>>
vreg-immediate-bitwise?
]
[
##xor-imm
f
insn>imm-insn
]
}
{
[
dup
src1>>
vreg-immediate-bitwise?
]
[
##xor-imm
t
insn>imm-insn
]
}
[
drop
f
]
}
cond
;
USING:
compiler.cfg.gvn.rewrite
compiler.cfg.instructions
kernel
;
M:
insn
rewrite
drop
f
;