2010-04-21 03:08:52 -04:00
|
|
|
! Copyright (C) 2008, 2010 Slava Pestov, Doug Coleman.
|
2008-10-20 21:40:15 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2014-12-13 19:10:21 -05:00
|
|
|
USING: assocs compiler.cfg.comparisons compiler.cfg.hats
|
|
|
|
compiler.cfg.intrinsics.alien compiler.cfg.intrinsics.allot
|
|
|
|
compiler.cfg.intrinsics.fixnum compiler.cfg.intrinsics.float
|
|
|
|
compiler.cfg.intrinsics.misc compiler.cfg.intrinsics.slots
|
|
|
|
compiler.cfg.intrinsics.strings compiler.cfg.stacks
|
|
|
|
cpu.architecture kernel words ;
|
2009-08-27 01:06:19 -04:00
|
|
|
QUALIFIED: alien
|
|
|
|
QUALIFIED: alien.accessors
|
2010-04-23 18:42:09 -04:00
|
|
|
QUALIFIED: alien.c-types
|
2014-12-13 19:10:21 -05:00
|
|
|
QUALIFIED: alien.data.private
|
2008-10-20 21:46:47 -04:00
|
|
|
QUALIFIED: arrays
|
|
|
|
QUALIFIED: byte-arrays
|
2008-10-20 21:40:15 -04:00
|
|
|
QUALIFIED: classes.tuple.private
|
2014-12-13 19:10:21 -05:00
|
|
|
QUALIFIED: kernel
|
|
|
|
QUALIFIED: kernel.private
|
2010-05-15 16:59:47 -04:00
|
|
|
QUALIFIED: math.bitwise.private
|
2009-08-28 06:21:16 -04:00
|
|
|
QUALIFIED: math.floats.private
|
2014-12-13 19:10:21 -05:00
|
|
|
QUALIFIED: math.integers.private
|
2009-08-26 00:22:15 -04:00
|
|
|
QUALIFIED: math.libm
|
2014-12-13 19:10:21 -05:00
|
|
|
QUALIFIED: math.private
|
|
|
|
QUALIFIED: slots.private
|
|
|
|
QUALIFIED: strings.private
|
2008-10-20 21:40:15 -04:00
|
|
|
IN: compiler.cfg.intrinsics
|
|
|
|
|
2013-03-20 13:59:45 -04:00
|
|
|
ERROR: inline-intrinsics-not-supported word quot ;
|
|
|
|
|
2009-08-30 23:20:49 -04:00
|
|
|
: enable-intrinsics ( alist -- )
|
2013-03-20 13:59:45 -04:00
|
|
|
[
|
2015-08-13 19:13:05 -04:00
|
|
|
over inline? [ inline-intrinsics-not-supported ] when
|
2013-03-20 13:59:45 -04:00
|
|
|
"intrinsic" set-word-prop
|
|
|
|
] assoc-each ;
|
2009-08-28 20:02:59 -04:00
|
|
|
|
2008-10-20 21:40:15 -04:00
|
|
|
{
|
2009-08-30 23:20:49 -04:00
|
|
|
{ kernel.private:tag [ drop emit-tag ] }
|
2010-03-26 23:11:05 -04:00
|
|
|
{ kernel.private:context-object [ emit-context-object ] }
|
2010-01-13 00:08:18 -05:00
|
|
|
{ kernel.private:special-object [ emit-special-object ] }
|
2010-04-01 20:06:18 -04:00
|
|
|
{ kernel.private:set-special-object [ emit-set-special-object ] }
|
2009-11-11 01:50:57 -05:00
|
|
|
{ kernel.private:(identity-hashcode) [ drop emit-identity-hashcode ] }
|
2009-08-30 23:20:49 -04:00
|
|
|
{ math.private:both-fixnums? [ drop emit-both-fixnums? ] }
|
|
|
|
{ math.private:fixnum+ [ drop emit-fixnum+ ] }
|
|
|
|
{ math.private:fixnum- [ drop emit-fixnum- ] }
|
|
|
|
{ math.private:fixnum* [ drop emit-fixnum* ] }
|
2010-04-22 04:21:23 -04:00
|
|
|
{ math.private:fixnum+fast [ drop [ ^^add ] binary-op ] }
|
|
|
|
{ math.private:fixnum-fast [ drop [ ^^sub ] binary-op ] }
|
|
|
|
{ math.private:fixnum*fast [ drop [ ^^mul ] binary-op ] }
|
|
|
|
{ math.private:fixnum-bitand [ drop [ ^^and ] binary-op ] }
|
|
|
|
{ math.private:fixnum-bitor [ drop [ ^^or ] binary-op ] }
|
|
|
|
{ math.private:fixnum-bitxor [ drop [ ^^xor ] binary-op ] }
|
2009-08-30 23:20:49 -04:00
|
|
|
{ math.private:fixnum-shift-fast [ emit-fixnum-shift-fast ] }
|
2010-04-22 04:21:23 -04:00
|
|
|
{ math.private:fixnum-bitnot [ drop [ ^^not ] unary-op ] }
|
2009-08-30 23:20:49 -04:00
|
|
|
{ math.private:fixnum< [ drop cc< emit-fixnum-comparison ] }
|
|
|
|
{ math.private:fixnum<= [ drop cc<= emit-fixnum-comparison ] }
|
|
|
|
{ math.private:fixnum>= [ drop cc>= emit-fixnum-comparison ] }
|
|
|
|
{ math.private:fixnum> [ drop cc> emit-fixnum-comparison ] }
|
2010-04-22 04:21:23 -04:00
|
|
|
{ kernel:eq? [ emit-eq ] }
|
2009-08-30 23:20:49 -04:00
|
|
|
{ slots.private:slot [ emit-slot ] }
|
|
|
|
{ slots.private:set-slot [ emit-set-slot ] }
|
2010-04-25 20:19:50 -04:00
|
|
|
{ strings.private:string-nth-fast [ drop emit-string-nth-fast ] }
|
2009-08-30 23:20:49 -04:00
|
|
|
{ strings.private:set-string-nth-fast [ drop emit-set-string-nth-fast ] }
|
|
|
|
{ classes.tuple.private:<tuple-boa> [ emit-<tuple-boa> ] }
|
|
|
|
{ arrays:<array> [ emit-<array> ] }
|
|
|
|
{ byte-arrays:<byte-array> [ emit-<byte-array> ] }
|
|
|
|
{ byte-arrays:(byte-array) [ emit-(byte-array) ] }
|
|
|
|
{ kernel:<wrapper> [ emit-simple-allot ] }
|
2010-05-19 00:33:36 -04:00
|
|
|
{ alien.data.private:(local-allot) [ emit-local-allot ] }
|
2016-03-08 08:38:48 -05:00
|
|
|
{ alien.data.private:(cleanup-allot) [ emit-cleanup-allot ] }
|
2009-08-30 23:20:49 -04:00
|
|
|
{ alien:<displaced-alien> [ emit-<displaced-alien> ] }
|
2010-04-23 18:42:09 -04:00
|
|
|
{ alien.accessors:alien-unsigned-1 [ int-rep alien.c-types:uchar emit-load-memory ] }
|
|
|
|
{ alien.accessors:set-alien-unsigned-1 [ int-rep alien.c-types:uchar emit-store-memory ] }
|
|
|
|
{ alien.accessors:alien-signed-1 [ int-rep alien.c-types:char emit-load-memory ] }
|
|
|
|
{ alien.accessors:set-alien-signed-1 [ int-rep alien.c-types:char emit-store-memory ] }
|
|
|
|
{ alien.accessors:alien-unsigned-2 [ int-rep alien.c-types:ushort emit-load-memory ] }
|
|
|
|
{ alien.accessors:set-alien-unsigned-2 [ int-rep alien.c-types:ushort emit-store-memory ] }
|
|
|
|
{ alien.accessors:alien-signed-2 [ int-rep alien.c-types:short emit-load-memory ] }
|
|
|
|
{ alien.accessors:set-alien-signed-2 [ int-rep alien.c-types:short emit-store-memory ] }
|
|
|
|
{ alien.accessors:alien-cell [ emit-alien-cell ] }
|
|
|
|
{ alien.accessors:set-alien-cell [ emit-set-alien-cell ] }
|
2009-08-28 20:02:59 -04:00
|
|
|
} enable-intrinsics
|
2008-10-20 21:40:15 -04:00
|
|
|
|
|
|
|
: enable-alien-4-intrinsics ( -- )
|
|
|
|
{
|
2010-04-23 18:42:09 -04:00
|
|
|
{ alien.accessors:alien-signed-4 [ int-rep alien.c-types:int emit-load-memory ] }
|
|
|
|
{ alien.accessors:set-alien-signed-4 [ int-rep alien.c-types:int emit-store-memory ] }
|
|
|
|
{ alien.accessors:alien-unsigned-4 [ int-rep alien.c-types:uint emit-load-memory ] }
|
|
|
|
{ alien.accessors:set-alien-unsigned-4 [ int-rep alien.c-types:uint emit-store-memory ] }
|
2009-08-28 20:02:59 -04:00
|
|
|
} enable-intrinsics ;
|
2008-10-20 21:40:15 -04:00
|
|
|
|
|
|
|
: enable-float-intrinsics ( -- )
|
|
|
|
{
|
2010-04-22 04:21:23 -04:00
|
|
|
{ math.private:float+ [ drop [ ^^add-float ] binary-op ] }
|
|
|
|
{ math.private:float- [ drop [ ^^sub-float ] binary-op ] }
|
|
|
|
{ math.private:float* [ drop [ ^^mul-float ] binary-op ] }
|
|
|
|
{ math.private:float/f [ drop [ ^^div-float ] binary-op ] }
|
2009-09-12 23:20:13 -04:00
|
|
|
{ math.private:float< [ drop cc< emit-float-ordered-comparison ] }
|
|
|
|
{ math.private:float<= [ drop cc<= emit-float-ordered-comparison ] }
|
|
|
|
{ math.private:float>= [ drop cc>= emit-float-ordered-comparison ] }
|
|
|
|
{ math.private:float> [ drop cc> emit-float-ordered-comparison ] }
|
|
|
|
{ math.private:float-u< [ drop cc< emit-float-unordered-comparison ] }
|
|
|
|
{ math.private:float-u<= [ drop cc<= emit-float-unordered-comparison ] }
|
|
|
|
{ math.private:float-u>= [ drop cc>= emit-float-unordered-comparison ] }
|
|
|
|
{ math.private:float-u> [ drop cc> emit-float-unordered-comparison ] }
|
|
|
|
{ math.private:float= [ drop cc= emit-float-unordered-comparison ] }
|
2010-04-22 04:21:23 -04:00
|
|
|
{ math.private:float>fixnum [ drop [ ^^float>integer ] unary-op ] }
|
|
|
|
{ math.private:fixnum>float [ drop [ ^^integer>float ] unary-op ] }
|
2009-09-12 23:20:13 -04:00
|
|
|
{ math.floats.private:float-unordered? [ drop cc/<>= emit-float-unordered-comparison ] }
|
2010-04-23 18:42:09 -04:00
|
|
|
{ alien.accessors:alien-float [ float-rep f emit-load-memory ] }
|
|
|
|
{ alien.accessors:set-alien-float [ float-rep f emit-store-memory ] }
|
|
|
|
{ alien.accessors:alien-double [ double-rep f emit-load-memory ] }
|
|
|
|
{ alien.accessors:set-alien-double [ double-rep f emit-store-memory ] }
|
2009-08-28 20:02:59 -04:00
|
|
|
} enable-intrinsics ;
|
2008-10-20 21:40:15 -04:00
|
|
|
|
2009-08-26 00:22:15 -04:00
|
|
|
: enable-fsqrt ( -- )
|
2009-08-30 23:20:49 -04:00
|
|
|
{
|
2010-04-22 04:21:23 -04:00
|
|
|
{ math.libm:fsqrt [ drop [ ^^sqrt ] unary-op ] }
|
2009-08-30 23:20:49 -04:00
|
|
|
} enable-intrinsics ;
|
2009-08-26 00:22:15 -04:00
|
|
|
|
2009-08-28 06:21:16 -04:00
|
|
|
: enable-float-min/max ( -- )
|
|
|
|
{
|
2010-04-22 04:21:23 -04:00
|
|
|
{ math.floats.private:float-min [ drop [ ^^min-float ] binary-op ] }
|
|
|
|
{ math.floats.private:float-max [ drop [ ^^max-float ] binary-op ] }
|
2009-08-28 20:02:59 -04:00
|
|
|
} enable-intrinsics ;
|
|
|
|
|
|
|
|
: enable-min/max ( -- )
|
|
|
|
{
|
2010-04-22 04:21:23 -04:00
|
|
|
{ math.integers.private:fixnum-min [ drop [ ^^min ] binary-op ] }
|
|
|
|
{ math.integers.private:fixnum-max [ drop [ ^^max ] binary-op ] }
|
2009-08-28 20:02:59 -04:00
|
|
|
} enable-intrinsics ;
|
2009-08-28 06:21:16 -04:00
|
|
|
|
2010-04-21 03:08:52 -04:00
|
|
|
: enable-log2 ( -- )
|
2009-08-30 23:20:49 -04:00
|
|
|
{
|
2010-04-22 04:21:23 -04:00
|
|
|
{ math.integers.private:fixnum-log2 [ drop [ ^^log2 ] unary-op ] }
|
2009-08-30 23:20:49 -04:00
|
|
|
} enable-intrinsics ;
|
2008-12-06 16:31:17 -05:00
|
|
|
|
2010-05-15 16:59:47 -04:00
|
|
|
: enable-bit-count ( -- )
|
|
|
|
{
|
|
|
|
{ math.bitwise.private:fixnum-bit-count [ drop [ ^^bit-count ] unary-op ] }
|
|
|
|
} enable-intrinsics ;
|
|
|
|
|
2015-06-17 22:11:10 -04:00
|
|
|
: enable-bit-test ( -- )
|
|
|
|
{
|
|
|
|
{ math.integers.private:fixnum-bit? [ drop [ ^^bit-test ] binary-op ] }
|
|
|
|
} enable-intrinsics ;
|