summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBond_009 <bond.009@outlook.com>2020-12-22 00:27:40 +0100
committerBond_009 <bond.009@outlook.com>2020-12-22 00:27:40 +0100
commit1e0092d454d4243da23d421b35a02a5d80ec9d30 (patch)
treea475350f65d4ffb12e5f892d3ac3a4a3578bc5c4
parent48c6bd9e5263b7b3953e48afe6c5928514787a0f (diff)
Improve assembly day 5
-rw-r--r--5/part2_fast.c4
-rw-r--r--5/seat_id.asm20
-rw-r--r--5/seat_id_sse3.asm11
3 files changed, 19 insertions, 16 deletions
diff --git a/5/part2_fast.c b/5/part2_fast.c
index 2334390..483dd8f 100644
--- a/5/part2_fast.c
+++ b/5/part2_fast.c
@@ -27,6 +27,9 @@ int column(const char *seat)
return end_res;
}
+#ifdef USE_ASM
+int seat_id(const char *seat);
+#else
int seat_id(const char *seat)
{
int end_res = 0;
@@ -45,6 +48,7 @@ int seat_id(const char *seat)
return end_res;
}
+#endif
int missing_seat_id(const char *filename)
{
diff --git a/5/seat_id.asm b/5/seat_id.asm
index 562dec4..c9ca8b8 100644
--- a/5/seat_id.asm
+++ b/5/seat_id.asm
@@ -6,43 +6,43 @@ section .text
seat_id:
xor eax, eax ; set up return value
- cmp BYTE [rdi], 66 ; B
+ cmp BYTE [rdi], 'B'
sete al
shl eax, 1
xor ecx, ecx
- cmp BYTE [rdi + 1], 66
+ cmp BYTE [rdi + 1], 'B'
sete cl
or eax, ecx
shl eax, 1
- cmp BYTE [rdi + 2], 66
+ cmp BYTE [rdi + 2], 'B'
sete cl
or eax, ecx
shl eax, 1
- cmp BYTE [rdi + 3], 66
+ cmp BYTE [rdi + 3], 'B'
sete cl
or eax, ecx
shl eax, 1
- cmp BYTE [rdi + 4], 66
+ cmp BYTE [rdi + 4], 'B'
sete cl
or eax, ecx
shl eax, 1
- cmp BYTE [rdi + 5], 66
+ cmp BYTE [rdi + 5], 'B'
sete cl
or eax, ecx
shl eax, 1
- cmp BYTE [rdi + 6], 66
+ cmp BYTE [rdi + 6], 'B'
sete cl
or eax, ecx
shl eax, 1
- cmp BYTE [rdi + 7], 82 ; R
+ cmp BYTE [rdi + 7], 'R'
sete cl
or eax, ecx
shl eax, 1
- cmp BYTE [rdi + 8], 82
+ cmp BYTE [rdi + 8], 'R'
sete cl
or eax, ecx
shl eax, 1
- cmp BYTE [rdi + 9], 82
+ cmp BYTE [rdi + 9], 'R'
sete cl
or eax, ecx
ret
diff --git a/5/seat_id_sse3.asm b/5/seat_id_sse3.asm
index 40127bf..9ea9720 100644
--- a/5/seat_id_sse3.asm
+++ b/5/seat_id_sse3.asm
@@ -1,25 +1,24 @@
-global seat_id_sse3
+global seat_id
section .data
align 16
- xmm_cmp: db 1, 'RBBBBBBB', 1, 1, 1, 1, 1, 1, 1
xmm_shuf: db 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 10, 11, 12, 13, 14, 15
-
+ xmm_cmp: db 1, 'RBBBBBBB', 1, 1, 1, 1, 1, 1, 1
section .text
-seat_id_sse3:
+seat_id:
xor eax, eax ; set up return value
movq xmm0, qword [rdi] ; load first 8 bytes
pshufb xmm0, [rel xmm_shuf] ; reverse byte order and already shift left once
pcmpeqb xmm0, [rel xmm_cmp]
pmovmskb eax, xmm0 ; store mask in return value
xor ecx, ecx
- cmp BYTE [rdi + 8], 'R'
+ cmp byte [rdi + 8], 'R'
sete cl
or eax, ecx
shl eax, 1
- cmp BYTE [rdi + 9], 'R'
+ cmp byte [rdi + 9], 'R'
sete cl
or eax, ecx
ret