Created
September 26, 2021 18:01
-
-
Save hydrastro/36e05db8b801c1703c072794d9fe7d50 to your computer and use it in GitHub Desktop.
MIPS locks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Atomic Swap/Exchange (Test-and-set) (T&S) | |
| lock1: addi $t0, $zero, 1 | |
| ll $t1, 0($s1) | |
| sc $t0, 0($s1) | |
| beq $t0, $zero, lock1 | |
| add $s2, $zero, $t1 | |
| # Atomic Increment (Fetch-and-Add) (FAA) | |
| lock2: ll $t0, 0($s1) | |
| addi $t1, $t0 | |
| sc $t1, 0($s1) | |
| beq $t1, $zero, lock2 | |
| # Atomic Compare-and-Swap (CAS) | |
| lock3: ll $t0, 0($s1) | |
| bne $t0, $t1, YEET | |
| li $t2, 0($s1) | |
| move $t3, $t4 | |
| sc $t3, 0($s1) | |
| beq $t3, $zero, lock3 | |
| li $t2, 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment