Skip to content

Commit e9a2ca2

Browse files
authored
Merge pull request #158 from edwin7026/march_mabi_gen
Added function that returns the march and mabi for gcc from a given ISA
2 parents 829f875 + b9d9147 commit e9a2ca2

File tree

4 files changed

+79
-2
lines changed

4 files changed

+79
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
44

5+
## [3.15.0] - 2024-01-01
6+
- Added function that returns the march and mabi for gcc from a given ISA
57

68
## [3.14.3] - 2023-12-01
79
- Add support for Zimop extension

riscv_config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from pkgutil import extend_path
22
__path__ = extend_path(__path__, __name__)
3-
__version__ = '3.14.3'
3+
__version__ = '3.15.0'
44

riscv_config/isa_validator.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,79 @@ def get_extension_list(isa):
161161

162162
return (extension_list, err, err_list)
163163

164+
def get_march_mabi (isa : str):
165+
'''
166+
This function returns the corresponding march and mabi argument values
167+
for RISC-V GCC
164168
169+
arguments:
170+
isa: (string) this is the isa string in canonical order
171+
172+
returns:
173+
march: (string) this is the string to be passed to -march to gcc for a given isa
174+
mabi: (string) this is the string to be passed to -mabi for given isa
175+
march_list: (list) gives march as a list of all extensions as elements
176+
None: if ISA validation throws error
177+
'''
178+
179+
# march generation
180+
181+
march = 'rv32' if '32' in isa else 'rv64'
182+
march_list = []
183+
march_list.append(march)
184+
185+
# get extension list
186+
(ext_list, err, err_list) = get_extension_list(isa)
187+
188+
# if isa validation throws errors, return None
189+
if err:
190+
return None
191+
192+
# extensions to be nullified
193+
null_ext = [
194+
# privilege modes
195+
'U',
196+
'S',
197+
198+
# rnmi
199+
'Smrnmi',
200+
201+
# debug mode
202+
'Sdext',
203+
204+
# performance counter
205+
'Zicntr',
206+
'Zihpm',
207+
208+
# unratified Zb* extensions
209+
'Zbe',
210+
'Zbf',
211+
'Zbm',
212+
'Zbr',
213+
]
214+
215+
# add Zbp and Zbt to null_ext if Zbpbo is present
216+
if 'Zbpbo' in ext_list:
217+
null_ext += ['Zbp', 'Zbt']
218+
# construct march
219+
for ext in ext_list:
220+
if ext not in null_ext:
221+
march_list.append(ext.lower())
222+
# suffix multicharacter extensions with '_'
223+
if len(ext) == 1:
224+
march += ext.lower()
225+
else:
226+
# suffix multiline extensions with '_'
227+
march = march + '_' + ext.lower()
228+
229+
# mabi generation
230+
mabi = 'ilp32'
231+
if 'F' in ext_list and 'D' in ext_list:
232+
mabi += 'd'
233+
elif 'F' in ext_list:
234+
mabi += 'f'
235+
236+
if 'rv64' in march:
237+
mabi = mabi.replace('ilp32', 'lp64')
238+
239+
return (march, mabi, march_list)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 3.14.3
2+
current_version = 3.15.0
33
commit = True
44
tag = True
55

0 commit comments

Comments
 (0)