SPARC register names to binary - cpu-registers

So in SPARC V8, the destination register (rd) occupies 5 bits of the instruction (25th-29th). My question is: is there a document with map associating each register name, say %i1, to its respective 5-bit binary, say, 01010? I can't find such thing...

Register numbers 0-7 are %g0-%g7, 8-15 are %o0-%o7, 16-23 are %l0-%l7 and 24-31 are %i0-%i7

http://www.gaisler.com/doc/sparcv8.pdf
Note that Sparc uses register windows.... so you are addressing the register window not the register file itself.
The data formats are defined on page 18 of the Sparc V8 manual. Sparc uses LSB 0 bit notation. The order of the register window locations names are on page 24.
A byte for instance is 7 6 5 4 3 2 1 0 with 0 being least significant.
This in turn means the instructions map as follows.
0 00000 %g0
1 00001 %g1
2 00010 %g2
3 00011 %g3
4 00100 %g4
5 00101 %g5
6 00110 %g6
7 00111 %g7
8 01000 %o0
9 01001 %o1
10 01010 %o2
11 01011 %o3
12 01100 %o4
13 01101 %o5
14 01110 %o6
15 01111 %o7
16 10000 %l0
17 10001 %l1
18 10010 %l2
19 10011 %l3
20 10100 %l4
21 10101 %l5
22 10110 %l6
23 10111 %l7
24 11000 %i0
25 11001 %i1
26 11010 %i2
27 11011 %i3
28 11100 %i4
29 11101 %i5
30 11110 %i6
31 11111 %i7

Related

Alphabet conversion - Cyrillic to Latin

I have a list of names and surnames written on Cyrillic.
head(text, n = 20)
unique(clients$RODITEL)
1 <NA>
2 ЃОРЃИ
3 ALEKSANDAR
4 000000000000
5 ТР4АЈЧЕ
6 0
7 HHHHHHH
8 0000000
9 TASKO
10 --------------------
11 ДРАГИ
12 СЛАВЧО
13 ACO
14 НИКОЛА
15 САШО
16 НАУМЧЕ
17 ОРЦЕ
18 САНДРА
19 МИРСАД
20 ОКТАЈ
What I need to do is to convert the names written on Cyrlic, such as the last 10 rows into Latin.
So the output would be:
1 <NA>
2 GJORGJI
3 ALEKSANDAR
4 000000000000
5 TRAJCHE
6 0
7 HHHHHHH
8 0000000
9 TASKO
10 --------------------
11 DRAGI
12 SLAVCHO
13 ACO
14 NIKOLA
15 SASHO
16 NAUMCHE
17 ORCE
18 SANDRA
19 MIRSAD
20 OKTAJ
The particular, Cyrlic alphabet is Macedonian.
I am not sure if there is any R package that deals with such conversion?
You can use functions from the package stringi, for example:
> stri_trans_general('ДРАГИ', 'latin')
[1] "DRAGI"

Calculating cumulative values for all nodes in a chain in R

I have a dataframe consisting of an edge lists (FromID/ToID) with various attributes.
FromID ToID from_median degree since_0001 total_saved
0002 0001 10 1 30
0003 0001 20 1 40
0004 0002 10 2 70
0004 0003 10 2 70
0005 0003 33 2 112
0006 0004 26 3 129
0007 0004 14 3 148
0008 0005 22 3 150
0009 0005 14 3 157
0010 0007 15 4 178
0011 0007 28 4 184
0011 0008 28 4 184
0012 0008 12 4 188
0013 0011 30 5 220
0014 0012 12 5 207
df$degree is the distance (in degrees) of df$FromID from the initial df$ToID (0001).
df$total_saved should be df$from_median + the df$from_median value for each ID in its chain: e.g. FromID 0014 should equal 99: 0001 -> 0003 -> 0005 -> 0008 -> 0012 -> 0014 == 20 + 33 + 22 + 12 + 12
I simply populated df$total_saved with
df$total_saved <- df$from_median
and then tried various combinations of for loops, ifelse() and vectorization approaches (using %in% or match() to match FromIDs and TOIDs) without much luck, only getting correct df$total_saved values up to 2 degrees.
Any thoughts greatly appreciated.
Many thanks
Your question is not totally clear but I try to find a solution. I assumed that you want to have find the total length of all paths below the edge FromID TOid.
First we make a matrix whether you can come from a point to another point. Next we find the total degree.
Here the code:
require("data.table")
require("igraph")
require("matrixStats")
test <- data.table(FromID = as.character(c(2,3,4,4,5,6,7,8,9,10,11,11,12,13,14)),
ToID = as.character(c(1,1,2,3,3,4,4,5,5,7,7,8,8,11,12)),
degree = c(10,20,10,10,33,26,14,22,14,15,28,28,12,30,12))
igraph <- make_graph(t(test[, .(FromID, ToID)]))
E(igraph)$weight <- test$degree
distances <- distances(igraph, mode = "out")
distances[!is.infinite(distances)] <- 1
distances[is.infinite(distances)] <- 0
# Find the longest chain from each node
chain_dist <- rowMaxs(distances[test$FromID,])
names(chain_dist) <- test$FromID
# Function to find the total length
FindTotalLength <- function(x){
dist_to <- distances[test$ToID[x],, drop =F]
names <- c(test$FromID[x], colnames(dist_to)[dist_to == 1])
return(sum(test[FromID %in% names & ToID %in% names, degree]))
}
# Now we got allt he distances now we have to make sure that the first edge will be to ToID
test[,total_saved := sapply(1 : length(FromID), function(x) FindTotalLength(x))]
> test
FromID ToID degree total_saved
1: 2 1 10 10
2: 3 1 20 20
3: 4 2 10 20
4: 4 3 10 30
5: 5 3 33 53
6: 6 4 26 76
7: 7 4 14 64
8: 8 5 22 75
9: 9 5 14 67
10: 10 7 15 79
11: 11 7 28 92
12: 11 8 28 103
13: 12 8 12 87
14: 13 11 30 205
15: 14 12 12 99

How to set the data in datatable

I executing the query I get the result as below format
ID Name Date MF SOB PCB
1001 KIRAN 02/08/2015 10 20 10
1002 KIRAN 03/O8/2015 12 20
1003 SWATHY 02/08/2015 10 8 10
1004 DEVAN 02/08/2015 13 9 10
1005 VIKAS 03/08/2015 14 12 10
1006 MADHAV 07/08/2015 12 11 10
1007 KIRAN 07/08/2015 10 15 20
1008 SWATHY 08/08/2015 10 17 15
The user can select a start date and end date option... I need to show the result in a data table like:
If the start date is 02/08/2015 and end date is 05/08/2015
I have to shows the data table COLUMN heading of data table like below
MF01/08/15 ,SOB01/08/15,PCB01/08/15, MF02/08/15 ,SOB02/08/15,PCB02/08/15, MF03/08/15 ,SOB03/08/15,PCB03/08/15,.............MF05/08/15,SOB05/08/15,PCB05/08/15,TOTALMF,TOTALSOB,
TOTALPCB
NAME MF01/08/15 SOB01/08/15 PCB01/08/2015 MF02/08/15 SOB02/08/15 Total
MF Total
SOb Total
PCB
KIRAN 10 20 10 12 20 22 20 30
SWATHY 10 8 10
DEVAN 13
VIKAS 14 12 10 14 12 10
MADHAV
You could create a stored procedure to tranform tha data and call that and the headings would all be OK.
At a glance, I think you'd want to utilise a PIVOT table in the stored procedure.
Good luck

how to deal with this kind of data type

I used igraph package to detect communities. When I used membership(community) function, the result is:
1 2 3 4 5 6 7 13 17 18 19 20 22 23 24 25
12 9 1 10 12 6 12 16 1 11 6 6 3 13 16 1
29 30 31 33 34 37 38 39 40 41 42 43 44 45 46 47
9 5 11 14 13 6 13 11 12 13 1 16 11 6 12 7
...
The first line is node ID and the second line is its corresponding community ID.
Suppose the name of the above result is X. I used Y=data.frame(X). The result is:
community
1 12
2 9
3 1
4 10
5 12
6 6
7 12
13 16
...
I want to use the first column (1,2,3,...), for instance, Y[13,]=16. But in this case, it is Y[8,]=16. How to do this?
This question may be very simple. But I do not know how to google it. Thanks.
Function as.data.frame() converts a named vector to a data frame, where the names of the vector elements are used as row names.
In other words, use a construct like rownames(Y)[8] to access the first column (or the row names, actually).

cumulative variable construction in longitudinal data set

The problem:
I would like to construct a variable that measures cumulative work experience within a person-year longitudinal data set. The problem applies to all sorts of longitudinal data sets and many variables might be constructed in this cumulative way (e.g., number of children, cumulative education, cumulative dollars spend on vacations, etc.)
The case:
I have a large longitudinal data set in which every row constitutes a person year. The data set contains thousands of persons (variable “ID”) followed through their lives (variable “age”), resulting in a data frame with about 1.2 million rows. One variable indicates how many months a person has worked in each person year (variable “work”). For example, when Dan was 15 years old he worked 3 months.
ID age work
1 Dan 10 0
2 Dan 11 0
3 Dan 12 0
4 Dan 13 0
5 Dan 14 0
6 Dan 15 3
7 Dan 16 5
8 Dan 17 8
9 Dan 18 5
10 Dan 19 12
11 Jeff 20 0
12 Jeff 16 0
13 Jeff 17 0
14 Jeff 18 0
15 Jeff 19 0
16 Jeff 20 0
17 Jeff 21 8
18 Jeff 22 10
19 Jeff 23 12
20 Jeff 24 12
21 Jeff 25 12
22 Jeff 26 12
23 Jeff 27 12
24 Jeff 28 12
25 Jeff 29 12
I now want to construct a cumulative work experience variable, which adds the value of year x to year x+1. The goal is to know at each age of a person how many months they have worked in their entire carrier. The variable should look like “cumwork”.
ID age work cumwork
1 Dan 10 0 0
2 Dan 11 0 0
3 Dan 12 0 0
4 Dan 13 0 0
5 Dan 14 0 0
6 Dan 15 3 3
7 Dan 16 5 8
8 Dan 17 8 16
9 Dan 18 5 21
10 Dan 19 12 33
11 Jeff 20 0 0
12 Jeff 16 0 0
13 Jeff 17 0 0
14 Jeff 18 0 0
15 Jeff 19 0 0
16 Jeff 20 0 0
17 Jeff 21 8 8
18 Jeff 22 10 18
19 Jeff 23 12 30
20 Jeff 24 12 42
21 Jeff 25 12 54
22 Jeff 26 12 66
23 Jeff 27 12 78
24 Jeff 28 12 90
25 Jeff 29 12 102
A poor solution: I can construct such a cumulative variable using the following simple loop:
# Generate test data set
x=data.frame(ID=c(rep("Dan",times=10),rep("Jeff",times=15)),age=c(10:20,16:29),work=c(rep(0,times=5),3,5,8,5,12,rep(0,times=6),8,10,rep(12,times=7)),stringsAsFactors=F)
# Generate cumulative work experience variable
x$cumwork=x$work
for(r in 2:nrow(x)){
if(x$ID[r]==x$ID[r-1]){
x$cumwork[r]=x$cumwork[r-1]+x$cumwork[r]
}
}
However, my dataset has 1.2 million rows and looping through each row is highly inefficient and running this loop would take hours. Does any brilliant programmer have a suggestion of how to construct this cumulative measure most efficiently?
Many thanks in advance!
Best,
Raphael
ave is convenient for these types of tasks. The function you want to use with it is cumsum:
x$cumwork <- ave(x$work, x$ID, FUN = cumsum)
x
# ID age work cumwork
# 1 Dan 10 0 0
# 2 Dan 11 0 0
# 3 Dan 12 0 0
# 4 Dan 13 0 0
# 5 Dan 14 0 0
# 6 Dan 15 3 3
# 7 Dan 16 5 8
# 8 Dan 17 8 16
# 9 Dan 18 5 21
# 10 Dan 19 12 33
# 11 Jeff 20 0 0
# 12 Jeff 16 0 0
# 13 Jeff 17 0 0
# 14 Jeff 18 0 0
# 15 Jeff 19 0 0
# 16 Jeff 20 0 0
# 17 Jeff 21 8 8
# 18 Jeff 22 10 18
# 19 Jeff 23 12 30
# 20 Jeff 24 12 42
# 21 Jeff 25 12 54
# 22 Jeff 26 12 66
# 23 Jeff 27 12 78
# 24 Jeff 28 12 90
# 25 Jeff 29 12 102
However, given the scale of your data, I would also strongly suggest the "data.table" package, which also gives you access to convenient syntax:
library(data.table)
DT <- data.table(x)
DT[, cumwork := cumsum(work), by = ID]

Resources