This repository has been archived on 2020-09-21. You can view files and clone it, but cannot push or open issues or pull requests.
cs2011-cachelab/trans.c

84 lines
2.2 KiB
C
Raw Normal View History

2016-04-24 20:12:20 -04:00
/*
2016-04-24 20:07:46 -04:00
* trans.c - Matrix transpose B = A^T
*
* Each transpose function must have a prototype of the form:
* void trans(int M, int N, int A[N][M], int B[M][N]);
*
* A transpose function is evaluated by counting the number of misses
* on a 1KB direct mapped cache with a block size of 32 bytes.
2016-04-24 20:12:20 -04:00
*/
2016-04-24 20:07:46 -04:00
#include <stdio.h>
#include "cachelab.h"
int is_transpose(int M, int N, int A[N][M], int B[M][N]);
2016-04-24 20:12:20 -04:00
/*
2016-04-24 20:07:46 -04:00
* transpose_submit - This is the solution transpose function that you
* will be graded on for Part B of the assignment. Do not change
* the description string "Transpose submission", as the driver
* searches for that string to identify the transpose function to
2016-04-24 20:12:20 -04:00
* be graded.
2016-04-24 20:07:46 -04:00
*/
char transpose_submit_desc[] = "Transpose submission";
void transpose_submit(int M, int N, int A[N][M], int B[M][N])
{
}
2016-04-24 20:12:20 -04:00
/*
2016-04-24 20:07:46 -04:00
* You can define additional transpose functions below. We've defined
2016-04-24 20:12:20 -04:00
* a simple one below to help you get started.
*/
2016-04-24 20:07:46 -04:00
2016-04-24 20:12:20 -04:00
/*
2016-04-24 20:07:46 -04:00
* trans - A simple baseline transpose function, not optimized for the cache.
*/
char trans_desc[] = "Simple row-wise scan transpose";
void trans(int M, int N, int A[N][M], int B[M][N])
{
int i, j, tmp;
for (i = 0; i < N; i++) {
for (j = 0; j < M; j++) {
tmp = A[i][j];
B[j][i] = tmp;
}
2016-04-24 20:12:20 -04:00
}
2016-04-24 20:07:46 -04:00
}
/*
* registerFunctions - This function registers your transpose
* functions with the driver. At runtime, the driver will
* evaluate each of the registered functions and summarize their
* performance. This is a handy way to experiment with different
* transpose strategies.
*/
void registerFunctions()
{
/* Register your solution function */
2016-04-24 20:12:20 -04:00
registerTransFunction(transpose_submit, transpose_submit_desc);
2016-04-24 20:07:46 -04:00
/* Register any additional transpose functions */
2016-04-24 20:12:20 -04:00
registerTransFunction(trans, trans_desc);
2016-04-24 20:07:46 -04:00
}
2016-04-24 20:12:20 -04:00
/*
2016-04-24 20:07:46 -04:00
* is_transpose - This helper function checks if B is the transpose of
* A. You can check the correctness of your transpose by calling
* it before returning from the transpose function.
*/
int is_transpose(int M, int N, int A[N][M], int B[M][N])
{
int i, j;
for (i = 0; i < N; i++) {
for (j = 0; j < M; ++j) {
if (A[i][j] != B[j][i]) {
return 0;
}
}
}
return 1;
}