Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Commit

Permalink
Add back jserv's changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jserv authored and lihop committed May 22, 2022
1 parent 0c499d9 commit e293033
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 302 deletions.
65 changes: 0 additions & 65 deletions 2019-02-10/Makefile.js

This file was deleted.

226 changes: 0 additions & 226 deletions 2019-02-10/cutils.h

This file was deleted.

4 changes: 2 additions & 2 deletions Makefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ all: $(PROGS)
JS_OBJS=jsemu.js.o softfp.js.o virtio.js.o fs.js.o fs_net.js.o fs_wget.js.o fs_utils.js.o simplefb.js.o pci.js.o json.js.o block_net.js.o
JS_OBJS+=iomem.js.o cutils.js.o aes.js.o sha256.js.o

RISCVEMU64_OBJS=$(JS_OBJS) riscv_cpu64.js.o riscv_machine.js.o machine.js.o
RISCVEMU32_OBJS=$(JS_OBJS) riscv_cpu32.js.o riscv_machine.js.o machine.js.o
RISCVEMU64_OBJS=$(JS_OBJS) riscv_cpu64.js.o riscv_machine.js.o machine.js.o elf.js.o
RISCVEMU32_OBJS=$(JS_OBJS) riscv_cpu32.js.o riscv_machine.js.o machine.js.o elf.js.o

js/riscvemu64.js: $(RISCVEMU64_OBJS) js/lib.js
$(EMCC) $(EMLDFLAGS_ASMJS) -o $@ $(RISCVEMU64_OBJS)
Expand Down
50 changes: 41 additions & 9 deletions cutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,21 @@ static inline int min_int(int a, int b)
void *mallocz(size_t size);

#if defined(_WIN32)
static inline uint16_t bswap_16(uint16_t v)
{
return (((v) & 0xff) << 8) | ((v) >> 8);
}
static inline uint32_t bswap_32(uint32_t v)
{
return ((v & 0xff000000) >> 24) | ((v & 0x00ff0000) >> 8) |
((v & 0x0000ff00) << 8) | ((v & 0x000000ff) << 24);
}
#define bswap_64(x) _byteswap_uint64(x)
#elif defined(__APPLE__)
#include <libkern/OSByteOrder.h>
#define bswap_16(x) OSSwapInt16(x)
#define bswap_32(x) OSSwapInt32(x)
#define bswap_64(x) OSSwapInt64(x)
#else
#include <byteswap.h>
#endif
Expand Down Expand Up @@ -160,17 +170,39 @@ static inline uint32_t cpu_to_be32(uint32_t v)
}
#endif

/* XXX: optimize */
static inline int ctz32(uint32_t a)
static inline int ctz32(uint32_t val)
{
int i;
if (a == 0)
return 32;
for(i = 0; i < 32; i++) {
if ((a >> i) & 1)
return i;
#if defined(__GNUC__) && __GNUC__ >= 4
return val ? __builtin_ctz(val) : 32;
#else
/* Binary search for the trailing one bit. */
int cnt;
cnt = 0;
if (!(val & 0x0000FFFFUL)) {
cnt += 16;
val >>= 16;
}
if (!(val & 0x000000FFUL)) {
cnt += 8;
val >>= 8;
}
if (!(val & 0x0000000FUL)) {
cnt += 4;
val >>= 4;
}
return 32;
if (!(val & 0x00000003UL)) {
cnt += 2;
val >>= 2;
}
if (!(val & 0x00000001UL)) {
cnt++;
val >>= 1;
}
if (!(val & 0x00000001UL)) {
cnt++;
}
return cnt;
#endif
}


Expand Down

0 comments on commit e293033

Please sign in to comment.