Intial commit of source code samples for GitHub repo.

This commit is contained in:
Ed Braaten 2015-04-21 14:02:59 -07:00 committed by Ed Braaten
parent 5793080047
commit 9462407ba8
14 changed files with 397 additions and 1 deletions

40
sizeofchk/Makefile Normal file
View file

@ -0,0 +1,40 @@
# Makefile for Simple Sizeof Utility
#
# Created 2014-06-26 by Ed Braaten
#
# Variables that may need tweaking...
COMPILER=gcc
#COMPILER=icc
#COMPILER=clang
CCOPTIONS=-O -Wall
INSTALLPATH=/usr/local/bin
# These variables shouldn't need any tweaking
CCVERSION=`${COMPILER} --version | head -1`
BINARYNAME=sizeofchk-${COMPILER}
SHORT_SHA:=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
PGM_VERSION=1.0 (git-$(SHORT_SHA))
# Target to build the main program...
${BINARYNAME}: Makefile sizeofchk.c
@echo "#define COMPILEINFO \"${CCVERSION}\"" >sizeofchk.h
@echo "#define ARCHINFO \""`uname -m`"\"" >>sizeofchk.h
@echo "#define SYSINFO \""`uname -s`"\"" >>sizeofchk.h
@echo "#define RELEASEINFO \""`uname -r`"\"" >>sizeofchk.h
@echo "#define VERSION_STRING \"${PGM_VERSION}\"" >>sizeofchk.h
@echo "Header file created..."
${COMPILER} ${CCOPTIONS} -o ${BINARYNAME} sizeofchk.c
chmod 755 ${BINARYNAME}
install:
mkdir -p /usr/local/bin
cp ${BINARYNAME} ${INSTALLPATH}
chmod 755 ${INSTALLPATH}/${BINARYNAME}
clean:
rm -f ${BINARYNAME} sizeofchk.h *.o
tidy:
rm -f *.o

4
sizeofchk/README.md Normal file
View file

@ -0,0 +1,4 @@
sizeofchk
=========
Utility to print out size in bits of basic types supported by your compiler.

46
sizeofchk/sizeofchk.c Normal file
View file

@ -0,0 +1,46 @@
/* simple utility to print out sizeof values...
*/
#include <stdio.h>
#include <x86intrin.h>
#include "sizeofchk.h" /* generated by makefile */
static char version[] = VERSION_STRING;
int main()
{
int (*funcptr)();
printf("Sizeof Utility by Ed Braaten - Version %s\n", version);
printf("Running on %s (%s %s)\n", ARCHINFO, SYSINFO, RELEASEINFO);
printf("Compiler version: '%s'\n\n", COMPILEINFO);
printf(" sizeof(char) = %lu bits\n", sizeof(char) * 8);
printf(" sizeof(short) = %lu bits\n", sizeof(short) * 8);
printf(" sizeof(int) = %lu bits\n", sizeof(int) * 8);
printf(" sizeof(long int) = %lu bits\n", sizeof(long int) * 8);
printf(" sizeof(long) = %lu bits\n", sizeof(long) * 8);
printf(" sizeof(long long) = %lu bits\n", sizeof(long long) * 8);
printf(" sizeof(float) = %lu bits\n", sizeof(float) * 8);
printf(" sizeof(double) = %lu bits\n", sizeof(double) * 8);
printf(" sizeof(long double) = %lu bits\n", sizeof(long double) * 8);
printf(" sizeof(char *) = %lu bits\n", sizeof(char *) * 8);
printf(" sizeof((*)()) = %lu bits\n", sizeof(funcptr) * 8);
#ifdef __SSE__
printf("\nSSE types\n\n");
printf(" sizeof(__m64) = %lu bits\n", sizeof(__m64) * 8);
printf(" sizeof(__m128) = %lu bits\n", sizeof(__m128) * 8);
#endif
#ifdef __clang__
/* clang doesn't support __float128 */
#else
#ifdef __SSE2__
printf(" sizeof(__float128) = %lu bits\n", sizeof(__float128) * 8);
#endif
#endif
printf("\n");
return(0);
}