00001 /* Copyright 1994 - 1996, LongView Technologies L.L.C. $Revision: 1.9 $ */ 00002 /* Copyright (c) 2006, Sun Microsystems, Inc. 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 00006 following conditions are met: 00007 00008 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 00009 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 00010 disclaimer in the documentation and/or other materials provided with the distribution. 00011 * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived 00012 from this software without specific prior written permission. 00013 00014 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 00015 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 00016 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00017 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00018 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 00019 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00020 00021 00022 */ 00023 00024 // Floats describes the floating point operations of the interpreter 00025 // and implements stub routines used to execute this operations. 00026 // Note: The Floats stub routines are *inside* the interpreter code. 00027 00028 class Floats: AllStatic { 00029 public: 00030 enum Some_constants { 00031 magic = 0xbadbabe0, // indicates floats in the frame if stored in temp1 00032 max_number_of_functions = 256, 00033 }; 00034 00035 // Function codes for float operations. 00036 // Note: When changing these codes, make sure that the bytecode compiler 00037 // is updated as well! (use delta +GenerateSmalltalk to generate 00038 // an updated file-in file for Smalltalk). 00039 enum Function { 00040 // nullary functions 00041 zero, // float(i) := 0.0 00042 one, // float(i) := 1.0 00043 00044 // unary functions 00045 abs, // float(i) := |float(i)| 00046 negated, // float(i) := -float(i) 00047 squared, // float(i) := float(i) * float(i) 00048 sqrt, // float(i) := sqrt(float(i)) 00049 sin, // float(i) := sin(float(i)) 00050 cos, // float(i) := cos(float(i)) 00051 tan, // float(i) := tan(float(i)) 00052 exp, // float(i) := exp(float(i)) 00053 ln, // float(i) := ln(float(i)) 00054 00055 // binary functions 00056 add, // float(i) := float(i) + float(i + 1) 00057 subtract, // float(i) := float(i) - float(i + 1) 00058 multiply, // float(i) := float(i) * float(i + 1) 00059 divide, // float(i) := float(i) / float(i + 1) 00060 modulo, // float(i) := float(i) \ float(i + 1) 00061 00062 // unary functions to oop 00063 is_zero, // tos := float(i) = 0.0 00064 is_not_zero, // tos := float(i) ~= 1.0 00065 oopify, // tos := oop(float(i)) 00066 00067 // binary functions to oop 00068 is_equal, // tos := float(i) = float(i + 1) 00069 is_not_equal, // tos := float(i) ~= float(i + 1) 00070 is_less, // tos := float(i) < float(i + 1) 00071 is_less_equal, // tos := float(i) <= float(i + 1) 00072 is_greater, // tos := float(i) > float(i + 1) 00073 is_greater_equal, // tos := float(i) >= float(i + 1) 00074 00075 number_of_functions, 00076 00077 // debugging & other purposes only (not actually generated in the bytecodes) 00078 undefined, // error handling 00079 floatify // used only to find selectors (MethodIterator) 00080 }; 00081 00082 private: 00083 private: 00084 static bool _is_initialized; // true if Floats has been initialized 00085 static char* _function_names[]; 00086 00087 static void generate_tst(MacroAssembler* masm, Assembler::Condition cc); 00088 static void generate_cmp(MacroAssembler* masm, Assembler::Condition cc); 00089 static void generate(MacroAssembler* masm, Function f); 00090 00091 public: 00092 // Dispatch (interpreter) 00093 // Note: _function_table is bigger than number_of_functions to catch illegal (byte) indices 00094 static char* _function_table[max_number_of_functions]; 00095 00096 // Debugging/Printing 00097 static char* function_name_for(Function f); 00098 00099 // Tells if there is a selector for the float operation 00100 static bool has_selector_for(Function f); 00101 00102 // Returns the selector for the float operation; NULL is there is no selector 00103 static symbolOop selector_for(Function f); 00104 00105 static oop magic_value() { return smiOop(magic); } 00106 00107 // Initialization/debugging 00108 static bool is_initialized() { return _is_initialized; } 00109 static void init(MacroAssembler* masm); 00110 static void print(); 00111 };