Package org.jnode.vm.x86.compiler.l1a

Source Code of org.jnode.vm.x86.compiler.l1a.FPUHelper

/*
* $Id$
*
* Copyright (C) 2003-2014 JNode.org
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jnode.vm.x86.compiler.l1a;

import org.jnode.assembler.x86.X86Assembler;
import org.jnode.assembler.x86.X86Register;
import org.jnode.assembler.x86.X86Register.FPU;
import org.jnode.vm.bytecode.StackException;

/**
* @author Ewout Prangsma (epr@users.sourceforge.net)
*/
final class FPUHelper {

    /**
     * Swap ST0 and the given item. Action is emitted to code & performed on
     * fpuStack.
     *
     * @param os
     * @param fpuStack
     * @param item
     */
    static void fxch(X86Assembler os, FPUStack fpuStack, Item item) {
        if (!fpuStack.isTos(item)) {
            final FPU fpuReg = fpuStack.getRegister(item);
            fxch(os, fpuStack, fpuReg);
        }
    }

    /**
     * Swap ST0 and fpuReg. Action is emitted to code & performed on fpuStack.
     *
     * @param os
     * @param fpuStack
     * @param fpuReg
     */
    static void fxch(X86Assembler os, FPUStack fpuStack,
                     FPU fpuReg) {
        if (fpuReg == X86Register.ST0) {
            throw new StackException("Cannot fxch ST0");
        }
        os.writeFXCH(fpuReg);
        fpuStack.fxch(fpuReg);
    }
}
TOP

Related Classes of org.jnode.vm.x86.compiler.l1a.FPUHelper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.