From 2e415e7239cc2942c838694642c54326e84e86bc Mon Sep 17 00:00:00 2001 From: TimothyLottes Date: Sat, 12 Nov 2016 23:15:08 -0500 Subject: [PATCH] Add files via upload --- 20101004.html | 10 ++++++++++ 20101005.html | 9 +++++++++ index.html | 5 ++++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 20101004.html create mode 100644 20101005.html diff --git a/20101004.html b/20101004.html new file mode 100644 index 0000000..7b74a90 --- /dev/null +++ b/20101004.html @@ -0,0 +1,10 @@ +
+

20101004 - MSVC Optimizing Static Constant Function Tables?

+
+ + +Nope. Would be nice if the MSVC compiler could optimize FunctionJump() like FunctionIf() below,

#include <stdio.h>

typedef void (*Function)(const int);

static __forceinline void FunctionA(const int input) { printf("a=%d\n", input); }
static __forceinline void FunctionB(const int input) { printf("b=%d\n", input); }

static const Function function[2] = { FunctionA, FunctionB };

static __forceinline void FunctionJump(const int input) { function[input](input); }

static __forceinline void FunctionIf(const int input) {
if(input == 0) FunctionA(input);
if(input == 1) FunctionB(input); }

void main(void) {
FunctionJump(0);
FunctionJump(1);
FunctionIf(0);
FunctionIf(1); }


Trimmed section from assembly output /FAs,

PUBLIC _main
; Function compile flags: /Ogtpy
_TEXT SEGMENT
_main PROC

; 17 : FunctionJump(0);

push 0
call DWORD PTR _function

; 18 : FunctionJump(1);

push 1
call DWORD PTR _function+4

; 19 : FunctionIf(0);

push 0
push OFFSET $SG3833
call _printf

; 20 : FunctionIf(1); }

push 1
push OFFSET $SG3837
call _printf
add esp, 24 ; 00000018H
xor eax, eax
ret 0
_main ENDP
+ +
+ + diff --git a/20101005.html b/20101005.html new file mode 100644 index 0000000..23ee6f8 --- /dev/null +++ b/20101005.html @@ -0,0 +1,9 @@ +
+

20101005 - MSVC Optimizing Static Constant Data Copy?

+
+ +Yes. All extra copies factored out.

#include <stdio.h>

typedef struct {
int a;
int b;
int c;
int d;
} DataA;

typedef struct {
int a;
int d;
} DataB;

static const DataA dataA = { 0, 1, 2, 3 };

static __forceinline void DataCopy(
DataB* __restrict const dataB, const DataA* __restrict const dataA) {
dataB->a = dataA->a;
dataB->d = dataA->d; }

void main(void) {
DataB dataB;
DataCopy(&dataB, &dataA);
printf("dataB.d = %d\n", dataB.d); }


Trimmed part of /FAs assembly output,

PUBLIC _main
EXTRN _printf:PROC
; Function compile flags: /Ogtpy
_TEXT SEGMENT
_main PROC

; 56 : DataB dataB;
; 57 : DataCopy(&dataB, &dataA);
; 58 : printf("dataB.d = %d\n", dataB.d); }

push 3
push OFFSET $SG3859
call _printf
add esp, 8
xor eax, eax
ret 0
_main ENDP
+ +
+ + diff --git a/index.html b/index.html index a96b541..6b713ee 100644 --- a/index.html +++ b/index.html @@ -40,7 +40,7 @@ and attempting to restore what I can from prior lost images.

@@ -248,6 +248,9 @@ and attempting to restore what I can from prior lost images. 20110907 - Parallel Programming With Clones

2010
+20101005 - MSVC Optimizing Static Constant Data Copy?
+20101004 - MSVC Optimizing Static Constant Function Tables?
+
20100108 - AntiPlanet2
20100105 - Game Engine Architecture
20100104 - OnLive Notes