Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory test fails on 2 byte accesses #55

Closed
ukasz opened this issue May 19, 2023 · 3 comments
Closed

Memory test fails on 2 byte accesses #55

ukasz opened this issue May 19, 2023 · 3 comments

Comments

@ukasz
Copy link
Contributor

ukasz commented May 19, 2023

The following code fails on rev-devel (tested sha: cd753f7)
The same test works fine with 1,4,8 byte wide accesses.

#include <stdio.h>
#define u16 unsigned short
#define u8 unsigned char
#define assert(x) if (!(x)) { asm(".byte 0x00"); asm(".byte 0x00"); asm(".byte 0x00"); asm(".byte 0x00"); }

/*
 * Write 0 to a memory, hammer down ones around it,
 * check that it is still 0 at the end.
 */

#define hammer(type) int hammer_##type(type *addr, size_t size) { \
        int ret = 0; \
        type ff = (type)0xffffffffffff; \
        for (size_t i = 2; i < size - 2; i++) { \
                addr[i] = 0; \
                for (size_t j = 0; j < 10; j++) { \
                        addr[i - 1] = ff; \
                        addr[i - 2] = ff; \
                        addr[i + 1] = ff; \
                        addr[i + 2] = ff; \
                } \
                ret |= (addr[i] != 0);  \
        } \
        return ret; \
}

hammer(u16)

int test_3(void *addr, size_t size) {
        int ret = 0;

        ret |= hammer_u16(addr, size / 2);
        return ret;
}

/* Memory to test */
#define SIZE 10000
u8 mem[SIZE];

int main(){
        assert(!test_3(mem, SIZE));
}
@ukasz
Copy link
Contributor Author

ukasz commented May 19, 2023

Slightly different test case, which is also failing only on 2 byte data size:


#include <stdio.h>
#define u16 unsigned short
#define u8 unsigned char
#define assert(x) if (!(x)) { asm(".byte 0x00"); asm(".byte 0x00"); asm(".byte 0x00"); asm(".byte 0x00"); }

/* Memory to test */
#define SIZE 10000
u8 mem[SIZE];

#define fill_stride_f(type) void fill_stride_by_##type(type *addr, size_t size, type pattern, size_t idx, size_t stride) \
{ \
        for (size_t i = idx; i < size; i += stride) \
                addr[i] = pattern; \
}

fill_stride_f(u16);

#define check_stride_f(type) int check_stride_by_##type(type *addr, size_t size, size_t idx, type pattern, size_t stride) \
{ \
        int ret  = 0; \
        for (size_t i = idx; i < size; i += stride) \
                ret |= (addr[i] != pattern); \
        return ret;\
}

check_stride_f(u16);

int main(){
        u16 *addr =(u16*) mem;
        size_t size = SIZE/sizeof(u16);
        int ret = 0;
        const size_t stride = 16;

        for (size_t idx = 0; idx < stride; idx++) {
                fill_stride_by_u16((u16*)addr, size / 2, idx, idx, stride);
                ret |= check_stride_by_u16((u16*)addr, size / 2, idx, idx, stride);
        }
        assert(!ret);
        return 0;
}

@ukasz ukasz changed the title Memory test3 fails on 2 byte accesses Memory test fails on 2 byte accesses May 19, 2023
@donofrio
Copy link
Collaborator

Both of these tests should now work correctly in the latest devel branch

@ukasz
Copy link
Contributor Author

ukasz commented May 26, 2023

Tested on (4414659), problem no longer exists. Issue can be closed.

@ukasz ukasz closed this as completed May 26, 2023
leekillough pushed a commit to leekillough/rev that referenced this issue Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants