From 42b858b3f0ad9914e9b586d345b62d437e6e28cb Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 12 Aug 2010 21:41:57 -0700 Subject: [PATCH] math.libm: fix regression: fsqrt intrinsic was not working ever since change was made to inline FUNCTION: bodies --- .../compiler/cfg/builder/builder-tests.factor | 7 ------- basis/compiler/cfg/debugger/debugger.factor | 9 ++++++++- basis/cpu/x86/x86-tests.factor | 10 ++++++++++ basis/math/libm/libm.factor | 18 +++++++++++++++--- 4 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 basis/cpu/x86/x86-tests.factor diff --git a/basis/compiler/cfg/builder/builder-tests.factor b/basis/compiler/cfg/builder/builder-tests.factor index 5d2c5e2e3c..5f2b75f0e0 100644 --- a/basis/compiler/cfg/builder/builder-tests.factor +++ b/basis/compiler/cfg/builder/builder-tests.factor @@ -161,13 +161,6 @@ IN: compiler.cfg.builder.tests { pinned-c-ptr class fixnum } \ set-alien-cell '[ _ declare _ execute ] unit-test-builder ] each -: count-insns ( quot insn-check -- ? ) - [ test-regs [ post-order [ instructions>> ] map concat ] map concat ] dip - count ; inline - -: contains-insn? ( quot insn-check -- ? ) - count-insns 0 > ; inline - [ t ] [ [ swap ] [ ##replace? ] contains-insn? ] unit-test [ f ] [ [ swap swap ] [ ##replace? ] contains-insn? ] unit-test diff --git a/basis/compiler/cfg/debugger/debugger.factor b/basis/compiler/cfg/debugger/debugger.factor index fd0a0be7d9..28036241a5 100644 --- a/basis/compiler/cfg/debugger/debugger.factor +++ b/basis/compiler/cfg/debugger/debugger.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: kernel words sequences quotations namespaces io vectors -arrays hashtables classes.tuple accessors prettyprint +arrays hashtables classes.tuple math accessors prettyprint prettyprint.config assocs prettyprint.backend prettyprint.custom prettyprint.sections parser compiler.tree.builder compiler.tree.optimizer cpu.architecture compiler.cfg.builder @@ -125,3 +125,10 @@ M: rs-loc pprint* \ R pprint-loc ; bi append ] map concat ] map concat >hashtable representations set ; + +: count-insns ( quot insn-check -- ? ) + [ test-regs [ post-order [ instructions>> ] map concat ] map concat ] dip + count ; inline + +: contains-insn? ( quot insn-check -- ? ) + count-insns 0 > ; inline diff --git a/basis/cpu/x86/x86-tests.factor b/basis/cpu/x86/x86-tests.factor new file mode 100644 index 0000000000..31e0f23ebd --- /dev/null +++ b/basis/cpu/x86/x86-tests.factor @@ -0,0 +1,10 @@ +IN: cpu.x86.tests +USING: cpu.x86.features tools.test math.libm kernel.private math +compiler.cfg.instructions compiler.cfg.debugger kernel ; + +[ ] [ + [ { float } declare fsqrt ] + [ ##sqrt? ] contains-insn? + sse2? + assert= +] unit-test diff --git a/basis/math/libm/libm.factor b/basis/math/libm/libm.factor index c87a2819ca..e8d5d27c66 100644 --- a/basis/math/libm/libm.factor +++ b/basis/math/libm/libm.factor @@ -1,6 +1,6 @@ -! Copyright (C) 2006 Slava Pestov. +! Copyright (C) 2006, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: alien alien.c-types alien.syntax ; +USING: alien alien.c-types alien.syntax kernel words accessors ; IN: math.libm LIBRARY: libm @@ -49,7 +49,19 @@ FUNCTION-ALIAS: fpow FUNCTION-ALIAS: fsqrt double sqrt ( double x ) ; - + +! fsqrt has an intrinsic so we don't actually want to inline it +! unconditionally +<< +\ fsqrt f "inline" set-word-prop + +\ fsqrt [ + drop + \ fsqrt "intrinsic" word-prop + f \ fsqrt def>> ? +] "custom-inlining" set-word-prop +>> + ! Windows doesn't have these... FUNCTION-ALIAS: flog1+ double log1p ( double x ) ;