New arguments for sse_shufps()
[mesa.git] / src / mesa / glapi / gl_x86_asm.py
1 #!/usr/bin/python2
2
3 # (C) Copyright IBM Corporation 2004, 2005
4 # All Rights Reserved.
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a
7 # copy of this software and associated documentation files (the "Software"),
8 # to deal in the Software without restriction, including without limitation
9 # on the rights to use, copy, modify, merge, publish, distribute, sub
10 # license, and/or sell copies of the Software, and to permit persons to whom
11 # the Software is furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice (including the next
14 # paragraph) shall be included in all copies or substantial portions of the
15 # Software.
16 #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 # IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 # IN THE SOFTWARE.
24 #
25 # Authors:
26 # Ian Romanick <idr@us.ibm.com>
27
28 import gl_XML
29 import license
30 import sys, getopt
31
32 class PrintGenericStubs(gl_XML.FilterGLAPISpecBase):
33 name = "gl_x86_asm.py (from Mesa)"
34
35 def __init__(self):
36 gl_XML.FilterGLAPISpecBase.__init__(self)
37 self.license = license.bsd_license_template % ( \
38 """Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
39 (C) Copyright IBM Corporation 2004, 2005""", "BRIAN PAUL, IBM")
40
41
42 def get_stack_size(self, f):
43 size = 0
44 for p in f.parameterIterator():
45 t = p.p_type
46
47 if p.is_array() or t.size != 8:
48 size += 4
49 else:
50 size += 8
51
52 return size
53
54 def printRealHeader(self):
55 print '#include "assyntax.h"'
56 print '#include "glapioffsets.h"'
57 print ''
58 print "/* If we build with gcc's -fvisibility=hidden flag, we'll need to change"
59 print "* the symbol visibility mode to 'default'."
60 print '*/'
61 print '#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303'
62 print '# pragma GCC visibility push(default)'
63 print '# define HIDDEN(x) .hidden x'
64 print '#else'
65 print '# define HIDDEN(x)'
66 print '#endif'
67 print ''
68 print '#ifndef __WIN32__'
69 print ''
70 print '#if defined(STDCALL_API)'
71 print '# if defined(USE_MGL_NAMESPACE)'
72 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n2))'
73 print '# else'
74 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n2))'
75 print '# endif'
76 print '#else'
77 print '# if defined(USE_MGL_NAMESPACE)'
78 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n))'
79 print '# else'
80 print '# define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n))'
81 print '# endif'
82 print '#endif'
83 print ''
84 print '#define GL_OFFSET(x) CODEPTR(REGOFF(4 * x, EAX))'
85 print ''
86 print '#if defined(GNU_ASSEMBLER) && !defined(__DJGPP__) && !defined(__MINGW32__)'
87 print '#define GLOBL_FN(x) GLOBL x ; .type x, function'
88 print '#else'
89 print '#define GLOBL_FN(x) GLOBL x'
90 print '#endif'
91 print ''
92 print '#if defined(PTHREADS) || defined(XTHREADS) || defined(SOLARIS_THREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)'
93 print '# define THREADS'
94 print '#endif'
95 print ''
96 print '#ifdef GLX_USE_TLS'
97 print ''
98 print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
99 print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
100 print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
101 print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
102 print '\tCALL(_x86_get_dispatch) ;\t\t\t\\'
103 print '\tNOP ;\t\t\t\t\t\t\\'
104 print '\tJMP(GL_OFFSET(off))'
105 print ''
106 print '#elif defined(PTHREADS)'
107 print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
108 print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
109 print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
110 print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
111 print '\tMOV_L(CONTENT(GLNAME(_glapi_DispatchTSD)), EAX) ;\t\\'
112 print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\'
113 print '\tJE(1f) ;\t\t\t\t\t\\'
114 print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\'
115 print '1:\tCALL(_x86_get_dispatch) ;\t\t\t\\'
116 print '\tJMP(GL_OFFSET(off))'
117 print '#elif defined(THREADS)'
118 print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
119 print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
120 print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
121 print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
122 print '\tMOV_L(CONTENT(GLNAME(_glapi_DispatchTSD)), EAX) ;\t\\'
123 print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\'
124 print '\tJE(1f) ;\t\t\t\t\t\\'
125 print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\'
126 print '1:\tCALL(_glapi_get_dispatch) ;\t\t\t\\'
127 print '\tJMP(GL_OFFSET(off))'
128 print '#else /* Non-threaded version. */'
129 print '# define GL_STUB(fn,off,fn_alt)\t\t\t\\'
130 print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
131 print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
132 print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
133 print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\'
134 print '\tJMP(GL_OFFSET(off))'
135 print '#endif'
136 print ''
137 print '#ifdef HAVE_ALIAS'
138 print '# define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt)\t\\'
139 print '\t.globl\tGL_PREFIX(fn, fn_alt) ;\t\t\t\\'
140 print '\t.set\tGL_PREFIX(fn, fn_alt), GL_PREFIX(alias, alias_alt)'
141 print '#else'
142 print '# define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt)\t\\'
143 print ' GL_STUB(fn, off, fn_alt)'
144 print '#endif'
145 print ''
146 print 'SEG_TEXT'
147 print ''
148 print '#ifdef GLX_USE_TLS'
149 print ''
150 print '\tGLOBL\tGLNAME(_x86_get_dispatch)'
151 print '\tHIDDEN(GLNAME(_x86_get_dispatch))'
152 print 'ALIGNTEXT16'
153 print 'GLNAME(_x86_get_dispatch):'
154 print '\tmovl\t%gs:_glapi_tls_Dispatch@NTPOFF, %eax'
155 print '\tret'
156 print ''
157 print '#elif defined(PTHREADS)'
158 print 'EXTERN GLNAME(_glapi_Dispatch)'
159 print 'EXTERN GLNAME(_gl_DispatchTSD)'
160 print 'EXTERN GLNAME(pthread_getspecific)'
161 print ''
162 print 'ALIGNTEXT16'
163 print 'GLNAME(_x86_get_dispatch):'
164 print '\tSUB_L(CONST(24), ESP)'
165 print '\tPUSH_L(GLNAME(_gl_DispatchTSD))'
166 print '\tCALL(GLNAME(pthread_getspecific))'
167 print '\tADD_L(CONST(28), ESP)'
168 print '\tRET'
169 print '#elif defined(THREADS)'
170 print 'EXTERN GLNAME(_glapi_get_dispatch)'
171 print '#endif'
172 print ''
173
174 print '#if defined( GLX_USE_TLS )'
175 print '\t\t.section\twtext, "awx", @progbits'
176 print '#endif /* defined( GLX_USE_TLS ) */'
177
178 print ''
179 print '\t\tALIGNTEXT16'
180 print '\t\tGLOBL GLNAME(gl_dispatch_functions_start)'
181 print '\t\tHIDDEN(GLNAME(gl_dispatch_functions_start))'
182 print 'GLNAME(gl_dispatch_functions_start):'
183 print ''
184 return
185
186 def printRealFooter(self):
187 print ''
188 print '\t\tGLOBL\tGLNAME(gl_dispatch_functions_end)'
189 print '\t\tHIDDEN(GLNAME(gl_dispatch_functions_end))'
190 print '\t\tALIGNTEXT16'
191 print 'GLNAME(gl_dispatch_functions_end):'
192 print ''
193 print '#if defined(GLX_USE_TLS) && defined(__linux__)'
194 print ' .section ".note.ABI-tag", "a"'
195 print ' .p2align 2'
196 print ' .long 1f - 0f /* name length */'
197 print ' .long 3f - 2f /* data length */'
198 print ' .long 1 /* note length */'
199 print '0: .asciz "GNU" /* vendor name */'
200 print '1: .p2align 2'
201 print '2: .long 0 /* note data: the ABI tag */'
202 print ' .long 2,4,20 /* Minimum kernel version w/TLS */'
203 print '3: .p2align 2 /* pad out section */'
204 print '#endif /* GLX_USE_TLS */'
205 print ''
206 print '#endif /* __WIN32__ */'
207 return
208
209 def printFunction(self, f):
210 stack = self.get_stack_size(f)
211
212 alt = "%s@%u" % (f.name, stack)
213 if f.fn_alias == None:
214 print '\tGL_STUB(%s, _gloffset_%s, %s)' % (f.name, f.real_name, alt)
215 else:
216 alias_alt = "%s@%u" % (f.real_name, stack)
217 print '\tGL_STUB_ALIAS(%s, _gloffset_%s, %s, %s, %s)' % \
218 (f.name, f.real_name, alt, f.real_name, alias_alt)
219 return
220
221 def show_usage():
222 print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0]
223 sys.exit(1)
224
225 if __name__ == '__main__':
226 file_name = "gl_API.xml"
227 mode = "generic"
228
229 try:
230 (args, trail) = getopt.getopt(sys.argv[1:], "m:f:")
231 except Exception,e:
232 show_usage()
233
234 for (arg,val) in args:
235 if arg == '-m':
236 mode = val
237 elif arg == "-f":
238 file_name = val
239
240 if mode == "generic":
241 dh = PrintGenericStubs()
242 else:
243 print "ERROR: Invalid mode \"%s\" specified." % mode
244 show_usage()
245
246 gl_XML.parse_GL_API( dh, file_name )