diff options
| author | _ov4 <ov4@ov4.org> | 2026-11-09 10:54:59 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-11-09 10:54:59 +0000 |
| commit | 45b30cfcd4c5c133ab16fa0338e0f38f75b37751 (patch) | |
| tree | c75b99bdbab676210e37b8822c596f54b317a906 /cachelab-handout | |
| parent | 291012b8c04c306b934754525766bae5a75082fe (diff) | |
simplify with macro
Diffstat (limited to 'cachelab-handout')
| -rw-r--r-- | cachelab-handout/trans.c | 27 | ||||
| -rw-r--r-- | cachelab-handout/trans_32.h | 29 | ||||
| -rw-r--r-- | cachelab-handout/trans_64.h (renamed from cachelab-handout/trans.h) | 2 |
3 files changed, 36 insertions, 22 deletions
diff --git a/cachelab-handout/trans.c b/cachelab-handout/trans.c index 833e44f..8ce61ac 100644 --- a/cachelab-handout/trans.c +++ b/cachelab-handout/trans.c @@ -10,8 +10,6 @@ #include <stdio.h> #include "cachelab.h" -#include "trans.h" - int is_transpose(int M, int N, int A[N][M], int B[M][N]); /* @@ -27,6 +25,9 @@ int is_transpose(int M, int N, int A[N][M], int B[M][N]); #define CASE_64_64_BLOCK_SIZE 4 #define CASE_64_64_MAGIC_NUMBER 2 +#include "trans_64.h" +#include "trans_32.h" + char transpose_submit_desc[] = "Transpose submission"; void transpose_submit(int M, int N, int A[N][M], int B[M][N]) { @@ -64,6 +65,7 @@ void transpose_submit(int M, int N, int A[N][M], int B[M][N]) for (j = 0; j < M; j+=CASE_32_32_BLOCK_SIZE) { // wtf magic? + // diagonal if (i == j && i != 24) { for (i2 = 0; i2 < CASE_32_32_BLOCK_SIZE; i2++) @@ -85,26 +87,7 @@ void transpose_submit(int M, int N, int A[N][M], int B[M][N]) continue; } - - for (i2 = 0; i2 < CASE_32_32_BLOCK_SIZE; i2++) - { - t0 = A[i+i2][j+0]; - t1 = A[i+i2][j+1]; - t2 = A[i+i2][j+2]; - t3 = A[i+i2][j+3]; - t4 = A[i+i2][j+4]; - t5 = A[i+i2][j+5]; - t6 = A[i+i2][j+6]; - t7 = A[i+i2][j+7]; - B[j+0][i+i2] = t0; - B[j+1][i+i2] = t1; - B[j+2][i+i2] = t2; - B[j+3][i+i2] = t3; - B[j+4][i+i2] = t4; - B[j+5][i+i2] = t5; - B[j+6][i+i2] = t6; - B[j+7][i+i2] = t7; - } + B_32_8_BY_8_TRANSPOSE(i, j, i2); } } } diff --git a/cachelab-handout/trans_32.h b/cachelab-handout/trans_32.h new file mode 100644 index 0000000..879a55b --- /dev/null +++ b/cachelab-handout/trans_32.h @@ -0,0 +1,29 @@ +#pragma once + +#ifndef CASE_32_32_BLOCK_SIZE +#define CASE_32_32_BLOCK_SIZE 8 +#endif + +#define B_32_8_BY_8_TRANSPOSE(base_i, base_j, tmp) \ +do \ +{ \ +for (tmp = 0; tmp < CASE_32_32_BLOCK_SIZE; tmp++) \ +{ \ + t0 = A[base_i + tmp][base_j + 0]; \ + t1 = A[base_i + tmp][base_j + 1]; \ + t2 = A[base_i + tmp][base_j + 2]; \ + t3 = A[base_i + tmp][base_j + 3]; \ + t4 = A[base_i + tmp][base_j + 4]; \ + t5 = A[base_i + tmp][base_j + 5]; \ + t6 = A[base_i + tmp][base_j + 6]; \ + t7 = A[base_i + tmp][base_j + 7]; \ + B[base_j + 0][base_i + tmp] = t0; \ + B[base_j + 1][base_i + tmp] = t1; \ + B[base_j + 2][base_i + tmp] = t2; \ + B[base_j + 3][base_i + tmp] = t3; \ + B[base_j + 4][base_i + tmp] = t4; \ + B[base_j + 5][base_i + tmp] = t5; \ + B[base_j + 6][base_i + tmp] = t6; \ + B[base_j + 7][base_i + tmp] = t7; \ +} \ +} while (0) diff --git a/cachelab-handout/trans.h b/cachelab-handout/trans_64.h index 0d89704..542866e 100644 --- a/cachelab-handout/trans.h +++ b/cachelab-handout/trans_64.h @@ -1,3 +1,5 @@ +#pragma once + #define CP_4_BY_8(base_i, base_j, tmp) \ do \ { \ |
