Back to index

plt-scheme  4.2.1
asm-common.h
Go to the documentation of this file.
00001 /******************************** -*- C -*- ****************************
00002  *
00003  *     Dynamic assembler support
00004  *
00005  ***********************************************************************/
00006 
00007 
00008 /***********************************************************************
00009  *
00010  * Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
00011  * Written by Paolo Bonzini.
00012  *
00013  * This file is part of GNU lightning.
00014  *
00015  * GNU lightning is free software; you can redistribute it and/or modify it
00016  * under the terms of the GNU Lesser General Public License as published
00017  * by the Free Software Foundation; either version 2.1, or (at your option)
00018  * any later version.
00019  * 
00020  * GNU lightning is distributed in the hope that it will be useful, but 
00021  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00022  * or  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00023  * License for more details.
00024  * 
00025  * You should have received a copy of the GNU Lesser General Public License
00026  * along with GNU lightning; see the file COPYING.LESSER; if not, write to the
00027  * Free Software Foundation, 59 Temple Place - Suite 330, Boston,
00028  * MA 02111-1307, USA.
00029  *
00030  ***********************************************************************/
00031 
00032 
00033 #ifndef __lightning_asm_common_h
00034 #define __lightning_asm_common_h_
00035 
00036 
00037 #ifndef _ASM_SAFETY
00038 #define JITFAIL(MSG) 0
00039 #else
00040 #if defined __GNUC__ && (__GNUC__ == 3 ? __GNUC_MINOR__ >= 2 : __GNUC__ > 3)
00041 #define JITFAIL(MSG) jit_fail(MSG, __FILE__, __LINE__, __func__)
00042 #else
00043 #define JITFAIL(MSG) jit_fail(MSG, __FILE__, __LINE__, __FUNCTION__)
00044 #endif
00045 #endif
00046 
00047 #if defined __GNUC__ && (__GNUC__ == 3 ? __GNUC_MINOR__ >= 2 : __GNUC__ > 3)
00048 #define JITSORRY(MSG) jit_fail("sorry, unimplemented: " MSG, __FILE__, __LINE__, __func__)
00049 #else
00050 #define JITSORRY(MSG) jit_fail("sorry, unimplemented: " MSG, __FILE__, __LINE__, __FUNCTION__)
00051 #endif
00052 
00053 #ifdef __GNUC__
00054 #define JIT_UNUSED          __attribute__((unused))
00055 #else
00056 #define JIT_UNUSED
00057 #endif
00058 
00059 
00060 /* NextStep 2.0 cc is really gcc 1.93 but it defines __GNUC__ = 2 and
00061    does not implement __extension__.  But that compiler doesn't define
00062    __GNUC_MINOR__.  */
00063 #ifdef __GNUC__
00064 #if __GNUC__ < 2 || (defined(__NeXT__) && !__GNUC_MINOR__)
00065 #define __extension__
00066 #endif
00067 
00068 #define _TEMPD(type, var)   
00069 
00070 #define _TEMP(type, var, val, body) __extension__ ({    \
00071   register struct { type var } _jitl; _jitl.var = val;  \
00072   body;                                                 \
00073 })
00074 
00075 #else
00076 
00077 /* Between loading a global and calling a subroutine, we choose the lesser
00078  * evil. */
00079 #define _TEMPD(type, var)   static type var;
00080 #define _TEMP(type, var, val, body) ((var = val), body)
00081 
00082 #endif
00083 
00084 typedef char         _sc;
00085 typedef unsigned char       _uc;
00086 typedef unsigned short      _us;
00087 typedef unsigned int _ui;
00088 typedef int           _si;
00089 typedef long         _sl;
00090 typedef unsigned long       _ul;
00091 
00092 #define _jit_UC(X)   ((_uc  )(X))
00093 #define _jit_SC(X)   ((_sc  )(X))
00094 #define _jit_US(X)   ((_us  )(X))
00095 #define _jit_UI(X)   ((_ui  )(X))
00096 #define _jit_SI(X)   ((_si  )(X))
00097 #define _jit_SL(X)   ((_sl  )(X))
00098 #define _jit_UL(X)   ((_ul  )(X))
00099 # define _PUC(X)     ((_uc *)(X))
00100 # define _PSC(X)     ((_sc *)(X))
00101 # define _PUS(X)     ((_us *)(X))
00102 # define _PUI(X)     ((_ui *)(X))
00103 # define _PSI(X)     ((_si *)(X))
00104 # define _PSL(X)     ((_sl *)(X))
00105 # define _PUL(X)     ((_ul *)(X))
00106 
00107 # define _jit_VD(x) ((void)(x))
00108 
00109 #define _jit_B(B)         _jit_VD(((*_jit.x.uc_pc++)= _jit_UC((B)&  0xff)))
00110 #define _jit_W(W)         _jit_VD(((*_jit.x.us_pc++)= _jit_US((W)&0xffff)))
00111 #define _jit_I(I)         _jit_VD(((*_jit.x.ui_pc++)= _jit_UI((I)       )))
00112 #define _jit_L(L)         _jit_VD(((*_jit.x.ul_pc++)= _jit_UL((L)       )))
00113 #define _jit_I_noinc(I)   _jit_VD(((*_jit.x.ui_pc)=   _jit_UI((I)       )))
00114 
00115 #define _MASK(N)     ((unsigned long)(((long)1<<(N)))-1)
00116 #define _siP(N,I)    (!((((unsigned long)(I))^(((unsigned long)(I))<<1))&~_MASK(N)))
00117 #define _uiP(N,I)    (!(((unsigned long)(I))&~_MASK(N)))
00118 #define _suiP(N,I)   (_siP(N,I) | _uiP(N,I))
00119 
00120 #ifndef _ASM_SAFETY
00121 #define _ck_s(W,I)   (_jit_UL(I) & _MASK(W))
00122 #define _ck_u(W,I)          (_jit_UL(I) & _MASK(W))
00123 #define _ck_su(W,I)         (_jit_UL(I) & _MASK(W))
00124 #define _ck_d(W,I)          (_jit_UL(I) & _MASK(W))
00125 #else
00126 #define _ck_s(W,I)   (_siP(W,I) ? (_jit_UL(I) & _MASK(W)) : JITFAIL(  "signed integer `"#I"' too large for "#W"-bit field"))
00127 #define _ck_u(W,I)          (_uiP(W,I) ? (_jit_UL(I) & _MASK(W)) : JITFAIL("unsigned integer `"#I"' too large for "#W"-bit field"))
00128 #define _ck_su(W,I)         (_suiP(W,I) ? (_jit_UL(I) & _MASK(W)) : JITFAIL(        "integer `"#I"' too large for "#W"-bit field"))
00129 #define _ck_d(W,I)          (_siP(W,I) ? (_jit_UL(I) & _MASK(W)) : JITFAIL(    "displacement `"#I"' too large for "#W"-bit field"))
00130 #endif
00131 
00132 #define _s0P(I)             ((I)==0)
00133 #define _s8P(I)             _siP(8,I)
00134 #define _s16P(I)     _siP(16,I)
00135 #define _u8P(I)             _uiP(8,I)
00136 #define _u16P(I)     _uiP(16,I)
00137 
00138 #ifdef JIT_X86_64
00139 #define _s32P(I)     _siP(32,I)
00140 #define _u32P(I)     _uiP(32,I)
00141 #else
00142 #define _s32P(I)     1
00143 #define _u32P(I)     1
00144 #endif
00145 
00146 #define _su8(I)             _ck_su(8,I)
00147 #define _su16(I)     _ck_su(16,I)
00148 
00149 #define _s1(I)          _ck_s( 1,I)
00150 #define _s2(I)          _ck_s( 2,I)
00151 #define _s3(I)          _ck_s( 3,I)
00152 #define _s4(I)          _ck_s( 4,I)
00153 #define _s5(I)          _ck_s( 5,I)
00154 #define _s6(I)          _ck_s( 6,I)
00155 #define _s7(I)          _ck_s( 7,I)
00156 #define _s8(I)          _ck_s( 8,I)
00157 #define _s9(I)          _ck_s( 9,I)
00158 #define _s10(I)         _ck_s(10,I)
00159 #define _s11(I)         _ck_s(11,I)
00160 #define _s12(I)         _ck_s(12,I)
00161 #define _s13(I)         _ck_s(13,I)
00162 #define _s14(I)         _ck_s(14,I)
00163 #define _s15(I)         _ck_s(15,I)
00164 #define _s16(I)         _ck_s(16,I)
00165 #define _s17(I)         _ck_s(17,I)
00166 #define _s18(I)         _ck_s(18,I)
00167 #define _s19(I)         _ck_s(19,I)
00168 #define _s20(I)         _ck_s(20,I)
00169 #define _s21(I)         _ck_s(21,I)
00170 #define _s22(I)         _ck_s(22,I)
00171 #define _s23(I)         _ck_s(23,I)
00172 #define _s24(I)         _ck_s(24,I)
00173 #define _s25(I)         _ck_s(25,I)
00174 #define _s26(I)         _ck_s(26,I)
00175 #define _s27(I)         _ck_s(27,I)
00176 #define _s28(I)         _ck_s(28,I)
00177 #define _s29(I)         _ck_s(29,I)
00178 #define _s30(I)         _ck_s(30,I)
00179 #define _s31(I)         _ck_s(31,I)
00180 #define _u1(I)          _ck_u( 1,I)
00181 #define _u2(I)          _ck_u( 2,I)
00182 #define _u3(I)          _ck_u( 3,I)
00183 #define _u4(I)          _ck_u( 4,I)
00184 #define _u5(I)          _ck_u( 5,I)
00185 #define _u6(I)          _ck_u( 6,I)
00186 #define _u7(I)          _ck_u( 7,I)
00187 #define _u8(I)          _ck_u( 8,I)
00188 #define _u9(I)          _ck_u( 9,I)
00189 #define _u10(I)         _ck_u(10,I)
00190 #define _u11(I)         _ck_u(11,I)
00191 #define _u12(I)         _ck_u(12,I)
00192 #define _u13(I)         _ck_u(13,I)
00193 #define _u14(I)         _ck_u(14,I)
00194 #define _u15(I)         _ck_u(15,I)
00195 #define _u16(I)         _ck_u(16,I)
00196 #define _u17(I)         _ck_u(17,I)
00197 #define _u18(I)         _ck_u(18,I)
00198 #define _u19(I)         _ck_u(19,I)
00199 #define _u20(I)         _ck_u(20,I)
00200 #define _u21(I)         _ck_u(21,I)
00201 #define _u22(I)         _ck_u(22,I)
00202 #define _u23(I)         _ck_u(23,I)
00203 #define _u24(I)         _ck_u(24,I)
00204 #define _u25(I)         _ck_u(25,I)
00205 #define _u26(I)         _ck_u(26,I)
00206 #define _u27(I)         _ck_u(27,I)
00207 #define _u28(I)         _ck_u(28,I)
00208 #define _u29(I)         _ck_u(29,I)
00209 #define _u30(I)         _ck_u(30,I)
00210 #define _u31(I)         _ck_u(31,I)
00211 
00212 #endif /* __lightning_asm_common_h */