Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
ch32v003fun
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Horn
ch32v003fun
Commits
cece4f73
Unverified
Commit
cece4f73
authored
1 year ago
by
duk
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Create xw_ext.inc
parent
2d3cde8c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ch32v003fun/xw_ext.inc
+57
-0
57 additions, 0 deletions
ch32v003fun/xw_ext.inc
with
57 additions
and
0 deletions
ch32v003fun/xw_ext.inc
0 → 100644
+
57
−
0
View file @
cece4f73
/*
Encoder for some of the proprietary 'XW' RISC-V instructions present on the QingKe RV32 processor.
Examples:
XW_C_LBU(a3, a1, 27); // c.xw.lbu a3, 27(a1)
XW_C_SB(a0, s0, 13); // c.xw.sb a0, 13(s0)
XW_C_LHU(a5, a5, 38); // c.xw.lhu a5, 38(a5)
XW_C_SH(a2, s1, 14); // c.xw.sh a2, 14(s1)
*/
// Let us do some compile-time error checking.
#define ASM_ASSERT(COND) .if (!(COND)); .err; .endif
// Integer encodings of the possible compressed registers.
#define C_s0 0
#define C_s1 1
#define C_a0 2
#define C_a1 3
#define C_a2 4
#define C_a3 5
#define C_a4 6
#define C_a5 7
// register to encoding
#define REG2I(X) (C_ ## X)
// XW opcodes
#define XW_OP_LBUSP 0b1000000000000000
#define XW_OP_STSP 0b1000000001000000
#define XW_OP_LHUSP 0b1000000000100000
#define XW_OP_SHSP 0b1000000001100000
#define XW_OP_LBU 0b0010000000000000
#define XW_OP_SB 0b1010000000000000
#define XW_OP_LHU 0b0010000000000010
#define XW_OP_SH 0b1010000000000010
// The two different XW encodings supported at the moment.
#define XW_ENCODE1(OP, R1, R2, IMM) ASM_ASSERT((IMM) >= 0 && (IMM) < 32); .2byte ((OP) | (REG2I(R1) << 2) | (REG2I(R2) << 7) | \
(((
IMM
)
&
0b1
)
<<
12
)
|
(((
IMM
)
&
0b110
)
<<
(
5
-
1
))
|
(((
IMM
)
&
0b11000
)
<<
(
10
-
3
)))
#define XW_ENCODE2(OP, R1, R2, IMM) ASM_ASSERT((IMM) >= 0 && (IMM) < 32); .2byte ((OP) | (REG2I(R1) << 2) | (REG2I(R2) << 7) | \
(((
IMM
)
&
0b11
)
<<
5
)
|
(((
IMM
)
&
0b11100
)
<<
(
10
-
2
))
// Compressed load byte, zero-extend result
#define XW_C_LBU(RD, RS, IMM) XW_ENCODE1(XW_OP_LBU, RD, RS, IMM)
// Compressed store byte
#define XW_C_SB(RS1, RS2, IMM) XW_ENCODE1(XW_OP_SB, RS1, RS2, IMM)
// Compressed load half, zero-extend result
#define XW_C_LHU(RD, RS, IMM) ASM_ASSERT(((IMM) & 1) == 0); XW_ENCODE2(XW_OP_LHU, RD, RS, ((IMM) >> 1)))
// Compressed store half
#define XW_C_SH(RS1, RS2, IMM) ASM_ASSERT(((IMM) & 1) == 0); XW_ENCODE2(XW_OP_SH, RS1, RS2, ((IMM) >> 1)))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment