Skip to content

Commit

Permalink
Asm Formatting (#82)
Browse files Browse the repository at this point in the history
* Replace STAY2 with per instruction macros

Co-authored-by: Tharo <[email protected]>

* asm Formatting

Co-authored-by: Tharo <[email protected]>

* Remove unused STAY macros

* space after comma for some asm args

---------

Co-authored-by: Tharo <[email protected]>
  • Loading branch information
hensldm and Thar0 authored Aug 20, 2024
1 parent b755039 commit a68329a
Show file tree
Hide file tree
Showing 40 changed files with 675 additions and 672 deletions.
31 changes: 18 additions & 13 deletions include/sys/asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,37 @@ extern "C" {
#endif


#define NOP \
.set noreorder ;\
nop ;\
.set reorder

#define STAY1(stmnt) \
#define CACHE(op, reg) \
.set noreorder ;\
stmnt ;\
cache op, reg ;\
.set reorder

#define STAY2(stmnt, arg1) \
.set noreorder ;\
stmnt, arg1 ;\
#define MFC0(reg, op) \
.set noreorder ;\
mfc0 reg, op ;\
.set reorder

#define STAY3(stmnt, arg1, arg2) \
.set noreorder ;\
stmnt, arg1, arg2 ;\
#define MTC0(reg, op) \
.set noreorder ;\
mtc0 reg, op ;\
.set reorder

#define NOP \
.set noreorder ;\
nop ;\
#define CFC1(reg, op) \
.set noreorder ;\
cfc1 reg, op ;\
.set reorder

#define CACHE(op, reg) \
#define CTC1(reg, op) \
.set noreorder ;\
cache op, reg ;\
ctc1 reg, op ;\
.set reorder


#ifdef __cplusplus
}
#endif
Expand Down
20 changes: 10 additions & 10 deletions src/error/errorasm.s
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@

LEAF(__osError)
#if BUILD_VERSION < VERSION_J
lw t0,__osErrorHandler
beqz t0,1f
lw t0, __osErrorHandler
beqz t0, 1f
jr t0
#elif BUILD_VERSION < VERSION_K
lw t0,__kmc_pt_mode
bnez t0,_kmc_mode
lw t0, __kmc_pt_mode
bnez t0, _kmc_mode

lw t0,__osErrorHandler
beqz t0,1f
lw t0, __osErrorHandler
beqz t0, 1f
jr t0
_kmc_mode:
lw t0,__kmcErrorHandler
beqz t0,1f
lw t0, __kmcErrorHandler
beqz t0, 1f
jr t0
#else
lw t0,__osCommonHandler
beqz t0,1f
lw t0, __osCommonHandler
beqz t0, 1f
jr t0
#endif
1:
Expand Down
120 changes: 60 additions & 60 deletions src/libc/bcmp.s
Original file line number Diff line number Diff line change
Expand Up @@ -9,88 +9,88 @@ WEAK(bcmp, _bcmp)
#define _bcmp bcmp
#endif
LEAF(_bcmp)
xor v0, a0, a1
blt a2, 16, bytecmp
xor v0, a0, a1
blt a2, 16, bytecmp

andi v0, v0, 0x3
negu t8, a0
bnez v0, unalgncmp
andi v0, v0, 0x3
negu t8, a0
bnez v0, unalgncmp

andi t8, t8, 0x3
subu a2, a2, t8
beqz t8, wordcmp
andi t8, t8, 0x3
subu a2, a2, t8
beqz t8, wordcmp

move v0, v1
lwl v0, 0(a0)
lwl v1, 0(a1)
addu a0, a0, t8
addu a1, a1, t8
bne v0, v1, cmpne
move v0, v1
lwl v0, 0(a0)
lwl v1, 0(a1)
addu a0, a0, t8
addu a1, a1, t8
bne v0, v1, cmpne

wordcmp:
and a3, a2, ~3
subu a2, a2, a3
beqz a3, bytecmp
and a3, a2, ~3
subu a2, a2, a3
beqz a3, bytecmp

addu a3, a3, a0
addu a3, a3, a0
1:
lw v0, 0(a0)
lw v1, 0(a1)
addiu a0, a0, 4
addiu a1, a1, 4
bne v0, v1, cmpne
bne a0, a3, 1b
lw v0, 0(a0)
lw v1, 0(a1)
addiu a0, a0, 4
addiu a1, a1, 4
bne v0, v1, cmpne
bne a0, a3, 1b

b bytecmp
b bytecmp
unalgncmp:
negu a3, a1
andi a3, a3, 0x3
subu a2, a2, a3
beqz a3, partaligncmp
negu a3, a1
andi a3, a3, 0x3
subu a2, a2, a3
beqz a3, partaligncmp

addu a3, a3, a0

addu a3, a3, a0

1:
lbu v0, 0(a0)
lbu v1, 0(a1)
addiu a0, a0, 1
addiu a1, a1, 1
bne v0, v1, cmpne
bne a0, a3, 1b
lbu v0, 0(a0)
lbu v1, 0(a1)
addiu a0, a0, 1
addiu a1, a1, 1
bne v0, v1, cmpne
bne a0, a3, 1b

partaligncmp:
and a3, a2, ~3
subu a2, a2, a3
beqz a3, bytecmp
and a3, a2, ~3
subu a2, a2, a3
beqz a3, bytecmp

addu a3, a3, a0
addu a3, a3, a0

1:
lwl v0, 0(a0)
lwr v0, 3(a0)
lw v1, 0(a1)
addiu a0, a0, 4
addiu a1, a1, 4
bne v0, v1, cmpne
bne a0, a3, 1b
lwl v0, 0(a0)
lwr v0, 3(a0)
lw v1, 0(a1)
addiu a0, a0, 4
addiu a1, a1, 4
bne v0, v1, cmpne
bne a0, a3, 1b

bytecmp:
addu a3, a2, a0
blez a2, cmpdone
addu a3, a2, a0
blez a2, cmpdone

1:
lbu v0, 0(a0)
lbu v1, 0(a1)
addiu a0, a0, 1
addiu a1, a1, 1
bne v0, v1, cmpne
bne a0, a3, 1b
lbu v0, 0(a0)
lbu v1, 0(a1)
addiu a0, a0, 1
addiu a1, a1, 1
bne v0, v1, cmpne
bne a0, a3, 1b

cmpdone:
move v0, zero
jr ra
move v0, zero
jr ra
cmpne:
li v0, 1
jr ra
li v0, 1
jr ra

.end _bcmp
Loading

0 comments on commit a68329a

Please sign in to comment.