Rapsodia (generator)
 All Classes Namespaces Files Functions Variables Pages
genOpSinhCosh.py
Go to the documentation of this file.
1 ##########################################################
2 # This file is part of Rapsodia released under the LGPL. #
3 # The full COPYRIGHT notice can be found in the top #
4 # level directory of the Rapsodia distribution #
5 ##########################################################
6 import Common.names as names
7 import Common.parameters as parameters
8 import Common.util as util
9 def genSinhCosh(sourceList,helper):
10  # the generic steps for sinh and cosh
11  sourceList.append(generateSinhCoshBody(helper))
12  # the sinh intrinsic
13  sourceList.append(generateSinhModule(helper))
14  # the cosh intrinsic
15  sourceList.append(generateCoshModule(helper))
16 
17 import Common.ast as ast
18 import Common.slice as slice
19 
20 def generateSinhModule(helper):
21  return helper.generateUnaryOpAll('sinh',
22  None,
23  names.Fixed.pN+'sinhcosh',
24  None,
25  's',
26  None,
27  ['c','t'],
28  [], [], [])
29 
30 
31 def generateCoshModule(helper):
32  return helper.generateUnaryOpAll('cosh',
33  None,
34  names.Fixed.pN+'sinhcosh',
35  None,
36  'c',
37  None,
38  ['s','t'],
39  [], [], [])
40 
42  aSourceNode=ast.SimpleSource(names.Fixed.pN+'sinhcosh', helper.p.iE)
43 
44 # cRet = 'c'
45 # sRet = 's'
46  cRet = util.getVarGlobalName('c')
47  sRet = util.getVarGlobalName('s')
48 
49  if not parameters.useQueue:
50  # compute cosh
51  aRHS=ast.FuncCall('cosh',[util.vOf('a')])
52  aSourceNode.appendChild(ast.Assignment(util.vOf('c'),aRHS))
53  # compute sinh
54  aRHS=ast.FuncCall('sinh',[util.vOf('a')])
55  aSourceNode.appendChild(ast.Assignment(util.vOf('s'),aRHS))
56 
57  if parameters.openmpUseOrphaning:
58  aSourceNode.appendChild(ast.Assignment(util.vOf(cRet),util.vOf('c')))
59  aSourceNode.appendChild(ast.Assignment(util.vOf(sRet),util.vOf('s')))
60 
61  s = slice.Slice(aSourceNode)
62  for direct in range(1,parameters.sliceSize+1,1):
63  for deg in range(1,parameters.o+1,1):
64  # 't' is 'a' scaled by the deriviative degree
65  aRHS=ast.Multiplication(ast.Constant(str(deg)),
66  util.dOf('a',direct,deg))
67  s.appendChild(ast.Assignment(util.dOf('t',direct,deg),aRHS))
68  # cosh coefficients
69  s.appendChild(ast.Assignment(util.dOf(cRet,direct,deg),
70  helper.generateConvolution(('t',1,deg),(sRet,0,deg-1),direct,'plus')))
71  # sinh coefficients
72  s.appendChild(ast.Assignment(util.dOf(sRet,direct,deg),
73  helper.generateConvolution(('t',1,deg),(cRet,0,deg-1),direct,'plus')))
74  # scale c
75  aRHS=ast.Division(util.dOf(cRet,direct,deg), ast.Constant(str(deg)))
76  s.appendChild(ast.Assignment(util.dOf(cRet,direct,deg),aRHS))
77  # scale s
78  aRHS=ast.Division(util.dOf(sRet,direct,deg), ast.Constant(str(deg)))
79  s.appendChild(ast.Assignment(util.dOf(sRet,direct,deg),aRHS))
80  s.endSlice()
81  s.saveGlobals(['c','s'])
82 
83  return aSourceNode
84 
85 def genSinhCoshReverse(sourceList,helper):
86  sourceList.append(helper.generateUnaryIntrinsicReverse('sinh',None,names.Fixed.pN+'sinh',None,'r',None,[],[],[],[],getStatementA))
87  sourceList.append(helper.generateUnaryIntrinsicReverse('cosh',None,names.Fixed.pN+'cosh',None,'r',None,[],[],[],[],getStatementA))
88 
89 
90 def getStatementA(helper,aSource,name,k,resultTypes):
91  operand=util.vOf('a')
92  aLHS=util.vOf('r')
93  if (name=='sinh'):
94  aRHS=ast.FuncCall('sinh',[operand])
95  da=ast.FuncCall('cosh',[operand])
96  elif (name=='cosh'):
97  aRHS=ast.FuncCall('cosh',[operand])
98  da=ast.FuncCall('sinh',[operand])
99 
100  aSource.appendChild(ast.Assignment(aLHS,aRHS))
101  aSource.appendChild(helper.generatePushUnaryLocal(da,k,resultTypes,'r','a'))
102  return aSource
103 
104 
105 
106 
107