some work on x11 ext
This commit is contained in:
+1
-1
@@ -71,6 +71,6 @@ bool com_std_connect(com_std_fd fd, bool isnetwork, char const *address) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void com_std_exit(uint32_t status) { exit(status); }
|
||||
void com_std_exit(int32_t status) { exit(status); }
|
||||
|
||||
void com_std_close(com_std_fd fd) { fclose(fd); }
|
||||
|
||||
@@ -101,7 +101,7 @@ inline bool com_std_connect(com_std_fd fd, bool isnetwork,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
inline void com_std_exit(uint32_t status) {
|
||||
inline void com_std_exit(int32_t status) {
|
||||
__asm__ volatile("syscall" : : "a"(60), "D"(status) : "rcx", "r11", "memory");
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ inline bool com_std_connect(com_std_fd fd, bool isnetwork,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
inline void com_std_exit(uint32_t status) {
|
||||
inline void com_std_exit(int32_t status) {
|
||||
__asm__ volatile("int $0x80" : : "a"(1), "b"(status) : "memory", "cc");
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
@@ -12,3 +12,5 @@ void *com_std_alloc(void *ptr, size_t size) { return NULL; }
|
||||
|
||||
double com_std_sqrt(double v) { return __builtin_sqrt(v); }
|
||||
double com_std_fabs(double v) { return __builtin_fabs(v); }
|
||||
double com_std_sin(double v) { return __builtin_sin(v); }
|
||||
double com_std_cos(double v) { return __builtin_cos(v); }
|
||||
|
||||
+22
-17
@@ -24,23 +24,28 @@ size_t strlen(char const *s) {
|
||||
return p - s;
|
||||
}
|
||||
|
||||
double com_std_sin(double v) {
|
||||
double result;
|
||||
__asm__ __volatile__("fldl %1\n\t"
|
||||
"fsin\n\t"
|
||||
"fstpl %0"
|
||||
: "=g"(result)
|
||||
: "m"(v)
|
||||
: "st", "st(1)");
|
||||
return result;
|
||||
double sin(double v) {
|
||||
double r;
|
||||
__asm__ __volatile__("fsin" : "=t"(r) : "0"(v));
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
double com_std_cos(double v) {
|
||||
double result;
|
||||
__asm__ __volatile__("fldl %1\n\t"
|
||||
"fcos\n\t"
|
||||
"fstpl %0"
|
||||
: "=g"(result)
|
||||
: "m"(v));
|
||||
return result;
|
||||
double cos(double v) {
|
||||
double r;
|
||||
__asm__ __volatile__("fcos" : "=t"(r) : "0"(v));
|
||||
return r;
|
||||
}
|
||||
|
||||
void sincos(double v, double *s, double *c) {
|
||||
double sv, cv;
|
||||
__asm__ __volatile__("fsincos" : "=t"(cv), "=u"(sv) : "0"(v));
|
||||
*s = sv;
|
||||
*c = cv;
|
||||
}
|
||||
|
||||
double sqrt(double v) {
|
||||
double r;
|
||||
__asm__ volatile("sqrtss %1, %0" : "=x"(r) : "x"(v));
|
||||
return r;
|
||||
}
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ typedef struct com_buf {
|
||||
struct com_buf *p_v = (struct com_buf *)&p_v##_buf; \
|
||||
p_v->cap = (p_c); \
|
||||
p_v->flags = p_f | COM_BUF_STACK; \
|
||||
p_v->typesz = sizeof(p_t);
|
||||
p_v->typesz = sizeof(p_t)
|
||||
|
||||
#define com_buf_index_as(p_t, p_v, p_i) \
|
||||
(p_t *)(&(p_v)->data[sizeof(p_t) * (p_i)])
|
||||
|
||||
+2
-6
@@ -57,12 +57,7 @@ static inline uint8_t com_gem_clip_vis_project(com_vec_t a, com_pnt_t *out) {
|
||||
mask ^= COM_GEM_VERTEX_CLIPPED_X;
|
||||
if (a.a[1] < -a.a[2] || a.a[1] > a.a[2])
|
||||
mask ^= COM_GEM_VERTEX_CLIPPED_Y;
|
||||
// out->a[0] = com_fix_mul((com_fix_div(a.a[0], a.a[2]) + COM_FIX_FRACUNIT) >>
|
||||
// 1,
|
||||
// COM_CFG_WIDTH * COM_FIX_FRACUNIT);
|
||||
// out->a[1] = com_fix_mul((com_fix_div(a.a[1], a.a[2]) + COM_FIX_FRACUNIT) >>
|
||||
// 1,
|
||||
// COM_CFG_HEIGHT * COM_FIX_FRACUNIT);
|
||||
|
||||
out->a[0] = (com_fix_mul(com_fix_div(a.a[0], a.a[2]),
|
||||
COM_CFG_WIDTH * COM_FIX_FRACUNIT) >>
|
||||
COM_FIX_FRACBITS) +
|
||||
@@ -71,6 +66,7 @@ static inline uint8_t com_gem_clip_vis_project(com_vec_t a, com_pnt_t *out) {
|
||||
COM_CFG_HEIGHT * COM_FIX_FRACUNIT) >>
|
||||
COM_FIX_FRACBITS) +
|
||||
(COM_CFG_HEIGHT / 2);
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -26,12 +26,13 @@ typedef void *com_std_fd;
|
||||
#define COM_STD_OPEN_WRITE (1 << 1)
|
||||
com_std_fd com_std_open(char const *path, uint32_t flags);
|
||||
bool com_std_write(com_std_fd fd, void const *data, uint32_t bytes);
|
||||
/* TODO: Return unit32_t, error on ZERO? Separate EOF check? */
|
||||
int32_t com_std_read(com_std_fd fd, void *data, uint32_t upto);
|
||||
bool com_std_has_data(com_std_fd);
|
||||
bool com_std_sfwd(com_std_fd fd, uint32_t bytes);
|
||||
com_std_fd com_std_socket(bool isnetwork);
|
||||
bool com_std_connect(com_std_fd sock, bool isnetwork, char const *address);
|
||||
void com_std_exit(uint32_t status) __attribute__((noreturn));
|
||||
void com_std_exit(int32_t status) __attribute__((noreturn));
|
||||
void com_std_close(com_std_fd fd);
|
||||
|
||||
/* TODO: Remove, use buffer semantics instead. */
|
||||
|
||||
+3
-3
@@ -47,9 +47,9 @@ static inline int32_t com_str_ext_find_char(char const *s, char ch) {
|
||||
|
||||
/* Returns true if string 'a' is prefixed by 'b'. */
|
||||
static inline bool com_str_ext_prefixed(char const *__restrict a,
|
||||
struct com_str prefix) {
|
||||
uint32_t n = prefix.len;
|
||||
char *b = prefix.data;
|
||||
struct com_str const *prefix) {
|
||||
uint32_t n = prefix->len;
|
||||
char *b = prefix->data;
|
||||
while (n && *a && (*a == *b)) {
|
||||
++a;
|
||||
++b;
|
||||
|
||||
+30
-5
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "bits.h"
|
||||
#include "fix.h"
|
||||
#include "mat.h"
|
||||
#include "std.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
@@ -18,7 +19,7 @@
|
||||
static bool com_test_fix(void) {
|
||||
bool anyfail = false;
|
||||
{
|
||||
double max_sqrt_deviation = 0.0f;
|
||||
double max_sqrt_deviation = 0.0;
|
||||
com_fix_t sqrt_accumulator = 0;
|
||||
com_fix_t sqrt_test_step = COM_FIX_FRACUNIT >> 2; /* Quarter step */
|
||||
for (int i = 0; i < COM_FIX_FRACUNIT << 1; ++i) {
|
||||
@@ -34,7 +35,7 @@ static bool com_test_fix(void) {
|
||||
}
|
||||
|
||||
{
|
||||
double max_sin_deviation = 0.0f;
|
||||
double max_sin_deviation = 0.0;
|
||||
com_fix_t sin_accumulator = -COM_FIX_PI * 4;
|
||||
com_fix_t sin_test_step = (COM_FIX_PI << 1) >> 10;
|
||||
for (int i = 0; i < 1024 * 32; ++i) {
|
||||
@@ -50,7 +51,7 @@ static bool com_test_fix(void) {
|
||||
}
|
||||
|
||||
{
|
||||
double max_cos_deviation = 0.0f;
|
||||
double max_cos_deviation = 0.0;
|
||||
com_fix_t cos_accumulator = -COM_FIX_PI * 4;
|
||||
com_fix_t cos_test_step = (COM_FIX_PI << 1) >> 10;
|
||||
for (int i = 0; i < 1024 * 32; ++i) {
|
||||
@@ -66,8 +67,8 @@ static bool com_test_fix(void) {
|
||||
}
|
||||
|
||||
{
|
||||
double max_sin_deviation = 0.0f;
|
||||
double max_cos_deviation = 0.0f;
|
||||
double max_sin_deviation = 0.0;
|
||||
double max_cos_deviation = 0.0;
|
||||
com_fix_t sincos_accumulator = -COM_FIX_PI * 4;
|
||||
com_fix_t sincos_test_step = (COM_FIX_PI << 1) >> 10;
|
||||
for (int i = 0; i < 1024 * 32; ++i) {
|
||||
@@ -105,6 +106,26 @@ static bool com_test_bits(void) {
|
||||
return anyfail;
|
||||
}
|
||||
|
||||
static bool com_test_mat(void) {
|
||||
bool anyfail = false;
|
||||
|
||||
com_mat_t const m0 = com_mat_identity();
|
||||
com_mat_t m1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
|
||||
for (int i = 0; i < 16; ++i)
|
||||
m1.a[i] *= COM_FIX_FRACUNIT;
|
||||
|
||||
com_mat_t const mul = com_mat_mul(m1, m0);
|
||||
com_mat_t const mul_reordered = com_mat_mul_reodered(com_mat_reoder(m1), m0);
|
||||
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
TEST(mul.a[i] == mul_reordered.a[i]);
|
||||
if (mul.a[i] != mul_reordered.a[i])
|
||||
break;
|
||||
}
|
||||
|
||||
return anyfail;
|
||||
}
|
||||
|
||||
static bool com_test_run(void) {
|
||||
bool anyfail = false;
|
||||
if (com_test_fix()) {
|
||||
@@ -115,6 +136,10 @@ static bool com_test_run(void) {
|
||||
com_std_print('c', "com_bits tests failed!");
|
||||
anyfail = true;
|
||||
}
|
||||
if (com_test_mat()) {
|
||||
com_std_print('c', "com_mat tests failed!");
|
||||
anyfail = true;
|
||||
}
|
||||
return !anyfail;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user