Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
ti_bundle.c
Go to the documentation of this file.
00001 /*
00002 
00003   Copyright (C) 2000, 2001 Silicon Graphics, Inc.  All Rights Reserved.
00004 
00005   This program is free software; you can redistribute it and/or modify it
00006   under the terms of version 2 of the GNU General Public License as
00007   published by the Free Software Foundation.
00008 
00009   This program is distributed in the hope that it would be useful, but
00010   WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013   Further, this software is distributed without any warranty that it is
00014   free of the rightful claim of any third person regarding infringement 
00015   or the like.  Any license provided herein, whether implied or 
00016   otherwise, applies only to this software file.  Patent licenses, if 
00017   any, provided herein do not apply to combinations of this program with 
00018   other software, or any other product whatsoever.  
00019 
00020   You should have received a copy of the GNU General Public License along
00021   with this program; if not, write the Free Software Foundation, Inc., 59
00022   Temple Place - Suite 330, Boston MA 02111-1307, USA.
00023 
00024   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00025   Mountain View, CA 94043, or:
00026 
00027   http://www.sgi.com
00028 
00029   For further information regarding this notice, see:
00030 
00031   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00032 
00033 */
00034 
00035 
00036 #include <alloca.h>
00037 #include <stdio.h>
00038 #include <limits.h>
00039 #include <assert.h>
00040 
00041 #include "ti_si.h"
00042 #include "ti_errors.h"
00043 #include "targ_isa_bundle.h"
00044 #include "ti_bundle.h"
00045 
00046 
00047 /* ====================================================================
00048  *
00049  *  TI_BUNDLE_Has_Property
00050  *
00051  *  See interface description
00052  *
00053  * ====================================================================
00054  */
00055 BOOL TI_BUNDLE_Has_Property( 
00056   TI_BUNDLE *bundle,
00057   ISA_EXEC_UNIT_PROPERTY property,
00058   INT *error
00059 )
00060 {
00061   INT i;
00062 
00063   *error = TI_RC_OKAY;
00064 
00065   if (bundle == NULL) {
00066     sprintf(TI_errmsg, "ISA_BUNDLE_INFO is empty");
00067     *error = TI_RC_ERROR;
00068     return FALSE;
00069   }
00070 
00071   for (i = 0; i < TI_BUNDLE_slot_count(bundle); i++) {
00072     if (TI_BUNDLE_exec_property(bundle,i) & property) 
00073       return TRUE;
00074   }
00075   
00076   return FALSE;
00077 }
00078     
00079 /* ====================================================================
00080  *
00081  *  TI_BUNDLE_Is_Full
00082  *
00083  *  See interface description
00084  *
00085  * ====================================================================
00086  */
00087 BOOL TI_BUNDLE_Is_Full( 
00088   TI_BUNDLE *bundle,
00089   INT *error
00090 )
00091 {
00092   INT i;
00093 
00094   *error = TI_RC_OKAY;
00095 
00096   if (bundle == NULL) {
00097     sprintf(TI_errmsg, "ISA_BUNDLE_INFO is empty");
00098     *error = TI_RC_ERROR;
00099     return FALSE;
00100   }
00101 
00102   for (i = 0; i < TI_BUNDLE_slot_count(bundle); i++) {
00103     if (!TI_BUNDLE_slot_filled(bundle, i)) 
00104       return FALSE;
00105   }
00106   
00107   return TRUE;
00108 }
00109 
00110 /* ====================================================================
00111  *
00112  *  TI_BUNDLE_Is_Empty
00113  *
00114  *  See interface description
00115  *
00116  * ====================================================================
00117  */
00118 BOOL TI_BUNDLE_Is_Empty( 
00119   TI_BUNDLE *bundle,
00120   INT *error
00121 )
00122 {
00123   INT i;
00124 
00125   *error = TI_RC_OKAY;
00126 
00127   if (bundle == NULL) {
00128     sprintf(TI_errmsg, "ISA_BUNDLE_INFO is empty");
00129     *error = TI_RC_ERROR;
00130     return FALSE;
00131   }
00132 
00133   for (i = 0; i < TI_BUNDLE_slot_count(bundle); i++) {
00134     if (TI_BUNDLE_slot_filled(bundle, i)) 
00135       return FALSE;
00136   }
00137   
00138   return TRUE;
00139 }
00140 
00141 /* ====================================================================
00142  *
00143  *  TI_BUNDLE_Return_Template
00144  *
00145  *  See interface description
00146  *
00147  * ====================================================================
00148  */
00149 INT TI_BUNDLE_Return_Template( 
00150   TI_BUNDLE *bundle
00151 )
00152 {
00153   return TI_BUNDLE_pack_code(bundle);
00154 }
00155 
00156 /* ====================================================================
00157  *
00158  *  TI_BUNDLE_Clear
00159  *
00160  *  See interface description
00161  *
00162  * ====================================================================
00163  */
00164 void TI_BUNDLE_Clear( 
00165   TI_BUNDLE *bundle
00166 )
00167 {
00168   INT i;
00169   for (i = 0; i < ISA_MAX_SLOTS; i++) {
00170     TI_BUNDLE_slot_filled(bundle, i) =  0;
00171     TI_BUNDLE_exec_property(bundle, i) = 0;
00172     TI_BUNDLE_stop_bit(bundle, i) = 0; 
00173   }
00174 
00175   Set_TI_BUNDLE_pack_code(bundle, 0);
00176   Set_TI_BUNDLE_stop_mask(bundle, 0x0);
00177   Set_TI_BUNDLE_slot_mask(bundle, 0x0);
00178   Set_TI_BUNDLE_slot_count(bundle, ISA_MAX_SLOTS);
00179 
00180 }
00181 
00182 /* ====================================================================
00183  *
00184  *  TI_BUNDLE_Slot_Available
00185  *
00186  *  See interface description
00187  *
00188  * ====================================================================
00189  */
00190 BOOL TI_BUNDLE_Slot_Available(
00191   TI_BUNDLE  *bundle,
00192   ISA_EXEC_UNIT_PROPERTY property,
00193   INT        slot
00194 )
00195 {
00196   INT i, j;
00197   ISA_EXEC_UNIT_PROPERTY slot_prop;
00198   BOOL match;
00199 
00200   /* if <slot> is exceeds the bundle slot capacity, return FALSE */
00201   if (slot >= ISA_MAX_SLOTS) return FALSE;
00202   
00203   /* Loop through the bundles unless either a match is found or withdrawn. 
00204      TODO: Access it through hierarchical (or state) tables */
00205 
00206 /* an instruction is compatible with a template slot if its EXEC_UNIT_PROPERTY
00207    is a superset of the slot's EXEC_UNIT_PROPERTY.  As a special case, consider
00208    instructions with an EXEC_UNIT_PROPERTY of 0 to always match */
00209 
00210 #define SLOTS_COMPATIBLE(_prop, _bundle_index, _slot_index) \
00211  ((_prop == 0) || \
00212   ((_prop & ISA_EXEC_Slot_Prop(_bundle_index, _slot_index)) == \
00213    ISA_EXEC_Slot_Prop(_bundle_index, _slot_index)))
00214   
00215   /* Loop through the bundle and slot info. */  
00216   for (i = 0; i < ISA_MAX_BUNDLES; ++i) {
00217     match = TRUE;
00218     for (j = 0; j < ISA_MAX_SLOTS; ++j) {
00219       slot_prop = (j == slot) ? property : TI_BUNDLE_exec_property(bundle, j);
00220       if ((j == slot) || TI_BUNDLE_slot_filled(bundle, j) ||
00221           TI_BUNDLE_stop_bit(bundle, j)) {
00222           if (!SLOTS_COMPATIBLE(slot_prop, i, j) ||
00223                   (TI_BUNDLE_stop_bit(bundle, j) != ISA_EXEC_Stop(i, j))) {
00224             match = FALSE;
00225             break;
00226         }
00227       }
00228     }
00229     if (match) {
00230       Set_TI_BUNDLE_pack_code(bundle, i);
00231       return TRUE;
00232     }
00233   }
00234   return FALSE;
00235 }
00236 
00237 /* ====================================================================
00238  *
00239  *  TI_BUNDLE_Stop_Bit_Available
00240  *
00241  *  See interface description
00242  *
00243  * ====================================================================
00244  */
00245 BOOL TI_BUNDLE_Stop_Bit_Available(
00246   TI_BUNDLE  *bundle,
00247   INT        slot
00248 )
00249 {
00250   INT i, j;
00251   ISA_EXEC_UNIT_PROPERTY slot_prop;
00252   BOOL stop_bit_value;
00253   BOOL match;
00254 
00255   /* if <slot> is exceeds the bundle slot capacity, return FALSE */
00256   if (slot >= ISA_MAX_SLOTS) return FALSE;
00257 
00258   /* Loop through the bundle and slot info. */  
00259   for (i = 0; i < ISA_MAX_BUNDLES; ++i) {
00260     match = TRUE;
00261     for (j = 0; j < ISA_MAX_SLOTS; ++j) {
00262       stop_bit_value = (j == slot) ? TRUE : TI_BUNDLE_stop_bit(bundle, j);
00263       if (ISA_EXEC_Stop(i, j) != stop_bit_value) {
00264           /* always look at stop bits */
00265           match = FALSE;
00266           break;
00267       } else if (TI_BUNDLE_slot_filled(bundle, j)) {
00268           /* only look at exec props if slot is filled */
00269           slot_prop = TI_BUNDLE_exec_property(bundle, j);
00270           if (!SLOTS_COMPATIBLE(slot_prop, i, j)) {
00271               match = FALSE;
00272               break;
00273           }
00274       }
00275     }
00276     if (match) {
00277       Set_TI_BUNDLE_pack_code(bundle, i);
00278       return TRUE;
00279     }
00280   }
00281   return FALSE;
00282 }
00283 
00284 /* ====================================================================
00285  *
00286  *  TI_BUNDLE_Reserve_Slot
00287  *
00288  *  See interface description
00289  *
00290  * ====================================================================
00291  */
00292 void TI_BUNDLE_Reserve_Slot(
00293   TI_BUNDLE  *bundle,
00294   INT slot,
00295   ISA_EXEC_UNIT_PROPERTY property
00296 )
00297 {
00298 
00299   TI_BUNDLE_slot_filled(bundle, slot) = TRUE;
00300   Set_TI_BUNDLE_exec_property(bundle, slot, property);
00301   TI_BUNDLE_slot_mask(bundle) |= property << 
00302     (ISA_TAG_SHIFT * (ISA_MAX_SLOTS - slot - 1));
00303 }
00304 
00305 /* ====================================================================
00306  *
00307  *  TI_BUNDLE_Reserve_Stop_Bit
00308  *
00309  *  See interface description
00310  *
00311  * ====================================================================
00312  */
00313 void TI_BUNDLE_Reserve_Stop_Bit(
00314   TI_BUNDLE  *bundle,
00315   INT slot
00316 )
00317 {
00318   if (slot < 0 || slot > ISA_MAX_SLOTS) {
00319     fprintf(stderr,"TI_BUNDLE_Reserve_Stop_Bit: slot value not legal value \n");
00320     assert(FALSE);
00321   }
00322 
00323   Set_TI_BUNDLE_stop_bit(bundle, slot, TRUE);
00324 }
00325 
00326 /* ====================================================================
00327  *
00328  *  TI_BUNDLE_Unreserve_Stop_Bit
00329  *
00330  *  See interface description
00331  *
00332  * ====================================================================
00333  */
00334 void TI_BUNDLE_Unreserve_Stop_Bit(
00335   TI_BUNDLE  *bundle,
00336   INT slot
00337 )
00338 {
00339   if (slot < 0 || slot > ISA_MAX_SLOTS) {
00340     fprintf(stderr,"TI_BUNDLE_Reserve_Stop_Bit: slot value not legal value \n");
00341     assert(FALSE);
00342   }
00343 
00344   Set_TI_BUNDLE_stop_bit(bundle, slot, FALSE);
00345 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines