Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / arch / sun / auto-field.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: auto-field.fth
4\
5\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6\
7\ - Do no alter or remove copyright notices
8\
9\ - Redistribution and use of this software in source and binary forms, with
10\ or without modification, are permitted provided that the following
11\ conditions are met:
12\
13\ - Redistribution of source code must retain the above copyright notice,
14\ this list of conditions and the following disclaimer.
15\
16\ - Redistribution in binary form must reproduce the above copyright notice,
17\ this list of conditions and the following disclaimer in the
18\ documentation and/or other materials provided with the distribution.
19\
20\ Neither the name of Sun Microsystems, Inc. or the names of contributors
21\ may be used to endorse or promote products derived from this software
22\ without specific prior written permission.
23\
24\ This software is provided "AS IS," without a warranty of any kind.
25\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
26\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
27\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
28\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
29\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
30\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
31\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
32\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
33\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
34\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
35\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
36\
37\ You acknowledge that this software is not designed, licensed or
38\ intended for use in the design, construction, operation or maintenance of
39\ any nuclear facility.
40\
41\ ========== Copyright Header End ============================================
42id: @(#)auto-field.fth 1.3 01/09/28
43purpose:
44copyright: Copyright 2001 Sun Microsystems, Inc. All Rights Reserved
45
46\ Use this to make structured member use more efficient for large structs
47\ that only have a few fields used.
48\
49\ constants and structs defined once inline-struct? is set to on will
50\ be defined as immediate transients that will replace their references with
51\ the literal value or sequence of tokens representing their literal value in
52\ all referencing routines.
53\
54\ This saves space and makes code easier to maintain, however it is important
55\ to realise that inline structs used more than 4 or 5 times are more expensive
56\ in dictionary usage than the simple alternative. Naturally, this is a
57\ direct function of the usage of the struct/constant definitions and the
58\ unused struct members.
59\
60\ You have been warned! You are not a supposed to define all structures and
61\ constants as inline.. If you are unsure then don't do it.
62\
63\ Example use:
64\ inline-struct? on
65\ struct
66\ \n field >foo
67\ \n field >bar
68\ \c field >thingy
69\ constant /widget
70\ inline-struct? off
71\
72\ : foo! ( n va -- ) >foo ! ;
73\ : bar@ ( va -- n ) >bar @ ;
74\
75\ Now 'see foo!'
76\ Notice how the '>foo' has been completed optimised out..
77\
78\ Now 'see bar@'
79\ The '>bar' is now represented as '/x +'
80\
81\ For this specific case the payback on the definition of /widget is
82\ 4 or 5 uses of each of the fields and constants.
83\
84\ An inline struct/constant behaves exactly as expected when not in compile
85\ mode, so:
86\
87\ /widget .
88\ 0 >foo .
89\ 0 >bar .
90\
91\ will all behave as expected.
92\
93\
94\ Need this to ensure that defining 'no-auto-field?' will still compile, but
95\ will suppress the inline struct behaviour.
96\
97[ifnexist] inline-struct?
98variable inline-struct?
99[then]
100
101[ifndef] no-auto-field?
102also forth definitions
103
104[ifnexist] headerless?
105\ The assembler does not define headerless? which is problematic for this
106\ code..
1070 value headerless?
108: headerless headerless true is headerless? ;
109: headers headers false is headerless? ;
110[then]
111
112headerless? headers
113transient? 0= if transient then
114inline-struct? off
115
116warning @ warning off
117: auto-field ( a b -- c )
118 state @ 0= if + exit then ( a b )
119 case
120 0 of endof
121 1 of postpone 1+ endof
122 2 of postpone 2+ endof
123 3 of postpone 3 postpone + endof
124 /l of postpone la1+ endof
125 /x of postpone xa1+ endof
126 dup postpone literal postpone +
127 endcase ( c )
128;
129: auto-const ( n -- )
130 state @ 0= if exit then ( n )
131 case
132 0 of postpone 0 endof
133 1 of postpone 1 endof
134 2 of postpone 2 endof
135 3 of postpone 3 endof
136 4 of postpone 4 endof
137 5 of postpone 5 endof
138 6 of postpone 6 endof
139 7 of postpone 7 endof
140 8 of postpone 8 endof
141 dup postpone literal
142 endcase ( )
143;
144: auto-create ( -- )
145 headerless? >r headers
146 transient? 0= dup >r if transient then
147 create immediate ,
148 r> if resident then
149 r> if headerless then
150;
151: auto-field ( n a -- n' ) over auto-create + does> @ auto-field ;
152: auto-const ( n -- ) auto-create does> @ auto-const ;
153
154: constant ( n -- ) \ name
155 ['] constant inline-struct? @ if
156 drop auto-const
157 else
158 state @ if token, else execute then
159 then
160; immediate
161: field ( offset n -- n' ) \ name
162 inline-struct? @ if auto-field else field then
163; immediate
164
165warning !
166
167resident if headerless then
168previous definitions
169[then] \ no-auto-field?