Skip to content

Instantly share code, notes, and snippets.

View xigh's full-sized avatar

Philippe Anel xigh

View GitHub Profile
@xigh
xigh / asm_amd64.s
Last active May 20, 2024 09:48
DCAS for golang
TEXT ·CompareAndSwapDPointer(SB),4,$0
MOVQ addr+0(FP), SI
MOVQ old+8(FP), AX
MOVQ old+16(FP), DX
MOVQ new+24(FP), BX
MOVQ new+32(FP), CX
LOCK // forgot this one
// CMPXCHG16B (SI)
BYTE $0x48; BYTE $0x0F; BYTE $0xC7; BYTE $0x0E
@xigh
xigh / cond.go
Created August 23, 2018 14:02
How to use Golang sync/cond
package main
import (
"fmt"
"sync"
"time"
)
func main() {
c := sync.NewCond(&sync.Mutex{})
@xigh
xigh / pyth.c
Created December 24, 2018 08:19
Pythagorian Triples, the old way
#include <stdio.h>
int main()
{
int c = 1, n = 0;
while (n < 10)
{
int c2 = c * c;
for (int a = 1; a < c; a++)
{
@xigh
xigh / description.txt
Last active January 23, 2019 18:06
Retrieve openoffice documents from formatted harddrive
1- calls mmap on the disk device
2- looks for zip headers
3- retrieves the begining of the zip file
4- check if it contains a mimetype file with the expected mimetype
5- save the result to a file
@xigh
xigh / extractgc.sh
Created February 5, 2019 08:12
Extracting LLVM bitcode from ELF files generated with -fembed-bitcode.
#!/bin/sh
if [ "*$1" == "*" ]; then
echo "usage: extract.sh src dst"
fi
if [ "*$2" == "*" ]; then
echo "usage: extract.sh src dst"
fi
package main
import (
"database/sql"
"flag"
"fmt"
"log"
"time"
// Yes ... this is required !!!
@xigh
xigh / tables.go
Created June 19, 2019 18:04
dump #sql tables in #golang
package main
import (
"database/sql"
"flag"
"fmt"
"log"
_ "github.com/go-sql-driver/mysql"
)
@xigh
xigh / gcc-arm-test.c
Created January 19, 2020 10:30
I probably did something wrong ...
// -Wall -O2 -nostdlib -nostartfiles -ffreestanding -mcpu=arm1176jzf-s -mtune=arm1176jzf-s -mhard-float
void foobar()
{
uint8 buf[11] = { 0 };
for (int i = 0; i < sizeof(buf); i++)
{
uint8 x = buf[i];
uint32 a = (uint32) &buf[i];
uart_putx(a);
@xigh
xigh / uart-tx.v
Last active March 8, 2020 17:38
tinyfpga fpga uart tx hello world verilog
module top(
input CLK,
output USBPU,
output PIN_24,
);
assign USBPU = 0; // disable USB
wire clk115200hz;
dclk0 d0(.clk16mhz(CLK), .clk115200hz(clk115200hz));
#include <immintrin.h>
#include <inttypes.h>
#include <stdio.h>
char * sprint_m256(__m256 v) {
static char tmp[256];
snprintf(tmp, sizeof tmp, "[%8.2f, %8.2f, %8.2f, %8.2f, %8.2f, %8.2f, %8.2f, %8.2f]",
v[7], v[6], v[5], v[4], v[3], v[2], v[1], v[0]);
return tmp;
}