mirror of
https://github.com/eddyem/eddys_snippets.git
synced 2025-12-06 02:35:12 +03:00
fix makefile base (debug/release)
This commit is contained in:
parent
c7f8aa1d86
commit
58c3f188fe
0
Socket_CAN/ca/gen.sh
Normal file → Executable file
0
Socket_CAN/ca/gen.sh
Normal file → Executable file
0
Socket_CAN/diff/clientscript
Normal file → Executable file
0
Socket_CAN/diff/clientscript
Normal file → Executable file
0
Socket_CAN/diff/serverscript
Normal file → Executable file
0
Socket_CAN/diff/serverscript
Normal file → Executable file
0
Socket_CAN/socketcan0
Normal file → Executable file
0
Socket_CAN/socketcan0
Normal file → Executable file
@ -1,38 +1,43 @@
|
|||||||
# run `make DEF=...` to add extra defines
|
# run `make DEF=...` to add extra defines
|
||||||
PROGRAM :=
|
PROGRAM := dumpregs
|
||||||
<<<<<<< HEAD
|
|
||||||
LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all
|
LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all
|
||||||
|
LDFLAGS += -lusefull_macros
|
||||||
SRCS := $(wildcard *.c)
|
SRCS := $(wildcard *.c)
|
||||||
DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111
|
DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111
|
||||||
OBJDIR := mk
|
OBJDIR := mk
|
||||||
CFLAGS += -O2 -Wall -Wextra -Wno-trampolines -std=gnu99
|
CFLAGS += -O2 -Wall -Wextra -Wno-trampolines -std=gnu99
|
||||||
=======
|
|
||||||
LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all -Xlinker --warn-common
|
|
||||||
SRCS := $(wildcard *.c)
|
|
||||||
DEFINES := $(DEF) -D_XOPEN_SOURCE=1111
|
|
||||||
OBJDIR := mk
|
|
||||||
CFLAGS += -O2 -Wall -Werror -Wextra -Wno-trampolines -std=gnu99
|
|
||||||
>>>>>>> 8c51b1c4c29737d7d3c062d88cbb0f3ca2f97652
|
|
||||||
OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o))
|
OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o))
|
||||||
DEPS := $(OBJS:.o=.d)
|
DEPS := $(OBJS:.o=.d)
|
||||||
|
TARGFILE := $(OBJDIR)/TARGET
|
||||||
CC = gcc
|
CC = gcc
|
||||||
#CXX = g++
|
#TARGET := RELEASE
|
||||||
|
|
||||||
|
ifeq ($(shell test -e $(TARGFILE) && echo -n yes),yes)
|
||||||
|
TARGET := $(file < $(TARGFILE))
|
||||||
|
else
|
||||||
|
TARGET := RELEASE
|
||||||
|
endif
|
||||||
|
|
||||||
all : $(OBJDIR) $(PROGRAM)
|
ifeq ($(TARGET), DEBUG)
|
||||||
|
.DEFAULT_GOAL := debug
|
||||||
|
endif
|
||||||
|
|
||||||
|
release: $(PROGRAM)
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
debug: CFLAGS += -DEBUG -Werror
|
debug: CFLAGS += -DEBUG -Werror
|
||||||
debug: all
|
debug: TARGET := DEBUG
|
||||||
|
debug: $(PROGRAM)
|
||||||
|
|
||||||
=======
|
$(TARGFILE): $(OBJDIR)
|
||||||
>>>>>>> 8c51b1c4c29737d7d3c062d88cbb0f3ca2f97652
|
@echo -e "\t\tTARGET: $(TARGET)"
|
||||||
$(PROGRAM) : $(OBJS)
|
@echo "$(TARGET)" > $(TARGFILE)
|
||||||
|
|
||||||
|
$(PROGRAM) : $(TARGFILE) $(OBJS)
|
||||||
@echo -e "\t\tLD $(PROGRAM)"
|
@echo -e "\t\tLD $(PROGRAM)"
|
||||||
$(CC) $(LDFLAGS) $(OBJS) -o $(PROGRAM)
|
$(CC) $(LDFLAGS) $(OBJS) -o $(PROGRAM)
|
||||||
|
|
||||||
$(OBJDIR):
|
$(OBJDIR):
|
||||||
mkdir $(OBJDIR)
|
@mkdir $(OBJDIR)
|
||||||
|
|
||||||
ifneq ($(MAKECMDGOALS),clean)
|
ifneq ($(MAKECMDGOALS),clean)
|
||||||
-include $(DEPS)
|
-include $(DEPS)
|
||||||
@ -44,13 +49,9 @@ $(OBJDIR)/%.o: %.c
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
@echo -e "\t\tCLEAN"
|
@echo -e "\t\tCLEAN"
|
||||||
@rm -f $(OBJS) $(DEPS)
|
@rm -rf $(OBJDIR) 2>/dev/null || true
|
||||||
@rmdir $(OBJDIR) 2>/dev/null || true
|
|
||||||
|
|
||||||
xclean: clean
|
xclean: clean
|
||||||
@rm -f $(PROGRAM)
|
@rm -f $(PROGRAM)
|
||||||
|
|
||||||
gentags:
|
.PHONY: clean xclean
|
||||||
CFLAGS="$(CFLAGS) $(DEFINES)" geany -g $(PROGRAM).c.tags *[hc] 2>/dev/null
|
|
||||||
|
|
||||||
.PHONY: gentags clean xclean
|
|
||||||
144
factor.c
Normal file
144
factor.c
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <omp.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <usefull_macros.h>
|
||||||
|
|
||||||
|
#define THREADNO 8
|
||||||
|
|
||||||
|
typedef struct _num{
|
||||||
|
uint64_t n;
|
||||||
|
uint8_t isprime;
|
||||||
|
struct _num *next;
|
||||||
|
struct _num *prev;
|
||||||
|
} num;
|
||||||
|
|
||||||
|
static num *listhead = NULL, *listtail = NULL;
|
||||||
|
|
||||||
|
static void ins(uint64_t n, uint8_t isprime){// printf("ins %zd %d\n", n, isprime);
|
||||||
|
num *N = calloc(1, sizeof(num));
|
||||||
|
N->n = n; N->isprime = isprime;
|
||||||
|
if(listhead){
|
||||||
|
N->prev = listtail;
|
||||||
|
listtail->next = N;
|
||||||
|
listtail = N;
|
||||||
|
}else{
|
||||||
|
listhead = N;
|
||||||
|
listtail = N;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static num *del(num *el){// printf("del %zd %d\n", el->n, el->isprime);
|
||||||
|
num *nxt = el->next, *prev = el->prev;
|
||||||
|
if(el == listhead) listhead = nxt;
|
||||||
|
if(el == listtail) listtail = prev;
|
||||||
|
if(el->prev) el->prev->next = nxt;
|
||||||
|
if(el->next) el->next->prev = prev;
|
||||||
|
free(el);
|
||||||
|
return nxt;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint64_t __1st[2] = {2,3};
|
||||||
|
static void factorize(uint64_t n){
|
||||||
|
if(n < 2) return;
|
||||||
|
for(int i = 0; i < 2; ++i){
|
||||||
|
if(n % __1st[i] == 0){
|
||||||
|
ins(__1st[i], 1);
|
||||||
|
n /= __1st[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(n < 2) return;
|
||||||
|
uint8_t prime = 1;
|
||||||
|
register uint64_t last = (2 + sqrt(n))/6;
|
||||||
|
#pragma omp parallel for shared(n, prime)
|
||||||
|
for(uint64_t i = 1; i < last; ++i){
|
||||||
|
uint64_t nmb = i*6 - 1;
|
||||||
|
for(uint64_t x = 0; x < 3; x += 2){
|
||||||
|
nmb += x;
|
||||||
|
if(n % nmb == 0){
|
||||||
|
#pragma omp critical
|
||||||
|
{
|
||||||
|
ins(nmb, 0);
|
||||||
|
prime = 0;
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
if(prime){ // prime number
|
||||||
|
ins(n, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void calc_fact(uint64_t numb){
|
||||||
|
num *n = NULL;
|
||||||
|
if(listhead){ // free previous list
|
||||||
|
n = listhead;
|
||||||
|
do{
|
||||||
|
num *nxt = n->next;
|
||||||
|
free(n); n = nxt;
|
||||||
|
}while(n);
|
||||||
|
listhead = listtail = NULL;
|
||||||
|
}
|
||||||
|
factorize(numb);
|
||||||
|
n = listhead;
|
||||||
|
do{
|
||||||
|
if(n->n == numb){
|
||||||
|
n = del(n);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(!n->isprime){
|
||||||
|
uint64_t p = n->n;
|
||||||
|
n = del(n);
|
||||||
|
factorize(p);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
n = n->next;
|
||||||
|
}while(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv){
|
||||||
|
if(argc != 2){
|
||||||
|
printf("Usage: %s number or -t for test\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
omp_set_num_threads(THREADNO);
|
||||||
|
if(strcmp(argv[1], "-t") == 0){ // run test
|
||||||
|
uint64_t nmax = 0; double tmax = 0.;
|
||||||
|
for(uint64_t x = UINT64_MAX; x > 1ULL<<58; --x){
|
||||||
|
double t0 = dtime();
|
||||||
|
calc_fact(x);
|
||||||
|
double t = dtime() - t0;
|
||||||
|
if(t > tmax){
|
||||||
|
tmax = t;
|
||||||
|
nmax = x;
|
||||||
|
printf("n = %lu, t=%g\n", nmax, tmax);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
uint64_t numb = atoll(argv[1]), norig = numb;
|
||||||
|
calc_fact(numb);
|
||||||
|
printf("Number: %zd\n", numb);
|
||||||
|
if(!listhead || (listhead == listtail && listhead->n == numb)){
|
||||||
|
printf("Prime number %zd\n", numb);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
num *n = listhead;
|
||||||
|
printf("Fact: ");
|
||||||
|
uint64_t test = 1;
|
||||||
|
do{
|
||||||
|
while(numb % n->n == 0){
|
||||||
|
printf("%zd ", n->n);
|
||||||
|
numb /= n->n;
|
||||||
|
test *= n->n;
|
||||||
|
}
|
||||||
|
n = n->next;
|
||||||
|
}while(n);
|
||||||
|
if(numb != 1){
|
||||||
|
printf("%zd", numb);
|
||||||
|
test *= numb;
|
||||||
|
}
|
||||||
|
printf("\n\nTest: %zd == %zd ?\n", norig, test);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
0
serialsockCANmanage/www/bin/runSpeedCtrl
Normal file → Executable file
0
serialsockCANmanage/www/bin/runSpeedCtrl
Normal file → Executable file
@ -24,9 +24,9 @@ static inline __attribute__((always_inline)) void reset(uint64_t idx){
|
|||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
masks = malloc(MASKSZ);
|
masks = malloc(MASKSZ);
|
||||||
|
double t0 = dtime();
|
||||||
memset(masks, 0b10101010, MASKSZ); // without even numbers
|
memset(masks, 0b10101010, MASKSZ); // without even numbers
|
||||||
masks[0] = 0b10101100; // with 2 and withoun 0 and 1
|
masks[0] = 0b10101100; // with 2 and withoun 0 and 1
|
||||||
double t0 = dtime();
|
|
||||||
for(uint64_t i = 3; i < 64; i += 2){
|
for(uint64_t i = 3; i < 64; i += 2){
|
||||||
if(get(i)){
|
if(get(i)){
|
||||||
for(uint64_t j = i*2; j < MNUMBERS; j += i){
|
for(uint64_t j = i*2; j < MNUMBERS; j += i){
|
||||||
@ -35,18 +35,23 @@ int main(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("\tfirst 64: %g\n", dtime()-t0);
|
printf("\tfirst 64: %g\n", dtime()-t0);
|
||||||
omp_set_num_threads(8);
|
#define THREADNO 8
|
||||||
#pragma omp parallel for
|
omp_set_num_threads(THREADNO);
|
||||||
for(uint64_t i = 65; i < MNUMBERS; i += 2){
|
#pragma omp parallel for shared(masks)
|
||||||
if(get(i)){
|
for(uint64_t i = 0; i < THREADNO; ++i){
|
||||||
for(uint64_t j = i*2; j < MNUMBERS; j += i){
|
for(uint64_t idx = 65 + 2*omp_get_thread_num(); idx < MNUMBERS; idx += THREADNO*2){
|
||||||
|
if(get(idx)){
|
||||||
|
for(uint64_t j = idx*2; j < MNUMBERS; j += idx){
|
||||||
reset(j);
|
reset(j);
|
||||||
}
|
}
|
||||||
}
|
}}
|
||||||
}
|
}
|
||||||
printf("\tfull table: %g\n", dtime()-t0);
|
printf("\tfull table: %g\n", dtime()-t0);
|
||||||
for(uint64_t i = 0; i < 1000; ++i){
|
for(uint64_t i = 0; i < 1000; ++i){
|
||||||
if(get(i)) printf("%zd\n", i);
|
if(get(i)) printf("%zd\n", i);
|
||||||
}
|
}
|
||||||
|
for(uint64_t last = MNUMBERS-1; last > 1000; --last){
|
||||||
|
if(get(last)){ printf("last in list: %zd\n", last); break;}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user