I am converting the dhrystone benchmark to test its performance on a riscv compiled version. I have generated the assembly code and now intend to convert it into a hexcode format using the venus-simulator.
But when i run the code on the simulator i get multiple warnings regarding the same few lines. it seems that i am passing extra arguments in the 'lui', 'addi' and a few other instructions. I cant seem to make any sense of it.
Your help is greatly appreciated.
Here is the code
Proc_6: # #Proc_6
addi sp, sp, -32
sw ra, 28(sp) # 4-byte Folded Spill
sw s0, 24(sp) # 4-byte Folded Spill
addi s0, sp, 32
sw a0, -16(s0)
sw a1, -20(s0)
lw a0, -16(s0)
lw a1, -20(s0)
sw a0, 0(a1)
lw a0, -16(s0)
call Func_3
li a1, 0
bne a0, a1, .LBB0_2
j .LBB0_1
.LBB0_1:
lw a1, -20(s0)
li a0, 3
sw a0, 0(a1)
j .LBB0_2
.LBB0_2:
lw a1, -16(s0)
sw a1, -24(s0) # 4-byte Folded Spill
li a0, 4
bltu a0, a1, .LBB0_12
lw a0, -24(s0) # 4-byte Folded Reload
slli a0, a0, 2
lui a1, %hi(.LJTI0_0)
addi a1, a1, %lo(.LJTI0_0)
add a0, a0, a1
lw a0, 0(a0)
jr a0
.LBB0_4:
lw a1, -20(s0)
li a0, 0
sw a0, 0(a1)
j .LBB0_12
.LBB0_5:
lui a0, %hi(Int_Glob)
lw a0, %lo(Int_Glob)(a0)
li a1, 101
blt a0, a1, .LBB0_7
j .LBB0_6
.LBB0_6:
lw a1, -20(s0)
li a0, 0
sw a0, 0(a1)
j .LBB0_8
.LBB0_7:
lw a1, -20(s0)
li a0, 3
sw a0, 0(a1)
j .LBB0_8
.LBB0_8:
j .LBB0_12
.LBB0_9:
lw a1, -20(s0)
li a0, 1
sw a0, 0(a1)
j .LBB0_12
.LBB0_10:
j .LBB0_12
.LBB0_11:
lw a1, -20(s0)
li a0, 2
sw a0, 0(a1)
j .LBB0_12
.LBB0_12:
lw a0, -12(s0)
lw ra, 28(sp) # 4-byte Folded Reload
lw s0, 24(sp) # 4-byte Folded Reload
addi sp, sp, 32
ret
.LJTI0_0:
.word .LBB0_4
.word .LBB0_5
.word .LBB0_9
.word .LBB0_10
.word .LBB0_11
Proc_7: # #Proc_7
addi sp, sp, -32
sw ra, 28(sp) # 4-byte Folded Spill
sw s0, 24(sp) # 4-byte Folded Spill
addi s0, sp, 32
sw a0, -16(s0)
sw a1, -20(s0)
sw a2, -24(s0)
lw a0, -16(s0)
addi a0, a0, 2
sw a0, -28(s0)
lw a0, -20(s0)
lw a1, -28(s0)
add a0, a0, a1
lw a1, -24(s0)
sw a0, 0(a1)
lw a0, -12(s0)
lw ra, 28(sp) # 4-byte Folded Reload
lw s0, 24(sp) # 4-byte Folded Reload
addi sp, sp, 32
ret
Proc_8: # #Proc_8
addi sp, sp, -48
sw ra, 44(sp) # 4-byte Folded Spill
sw s0, 40(sp) # 4-byte Folded Spill
addi s0, sp, 48
sw a0, -16(s0)
sw a1, -20(s0)
sw a2, -24(s0)
sw a3, -28(s0)
lw a0, -24(s0)
addi a0, a0, 5
sw a0, -36(s0)
lw a0, -28(s0)
lw a1, -16(s0)
lw a2, -36(s0)
slli a2, a2, 2
add a1, a1, a2
sw a0, 0(a1)
lw a0, -16(s0)
lw a1, -36(s0)
slli a1, a1, 2
add a1, a1, a0
lw a0, 0(a1)
sw a0, 4(a1)
lw a0, -36(s0)
lw a2, -16(s0)
slli a1, a0, 2
add a1, a1, a2
sw a0, 120(a1)
lw a0, -36(s0)
sw a0, -32(s0)
j .LBB2_1
.LBB2_1: # =>This Inner Loop Header: Depth=1
lw a1, -32(s0)
lw a0, -36(s0)
addi a0, a0, 1
blt a0, a1, .LBB2_4
j .LBB2_2
.LBB2_2: # in Loop: Header=BB2_1 Depth=1
lw a0, -36(s0)
lw a1, -20(s0)
li a2, 200
mul a2, a0, a2
add a1, a1, a2
lw a2, -32(s0)
slli a2, a2, 2
add a1, a1, a2
sw a0, 0(a1)
j .LBB2_3
.LBB2_3: # in Loop: Header=BB2_1 Depth=1
lw a0, -32(s0)
addi a0, a0, 1
sw a0, -32(s0)
j .LBB2_1
.LBB2_4:
lw a1, -20(s0)
lw a0, -36(s0)
li a4, 200
mul a2, a0, a4
add a1, a1, a2
slli a0, a0, 2
add a1, a1, a0
lw a0, -4(a1)
addi a0, a0, 1
sw a0, -4(a1)
lw a0, -16(s0)
lw a3, -36(s0)
slli a2, a3, 2
add a0, a0, a2
lw a0, 0(a0)
lw a1, -20(s0)
addi a3, a3, 20
mul a3, a3, a4
add a1, a1, a3
add a1, a1, a2
sw a0, 0(a1)
lui a1, %hi(Int_Glob)
li a0, 5
sw a0, %lo(Int_Glob)(a1)
lw a0, -12(s0)
lw ra, 44(sp) # 4-byte Folded Reload
lw s0, 40(sp) # 4-byte Folded Reload
addi sp, sp, 48
ret
Func_1: # #Func_1
addi sp, sp, -16
sw ra, 12(sp) # 4-byte Folded Spill
sw s0, 8(sp) # 4-byte Folded Spill
addi s0, sp, 16
sb a0, -13(s0)
sb a1, -14(s0)
lb a0, -13(s0)
sb a0, -15(s0)
lb a0, -15(s0)
sb a0, -16(s0)
lbu a0, -16(s0)
lbu a1, -14(s0)
beq a0, a1, .LBB3_2
j .LBB3_1
.LBB3_1:
li a0, 0
sw a0, -12(s0)
j .LBB3_3
.LBB3_2:
lb a0, -15(s0)
lui a1, %hi(Ch_1_Glob)
sb a0, %lo(Ch_1_Glob)(a1)
li a0, 1
sw a0, -12(s0)
j .LBB3_3
.LBB3_3:
lw a0, -12(s0)
lw ra, 12(sp) # 4-byte Folded Reload
lw s0, 8(sp) # 4-byte Folded Reload
addi sp, sp, 16
ret
Func_2: # #Func_2
addi sp, sp, -32
sw ra, 28(sp) # 4-byte Folded Spill
sw s0, 24(sp) # 4-byte Folded Spill
addi s0, sp, 32
sw a0, -16(s0)
sw a1, -20(s0)
li a0, 2
sw a0, -24(s0)
j .LBB4_1
.LBB4_1: # =>This Inner Loop Header: Depth=1
lw a1, -24(s0)
li a0, 2
blt a0, a1, .LBB4_5
j .LBB4_2
.LBB4_2: # in Loop: Header=BB4_1 Depth=1
lw a0, -16(s0)
lw a1, -24(s0)
add a0, a0, a1
lbu a0, 0(a0)
lw a2, -20(s0)
add a1, a1, a2
lbu a1, 1(a1)
call Func_1
li a1, 0
bne a0, a1, .LBB4_4
j .LBB4_3
.LBB4_3: # in Loop: Header=BB4_1 Depth=1
li a0, 65
sb a0, -25(s0)
lw a0, -24(s0)
addi a0, a0, 1
sw a0, -24(s0)
j .LBB4_4
.LBB4_4: # in Loop: Header=BB4_1 Depth=1
j .LBB4_1
.LBB4_5:
lbu a0, -25(s0)
li a1, 87
blt a0, a1, .LBB4_8
j .LBB4_6
.LBB4_6:
lbu a1, -25(s0)
li a0, 89
blt a0, a1, .LBB4_8
j .LBB4_7
.LBB4_7:
li a0, 7
sw a0, -24(s0)
j .LBB4_8
.LBB4_8:
lbu a0, -25(s0)
li a1, 82
bne a0, a1, .LBB4_10
j .LBB4_9
.LBB4_9:
li a0, 1
sw a0, -12(s0)
j .LBB4_13
.LBB4_10:
lw a0, -16(s0)
lw a1, -20(s0)
call strcmp
mv a1, a0
li a0, 0
bge a0, a1, .LBB4_12
j .LBB4_11
.LBB4_11:
lw a0, -24(s0)
addi a0, a0, 7
sw a0, -24(s0)
lw a0, -24(s0)
lui a1, %hi(Int_Glob)
sw a0, %lo(Int_Glob)(a1)
li a0, 1
sw a0, -12(s0)
j .LBB4_13
.LBB4_12:
li a0, 0
sw a0, -12(s0)
j .LBB4_13
.LBB4_13:
lw a0, -12(s0)
lw ra, 28(sp) # 4-byte Folded Reload
lw s0, 24(sp) # 4-byte Folded Reload
addi sp, sp, 32
ret
Func_3: # #Func_3
addi sp, sp, -32
sw ra, 28(sp) # 4-byte Folded Spill
sw s0, 24(sp) # 4-byte Folded Spill
addi s0, sp, 32
sw a0, -16(s0)
lw a0, -16(s0)
sw a0, -20(s0)
lw a0, -20(s0)
li a1, 2
bne a0, a1, .LBB5_2
j .LBB5_1
.LBB5_1:
li a0, 1
sw a0, -12(s0)
j .LBB5_3
.LBB5_2:
li a0, 0
sw a0, -12(s0)
j .LBB5_3
.LBB5_3:
lw a0, -12(s0)
lw ra, 28(sp) # 4-byte Folded Reload
lw s0, 24(sp) # 4-byte Folded Reload
addi sp, sp, 32
ret
debug_printf: # #debug_printf
addi sp, sp, -48
sw ra, 12(sp) # 4-byte Folded Spill
sw s0, 8(sp) # 4-byte Folded Spill
addi s0, sp, 16
sw a7, 28(s0)
sw a6, 24(s0)
sw a5, 20(s0)
sw a4, 16(s0)
sw a3, 12(s0)
sw a2, 8(s0)
sw a1, 4(s0)
sw a0, -12(s0)
lw ra, 12(sp) # 4-byte Folded Reload
lw s0, 8(sp) # 4-byte Folded Reload
addi sp, sp, 48
ret
I have two vectors:
a = c(1,1,2,2,3,3,4,4)
b = c(1)
I want to remove the first match of b from a. Thus, here only the first 1 is removed from a:
c = c(1,2,2,3,3,4,4)
The order of items in a is not important.
I tried this code:
a[a != b]
a[! a %in% b]
Both results are:
[1] 2 2 3 3 4 4.
All numbers of 1 are removed. However, I only want to remove the specific item in b from a.
If b = c(1, 1, 2), then I wish the result
[1] 2 3 3 4 4
a[-(1:3)]
The above code could lead to the result of [1] 2 3 3 4 4. However, I wish it could be more flexible. For example when the order of items are unknown or random:
a = c(3,4,3,1,2,2,1,4)
How can I do it using R?
vecsets package can perform standard set operations, while retaining duplicates:
vecsets::vsetdiff( c(1,1,2,2,3,3,4,4), c(1) )
## [1] 1 2 2 3 3 4 4
vecsets::vsetdiff( c(1,1,2,2,3,3,4,4), c(1,1,2) )
## [1] 2 3 3 4 4
Note that it will preserve the order of the first argument. Using your last example:
vecsets::vsetdiff( c(3,4,3,1,2,2,1,4), c(1,1,2) )
## [1] 3 4 3 2 4
Taking inspiration from this answer to one of the questions I linked in comment, you can use fsetdiff from the package data.table.
It takes all as argument, which avoids having only the unique values returned, as happens with setdiff:
library(data.table)
# with your first example (b = c(1)):
unlist(fsetdiff(data.table(v1=a), data.table(v1=b), all = TRUE))
# v11 v12 v13 v14 v15 v16 v17
# 1 2 2 3 3 4 4
# with second example (b = c(1, 1, 2)):
unlist(fsetdiff(data.table(v1=a), data.table(v1=b), all = TRUE))
# v11 v12 v13 v14 v15
# 2 3 3 4 4
You can use which()
a = c(3, 4, 3, 1, 2, 2, 1, 4)
a
## [1] 3 4 3 1 2 2 1 4
b = 1
a[- which(a %in% b)[1]]
## [1] 3 4 3 2 2 1 4
Case b has two elements:
b2 = c(1, 2)
sapply(seq_along(b1), function(x) a <<- a[- which(a == x)[1]])[[2]]
## [1] 3 4 3 2 1 4
Or three...
b3 <- c(1, 2, 3)
sapply(seq_along(b1), function(x) a <<- a[- which(a == x)[1]])[[3]]
# [1] 4 3 2 1 4
I don't think that the following is the best solution (the vecsets approach strikes me as the best), but #Aaron's comment about possibly using Rcpp struck me as interesting. This is the first time I used that package. If nothing else, the fact that I was able to get working code in less than 20 minutes underscores his point that Rcpp makes it relatively easy:
library(Rcpp)
cppFunction('
NumericVector difference(NumericVector xs, NumericVector ys){
int m = xs.size();
int n = ys.size();
float flag = 1 + abs(max(xs)) + abs(max(ys)); //occurs in neither xs nor ys
NumericVector zs = clone(xs);
for(int i = 0; i < n; i++){
double y = ys[i];
int j = 0;
while(j < m && zs[j]!= y) j++;
if(j < m) zs[j] = flag;
}
int count = 0;
for(int k = 0; k < m; k++){
if(zs[k] < flag) count++;
}
NumericVector ws(count);
int k = 0;
for(int j = 0; j < m; j++){
if(zs[j] < flag){
ws[k] = zs[j];
k++;
}
}
return ws;
}
')
After you source this:
> a = c(1,1,2,2,3,3,4,4)
> b = c(1,2,1)
> difference(a,b)
[1] 2 3 3 4 4
Since this was my first attempt at such code, I'm sure that it could be improved in multiple ways.
A little frustrating, the syntactical order, but Reduce and which do it with just Base R.
Reduce(b, a) a[-which(a==b)[1]], a, b)
I've read a few questions that have been answered and are similar, but for the life of me, I can't figure out how to apply it to my question. I have a data frame like this (some entries are blank, the number of columns are determined by the pronunciation guide of a word)
5 SUPERNATURALISM S UW2 P ER0 N AE1 CH ER0 AH0 L IH2 Z AH0 M
6 ESTABLISH IH0 S T AE1 B L IH0 SH
7 FABRIC F AE1 B R IH0 K
1504 AMTRAK AE1 M T R AE0 K
I'd basically like to be able to sort the table according to the number of syllables, and that's easily visible by the number of times you see a number (0,1 or 2) in each row (the 0,1,or 2 indicates the stress placed on the vowels. The consonants like S, P, and so on, don't come attached with a number)
For example, Row 7 and 1504 both have 2 syllables because there are 2 numbers in each row (although in different columns), so I'd like them to be together.
In the end, I'd just like to sort it so out of the 4 rows I showed, the order should be 7,1504,6,5
Does anyone know the code I should write?
You can extract digit from each line and order them according to the number of digits(length of the list)
library(stringr)
## read lines
ll <- readLines(textConnection('5 SUPERNATURALISM S UW2 P ER0 N AE1 CH ER0 AH0 L IH2 Z AH0 M
6 ESTABLISH IH0 S T AE1 B L IH0 SH
7 FABRIC F AE1 B R IH0 K
1504 AMTRAK AE1 M T R AE0 K '))
## extract digit , remove the first one and order
ord <- order(sapply(str_extract_all(ll,'\\d+'),function(x)length(x[-1])))
## get the result
ll[ord]
[1] "7 FABRIC F AE1 B R IH0 K "
[2] "1504 AMTRAK AE1 M T R AE0 K "
[3] "6 ESTABLISH IH0 S T AE1 B L IH0 SH "
[4] "5 SUPERNATURALISM S UW2 P ER0 N AE1 CH ER0 AH0 L IH2 Z AH0 M"
Here's a solution using base and positive look-behind regex (using #agstudy's data):
len = unlist(lapply(ll, function(x)
length(gregexpr("(?<=[A-Za-z])[0-2]", x, perl=TRUE)[[1L]])))
ll[order(len)]
The regex (?<=[A-Za-z])[0-2] basically means if there's a number between 0-2 and it's previous character is any of the alphabets, then there's a match. perl=TRUE is required for matching with look-ahead and look-behind regexps as it requires PCRE.
We loop through ll using this regex. gregexpr returns a list with it's first index returning the position of matches. So, we extract it using length(.) and then use order to rearrange ll.
HTH
You would have to process the data first, probably regex is the way to go. Here is a solution (I will use the package stringr):
## your data
df <- read.table(text=
"5 SUPERNATURALISM S UW2 P ER0 N AE1 CH ER0 AH0 L IH2 Z AH0 M
6 ESTABLISH IH0 S T AE1 B L IH0 SH
7 FABRIC F AE1 B R IH0 K
1504 AMTRAK AE1 M T R AE0 K ",
fill=TRUE,
stringsAsFactors=FALSE)
Manipulating to extract numbers and count:
library(stringr)
text <- apply(df[,3:16], 1,paste, collapse="")
numbers <- str_extract_all(text, "\\d+")
df$syllables <- sapply(numbers, length)
Order:
df <- df[order(df$syllables),]
df
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 syllables
3 7 FABRIC F AE1 B R IH0 K 2
4 1504 AMTRAK AE1 M T R AE0 K 2
2 6 ESTABLISH IH0 S T AE1 B L IH0 SH 3
1 5 SUPERNATURALISM S UW2 P ER0 N AE1 CH ER0 AH0 L IH2 Z AH0 M 7