Sparc optimized GLAPI dispatch table.
[mesa.git] / src / mesa / glapi / glsparcasm.py
1 #!/usr/bin/env python
2
3 # $Id: glsparcasm.py,v 1.2 2001/06/05 23:54:00 davem69 Exp $
4
5 # Mesa 3-D graphics library
6 # Version: 3.5
7 #
8 # Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
9 #
10 # Permission is hereby granted, free of charge, to any person obtaining a
11 # copy of this software and associated documentation files (the "Software"),
12 # to deal in the Software without restriction, including without limitation
13 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 # and/or sell copies of the Software, and to permit persons to whom the
15 # Software is furnished to do so, subject to the following conditions:
16 #
17 # The above copyright notice and this permission notice shall be included
18 # in all copies or substantial portions of the Software.
19 #
20 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 # BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
24 # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
27
28 # Generate the glapi_sparc.S assembly language file.
29 #
30 # Usage:
31 # glsparcasm.py >glapi_sparc.S
32 #
33 # Dependencies:
34 # The gl.spec file from the SI must be in the current directory.
35 #
36 # Brian Paul 11 May 2000
37 # David S. Miller 4 Jun 2001
38
39 import string
40 import re
41
42
43 def PrintHead():
44 print '/* DO NOT EDIT - This file generated automatically with glsparcasm.py script */'
45 print '#include "glapioffsets.h"'
46 print ''
47 print '#define GL_PREFIX(n) gl##n'
48 print '#define GLOBL_FN(x) .globl x ; .type x,@function'
49 print ''
50 print '/* The _glapi_Dispatch symbol addresses get relocated into the'
51 print ' * sethi/or instruction sequences below at library init time.'
52 print ' */'
53 print ''
54 print '.data'
55 print '.align 64'
56 print ''
57 print '.globl _mesa_sparc_glapi_begin'
58 print '_mesa_sparc_glapi_begin:'
59 print ''
60 return
61 #endif
62
63 def PrintTail():
64 print '\t nop'
65 print ''
66 print '.globl _mesa_sparc_glapi_end'
67 print '_mesa_sparc_glapi_end:'
68 print ''
69 #endif
70
71
72 def GenerateDispatchCode(name, offset):
73 print ''
74 print "GLOBL_FN(GL_PREFIX(%s))" % (name)
75 print "GL_PREFIX(%s):" % (name)
76 print '#ifdef __sparc_v9__'
77 print '\tsethi\t%hi(0x00000000), %g2'
78 print '\tsethi\t%hi(0x00000000), %g1'
79 print '\tor\t%g2, %lo(0x00000000), %g2'
80 print '\tor\t%g1, %lo(0x00000000), %g1'
81 print '\tsllx\t%g2, 32, %g2'
82 print '\tldx\t[%g1 + %g2], %g1'
83 print "\tsethi\t%%hi(8 * _gloffset_%s), %%g2" % (offset)
84 print "\tor\t%%g2, %%lo(8 * _gloffset_%s), %%g2" % (offset)
85 print '\tldx\t[%g1 + %g2], %g3'
86 print '#else'
87 print '\tsethi\t%hi(0x00000000), %g1'
88 print '\tld\t[%g1 + %lo(0x00000000)], %g1'
89 print "\tld\t[%%g1 + (4 * _gloffset_%s)], %%g3" % (offset)
90 print '#endif'
91 print '\tjmpl\t%g3, %g0'
92 #enddef
93
94
95 def FindAlias(list, funcName):
96 for i in range(0, len(list)):
97 entry = list[i]
98 if entry[0] == funcName:
99 return entry[1]
100 #endif
101 #endfor
102 return ''
103 #enddef
104
105
106
107 def PrintDefines():
108 functionPattern = re.compile('^[a-zA-Z0-9]+\(')
109 functionNamePattern = re.compile('^[a-zA-Z0-9]+')
110
111 funcName = ''
112 functions = [ ]
113
114 f = open('gl.spec')
115 for line in f.readlines():
116
117 m = functionPattern.match(line)
118 if m:
119 # extract funcName
120 n = functionNamePattern.findall(line)
121 funcName = n[0]
122
123 m = string.split(line)
124 if len(m) > 1:
125 if m[0] == 'param':
126 paramName = m[1]
127 if m[0] == 'offset':
128 if m[1] == '?':
129 #print 'WARNING skipping', funcName
130 noop = 0
131 else:
132 entry = [ funcName, funcName ]
133 functions.append(entry)
134 #endif
135 elif m[0] == 'alias':
136 aliasedName = FindAlias(functions, m[1])
137 if aliasedName:
138 entry = [ funcName, aliasedName ]
139 functions.append(entry)
140 else:
141 print 'WARNING: alias to unknown function:', aliasedName
142 #endif
143 #endif
144 #endif
145 #endfor
146
147 # Now generate the assembly dispatch code
148 for i in range(0, len(functions)):
149 entry = functions[i]
150 GenerateDispatchCode( entry[0], entry[1] )
151
152 #enddef
153
154
155
156 PrintHead()
157 PrintDefines()
158 PrintTail()