Skip to content

Commit

Permalink
make format
Browse files Browse the repository at this point in the history
  • Loading branch information
klin02 committed Feb 29, 2024
1 parent bd1d1af commit 9712733
Show file tree
Hide file tree
Showing 43 changed files with 1,207 additions and 1,221 deletions.
23 changes: 8 additions & 15 deletions src/test/csrc/common/SimJTAG.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
// See LICENSE.SiFive for license details.

#include <cstdlib>
#include "remote_bitbang.h"
#include "common.h"
#include "remote_bitbang.h"
#include <cstdlib>
#ifdef CONFIG_DIFFTEST_PERFCNT
#include "perf.h"
#endif // CONFIG_DIFFTEST_PERFCNT

remote_bitbang_t* jtag;
remote_bitbang_t *jtag;
bool enable_simjtag;
extern "C" int jtag_tick
(
unsigned char * jtag_TCK,
unsigned char * jtag_TMS,
unsigned char * jtag_TDI,
unsigned char * jtag_TRSTn,
unsigned char jtag_TDO
)
{
extern "C" int jtag_tick(unsigned char *jtag_TCK, unsigned char *jtag_TMS, unsigned char *jtag_TDI,
unsigned char *jtag_TRSTn, unsigned char jtag_TDO) {
#ifdef CONFIG_DIFFTEST_PERFCNT
difftest_calls[perf_jtag_tick] ++;
difftest_calls[perf_jtag_tick]++;
difftest_bytes[perf_jtag_tick] += 5;
#endif // CONFIG_DIFFTEST_PERFCNT
if (!enable_simjtag) return 0;
if (!enable_simjtag)
return 0;
if (!jtag) {
// TODO: Pass in real port number
jtag = new remote_bitbang_t(23334);
Expand All @@ -31,5 +25,4 @@ extern "C" int jtag_tick
jtag->tick(jtag_TCK, jtag_TMS, jtag_TDI, jtag_TRSTn, jtag_TDO);

return jtag->done() ? (jtag->exit_code() << 1 | 1) : 0;

}
9 changes: 4 additions & 5 deletions src/test/csrc/common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* See the Mulan PSL v2 for more details.
***************************************************************************************/

#include <signal.h>
#include <locale.h>
#include "common.h"
#include <locale.h>
#include <signal.h>

int assert_count = 0;
int signal_num = 0;
const char* emu_path = NULL;
const char *emu_path = NULL;

extern "C" void xs_assert(long long line) {
if (assert_count >= 0) {
Expand All @@ -44,7 +44,7 @@ uint32_t uptime(void) {
int s = t.tv_sec - boot.tv_sec;
int us = t.tv_usec - boot.tv_usec;
if (us < 0) {
s --;
s--;
us += 1000000;
}

Expand Down Expand Up @@ -76,7 +76,6 @@ void common_init(const char *program_name) {

assert_count = 0;
signal_num = 0;

}

void common_finish() {
Expand Down
43 changes: 21 additions & 22 deletions src/test/csrc/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@
#ifndef __COMMON_H
#define __COMMON_H

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cstdint>
#include "config.h"
#include <cassert>
#include <cerrno>
#include <cinttypes>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sys/time.h>
#include <unistd.h>

#include "config.h"

#define ANSI_COLOR_RED "\x1b[31m"
#define ANSI_COLOR_GREEN "\x1b[32m"
#define ANSI_COLOR_YELLOW "\x1b[33m"
Expand All @@ -37,14 +36,14 @@
#define ANSI_COLOR_CYAN "\x1b[36m"
#define ANSI_COLOR_RESET "\x1b[0m"

#define eprintf(...) fprintf(stdout, ## __VA_ARGS__)
#define eprintf(...) fprintf(stdout, ##__VA_ARGS__)

#ifdef WITH_DRAMSIM3
#include "cosimulation.h"
#endif

extern int assert_count;
extern const char* emu_path;
extern const char *emu_path;
extern bool enable_simjtag;

extern int signal_num;
Expand All @@ -63,29 +62,29 @@ extern bool sim_verbose;
} \
} while (0)

#define Assert(cond, ...) \
do { \
if (!(cond)) { \
fflush(stdout); \
#define Assert(cond, ...) \
do { \
if (!(cond)) { \
fflush(stdout); \
fprintf(stderr, "\33[1;31m"); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\33[0m\n"); \
assert(cond); \
} \
fprintf(stderr, "\33[0m\n"); \
assert(cond); \
} \
} while (0)

#define panic(...) Assert(0, __VA_ARGS__)

#define fprintf_with_pid(stream, ...) \
do { \
#define fprintf_with_pid(stream, ...) \
do { \
fprintf(stream, "(%d) ", getpid()); \
fprintf(stream, __VA_ARGS__); \
}while(0)
fprintf(stream, __VA_ARGS__); \
} while (0)

#define printf_with_pid(...) \
do { \
#define printf_with_pid(...) \
do { \
fprintf_with_pid(stdout, __VA_ARGS__); \
}while(0)
} while (0)

#define TODO() panic("please implement me")

Expand Down
58 changes: 30 additions & 28 deletions src/test/csrc/common/compress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ double calcTime(timeval s, timeval e) {
double sec, usec;
sec = e.tv_sec - s.tv_sec;
usec = e.tv_usec - s.tv_usec;
return 1000*sec + usec/1000.0;
return 1000 * sec + usec / 1000.0;
}

// Return whether the file is a gz file
Expand Down Expand Up @@ -51,25 +51,27 @@ long snapshot_compressToFile(uint8_t *ptr, const char *filename, long buf_size)
long curr_size = 0;
const uint32_t chunk_size = 16384;
long *temp_page = new long[chunk_size];
long *pmem_current = (long*)ptr;
long *pmem_current = (long *)ptr;

while (curr_size < buf_size) {
memset(temp_page, 0, chunk_size * sizeof(long));
for (uint32_t x = 0; x < chunk_size / sizeof(long); x++) {
pmem_current = (long*)((uint8_t*)ptr + curr_size + x * sizeof(long));
pmem_current = (long *)((uint8_t *)ptr + curr_size + x * sizeof(long));
if (*pmem_current != 0) {
*(temp_page + x) = *pmem_current;
}
}
uint32_t bytes_write = gzwrite(compressed_mem, temp_page, chunk_size);
if (bytes_write <= 0) { printf("Compress failed\n"); break; }
if (bytes_write <= 0) {
printf("Compress failed\n");
break;
}
curr_size += bytes_write;
// assert(bytes_write % sizeof(long) == 0);

}
// printf("Write %lu bytes from gz stream in total\n", curr_size);

delete [] temp_page;
delete[] temp_page;

if (gzclose(compressed_mem)) {
printf("Error closing '%s'\n", filename);
Expand All @@ -81,7 +83,7 @@ long snapshot_compressToFile(uint8_t *ptr, const char *filename, long buf_size)
#endif
}

long readFromGz(void* ptr, const char *file_name, long buf_size, uint8_t load_type) {
long readFromGz(void *ptr, const char *file_name, long buf_size, uint8_t load_type) {
#ifndef NO_GZ_COMPRESSION
assert(buf_size > 0);
gzFile compressed_mem = gzopen(file_name, "rb");
Expand Down Expand Up @@ -109,22 +111,22 @@ long readFromGz(void* ptr, const char *file_name, long buf_size, uint8_t load_ty
}
for (uint32_t x = 0; x < bytes_read / sizeof(long) + 1; x++) {
if (*(temp_page + x) != 0) {
long *pmem_current = (long*)((uint8_t*)ptr + curr_size + x * sizeof(long));
long *pmem_current = (long *)((uint8_t *)ptr + curr_size + x * sizeof(long));
*pmem_current = *(temp_page + x);
}
}
curr_size += bytes_read;
}

if(gzread(compressed_mem, temp_page, chunk_size) > 0) {
if (gzread(compressed_mem, temp_page, chunk_size) > 0) {
printf("File size is larger than buf_size!\n");
assert(0);
}
// printf("Read %lu bytes from gz stream in total\n", curr_size);

delete [] temp_page;
delete[] temp_page;

if(gzclose(compressed_mem)) {
if (gzclose(compressed_mem)) {
printf("Error closing '%s'\n", file_name);
return -1;
}
Expand All @@ -134,7 +136,7 @@ long readFromGz(void* ptr, const char *file_name, long buf_size, uint8_t load_ty
#endif
}

long readFromZstd(void* ptr, const char *file_name, long buf_size, uint8_t load_type) {
long readFromZstd(void *ptr, const char *file_name, long buf_size, uint8_t load_type) {
#ifndef NO_ZSTD_COMPRESSION
assert(buf_size > 0);

Expand Down Expand Up @@ -186,17 +188,17 @@ long readFromZstd(void* ptr, const char *file_name, long buf_size, uint8_t load_
ZSTD_DStream *dstream = ZSTD_createDStream();
if (!dstream) {
printf("Can't create zstd dstream object\n");
delete [] compress_file_buffer;
delete [] temp_page;
delete[] compress_file_buffer;
delete[] temp_page;
return -1;
}

size_t init_result = ZSTD_initDStream(dstream);
if (ZSTD_isError(init_result)) {
printf("Can't init zstd dstream object: %s\n",ZSTD_getErrorName(init_result));
printf("Can't init zstd dstream object: %s\n", ZSTD_getErrorName(init_result));
ZSTD_freeDStream(dstream);
delete [] compress_file_buffer;
delete [] temp_page;
delete[] compress_file_buffer;
delete[] temp_page;
return -1;
}

Expand All @@ -209,8 +211,8 @@ long readFromZstd(void* ptr, const char *file_name, long buf_size, uint8_t load_
if (ZSTD_isError(decompress_result)) {
printf("Decompress failed: %s\n", ZSTD_getErrorName(decompress_result));
ZSTD_freeDStream(dstream);
delete [] compress_file_buffer;
delete [] temp_page;
delete[] compress_file_buffer;
delete[] temp_page;
return -1;
}

Expand All @@ -220,7 +222,7 @@ long readFromZstd(void* ptr, const char *file_name, long buf_size, uint8_t load_

for (uint32_t x = 0; x < output_buffer.pos / sizeof(long) + 1; x++) {
if (*(temp_page + x) != 0) {
long *pmem_current = (long*)((uint8_t*)ptr + curr_size + x * sizeof(long));
long *pmem_current = (long *)((uint8_t *)ptr + curr_size + x * sizeof(long));
*pmem_current = *(temp_page + x);
}
}
Expand All @@ -229,28 +231,28 @@ long readFromZstd(void* ptr, const char *file_name, long buf_size, uint8_t load_

ZSTD_outBuffer output_buffer = {temp_page, chunk_size * sizeof(long), 0};
size_t decompress_result = ZSTD_decompressStream(dstream, &output_buffer, &input_buffer);
if (ZSTD_isError(decompress_result) || output_buffer.pos!=0) {
if (ZSTD_isError(decompress_result) || output_buffer.pos != 0) {
printf("Decompress failed: %s\n", ZSTD_getErrorName(decompress_result));
printf("Binary size larger than memory\n");
ZSTD_freeDStream(dstream);
delete [] compress_file_buffer;
delete [] temp_page;
delete[] compress_file_buffer;
delete[] temp_page;
return -1;
}

ZSTD_freeDStream(dstream);
delete [] compress_file_buffer;
delete [] temp_page;
delete[] compress_file_buffer;
delete[] temp_page;

return curr_size;
#else
return 0;
#endif
}

void nonzero_large_memcpy(const void* __restrict dest, const void* __restrict src, size_t n) {
void nonzero_large_memcpy(const void *__restrict dest, const void *__restrict src, size_t n) {
uint64_t *_dest = (uint64_t *)dest;
uint64_t *_src = (uint64_t *)src;
uint64_t *_src = (uint64_t *)src;
while (n >= sizeof(uint64_t)) {
if (*_src != 0) {
*_dest = *_src;
Expand All @@ -261,7 +263,7 @@ void nonzero_large_memcpy(const void* __restrict dest, const void* __restrict sr
}
if (n > 0) {
uint8_t *dest8 = (uint8_t *)_dest;
uint8_t *src8 = (uint8_t *)_src;
uint8_t *src8 = (uint8_t *)_src;
while (n > 0) {
*dest8 = *src8;
dest8++;
Expand Down
10 changes: 5 additions & 5 deletions src/test/csrc/common/compress.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@
#include <zlib.h>
#endif
#ifndef NO_ZSTD_COMPRESSION
#include <zstd.h>
#include <fcntl.h>
#include <zstd.h>
#endif

#define LOAD_SNAPSHOT 0
#define LOAD_RAM 1
#define LOAD_RAM 1

double calcTime(timeval s, timeval e);

bool isGzFile(const char *filename);
long snapshot_compressToFile(uint8_t *ptr, const char *filename, long buf_size);
long readFromGz(void* ptr, const char *file_name, long buf_size, uint8_t load_type);
long readFromGz(void *ptr, const char *file_name, long buf_size, uint8_t load_type);

void nonzero_large_memcpy(const void* __restrict dest, const void* __restrict src, size_t n);
void nonzero_large_memcpy(const void *__restrict dest, const void *__restrict src, size_t n);

bool isZstdFile(const char *filename);
long readFromZstd(void* ptr, const char *file_name, long buf_size, uint8_t load_type);
long readFromZstd(void *ptr, const char *file_name, long buf_size, uint8_t load_type);

#endif
Loading

0 comments on commit 9712733

Please sign in to comment.